Skip to content

Conversation

@tpambor
Copy link
Contributor

@tpambor tpambor commented Dec 17, 2025

This PR introduces a PWM driver for the STM32 low-power timer (LPTIM) peripheral on STM32 MCUs.

This driver is loosely based on the PWM driver for standard timers on STM32. For maintainability and readability, I split this into a new driver instead of integrating with the existing STM PWM driver, as the supported features differ and LPTIMs use a different low-level API LL_LPTIM_*.

Fixes #57316.

@zephyrbot zephyrbot added area: LED Label to identify LED subsystem area: Boards/SoCs area: PWM Pulse Width Modulation labels Dec 17, 2025
@github-actions
Copy link

github-actions bot commented Dec 17, 2025

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff

All manifest checks OK

Note: This message is automatically posted and updated by the Manifest GitHub Action.

Copy link
Contributor

@gautierg-st gautierg-st left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. Driver side looks ok to me.
As I said in one comment, a pwm child node should be added in the lptim nodes of the dtsi, like it is done for the timers nodes. This will require some minor changes to the driver and the overlay.
And make that 3 commits:

  • Driver
  • Dtsi update
  • Tests/samples

return 0;
}

#define PWM(index) DT_DRV_INST(index)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, LPTIM PWM driver should be as close as possible to TIM PWM driver. So there should be a pwm child node to the lptim instances in the dtsi files.
And this line, like it's done in the TIM PWM driver, should be

Suggested change
#define PWM(index) DT_DRV_INST(index)
#define PWM(index) DT_INST_PARENT(index)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally agree, but this would require major refactoring and introduce breaking changes. The current top-level st,stm32-lptim binding is tailored specifically for using LPTIM as a system tick source. Therefore, I see the following steps:

  1. Introduce a new top-level binding: st,stm32-lptimers, essentially based on st,stm32-lptim but without the tick-source-specific st,timeout property.
  2. Add a new binding for tick source functionality and include it as a subnode within LPTIM instances.
  3. Update the current LPTIM tick source driver to align with the new structure.
  4. Update samples and tests to reflect these changes.
  5. Update the binding of this PWM driver so that it can be added as a subnode to LPTIM instances that support PWM.
  6. Update this PWM driver

All users using LPTIM as systick source would then need to update their device tree to adapt to these changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I didn't have the full picture in mind.
Even though it's a lot more work, I still think it's a better way to go. Changing the compatible value of a node doesn't seem like a good idea for readability and maintenance.
Besides, it's better if the dtsi can describe all available features.
And this could also be used to add support for other potential features of the LPTIM in the future.
But before diving into it, let's have other opinions: @erwango, @etienne-lms ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduce a new top-level binding: st,stm32-lptimers, essentially based on st,stm32-lptim but without the tick-source-specific st,timeout property.

Why is that? I must be missing something, the property is not required, so just don't use it in the PWM driver.

Add a PWM driver for the STM32 low-power timer (LPTIM) peripheral
on STM32 MCUs.

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
Add overlay and update sample.yaml to include stm32h573i_dk board.

This board can utilize LPTIM5 for PWM generation to drive the
red (LD3) LED.

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
@github-actions github-actions bot removed manifest manifest-hal_stm32 DNM (manifest) This PR should not be merged (controlled by action-manifest) labels Dec 20, 2025
@sonarqubecloud
Copy link


&lptim5 {
compatible = "st,stm32-lptim-pwm";
clocks = <&rcc STM32_CLOCK(APB3, 14)>,
Copy link
Contributor

@JarmouniA JarmouniA Dec 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no point in inventing another compatible for the same hw device (

compatible = "st,stm32-lptim";
) just to use it with another driver class.
Add a child PWM node and use it with the PWM driver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Boards/SoCs area: Devicetree Bindings area: LED Label to identify LED subsystem area: PWM Pulse Width Modulation area: Samples Samples platform: STM32 ST Micro STM32

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lptim pwm support for stm32

6 participants