Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name: CMake
# Define the workflow's triggers
on:
pull_request:
branches: [ main ]
branches: [main]

# Set necessary environment variables
env:
Expand All @@ -30,20 +30,25 @@ jobs:
- name: Install Compiler and Linter
run: |
sudo apt-get install gcc-arm-none-eabi
sudo apt-get install clang-format-12
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-12 10000
sudo apt-get install clang-format-15
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-15 10000

# Build the code for all supported chips
- name: F302 Build
run: |
cmake -DTARGET_DEV=STM32F302x8 -B ${{github.workspace}}/build
cmake --build ${{github.workspace}}/build
# - name: F302 Build
# run: |
# cmake -DTARGET_DEV=STM32F302x8 -B ${{github.workspace}}/build
# cmake --build ${{github.workspace}}/build

- name: F334 Build
run: |
cmake -DTARGET_DEV=STM32F334x8 -B ${{github.workspace}}/build
cmake --build ${{github.workspace}}/build

# - name: F446 Build
# run: |
# cmake -DTARGET_DEV=STM32F446xx -B ${{github.workspace}}/build
# cmake --build ${{github.workspace}}/build

# Apply clang-format formatting to the branch and create a new commit if any files are changed
- name: Apply Formatting
run: |
Expand All @@ -57,4 +62,4 @@ jobs:
git config --global user.name "GitHub Build"
git commit -a -m "Applied Formatting Changes During GitHub Build"
git push origin
fi
fi
34 changes: 17 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
cmake_minimum_required(VERSION 3.15)

# Convert CMake flags to compiler flags
if(EVT_CORE_LOG_ENABLE)
if (EVT_CORE_LOG_ENABLE)
add_compile_definitions(EVT_CORE_LOG_ENABLE)
endif()
endif ()

# Allow for up to 8 CANopen TPDOs
add_compile_definitions(CO_TPDO_N=8)
Expand All @@ -23,11 +23,11 @@ add_compile_definitions(USE_HAL_DRIVER)

# Handle Selection of the target device
option(TARGET_DEV "Target device" "STM32F302x8")
if(NOT TARGET_DEV)
if (NOT TARGET_DEV)
set(TARGET_DEV "STM32F334x8")
endif()
endif ()

set(EVT_CORE_DIR ${CMAKE_SOURCE_DIR}/libs/EVT-core)
set(EVT_CORE_DIR ${CMAKE_SOURCE_DIR}/libs/EVT-core)

# Link to the EVT-core library
add_subdirectory(libs/EVT-core/)
Expand All @@ -39,11 +39,11 @@ include(${EVT_CORE_DIR}/cmake/evt-core_install.cmake)
###############################################################################
# Project Setup
###############################################################################
set(BOARD_LIB_NAME BMS)
if("${BOARD_LIB_NAME}" STREQUAL BOARD_NAME)
set(BOARD_LIB_NAME BMS)
if ("${BOARD_LIB_NAME}" STREQUAL BOARD_NAME)
message(FATAL_ERROR
"You must set the template project name in the top-level CMakeLists.txt")
endif()
endif ()

file(STRINGS version.txt BOARD_VERSION)

Expand All @@ -56,22 +56,22 @@ add_library(${PROJECT_NAME} STATIC)

# Add sources
target_sources(${PROJECT_NAME} PRIVATE
src/BMS.cpp
src/BQSettingStorage.cpp
src/BQSetting.cpp
src/ResetHandler.cpp
src/SystemDetect.cpp
src/dev/BQ76952.cpp
src/dev/Interlock.cpp
src/dev/ThermistorMux.cpp
src/BMS.cpp
src/BQSettingStorage.cpp
src/BQSetting.cpp
src/ResetHandler.cpp
src/SystemDetect.cpp
src/dev/BQ76952.cpp
src/dev/Interlock.cpp
src/dev/ThermistorMux.cpp
)

###############################################################################
# Handle dependencies
###############################################################################
target_link_libraries(${PROJECT_NAME}
PUBLIC EVT
)
)

###############################################################################
# Install and expose library
Expand Down
59 changes: 33 additions & 26 deletions include/BMS.hpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
#pragma once

#include <cstdint>

#include <EVT/io/CANDevice.hpp>
#include <EVT/io/CANOpenMacros.hpp>
#include <co_core.h>
#include <core/io/CANDevice.hpp>
#include <core/io/CANOpenMacros.hpp>
#include <core/io/pin.hpp>
#include <core/dev/IWDG.hpp>

#include <BMSCANOpenMacros.hpp>
#include <BQSettingStorage.hpp>
#include <EVT/dev/IWDG.hpp>
#include <EVT/io/pin.hpp>
#include <ResetHandler.hpp>
#include <SystemDetect.hpp>

#include <dev/Interlock.hpp>
#include <dev/ThermistorMux.hpp>

namespace IO = EVT::core::IO;
namespace IO = core::io;

