How rnd-ash/ultimate-nag52-fw works
Project type and purpose
• This is an embedded‐firmware project (written in C/C++ with PlatformIO/CMake) for the Ultimate NAG52 722.6 Transmission Control Unit (TCU).
• Its goal is to run on a microcontroller board, interface with transmission hardware (solenoids, sensors), communicate over CAN and USB, provide diagnostics, and manage gear‐shifting logic and calibration.
File structure
• Top-level: platformio.ini, CMakeLists.txt, sdkconfig, main src/ and include/, a lib/ directory with reusable modules (CAN definitions, ECU data, utility code), scripts/, tests/.
• src/ subdivides by functionality:
• canbus (CAN HAL and bus drivers)
• diag (diagnostic endpoints, flasher, KWP2000)
• nvs (persistent storage abstractions)
• adaptation, behaviour, shifting_algo (core TCU control algorithms)
• solenoids, tcu_io, sensors, pressure_manager, models (hardware interface + models)
• egs_calibration, maps (calibration data management)
• main.cpp – application entry point and task setup
• lib/ provides generic support: core math, CAN-message definitions for multiple ECU types, DTC manager, code‐generation scripts.
• Configuration/build files: platformio.ini, CMakeLists.txt, sdkconfig.unified, doxygen configs, GitHub workflows.
Key insights from README.md
• Confirms this is the TCU firmware for 722.6 gearbox, running on a custom hardware board.
• Emphasizes diagnostic, calibration, and CAN network integration.
• Build and documentation via Doxygen and PlatformIO.
A. Hardware Layer
• Microcontroller (center): CPU, RAM, Flash, peripheral buses.
• External buses: CAN bus (to vehicle ECUs), USB (for diagnostics & flashing).
• Hardware interfaces: Solenoid driver circuits, sensors (speed, temperature, pressure), e-fuse, IO expanders.
B. Firmware Software Layers (inside MCU)
1. Bootloader/Flasher (src/diag/flasher): initializes the device and performs updates.
2. HAL / Platform Abstraction
– canbus/can_hal.*
– efuse/efuse.*
– board_config.*
– tcu_io/tcu_io.*
– nvs (eeprom_config, module_settings)
3. Core Services
– CAN message routing (src/canbus/can_egs5x, can_custom, can_hfm)
– Diagnostic server (src/diag/endpoints/*.cpp, kwp2000)
– Data storage and DTC management (lib/dtcs, src/stored_*)
4. Control Logic
– Behaviour & driving profiler (src/behaviour)
– Adaptation (shift adaptation)
– Shifting algorithm (shift_crossover, shift_release, helpers)
– Gearbox model & torque converter (src/models, torque_converter)
– Solenoid control (src/solenoids)
– Pressure management (src/pressure_manager)
5. Configuration & Calibration
– Map loader and stored tables (src/maps, stored_map)
– Calibration engine (src/egs_calibration)
6. Application Entry (src/main.cpp)
– Starts RTOS tasks/loops, schedules sensor reads, CAN traffic, control loops.
Relationships and data flows
• Sensors → HAL → Control Logic → Solenoid drivers
• Control Logic ↔ Calibration & stored maps
• Control Logic & diagnostic ↔ CAN bus (external ECUs, tuner tools)
• Diagnostic server → USB (PC tool) & CAN endpoints
• Persistent settings (NVS) ←→ Control Logic
Architectural patterns & design principles
• Layered architecture: HAL → Services → Control Logic → Application
• Modularity: each functional area in its own directory and namespace
• Separation of concerns: distinct CAN stacks per ECU version, separate diagnostic endpoints
• RTOS/task‐based scheduling implied in main (not shown in file tree but typical for embedded)
Technologies & frameworks
• PlatformIO or ESP-IDF (sdkconfig) + CMake
• Doxygen for documentation
• Python/Perl scripts for code‐generation (lib/gen_headers, scripts/*.py)
• GitHub Actions for CI and docs deployment