Skip to content

Commit c355ad3

Browse files
authored
feat(uart): fixes loopback function after IDF changes
IDF 5.4.1 has added a new function called uart_release_pin() that is called whenever new pins are set or when uart driver is deleted. This has a side effect that causes RX pin to never work again with the loopback function. Other changes also have removed some GPIO setup that was necessary for the GPIO loopback mode work. The PR forces a full RX Pin setup in order to make it work in GPIO Matrix with Loopback TX Signal
1 parent ccda9c5 commit c355ad3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

cores/esp32/esp32-hal-uart.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
#include "driver/rtc_io.h"
3737
#include "driver/lp_io.h"
38-
#include "soc/uart_periph.h"
38+
#include "soc/uart_pins.h"
3939
#include "esp_private/uart_share_hw_ctrl.h"
4040

4141
static int s_uart_debug_nr = 0; // UART number for debug output
@@ -1391,7 +1391,7 @@ unsigned long uartDetectBaudrate(uart_t *uart) {
13911391
This is intended to make an internal loopback connection using IOMUX
13921392
The function uart_internal_loopback() shall be used right after Arduino Serial.begin(...)
13931393
This code "replaces" the physical wiring for connecting TX <--> RX in a loopback
1394-
*/
1394+
13951395
13961396
// gets the right TX or RX SIGNAL, based on the UART number from gpio_sig_map.h
13971397
#ifdef CONFIG_IDF_TARGET_ESP32P4
@@ -1416,6 +1416,7 @@ unsigned long uartDetectBaudrate(uart_t *uart) {
14161416
#define UART_RX_SIGNAL(uartNumber) (uartNumber == UART_NUM_0 ? U0RXD_IN_IDX : U1RXD_IN_IDX)
14171417
#endif
14181418
#endif // ifdef CONFIG_IDF_TARGET_ESP32P4
1419+
*/
14191420

14201421
/*
14211422
This function internally binds defined UARTs TX signal with defined RX pin of any UART (same or different).
@@ -1427,7 +1428,12 @@ void uart_internal_loopback(uint8_t uartNum, int8_t rxPin) {
14271428
log_e("UART%d is not supported for loopback or RX pin %d is invalid.", uartNum, rxPin);
14281429
return;
14291430
}
1430-
esp_rom_gpio_connect_out_signal(rxPin, UART_TX_SIGNAL(uartNum), false, false);
1431+
// forces rxPin to use GPIO Matrix and setup the pin to receive UART TX Signal - IDF 5.4.1 Change with uart_release_pin()
1432+
gpio_func_sel((gpio_num_t) rxPin, PIN_FUNC_GPIO);
1433+
gpio_pullup_en((gpio_num_t) rxPin);
1434+
gpio_input_enable((gpio_num_t) rxPin);
1435+
esp_rom_gpio_connect_in_signal(rxPin, uart_periph_signal[uartNum].pins[SOC_UART_RX_PIN_IDX].signal, false);
1436+
esp_rom_gpio_connect_out_signal(rxPin, uart_periph_signal[uartNum].pins[SOC_UART_TX_PIN_IDX].signal, false, false);
14311437
}
14321438

14331439
/*

0 commit comments

Comments
 (0)