namespace BMS {

Expand Down Expand Up @@ -58,11 +56,13 @@ class BMS : public CANDevice {
static constexpr IO::Pin CAN_RX_PIN = IO::Pin::PA_11;
static constexpr IO::Pin I2C_SCL_PIN = IO::Pin::PB_6;
static constexpr IO::Pin I2C_SDA_PIN = IO::Pin::PB_7;
static constexpr IO::Pin INTERLOCK_PIN = IO::Pin::PA_3;
static constexpr IO::Pin INTERLOCK_PIN = IO::Pin::PF_0;
static constexpr IO::Pin TEMP_INPUT_PIN = IO::Pin::PA_0;
static constexpr IO::Pin MUX_S1_PIN = IO::Pin::PA_15;
static constexpr IO::Pin MUX_S2_PIN = IO::Pin::PB_4;
static constexpr IO::Pin MUX_S3_PIN = IO::Pin::PA_8;
static constexpr IO::Pin ERROR_LED_PIN = IO::Pin::PA_7;
static constexpr IO::Pin BQ_RESET_PIN = IO::Pin::PB_1;

/** Error values */
static constexpr uint8_t BQ_COMM_ERROR = 0x01;
Expand All @@ -72,18 +72,20 @@ class BMS : public CANDevice {
/**
* Make a new instance of the BMS with the given devices
*
* @param bqSettingsStorage Object used to manage BQ settings storage
* @param bq BQ chip instance
* @param interlock GPIO used to check the interlock status
* @param alarm GPIO used to check the BQ alarm status
* @param systemDetect Object used to detect what system the BMS is connected to
* @param bmsOK GPIO used to output the OK signal from the BMS
* @param thermMux MUX for pack thermistors
* @param resetHandler Handler for reset messages
*/
BMS(BQSettingsStorage& bqSettingsStorage, DEV::BQ76952 bq, DEV::Interlock& interlock,
IO::GPIO& alarm, SystemDetect& systemDetect, IO::GPIO& bmsOK,
DEV::ThermistorMux& thermMux, ResetHandler& resetHandler, EVT::core::DEV::IWDG& iwdg);
* @param[in] bqSettingsStorage Object used to manage BQ settings storage
* @param[in] bq BQ chip instance
* @param[in] interlock GPIO used to check the interlock status
* @param[in] alarm GPIO used to check the BQ alarm status
* @param[in] systemDetect Object used to detect what system the BMS is connected to
* @param[in] bmsOK GPIO used to output the OK signal from the BMS
* @param[in] errorLed GPIO used to indicate a BMS error with an LED
* @param[in] thermMux MUX for pack thermistors
* @param[in] resetHandler Handler for reset messages
* @param[in] iwdg Internal watchdog to ensure the BMS code is running without getting stuck
*/
BMS(BQSettingsStorage& bqSettingsStorage, const dev::BQ76952 &bq, dev::Interlock& interlock,
IO::GPIO& alarm, SystemDetect& systemDetect, IO::GPIO& bmsOK, IO::GPIO& errorLed,
const dev::ThermistorMux& thermMux, ResetHandler& resetHandler, core::dev::IWDG& iwdg);

/**
* The node ID used to identify the device on the CAN network.
Expand Down Expand Up @@ -185,7 +187,7 @@ class BMS : public CANDevice {
/**
* Interface to the BQ chip
*/
DEV::BQ76952 bq;
dev::BQ76952 bq;

/**
* The current state of the BMS
Expand All @@ -195,7 +197,7 @@ class BMS : public CANDevice {
/**
* The interlock which is used to detect a cable plugged in
*/
DEV::Interlock& interlock;
dev::Interlock& interlock;

/**
* This GPIO is connected to the ALARM pin of the BQ
Expand Down Expand Up @@ -223,15 +225,20 @@ class BMS : public CANDevice {
*/
IO::GPIO& bmsOK;

/**
* LED to indicate an error in the BMS
*/
IO::GPIO& errorLed;

/**
* Multiplexer to handle pack thermistors
*/
DEV::ThermistorMux thermistorMux;
dev::ThermistorMux thermistorMux;

/**
* Internal watchdog to detect STM hang
*/
EVT::core::DEV::IWDG& iwdg;
core::dev::IWDG& iwdg;

/**
* Boolean flag which represents that a state has just changed
Expand Down Expand Up @@ -318,7 +325,7 @@ class BMS : public CANDevice {
* by reading the voltage from the BQ chip and is then exposed over
* CANopen.
*/
uint16_t cellVoltage[DEV::BQ76952::NUM_CELLS] = {};
uint16_t cellVoltage[dev::BQ76952::NUM_CELLS] = {};

/**
* Used to store values which the BMS updates.
Expand Down
2 changes: 1 addition & 1 deletion include/BMSCANOpenMacros.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <EVT/io/CANOpenMacros.hpp>
#include <core/io/CANOpenMacros.hpp>

/**
* This macro creates a TPDO settings object for an extra node on a single
Expand Down
14 changes: 7 additions & 7 deletions include/BQSettingStorage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <cstdint>

#include <EVT/dev/storage/M24C32.hpp>
#include <core/dev/storage/M24C32.hpp>

#include <BQSetting.hpp>
#include <dev/BQ76952.hpp>
Expand Down Expand Up @@ -37,7 +37,7 @@ class BQSettingsStorage {
* @param eeprom EEPROM instance that stores settings
* @param bq BQ instance to send settings to
*/
BQSettingsStorage(EVT::core::DEV::M24C32& eeprom, DEV::BQ76952& bq);
BQSettingsStorage(core::dev::M24C32& eeprom, dev::BQ76952& bq);

/**
* Get the number of settings stored for the BQ
Expand Down Expand Up @@ -94,7 +94,7 @@ class BQSettingsStorage {
*
* @return The EEPROM instance
*/
EVT::core::DEV::M24C32& getEEPROM();
core::dev::M24C32& getEEPROM();

/**
* Reset the transfer setting logic
Expand Down Expand Up @@ -126,7 +126,7 @@ class BQSettingsStorage {
* @param[out] isComplete Flag that represents all settings have been transferred
* @return The resulting status of the transfer operation
*/
BMS::DEV::BQ76952::Status transferSetting(bool& isComplete);
dev::BQ76952::Status transferSetting(bool& isComplete);

/**
* Check if the settings are stored and can be used
Expand Down Expand Up @@ -158,11 +158,11 @@ class BQSettingsStorage {
/**
* EEPROM for storing the BQ settings.
*/
EVT::core::DEV::M24C32& eeprom;
core::dev::M24C32& eeprom;
/**
* The BQ chip interface
*/
DEV::BQ76952& bq;
dev::BQ76952& bq;
/**
* This is a count of the number of settings that have been written into
* EEPROM. This is used for determining if all the settings have been
Expand All @@ -175,7 +175,7 @@ class BQSettingsStorage {
*/
uint16_t numSettingsTransferred = 0;

friend class BMS;
friend class bms;
};

}// namespace BMS
6 changes: 3 additions & 3 deletions include/ResetHandler.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <EVT/io/types/CANMessage.hpp>
#include <core/io/types/CANMessage.hpp>

namespace BMS {

Expand All @@ -19,7 +19,7 @@ class ResetHandler {
*
* @param msg Message to register
*/
void registerInput(EVT::core::IO::CANMessage msg);
void registerInput(core::io::CANMessage msg);

/**
* Check whether reset messages have been received, indicating that the BMS
Expand All @@ -43,7 +43,7 @@ class ResetHandler {
{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};

/** Array of last MSG_HIST_LEN messages received */
EVT::core::IO::CANMessage msgHistory[MSG_HIST_LEN] = {};
core::io::CANMessage msgHistory[MSG_HIST_LEN] = {};
/** Index of the last registered message */
uint8_t lastRegMsgIndex = 0;
};
Expand Down
21 changes: 15 additions & 6 deletions include/dev/BQ76952.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#pragma once

#include <EVT/io/I2C.hpp>
#include <core/io/I2C.hpp>
#include <core/io/GPIO.hpp>

#include <BMSInfo.hpp>
#include <BQSetting.hpp>

#include <co_obj.h>

namespace BMS::DEV {
namespace BMS::dev {

/**
* Represents the functionality of the BQ76952. This is a layer of abstraction
Expand Down Expand Up @@ -48,8 +49,9 @@ class BQ76952 {
*
* @param[in] i2c I2C interface to use to communicate on the bus
* @param[in] i2cAddress The address of the BQ76952 to use
* @param[in] resetPin GPIO instance to reset the BQ
*/
BQ76952(EVT::core::IO::I2C& i2c, uint8_t i2cAddress);
BQ76952(core::io::I2C& i2c, uint8_t i2cAddress, core::io::GPIO& resetPin);

/**
* Write out the given setting
Expand Down Expand Up @@ -225,6 +227,11 @@ class BQ76952 {
*/
Status getBQStatus(uint8_t bqStatusArr[7]);

/**
* Reset the BQ
*/
void reset();

/** CANopen interface for probing the state of the balancing */
//CO_OBJ_TYPE balancingCANOpen;

Expand Down Expand Up @@ -278,9 +285,11 @@ class BQ76952 {
static constexpr uint16_t BQ_ID = 0x7695;

/** I2C bus to communicate over */
EVT::core::IO::I2C& i2c;
/** The address of the BQ76952 on the I2C bus */
core::io::I2C& i2c;
/** The address of the BQ on the I2C bus */
uint8_t i2cAddress;
/** Reset pin of the BQ */
core::io::GPIO& resetPin;
};

}// namespace BMS::DEV
}// namespace BMS::dev
Loading
Loading