An Overview of how PWM pins are allocated on STM32F4


This port of RRF uses a combination of Hardware and Software PWM control.

Hardware PWM

Each hardware timer can handle up to four pins. If more than one pin maps to a timer then the 2nd,3rd.4th can only use hardware PWM if the frequency matches. The hardware PWM is only allocated the first time that PWM is actually needed (so essentially the first time that an output is set to something that is not full on/off).

Software PWM

If it doesn’t use the same frequecy, it will instead be controlled as a software PWM. There are a maximum of 16 software PWM channels.
Software PWM uses a single 1MHz timer. Software PWM uses MCU resources and does not work well for higher PWM frequencies. Anything above about 4KHz will have a reduction in the resolution and there is a minium delta (which is complicated, but basically means that any pulse that has an on time or off time of less than 20uS will be set to just full off/on). This mainly impacts higher frequencies.

Current Limitations

The hardware of the STM32 MCU limits which pins can be used with which timers. At the moment, this port has a limitation that means we have to pre-allocate the pins to a timer, so basically there is only one timer for each pin. It is planned for the future that we will be able to remove that restriction, but it is there at the moment.

Pin Timer Classification

Pin Number Timer
PA_0 Timer 2
PA_1 Timer 2
PA_15 Timer 2
PA_2 Timer 2
PA_3 Timer 2
PA_5 Timer 8
PA_6 Timer 13
PA_7 Timer 14
PB_0 Timer 3
PB_1 Timer 3
PB_10 Timer 2
PB_11 Timer 2
PB_14 Timer 12
PB_15 Timer 8
PB_3 Timer 2
PB_4 Timer 3
PB_5 Timer 3
PB_6 Timer 4
PB_7 Timer 4
PB_8 Timer 10
PB_9 Timer 11
PC_6 Timer 8
PC_7 Timer 3
PC_8 Timer 8
PC_9 Timer 8
PD_12 Timer 4
PD_13 Timer 4
PD_14 Timer 4
PD_15 Timer 4
PE_5 Timer 9
PE_6 Timer 9
PF_6 Timer 10
PF_7 Timer 11
PF_8 Timer 13
PF_9 Timer 14
PH_6 Timer 12
PI_5 Timer 8
PI_6 Timer 8