diff --git a/cpu/esp32/periph/uart.c b/cpu/esp32/periph/uart.c index 7ea886579cc3..0d52b384eb44 100644 --- a/cpu/esp32/periph/uart.c +++ b/cpu/esp32/periph/uart.c @@ -395,6 +395,20 @@ static int _uart_set_mode(uart_t uart, uart_data_bits_t data_bits, _uarts[uart].data = data_bits; /* set number of stop bits */ + #ifdef MCU_ESP32 + /* workaround for hardware bug when stop bits are set to 2-bit mode. */ + switch (stop_bits) { + case UART_STOP_BITS_1: _uarts[uart].regs->conf0.stop_bit_num = 1; + _uarts[uart].regs->rs485_conf.dl1_en = 1; + break; + case UART_STOP_BITS_2: _uarts[uart].regs->conf0.stop_bit_num = 1; + _uarts[uart].regs->rs485_conf.dl1_en = 1; + break; + default: LOG_TAG_ERROR("uart", "invalid number of stop bits\n"); + critical_exit(); + return UART_NOMODE; + } + #else switch (stop_bits) { case UART_STOP_BITS_1: _uarts[uart].regs->conf0.stop_bit_num = 1; break; case UART_STOP_BITS_2: _uarts[uart].regs->conf0.stop_bit_num = 3; break; @@ -402,6 +416,8 @@ static int _uart_set_mode(uart_t uart, uart_data_bits_t data_bits, critical_exit(); return UART_NOMODE; } + #endif + /* store changed number of stop bits in configuration */ _uarts[uart].stop = stop_bits;