Skip to content

Commit 9417a84

Browse files
SuGliderpre-commit-ci-lite[bot]
andauthoredNov 25, 2024
feat(uart): [IDF 5.3] fixes HardwareSerial::updateBaudRate() using a baud rate higher 230400 - checks UART Clock Source (#10643)
* fix(uart): fixes issue with update baudrate higher than 250000 * ci(pre-commit): Apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 6e57662 commit 9417a84

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed
 

‎cores/esp32/esp32-hal-uart.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
#include "hal/gpio_hal.h"
3434
#include "esp_rom_gpio.h"
3535

36-
static int s_uart_debug_nr = 0; // UART number for debug output
36+
static int s_uart_debug_nr = 0; // UART number for debug output
37+
#define REF_TICK_BAUDRATE_LIMIT 250000 // this is maximum UART badrate using REF_TICK as clock
3738

3839
struct uart_struct_t {
3940

@@ -522,7 +523,7 @@ uart_t *uartBegin(
522523
#if SOC_UART_SUPPORT_XTAL_CLK
523524
uart_config.source_clk = UART_SCLK_XTAL; // valid for C2, S3, C3, C6, H2 and P4
524525
#elif SOC_UART_SUPPORT_REF_TICK
525-
if (baudrate <= 250000) {
526+
if (baudrate <= REF_TICK_BAUDRATE_LIMIT) {
526527
uart_config.source_clk = UART_SCLK_REF_TICK; // valid for ESP32, S2 - MAX supported baud rate is 250 Kbps
527528
} else {
528529
uart_config.source_clk = UART_SCLK_APB; // baudrate may change with the APB Frequency!
@@ -804,6 +805,10 @@ void uartSetBaudRate(uart_t *uart, uint32_t baud_rate) {
804805
return;
805806
}
806807
UART_MUTEX_LOCK();
808+
#if !SOC_UART_SUPPORT_XTAL_CLK
809+
soc_module_clk_t newClkSrc = baud_rate <= REF_TICK_BAUDRATE_LIMIT ? SOC_MOD_CLK_REF_TICK : SOC_MOD_CLK_APB;
810+
uart_ll_set_sclk(UART_LL_GET_HW(uart->num), newClkSrc);
811+
#endif
807812
if (uart_set_baudrate(uart->num, baud_rate) == ESP_OK) {
808813
uart->_baudrate = baud_rate;
809814
} else {

0 commit comments

Comments
 (0)