In the "normal" STM32 timers, when set to one of the PWM modes, if TIM_CCRx = 0, corresponding output is at one steady state, and if TIM_CCRx >= TIM_ARR + 1, output is at the other steady state. TIM_CCRx values in between 1..TIM_ARR correspond to pulse lengths of 1..TIM_ARR, while the PWM period is (TIM_ARR + 1).
LPTIM works differently.
Values of LPTIM_CMP between 0..(LPTIM_ARR - 1) correspond to pulse lengths of 1..LPTIM_ARR while the PWM period is (LPTIM_ARR + 1) 1. It is prohibited to set LPTIM_CMP to or above LPTIM_ARR.
This means, that steady states cannot be achieved by setting purely LPTIM_CMP. This may come as an unpleasant surprise for those, who expect LPTIM PWM to be used as a direct replacement for TIM PWM.
There are several workarounds available:
- when steady state is required, set the given pin's corresponding GPIO_MODER field to GPIO_Out, with the respective bit in GPIO_ODR providing the required output level.
Set it back to GPIO_AlternateFunction when PWM is required.
- use the Set-once mode of LPTIM by setting LPTIM_CFGR.WAVE when steady state is required (and clearing it when PWM is required). After initial delay given by LPTIM_CMP value (possibly set to 0), the output level is steady state as long as LPTIM_CFGR.WAVE is set. Polarity of output can be changed using LPTIM_CFGR.WAVPOL bit: if set to 0, output steady-state level is 1; and vice versa.