Skip to content

Commit 3dd24fb

Browse files
authored
fix(uart): esp32/s2 baudrate > 1MHz
Fixes the baudrate for ESP32 and ESP32-S2 when the baud rate is higher than 1MHz. REF_TICK is just 2MHZ and can handle up to 1MHZ baudrate.
1 parent a9082d4 commit 3dd24fb

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cores/esp32/esp32-hal-uart.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,14 @@ uart_t *uartBegin(
508508
#if SOC_UART_SUPPORT_XTAL_CLK
509509
uart_config.source_clk = UART_SCLK_XTAL; // valid for C2, S3, C3, C6, H2 and P4
510510
#elif SOC_UART_SUPPORT_REF_TICK
511-
uart_config.source_clk = UART_SCLK_REF_TICK; // valid for ESP32, S2
511+
if (baudrate <= 1000000) {
512+
uart_config.source_clk = UART_SCLK_REF_TICK; // valid for ESP32, S2 - MAX supported baud rate is 1MHz
513+
} else {
514+
uart_config.source_clk = UART_SCLK_APB; // baudrate may change with the APB Frequency!
515+
}
512516
#else
513517
// Default CLK Source: CLK_APB for ESP32|S2|S3|C3 -- CLK_PLL_F40M for C2 -- CLK_PLL_F48M for H2 -- CLK_PLL_F80M for C6
514-
uart_config.source_clk = UART_SCLK_DEFAULT; // baudrate may change with the CPU Frequency!
518+
uart_config.source_clk = UART_SCLK_DEFAULT; // baudrate may change with the APB Frequency!
515519
#endif
516520

517521
UART_MUTEX_LOCK();

0 commit comments

Comments
 (0)