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


The following commit(s) were added to refs/heads/master by this push:
     new 1cc41cbcb15 arch/arm/src/stm32wl5: disable the USART while changing 
the line format
1cc41cbcb15 is described below

commit 1cc41cbcb15f5527a21dec3b54449d9c2f4b2a92
Author: Swatantra Yadav <[email protected]>
AuthorDate: Mon Nov 2 00:47:10 2026 +0530

    arch/arm/src/stm32wl5: disable the USART while changing the line format
    
    stm32wl5serial_setformat() writes BRR, CR2 STOP bits, and the PCE, PS,
    and M0/M1 bits of CR1 with the USART enabled.  They can only be written
    while UE = 0 per the ST Reference Manual (RM0453), so a run-time
    tcsetattr() that changes baud rate, parity, or word length returned
    success but left the hardware USART registers unchanged.
    
    Clear UE around the update and restore it inside a critical section,
    matching the approved STM32L4 (commit 47180bf5ea), STM32WB (PR #21334),
    STM32H7, and F7 implementations.
    
    Also fix pre-existing nxstyle alignment, declaration, and brace issues
    in stm32wl5serial_ioctl, stm32wl5serial_setapbclock, stm32wl5serial_detach,
    stm32wl5serial_pm_suspend, stm32wl5serial_pm_prepare, and
    stm32_serial_dma_poll.
    
    Signed-off-by: Swatantra Yadav <[email protected]>
    Assisted-by: Google Gemini
---
 arch/arm/src/stm32wl5/stm32wl5_serial.c | 678 ++++++++++++++++----------------
 1 file changed, 348 insertions(+), 330 deletions(-)

diff --git a/arch/arm/src/stm32wl5/stm32wl5_serial.c 
b/arch/arm/src/stm32wl5/stm32wl5_serial.c
index 31eda4fc60c..467701ddd14 100644
--- a/arch/arm/src/stm32wl5/stm32wl5_serial.c
+++ b/arch/arm/src/stm32wl5/stm32wl5_serial.c
@@ -763,15 +763,27 @@ static void stm32wl5serial_setformat(struct uart_dev_s 
*dev)
   struct stm32_serial_s *priv =
     (struct stm32_serial_s *)dev->priv;
   uint32_t regval;
+  uint32_t cr1_ue;
+  uint32_t usartdiv8;
+  uint32_t cr1;
+  uint32_t brr;
+  irqstate_t flags;
+
+  flags = enter_critical_section();
+
+  /* Disable UE: the baud rate, parity and word length bits can not be
+   * written while UE = 1.
+   */
+
+  regval = stm32wl5serial_getreg(priv, STM32_USART_CR1_OFFSET);
+  cr1_ue = regval & USART_CR1_UE;
+  stm32wl5serial_putreg(priv, STM32_USART_CR1_OFFSET,
+                        regval & ~USART_CR1_UE);
 
   /* This first implementation is for U[S]ARTs that support oversampling
    * by 8 in additional to the standard oversampling by 16.
    */
 
-  uint32_t usartdiv8;
-  uint32_t cr1;
-  uint32_t brr;
-
   if (priv->usartbase == STM32_LPUART1_BASE)
     {
       /* lpuart has different calculations baudrate, and there is not
@@ -907,6 +919,13 @@ static void stm32wl5serial_setformat(struct uart_dev_s 
*dev)
 #endif
 
   stm32wl5serial_putreg(priv, STM32_USART_CR3_OFFSET, regval);
+
+  /* Restore UE */
+
+  regval = stm32wl5serial_getreg(priv, STM32_USART_CR1_OFFSET);
+  stm32wl5serial_putreg(priv, STM32_USART_CR1_OFFSET, regval | cr1_ue);
+
+  leave_critical_section(flags);
 }
 #endif /* CONFIG_SUPPRESS_UART_CONFIG */
 
@@ -1053,7 +1072,9 @@ static void stm32wl5serial_pm_setsuspend(bool suspend)
   /* Already in desired state? */
 
   if (suspend == g_serialpm.serial_suspended)
-    return;
+    {
+      return;
+    }
 
   g_serialpm.serial_suspended = suspend;
 
@@ -1094,25 +1115,25 @@ static void stm32wl5serial_setapbclock(struct 
uart_dev_s *dev, bool on)
 
   switch (priv->usartbase)
     {
-    default:
-      return;
+      default:
+        return;
 #ifdef CONFIG_STM32_LPUART1_SERIALDRIVER
-    case STM32_LPUART1_BASE:
-      rcc_en = RCC_APB1ENR2_LPUART1EN;
-      regaddr = STM32_RCC_APB1ENR2;
-      break;
+      case STM32_LPUART1_BASE:
+        rcc_en  = RCC_APB1ENR2_LPUART1EN;
+        regaddr = STM32_RCC_APB1ENR2;
+        break;
 #endif
 #ifdef CONFIG_STM32_USART1_SERIALDRIVER
-    case STM32_USART1_BASE:
-      rcc_en = RCC_APB2ENR_USART1EN;
-      regaddr = STM32_RCC_APB2ENR;
-      break;
+      case STM32_USART1_BASE:
+        rcc_en  = RCC_APB2ENR_USART1EN;
+        regaddr = STM32_RCC_APB2ENR;
+        break;
 #endif
 #ifdef CONFIG_STM32_USART2_SERIALDRIVER
-    case STM32_USART2_BASE:
-      rcc_en = RCC_APB1ENR1_USART2EN;
-      regaddr = STM32_RCC_APB1ENR1;
-      break;
+      case STM32_USART2_BASE:
+        rcc_en  = RCC_APB1ENR1_USART2EN;
+        regaddr = STM32_RCC_APB1ENR1;
+        break;
 #endif
     }
 
@@ -1502,6 +1523,7 @@ static void stm32wl5serial_detach(struct uart_dev_s *dev)
 {
   struct stm32_serial_s *priv =
     (struct stm32_serial_s *)dev->priv;
+
   up_disable_irq(priv->irq);
   irq_detach(priv->irq);
 }
@@ -1655,371 +1677,365 @@ static int stm32wl5serial_ioctl(struct file *filep, 
int cmd,
   switch (cmd)
     {
 #ifdef CONFIG_SERIAL_TIOCSERGSTRUCT
-    case TIOCSERGSTRUCT:
-      {
-        struct stm32_serial_s *user;
-
-        user = (struct stm32_serial_s *)arg;
+      case TIOCSERGSTRUCT:
+        {
+          struct stm32_serial_s *user = (struct stm32_serial_s *)arg;
 
-        if (!user)
-          {
-            ret = -EINVAL;
-          }
-        else
-          {
-            memcpy(user, dev, sizeof(struct stm32_serial_s));
-          }
-      }
-      break;
+          if (!user)
+            {
+              ret = -EINVAL;
+            }
+          else
+            {
+              memcpy(user, dev, sizeof(struct stm32_serial_s));
+            }
+        }
+        break;
 #endif
 
 #ifdef CONFIG_STM32_USART_SINGLEWIRE
-    case TIOCSSINGLEWIRE:
-      {
-        uint32_t cr1;
-        uint32_t cr1_ue;
-        irqstate_t flags;
-
-        flags = enter_critical_section();
-
-        /* Get the original state of UE */
-
-        cr1    = stm32wl5serial_getreg(priv, STM32_USART_CR1_OFFSET);
-        cr1_ue = cr1 & USART_CR1_UE;
-        cr1   &= ~USART_CR1_UE;
-
-        /* Disable UE, HDSEL can only be written when UE=0 */
-
-        stm32wl5serial_putreg(priv, STM32_USART_CR1_OFFSET, cr1);
+      case TIOCSSINGLEWIRE:
+        {
+          uint32_t cr;
+          uint32_t cr1;
+          uint32_t cr1_ue;
+          uint32_t gpio_val;
+          irqstate_t flags;
 
-        /* Change the TX port to be open-drain/push-pull and enable/disable
-         * half-duplex mode.
-         */
+          flags = enter_critical_section();
 
-        uint32_t cr = stm32wl5serial_getreg(priv, STM32_USART_CR3_OFFSET);
+          /* Get the original state of UE */
 
-        if ((arg & SER_SINGLEWIRE_ENABLED) != 0)
-          {
-            uint32_t gpio_val = GPIO_OPENDRAIN;
+          cr1    = stm32wl5serial_getreg(priv, STM32_USART_CR1_OFFSET);
+          cr1_ue = cr1 & USART_CR1_UE;
+          cr1   &= ~USART_CR1_UE;
 
-            if ((arg & SER_SINGLEWIRE_PULL_MASK) == SER_SINGLEWIRE_PULLUP)
-              {
-                gpio_val |= GPIO_PULLUP;
-              }
-            else
-              {
-                gpio_val |= GPIO_FLOAT;
-              }
+          /* Disable UE, HDSEL can only be written when UE=0 */
 
-            if ((arg & SER_SINGLEWIRE_PULL_MASK) == SER_SINGLEWIRE_PULLDOWN)
-              {
-                gpio_val |= GPIO_PULLDOWN;
-              }
-            else
-              {
-                gpio_val |= GPIO_FLOAT;
-              }
+          stm32wl5serial_putreg(priv, STM32_USART_CR1_OFFSET, cr1);
 
-            if (priv->tx_gpio != 0)
-              {
-                stm32_configgpio((priv->tx_gpio &
-                                     ~(GPIO_PUPD_MASK | GPIO_OPENDRAIN)) |
-                                     gpio_val);
-              }
+          /* Change the TX port to be open-drain/push-pull and enable/disable
+           * half-duplex mode.
+           */
 
-            cr |= USART_CR3_HDSEL;
-          }
-        else
-          {
-            if (priv->tx_gpio != 0)
-              {
-                stm32_configgpio((priv->tx_gpio &
-                                     ~(GPIO_PUPD_MASK | GPIO_OPENDRAIN)) |
-                                     GPIO_PUSHPULL);
-              }
+          cr = stm32wl5serial_getreg(priv, STM32_USART_CR3_OFFSET);
 
-            cr &= ~USART_CR3_HDSEL;
-          }
+          if ((arg & SER_SINGLEWIRE_ENABLED) != 0)
+            {
+              gpio_val = (arg & SER_SINGLEWIRE_PUSHPULL) ==
+                          SER_SINGLEWIRE_PUSHPULL ?
+                          GPIO_PUSHPULL : GPIO_OPENDRAIN;
+              gpio_val |= (arg & SER_SINGLEWIRE_PULL_MASK) ==
+                           SER_SINGLEWIRE_PULLUP ?
+                           GPIO_PULLUP : GPIO_FLOAT;
+              gpio_val |= (arg & SER_SINGLEWIRE_PULL_MASK) ==
+                           SER_SINGLEWIRE_PULLDOWN ?
+                           GPIO_PULLDOWN : GPIO_FLOAT;
+
+              if (priv->tx_gpio != 0)
+                {
+                  stm32_configgpio((priv->tx_gpio & ~(GPIO_PUPD_MASK |
+                                                        GPIO_OPENDRAIN)) |
+                                                        gpio_val);
+                }
+
+              cr |= USART_CR3_HDSEL;
+            }
+          else
+            {
+              if (priv->tx_gpio != 0)
+                {
+                  stm32_configgpio((priv->tx_gpio & ~(GPIO_PUPD_MASK |
+                                                        GPIO_OPENDRAIN)) |
+                                                        GPIO_PUSHPULL);
+                }
+
+              cr &= ~USART_CR3_HDSEL;
+            }
 
-        stm32wl5serial_putreg(priv, STM32_USART_CR3_OFFSET, cr);
+          stm32wl5serial_putreg(priv, STM32_USART_CR3_OFFSET, cr);
 
-        /* Re-enable UE if appropriate */
+          /* Re-enable UE if appropriate */
 
-        stm32wl5serial_putreg(priv, STM32_USART_CR1_OFFSET, cr1 | cr1_ue);
-        leave_critical_section(flags);
-      }
-     break;
+          stm32wl5serial_putreg(priv, STM32_USART_CR1_OFFSET, cr1 | cr1_ue);
+          leave_critical_section(flags);
+        }
+        break;
 #endif
 
 #ifdef CONFIG_STM32_USART_INVERT
-    case TIOCSINVERT:
-      {
-        uint32_t cr1;
-        uint32_t cr1_ue;
-        irqstate_t flags;
+      case TIOCSINVERT:
+        {
+          uint32_t cr;
+          uint32_t cr1;
+          uint32_t cr1_ue;
+          irqstate_t flags;
 
-        flags = enter_critical_section();
+          flags = enter_critical_section();
 
-        /* Get the original state of UE */
+          /* Get the original state of UE */
 
-        cr1    = stm32wl5serial_getreg(priv, STM32_USART_CR1_OFFSET);
-        cr1_ue = cr1 & USART_CR1_UE;
-        cr1   &= ~USART_CR1_UE;
+          cr1    = stm32wl5serial_getreg(priv, STM32_USART_CR1_OFFSET);
+          cr1_ue = cr1 & USART_CR1_UE;
+          cr1   &= ~USART_CR1_UE;
 
-        /* Disable UE, {R,T}XINV can only be written when UE=0 */
+          /* Disable UE, {R,T}XINV can only be written when UE=0 */
 
-        stm32wl5serial_putreg(priv, STM32_USART_CR1_OFFSET, cr1);
+          stm32wl5serial_putreg(priv, STM32_USART_CR1_OFFSET, cr1);
 
-        /* Enable/disable signal inversion. */
+          /* Enable/disable signal inversion. */
 
-        uint32_t cr = stm32wl5serial_getreg(priv, STM32_USART_CR2_OFFSET);
+          cr = stm32wl5serial_getreg(priv, STM32_USART_CR2_OFFSET);
 
-        if (arg & SER_INVERT_ENABLED_RX)
-          {
-            cr |= USART_CR2_RXINV;
-          }
-        else
-          {
-            cr &= ~USART_CR2_RXINV;
-          }
+          if (arg & SER_INVERT_ENABLED_RX)
+            {
+              cr |= USART_CR2_RXINV;
+            }
+          else
+            {
+              cr &= ~USART_CR2_RXINV;
+            }
 
-        if (arg & SER_INVERT_ENABLED_TX)
-          {
-            cr |= USART_CR2_TXINV;
-          }
-        else
-          {
-            cr &= ~USART_CR2_TXINV;
-          }
+          if (arg & SER_INVERT_ENABLED_TX)
+            {
+              cr |= USART_CR2_TXINV;
+            }
+          else
+            {
+              cr &= ~USART_CR2_TXINV;
+            }
 
-        stm32wl5serial_putreg(priv, STM32_USART_CR2_OFFSET, cr);
+          stm32wl5serial_putreg(priv, STM32_USART_CR2_OFFSET, cr);
 
-        /* Re-enable UE if appropriate */
+          /* Re-enable UE if appropriate */
 
-        stm32wl5serial_putreg(priv, STM32_USART_CR1_OFFSET, cr1 | cr1_ue);
-        leave_critical_section(flags);
-      }
-     break;
+          stm32wl5serial_putreg(priv, STM32_USART_CR1_OFFSET, cr1 | cr1_ue);
+          leave_critical_section(flags);
+        }
+        break;
 #endif
 
 #ifdef CONFIG_STM32_USART_SWAP
-    case TIOCSSWAP:
-      {
-        uint32_t cr1;
-        uint32_t cr1_ue;
-        irqstate_t flags;
+      case TIOCSSWAP:
+        {
+          uint32_t cr;
+          uint32_t cr1;
+          uint32_t cr1_ue;
+          irqstate_t flags;
 
-        flags = enter_critical_section();
+          flags = enter_critical_section();
 
-        /* Get the original state of UE */
+          /* Get the original state of UE */
 
-        cr1    = stm32wl5serial_getreg(priv, STM32_USART_CR1_OFFSET);
-        cr1_ue = cr1 & USART_CR1_UE;
-        cr1   &= ~USART_CR1_UE;
+          cr1    = stm32wl5serial_getreg(priv, STM32_USART_CR1_OFFSET);
+          cr1_ue = cr1 & USART_CR1_UE;
+          cr1   &= ~USART_CR1_UE;
 
-        /* Disable UE, SWAP can only be written when UE=0 */
+          /* Disable UE, SWAP can only be written when UE=0 */
 
-        stm32wl5serial_putreg(priv, STM32_USART_CR1_OFFSET, cr1);
+          stm32wl5serial_putreg(priv, STM32_USART_CR1_OFFSET, cr1);
 
-        /* Enable/disable Swap mode. */
+          /* Enable/disable Swap mode. */
 
-        uint32_t cr = stm32wl5serial_getreg(priv, STM32_USART_CR2_OFFSET);
+          cr = stm32wl5serial_getreg(priv, STM32_USART_CR2_OFFSET);
 
-        if (arg == SER_SWAP_ENABLED)
-          {
-            cr |= USART_CR2_SWAP;
-          }
-        else
-          {
-            cr &= ~USART_CR2_SWAP;
-          }
+          if (arg == SER_SWAP_ENABLED)
+            {
+              cr |= USART_CR2_SWAP;
+            }
+          else
+            {
+              cr &= ~USART_CR2_SWAP;
+            }
 
-        stm32wl5serial_putreg(priv, STM32_USART_CR2_OFFSET, cr);
+          stm32wl5serial_putreg(priv, STM32_USART_CR2_OFFSET, cr);
 
-        /* Re-enable UE if appropriate */
+          /* Re-enable UE if appropriate */
 
-        stm32wl5serial_putreg(priv, STM32_USART_CR1_OFFSET, cr1 | cr1_ue);
-        leave_critical_section(flags);
-      }
-     break;
+          stm32wl5serial_putreg(priv, STM32_USART_CR1_OFFSET, cr1 | cr1_ue);
+          leave_critical_section(flags);
+        }
+        break;
 #endif
 
 #ifdef CONFIG_SERIAL_TERMIOS
-    case TCGETS:
-      {
-        struct termios *termiosp = (struct termios *)arg;
-
-        if (!termiosp)
-          {
-            ret = -EINVAL;
-            break;
-          }
+      case TCGETS:
+        {
+          struct termios *termiosp = (struct termios *)arg;
 
-        cfsetispeed(termiosp, priv->baud);
+          if (!termiosp)
+            {
+              ret = -EINVAL;
+              break;
+            }
 
-        /* Note that since we only support 8/9 bit modes and
-         * there is no way to report 9-bit mode, we always claim 8.
-         */
+          /* Note that since we only support 8/9 bit modes and
+           * there is no way to report 9-bit mode, we always claim 8.
+           */
 
-        termiosp->c_cflag =
-          ((priv->parity != 0) ? PARENB : 0) |
-          ((priv->parity == 1) ? PARODD : 0) |
-          ((priv->stopbits2) ? CSTOPB : 0) |
+          termiosp->c_cflag =
+            ((priv->parity != 0) ? PARENB : 0) |
+            ((priv->parity == 1) ? PARODD : 0) |
+            ((priv->stopbits2) ? CSTOPB : 0) |
 #ifdef CONFIG_SERIAL_OFLOWCONTROL
-          ((priv->oflow) ? CCTS_OFLOW : 0) |
+            ((priv->oflow) ? CCTS_OFLOW : 0) |
 #endif
 #ifdef CONFIG_SERIAL_IFLOWCONTROL
-          ((priv->iflow) ? CRTS_IFLOW : 0) |
+            ((priv->iflow) ? CRTS_IFLOW : 0) |
 #endif
-          CS8;
+            CS8;
 
-        /* TODO: CRTS_IFLOW, CCTS_OFLOW */
-      }
-      break;
+          cfsetispeed(termiosp, priv->baud);
 
-    case TCSETS:
-      {
-        struct termios *termiosp = (struct termios *)arg;
+          /* TODO: CRTS_IFLOW, CCTS_OFLOW */
+        }
+        break;
+
+      case TCSETS:
+        {
+          struct termios *termiosp = (struct termios *)arg;
 
-        if (!termiosp)
-          {
-            ret = -EINVAL;
-            break;
-          }
+          if (!termiosp)
+            {
+              ret = -EINVAL;
+              break;
+            }
 
-        /* Perform some sanity checks before accepting any changes */
+          /* Perform some sanity checks before accepting any changes */
 
-        if (((termiosp->c_cflag & CSIZE) != CS8)
+          if (((termiosp->c_cflag & CSIZE) != CS8)
 #ifdef CONFIG_SERIAL_OFLOWCONTROL
-            || ((termiosp->c_cflag & CCTS_OFLOW) && (priv->cts_gpio == 0))
+              || ((termiosp->c_cflag & CCTS_OFLOW) && (priv->cts_gpio == 0))
 #endif
 #ifdef CONFIG_SERIAL_IFLOWCONTROL
-            || ((termiosp->c_cflag & CRTS_IFLOW) && (priv->rts_gpio == 0))
-#endif
-           )
-          {
-            ret = -EINVAL;
-            break;
-          }
-
-        if (termiosp->c_cflag & PARENB)
-          {
-            priv->parity = (termiosp->c_cflag & PARODD) ? 1 : 2;
-          }
-        else
-          {
-            priv->parity = 0;
-          }
-
-        priv->stopbits2 = (termiosp->c_cflag & CSTOPB) != 0;
+              || ((termiosp->c_cflag & CRTS_IFLOW) && (priv->rts_gpio == 0))
+#endif
+             )
+            {
+              ret = -EINVAL;
+              break;
+            }
+
+          if (termiosp->c_cflag & PARENB)
+            {
+              priv->parity = (termiosp->c_cflag & PARODD) ? 1 : 2;
+            }
+          else
+            {
+              priv->parity = 0;
+            }
+
+          priv->stopbits2 = (termiosp->c_cflag & CSTOPB) != 0;
 #ifdef CONFIG_SERIAL_OFLOWCONTROL
-        priv->oflow = (termiosp->c_cflag & CCTS_OFLOW) != 0;
+          priv->oflow = (termiosp->c_cflag & CCTS_OFLOW) != 0;
 #endif
 #ifdef CONFIG_SERIAL_IFLOWCONTROL
-        priv->iflow = (termiosp->c_cflag & CRTS_IFLOW) != 0;
+          priv->iflow = (termiosp->c_cflag & CRTS_IFLOW) != 0;
 #endif
 
-        /* Note that since there is no way to request 9-bit mode
-         * and no way to support 5/6/7-bit modes, we ignore them
-         * all here.
-         */
+          /* Note that since there is no way to request 9-bit mode
+           * and no way to support 5/6/7-bit modes, we ignore them
+           * all here.
+           */
 
-        /* Note that only cfgetispeed is used because we have knowledge
-         * that only one speed is supported.
-         */
+          /* Note that only cfgetispeed is used because we have knowledge
+           * that only one speed is supported.
+           */
 
-        priv->baud = cfgetispeed(termiosp);
+          priv->baud = cfgetispeed(termiosp);
 
-        /* Effect the changes immediately - note that we do not implement
-         * TCSADRAIN / TCSAFLUSH
-         */
+          /* Effect the changes immediately - note that we do not implement
+           * TCSADRAIN / TCSAFLUSH
+           */
 
-        stm32wl5serial_setformat(dev);
-      }
-      break;
+          stm32wl5serial_setformat(dev);
+        }
+        break;
 #endif /* CONFIG_SERIAL_TERMIOS */
 
 #ifdef CONFIG_STM32_USART_BREAKS
 #  ifdef CONFIG_STM32_SERIALBRK_BSDCOMPAT
-    case TIOCSBRK:  /* BSD compatibility: Turn break on, unconditionally */
-      {
-        irqstate_t flags;
+      case TIOCSBRK:  /* BSD compatibility: Turn break on, unconditionally */
+        {
+          uint32_t tx_break;
+          irqstate_t flags;
 
-        flags = enter_critical_section();
+          flags = enter_critical_section();
 
-        /* Disable any further tx activity */
+          /* Disable any further tx activity */
 
-        priv->ie |= USART_CR1_IE_BREAK_INPROGRESS;
+          priv->ie |= USART_CR1_IE_BREAK_INPROGRESS;
 
-        stm32wl5serial_txint(dev, false);
+          stm32wl5serial_txint(dev, false);
 
-        /* Configure TX as a GPIO output pin and Send a break signal */
+          /* Configure TX as a GPIO output pin and Send a break signal */
 
-        if (priv->tx_gpio != 0)
-          {
-            uint32_t tx_break = GPIO_OUTPUT |
-                    (~(GPIO_MODE_MASK | GPIO_OUTPUT_SET) & priv->tx_gpio);
-            stm32_configgpio(tx_break);
-          }
+          if (priv->tx_gpio != 0)
+            {
+              tx_break = GPIO_OUTPUT |
+                         (~(GPIO_MODE_MASK | GPIO_OUTPUT_SET) &
+                          priv->tx_gpio);
+              stm32_configgpio(tx_break);
+            }
 
-        leave_critical_section(flags);
-      }
-      break;
+          leave_critical_section(flags);
+        }
+        break;
 
-    case TIOCCBRK:  /* BSD compatibility: Turn break off, unconditionally */
-      {
-        irqstate_t flags;
+      case TIOCCBRK:  /* BSD compatibility: Turn break off, unconditionally */
+        {
+          irqstate_t flags;
 
-        flags = enter_critical_section();
+          flags = enter_critical_section();
 
-        /* Configure TX back to U(S)ART */
+          /* Configure TX back to U(S)ART */
 
-        if (priv->tx_gpio != 0)
-          {
-            stm32_configgpio(priv->tx_gpio);
-          }
+          if (priv->tx_gpio != 0)
+            {
+              stm32_configgpio(priv->tx_gpio);
+            }
 
-        priv->ie &= ~USART_CR1_IE_BREAK_INPROGRESS;
+          priv->ie &= ~USART_CR1_IE_BREAK_INPROGRESS;
 
-        /* Enable further tx activity */
+          /* Enable further tx activity */
 
-        stm32wl5serial_txint(dev, true);
+          stm32wl5serial_txint(dev, true);
 
-        leave_critical_section(flags);
-      }
-      break;
+          leave_critical_section(flags);
+        }
+        break;
 #  else
-    case TIOCSBRK:  /* No BSD compatibility: Turn break on for M bit times */
-      {
-        uint32_t cr1;
-        irqstate_t flags;
-
-        flags = enter_critical_section();
-        cr1   = stm32wl5serial_getreg(priv, STM32_USART_CR1_OFFSET);
-        stm32wl5serial_putreg(priv, STM32_USART_CR1_OFFSET,
-                             cr1 | USART_CR1_SBK);
-        leave_critical_section(flags);
-      }
-      break;
-
-    case TIOCCBRK:  /* No BSD compatibility: May turn off break too soon */
-      {
-        uint32_t cr1;
-        irqstate_t flags;
-
-        flags = enter_critical_section();
-        cr1   = stm32wl5serial_getreg(priv, STM32_USART_CR1_OFFSET);
-        stm32wl5serial_putreg(priv, STM32_USART_CR1_OFFSET,
-                             cr1 & ~USART_CR1_SBK);
-        leave_critical_section(flags);
-      }
-      break;
+      case TIOCSBRK:  /* No BSD compatibility: Turn break on for M bit times */
+        {
+          uint32_t cr1;
+          irqstate_t flags;
+
+          flags = enter_critical_section();
+          cr1   = stm32wl5serial_getreg(priv, STM32_USART_CR1_OFFSET);
+          stm32wl5serial_putreg(priv, STM32_USART_CR1_OFFSET,
+                              cr1 | USART_CR1_SBK);
+          leave_critical_section(flags);
+        }
+        break;
+
+      case TIOCCBRK:  /* No BSD compatibility: May turn off break too soon */
+        {
+          uint32_t cr1;
+          irqstate_t flags;
+
+          flags = enter_critical_section();
+          cr1   = stm32wl5serial_getreg(priv, STM32_USART_CR1_OFFSET);
+          stm32wl5serial_putreg(priv, STM32_USART_CR1_OFFSET,
+                              cr1 & ~USART_CR1_SBK);
+          leave_critical_section(flags);
+        }
+        break;
 #  endif
 #endif
 
-    default:
-      ret = -ENOTTY;
-      break;
+      default:
+        ret = -ENOTTY;
+        break;
     }
 
   return ret;
@@ -2723,62 +2739,64 @@ static int stm32wl5serial_pmprepare(struct 
pm_callback_s *cb, int domain,
 
   switch (pmstate)
     {
-    case PM_NORMAL:
-    case PM_IDLE:
-      break;
-
-    case PM_STANDBY:
-    case PM_SLEEP:
+      case PM_NORMAL:
+      case PM_IDLE:
+        break;
 
+      case PM_STANDBY:
+      case PM_SLEEP:
+        {
 #ifdef SERIAL_HAVE_DMA
-      /* Flush Rx DMA buffers before checking state of serial device
-       * buffers.
-       */
+          /* Flush Rx DMA buffers before checking state of serial device
+           * buffers.
+           */
 
-      stm32_serial_dma_poll();
+          stm32_serial_dma_poll();
 #endif
 
-      /* Check if any of the active ports have data pending on Tx/Rx
-       * buffers.
-       */
-
-      for (n = 0; n < STM32_NLPUART + STM32_NUSART; n++)
-        {
-          struct stm32_serial_s *priv = g_uart_devs[n];
+          /* Check if any of the active ports have data pending on Tx/Rx
+           * buffers.
+           */
 
-          if (!priv || !priv->initialized)
+          for (n = 0; n < STM32_NLPUART + STM32_NUSART; n++)
             {
-              /* Not active, skip. */
+              struct stm32_serial_s *priv = g_uart_devs[n];
 
-              continue;
-            }
+              if (!priv || !priv->initialized)
+                {
+                  /* Not active, skip. */
 
-          if (priv->suspended)
-            {
-              /* Port already suspended, skip. */
+                  continue;
+                }
 
-              continue;
-            }
+              if (priv->suspended)
+                {
+                  /* Port already suspended, skip. */
 
-          /* Check if port has data pending (Rx & Tx). */
+                  continue;
+                }
 
-          if (priv->dev.xmit.head != priv->dev.xmit.tail)
-            {
-              return ERROR;
-            }
+              /* Check if port has data pending (Rx & Tx). */
 
-          if (priv->dev.recv.head != priv->dev.recv.tail)
-            {
-              return ERROR;
+              if (priv->dev.xmit.head != priv->dev.xmit.tail)
+                {
+                  return ERROR;
+                }
+
+              if (priv->dev.recv.head != priv->dev.recv.tail)
+                {
+                  return ERROR;
+                }
             }
+
+          break;
         }
-      break;
 
-    default:
+      default:
 
-      /* Should not get here */
+        /* Should not get here */
 
-      break;
+        break;
     }
 
   return OK;
@@ -2921,9 +2939,9 @@ void arm_serialinit(void)
 #ifdef SERIAL_HAVE_DMA
 void stm32_serial_dma_poll(void)
 {
-    irqstate_t flags;
+  irqstate_t flags;
 
-    flags = enter_critical_section();
+  flags = enter_critical_section();
 
 #ifdef CONFIG_LPUART1_RXDMA
   if (g_lpuart1priv.rxdma != NULL)

Reply via email to