Stepper library


Purpose


CubeMX

1) PWM

NOTE: If you are new to PWM, first take a look at Example PWM generation, it is more in depth

afbeelding.png

For each stepper, enable pwm on channel 1. This is done by setting Clock Source = Internal Clock and Channel 1 = PWM Generation CH1.

NOTE: Each pwm output for each stepper needs a separate timer. Right now, it is hardcoded that PWM uses Channel 1, so only use Channel 1!

The following parameters are important:

2) DMA

Now, you have to set up the DMA for the same timer/channel. This is in the DMA settings tab.

afbeelding.png

Set the following parameters:

3) GPIO pins

Set 2 pins to GPIO_Output by clicking on them in the CubeMX UI. One of these will be used for the direction pin and another for the enable pin.

//TODO: add driver resource

4) Clock Configuration

For PWM it really doesn't matter at what speed you set the clock. The only thing that matters is that the prescalar is set to the same amount. So if your clock speed is 72, set it to 72-1, if your clock speed is 84, set it to 84-1.



Code

1) Public Methods

2) Private Methods

3) Example


Resources

  1. Controllerstech: STM32 PWM Output: Generate PWM Signal with & without DMA




Revision #9
Created 2026-04-14 08:57:13 UTC by Lisa te Braak
Updated 2026-05-25 19:39:56 UTC by Lisa te Braak