DEV Community

Cover image for Build a $29 Open-Source STM32F405 FOC Driver for BLDC Motors
circuitrocks
circuitrocks

Posted on Originally published at blog.circuit.rocks

Build a $29 Open-Source STM32F405 FOC Driver for BLDC Motors

Three chips do most of the work in a field-oriented control driver, and Sirojudin Munir's new SF-Motion board picks good ones: an STMicroelectronics STM32F405 for the math, a Texas Instruments DRV8323RH gate driver for the three-phase bridge, and a TI INA240A1 to read phase current. Add an AS5047 magnetic encoder for rotor position and the control loop is complete. Munir priced the bill of materials at about $28.58 from LCSC, PCB and assembly not included, which puts a proper FOC driver well under the cost of most off-the-shelf boards.

A second attempt, not a first

Munir had already built an FOC driver once. That one took several rounds of trial and error before it behaved, so rather than patch it he started over with a fresh schematic, a reworked current-sensing section, new firmware, and a different communication scheme. The part he singles out as most improved is current sensing, which is exactly the section most homebrew FOC drivers get wrong.

Everything is open. The KiCad hardware files and the firmware sit on GitHub under the MIT license, along with a client-side package for calibration and tuning. A permissive license on a motor driver is rare enough to be worth noting.

Why an F405 and not something smaller

Field-oriented control holds the stator field at 90 degrees to the rotor field, which is where the smooth torque and high efficiency come from. Holding that angle means running Clarke and Park transforms plus a pair of PI loops on every PWM cycle, typically at 20 kHz or faster. The STM32F405 carries a hardware floating-point unit, so those transforms run in single-precision float instead of hand-tuned fixed point. Its ADC handles the current sense, its advanced timers generate complementary PWM for the inverter, and SPI talks to the magnetic encoder. USB and CAN sit on the same die, so a bench link and a robot bus both come free.

The DRV8323RH earns its place twice over: it drives the six MOSFETs of the inverter and also acts as the buck regulator for the logic rail, which removes a whole cluster of parts from the board.

If you want to build one

Read the design walkthrough on Munir's video and the full write-up at Hackster, then pull the KiCad project before ordering a thing. Shunt placement and gate-drive layout decide whether this works, more than the parts list does. For a first FOC build, order the PCB assembled, keep a current-limited supply on the bench, and start the motor unloaded. A miswired half-bridge fails loudly and expensively. Gimbal motors and 2204-size BLDCs are the friendly starting point, and you can pick them up along with the connectors and encoders at Circuit.Rocks.


Originally published on blog.circuit.rocks.

robotics #robots #engineering #stem #circuitrocks

Top comments (0)