How omar-magdy0/forgedrive works
Purpose and Build Targets
EcoDrive is a C/C++ PMSM inverter-control platform for EV use, supporting Field-Oriented Control (FOC), self-commissioning, telemetry, and host-side simulation. It has two primary executable domains: firmware/simulation in EcoDrive/main.cpp and a desktop communication/tooling application in EcoTool/EcoTool.cpp. CMake target definitions are rooted per application: EcoDrive/CMakeLists.txt and EcoTool/CMakeLists.txt.
Control Application and Mode Dispatch
EcoDrive/PmsmControl/PmsmControl.h exposes the motor-control application layer; EcoDrive/PmsmControl/PmsmControl.cpp integrates it with the system. Shared control states, signals, and configuration are concentrated in EcoDrive/PmsmControl/PmsmControlTypes.h and EcoDrive/PmsmControl/PmsmControlConf.h. The controller selects operational behavior such as safe idle, FOC, and self-commissioning rather than exposing platform drivers directly to application logic.
Real-Time Motor-Control Core
EcoDrive/PmsmControl/PmsmControlCore.h / EcoDrive/PmsmControl/PmsmControlCore.cpp form the common execution core. FOC-specific processing is isolated in EcoDrive/PmsmControl/PmsmControlCore_Foc.cpp, corresponding to the fast PWM-rate path described in the README: sampling currents/voltage, frame transforms, current regulation, and PWM duty generation. This is the critical real-time boundary: control code consumes normalized measurements and produces inverter commands through platform abstractions.
Commissioning and Position Feedback
Self-commissioning is separated from normal closed-loop control in EcoDrive/PmsmControl/PmsmControlCore_SComm.cpp and EcoDrive/PmsmControl/PmsmControlCore_SComm.h; this encapsulates HFI-based motor parameter identification. Rotor position acquisition is abstracted by EcoDrive/PmsmControl/PosDriver.h and implemented in EcoDrive/PmsmControl/PosDriver.cpp, preventing FOC/SComm logic from depending on a particular Hall or hardware timer implementation.
Platform Boundary: Host SIL vs STM32F4
EcoDrive/platform/host/platform.cpp provides the native-host runtime, including software-in-the-loop support represented by EcoDrive/platform/host/sil.h; host motor/Hall models are present in EcoDrive/platform/host/el_mc3p.cpp and EcoDrive/platform/host/el_hall.cpp. EcoDrive/platform/stm32f4/platform.c is the embedded counterpart. Platform-specific CMake selection files (EcoDrive/platform/host/platform.cmake, EcoDrive/platform/stm32f4/platform.cmake) are the build-time boundary that lets common control code target x86 simulation or STM32F4 hardware.
Communications, DAQ, and Desktop Tool
The reusable middleware layer implements binary framing and data acquisition: ecolib/middleware/ABFStream.h, ecolib/middleware/DAQStream.h, and ecolib/middleware/DAQCodec.h. It sits between control/DAQ producers and transport drivers. Host transports include TCP, UART, USB CDC, and USB exchange under ecolib/driver/host/; STM32 equivalents are under ecolib/driver/stm32f4/. EcoTool/EcoTool.cpp, with EcoTool/Serial.hpp and EcoTool/TcpClient.hpp, is the PC-side consumer/controller for device sessions. The repository also vendors STM32 HAL/CMSIS, CMSIS-DSP, ImGui/ImPlot, and Catch2; external runtime interaction is primarily physical motor/inverter I/O plus USB-CDC, UART, and TCP rather than cloud services.
Main entry points: PmsmControlCore.cpp Common control core · CMakeLists.txt EcoDrive build target · PmsmControl.cpp Control application · ABFStream.h ABF and DAQ middleware
Components 18
Motor Control
- EcoDrive entry
EcoDrive/main.cpp - EcoDrive build target
EcoDrive/CMakeLists.txt - Control application · Selects safe idle, FOC, and self-commissioning modes.
EcoDrive/PmsmControl/PmsmControl.cpp - Control state & config
EcoDrive/PmsmControl/PmsmControlTypes.h - Common control core · Consumes normalized measurements and produces inverter commands.
EcoDrive/PmsmControl/PmsmControlCore.cpp - FOC fast path · Sampling, transforms, current regulation, and PWM duty generation.
EcoDrive/PmsmControl/PmsmControlCore_Foc.cpp - Self-commissioning
EcoDrive/PmsmControl/PmsmControlCore_SComm.cpp - Position driver
EcoDrive/PmsmControl/PosDriver.cpp
Runtime Platforms
- Host platform selection
EcoDrive/platform/host/platform.cmake - STM32F4 platform selection
EcoDrive/platform/stm32f4/platform.cmake - Host SIL runtime
EcoDrive/platform/host/platform.cpp - Motor and Hall models
EcoDrive/platform/host/el_mc3p.cpp - STM32F4 runtime · Connects control commands and measurements to physical inverter I/O.
EcoDrive/platform/stm32f4/platform.c
Communications
- ABF and DAQ middleware
ecolib/middleware/ABFStream.h - Host transports
- STM32 transports
Desktop Tool
- EcoTool build target
EcoTool/CMakeLists.txt - EcoTool · PC-side device consumer and controller.
EcoTool/EcoTool.cpp
Connections 21
- EcoDrive build target → EcoDrive entry: builds
- EcoDrive entry → Control application: starts
- Control application → Control state & config: uses
- Control application → Common control core: dispatches to
- Common control core → FOC fast path: runs FOC mode
- Common control core → Self-commissioning: runs commissioning mode
- FOC fast path → Position driver: reads rotor position
- Self-commissioning → Position driver: uses position feedback
- Host platform selection → Host SIL runtime: selects
- STM32F4 platform selection → STM32F4 runtime: selects
- EcoDrive build target → Host platform selection: host build option
- EcoDrive build target → STM32F4 platform selection: embedded build option
- Common control core → Host SIL runtime: normalized I/O boundary
- Common control core → STM32F4 runtime: normalized I/O boundary
- Host SIL runtime → Motor and Hall models: simulates with
- Common control core → ABF and DAQ middleware: publishes DAQ
- ABF and DAQ middleware → Host transports: frames over
- ABF and DAQ middleware → STM32 transports: frames over
- STM32 transports → STM32F4 runtime: device I/O
- EcoTool build target → EcoTool: builds
- EcoTool → Host transports: TCP/serial sessions