Skip to content

arch/arm/src/stm32n6: disable the USART while changing the line format - #21380

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
Swatantra-66:fix/stm32n6-serial-setformat-ue
Nov 3, 2026
Merged

xiaoxiang781216 merged 1 commit into
apache:masterfrom
Swatantra-66:fix/stm32n6-serial-setformat-ue

Conversation

@Swatantra-66

Copy link
Copy Markdown
Contributor

Summary

Fixes #21377

In arch/arm/src/stm32n6/stm32_serial.c, stm32serial_setformat() writes the baud rate register (BRR), CR2 STOP bits, and the parity/word length bits (PCE, PS, M0, M1) in CR1 while the USART is enabled (UE = 1).

Per the ST Reference Manual (RM0486), these registers/bits are write-protected and can only be written when the USART is disabled (UE = 0). Consequently, run-time tcsetattr() calls attempting to change baud rate, parity, or word length return success (0) while leaving the hardware USART registers unchanged.

This patch clears USART_CR1_UE before the update and restores it upon completion inside a critical section, aligning the STM32N6 serial driver with the approved implementations in:

Also fixes pre-existing nxstyle case indentation issues in stm32serial_ioctl() and a comment typo in stm32serial_rxint().

Impact

  • Is new feature added? No
  • Impact on user: Bug fix. Runtime tcsetattr() calls to change serial line speed, parity, or format on STM32N6 now correctly reconfigure the hardware USART peripheral instead of silently failing.
  • Impact on build: None.
  • Impact on hardware: STM32N6 (Cortex-M55) series boards.
  • Impact on documentation: None.
  • Impact on security: None.
  • Impact on compatibility: Fully backwards compatible.

Testing

Verified code logic against ST Reference Manual RM0486. Built cleanly. Verified nxstyle compliance.

xiaoxiang781216
xiaoxiang781216 previously approved these changes Nov 2, 2026
@github-actions github-actions Bot added Arch: arm Issues related to ARM (32-bit) architecture Size: M The size of the change in this PR is medium labels Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

stm32serial_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 (RM0486), 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 47180bf), STM32WB (PR apache#21334),
STM32WL5 (PR apache#21336), STM32H7, and F7 implementations.

Also fix pre-existing nxstyle alignment, declaration, and brace issues
in stm32serial_pm_setsuspend, stm32serial_setapbclock, stm32serial_detach,
stm32serial_interrupt, stm32serial_ioctl, and stm32serial_pmprepare.

Fixes apache#21377

Signed-off-by: Swatantra Yadav <[email protected]>
Assisted-by: Google Gemini
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm Issues related to ARM (32-bit) architecture Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] arch/arm/stm32n6: USART hardware format and baud rate changes silently ignored at runtime (UE not disabled)

3 participants