Using zig and the STM32H7 to drive stepper motors

May 09, 2020


Finally got stepper motors working with the STM32H7 and DRV8825 using ziglang!


The TI DRV8825 just takes step and direction signals. The code design is based on the TeensyStep project. The step signals are controlled by timers, it supports multiple motors, and custom acceleration profiles (the standard trapezoidal one is used here).


So it's nothing new or fancy, except it's written in pure Zig! By pure, I literally mean 100% zig. There is ZERO C anywhere in the project! No STM32 SDK/HAL, no Arduino, no mbed-os, no cimport, nothing except zig (well... zig and a linker script)!





While it took a really long time (I ported most of of the stm32h7 hal by hand), I'm really impressed by how well zig works. Zig is actually fun to code in compared to C/C++! Having error handling in an embedded system is extremely helpful.


Hats off to the Zig project! Keep it up!