Skip to content

Embedded firmware for the Battery Management System (BMS) of a Formula SAE electric vehicle, developed on STM32 Nucleo-F446RE with FreeRTOS. Features cell voltage monitoring, CAN bus and serial communication, CC–CV charging management, and real-time safety logic for high-voltage systems.

Notifications You must be signed in to change notification settings

davideronchini/bms-freertos-stm32

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BMS FreeRTOS STM32 ⚡

Battery Management System for Formula SAE Electric Vehicle

Professional BMS implementation based on STM32F446RE + FreeRTOS
FSAE 2025 Compliant • Melasta SLPB9270175HV Optimized • LTC6811-1 Based

STM32F446RE FreeRTOS FSAE LTC6811


🎯 Project Overview

This BMS (Battery Management System) is specifically designed for Polimarche Racing Team's Formula SAE electric vehicle. The system manages a 138-cell lithium polymer battery pack using Melasta SLPB9270175HV cells, ensuring safety, performance, and FSAE 2025 regulatory compliance.

Key Specifications

  • Microcontroller: STM32F446RE @ 128MHz
  • RTOS: FreeRTOS v10.3.1 with clean architecture separation
  • Battery Pack: 138 cells (6 modules × 23 cells/module)
  • Monitoring IC: 12× LTC6811-1 (2 per module)
  • Communication: isoSPI (LTC6820) + CAN bus
  • Compliance: FSAE 2025 regulations

📁 Project Structure


bms-freertos/
├── Core/
│   ├── Inc/                           # Header Files
│   │   ├── BMS\_Configuration/         # Pack Configuration
│   │   │   └── bms\_pack\_config.h      # CENTRALIZED pack configuration (138 cells)
│   │   │
│   │   ├── BMS\_Safety/                # Safety Systems
│   │   │   └── bms\_safety.h           # Unified safety management & fault detection
│   │   │
│   │   ├── BMS\_Monitoring/            # Battery Monitoring
│   │   │   └── bms\_monitoring.h       # LTC6811 cell monitoring & sensors
│   │   │
│   │   ├── BMS\_Communication/         # Communication Protocols
│   │   │   ├── can.h                  # CAN bus interface
│   │   │   ├── charger.h              # EVO11KA charger communication
│   │   │   └── serial.h               # UART debug interface
│   │   │
│   │   ├── BMS\_Drivers/               # Hardware Drivers
│   │   │   ├── LTC6811.h              # LTC6811-1 AFE driver
│   │   │   ├── LTC681x.h              # LTC681x common functions
│   │   │   └── bms\_hardware.h         # Hardware abstraction layer
│   │   │
│   │   ├── BMS\_Tasks/                 # FreeRTOS Logic
│   │   │   └── bms\_tasks.h            # BMS logic functions (no task definitions)
│   │   │
│   │   ├── main.h                     # Main application header
│   │   ├── FreeRTOSConfig.h           # FreeRTOS configuration
│   │   ├── stm32f4xx\_hal\_conf.h       # HAL configuration
│   │   └── stm32f4xx\_it.h             # Interrupt handlers
│   │
│   └── Src/                           # Source Files (mirrors Inc/ structure)
│       ├── BMS\_Communication/         # Communication implementations
│       ├── BMS\_Drivers/               # Driver implementations
│       ├── BMS\_Monitoring/            # Monitoring implementations
│       ├── BMS\_Safety/                # Safety implementations
│       ├── BMS\_Tasks/                 # BMS logic implementations
│       ├── main.c                     # Main application
│       ├── freertos.c                 # FreeRTOS tasks & configuration
│       ├── stm32f4xx\_hal\_msp.c        # HAL MSP functions
│       ├── stm32f4xx\_it.c             # Interrupt handlers
│       └── system\_stm32f4xx.c         # System initialization
│
├── Debug/                             # Debug build output
├── Drivers/                           # STM32 HAL & CMSIS
├── Middlewares/Third\_Party/FreeRTOS/  # FreeRTOS kernel
└── Startup/                           # Startup files


🔋 Battery Pack Configuration

Centralized Configuration System

The system uses a centralized configuration in the file BMS_Configuration/bms_pack_config.h:

// CENTRALIZED CONFIGURATION - MODIFY ONLY THESE VALUES
#define BMS_MODULES_COUNT 6        // Number of modules in the pack
#define BMS_CELLS_PER_MODULE 23    // Cells per module (standard: 23)
#define BMS_ICS_PER_MODULE 2       // LTC6811 ICs per module (standard: 2)

All other modules automatically adapt to these parameters:

  • Total cells: BMS_TOTAL_CELLS = 6 × 23 = 138
  • Total ICs: BMS_TOTAL_ICS = 6 × 2 = 12
  • Pack voltages: Automatically calculated (510.6V nom, 579.6V max, 414.0V min)
  • Charging currents: Automatically scaled with pack size
  • Cell distribution: Automatically distributed among ICs (6×12 cells + 6×11 cells)

