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

GUIDINGLI 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 a60e7a3af4b arch/arm/stm32: fix UE handling in stm32_serial_m3m4 
setformat for F3/G4
a60e7a3af4b is described below

commit a60e7a3af4b55eca861594bcd4c3e8061d49d50b
Author: Wooohaaa <[email protected]>
AuthorDate: Tue Nov 17 00:03:28 2026 +0800

    arch/arm/stm32: fix UE handling in stm32_serial_m3m4 setformat for F3/G4
    
    On USART v2 and later, the parity and word-length bits in CR1 (PCE, PS,
    M0/M1) can only be written while UE = 0. The up_set_format() function
    in stm32_serial_m3m4_v1v2v3v4.c had two problems for the F3 and G4
    families:
    
    1. F3 (F30XX/F33XX/F37XX): UE was never cleared, so tcsetattr(8E1)
       returned 0 but the parity and word length did not change.
    
    2. G4 (STM32G4XXX): UE|TE|RE were cleared but the original values were
       not saved. At the end, UE|TE|RE were unconditionally OR-ed back,
       which would incorrectly set them to 1 even if they were originally 0.
    
    Follow the pattern from the L4 (#20914) and WB (#21334) drivers: enter a
    critical section, save and clear UE, configure the format bits, then
    restore UE. Only UE is saved/cleared/restored; TE|RE are left unchanged
    (the L4 fix does the same).
    
    Built nucleo-f334r8:nsh and nucleo-g431rb:nsh with arm-none-eabi-gcc;
    the serial driver compiles cleanly for both. Not tested on hardware.
    
    Assisted-by: OpenCode:DeepSeek-V4.1-Flash
    
    Fixes #20969
    
    Signed-off-by: Wooohaaa <[email protected]>
---
 .../src/common/stm32/stm32_serial_m3m4_v1v2v3v4.c  | 543 +++++++++++----------
 1 file changed, 285 insertions(+), 258 deletions(-)

diff --git a/arch/arm/src/common/stm32/stm32_serial_m3m4_v1v2v3v4.c 
b/arch/arm/src/common/stm32/stm32_serial_m3m4_v1v2v3v4.c
index 01db9584eaf..f86bbbc5674 100644
--- a/arch/arm/src/common/stm32/stm32_serial_m3m4_v1v2v3v4.c
+++ b/arch/arm/src/common/stm32/stm32_serial_m3m4_v1v2v3v4.c
@@ -1556,13 +1556,26 @@ static void up_set_format(struct uart_dev_s *dev)
 #endif
   uint32_t regval;
   uint32_t brr;
+#if defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F33XX) || \
+    defined(CONFIG_STM32_STM32F37XX) || defined(CONFIG_STM32_STM32G4XXX)
+  uint32_t cr1_ue;
+  irqstate_t flags;
+#endif
 
   /* Load CR1 */
 
   regval = up_serialin(priv, STM32_USART_CR1_OFFSET);
 
-#if defined(CONFIG_STM32_STM32G4XXX)
-  regval &= ~(USART_CR1_UE | USART_CR1_TE | USART_CR1_RE);
+#if defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F33XX) || \
+    defined(CONFIG_STM32_STM32F37XX) || defined(CONFIG_STM32_STM32G4XXX)
+
+  /* Disable UE: the parity and word-length bits in CR1 can not be
+   * written while UE = 1.
+   */
+
+  flags = enter_critical_section();
+  cr1_ue = regval & USART_CR1_UE;
+  regval &= ~USART_CR1_UE;
   up_serialout(priv, STM32_USART_CR1_OFFSET, regval);
 #endif
 #if defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F33XX)|| \
@@ -1832,10 +1845,16 @@ static void up_set_format(struct uart_dev_s *dev)
 #endif
 
   up_serialout(priv, STM32_USART_CR3_OFFSET, regval);
-#if defined(CONFIG_STM32_STM32G4XXX)
-  regval      = up_serialin(priv, STM32_USART_CR1_OFFSET);
-  regval     |= (USART_CR1_UE | USART_CR1_TE | USART_CR1_RE);
+#if defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F33XX) || \
+    defined(CONFIG_STM32_STM32F37XX) || defined(CONFIG_STM32_STM32G4XXX)
+
+  /* Restore UE */
+
+  regval = up_serialin(priv, STM32_USART_CR1_OFFSET);
+  regval |= cr1_ue;
   up_serialout(priv, STM32_USART_CR1_OFFSET, regval);
+
+  leave_critical_section(flags);
 #endif
 }
 #endif /* CONFIG_SUPPRESS_UART_CONFIG */
