Firmware for Xanadu BMS : This is the source code for the Xanadu BMS, based on the Ennoid-BMS
- Tools:
git
,make
,gcc arm none-eabi
- Install git : https://git-scm.com/download/win. Make sure to click any boxes to add Git to your Environment (aka PATH)
- Install GNU Arm Embedded Toolchain, version 11.2 2022.02 for Windows : https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads
- Install Cygwin : https://www.cygwin.com/ . Ensure
make
package is installed. - Install OpenOCD : https://github.com/xpack-dev-tools/openocd-xpack/releases
- Install ST-Link Utility : https://www.st.com/en/development-tools/stsw-link004.html
- Open a Git terminal in the desired directory by selecting
Git Bash Here
- Type
git clone https://github.com/psychendPerspective/Xanadu-BMS-Firmware.git
- Change directory to the recently cloned repository
- Type
git checkout origin/main
- Now open a Cygwin64 Terminal and change the working directory to the recently cloned repository :
cd /cygdrive/c/...../Xanadu-BMS-Firmware/build_all
Replace the ..... with your working directory path. - Run the build script :
./rebuild_HV.sh
- Flashing to a new board without a bootloader :
- Open STM32 ST-Link Utility, select the address as
0x08032000
and then connect to the Xanadu-BMS with the ST-Link. - Open the bootloader file present in the build_all folder :
generic_bootloader.bin
and flash the bootloader. - Disconnect, select the address as
0x08000000
and then reconnect to the Xanadu-BMS with the ST-Link. - Open the recently built firmware bin file in the
build_all/ XANADU_HV_EV
folder and flash the firmware.
- Flashing firmware to the board :
- Open STM32 ST-Link Utility.
- Select the address as
0x08000000
and then connect to the Xanadu-BMS with the ST-Link. - Open the recently built firmware bin file in the
build_all/ XANADU_HV_EV
folder and flash the firmware.
- In
generalDefines.h
in theMain
folder, setXANADU_HV_EV
macro as 1 - Set the other macros under
XANADU_HV_EV
based on the hardware configuration - In
modConfig.c
in theModules/Src
folder, undermodConfigLoadDefaultConfig
, configure the following based on the battery pack :
noOfCellsSeries
: Total number of cells in series in the battery packnoOfCellsParallel
: Number of cells in parallel per series string in the battery packbatteryCapacity
: Battery Pack Capacity in AhCANID
: Set the CAN ID for the BMS (1-255)canBusSpeed
: Set the Baud rate for CAN transmissionnoOfTempSensorPerModule
: Total number of thermistors present which are being monitored per LTC681x AFE ICcellMonitorType
: Set the type of AFE Cell Monitor IC used (LTC6811, LTC6812, LTC6813)cellMonitorICCount
: Total number of AFE Cell Monitor ICs connected in the stacknoOfCellsPerModule
: Total number of cells being monitored per AFE Cell Monitor IClastICNoOfCells
: Number of cells being monitored by the last AFE Cell Monitor IC in the stackcellTypeUsed
: Select the cell Type used in the battery pack to calculate initial SoC
- In
modConfig.c
in theModules/Src
folder, undermodConfigLoadDefaultConfig
, configure the following based on the battery pack :
cellHardUnderVoltage
: Absolute minimum voltage(V) for the lowest cell voltagecellLCSoftUnderVoltage
: Lower Cell voltage limit for the BMS to cut-off during operation
cellHardOverVoltage
: Absolute maximum voltage(V) for the highest cell voltagecellSoftOverVoltage
: Upper Cell voltage limit for the BMS to cut-off during operation
- Note : Positive Current is taken as Charging Current while Negative Current is taken as Discharging Current
maxAllowedCurrent
: Absolute maximum allowed current(A) through the BMS without triggering an errormaxAllowedChargingCurrent
: Current Limit for the BMS to cut-off during Charging. Set this limit based on the maximum recommended charging current for the cells used in the battery pack.maxAllowedDischargingCurrent
: Current Limit for the BMS to cut-off during Discharging . Set this limit based on the load rating/ maximum recommended discharging current for the cells used in the battery pack. This value should have a negative sign.
allowedTempBattDischargingMax
: Maximum Battery Pack Temperature(degC) allowed during DischargingallowedTempBattDischargingMin
: Minimum Battery Pack Temperature (degC)allowed during DischargingallowedTempBattChargingMax
: Maximum Battery Pack Temperature(degC) allowed during ChargingallowedTempBattChargingMin
: Minimum Battery Pack Temperature(degC) allowed during ChargingallowedTempBMSMax
: Absolute Maximum temperature(degC) allowed for normal BMS operationallowedTempBMSMin
: Absolute Minimum temperature(degC) allowed for normal BMS operation
cellBalanceStart
: Start balancing above this cell voltage(V) during chargingcellBalanceDifferenceThreshold
: If the Cell Imbalance Voltage, i.e (Cell Voltage - Lowest Cell Voltage) is above this voltage limit, cell balancing will occurcellBalanceAllTime
: Enable cell balancing under all operational states
- In
modSDcard.h
in theModules/Inc
folder,configure the following :
LOGGING_INTERVAL
: Set the SD card logging interval in milliseconds.
Main
folder contains the main application codeModules
folder contains the source and header files for the application layerLibraries
folder contains the source and header files for the external libraries usedDrivers
folder contains drivers for the hardware and software peripherals, as well as the STM32 HAL driversGCC
folder contains the startup code and linker script required for the controllerbuild_all
folder contains the build scripts and firmware build files
- The integer values present in the SD card logging file correspond to the following operational and fault state enums respectively, present in
Main/mainDataTypes.h
//Operational States
typedef enum {
OP_STATE_INIT = 0, // 0
OP_STATE_CHARGING, // 1
OP_STATE_PRE_CHARGE, // 2
OP_STATE_LOAD_ENABLED, // 3
OP_STATE_BATTERY_DEAD, // 4
OP_STATE_POWER_DOWN, // 5
OP_STATE_EXTERNAL, // 6
OP_STATE_ERROR, // 7
OP_STATE_ERROR_PRECHARGE, // 8
OP_STATE_BALANCING, // 9
OP_STATE_CHARGED, // 10
OP_STATE_FORCEON, // 11
} OperationalStateTypedef;
//Fault States
typedef enum {
FAULT_CODE_NONE = 0, //0
FAULT_CODE_PACK_OVER_VOLTAGE, //1
FAULT_CODE_PACK_UNDER_VOLTAGE, //2
FAULT_CODE_LOAD_OVER_VOLTAGE, //3
FAULT_CODE_LOAD_UNDER_VOLTAGE, //4
FAULT_CODE_CHARGER_OVER_VOLTAGE, //5
FAULT_CODE_CHARGER_UNDER_VOLTAGE, //6
FAULT_CODE_CELL_HARD_OVER_VOLTAGE, //7
FAULT_CODE_CELL_HARD_UNDER_VOLTAGE, //8
FAULT_CODE_CELL_SOFT_OVER_VOLTAGE, //9
FAULT_CODE_CELL_SOFT_UNDER_VOLTAGE, //10
FAULT_CODE_MAX_UVP_OVP_ERRORS, //11
FAULT_CODE_MAX_UVT_OVT_ERRORS, //12
FAULT_CODE_OVER_CURRENT, //13
FAULT_CODE_OVER_TEMP_BMS, //14
FAULT_CODE_UNDER_TEMP_BMS, //15
FAULT_CODE_DISCHARGE_OVER_TEMP_CELLS, //16
FAULT_CODE_DISCHARGE_UNDER_TEMP_CELLS, //17
FAULT_CODE_CHARGE_OVER_TEMP_CELLS, //18
FAULT_CODE_CHARGE_UNDER_TEMP_CELLS, //19
FAULT_CODE_PRECHARGE_TIMEOUT, //20
FAULT_CODE_DISCHARGE_RETRY, //21
FAULT_CODE_CHARGE_RETRY, //22
FAULT_CODE_CAN_DELAYED_POWER_DOWN, //23
FAULT_CODE_NOT_USED_TIMEOUT, //24
FAULT_CODE_CHARGER_DISCONNECT, //25
FAULT_CODE_MAX_SOFT_UVP_ERRORS //26
} bms_fault_state;
When flashing the application the start address should be: 0x08000000
When flashing the bootloader the start address should be: 0x08032000
The flash is formatted as follows (summary):
- ((uint32_t)0x08000000) : Base @ of Page 0, 2 Kbytes // Startup Code - Main application
- ((uint32_t)0x08000800) : Base @ of Page 1, 2 Kbytes // Page0 - EEPROM emulation
- ((uint32_t)0x08001000) : Base @ of Page 2, 2 Kbytes // Page1 - EEPROM emulation
- ((uint32_t)0x08001800) : Base @ of Page 3, 2 Kbytes // Remainder of the main application firmware stars from here.
- ((uint32_t)0x08019000) : Base @ of Page 50, 2 Kbytes // New app firmware base addres
- ((uint32_t)0x08032000) : Base @ of Page 100, 2 Kbytes // Bootloader base
See modFlash.h
and modFlash.c
for more info.