From 0ecaef0053eadff44dffb5c83a8460b768559971 Mon Sep 17 00:00:00 2001 From: Axel Le Bourhis Date: Tue, 29 Apr 2025 17:32:09 +0200 Subject: [PATCH] drivers: mcux_flexcomm: fix character glitches at low power entry Character glitches are observed when entering suspend and standby low power modes. To fix it, we make sure the `poll_out` API waits for the character transfer to complete. This is aligned with the uart driver API description. Signed-off-by: Axel Le Bourhis --- drivers/serial/uart_mcux_flexcomm.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/serial/uart_mcux_flexcomm.c b/drivers/serial/uart_mcux_flexcomm.c index 9fdb3c26c60..ac065769633 100644 --- a/drivers/serial/uart_mcux_flexcomm.c +++ b/drivers/serial/uart_mcux_flexcomm.c @@ -134,11 +134,22 @@ static void mcux_flexcomm_poll_out(const struct device *dev, { const struct mcux_flexcomm_config *config = dev->config; - /* Wait until space is available in TX FIFO */ - while (!(USART_GetStatusFlags(config->base) & kUSART_TxFifoEmptyFlag)) { + /* Wait until space is available in TX FIFO, as per API description: + * This routine checks if the transmitter is full. + * When the transmitter is not full, it writes a character to the data register. + * It waits and blocks the calling thread otherwise. + */ + while (!(USART_GetStatusFlags(config->base) & kUSART_TxFifoNotFullFlag)) { } USART_WriteByte(config->base, c); + + /* Wait for the transfer to complete, as per API description: + * This function is a blocking call. It blocks the calling thread until the character + * is sent. + */ + while (!(USART_GetStatusFlags(config->base) & kUSART_TxFifoEmptyFlag)) { + } } static int mcux_flexcomm_err_check(const struct device *dev)