-
Notifications
You must be signed in to change notification settings - Fork 8.2k
drivers: serial: stm32: Refactor for PM handling #59406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
fb06a37 to
106171f
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ok generally.
The only point is the use of new struct in the device const config struct while in theory runtime updatable parameters should go in data struct.
a7f533b to
b27e59c
Compare
|
b27e59c to
0b8a3e4
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments about the datawidth check, otherwise looks good
0b8a3e4 to
0f56e5e
Compare
|
#54354 has been merged. Please rebase |
Move select include directives from source to header file, as these pull data types required by the struct definitions contained within it. This promotes a more modular file structure. Signed-off-by: Kenneth J. Miller <[email protected]>
Move reset configuration from uart_stm32_data to const uart_stm32_config struct, as this is set once at boot and isn't modified during runtime. Signed-off-by: Kenneth J. Miller <[email protected]>
Add static uart_config struct to init macro with corresponding pointer as uart_stm32_config struct member. This struct will store boot and runtime UART configuration for reinitialization upon exiting low-power modes, where register contents might be lost. Remove hw_flow_control, parity, and baud_rate from uart_stm32_config and uart_stm32_data structs, respectively, as the need for these is now obviated by the presence of the uart_config struct, which contains equivalent members. Add default baudrate, parity, stop, and data bits constants, used to initialize the uart_config struct, in case the corresponding UART DT properties are not set. Signed-off-by: Kenneth J. Miller <[email protected]>
Move clock enable and register configuration to their own functions in preparation for later uart_stm32_reinit function that will use these in addition to uart_stm32_init. Signed-off-by: Kenneth J. Miller <[email protected]>
Move overlapping UART parameter configuration to new uart_stm32_parameters_set function. This function is called by uart_stm32_configure upon application/subsystem configuration, and uart_stm32_registers_configure upon (re-)initialization of driver instances. Signed-off-by: Kenneth J. Miller <[email protected]>
Replace incorrect and limited runtime parity/data bits conditional configuration with build-time logic using BUILD_ASSERT. This allows for more flexible UART configurations, while preventing invalid DTS configurations at build-time. Signed-off-by: Kenneth J. Miller <[email protected]>
0f56e5e to
c1297a7
Compare
|
Summary
This PR refactors the initialization/configuration logic of STM32 UART driver. It is intended to complement PR #59200 by making reinitialization of the peripheral clocks and registers more straightforward, for when the SoC loses their context and contents in certain low-power modes.
In refactoring I've also stumbled on a few bugs that I've fixed.
uart_configstruct toSTM32_UART_INITmacrouart_configstruct pointer asuart_stm32_configmemberbaud_rate,parity, andhw_flow_controlstruct membersuart_configstructBUILD_ASSERTstatementsinitforced a very small subset of UART configurations, and straight-up ignored many valid DT property combinations (e.g 7E1)uart_stm32_configure, especially that relating to parity/data-bits combinations, where either enforced opposite configurations#if defined(LL_USART_STOPBITS_1_5) && HAS_LPUART_1conditional broke "half-bit" parity application configurations of USARTs, this is now fixedChange Description
Add static uart_config struct to init macro with corresponding pointer as uart_stm32_config struct member. This struct will store boot and runtime UART configuration for reinitialization upon exiting low-power modes, where register contents might be lost.
Remove hw_flow_control, parity, and baud_rate from uart_stm32_config and uart_stm32_data structs, respectively, as the need for these is now obviated by the presence of the uart_config struct, which contains equivalent members.
Add default baudrate, parity, stop, and data bits constants, used to initialize the uart_config struct, in case the corresponding UART DT properties are not set.
Move overlapping UART parameter configuration to new uart_stm32_parameters_set function. This function is called by uart_stm32_configure upon application/subsystem configuration, and uart_stm32_registers_configure upon (re-)initialization of driver instances.
Fix flawed stop bit/LPUART conditionals, which didn't allow for 0.5/1.5 stop bit USART configurations via application uart_configure syscalls.
Replace incorrect and limited runtime parity/data bits conditional configuration with build-time logic using BUILD_ASSERT. This allows for more flexible UART configurations, while preventing invalid DTS configurations at build-time.
Issues Closed by this PR
Related Issues or Pull Requests