Arm Mbed OS support forum

Creating an unused PwmOut object breaks rest of program

Hello,

I am writing a simple program for the STM Bluepill chip and am using this diagram for the pinout
image

I am trying to use a pwm pin for motor control. Certain pwm pin choices appear to break the entire program for no apparent reason. This is a problem since I have limited pins remaining since I plan to use them for other things. For example, if I define PwmOut test(PB_6); and strip the rest of my program down to just a serial print statement and a blinking LED it will not work, the LED goes haywire and no serial output.

If I switch the pin to a digital out or pick certain other pins (PA_0) works for example, this issue does not appear. I think this eliminates any potential memory issues. I suspected there might be interference with serial which could explain not getting any serial output, but I added the LED blinking as a second debug output.

Is there something I am missing with PWM outputs that could be causing this?

Is your desired pin set to be PWM in your targets PeripheralPins.c file? That would be a good place to look first. You could also try running a software pwm library to simulate pwm using tickers rather than hardware timers.

This is a SoftPwm library I use: https://os.mbed.com/users/pattyolanterns/code/mbed-soft-pwm/