From 50840e491b767e64f8dd8791842a0f52655ba418 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Mon, 23 Jun 2025 15:11:25 -0300 Subject: [PATCH 1/8] fix(uart): idf 5.5 new gpio_iomux_* functions --- cores/esp32/esp32-hal-uart.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 3e33c588c3b..c650b1c2169 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -315,26 +315,25 @@ static bool _uartTrySetIomuxPin(uart_port_t uart_num, int io_num, uint32_t idx) if (upin->iomux_func == -1 || upin->default_gpio == -1 || upin->default_gpio != io_num) { return false; } - // Assign the correct function to the GPIO. assert(upin->iomux_func != -1); if (uart_num < SOC_UART_HP_NUM) { - gpio_iomux_out(io_num, upin->iomux_func, false); - // If the pin is input, we also have to redirect the signal, in order to bypass the GPIO matrix. if (upin->input) { - gpio_iomux_in(io_num, upin->signal); + gpio_iomux_input(io_num, upin->iomux_func, upin->signal); + } else { + gpio_iomux_output(io_num, upin->iomux_func); } } #if (SOC_UART_LP_NUM >= 1) && (SOC_RTCIO_PIN_COUNT >= 1) - else { - if (upin->input) { - rtc_gpio_set_direction(io_num, RTC_GPIO_MODE_INPUT_ONLY); - } else { - rtc_gpio_set_direction(io_num, RTC_GPIO_MODE_OUTPUT_ONLY); + else { + if (upin->input) { + rtc_gpio_set_direction(io_num, RTC_GPIO_MODE_INPUT_ONLY); + } else { + rtc_gpio_set_direction(io_num, RTC_GPIO_MODE_OUTPUT_ONLY); + } + rtc_gpio_init(io_num); + rtc_gpio_iomux_func_sel(io_num, upin->iomux_func); } - rtc_gpio_init(io_num); - rtc_gpio_iomux_func_sel(io_num, upin->iomux_func); - } #endif return true; } From e5a57f5a997d875d76e1826f5f4e80b0fc814382 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Mon, 23 Jun 2025 15:21:07 -0300 Subject: [PATCH 2/8] fix(uart): formatting and style --- cores/esp32/esp32-hal-uart.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index c650b1c2169..d8b64bf8cd8 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -326,13 +326,13 @@ static bool _uartTrySetIomuxPin(uart_port_t uart_num, int io_num, uint32_t idx) } #if (SOC_UART_LP_NUM >= 1) && (SOC_RTCIO_PIN_COUNT >= 1) else { - if (upin->input) { - rtc_gpio_set_direction(io_num, RTC_GPIO_MODE_INPUT_ONLY); - } else { - rtc_gpio_set_direction(io_num, RTC_GPIO_MODE_OUTPUT_ONLY); - } - rtc_gpio_init(io_num); - rtc_gpio_iomux_func_sel(io_num, upin->iomux_func); + if (upin->input) { + rtc_gpio_set_direction(io_num, RTC_GPIO_MODE_INPUT_ONLY); + } else { + rtc_gpio_set_direction(io_num, RTC_GPIO_MODE_OUTPUT_ONLY); + } + rtc_gpio_init(io_num); + rtc_gpio_iomux_func_sel(io_num, upin->iomux_func); } #endif return true; From b95906f8774baeea455fd69107de80cec1de0817 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Mon, 23 Jun 2025 15:22:36 -0300 Subject: [PATCH 3/8] fix(uart): commentaries style fix --- cores/esp32/esp32-hal-uart.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index d8b64bf8cd8..89968fd2f5d 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -325,15 +325,15 @@ static bool _uartTrySetIomuxPin(uart_port_t uart_num, int io_num, uint32_t idx) } } #if (SOC_UART_LP_NUM >= 1) && (SOC_RTCIO_PIN_COUNT >= 1) - else { - if (upin->input) { - rtc_gpio_set_direction(io_num, RTC_GPIO_MODE_INPUT_ONLY); - } else { - rtc_gpio_set_direction(io_num, RTC_GPIO_MODE_OUTPUT_ONLY); - } - rtc_gpio_init(io_num); - rtc_gpio_iomux_func_sel(io_num, upin->iomux_func); + else { + if (upin->input) { + rtc_gpio_set_direction(io_num, RTC_GPIO_MODE_INPUT_ONLY); + } else { + rtc_gpio_set_direction(io_num, RTC_GPIO_MODE_OUTPUT_ONLY); } + rtc_gpio_init(io_num); + rtc_gpio_iomux_func_sel(io_num, upin->iomux_func); + } #endif return true; } From b30b7d1e68a6dbf1f245dce41be19e2c22062c04 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Mon, 23 Jun 2025 15:23:39 -0300 Subject: [PATCH 4/8] fix(uart): commentaries style fix --- cores/esp32/esp32-hal-uart.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 89968fd2f5d..3c6b24cb56b 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -315,7 +315,8 @@ static bool _uartTrySetIomuxPin(uart_port_t uart_num, int io_num, uint32_t idx) if (upin->iomux_func == -1 || upin->default_gpio == -1 || upin->default_gpio != io_num) { return false; } - // Assign the correct function to the GPIO. + + // Assign the correct function to the GPIO. assert(upin->iomux_func != -1); if (uart_num < SOC_UART_HP_NUM) { if (upin->input) { From 9255202986a6722d984dea79495ec87b8f819580 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Mon, 23 Jun 2025 15:24:13 -0300 Subject: [PATCH 5/8] fix(uart): commentaries style fix --- cores/esp32/esp32-hal-uart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 3c6b24cb56b..562131e2524 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -316,7 +316,7 @@ static bool _uartTrySetIomuxPin(uart_port_t uart_num, int io_num, uint32_t idx) return false; } - // Assign the correct function to the GPIO. + // Assign the correct function to the GPIO. assert(upin->iomux_func != -1); if (uart_num < SOC_UART_HP_NUM) { if (upin->input) { From 054742b6a8d2b44c6e6f4ffd792c44cddc2e81e2 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Mon, 23 Jun 2025 15:31:13 -0300 Subject: [PATCH 6/8] fix(uart): support to any idf 5.x version --- cores/esp32/esp32-hal-uart.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 562131e2524..f06ce7a44f6 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -319,11 +319,19 @@ static bool _uartTrySetIomuxPin(uart_port_t uart_num, int io_num, uint32_t idx) // Assign the correct function to the GPIO. assert(upin->iomux_func != -1); if (uart_num < SOC_UART_HP_NUM) { +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0) if (upin->input) { gpio_iomux_input(io_num, upin->iomux_func, upin->signal); } else { gpio_iomux_output(io_num, upin->iomux_func); } +#else + gpio_iomux_out(io_num, upin->iomux_func, false); + // If the pin is input, we also have to redirect the signal, in order to bypass the GPIO matrix. + if (upin->input) { + gpio_iomux_in(io_num, upin->signal); + } +#endif } #if (SOC_UART_LP_NUM >= 1) && (SOC_RTCIO_PIN_COUNT >= 1) else { From 85cd26e57f58110c2894eeb1234368e532227c35 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Mon, 23 Jun 2025 15:37:18 -0300 Subject: [PATCH 7/8] fix(uart): changing assert in order to avoid reset --- cores/esp32/esp32-hal-uart.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index f06ce7a44f6..2d8ba6a4e52 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -317,7 +317,10 @@ static bool _uartTrySetIomuxPin(uart_port_t uart_num, int io_num, uint32_t idx) } // Assign the correct function to the GPIO. - assert(upin->iomux_func != -1); + if (upin->iomux_func == -1) { + log_e("IO#%d has bad IOMUX internal information. Switching to GPIO Matrix UART function.", io_num); + return false; + } if (uart_num < SOC_UART_HP_NUM) { #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0) if (upin->input) { From 949515b2209a886cc8ca7d6567d6a0902c695a3d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Mon, 23 Jun 2025 20:30:54 +0000 Subject: [PATCH 8/8] ci(pre-commit): Apply automatic fixes --- cores/esp32/esp32-hal-uart.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 2d8ba6a4e52..6e5a22da9f8 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -1287,11 +1287,11 @@ bool uartSetClockSource(uint8_t uartNum, uart_sclk_t clkSrc) { #if SOC_UART_LP_NUM >= 1 if (uart->num >= SOC_UART_HP_NUM) { switch (clkSrc) { - case UART_SCLK_XTAL: uart->_uart_clock_source = LP_UART_SCLK_XTAL_D2; break; + case UART_SCLK_XTAL: uart->_uart_clock_source = LP_UART_SCLK_XTAL_D2; break; #if CONFIG_IDF_TARGET_ESP32C5 - case UART_SCLK_RTC: uart->_uart_clock_source = LP_UART_SCLK_RC_FAST; break; + case UART_SCLK_RTC: uart->_uart_clock_source = LP_UART_SCLK_RC_FAST; break; #else - case UART_SCLK_RTC: uart->_uart_clock_source = LP_UART_SCLK_LP_FAST; break; + case UART_SCLK_RTC: uart->_uart_clock_source = LP_UART_SCLK_LP_FAST; break; #endif case UART_SCLK_DEFAULT: default: uart->_uart_clock_source = LP_UART_SCLK_DEFAULT;