console: allow use apb clock for uart to achieve high baud rate
Console sets UART clock source to REF_TICK on ESP32 and ESP32S2 by
default, however, APB clock frequency does not change when power
management is disabled. Using APB clock source allows higher baud rates
for UART console.
Closes
@@ -225,16 +225,24 @@ esp_err_t esp_console_new_repl_uart(const esp_console_dev_uart_config_t *dev_con
/* Configure UART. Note that REF_TICK/XTAL is used so that the baud rate remains
* correct while APB frequency is changing in light sleep mode.
*/
+#if SOC_UART_SUPPORT_REF_TICK
+ uart_sclk_t clk_source = UART_SCLK_REF_TICK;
+ // REF_TICK clock can't provide a high baudrate
+ if (dev_config->baud_rate > 1 * 1000 * 1000) {
+ clk_source = UART_SCLK_DEFAULT;
+ ESP_LOGW(TAG, "light sleep UART wakeup might not work at the configured baud rate");
+ }
+#elif SOC_UART_SUPPORT_XTAL_CLK
+ uart_sclk_t clk_source = UART_SCLK_XTAL;
+#else
+ #error "No UART clock source is aware of DFS"
+#endif // SOC_UART_SUPPORT_xxx
const uart_config_t uart_config = {
.baud_rate = dev_config->baud_rate,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
-#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
- .source_clk = UART_SCLK_REF_TICK,
-#else
- .source_clk = UART_SCLK_XTAL,
-#endif
+ .source_clk = clk_source,
};
uart_param_config(dev_config->channel, &uart_config);
