Skip to content

Commit ddc95d9

Browse files
committed
Add an option to force IDF's default UART clock source
1 parent bbaabb1 commit ddc95d9

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Kconfig.projbuild

+11
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ config ARDUINO_SERIAL_EVENT_TASK_PRIORITY
118118
help
119119
Select at what priority you want the Serial Event task to run.
120120

121+
config ARDUINO_SERIAL_FORCE_IDF_DEFAULT_CLOCK_SOURCE
122+
bool "Force IDF default UART clock source"
123+
default "n"
124+
help
125+
Overrides Arduino's automatic UART clock selection with the default clock from IDF (clk_tree_defs.h).
126+
By default, Arduino optimizes the UART clock automatically: XTAL clock for C2, S3, C3, C6, H2, P4 and
127+
REF_TICK (<250k baud) or APB (>250k baud) for ESP32, S2.
128+
Enable this option only if you need to force IDF's default clock instead of Arduino's optimized settings.
129+
It is generally recommended to leave this disabled unless specifically required.
130+
Note: This configuration is not applicable to the low-power (LP) UART controller.
131+
121132
choice ARDUINO_UDP_RUNNING_CORE
122133
bool "Core on which Arduino's UDP is running"
123134
default ARDUINO_UDP_RUN_CORE0

cores/esp32/esp32-hal-uart.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,11 @@ uart_t *uartBegin(
670670
} else
671671
#endif
672672
{
673+
#if CONFIG_ARDUINO_SERIAL_FORCE_IDF_DEFAULT_CLOCK_SOURCE
674+
// 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|P4
675+
uart_config.source_clk = UART_SCLK_DEFAULT; // baudrate may change with the APB Frequency!
676+
log_v("Setting UART%d to use DEFAULT clock", uart_nr);
677+
#else
673678
// there is an issue when returning from light sleep with the C6 and H2: the uart baud rate is not restored
674679
// therefore, uart clock source will set to XTAL for all SoC that support it. This fix solves the C6|H2 issue.
675680
#if SOC_UART_SUPPORT_XTAL_CLK
@@ -684,9 +689,10 @@ uart_t *uartBegin(
684689
log_v("Setting UART%d to use APB clock", uart_nr);
685690
}
686691
#else
687-
// 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
692+
// 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|P4
688693
uart_config.source_clk = UART_SCLK_DEFAULT; // baudrate may change with the APB Frequency!
689694
log_v("Setting UART%d to use DEFAULT clock", uart_nr);
695+
#endif
690696
#endif
691697
}
692698

0 commit comments

Comments
 (0)