Skip to main content
Visitor II
January 12, 2026
Solved

Blue Pill: Drive a Stepper Motor Using STM32CubeMX and a Stepper Driver?

  • January 12, 2026
  • 2 replies
  • 579 views

Hi everyone,

I'm currently working on a project involving a stepper motor controlled by an STM32 microcontroller, and I wanted to share a quick overview of how I set it up using STM32CubeMX.

Hardware:
STM32F103C8T6 (Blue Pill)
Stepper Motor (28BYJ-48)
Stepper Motor Driver (ULN2003 or A4988)
Steps I Followed:
STM32CubeMX Configuration:

Created a new project for my STM32 board.
Enabled GPIO outputs for the control pins connected to the driver.
Set up a Timer for delays or PWM (if using A4988).
Generated code with HAL libraries.
Coding in STM32CubeIDE:

Wrote a simple function to send step pulses and direction signals.
For A4988, I toggled the STEP pin with a delay and used the DIR pin to control direction.
For ULN2003, I used a stepping sequence on 4 GPIO pins.
Testing:

Got the motor running with basic forward and reverse motion.
Planning to implement acceleration profiles and microstepping next.
Let me know if anyone needs sample code or has tips on improving the motion control. Also, is anyone using FreeRTOS with stepper motors?

Best answer by Andrew Neil

Note that Blue Pill is not an ST product, and likely does not contain a genuine STM32 microcontroller.

 

2 replies

Andrew Neil
Andrew NeilBest answer
Super User
January 12, 2026

Note that Blue Pill is not an ST product, and likely does not contain a genuine STM32 microcontroller.

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
AScha.3
Super User
January 12, 2026

The board is not by ST , like the majority of customer boards.

But the cpu is STM32 ...otherwise he would complain about st-link not connecting or debug not working.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Visitor II
April 24, 2026

Hey, nice project !
I've been wondering if I could use the HAL library to do that.


Do you want / can you share the code you use ?

Thanks

Mathis