Skip to content

Commit 0fe2b60

Browse files
authored
feat(uart): adds option for setting default uart clock source from IDF
1 parent 513d67f commit 0fe2b60

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cores/esp32/HardwareSerial.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ bool HardwareSerial::setMode(SerialMode mode) {
610610
// Sets the UART Clock Source based on the compatible SoC options
611611
// This method must be called before starting UART using begin(), otherwise it won't have any effect.
612612
// Clock Source Options are:
613+
// UART_CLK_SRC_DEFAULT :: any SoC - it will set whatever IDF defines as the default UART Clock Source
613614
// UART_CLK_SRC_APB :: ESP32, ESP32-S2, ESP32-C3 and ESP32-S3
614615
// UART_CLK_SRC_PLL :: ESP32-C2, ESP32-C5, ESP32-C6, ESP32-C61, ESP32-H2 and ESP32-P4
615616
// UART_CLK_SRC_XTAL :: ESP32-C2, ESP32-C3, ESP32-C5, ESP32-C6, ESP32-C61, ESP32-H2, ESP32-S3 and ESP32-P4
@@ -618,7 +619,11 @@ bool HardwareSerial::setMode(SerialMode mode) {
618619
// Note: CLK_SRC_PLL Freq depends on the SoC - ESP32-C2 has 40MHz, ESP32-H2 has 48MHz and ESP32-C5, C6, C61 and P4 has 80MHz
619620
// Note: ESP32-C6, C61, ESP32-P4 and ESP32-C5 have LP UART that will use only RTC_FAST or XTAL/2 as Clock Source
620621
bool HardwareSerial::setClockSource(SerialClkSrc clkSrc) {
621-
return uartSetClockSource(_uart, (uart_sclk_t) clkSrc);
622+
if (clkSrc == UART_CLK_SRC_DEFAULT) {
623+
return uartSetClockSource(_uart, (uart_sclk_t) UART_SCLK_DEFAULT);
624+
} else {
625+
return uartSetClockSource(_uart, (uart_sclk_t) clkSrc);
626+
}
622627
}
623628

624629
// minimum total RX Buffer size is the UART FIFO space (128 bytes for most SoC) + 1. IDF imposition.

0 commit comments

Comments
 (0)