Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions drivers/serial/uart_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -1806,11 +1806,21 @@ static void uart_stm32_async_rx_timeout(struct k_work *work)

LOG_DBG("rx timeout");

/* The DMA is still active and could trigger an interrupt
* while we are processing this timeout, which could cause
* data corruption when the DMA ISR modifies shared data
* as we are operating on it. Prevent data race with ISR by
* masking all interrupts until we're done.
*/
unsigned int key = irq_lock();

if (data->dma_rx.counter == data->dma_rx.buffer_length) {
uart_stm32_async_rx_disable(dev);
} else {
uart_stm32_dma_rx_flush(dev, STM32_ASYNC_STATUS_TIMEOUT);
}

irq_unlock(key);
}

static void uart_stm32_async_tx_timeout(struct k_work *work)
Expand Down