Embedded motor-control firmware and simulation stack for PMSM/inverter development, with host simulation and STM32F4 hardware targets.
- Install dependencies:
cmake, a C/C++ toolchain,glfw3, and OpenGL dev headers. - Configure:
cmake -S . -B build -DPLATFORM_NAME=host -DCMAKE_BUILD_TYPE=Release - Build:
cmake --build build -j - Run:
./build/bin/EcoDriveor a test binary like./build/bin/test_pmsm
- Install
arm-none-eabi-gccandcmake. - Configure:
cmake -S . -B build -DPLATFORM_NAME=stm32f4 -DCMAKE_BUILD_TYPE=Release - Build:
cmake --build build -j - Artifacts are emitted to
build/bin/and.hex/.binare generated post-build. OR easier Just run setup.sh file if provided
application/: Product-level application logic and system orchestration.core/: Core math, control, and shared utilities.middleware/: Shared middleware (e.g., streaming/serialization).platform/host/: Host simulation platform, FreeRTOS POSIX, ImGui UI, and drivers.platform/stm32f4/: STM32F4 HAL/LL platform, USB, startup, and FreeRTOS.test/: Host-only test and model executables.tools/: Python utilities, comm tooling, and scripts.build/: Out-of-tree build output (generated).
This repository follows a pragmatic embedded C/C++ standard intended to be portable across similar projects.
Language and compiler settings:
- C is
C11, C++ isC++20(seeCMakeLists.txt). - Warnings should be treated as errors for new code when feasible.
- Prefer
-O2or-Ogfor debug builds on embedded targets.
Style rules:
- Naming:
snake_casefor C functions/variables,PascalCasefor types,UPPER_SNAKE_CASEfor macros. - Module prefixes: use a consistent, short prefix per subsystem for identifiers and macros.
- Prefix examples:
ELDRIVER_for driver-level macros/constants and compile-time flags.eldriver_for driver-level C functions.ELCORE_for core macros/constants and compile-time flags.elcore_for core C functions , reusable datastructures.ELMATH_for math macros/constants and compile-time flags.elmath_for math C functions.- Files:
module_name.c/.hfor C,ModuleName.cpp/.hppfor C++ where practical. - Headers: include guards or
#pragma onceconsistently within a file. - Includes: order as local header, project headers, then system headers.
- Globals: avoid unless they are
staticor clearly documented hardware singletons. - Interfaces: keep C headers
extern "C"friendly for mixed C/C++ builds.
Embedded safety rules:
- No dynamic allocation on embedded targets unless explicitly justified.
- Keep ISR work minimal; move heavy work to tasks or deferred handlers.
- Validate bounds on buffers and peripheral data paths.
- Prefer fixed-point where timing determinism is required.
Formatting:
- Use 4 spaces, no tabs.
- Max line length 100 where reasonable.
- If you introduce a formatter, document it in
tools/and add aformattarget.
To add a new hardware platform, mirror the platform/stm32f4/ approach:
- Create
platform/<new_platform>/with aCMakeLists.txtthat exportsPLATFORM_LIB,PLATFORM_INTERFACE,PLATFORM_INCLUDES,PLATFORM_DEFINITIONS, andPLATFORM_SOURCE. - Add a toolchain file at
platform/<new_platform>/cmake/and reference it in the rootCMakeLists.txt. - Provide startup, system, and IRQ files as needed for your MCU. ( you can use vendor tools like CubeMX for that)
- Implement platform glue in
platform/<new_platform>/platform.cand any board drivers. - Add any RTOS or USB stacks under the new platform directory.
- Validate by building and running the host tests for shared core logic.
Minimal platform contract:
platform.cshould implement board init, clock init, and any HAL hooks.- IRQ handlers must be strong symbols when overriding weak startup defaults.
PLATFORM_SOURCEshould include driver core sources so overrides link correctly.
Create or update documentation under a docs/ folder for reusable patterns. Suggested structure:
docs/overview.md: system overview and architecture.docs/build.md: build instructions for host and hardware.docs/porting.md: detailed porting checklist and hardware bring-up.docs/testing.md: test strategy and how to run tests.docs/hardware.md: board notes, pin maps, power, and safety constraints.
Doxygen guidance:
- Keep public headers documented with
@briefand parameter descriptions. - Document control loops, scaling, and unit conventions.
- Add a short module comment block at the top of each subsystem header.
- Build the host target and run
test_pmsm. - Read
application/entry points and the main control loop. - Review
core/math utilities and motor models. - Review
platform/host/andplatform/stm32f4/for platform boundaries. - Read
docs/overview.md(or create it for a new project).
- Core Code , Custom Data structures , Core
- Control algorithms:
application/. - Hardware drivers:
platform/<target>/andplatform/<target>/eldriver/. - Simulation/GUI:
platform/host/andtools/. - Middleware/serialization:
middleware/. - Test and model validation:
test/and datasets in the repository root.
EcoDrive: main application binary.test_scopeStream: host-only scope stream test.test_inverter: host-only inverter test.test_pmsm: host-only PMSM test.
Contributions:
- Fork the repo and create a branch:
feature/<short-name>orfix/<short-name>. - Keep changes focused and aligned with the coding standard in this README.
- Add or update tests where behavior changes.
- Open a Pull Request with a concise summary and a checklist of what changed.
Issues:
- File issues for bugs, regressions, unclear behavior, and feature additions.
- Include target platform (
hostorstm32f4), steps to reproduce, expected vs actual behavior, and logs if available. - Use labels to clarify type and priority (bug, enhancement, documentation, hardware).
GitHub Projects:
- Use a Project board to track Epics, Features, and Tasks.
- Each task should link to an Issue and a PR.
- Assign an owner and a due date when the work starts.
- Close Issues via PR descriptions using
Closes #<issue-number>.
(KiCad + GitHub)
- Keep all KiCad sources in a single top-level folder per board or subsystem.
- Commit schematic and PCB files together for any change.
- Prefer project-local libraries to avoid missing symbols/footprints.
- Do not commit KiCad autosave, backup, or lock files.
- Export manufacturing outputs (Gerbers, drill, BOM, pick-and-place) into a dedicated folder and keep those outputs versioned only for releases.
- Include a short
READMEin each hardware folder with board purpose, revision, and KiCad version. - For PRs, include screenshots of schematic and PCB diffs when possible.
GitHub Projects:
- Use a Project board to track Epics, Features, and Tasks.
- Each task should link to an Issue and a PR.
- Assign an owner and a due date when the work starts.
- Close Issues via PR descriptions using
Closes #<issue-number>.
MIT. See license headers in platform dependencies where applicable.