How davidmolony/mesc_firmware works
MESC Firmware is an embedded BLDC field-oriented-control (FOC) motor-control project for STM32 targets. Its principal runtime is motor firmware initialization, followed by acquisition of motor measurements and closed-loop control that drives the inverter; the README documents sensorless, HFI, encoder and Hall sensing, plus torque, speed and duty modes. Shared control code is paired with target-specific hardware and several RTOS interfaces. The excerpts show shared data structures, target setup and one target’s peripheral configuration, but not the complete control loop or interface dispatch, so those links are left unverified. Major README capabilities are retained without asserting unsampled call paths.
Main entry points: MESCfoc.c FOC controller · main.c Target firmware entry · MESCmotor_state.h Motor state machine · apps.c RTOS app registry
Components 21
Motor control
- FOC controller
MESC_Common/Src/MESCfoc.c - Motor state machine
MESC_RTOS/AXIS/MESCmotor_state.h - Motor initialization
MESC_Common/Src/MESCmotor.c - BLDC commutation
MESC_Common/Src/MESCBLDC.c - PWM generation
MESC_Common/Src/MESCpwm.c - Sine and inductance lookup
MESC_Common/Src/MESCsin_lut.c
Sensing and safety
- ADC measurements
MESC_Common/Inc/MESCBLDC.h - Position observers
MESC_Common/Src/MESCfluxobs.c - HFI sensing
MESC_Common/Src/MESChfi.c - Thermal limits
MESC_Common/Src/MESCtemp.c - Fault handling
MESC_Common/Src/MESCerror.c
STM32 platforms
- Target firmware entry
MESC_F405RG/Core/Src/main.c - Hardware setup
MESC_Common/Inc/MESChw_setup.h - F405 target peripherals
MESC_F405RG/Core/Src/main.c
User interfaces
- RTOS app registry
MESC_RTOS/Tasks/apps.c - RTOS task setup
MESC_RTOS/Tasks/init.h - Axis interface
MESC_RTOS/AXIS/MESCinterface.c - Dashboard interface
MESC_RTOS/Dash/MESCinterface.c - MESC interface
MESC_RTOS/MESC/MESCinterface.c - Terminal
MESC_RTOS/TTerm/Core/TTerm.c
Other components
- Operator or host
Connections 22
- Target firmware entry → Motor initialization: initializes
MESC_F405RG/Core/Src/main.c - Target firmware entry → Thermal limits: uses
MESC_F405RG/Core/Src/main.c - Target firmware entry → Motor state machine: uses
MESC_F405RG/Core/Src/main.c - Target firmware entry → RTOS task setup: starts tasks
MESC_F405RG/Core/Src/main.c - Target firmware entry → F405 target peripherals: configures peripherals
MESC_F405RG/Core/Src/main.c - Hardware setup → FOC controller: configures
MESC_Common/Inc/MESChw_setup.h - ADC measurements → FOC controller: provides samples
- FOC controller → PWM generation: sets modulation
- Motor state machine → FOC controller: selects control mode
- FOC controller → Sine and inductance lookup: uses lookup
- FOC controller → Position observers: uses estimates
- FOC controller → HFI sensing: supports HFI
- FOC controller → Thermal limits: thermal rollback
- FOC controller → Fault handling: reports faults
- Operator or host → Axis interface: sends commands
- Operator or host → Dashboard interface: sends commands
- Operator or host → MESC interface: sends commands
- RTOS task setup → RTOS app registry: registers apps
MESC_RTOS/Tasks/init.h - RTOS app registry → Terminal: uses terminal
- Axis interface → FOC controller: commands control
- Dashboard interface → FOC controller: commands control
- MESC interface → FOC controller: commands control