Repository navigation
arch/stm32: unify LPTIM drivers - #21138
Merged
xiaoxiang781216 merged 11 commits intoOct 31, 2026
Merged
Conversation
raiden00pl
requested review from
Ouss4,
davids5,
gustavonihei,
hartmannathan,
jerpelea,
simbit18 and
xiaoxiang781216
as code owners
October 29, 2026 18:48
acassis
previously approved these changes
Oct 29, 2026
|
xiaoxiang781216
previously approved these changes
Oct 30, 2026
Only the STM32L4 PWM driver supports LPTIM PWM and it is the only user of the LPTIM clock source choice. Offer both only where they are used. Signed-off-by: raiden00pl <[email protected]> Assisted-by: Claude Code
Add the missing blank lines after declarations before the file moves to common/stm32. Signed-off-by: raiden00pl <[email protected]> Assisted-by: Claude Code
Move the STM32H5 LPTIM driver and its register header to common/stm32 and use it on STM32H7 instead of the local copy. The RCC clock enable and reset bits of each instance come from stm32_lptim_clk.h, detected from the family RCC definitions like stm32_tim_clk.h does for TIM. The ARR and CMP write wait of the STM32H5 driver is kept for STM32_HAVE_IP_LPTIM_V2 only, the STM32H7 driver had none. deinit() clears the RCC clock enable bit, the STM32H7 driver cleared the bit in the sleep mode clock enable register. Signed-off-by: raiden00pl <[email protected]> Assisted-by: Claude Code
Add the timer operations of the STM32L4 LPTIM API to the common driver: setmode, setclock, setchannel, setclocksource, setpolarity, setcountmode and getperiod. init() resets the timer and fails for an instance in use, start() takes stm32_lptim_mode_t. Signed-off-by: raiden00pl <[email protected]> Assisted-by: Claude Code
Use the common LPTIM driver for all STM32 families and remove the STM32L4 copy and its register header. The LPTIM register layout is described by two IP versions taken from the reference SVD files: - STM32_HAVE_IP_LPTIM_V1: IER and CMP, optional OR, CFGR2 and RCR (F4, F7, G0, G4, H7, L0, L4, L5, WB, WL5) - STM32_HAVE_IP_LPTIM_V2: DIER and capture/compare channels (C5, H5, H7RS, N6, U0, U3, U5) The interrupt and the base address of each instance come from the family headers, the RCC bits from stm32_lptim_clk.h. Changes compared to the old drivers: - setclocksource() selects the external or the internal clock only, the kernel clock is selected by the RCC configuration as on STM32F7. The STM32L4 driver also wrote RCC_CCIPR. - setchannel() configures the board GPIO_LPTIMn_CHkOUT pins like the STM32L4 PWM driver, instead of the GPIO_LPTIMn_OUT_k pinmap alternatives. - STM32H5 LPTIM2 builds, STM32_LPTIM2_BASE was missing the _BASE suffix. The STM32F7 LPTIM1 interrupt is renamed to STM32_IRQ_LPTIM1 as on the other families and the STM32U5 APB3RSTR LPTIM reset bits are added. Signed-off-by: raiden00pl <[email protected]> Assisted-by: Claude Code
The common LPTIM driver works on every STM32 with an LPTIM, so select the LPTIM instances available on each chip. The instances are taken from the reference SVD files and checked against the ST CMSIS device headers (the STM32G070 SVD file lists LPTIM1/2, but the device has no LPTIM): - STM32C5: LPTIM1 - STM32F410: LPTIM1 - STM32G0: LPTIM1-2, except G030, G050, G070 and G0B0 - STM32H5: LPTIM1-2, LPTIM3-6 on H56x/H57x only - STM32H7: LPTIM1-5, LPTIM1-3 on H7A3/H7B0/H7B3 - STM32L0: LPTIM1 - STM32L5: LPTIM1-3 - STM32N6: LPTIM1-5 - STM32U3: LPTIM1-4 - STM32U5: LPTIM2 added - STM32WB: LPTIM2 added - STM32WL5: LPTIM1-3 STM32_LPTIM2 and STM32_LPTIM5 depend on the STM32_HAVE_LPTIMn flags instead of chip lists and STM32_LPTIM6 is added. The missing STM32F410 LPTIM1 base address, interrupt and RCC bits and the STM32N6 RCC APB4L registers and LPTIM bits are added. Signed-off-by: raiden00pl <[email protected]> Assisted-by: Claude Code
ackint() wrote ICR only. On STM32H7 LPTIM2-5 the write had not taken effect when the interrupt returned, so every event was taken twice. Read ISR back after the write. Signed-off-by: raiden00pl <[email protected]> Assisted-by: Claude Code
LPTIM1 is clocked from MSIK (CCIPR3 LPTIM1SEL reset value), not HCLK, and LPTIM1 cannot select HCLK at all. MSIK runs at 4 MHz on this board. Signed-off-by: raiden00pl <[email protected]> Assisted-by: Claude Code
With -finstrument-functions (ARMV7M_STACKCHECK) each CNT read took longer than one count, so the getcounter() double read never matched and hung. Signed-off-by: raiden00pl <[email protected]> Assisted-by: Claude Code
LPTIM1 runs on PCLK1 and LPTIM2-5 on PCLK4, the reset values of the RCC_D2CCIP2R and RCC_D3CCIPR LPTIM source selections. Signed-off-by: raiden00pl <[email protected]> Assisted-by: Claude Code
raiden00pl
force-pushed
the
stm32_refactor_all-lptim
branch
from
October 30, 2026 08:01
555b23b to
a17acbf
Compare
jerpelea
previously approved these changes
Oct 30, 2026
Contributor
|
@raiden00pl thanks for the cleanup |
Contributor
|
@raiden00pl please fix style issue. |
LPTIM V2 DIER must only be modified while the timer is enabled and the write completes with DIEROK. Enable the timer for the write if needed, which fixes a restarted LPTIM timer on STM32C5 never firing. Signed-off-by: raiden00pl <[email protected]> Assisted-by: Claude Code
raiden00pl
dismissed stale reviews from jerpelea and xiaoxiang781216
via
October 30, 2026 12:10
3afb875
raiden00pl
force-pushed
the
stm32_refactor_all-lptim
branch
from
October 30, 2026 12:10
a17acbf to
3afb875
Compare
xiaoxiang781216
approved these changes
Oct 30, 2026
1 task done
simbit18
approved these changes
Oct 31, 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
unify LPTIM drivers for STM32
Impact
remove duplicated drivers
Testing
Verified on HW: