From 92fb477641596e6d48581b069c086ce77037b0a6 Mon Sep 17 00:00:00 2001 From: Sylvio Alves Date: Thu, 23 Dec 2021 17:45:14 -0300 Subject: [PATCH] drivers: uart: esp32: fix poll in return value ESP32 uart_poll_in should return 0 on success and not the total amount of data read. This also adds a check in fifo_fill call to avoid negative values, otherwise it would send garbage to uart Closes #41352 Signed-off-by: Sylvio Alves --- drivers/serial/uart_esp32.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/serial/uart_esp32.c b/drivers/serial/uart_esp32.c index 2adcc66b672..6e03121a99c 100644 --- a/drivers/serial/uart_esp32.c +++ b/drivers/serial/uart_esp32.c @@ -103,7 +103,8 @@ static int uart_esp32_poll_in(const struct device *dev, unsigned char *p_char) } uart_hal_read_rxfifo(&DEV_CFG(dev)->hal, p_char, &inout_rd_len); - return inout_rd_len; + + return 0; } static void uart_esp32_poll_out(const struct device *dev, unsigned char c) @@ -355,6 +356,10 @@ static int uart_esp32_fifo_fill(const struct device *dev, { uint32_t written = 0; + if (len < 0) { + return 0; + } + uart_hal_write_txfifo(&DEV_CFG(dev)->hal, tx_data, len, &written); return written; }