drivers: uart: stm32: Fixes timing of TX_DONE generation.
Corrects TX_DONE generation occuring to early
on async api.
Fixes #33866
Signed-off-by: Zisis Adamos <zisarono@gmail.com>
diff --git a/drivers/serial/uart_stm32.c b/drivers/serial/uart_stm32.c
index 85f8b03..190a89b 100644
--- a/drivers/serial/uart_stm32.c
+++ b/drivers/serial/uart_stm32.c
@@ -776,6 +776,13 @@
if (data->dma_rx.timeout == 0) {
uart_stm32_dma_rx_flush(dev);
}
+ } else if (LL_USART_IsEnabledIT_TC(UartInstance) &&
+ LL_USART_IsActiveFlag_TC(UartInstance)) {
+
+ LL_USART_DisableIT_TC(UartInstance);
+ LL_USART_ClearFlag_TC(UartInstance);
+ /* Generate TX_DONE event when transmission is done */
+ async_evt_tx_done(data);
}
/* Clear errors */
@@ -893,8 +900,6 @@
}
irq_unlock(key);
-
- async_evt_tx_done(data);
}
static void uart_stm32_dma_replace_buffer(const struct device *dev)
@@ -987,8 +992,11 @@
LOG_DBG("tx: l=%d", data->dma_tx.buffer_length);
- /* disable TX interrupt since DMA will handle it */
- LL_USART_DisableIT_TC(UartInstance);
+ /* Clear TC flag */
+ LL_USART_ClearFlag_TC(UartInstance);
+
+ /* Enable TC interrupt so we can signal correct TX done */
+ LL_USART_EnableIT_TC(UartInstance);
/* set source address */
data->dma_tx.blk_cfg.source_address = (uint32_t)data->dma_tx.buffer;