Automatic Cell Distribution System

The new system automatically calculates the optimal cell distribution among LTC6811 ICs:

// AUTOMATIC SYSTEM based on BMS_PACK_CONFIG.H
#define BMS_MODULES_COUNT 6        // 6 modules
#define BMS_CELLS_PER_MODULE 23    // 23 cells per module
#define BMS_ICS_PER_MODULE 2       // 2 ICs per module
// Result: 6×23=138 cells, 6×2=12 ICs total

Distribution Algorithm

  1. Base Calculation: base_cells = TOTAL_CELLS ÷ TOTAL_ICS
  2. Extra Cells: extra_cells = TOTAL_CELLS % TOTAL_ICS
  3. Distribution: The first extra_cells ICs get base_cells + 1
  4. Remaining: The other ICs get base_cells

Practical Examples

Pack Config Cells IC Distribution
6 mod × 23 cells 138 12 6 ICs with 12 + 6 ICs with 11
3 mod × 23 cells 69 6 3 ICs with 12 + 3 ICs with 11
1 mod × 23 cells 23 2 1 IC with 12 + 1 IC with 11
2 mod × 12 cells 24 2 2 ICs with 12 each

Integrated Safety

Maximum Control: Each IC max 12 cells (LTC6811 limit) ✅ Total Validation: Compile-time verification of configuration ✅ Compile-Time Errors: Impossible configurations fail at compilation ✅ Runtime Diagnostics: Detailed debugging messages


⚙️ System Architecture

FreeRTOS Implementation (Clean Architecture)

The system implements BMS logic functions called by the FreeRTOS tasks generated by CubeMX:


Safety features

Hardware Safety

  • LTC6811-1: Cell voltage monitoring with ±0.1mV accuracy
  • LTC6820: Galvanic isolation via isoSPI
  • Emergency Shutdown (SDC): Hardware-based safety circuit

Software Safety

  • Unified safety system: BMS_Safety with centralized thresholds
  • Immediate callbacks: <50μs response time for critical emergencies
  • Multilevel protection: Voltage, temperature, communication
  • Watchdog: Task responsiveness monitoring
  • Safe state management: Automatic emergency procedures

Unified Safety Thresholds (in BMS_Safety/bms_safety.h):

#define BMS_OVERVOLTAGE_EMERGENCY_MV  4250  // Immediate SDC
#define BMS_UNDERVOLTAGE_EMERGENCY_MV 2700  // Immediate SDC
#define BMS_OVERTEMP_EMERGENCY_C      65    // Immediate SDC
#define BMS_IMBALANCE_EMERGENCY_MV    500   // Immediate SDC

🔍 Monitoring & Diagnostics

Real-time Parameters

  • Cell Voltages: 138 cells individually monitored via LTC6811
  • Pack Voltage: Automatically calculated from cells
  • Temperatures: Multi-point thermal monitoring
  • System Status: Continuous initialization with hardware status
  • Safety Status: Unified system with centralized thresholds

System States & LED Indicators

  • Blink LED: System initializing (hardware detection)
  • Solid LED: System operational (LTC6811 + Charger active)
  • LED Off: Fault detected or unsafe system

Performance Metrics

  • Continuous Init: Automatic detection of LTC6811 and Charger hardware
  • Response Times: <50μs for critical emergency functions
  • Memory Monitoring: Real-time heap usage
  • Hardware Status: Online/Offline for each component

Diagnostic Features

  • Hardware Detection: LTC6811 and Charger automatically detected
  • Fault Logging: Unified system via BMS_Safety
  • Communication Status: isoSPI and CAN monitoring
  • Serial Debug: Continuous status via UART2 115200 baud

📄 License & Credits

Author: Davide Ronchini (Polimarche Racing Team) Date: August 2025 Version: 2.0 - Production Release (Cleaned Architecture) Compliance: FSAE 2025, Melasta SLPB9270175HV optimized

Architecture:

  • Centralized Configuration: BMS_Configuration/bms_pack_config.h
  • Unified Safety System: BMS_Safety/bms_safety.h
  • Logic Separation: Logical BMS functions separated from FreeRTOS tasks
  • Continuous Initialization: Automatic hardware detection

Hardware Credits:

  • STMicroelectronics: STM32F446RE microcontroller
  • Analog Devices: LTC6811-1 and LTC6820 ICs
  • FreeRTOS: Real-time operating system kernel
  • Melasta: SLPB9270175HV Li-Polymer cells

⚡ Ready for FSAE 2025 Competition ⚡

This BMS provides a professional, safety-critical foundation for Formula SAE electric vehicle battery management with comprehensive monitoring, fault protection, and regulatory compliance.

About

Embedded firmware for the Battery Management System (BMS) of a Formula SAE electric vehicle, developed on STM32 Nucleo-F446RE with FreeRTOS. Features cell voltage monitoring, CAN bus and serial communication, CC–CV charging management, and real-time safety logic for high-voltage systems.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published