6 years, 7 months ago.

GPIO configuration wrong

If PA_2 have no PWM function, but I use PwmOut to config the GPIO , such as PwmOut (PA_2). I found the compiler is successful, but I download Bin file to my NUCLEO-L073 board, my board is not working normally. if I change PA_2 to PA_0(PWM port),it word normally. why ?

PwmOut only works on certain pins. You'll have to dig into the source files for your target. For ST parts there is a file called PeripheralPins.c for each target with a const array/table called PinMap_PWM[]. When you choose a pin like PA_2, the PwmOut class looks up your pin in this table and uses that information to configure the hardware. Also be sure you are watching mbed debug messages on a terminal program. When something like this fails (like if that pin doesn’t support PWM) mbed usually gives you a hint as to why it failed. Also certain pins on certain devboards are by default used for a different function and you will not be able to configure them as pwmout even if micro hardware supports it. It is possible to override this behavior by making sure the correct entry is in the PinMap_PWM table.

You can see here PA_2 has been commented out by default. Looks like PA_2 is used for stdio debug messages. You should probably choose a different pwm output. https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/PeripheralPins.c

posted by Graham S. 25 Sep 2017
Be the first to answer this question.