Skip to content

Commit 6cf3d68

Browse files
authored
fix(uart): adjust get/set baudrate
Fixes the functions for reading/writing UART baudrate by using IDF functions instead of HAL/LL.
1 parent 0a885fd commit 6cf3d68

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

cores/esp32/esp32-hal-uart.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -784,25 +784,25 @@ void uartSetBaudRate(uart_t *uart, uint32_t baud_rate) {
784784
return;
785785
}
786786
UART_MUTEX_LOCK();
787-
uint32_t sclk_freq;
788-
if (uart_get_sclk_freq(UART_SCLK_DEFAULT, &sclk_freq) == ESP_OK) {
789-
uart_ll_set_baudrate(UART_LL_GET_HW(uart->num), baud_rate, sclk_freq);
787+
if (uart_set_baudrate(uart->num, baud_rate) == ESP_OK) {
788+
uart->_baudrate = baud_rate;
789+
} else {
790+
log_e("Setting UART%d baud rate to %d has failed.", uart->num, baud_rate);
790791
}
791-
uart->_baudrate = baud_rate;
792792
UART_MUTEX_UNLOCK();
793793
}
794794

795795
uint32_t uartGetBaudRate(uart_t *uart) {
796796
uint32_t baud_rate = 0;
797-
uint32_t sclk_freq;
798797

799798
if (uart == NULL) {
800799
return 0;
801800
}
802801

803802
UART_MUTEX_LOCK();
804-
if (uart_get_sclk_freq(UART_SCLK_DEFAULT, &sclk_freq) == ESP_OK) {
805-
baud_rate = uart_ll_get_baudrate(UART_LL_GET_HW(uart->num), sclk_freq);
803+
if (uart_get_baudrate(uart->num, &baud_rate) != ESP_OK) {
804+
log_e("Getting UART%d baud rate has failed.", uart->num);
805+
baud_rate = (uint32_t) -1; // return value when failed
806806
}
807807
UART_MUTEX_UNLOCK();
808808
return baud_rate;

0 commit comments

Comments
 (0)