diff --git a/drivers/serial/uart_imx.c b/drivers/serial/uart_imx.c index 7c1b336c731..e07588381ce 100644 --- a/drivers/serial/uart_imx.c +++ b/drivers/serial/uart_imx.c @@ -113,16 +113,18 @@ static void uart_imx_poll_out(const struct device *dev, unsigned char c) static int uart_imx_poll_in(const struct device *dev, unsigned char *c) { UART_Type *uart = UART_STRUCT(dev); + int ret = -1; - while (!UART_GetStatusFlag(uart, uartStatusRxDataReady)) { - } - *c = UART_Getchar(uart); + if (UART_GetStatusFlag(uart, uartStatusRxDataReady)) { + *c = UART_Getchar(uart); - if (UART_GetStatusFlag(uart, uartStatusRxOverrun)) { - UART_ClearStatusFlag(uart, uartStatusRxOverrun); + if (UART_GetStatusFlag(uart, uartStatusRxOverrun)) { + UART_ClearStatusFlag(uart, uartStatusRxOverrun); + } + ret = 0; } - return 0; + return ret; } #ifdef CONFIG_UART_INTERRUPT_DRIVEN