This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
rusEFI is an open-source engine control unit firmware for STM32 microcontrollers.
Default to building with 12 threads unless otherwise specified (-j12 etc).
Each board+chip combination has its own compile script in firmware/config/boards/<board>/:
# Example: Build for Proteus F7
cd firmware/config/boards/proteus
./compile_proteus_f7.shOutputs are placed in firmware/deliver/:
rusefi.bin- Complete image (bootloader + firmware) for blank ECUsrusefi_update.srec- Update image for bootloader flashing
cd unit_tests
make
./build/rusefi_test
# Run a specific test
./build/rusefi_test --gtest_filter=TestNameUnit tests use Google Test and run on amd64/aarch64, not on the ECU.
# Generate configs for a specific board
firmware/gen_config_board.sh <board>
# Generate all board configs
firmware/gen_config.sh
# Generate enum-to-string conversions
firmware/gen_enum_to_string.shfirmware/config/boards/- Hardware configuration and defaults for different ECU hardwarefirmware/config/engines/- Hardware-agnostic configuration for engines (orthogonal to what ECU you run)firmware/controllers/- Core control logicalgo/- Fuel, ignition, and air calculationsactuators/- Control for engine-asynchronous outputs like electonic throttle, idle, AC, boost, VVT, etc.engine_cycle/- Control for engine-synchronous outputs like injection, ignitionsensors/- Input processing (ADC, thermistors, pressure)trigger/- Crank/cam position decoding and synccan/- CAN bus communicationlua/- Runtime scripting
firmware/hw_layer/- Hardware abstraction layerfirmware/libfirmware/- Reusable library codefirmware/util/- Self-contained utilities (no external dependencies)unit_tests/- Google Test suitesimulator/- Windows/Linux firmware simulator
- Event-driven execution: Trigger events from crank/cam sensors drive the main control loop
- Angle-based scheduling: Events scheduled by crank angle, not just time
- Configuration-driven: Board and engine parameters externalized; firmware adapts via configuration
- ChibiOS RTOS: Real-time operating system foundation
firmware/rusefi_config.txtdefines the parameters stored in persistent configuration (both "configuration", ie which pins do what, and the "calibration" or "tune", like the VE table, timing, etc.)- That file is processed by the java tool at
java_tools/configuration_definitionto generate several outputs. It is critical that these match, so that each part of the system can communicate and agree about the in-memory config format.- C/C++ headers in
firmware/generated - Along with
firmware/tunerstudio/tunerstudio.template.ini, generates the ini file used by TunerStudio to communicate with the ECU. All tuner-adjustable parameters MUST appear in this file to be useful.
- C/C++ headers in
firmware/integration/LiveData.yamldefines objects processed by the same tool to be transmitted from the ECU about the current state of the world. For example sensors, output values, and intermediate calculations useful for logging.
These are all automatically regenerated as part of running make, so no direct script invocation is required. Do not attempt to commit any generated files.
- C99 with GNU extensions for C code
- C++20 for firmware code
- No RTTI, no exceptions (
-fno-rtti -fno-exceptions) - LTO enabled by default
Key preprocessor flags that control compilation:
EFI_PROD_CODE=1- Production firmwareEFI_UNIT_TEST=1- Unit test buildEFI_SIMULATOR=1- Simulator build
- Static allocation: Prefer static allocation over dynamic (
new/malloc). Memory is limited and fragmentation must be avoided. - Performance matters: This is a hard real-time application. Fuel and ignition events must fire at precise crank angles. Avoid unnecessary computation in hot paths. Use lower priority threads for expensive computation.
- No exceptions: C++ exceptions are disabled. Use return values or error codes for error handling.
- No RTTI:
dynamic_castandtypeidare unavailable. - Interrupt safety: Be mindful of code that runs in interrupt context vs. thread context. Use appropriate synchronization primitives.
- Stack usage: Keep stack allocations small. Large arrays should be static or global, not local variables.
- Supported IDE: Visual Studio Code
- Requires Unix-like OS (Linux, macOS, or Windows WSL)
- All PRs must pass CI gates (firmware builds for all boards, unit tests)
- Wiki: https://wiki.rusefi.com/