From aa91500aee386eddfd2f5a3912320c08bff3d705 Mon Sep 17 00:00:00 2001 From: Andriy Gelman Date: Sun, 15 May 2022 14:49:22 -0400 Subject: [PATCH] drivers: uart_xmc4xxx: Check that receive buffers have data in poll_in As per XMCLib documentation we need to check that data has been received before reading the buffers. Fixes test_uart_poll_in test in tests/drivers/uart/uart_basic_api. Signed-off-by: Andriy Gelman --- drivers/serial/uart_xmc4xxx.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/serial/uart_xmc4xxx.c b/drivers/serial/uart_xmc4xxx.c index 22efc67ac61..deb2a6cdf5e 100644 --- a/drivers/serial/uart_xmc4xxx.c +++ b/drivers/serial/uart_xmc4xxx.c @@ -23,6 +23,10 @@ static int uart_xmc4xxx_poll_in(const struct device *dev, unsigned char *c) { const struct uart_xmc4xx_config *config = dev->config; + if (!XMC_USIC_CH_GetReceiveBufferStatus(config->uart)) { + return -1; + } + *c = (unsigned char)XMC_UART_CH_GetReceivedData(config->uart); return 0;