From f9b42bc911c30fcbf4a096b20c6eca83da750c39 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Thu, 16 Nov 2023 20:39:39 +0100 Subject: [PATCH] drivers: serial: uart_stm32.c: RxDataFlush on async_rx_enable When enabling async RX the first time after boot, there is an additional byte received with the first RX_DATA_RDY event, which seems to be caused by the RX data not being flushed before enabling the UART RX DMA. Adding a request to flush the RX data register before enabling the RX DMA, solves the issue. Signed-off-by: Bjarki Arge Andreasen --- drivers/serial/uart_stm32.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/serial/uart_stm32.c b/drivers/serial/uart_stm32.c index 6c41d0f0a2e..fa2371cc1df 100644 --- a/drivers/serial/uart_stm32.c +++ b/drivers/serial/uart_stm32.c @@ -1579,6 +1579,13 @@ static int uart_stm32_async_rx_enable(const struct device *dev, return -EFAULT; } + /* Flush RX data buffer */ +#ifdef USART_SR_RXNE + LL_USART_ClearFlag_RXNE(config->usart); +#else + LL_USART_RequestRxDataFlush(config->usart); +#endif /* USART_SR_RXNE */ + /* Enable RX DMA requests */ uart_stm32_dma_rx_enable(dev);