Arm Mbed OS support forum

PwmOut initial value

I’m suprised to find out that the PwmOut constructor does not have an initial value argument.

I have this use case where I want to keep an LED turned on during the transition from the bootloader to the application. Currently, since the PwmOut is initialized with 0 duty cycle, an annoying flicker is visible before the duty cycle is set to its correct value in the application.

I think this could be added to the PwmOut API in a non-breaking way with C++ default arguments. The question is how to implement this for all supported targets. Is it possible to indicate that an API is only available for some targets?

That’s an interesting use case!

Have you tried fixing the issue for your target as you suggested?

Yes, technically this is possible. Tested on an STM32 target.

At least it is possible to make it fast enough that it is not visible to my eyes :slight_smile:

then I suggest making a PR for mbed-core to review and discuss how to enable for other targets.

afaik the initial period time for the PwmOut is 20 ms, compatible with rc servos. That was already default for grandpa LPC1768 in mbed-OS2.
But a constructor with period and duty sounds good, it can be set to the old defaults when not provided.