Repository navigation
arch/arm/stm32: fix UE handling in stm32_serial_m3m4 setformat for F3/G4 - #21894
Merged
Merged
Conversation
Wooohaaa
requested review from
hartmannathan,
raiden00pl and
xiaoxiang781216
as code owners
November 16, 2026 16:04
xiaoxiang781216
previously approved these changes
Nov 16, 2026
|
Contributor
|
@Wooohaaa please rebase your patch to the last master and fix style issue: |
Contributor
|
Please see #21903 |
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 (apache#20914) and WB (apache#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 apache#20969 Signed-off-by: Wooohaaa <[email protected]>
Wooohaaa
force-pushed
the
fix/stm32f3g4-setformat-ue
branch
from
November 23, 2026 13:12
8434236 to
ad02cc4
Compare
xiaoxiang781216
approved these changes
Nov 23, 2026
GUIDINGLI
approved these changes
Nov 24, 2026
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
up_set_format()instm32_serial_m3m4_v1v2v3v4.chad two problemsfor the F3 and G4 families:
F3 (F30XX/F33XX/F37XX): UE was never cleared, so
tcsetattr(8E1)returned 0 but the parity and word length did notchange.
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.
Change
arch/arm/src/common/stm32/stm32_serial_m3m4_v1v2v3v4.c:saving).
pattern.
OR-ing UE|TE|RE).
Test plan
nucleo-f334r8:nsh(F3) andnucleo-g431rb:nsh(G4) witharm-none-eabi-gcc; the serial driver compiles cleanly for both.
#ifconditions, so F1/F2/F4/L1boards are unaffected.
Fixes #20969