Repository navigation
arch/arm/src/stm32wl5: disable the USART while changing the line format - #21336
Merged
xiaoxiang781216 merged 1 commit intoNov 2, 2026
Merged
Conversation
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 47180bf), STM32WB (PR apache#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
Swatantra-66
requested review from
hartmannathan and
xiaoxiang781216
as code owners
November 1, 2026 19:19
|
acassis
approved these changes
Nov 1, 2026
xiaoxiang781216
approved these changes
Nov 2, 2026
Swatantra-66
added a commit
to Swatantra-66/nuttx
that referenced
this pull request
Nov 2, 2026
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
xiaoxiang781216
pushed a commit
that referenced
this pull request
Nov 3, 2026
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 #21334), STM32WL5 (PR #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 #21377 Signed-off-by: Swatantra Yadav <[email protected]> Assisted-by: Google Gemini
Swatantra-66
added a commit
to Swatantra-66/nuttx
that referenced
this pull request
Nov 3, 2026
In stm32serial_setformat(), BRR, CR2 STOP bits, and the PCE, PS, and M0/M1 bits of CR1 were modified with the USART enabled. Per the ST Reference Manuals (e.g., RM0456 for STM32H5, RM0454 for STM32U5, RM0438 for STM32L5, and RM0481 for STM32C5), these registers and bits can only be written while UE = 0. Modifying them while UE = 1 is ignored by the hardware, so a run-time tcsetattr() call attempting to change baud rate, parity, or word length returned success while leaving the hardware USART registers unchanged. Clear UE before updating the line configuration and restore it afterwards inside a critical section, aligning stm32_serial_m33_v3.c with the approved implementations in STM32N6 (commit 2b1b82c), STM32WL5 (PR apache#21336), STM32WB (PR apache#21334), and STM32L4 (commit 47180bf). Signed-off-by: Swatantra Yadav <[email protected]> Assisted-by: Google Gemini
xiaoxiang781216
pushed a commit
that referenced
this pull request
Nov 4, 2026
In stm32serial_setformat(), BRR, CR2 STOP bits, and the PCE, PS, and M0/M1 bits of CR1 were modified with the USART enabled. Per the ST Reference Manuals (e.g., RM0456 for STM32H5, RM0454 for STM32U5, RM0438 for STM32L5, and RM0481 for STM32C5), these registers and bits can only be written while UE = 0. Modifying them while UE = 1 is ignored by the hardware, so a run-time tcsetattr() call attempting to change baud rate, parity, or word length returned success while leaving the hardware USART registers unchanged. Clear UE before updating the line configuration and restore it afterwards inside a critical section, aligning stm32_serial_m33_v3.c with the approved implementations in STM32N6 (commit 2b1b82c), STM32WL5 (PR #21336), STM32WB (PR #21334), and STM32L4 (commit 47180bf). Signed-off-by: Swatantra Yadav <[email protected]> Assisted-by: Google Gemini
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In
arch/arm/src/stm32wl5/stm32wl5_serial.c,stm32wl5serial_setformat()writes the baud rate register (BRR),CR2STOP bits, and the parity/word length bits (PCE,PS,M0,M1) inCR1while the USART is enabled (UE = 1).Per ST Reference Manual RM0453 (STM32WL5x) Section 31.8 / 32.8, these bits are write-protected and can only be written when the USART is disabled (
UE = 0). Consequently, run-timetcsetattr()calls attempting to change baud rate, parity, or word length return success while leaving the hardware USART registers unchanged.Clears
USART_CR1_UEbefore the update and restores it upon completion inside a critical section, aligning the STM32WL5 driver with the approved implementations in STM32L4 (commit 47180bf), STM32WB (PR #21334), STM32H7, and F7.Also fixes pre-existing
nxstylealignment, declaration, and brace issues instm32wl5serial_ioctl,stm32wl5serial_setapbclock,stm32wl5serial_detach,stm32wl5serial_pm_suspend,stm32wl5serial_pm_prepare, andstm32_serial_dma_poll.Impact
arch/arm/src/stm32wl5/stm32wl5_serial.c.tcsetattr(). 100%nxstylecompliant across the file.Testing
nxstylecompliance with NuttX's officialnxstyletool across all 3,008 lines (0 errors, 0 warnings).