@@ -1862,61 +1881,61 @@ static void up_set_apb_clock(struct uart_dev_s *dev, 
bool on)
 
   switch (priv->usartbase)
     {
-    default:
-      return;
+      default:
+        return;
 #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_APB1ENR_USART2EN;
-      regaddr = STM32_RCC_APB1ENR;
-      break;
+      case STM32_USART2_BASE:
+        rcc_en = RCC_APB1ENR_USART2EN;
+        regaddr = STM32_RCC_APB1ENR;
+        break;
 #endif
 #ifdef CONFIG_STM32_USART3_SERIALDRIVER
-    case STM32_USART3_BASE:
-      rcc_en = RCC_APB1ENR_USART3EN;
-      regaddr = STM32_RCC_APB1ENR;
-      break;
+      case STM32_USART3_BASE:
+        rcc_en = RCC_APB1ENR_USART3EN;
+        regaddr = STM32_RCC_APB1ENR;
+        break;
 #endif
 #ifdef CONFIG_STM32_UART4_SERIALDRIVER
-    case STM32_UART4_BASE:
-      rcc_en = RCC_APB1ENR_UART4EN;
-      regaddr = STM32_RCC_APB1ENR;
-      break;
+      case STM32_UART4_BASE:
+        rcc_en = RCC_APB1ENR_UART4EN;
+        regaddr = STM32_RCC_APB1ENR;
+        break;
 #endif
 #ifdef CONFIG_STM32_UART5_SERIALDRIVER
-    case STM32_UART5_BASE:
-      rcc_en = RCC_APB1ENR_UART5EN;
-      regaddr = STM32_RCC_APB1ENR;
-      break;
+      case STM32_UART5_BASE:
+        rcc_en = RCC_APB1ENR_UART5EN;
+        regaddr = STM32_RCC_APB1ENR;
+        break;
 #endif
 #ifdef CONFIG_STM32_USART6_SERIALDRIVER
-    case STM32_USART6_BASE:
-      rcc_en = RCC_APB2ENR_USART6EN;
-      regaddr = STM32_RCC_APB2ENR;
-      break;
+      case STM32_USART6_BASE:
+        rcc_en = RCC_APB2ENR_USART6EN;
+        regaddr = STM32_RCC_APB2ENR;
+        break;
 #endif
 #ifdef CONFIG_STM32_UART7_SERIALDRIVER
-    case STM32_UART7_BASE:
-      rcc_en = RCC_APB1ENR_UART7EN;
-      regaddr = STM32_RCC_APB1ENR;
-      break;
+      case STM32_UART7_BASE:
+        rcc_en = RCC_APB1ENR_UART7EN;
+        regaddr = STM32_RCC_APB1ENR;
+        break;
 #endif
 #ifdef CONFIG_STM32_UART8_SERIALDRIVER
-    case STM32_UART8_BASE:
-      rcc_en = RCC_APB1ENR_UART8EN;
-      regaddr = STM32_RCC_APB1ENR;
-      break;
+      case STM32_UART8_BASE:
+        rcc_en = RCC_APB1ENR_UART8EN;
+        regaddr = STM32_RCC_APB1ENR;
+        break;
 #endif
 #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
     }
 
@@ -2321,6 +2340,7 @@ static int up_attach(struct uart_dev_s *dev)
 static void up_detach(struct uart_dev_s *dev)
 {
   struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
+
   up_disable_irq(priv->irq);
   irq_detach(priv->irq);
 }
