Field-Oriented Control (FOC) on STM32 From Scratch – Practical BLDC Motor Control

Published at : 23 Dec 2025

In this video, we walk you through a complete hands-on implementation of Field-Oriented Control (FOC) for a BLDC motor using the STM32 microcontroller — from scratch.
You'll learn how to build an efficient and responsive motor control system without relying on high-level libraries. We cover the theory behind FOC, sensor integration (e.g. AS5047 encoder), current sampling, Clarke and Park transforms, SVPWM generation, and real-time tuning using USB CDC.
Tools & Frameworks:
• STM32 (STM32F407)
• DRV8302 gate driver
• AS5047 magnetic encoder
• PlatformIO & FreeRTOS
• STM32 HAL & LL drivers

Hardware & Firmware:
https://github.com/sirojudinMunir/stm32-FOC

Software used in this video:
• Altium Designer
• STM32CubeMx
• VS Code

Music track: Avocado by Pufino
Source: https://freetouse.com/music
Royalty Free Music (Free Download)

Chapters:

00:00 - 01:37 - FOC Explanation
01:38 - 02:43 - Hardware Implementation
02:44 - 04:47 - STM32CubeMX Settings
04:48 - 05:34 - Center Align PWM
05:35 - 07:11 - Magnetic Encoder & Offset Calibration
07:12 - 09:14 - Current sensor & Current Control