From e28b7e04e29e8c9b16b095a0b3fd24718fe5864a Mon Sep 17 00:00:00 2001 From: Peng Li Date: Mon, 12 Apr 2021 21:11:22 -0700 Subject: [PATCH] driver: serial: fixed the buffer underflow issue when clearing the port. Set DLAB bit before reading RDR to avoid buffer underflow. Signed-off-by: Peng Li --- drivers/serial/uart_ns16550.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/serial/uart_ns16550.c b/drivers/serial/uart_ns16550.c index 19b4dd64300..11e859b693e 100644 --- a/drivers/serial/uart_ns16550.c +++ b/drivers/serial/uart_ns16550.c @@ -339,7 +339,7 @@ static int uart_ns16550_configure(const struct device *dev, { struct uart_ns16550_dev_data_t * const dev_data = DEV_DATA(dev); const struct uart_ns16550_device_config * const dev_cfg = DEV_CFG(dev); - + uint8_t lcr_cache; uint8_t mdc = 0U; /* temp for return value if error occurs in this locked region */ @@ -466,7 +466,10 @@ static int uart_ns16550_configure(const struct device *dev, ); /* clear the port */ + lcr_cache = INBYTE(LCR(dev)); + OUTBYTE(LCR(dev), LCR_DLAB | lcr_cache); INBYTE(RDR(dev)); + OUTBYTE(LCR(dev), lcr_cache); /* disable interrupts */ OUTBYTE(IER(dev), 0x00);