This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 12d8f81c0b947f275892d2160a6357c124233e8b
Author: ligd <[email protected]>
AuthorDate: Fri Feb 6 22:31:07 2026 +0800

    serial/cmsdk: drain stale rx data when enabling rx interrupt
    
    The CMSDK UART has only a 1-byte receive buffer with no FIFO.
    During boot, uart_cmsdk_setup() enables RX (CTRL.RX_EN) but the
    RX interrupt (CTRL.RX_INTEN) is not enabled until later when
    uart_cmsdk_rxint(enable=true) is called.
    
    If a character arrives in this window, the hardware sets RXFULL
    but does not set INTSTATUS.RX (because RX_INTEN is still off).
    Once RXFULL is stuck at 1, the UART refuses to accept any new
    characters and RX is permanently stalled. Enabling RX_INTEN
    afterwards does not retroactively generate the missed interrupt.
    
    Fix this by checking rxavailable() right after enabling the RX
    interrupt. If data is already present, call uart_recvchars() to
    drain it immediately, clearing RXFULL so the UART can receive
    new characters again.
    
    Signed-off-by: ligd <[email protected]>
---
 drivers/serial/serial_cmsdk.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/serial/serial_cmsdk.c b/drivers/serial/serial_cmsdk.c
index 76aed290527..08e6f3802e5 100644
--- a/drivers/serial/serial_cmsdk.c
+++ b/drivers/serial/serial_cmsdk.c
@@ -580,6 +580,18 @@ static void uart_cmsdk_rxint(struct uart_dev_s *dev, bool 
enable)
     {
       uart_cmsdk_serialmodify(priv, UART_CTRL_OFFSET,
         0, UART_CTRL_RX_INT_ENABLE | UART_CTRL_RX_OVERRUN_INT_ENABLE);
+
+      /* If a character arrived before the RX interrupt was enabled
+       * (e.g. during early boot when RX is on but RX_INT is off),
+       * RXFULL is already set but no interrupt was generated.
+       * The CMSDK UART won't accept new characters while RXFULL is
+       * set, so we must drain it here to avoid a permanent stall.
+       */
+
+      if (uart_cmsdk_rxavailable(dev))
+        {
+          uart_recvchars(dev);
+        }
     }
   else
     {

Reply via email to