@@ -2506,283 +2526,288 @@ static int up_ioctl(struct file *filep, int cmd, 
unsigned long arg)
   switch (cmd)
     {
 #ifdef CONFIG_SERIAL_TIOCSERGSTRUCT
-    case TIOCSERGSTRUCT:
-      {
-        struct up_dev_s *user = (struct up_dev_s *)arg;
-        if (!user)
-          {
-            ret = -EINVAL;
-          }
-        else
-          {
-            memcpy(user, dev, sizeof(struct up_dev_s));
-          }
-      }
-      break;
+      case TIOCSERGSTRUCT:
+        {
+          struct up_dev_s *user = (struct up_dev_s *)arg;
+
+          if (!user)
+            {
+              ret = -EINVAL;
+            }
+          else
+            {
+              memcpy(user, dev, sizeof(struct up_dev_s));
+            }
+        }
+        break;
 #endif
 
 #ifdef CONFIG_SERIAL_TIOCGICOUNT
-    /* Get U(S)ART error counters */
+      /* Get U(S)ART error counters */
 
-    case TIOCGICOUNT:
-      {
-        struct serial_icounter_s *icount = (struct serial_icounter_s *)arg;
-        if (icount == NULL)
-          {
-            ret = -EINVAL;
-          }
-        else
-          {
-            memcpy(icount, &priv->icount, sizeof(struct serial_icounter_s));
-          }
-      }
-      break;
+      case TIOCGICOUNT:
+        {
+          struct serial_icounter_s *icount = (struct serial_icounter_s *)arg;
+
+          if (icount == NULL)
+            {
+              ret = -EINVAL;
+            }
+          else
+            {
+              memcpy(icount, &priv->icount,
+                     sizeof(struct serial_icounter_s));
+            }
+        }
+        break;
 #endif
 
 #ifdef CONFIG_STM32_USART_SINGLEWIRE
-    case TIOCSSINGLEWIRE:
-      {
-        /* Change the TX port to be open-drain/push-pull and enable/disable
-         * half-duplex mode.
-         */
+      case TIOCSSINGLEWIRE:
+        {
+          /* Change the TX port to be open-drain/push-pull and enable/disable
+           * half-duplex mode.
+           */
 
-        uint32_t cr = up_serialin(priv, STM32_USART_CR3_OFFSET);
+          uint32_t cr = up_serialin(priv, STM32_USART_CR3_OFFSET);
 
 #if defined(CONFIG_STM32_STM32F10XX)
-        if ((arg & SER_SINGLEWIRE_ENABLED) != 0)
-          {
-            if (priv->tx_gpio != 0)
-              {
-                stm32_configgpio((priv->tx_gpio & ~(GPIO_CNF_MASK)) |
-                                 GPIO_CNF_AFOD);
-              }
-
-            cr |= USART_CR3_HDSEL;
-          }
-        else
-          {
-            if (priv->tx_gpio != 0)
-              {
-                stm32_configgpio((priv->tx_gpio & ~(GPIO_CNF_MASK)) |
-                                 GPIO_CNF_AFPP);
-              }
-
-            cr &= ~USART_CR3_HDSEL;
-          }
+          if ((arg & SER_SINGLEWIRE_ENABLED) != 0)
+            {
+              if (priv->tx_gpio != 0)
+                {
+                  stm32_configgpio((priv->tx_gpio & ~(GPIO_CNF_MASK)) |
+                                   GPIO_CNF_AFOD);
+                }
+
+              cr |= USART_CR3_HDSEL;
+            }
+          else
+            {
+              if (priv->tx_gpio != 0)
+                {
+                  stm32_configgpio((priv->tx_gpio & ~(GPIO_CNF_MASK)) |
+                                   GPIO_CNF_AFPP);
+                }
+
+              cr &= ~USART_CR3_HDSEL;
+            }
 #else
-        if ((arg & SER_SINGLEWIRE_ENABLED) != 0)
-          {
-            uint32_t 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
+          if ((arg & SER_SINGLEWIRE_ENABLED) != 0)
+            {
+              uint32_t 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;
-            if (priv->tx_gpio != 0)
-              {
-                stm32_configgpio((priv->tx_gpio & ~(GPIO_PUPD_MASK |
-                                                    GPIO_OPENDRAIN)) |
-                                 gpio_val);
-              }
+              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;
+            }
+#endif
+
+          up_serialout(priv, STM32_USART_CR3_OFFSET, cr);
+        }
+        break;
+#endif
 
-            cr |= USART_CR3_HDSEL;
-          }
-        else
-          {
-            if (priv->tx_gpio != 0)
-              {
-                stm32_configgpio((priv->tx_gpio & ~(GPIO_PUPD_MASK |
-                                                    GPIO_OPENDRAIN)) |
-                                 GPIO_PUSHPULL);
-              }
+#ifdef CONFIG_SERIAL_TERMIOS
+      case TCGETS:
+        {
+          struct termios *termiosp = (struct termios *)arg;
 
-            cr &= ~USART_CR3_HDSEL;
-          }
-#endif
+          if (!termiosp)
+            {
+              ret = -EINVAL;
+              break;
+            }
 
-        up_serialout(priv, STM32_USART_CR3_OFFSET, cr);
-      }
-     break;
-#endif
+          /* Note that since we only support 8/9 bit modes and
+           * there is no way to report 9-bit mode, we always claim 8.
+           */
 
-#ifdef CONFIG_SERIAL_TERMIOS
-    case TCGETS:
-      {
-        struct termios *termiosp = (struct termios *)arg;
-
-        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.
-         */
-
-        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;
 
-        cfsetispeed(termiosp, priv->baud);
+          cfsetispeed(termiosp, priv->baud);
 
-        /* TODO: CRTS_IFLOW, CCTS_OFLOW */
-      }
-      break;
+          /* TODO: CRTS_IFLOW, CCTS_OFLOW */
+        }
+        break;
 
-    case TCSETS:
-      {
-        struct termios *termiosp = (struct termios *)arg;
+      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
+           */
 
-        up_set_format(dev);
-      }
-      break;
+          up_set_format(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 */
+        {
+          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;
 
-        up_txint(dev, false);
+          up_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)
+            {
+              uint32_t tx_break = GPIO_OUTPUT |
+                      (~(GPIO_MODE_MASK | GPIO_OUTPUT_SET) &
+                       priv->tx_gpio);
 
-        leave_critical_section(flags);
-      }
-      break;
+              stm32_configgpio(tx_break);
+            }
 
-    case TIOCCBRK:  /* BSD compatibility: Turn break off, unconditionally */
-      {
-        irqstate_t flags;
+          leave_critical_section(flags);
+        }
+        break;
+
+      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 */
 
-        up_txint(dev, true);
+          up_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;
+      case TIOCSBRK:  /* No BSD compatibility: Turn break on for M bit times */
+        {
+          uint32_t cr1;
+          irqstate_t flags;
 
-        flags = enter_critical_section();
-        cr1   = up_serialin(priv, STM32_USART_CR1_OFFSET);
-        up_serialout(priv, STM32_USART_CR1_OFFSET, cr1 | USART_CR1_SBK);
-        leave_critical_section(flags);
-      }
-      break;
+          flags = enter_critical_section();
+          cr1   = up_serialin(priv, STM32_USART_CR1_OFFSET);
+          up_serialout(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;
+      case TIOCCBRK:  /* No BSD compatibility: May turn off break too soon */
+        {
+          uint32_t cr1;
+          irqstate_t flags;
 
-        flags = enter_critical_section();
-        cr1   = up_serialin(priv, STM32_USART_CR1_OFFSET);
-        up_serialout(priv, STM32_USART_CR1_OFFSET, cr1 & ~USART_CR1_SBK);
-        leave_critical_section(flags);
-      }
-      break;
+          flags = enter_critical_section();
+          cr1   = up_serialin(priv, STM32_USART_CR1_OFFSET);
+          up_serialout(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;
@@ -2889,6 +2914,7 @@ static void up_rxint(struct uart_dev_s *dev, bool enable)
 static bool up_rxavailable(struct uart_dev_s *dev)
 {
   struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
+
   return ((up_serialin(priv, STM32_USART_SR_OFFSET) & USART_SR_RXNE) != 0);
 }
 #endif
@@ -3307,6 +3333,7 @@ static void up_txint(struct uart_dev_s *dev, bool enable)
 static bool up_txready(struct uart_dev_s *dev)
 {
   struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
+
   return ((up_serialin(priv, STM32_USART_SR_OFFSET) & USART_SR_TXE) != 0);
 }
 
@@ -3639,9 +3666,9 @@ void arm_serialinit(void)
 #ifdef SERIAL_HAVE_RXDMA
 void stm32_serial_dma_poll(void)
 {
-    irqstate_t flags;
+  irqstate_t flags;
 
-    flags = enter_critical_section();
+  flags = enter_critical_section();
 
 #ifdef CONFIG_USART1_RXDMA
   if (g_usart1priv.rxdma != NULL)

Reply via email to