# binani-tech/bms-module architecture

> Architecture diagram of the GitHub repository binani-tech/bms-module, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/binani-tech/bms-module
- Repository: https://github.com/binani-tech/bms-module

## Overview

##### Main System Components

a) Hardware Layer (Bottom Level):
- STM32L431RC Microcontroller
- ISL78600 Analog Front End
- External Components (ADC, I2C, SPI peripherals)

b) Driver Layer (Lower Middle):
- HAL Drivers (STM32L4xx_HAL)
- Custom Drivers (in SPARK_BMS/DRIVER):
- ADC, CAN, DMA, GPIO, I2C, SPI, UART

c) Module Layer (Upper Middle):
- AFE Interface
- Battery Management
- Communication Protocols
- Storage (SD Card, EEPROM)

d) Application Layer (Top Level):
- Balancing
- Fault Monitoring
- State of Charge
- System Configuration

##### Component Relationships

- Data flow between layers
- Control signals
- Communication protocols
- Interrupt paths

##### Specific Features to Highlight

a) Safety Systems:
- Fault monitoring
- Short circuit protection
- Watchdog timers
- With red highlights or borders

b) Communication Interfaces:
- CAN bus
- UART
- I2C
- SPI
- Use different line styles for each protocol

c) Storage Systems:
- FATFS
- SD Card interface
- EEPROM

##### Key Design Elements

- Battery Management (balancing, monitoring)
- Communication (CAN, UART)
- Protection (fault handling)
- Data Storage (SD card, EEPROM)
- System Control (RTC, timers)

##### Additional Details

Callouts for:
- Voltage/current monitoring paths
- Cell balancing control
- Fault detection paths
- External communication interfaces

##### System States

- Initialization
- Normal operation
- Fault handling
- Sleep/low power modes

Remember to add version information and any relevant notes about critical timing or safety requirements.

This will provide a comprehensive view of the BMS architecture while maintaining clarity and showing the relationships between all major components.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef hardware fill:#b3d9ff,stroke:#333
    classDef driver fill:#90EE90,stroke:#333
    classDef module fill:#ffeb99,stroke:#333
    classDef application fill:#ffcc80,stroke:#333
    classDef safety stroke:#ff0000,stroke-width:2px
    
    %% Hardware Layer
    subgraph HW["Hardware Layer"]
        MCU["STM32L431RC MCU"]
        AFE["ISL78600 AFE"]
        EXT["External Components"]
    end
    
    %% Driver Layer
    subgraph DRV["Driver Layer"]
        HAL["HAL Drivers"]
        CAN["CAN Driver"]
        UART["UART Driver"]
        I2C["I2C Driver"]
        SPI["SPI Driver"]
        GPIO["GPIO Driver"]
    end
    
    %% Module Layer
    subgraph MOD["Module Layer"]
        AFE_IF["AFE Interface"]
        STORAGE["Storage Module"]
        EEPROM["EEPROM"]
        SD["SD Card"]
        FATFS["FATFS"]
        DB["Database"]
    end
    
    %% Application Layer
    subgraph APP["Application Layer"]
        BAL["Balancing"]
        SOC["State of Charge"]
        FAULT["Fault Monitoring"]
        SHORT["Short Circuit Protection"]
        CFG["System Configuration"]
    end
    
    %% Relationships
    MCU --> HAL
    AFE --> AFE_IF
    HAL --> |"Control"| DRV
    AFE_IF --> BAL
    AFE_IF --> SOC
    AFE_IF --> FAULT
    STORAGE --> EEPROM
    STORAGE --> SD
    STORAGE --> FATFS
    
    %% Click Events
    click MCU "https://github.com/Binani-Tech/BMS-module/blob/main/ISL78600/Core/Src/main.c"
    click HAL "https://github.com/Binani-Tech/BMS-module/blob/main/ISL78600/Core/Inc/stm32l4xx_hal_conf.h"
    click AFE_IF "https://github.com/Binani-Tech/BMS-module/blob/main/ISL78600/SPARK_BMS/MODULE/Inc/afe.h"
    click BAL "https://github.com/Binani-Tech/BMS-module/blob/main/ISL78600/SPARK_BMS/APPLICATION/Inc/balancing.h"
    click SOC "https://github.com/Binani-Tech/BMS-module/blob/main/ISL78600/SPARK_BMS/APPLICATION/Inc/soc.h"
    click FAULT "https://github.com/Binani-Tech/BMS-module/blob/main/ISL78600/SPARK_BMS/APPLICATION/Inc/fault_monitor.h"
    click SHORT "https://github.com/Binani-Tech/BMS-module/blob/main/ISL78600/SPARK_BMS/APPLICATION/Inc/shortcircuit.h"
    click CAN "https://github.com/Binani-Tech/BMS-module/blob/main/ISL78600/SPARK_BMS/DRIVER/Inc/can.h"
    click UART "https://github.com/Binani-Tech/BMS-module/blob/main/ISL78600/SPARK_BMS/DRIVER/Inc/uart.h"
    click I2C "https://github.com/Binani-Tech/BMS-module/blob/main/ISL78600/SPARK_BMS/DRIVER/Inc/i2c.h"
    click SPI "https://github.com/Binani-Tech/BMS-module/blob/main/ISL78600/SPARK_BMS/DRIVER/Inc/spi.h"
    click EEPROM "https://github.com/Binani-Tech/BMS-module/blob/main/ISL78600/SPARK_BMS/MODULE/Inc/eeprom.h"
    click SD "https://github.com/Binani-Tech/BMS-module/blob/main/ISL78600/SPARK_BMS/MODULE/Inc/sd_card.h"
    click FATFS "https://github.com/Binani-Tech/BMS-module/blob/main/ISL78600/FATFS/App/fatfs.h"
    click CFG "https://github.com/Binani-Tech/BMS-module/blob/main/ISL78600/SPARK_BMS/CONFIG/Inc/sparkbms_cfg.h"
    click DB "https://github.com/Binani-Tech/BMS-module/blob/main/ISL78600/SPARK_BMS/ENGINE/Inc/database.h"
    
    %% Style Applications
    class MCU,AFE,EXT hardware
    class HAL,CAN,UART,I2C,SPI,GPIO driver
    class AFE_IF,STORAGE,EEPROM,SD,FATFS,DB module
    class BAL,SOC,FAULT,SHORT,CFG application
    class FAULT,SHORT safety
```
