Skip to content
Draft
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
12 changes: 8 additions & 4 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,8 +30,8 @@ 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
Expand All @@ -44,6 +44,10 @@ jobs:
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 +61,4 @@ jobs:
git config --global user.name "GitHub Build"
git commit -a -m "Applied Formatting Changes During GitHub Build"
git push origin
fi
fi
29 changes: 19 additions & 10 deletions include/BMS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,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,17 +74,19 @@ 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
* @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, DEV::BQ76952 bq, DEV::Interlock& interlock,
IO::GPIO& alarm, SystemDetect& systemDetect, IO::GPIO& bmsOK,
IO::GPIO& alarm, SystemDetect& systemDetect, IO::GPIO& bmsOK, IO::GPIO& errorLed,
DEV::ThermistorMux& thermMux, ResetHandler& resetHandler, EVT::core::DEV::IWDG& iwdg);

/**
Expand Down Expand Up @@ -223,6 +227,11 @@ class BMS : public CANDevice {
*/
IO::GPIO& bmsOK;

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

/**
* Multiplexer to handle pack thermistors
*/
Expand Down
13 changes: 11 additions & 2 deletions include/dev/BQ76952.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

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

#include <BMSInfo.hpp>
#include <BQSetting.hpp>
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(EVT::core::IO::I2C& i2c, uint8_t i2cAddress, EVT::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 @@ -279,8 +286,10 @@ class BQ76952 {

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

}// namespace BMS::DEV
12 changes: 10 additions & 2 deletions src/BMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ namespace BMS {

BMS::BMS(BQSettingsStorage& bqSettingsStorage, DEV::BQ76952 bq,
DEV::Interlock& interlock, IO::GPIO& alarm, SystemDetect& systemDetect,
IO::GPIO& bmsOK, DEV::ThermistorMux& thermMux,
IO::GPIO& bmsOK, IO::GPIO& errorLed, DEV::ThermistorMux& thermMux,
ResetHandler& resetHandler, EVT::core::DEV::IWDG& iwdg) : bqSettingsStorage(bqSettingsStorage),
bq(bq), state(State::START), interlock(interlock),
alarm(alarm), systemDetect(systemDetect), resetHandler(resetHandler),
bmsOK(bmsOK), thermistorMux(thermMux), iwdg(iwdg), stateChanged(true) {
bmsOK(bmsOK), errorLed(errorLed), thermistorMux(thermMux),
iwdg(iwdg), stateChanged(true) {
bmsOK.writePin(IO::GPIO::State::LOW);
errorLed.writePin(IO::GPIO::State::LOW);

updateBQData();
}
Expand Down Expand Up @@ -194,6 +196,7 @@ void BMS::startState() {
void BMS::initializationErrorState() {
if (stateChanged) {
bmsOK.writePin(BMS_NOT_OK);
errorLed.writePin(IO::GPIO::State::HIGH);
stateChanged = false;
clearVoltageReadings();
log::LOGGER.log(log::Logger::LogLevel::INFO, "Entering initialization error state");
Expand All @@ -202,6 +205,8 @@ void BMS::initializationErrorState() {
updateThermistorReading();

if (resetHandler.shouldReset()) {
bq.reset();
errorLed.writePin(IO::GPIO::State::LOW);
state = State::START;
stateChanged = true;
}
Expand Down Expand Up @@ -302,6 +307,7 @@ void BMS::systemReadyState() {
void BMS::unsafeConditionsError() {
if (stateChanged) {
bmsOK.writePin(BMS_NOT_OK);
errorLed.writePin(IO::GPIO::State::HIGH);
stateChanged = false;
log::LOGGER.log(log::Logger::LogLevel::INFO, "Entering unsafe conditions state");
}
Expand All @@ -310,6 +316,8 @@ void BMS::unsafeConditionsError() {
updateThermistorReading();

if (resetHandler.shouldReset()) {
bq.reset();
errorLed.writePin(IO::GPIO::State::LOW);
state = State::START;
stateChanged = true;
}
Expand Down
14 changes: 12 additions & 2 deletions src/dev/BQ76952.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static CO_ERR COBalancingCtrl(CO_OBJ* obj, CO_NODE_T* node, uint16_t func,
*/
namespace BMS::DEV {

BQ76952::BQ76952(EVT::core::IO::I2C& i2c, uint8_t i2cAddress) : /*
BQ76952::BQ76952(EVT::core::IO::I2C& i2c, uint8_t i2cAddress, EVT::core::IO::GPIO& resetPin) : /*
balancingCANOpen{
COBQBalancingSize,
COBalancingCtrl,
Expand All @@ -154,7 +154,10 @@ BQ76952::BQ76952(EVT::core::IO::I2C& i2c, uint8_t i2cAddress) : /*
this,
},
*/
i2c(i2c), i2cAddress(i2cAddress) {}
i2c(i2c), i2cAddress(i2cAddress), resetPin(resetPin) {
// Ensure the pin is initialized to low, so it doesn't reset or shut down the BQ
resetPin.writePin(EVT::core::IO::GPIO::State::LOW);
}

BQ76952::Status BQ76952::writeSetting(BMS::BQSetting& setting) {
// Right now, the BQ only accepts settings made into RAM
Expand Down Expand Up @@ -495,4 +498,11 @@ BQ76952::Status BQ76952::getBQStatus(uint8_t bqStatusArr[7]) {
return BQ76952::Status::OK;
}

void BQ76952::reset() {
resetPin.writePin(EVT::core::IO::GPIO::State::HIGH);
// Wait an arbitrary amount of time to ensure the BQ actually resets
EVT::core::time::wait(10);
resetPin.writePin(EVT::core::IO::GPIO::State::LOW);
}

}// namespace BMS::DEV
10 changes: 7 additions & 3 deletions targets/DEV1-BMS/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int main() {
// TODO: Investigate adding CAN filters
IO::CAN& can = IO::getCAN<BMS::BMS::CAN_TX_PIN, BMS::BMS::CAN_RX_PIN>();
can.addIRQHandler(canInterruptHandler, reinterpret_cast<void*>(&canParams));
IO::UART& uart = IO::getUART<BMS::BMS::UART_TX_PIN, BMS::BMS::UART_RX_PIN>(115200, true);
IO::UART& uart = IO::getUART<BMS::BMS::UART_TX_PIN, BMS::BMS::UART_RX_PIN>(115200);
IO::I2C& i2c = IO::getI2C<BMS::BMS::I2C_SCL_PIN, BMS::BMS::I2C_SDA_PIN>();

// Initialize the timer
Expand All @@ -100,7 +100,8 @@ int main() {
log::LOGGER.setLogLevel(log::Logger::LogLevel::INFO);

// Initialize the BQ interfaces
BMS::DEV::BQ76952 bq(i2c, 0x08);
IO::GPIO& bqReset = IO::getGPIO<BMS::BMS::BQ_RESET_PIN>();
BMS::DEV::BQ76952 bq(i2c, 0x08, bqReset);
BMS::BQSettingsStorage bqSettingsStorage(eeprom, bq);

// Initialize the Interlock
Expand All @@ -113,6 +114,9 @@ int main() {
// Initialize the system OK pin
IO::GPIO& bmsOK = IO::getGPIO<BMS::BMS::OK_PIN>(IO::GPIO::Direction::OUTPUT);

// Initialize the error LED pin
IO::GPIO& errorLed = IO::getGPIO<BMS::BMS::ERROR_LED_PIN>(IO::GPIO::Direction::OUTPUT);

// Initialize the thermistor MUX
IO::GPIO* muxSelectArr[3] = {
&IO::getGPIO<BMS::BMS::MUX_S1_PIN>(),
Expand All @@ -126,7 +130,7 @@ int main() {
DEV::IWDG& iwdg = DEV::getIWDG(500);

// Initialize the BMS itself
BMS::BMS bms(bqSettingsStorage, bq, interlock, alarm, systemDetect, bmsOK, thermMux, resetHandler, iwdg);
BMS::BMS bms(bqSettingsStorage, bq, interlock, alarm, systemDetect, bmsOK, errorLed, thermMux, resetHandler, iwdg);

///////////////////////////////////////////////////////////////////////////
// Setup CAN configuration, this handles making drivers, applying settings.
Expand Down
10 changes: 7 additions & 3 deletions targets/bms_canopen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int main() {
// Initialize IO
IO::CAN& can = IO::getCAN<BMS::BMS::CAN_TX_PIN, BMS::BMS::CAN_RX_PIN>();
can.addIRQHandler(canInterruptHandler, reinterpret_cast<void*>(&canParams));
IO::UART& uart = IO::getUART<BMS::BMS::UART_TX_PIN, BMS::BMS::UART_RX_PIN>(115200, true);
IO::UART& uart = IO::getUART<BMS::BMS::UART_TX_PIN, BMS::BMS::UART_RX_PIN>(115200);
IO::I2C& i2c = IO::getI2C<BMS::BMS::I2C_SCL_PIN, BMS::BMS::I2C_SDA_PIN>();

// Initialize the timer
Expand All @@ -100,7 +100,8 @@ int main() {
log::LOGGER.setLogLevel(log::Logger::LogLevel::DEBUG);

// Initialize the BQ interfaces
BMS::DEV::BQ76952 bq(i2c, 0x08);
IO::GPIO& bqReset = IO::getGPIO<BMS::BMS::BQ_RESET_PIN>();
BMS::DEV::BQ76952 bq(i2c, 0x08, bqReset);
BMS::BQSettingsStorage bqSettingsStorage(eeprom, bq);

// Initialize the Interlock
Expand All @@ -113,6 +114,9 @@ int main() {
// Initialize the system OK pin
IO::GPIO& bmsOK = IO::getGPIO<BMS::BMS::OK_PIN>(IO::GPIO::Direction::OUTPUT);

// Initialize the error LED pin
IO::GPIO& errorLed = IO::getGPIO<BMS::BMS::ERROR_LED_PIN>(IO::GPIO::Direction::OUTPUT);

// Initialize the thermistor MUX
IO::GPIO* muxSelectArr[3] = {
&IO::getGPIO<BMS::BMS::MUX_S1_PIN>(),
Expand All @@ -126,7 +130,7 @@ int main() {
DEV::IWDG& iwdg = DEV::getIWDG(500);

// Initialize the BMS itself
BMS::BMS bms(bqSettingsStorage, bq, interlock, alarm, systemDetect, bmsOK, thermMux, resetHandler, iwdg);
BMS::BMS bms(bqSettingsStorage, bq, interlock, alarm, systemDetect, bmsOK, errorLed, thermMux, resetHandler, iwdg);

///////////////////////////////////////////////////////////////////////////
// Setup CAN configuration, this handles making drivers, applying settings.
Expand Down
27 changes: 24 additions & 3 deletions targets/bq_interface/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void printHelp(IO::UART& uart) {
uart.printf(" i - Get interlock state\r\n");
uart.printf(" a - Get alarm state\r\n");
uart.printf(" o - Set OK signal output\r\n");
uart.printf(" e - Set error LED output\r\n");
uart.printf(" v - Read voltages\r\n");
uart.printf(" t - Transfer settings\r\n");

Expand Down Expand Up @@ -319,7 +320,7 @@ void exitConfigMode(IO::UART& uart, BMS::DEV::BQ76952& bq) {
void getTemperatures(IO::UART& uart, BMS::DEV::BQ76952& bq, BMS::DEV::ThermistorMux tMux) {
for (uint8_t i = 0; i < 6; i++) {
uint16_t temp = tMux.getTemp(i);
uart.printf("Thermistor %d: %d.%03d\r\n", i, temp / 1000, temp % 1000);
uart.printf("Thermistor %d: %d\r\n", i, temp);
}
uint16_t result;
bq.makeDirectRead(0x68, &result);
Expand Down Expand Up @@ -354,6 +355,19 @@ void setOK(IO::UART& uart, IO::GPIO& bmsOK) {
}
}

void setError(IO::UART& uart, IO::GPIO& errorLed) {
uart.printf("Set error LED pin (0/1): ");
uart.printf("\r\n");
uart.gets(inputBuffer, MAX_BUFF);
if (inputBuffer[0] == '1') {
errorLed.writePin(IO::GPIO::State::HIGH);
uart.printf("Set error LED high\r\n");
} else {
errorLed.writePin(IO::GPIO::State::LOW);
uart.printf("Set error LED low\r\n");
}
}

void getVoltages(IO::UART& uart, BMS::DEV::BQ76952& bq) {
uint16_t tot = 0;
for (uint8_t i = 0; i < 16; i++) {
Expand Down Expand Up @@ -415,10 +429,11 @@ int main() {
EVT::core::platform::init();

IO::I2C& i2c = IO::getI2C<BMS::BMS::I2C_SCL_PIN, BMS::BMS::I2C_SDA_PIN>();
BMS::DEV::BQ76952 bq(i2c, 0x08);
IO::GPIO& bqReset = IO::getGPIO<BMS::BMS::BQ_RESET_PIN>();
BMS::DEV::BQ76952 bq(i2c, 0x08, bqReset);
EVT::core::DEV::M24C32 eeprom(0x57, i2c);

IO::UART& uart = IO::getUART<BMS::BMS::UART_TX_PIN, BMS::BMS::UART_RX_PIN>(115200, true);
IO::UART& uart = IO::getUART<BMS::BMS::UART_TX_PIN, BMS::BMS::UART_RX_PIN>(115200);
log::LOGGER.setUART(&uart);
log::LOGGER.setLogLevel(log::Logger::LogLevel::DEBUG);

Expand All @@ -438,6 +453,8 @@ int main() {

IO::GPIO& bmsOK = IO::getGPIO<BMS::BMS::OK_PIN>(IO::GPIO::Direction::OUTPUT);

IO::GPIO& errorLed = IO::getGPIO<BMS::BMS::ERROR_LED_PIN>(IO::GPIO::Direction::OUTPUT);

time::wait(500);

while (true) {
Expand Down Expand Up @@ -519,6 +536,10 @@ int main() {
case 'o':
setOK(uart, bmsOK);
break;
// Set OK signal output
case 'e':
setError(uart, errorLed);
break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion targets/bq_settings/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void serializeDeserializeTest(IO::UART& uart) {
int main() {
EVT::core::platform::init();

IO::UART& uart = IO::getUART<BMS::BMS::UART_TX_PIN, BMS::BMS::UART_RX_PIN>(115200, true);
IO::UART& uart = IO::getUART<BMS::BMS::UART_TX_PIN, BMS::BMS::UART_RX_PIN>(115200);

uart.printf("\r\n\r\nBQ SETTING TEST\r\n");

Expand Down
5 changes: 3 additions & 2 deletions targets/eeprom_dump/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace log = EVT::core::log;
int main() {
EVT::core::platform::init();

IO::UART& uart = IO::getUART<BMS::BMS::UART_TX_PIN, BMS::BMS::UART_RX_PIN>(115200, true);
IO::UART& uart = IO::getUART<BMS::BMS::UART_TX_PIN, BMS::BMS::UART_RX_PIN>(115200);

uart.printf("\r\n\r\nEEPROM Dump\r\n");

Expand All @@ -29,7 +29,8 @@ int main() {
log::LOGGER.setUART(&uart);
log::LOGGER.setLogLevel(log::Logger::LogLevel::DEBUG);

BMS::DEV::BQ76952 bq(i2c, 0x08);
IO::GPIO& bqReset = IO::getGPIO<BMS::BMS::BQ_RESET_PIN>();
BMS::DEV::BQ76952 bq(i2c, 0x08, bqReset);
BMS::BQSettingsStorage bqSettingsStorage(eeprom, bq);
bqSettingsStorage.resetEEPROMOffset();

Expand Down
Loading
Loading