Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d129308

Browse files
authoredJul 30, 2024··
fix(uart): Sets XTAL as clock source for uart
C6 and H2 have problems after returning from light sleep. The baud rate seems to be off when APB is used as clock source. This fix solves the issue using a steady clock source.
1 parent f5be003 commit d129308

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
@@ -503,9 +503,15 @@ uart_t *uartBegin(
503503
uart_config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
504504
uart_config.rx_flow_ctrl_thresh = rxfifo_full_thrhd;
505505
uart_config.baud_rate = baudrate;
506-
// CLK_APB for ESP32|S2|S3|C3 -- CLK_PLL_F40M for C2 -- CLK_PLL_F48M for H2 -- CLK_PLL_F80M for C6
507-
uart_config.source_clk = UART_SCLK_DEFAULT;
508-
506+
// there is an issue when returning from light sleep with the C6 and H2: the uart baud rate is not restored
507+
// therefore, uart clock source will set to XTAL for all SoC that support it. This fix solves the C6|H2 issue.
508+
#if SOC_UART_SUPPORT_XTAL_CLK
509+
uart_config.source_clk = UART_SCLK_XTAL; // valid for S3, C3, C6, H2 and P4
510+
#else
511+
// 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
512+
uart_config.source_clk = UART_SCLK_DEFAULT; // valid for ESP32 and S2
513+
#endif
514+
509515
UART_MUTEX_LOCK();
510516
bool retCode = ESP_OK == uart_driver_install(uart_nr, rx_buffer_size, tx_buffer_size, 20, &(uart->uart_event_queue), 0);
511517

0 commit comments

Comments
 (0)
Please sign in to comment.