From 87fe374b3bec4a11fa11fe903c43fe8a8c2c6fed Mon Sep 17 00:00:00 2001 From: CTCaer Date: Sat, 14 May 2022 12:25:02 +0300 Subject: [PATCH] bdk: uart: use 2 STOP bits based on baudrate --- bdk/soc/uart.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bdk/soc/uart.c b/bdk/soc/uart.c index 4b72944..62a4692 100644 --- a/bdk/soc/uart.c +++ b/bdk/soc/uart.c @@ -34,14 +34,17 @@ void uart_init(u32 idx, u32 baud, u32 mode) // Set clock. bool clk_type = clock_uart_use_src_div(idx, baud); + // 2 STOP bits for rates > 1M. (Reduced efficiency but less errors on high baudrates). + u32 uart_lcr_stop = baud > 1000000 ? UART_LCR_STOP : 0; + // Misc settings. u32 div = clk_type ? ((8 * baud + 408000000) / (16 * baud)) : 1; // DIV_ROUND_CLOSEST. uart->UART_IER_DLAB = 0; // Disable interrupts. uart->UART_LCR = UART_LCR_DLAB | UART_LCR_WORD_LENGTH_8; // Enable DLAB & set 8n1 mode. uart->UART_THR_DLAB = (u8)div; // Divisor latch LSB. uart->UART_IER_DLAB = (u8)(div >> 8); // Divisor latch MSB. - // Disable DLAB and set 2 STOP bits (reduced efficiency but less errors on high baudrates). - uart->UART_LCR = UART_LCR_STOP | UART_LCR_WORD_LENGTH_8; + // Disable DLAB and set STOP bits setting if applicable. + uart->UART_LCR = uart_lcr_stop | UART_LCR_WORD_LENGTH_8; (void)uart->UART_SPR; // Setup and flush fifo.