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 bcf8c6690861ae1e45f79541a0b1ad3293997886
Author: ligd <[email protected]>
AuthorDate: Wed Feb 11 12:43:44 2026 +0800

    serial/cmsdk: fix RX lockup caused by up_putc disabling RX interrupts
    
    up_putc() uses disableuartint/restoreuartint to temporarily suppress
    all UART interrupts while doing polled TX output.  This includes
    clearing CTRL.RX_INT_ENABLE.
    
    On the CMSDK APB UART, the hardware only sets INTSTATUS_RX when a
    character is received AND RX_INT_ENABLE is asserted at that moment.
    If a character arrives during the window where up_putc() has cleared
    RX_INT_ENABLE, the UART latches RX_BUF_FULL in STATE but does NOT
    set INTSTATUS_RX.  When restoreuartint() re-enables RX_INT_ENABLE
    the interrupt is never generated, so the byte stays in the single-
    entry holding register forever.  Because RX_BUF_FULL blocks further
    reception, the UART is permanently stalled — no more RX interrupts
    fire, and if the console reader task blocks on input the TX path
    stalls as well.
    
    Fix this by having up_putc() only disable/restore the TX-side
    interrupt enables (TX_INT_ENABLE and TX_OVERRUN_INT_ENABLE).  Polled
    character transmission has no need to suppress RX interrupts, so
    leaving them enabled closes the race window entirely.
    
    Signed-off-by: ligd <[email protected]>
---
 drivers/serial/serial_cmsdk.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/serial/serial_cmsdk.c b/drivers/serial/serial_cmsdk.c
index 08e6f3802e5..e2dc99769aa 100644
--- a/drivers/serial/serial_cmsdk.c
+++ b/drivers/serial/serial_cmsdk.c
@@ -791,8 +791,20 @@ void up_putc(int ch)
   FAR struct uart_cmsdk_s *priv = CONSOLE_DEV.priv;
   uint32_t ier;
 
-  ier = uart_cmsdk_disableuartint(priv);
+  /* Only disable TX interrupts for polled output.  Disabling RX
+   * interrupts here is dangerous: if a character arrives while
+   * RX_INT_ENABLE is cleared, the CMSDK UART sets RX_BUF_FULL but
+   * does NOT set INTSTATUS_RX (the enable is checked at the moment
+   * the character is received).  When we restore the enable bit the
+   * interrupt is never generated and the byte stays in the holding
+   * register forever, blocking all further RX and — because the
+   * console task is now stuck — TX as well.
+   */
+
+  ier = uart_cmsdk_serialmodify(priv, UART_CTRL_OFFSET,
+          UART_CTRL_TX_INT_ENABLE | UART_CTRL_TX_OVERRUN_INT_ENABLE, 0);
   uart_cmsdk_putc(priv, ch);
-  uart_cmsdk_restoreuartint(priv, ier);
+  uart_cmsdk_serialmodify(priv, UART_CTRL_OFFSET, 0,
+          ier & (UART_CTRL_TX_INT_ENABLE | UART_CTRL_TX_OVERRUN_INT_ENABLE));
 }
 #endif

Reply via email to