Skip to content

Commit

Permalink
Cold Boot Proof of Concept (#58)
Browse files Browse the repository at this point in the history
Graceful Cold Boot PoC
  • Loading branch information
doppelhub authored Jul 24, 2024
1 parent 90a56ab commit 0705b6b
Show file tree
Hide file tree
Showing 56 changed files with 222 additions and 145 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
16U2 toggle PD7 ~2.5 seconds after powerup. This causes pulse on MEGA2560's reset pin, which briefly disables Mega's output pins... but for some reason doesn't actually reset program execution.

This only occurs when USB cable is connected during powerup. Given that a USB cable typically powers the 5V rail, this won't actually ever occur; in my testing that lead to this CAR, my USB cable's 5V wire was cut.
8 changes: 5 additions & 3 deletions Firmware/firmwareLiBCM/config.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Copyright 2021-2023(c) John Sullivan
//Copyright 2021-2024(c) John Sullivan
//github.com/doppelhub/Honda_Insight_LiBCM

//config.h - compile time configuration parameters
Expand All @@ -7,8 +7,8 @@
#define config_h
#include "src/libcm.h"

#define FW_VERSION "0.9.4b"
#define BUILD_DATE "2024JUL09"
#define FW_VERSION "0.9.4d"
#define BUILD_DATE "2024JUL23"

//////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -46,6 +46,8 @@
#define LCD_4X20_CONNECTED //display included with all LiBCM Kits
//#define LIDISPLAY_CONNECTED //optional color touch screen display //JTS2doLater: mudder has not yet tested this code. Use at your own risk.

//you don't need to change any settings below this line (but you can if you know what you're doing):
//__________________________________________________________________________________________________

//////////////////////////////////////////////////////////////////

Expand Down
21 changes: 10 additions & 11 deletions Firmware/firmwareLiBCM/firmwareLiBCM.ino
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
//Copyright 2021-2023(c) John Sullivan
//Copyright 2021-2024(c) John Sullivan
//github.com/doppelhub/Honda_Insight_LiBCM
//Lithium battery BMS for G1 Honda Insight. Replaces OEM BCM module.

#include "src/libcm.h"

void setup() //~t=2 milliseconds, BUT NOTE this doesn't include CPU_CLOCK warmup or bootloader delay
void setup()
{
//getting here takes ~02 milliseconds after poweron reset
//getting here takes ~16 milliseconds after IMA switch on
gpio_begin();
wdt_disable();
LiControl_begin(); //SPI errors until initialized
LTC68042configure_initialize();
Serial.begin(115200); //USB
METSCI_begin();
BATTSCI_begin();
heater_begin();
LiDisplay_begin();
LiControl_begin();
LTC68042configure_initialize();
eeprom_begin();
LiDisplay_begin();

if (gpio_keyStateNow() == GPIO_KEY_ON) { keyOn_coldBootTasks(); }
else { debugUSB_printWelcomeMessage(); }

bringupTester_gridcharger();
bringupTester_motherboard();

if (gpio_keyStateNow() == GPIO_KEY_ON){ LED(3,ON); } //turn LED3 on if LiBCM (re)boots while driving

Serial.print(F("\n\nLiBCM v" FW_VERSION ", " BUILD_DATE "\n'$HELP' for info\n"));
debugUSB_printHardwareRevision();
debugUSB_printConfigParameters();

wdt_enable(WDTO_2S); //set watchdog reset vector to 2 seconds
}

Expand Down
2 changes: 1 addition & 1 deletion Firmware/firmwareLiBCM/src/BringupTester.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Copyright 2021-2023(c) John Sullivan
//Copyright 2021-2024(c) John Sullivan
//Tests PCB (using custom external hardware)

//Not used when deployed in vehicle
Expand Down
2 changes: 1 addition & 1 deletion Firmware/firmwareLiBCM/src/BringupTester.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Copyright 2021-2023(c) John Sullivan
//Copyright 2021-2024(c) John Sullivan
//github.com/doppelhub/Honda_Insight_LiBCM

#ifndef bringuptester_h
Expand Down
4 changes: 2 additions & 2 deletions Firmware/firmwareLiBCM/src/LTC68042cell.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Copyright 2021-2023(c) John Sullivan
//Copyright 2021-2024(c) John Sullivan
//github.com/doppelhub/Honda_Insight_LiBCM

//LTC6804 cell voltage data processor and related functions
Expand Down Expand Up @@ -289,7 +289,7 @@ bool LTC68042cell_nextVoltages(void)
else if (presentState == LTC_STATE_FIRSTRUN)
{
//LTC6804 ICs were previously off
LTC68042configure_programVolatileDefaults();
LTC68042configure_programVolatileDefaults();
startCellConversion();
presentState = LTC_STATE_GATHER;
}
Expand Down
4 changes: 3 additions & 1 deletion Firmware/firmwareLiBCM/src/LTC68042cell.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Copyright 2021-2023(c) John Sullivan
//Copyright 2021-2024(c) John Sullivan
//github.com/doppelhub/Honda_Insight_LiBCM

#ifndef LTC68042cell_h
Expand All @@ -11,6 +11,8 @@
#define GATHERING_CELL_DATA 0
#define CELL_DATA_PROCESSED 1

#define LTC6804_MAX_CONVERSION_TIME_ms 5 //4.43 ms in '2kHz' sampling mode

bool LTC68042cell_nextVoltages(void);
void LTC68042cell_acquireAllCellVoltages(void);

Expand Down
92 changes: 48 additions & 44 deletions Firmware/firmwareLiBCM/src/LTC68042configure.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Copyright 2021-2023(c) John Sullivan
//Copyright 2021-2024(c) John Sullivan
//github.com/doppelhub/Honda_Insight_LiBCM

//LTC6804 configuration functions
Expand Down Expand Up @@ -103,46 +103,50 @@ bool LTC68042configure_doesActualPackSizeMatchUserConfig(void)
{
bool helper_doesActualPackSizeMatchUserConfig = true;

if (gpio_keyStateNow() == GPIO_KEY_OFF) //we don't have time to run this test if the key is on when LiBCM first boots
{
LTC6804_adax(); //send any broadcast command
delay(6); //wait for all LTC6804 ICs to process this command
#if defined RUN_BRINGUP_TESTER_MOTHERBOARD //don't verify cell count
#elif defined RUN_BRINGUP_TESTER_GRIDCHARGER //don't verify cell count
#else
if (gpio_keyStateNow() == GPIO_KEY_OFF) //we don't have time to run this test if the key is on when LiBCM first boots
{
LTC6804_adax(); //send any broadcast command
delay(6); //wait for all LTC6804 ICs to process this command

//read data back from either QTY4 ICs (if user selects PACK_IS_48S in config.h), or QTY5 ICs (if user selects PACK_IS_60S in config.h)
//we don't care about the actual data; only that the PEC error count doesn't increment
uint8_t errorCount_allUserSpecifiedLTC6804s = LTC6804_rdaux(0,TOTAL_IC,FIRST_IC_ADDR);
//read data back from either QTY4 ICs (if user selects PACK_IS_48S in config.h), or QTY5 ICs (if user selects PACK_IS_60S in config.h)
//we don't care about the actual data; only that the PEC error count doesn't increment
uint8_t errorCount_allUserSpecifiedLTC6804s = LTC6804_rdaux(0,TOTAL_IC,FIRST_IC_ADDR);

if (errorCount_allUserSpecifiedLTC6804s != 0) { helper_doesActualPackSizeMatchUserConfig = false; } //at least one IC had data transmissions errors
if (errorCount_allUserSpecifiedLTC6804s != 0) { helper_doesActualPackSizeMatchUserConfig = false; } //at least one IC had data transmissions errors

if (TOTAL_IC == 4)
{
uint8_t errorCount_onlyFifthLTC6804 = LTC6804_rdaux(0,1,FIRST_IC_ADDR+4);
if (TOTAL_IC == 4)
{
uint8_t errorCount_onlyFifthLTC6804 = LTC6804_rdaux(0,1,FIRST_IC_ADDR+4);

//the fifth LTC6804 (cells 49:60) should be unpowered (i.e. it should return errors)
if (errorCount_onlyFifthLTC6804 == 0) { helper_doesActualPackSizeMatchUserConfig = false; }
}
//the fifth LTC6804 (cells 49:60) should be unpowered (i.e. it should return errors)
if (errorCount_onlyFifthLTC6804 == 0) { helper_doesActualPackSizeMatchUserConfig = false; }
}

if (helper_doesActualPackSizeMatchUserConfig == false)
{
//fatal error
//alert user and then turn off
if (helper_doesActualPackSizeMatchUserConfig == false)
{
//fatal error
//alert user and then turn off

Serial.print(F("\nError: measured cell count disagrees with user specified cell count in config.h"));
Serial.print(F("\nError: measured cell count disagrees with user specified cell count in config.h"));

lcdTransmit_begin();
delay(50); //delay doesn't matter because this is a fatal error
lcdTransmit_displayOn();
delay(50); //delay doesn't matter because this is a fatal error
lcdTransmit_Warning(LCD_WARN_CELL_COUNT);
lcdTransmit_begin();
delay(50); //delay doesn't matter because this is a fatal error
lcdTransmit_displayOn();
delay(50); //delay doesn't matter because this is a fatal error
lcdTransmit_Warning(LCD_WARN_CELL_COUNT);

gpio_turnBuzzer_on_highFreq(); //call GPIO directly

wdt_disable(); //turn off watchdog to prevent reset
gpio_turnBuzzer_on_highFreq(); //call GPIO directly
wdt_disable(); //turn off watchdog to prevent reset

delay(10000); //give the user enough time to read error message
gpio_turnLiBCM_off(); //game over... thanks for playing
delay(10000); //give the user enough time to read error message
gpio_turnLiBCM_off(); //game over... thanks for playing
}
}
}
#endif

return helper_doesActualPackSizeMatchUserConfig;
}
Expand All @@ -152,12 +156,16 @@ bool LTC68042configure_doesActualPackSizeMatchUserConfig(void)
void LTC68042configure_initialize(void)
{
spi_enable(SPI_CLOCK_DIV64); //JTS2doLater: increase clock speed //DIV16 & DIV32 work on bench
}

#if defined RUN_BRINGUP_TESTER_MOTHERBOARD //don't verify cell count
#elif defined RUN_BRINGUP_TESTER_GRIDCHARGER //don't verify cell count
#else
LTC68042configure_doesActualPackSizeMatchUserConfig(); //verify cell count matches
#endif
/////////////////////////////////////////////////////////////////////////////////////////

void LTC68042configure_pulseChipSelectLow(uint16_t lowPulsePeriod_us)
{
digitalWrite(PIN_SPI_CS,LOW); //low edge wakes up LTC
delayMicroseconds(lowPulsePeriod_us); //wait specified time for LTC to wake
digitalWrite(PIN_SPI_CS,HIGH);
lastTimeDataSent_millis = millis();
}

/////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -172,10 +180,7 @@ bool LTC68042configure_wakeupCore(void)
if ((uint32_t)(millis() - lastTimeDataSent_millis) > T_SLEEP_WATCHDOG_MILLIS)
{
//LTC6804 core (probably) asleep
digitalWrite(PIN_SPI_CS,LOW); //wake up core
delayMicroseconds(300); // Guarantees the LTC6804 is in standby (tWake = 300 us max)
digitalWrite(PIN_SPI_CS,HIGH);
lastTimeDataSent_millis = millis();
LTC68042configure_pulseChipSelectLow(SPECIFIED_MAX_WAKEUP_TIME_LTCCORE_MICROSECONDS);
wasCoreAlreadyAwake = LTC6804_CORE_JUST_WOKE_UP;
}

Expand All @@ -192,10 +197,7 @@ void LTC68042configure_wakeupIsoSPI(void)
if ((uint32_t)(millis() - lastTimeDataSent_millis) > T_IDLE_isoSPI_MILLIS)
{
//LTC6804 isoSPI might be asleep (tIDLE elapsed)
digitalWrite(PIN_SPI_CS,LOW);
delayMicroseconds(10); //Guarantees isoSPI is in ready mode (tWAKE = 10 us max)
digitalWrite(PIN_SPI_CS,HIGH);
lastTimeDataSent_millis = millis();
LTC68042configure_pulseChipSelectLow(SPECIFIED_MAX_WAKEUP_TIME_isoSPI_MICROSECONDS);
}
}

Expand Down Expand Up @@ -254,6 +256,8 @@ void LTC68042configure_spiWriteRead(uint8_t tx_Data[],//array of data to be writ
for (uint8_t i = 0; i < tx_len; i++) { spi_write(tx_Data[i]); }
for (uint8_t i = 0; i < rx_len; i++) { rx_data[i] = (uint8_t)spi_read(0xFF); }
digitalWrite(PIN_SPI_CS,HIGH);

lastTimeDataSent_millis = millis();
}

/////////////////////////////////////////////////////////////////////////////////////////
Expand Down
8 changes: 7 additions & 1 deletion Firmware/firmwareLiBCM/src/LTC68042configure.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Copyright 2021-2023(c) John Sullivan
//Copyright 2021-2024(c) John Sullivan
//github.com/doppelhub/Honda_Insight_LiBCM

#ifndef LTC68042configure_h
Expand All @@ -25,6 +25,8 @@
#define FIRST_IC_ADDR 2 //lowest address. All additional IC addresses must be sequential
#define CELLS_PER_IC 12 //Each LTC6804 measures QTY12 cells

#define SPECIFIED_MAX_WAKEUP_TIME_LTCCORE_MICROSECONDS 300 //guarantees LTC6804 is in 'standby' mode (tWake = 300 us max)
#define SPECIFIED_MAX_WAKEUP_TIME_isoSPI_MICROSECONDS 10 //guarantees isoSPI is in 'ready' mode (tWAKE = 10 us max)

// |CHG | Dec |Channels to convert |
// |----|------|----------------------|
Expand Down Expand Up @@ -191,4 +193,8 @@

void LTC68042configure_setBalanceResistors(uint8_t icAddress, uint16_t cellBitmap, uint8_t softwareTimeout);

bool LTC68042configure_doesActualPackSizeMatchUserConfig(void);

void LTC68042configure_pulseChipSelectLow(uint16_t lowPulsePeriod_us);

#endif
2 changes: 1 addition & 1 deletion Firmware/firmwareLiBCM/src/LTC68042gpio.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Copyright 2021-2023(c) John Sullivan
//Copyright 2021-2024(c) John Sullivan
//github.com/doppelhub/Honda_Insight_LiBCM

//LTC6804 gpio (e.g. temperature) data and various functions
Expand Down
2 changes: 1 addition & 1 deletion Firmware/firmwareLiBCM/src/LTC68042gpio.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Copyright 2021-2023(c) John Sullivan
//Copyright 2021-2024(c) John Sullivan
//github.com/doppelhub/Honda_Insight_LiBCM

#ifndef LTC68042gpio_h
Expand Down
2 changes: 1 addition & 1 deletion Firmware/firmwareLiBCM/src/LTC68042result.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Copyright 2021-2023(c) John Sullivan
//Copyright 2021-2024(c) John Sullivan
//github.com/doppelhub/Honda_Insight_LiBCM

//The latest results gathered from LTC6804 are stored here.
Expand Down
2 changes: 1 addition & 1 deletion Firmware/firmwareLiBCM/src/LTC68042result.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Copyright 2021-2023(c) John Sullivan
//Copyright 2021-2024(c) John Sullivan
//github.com/doppelhub/Honda_Insight_LiBCM

#ifndef LTC68042result_h
Expand Down
2 changes: 1 addition & 1 deletion Firmware/firmwareLiBCM/src/LiControl.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Copyright 2021-2023(c) John Sullivan
//Copyright 2021-2024(c) John Sullivan
//github.com/doppelhub/Honda_Insight_LiBCM
#include "libcm.h"

Expand Down
2 changes: 1 addition & 1 deletion Firmware/firmwareLiBCM/src/LiControl.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Copyright 2021-2023(c) John Sullivan
//Copyright 2021-2024(c) John Sullivan
//github.com/doppelhub/Honda_Insight_LiBCM

#ifndef LiControl_h
Expand Down
3 changes: 1 addition & 2 deletions Firmware/firmwareLiBCM/src/LiDisplay.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Copyright 2021-2023(c) John Sullivan
//Copyright 2021-2024(c) John Sullivan
//github.com/doppelhub/Honda_Insight_LiBCM

//LiDisplay (HMI) Serial Functions
Expand Down Expand Up @@ -90,7 +90,6 @@ const uint16_t editableParamMinMax[2][2] = {
void LiDisplay_begin(void)
{
#ifdef LIDISPLAY_CONNECTED
Serial.print(F("\nLiDisplay BEGIN"));

#ifdef BATTERY_TYPE_47AhFoMoCo
#undef LIDISPLAY_GRIDCHARGE_PAGE_ID
Expand Down
2 changes: 1 addition & 1 deletion Firmware/firmwareLiBCM/src/LiDisplay.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Copyright 2021-2023(c) John Sullivan
//Copyright 2021-2024(c) John Sullivan
//github.com/doppelhub/Honda_Insight_LiBCM

#ifndef lidisplay_h
Expand Down
2 changes: 1 addition & 1 deletion Firmware/firmwareLiBCM/src/SoC.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Copyright 2021-2023(c) John Sullivan
//Copyright 2021-2024(c) John Sullivan
//github.com/doppelhub/Honda_Insight_LiBCM

//maintains battery state of charge
Expand Down
2 changes: 1 addition & 1 deletion Firmware/firmwareLiBCM/src/SoC.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Copyright 2021-2023(c) John Sullivan
//Copyright 2021-2024(c) John Sullivan
//github.com/doppelhub/Honda_Insight_LiBCM

#ifndef soc_h
Expand Down
Loading

0 comments on commit 0705b6b

Please sign in to comment.