2026-06-04 5:52 AM
I'm working on a device with an STM32L072CZT. It uses Channels 1, 3, and 4 of TIM2 to generate PWM signals that control LED drivers. The LEDs blink in predetermined patterns, so the PWM is periodically switched on and off, using LL_TIM_CC_EnableChannel and LL_TIM_CC_DisableChannel, respectively.
A few weeks ago, I made some required changes to the code, but had to put finalizing off because of other priorities. Today I picked it up again, and to my astonishment, the PWM outputs behaved completely wrong. Instead of seeing PWM - 0 - PWM - 0 - ..., I saw PWM - 1 - PWM - 1 - ... In other words, rather than off, the LEDs go fully on!
The exact same code in two other devices works as expected, so the fault is not in the firmware. I am seeing PWM, so the GPIOs are OK.
So, apparently, this particular chip has somehow been damaged in such a way that the PWM logic is broken? I find that kind of hard to believe.
Has anybody ever come across something similar? Can somebody from ST maybe shed some light on this?
2026-06-04 6:01 AM
LL_TIM_CC_DisableChannel() clears the respective TIMx_CCER.CCxE bit, and that sets the respective pin to Hi-Z.
So, it depends on your hardware, how will this behave.
JW
2026-06-04 6:13 AM - edited 2026-06-04 6:17 AM
@waclawek.jan wrote:[...] that sets the respective pin to Hi-Z.
Can you point me to a reference, because I could not find anything in the RM that states this. The ports are configured as push-pull, so I can hardly imagine this to be the case.
Anyhow, it works on dozens of devices, including the one where it now doesn't work anymore. Also, the PWM signals all have a pull-down.
2026-06-04 7:19 AM - edited 2026-06-04 7:20 AM
No, I don't have a direct reference.
Generally, this belongs to a group of issues which stem from the SoC character of the STM32, i.e. that they are assembled from modules. Consequence for documentation is, that the relationship between modules is poorly described in the RM (this demonstrates itself in many ways, e.g. incosistent signals naming, poor or no description of some of the interconnects, "Interconnections" chapter in RM is an afterthought missing for older families, etc.).
In this particular case, the thing is, that modules which control GPIO (in their AF mode) usually control in some way also the output-enable signal (i.e. the one which makes the pin Hi-Z). This is especially so for peripheral ports, which can be "turned" - in this case, all TIMx_CHx can be "turned" i.e. used either as input (if you set given channel as Input Capture) or output (if it's set as Output Compare). Input Capture essentially means, that the pin has to be Hi-Z, so the control is already there. And it is easy to test, that in Output Compare setting it *is* controlled by the TIMx_CCER.CCxE bit (and/or CCxNE, where applicable).
There's another indication for this, too, but not in the 'L0xx RMs - for Advanced Timers (and there's none in 'L0xx) there's a Output control bits for complementary OCx and OCxN channels with break feature table, from which it's quite obvious that cleared CCxE/CCxNE means HiZ AF pin.
---
> Also, the PWM signals all have a pull-down.
External? And connected so that it ensures the LED will be OFF?
Well, at any case, in debugger, stop the mcu when LED is in the unexpected 1 state, and measure + read out relevant GPIO and TIM registers content and check/post.
JW
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.