Skip to content

moyamartin/bms_firmware

Repository files navigation

Battery Management System (BMS) - Firmware CI - STM32

This is the firmware dev section of the BMS project, as the hardware section states, the brain of the BMS is based on a STM32F407VGTx microcontroller unit.

It's mainly based on STM32Cube HAL (Hardware Abstraction Layer) and the CMSIS (Cortex Microcontroller Software Interface Standard).

To clone this repo run:

git clone --recursive -j8 https://github.com/moyamartin/bms_firmware.git

Folder Structure

  • Core: Contains the firmware main source and header files related to the project's firmware

  • Test: Contains the unit tests related to different algorithms of the project, unit tests are NOT related to device drivers and so on. We would need to work on a hardware in the loop testing workbench for that.

  • Drivers: Contains the STM32Cube HAL, CMSIS software package and device drivers for the different peripherals of the main board

Features

The firmware has to be able to accomplish the following goals:

  • Estimate the state of charge of the battery using a Kalman Filter and an electrical model of a 18650PF (Under test).
  • Device drivers for the peripherals of the BMS in order to get the following information:
    • Discharge/charge current
    • Cell voltage
  • Unbalanced cell detector
  • Finite-state machine for handling charge/discharge phases
  • Communicate the current status of the battery pack via CAN bus or RS232 protocol
  • Handle failure interruptions and trigger the load switch for protection
  • Handle the battery charger indicators (WIP)

Requirements

Software

Before building and loading the firmware into the board, first you'll need to install the GNU ARM embedded toolchain and OpenOCD (On-Chip Debugger) or you can install the STM32CubeIDE and import it as this proyect is compatible with that development environment.

Hardware

You will need a STLink/V2 in-circuit debugger/programmer in order to loadand debug the firmware on the board.

NOTE: if you have a STM32F4discovery board or another known board that has a STLink programmer with accessible pins you won't need to acquire an stand-alone programmer in order to load the firmware to the board, you only need to connect the SWDIO pins.

Build and Run

Linux

Open a terminal and run the following steps

1 - Go to the cloned repo's folder

cd root_path/bms_unr 

2 - Run make to build the firmware . This will create a build folder containing the binaries of the firmware (.bin, .hex and .elf).

NOTE: to build the firmware without debug symbols modify the Makefile and set the DEBUG variable to 0. (WIP, run make debug or make prod to avoid changing this variable manually)

2- To load the firmware to the microcontroller run the following command

openocd -d0 -f board/stm32f4discovery.cfg -c "init;targets;halt;flash write_image erase bms_firmware.hex;shutdown"

3 - To debug the firmware you first have to run an openocd server on a terminal running (Make sure that you are building the project with debug symbols, otherwise you won't be able to see C code in GDB)

openocd -f board/stm32f4discovery.cfg

and on a separate terminal run

arm-none-eabi-gdb -f root_path/bms_firmare/build/bms_firmare.elf -x init.gdb

Windows

Testing

We are running some local test for specific algorithms using Cpputest. To run them first build and configure the framework running:

cd path_to_repo/Test/cpputest/cpputest_build && autoreconf .. -i && ../configure && make && mkdir ../lib && cp ./lib/* ../lib/

And them, to execute the tests run:

cd Test && make -B gcov

This will make a test coverage html file saying which tests passed or failed

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •