Posts

Showing posts from November, 2022

STM32 GPIO PWM Simple Example for Blackpill/Bluepill dev board

Image
 STM32 GPIO PWM Simple Example   Arduino hardware and Arduino IDE can easily let GPIO pin to work on PWM mode, simplyuse analogWrite() , ie analogWrite (pin, 128); simple and easy.   Unfortunately STM32F### hardware and STM32CubeIDE need quite a lot more work to achieve this. Here is some simple steps to let STM32F401 or STM32F103 to set GPIO to work on PWM mode on the fly, as simple as I can make it to be.  To be able to see the GPIO pins's PWM signal, a oscilloscope is needed, but any cheap one should work, including those 30$ low cost ones. 😜 Certain multi-meter can see pwm frequency and PWM % as well, but we cannot see the wave form. Choose the Right Pin and Timer. STM32 Pin PWM mode requires TIMER to support it.  We must choose the pin(s) or timer carefully, certain pins only work with certain timer; certain timer can only work with certain pins. That means, if our project uses a Timer for other purpose, then certain pins cannot be used for PWM.  How Many PWM GPIO Pins do we