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 cfd374587edb400d2748523a6b18f58961cc5904
Author: Piyush Patle <[email protected]>
AuthorDate: Wed May 20 08:01:01 2026 +0530

    drivers/serial/16550: fix AM62x console bring-up
    
    Adjust the generic 16550 driver for the AM62x console path. Preserve
    the FIFO programming sequence needed by the TI UART, keep the bootloader
    owned early console state when requested, and drain the transmit buffer
    correctly when polling mode is enabled.
    
    Signed-off-by: Piyush Patle <[email protected]>
---
 drivers/serial/uart_16550.c | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/drivers/serial/uart_16550.c b/drivers/serial/uart_16550.c
index 176250a922f..6278cab0728 100644
--- a/drivers/serial/uart_16550.c
+++ b/drivers/serial/uart_16550.c
@@ -807,11 +807,6 @@ static int u16550_setup(FAR struct uart_dev_s *dev)
       return -EPERM;
     }
 
-  /* Clear fifos */
-
-  u16550_serialout(priv, UART_FCR_OFFSET,
-                   (UART_FCR_RXRST | UART_FCR_TXRST));
-
   /* Set up the IER */
 
   priv->ier = u16550_serialin(priv, UART_IER_OFFSET);
@@ -892,10 +887,16 @@ static int u16550_setup(FAR struct uart_dev_s *dev)
 
   /* Configure the FIFOs */
 
+  /* Some 16550-compatible UARTs, including the AM62x console block, need
+   * FIFO enable, reset, and trigger configuration as separate writes.
+   */
+
+  u16550_serialout(priv, UART_FCR_OFFSET, UART_FCR_FIFOEN);
+  u16550_serialout(priv, UART_FCR_OFFSET,
+                   UART_FCR_FIFOEN | UART_FCR_TXRST | UART_FCR_RXRST);
   u16550_serialout(priv, UART_FCR_OFFSET,
-                   (priv->rxtrigger << UART_FCR_RXTRIGGER_SHIFT |
-                    UART_FCR_TXRST | UART_FCR_RXRST |
-                    UART_FCR_FIFOEN));
+                   UART_FCR_FIFOEN |
+                   (priv->rxtrigger << UART_FCR_RXTRIGGER_SHIFT));
 
 #ifdef CONFIG_16550_SET_MCR_OUT2
   /* Set OUT2 bit in MCR register */
@@ -1616,7 +1617,14 @@ static void u16550_txint(struct uart_dev_s *dev, bool 
enable)
 #ifdef CONFIG_16550_POLLING
       /* In polling mode, we loop until the buffer is empty */
 
-      uart_xmitchars(dev);
+      while (dev->xmit.head != dev->xmit.tail)
+        {
+          while (!u16550_txready(dev))
+            {
+            }
+
+          uart_xmitchars(dev);
+        }
 #else
       flags = enter_critical_section();
       priv->ier |= UART_IER_ETBEI;
@@ -1690,7 +1698,8 @@ void u16550_earlyserialinit(void)
 
 #ifdef CONSOLE_DEV
   CONSOLE_DEV.isconsole = true;
-#ifndef CONFIG_16550_SUPRESS_INITIAL_CONFIG
+#if !defined(CONFIG_16550_SUPRESS_INITIAL_CONFIG) && \
+    !defined(CONFIG_16550_SUPRESS_CONFIG)
   u16550_setup(&CONSOLE_DEV);
 #endif
 #endif

Reply via email to