Skip to content

ECU (Electronic Control Unit)

1. Project Overview

The ECU (Electronic Control Unit) is built around an STM32H563xx microcontroller and serves as the central brain of the vehicle's electronic architecture.

The primary responsibilities of this board are:

  • Vehicle Control Logic: Executing the primary finite state machines (FSMs) including Ready-to-Drive (R2D), overall Control, and Shutdown procedures.
  • Motor Control & Inverter Management: Interfacing with the motor controllers via CAN, adjusting slip control, torque vectoring (TV), and handling PID tunings.
  • Data Processing: Receiving sensor data from other nodes (like the CAN-Gateway), processing it using algorithms such as Unscented Kalman Filters (UKF) for vehicle state estimation.
  • System Monitoring & Safety: Monitoring BMS errors, temperatures, SDC (Shutdown Circuit) state, and communicating faults.

2. Features

  • STM32H563xx Microcontroller: A high-performance ARM Cortex-M33 core suitable for complex mathematical processing and control algorithms.
  • FDCAN Interface: High-speed CAN communication to talk to all vehicle nodes, inverters, and telemetry.
  • State-Machine Architecture: Implements distinct, robust FSMs for standard vehicle operations (ECU, R2D, Control, Shutdown).
  • Vehicle Dynamics Estimation: Uses UKF (Unscented Kalman Filter) to estimate velocity and side-slip.
  • Advanced Motor Control: Supports dynamic adjustment of slip control mode, PID gains, and torque vectoring parameters via CAN.

3. Software Architecture

The application uses the STM32Cube HAL alongside a custom application layer defining the core logic.

3.1. Application Layer (Core/Src/App)

The application is structured into the following distinct functional blocks:

  • FSM (App/ECU, App/R2D, App/Control, App/Shutdown): State machines that handle the state transitions of the car, safety checks, and control loop logic.
  • Communication (App/Communication): Manages all incoming and outgoing CAN messages (can_comm.c, can_driver.c).
  • Data Processing: Contains IMU calibration (imu_cal.c), SCS verification (scs_verif.c), and UKF math operations (ukf.h / ukf.c).
  • Motor Control (motor_control.c): Interprets input commands (throttle, steering) and outputs inverter commands while running slip/TV logic.

3.2. External Dependencies

The ECU relies on the common library module for the shared driver implementations. Specifically, it heavily utilizes:

  • CAN Driver (generic_can_driver)
  • FSM Driver

There are no other specific external dependencies outside of common.

4. Directory Structure

  • /Core: Contains the main application code.
    • /Inc: Header files (.h).
    • /Src: Source files (.c).
  • /Drivers: Low-level drivers including ST's HAL and the shared common module.
  • /docs: Project documentation (where this file resides).
  • /cmake: CMake toolchain files.
  • /build: Build output directory (not tracked by Git).

5. Building the Project

The project is configured to be built with CMake using CMakePresets.json. It can be built using an IDE like VS Code with the CMake Tools extension.

Released under the MIT License.