From 6831b8b15e1cc52b509f5ad500ef812954e59a1c Mon Sep 17 00:00:00 2001 From: Alexander Shuklin Date: Thu, 4 Feb 2021 12:00:49 +0300 Subject: [PATCH] Drivers: serial: Fix stm32 uart async api callback Fixes the bug when driver changes offset after the callback call. When you have the ready event you suppose no changes in driver data after that. Fixes #31973 Signed-off-by: Alexander Shuklin --- drivers/serial/uart_stm32.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/serial/uart_stm32.c b/drivers/serial/uart_stm32.c index 29a793c92f1..39f7bc06eab 100644 --- a/drivers/serial/uart_stm32.c +++ b/drivers/serial/uart_stm32.c @@ -653,6 +653,9 @@ static inline void async_evt_rx_rdy(struct uart_stm32_data *data) .data.rx.offset = data->dma_rx.offset }; + /* update the current pos for new data */ + data->dma_rx.offset = data->dma_rx.counter; + /* send event only for new data */ if (event.data.rx.len > 0) { async_user_callback(data, &event); @@ -750,9 +753,6 @@ static void uart_stm32_dma_rx_flush(const struct device *dev) data->dma_rx.counter = rx_rcv_len; async_evt_rx_rdy(data); - - /* update the current pos for new data */ - data->dma_rx.offset = rx_rcv_len; } } } @@ -953,8 +953,6 @@ void uart_stm32_dma_rx_cb(const struct device *dma_dev, void *user_data, async_evt_rx_rdy(data); - data->dma_rx.offset = data->dma_rx.counter; - if (data->rx_next_buffer != NULL) { async_evt_rx_buf_release(data);