From afec3d6d84e2bc5d15865ea76f9fc655e8cb104a Mon Sep 17 00:00:00 2001 From: khoulihan27 Date: Mon, 2 Mar 2026 13:11:03 -0800 Subject: [PATCH 01/17] init branch --- ECU/Application/Src/StateTicks.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ECU/Application/Src/StateTicks.c b/ECU/Application/Src/StateTicks.c index 27300853..6fb4320e 100644 --- a/ECU/Application/Src/StateTicks.c +++ b/ECU/Application/Src/StateTicks.c @@ -25,6 +25,7 @@ * * @remark Intentionally not a globally accessible variable */ + ECU_StateData stateLump = {.ecu_state = GR_GLV_ON, .bcu_software_latch = 1}; static uint32_t buzzer_start_millis; static uint32_t last_can_inverter_request_millis; From 6af659693ef99ee607858f5cb78896443f1536dd Mon Sep 17 00:00:00 2001 From: Thomas Xu Date: Mon, 2 Mar 2026 20:00:30 -0800 Subject: [PATCH 02/17] correct ordering of debug message logging --- ECU/Application/Src/StateTicks.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ECU/Application/Src/StateTicks.c b/ECU/Application/Src/StateTicks.c index 6fb4320e..4c10616f 100644 --- a/ECU/Application/Src/StateTicks.c +++ b/ECU/Application/Src/StateTicks.c @@ -87,15 +87,15 @@ void ECU_GLV_Off(ECU_StateData *stateData) void ECU_GLV_On(ECU_StateData *stateData) { if (stateData->ts_voltage >= SAFE_VOLTAGE_LIMIT) { - ECU_Transition_To_Tractive_System_Discharge(stateData); LOGOMATIC("Error: TS Voltage >= %d!\n", SAFE_VOLTAGE_LIMIT); + ECU_Transition_To_Tractive_System_Discharge(stateData); ECU_CAN_Send(GR_OLD_BUS_PRIMARY, GR_DEBUGGER, MSG_DEBUG_2_0, "TS-Runwy", 8); return; } if (stateData->ts_active_button_active /* && stateData->ir_plus*/) { // TODO: Talk to Owen if this is correct for precharge start confirmation - ECU_Transition_To_Precharge_Engaged(stateData); LOGOMATIC("GLV ON to PRECHARGE START!\n"); + ECU_Transition_To_Precharge_Engaged(stateData); return; } } @@ -119,9 +119,9 @@ void ECU_Precharge_Engaged(ECU_StateData *stateData) } if (!stateData->ts_active_button_active || CommunicationError(stateData)) { - ECU_Transition_To_Tractive_System_Discharge(stateData); LOGOMATIC("ERROR or ts_active OFF! PRECHARGE ENGAGED to TS DISCHARGE START!\n"); ECU_CAN_Send(GR_OLD_BUS_PRIMARY, GR_DEBUGGER, MSG_DEBUG_2_0, "TS-P-ITR", 8); + ECU_Transition_To_Tractive_System_Discharge(stateData); return; } } @@ -130,13 +130,13 @@ void ECU_Precharge_Engaged(ECU_StateData *stateData) void ECU_Precharge_Complete(ECU_StateData *stateData) { if (!stateData->ts_active_button_active) { - ECU_Transition_To_Tractive_System_Discharge(stateData); LOGOMATIC("TS Active Toggled Off. Discharging Tractive System.\n"); + ECU_Transition_To_Tractive_System_Discharge(stateData); return; } if (CriticalError(stateData)) { - ECU_Transition_To_Tractive_System_Discharge(stateData); LOGOMATIC("Error: Critical Error Occurred. Discharging Tractive System.\n"); + ECU_Transition_To_Tractive_System_Discharge(stateData); ECU_CAN_Send(GR_OLD_BUS_PRIMARY, GR_DEBUGGER, MSG_DEBUG_2_0, "HV-CritE", 8); return; } @@ -160,8 +160,8 @@ void ECU_Transition_To_Drive_Active(ECU_StateData *stateData) void ECU_Drive_Active(ECU_StateData *stateData) { if (!stateData->ts_active_button_active || CriticalError(stateData)) { - ECU_Transition_To_Tractive_System_Discharge(stateData); LOGOMATIC("Error: Critical Error Occured. Discharging Tractive System.\n"); + ECU_Transition_To_Tractive_System_Discharge(stateData); ECU_CAN_Send(GR_OLD_BUS_PRIMARY, GR_DEBUGGER, MSG_DEBUG_2_0, "DA-CritE", 8); return; } From 72f980d8b300be39310ed793cb05f713240148aa Mon Sep 17 00:00:00 2001 From: khoulihan27 Date: Mon, 2 Mar 2026 21:08:48 -0800 Subject: [PATCH 03/17] fixed discharge logic and CAN id --- ECU/Application/Src/CANutils.c | 3 ++- ECU/Application/Src/StateTicks.c | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ECU/Application/Src/CANutils.c b/ECU/Application/Src/CANutils.c index bbf562db..4b22d738 100644 --- a/ECU/Application/Src/CANutils.c +++ b/ECU/Application/Src/CANutils.c @@ -10,6 +10,7 @@ #include "can.h" #include "main.h" #include "string.h" +#include "stm32g4xx_hal_fdcan.h" uint32_t lastTickECUStateDataSent = 0; @@ -24,7 +25,7 @@ void ECU_CAN_Send(GR_OLD_BUS_ID bus, GR_OLD_NODE_ID destNode, GR_OLD_MSG_ID mess FDCAN_TxHeaderTypeDef header = { .Identifier = ID, - .IdType = FDCAN_STANDARD_ID, + .IdType = FDCAN_EXTENDED_ID, .TxFrameType = FDCAN_DATA_FRAME, .ErrorStateIndicator = FDCAN_ESI_ACTIVE, .DataLength = size, diff --git a/ECU/Application/Src/StateTicks.c b/ECU/Application/Src/StateTicks.c index 4c10616f..9258fa2e 100644 --- a/ECU/Application/Src/StateTicks.c +++ b/ECU/Application/Src/StateTicks.c @@ -27,8 +27,6 @@ */ ECU_StateData stateLump = {.ecu_state = GR_GLV_ON, .bcu_software_latch = 1}; -static uint32_t buzzer_start_millis; -static uint32_t last_can_inverter_request_millis; CANHandle *primary_can; CANHandle *data_can; @@ -150,10 +148,11 @@ void ECU_Precharge_Complete(ECU_StateData *stateData) } } +static uint32_t buzzer_start_millis; + void ECU_Transition_To_Drive_Active(ECU_StateData *stateData) { buzzer_start_millis = stateData->millisSinceBoot; - last_can_inverter_request_millis = stateData->millisSinceBoot; stateData->ecu_state = GR_DRIVE_ACTIVE; } @@ -195,6 +194,7 @@ void ECU_Drive_Active(ECU_StateData *stateData) torque_request = 0; } + static uint32_t last_can_inverter_request_millis; if (stateData->millisSinceBoot - last_can_inverter_request_millis > 10) { GR_OLD_INVERTER_COMMAND_MSG message = {.ac_current = torque_request * 100 + 32768, .dc_current = torque_request * 100 + 32768, .drive_enable = 1, .rpm_limit = 0}; ECU_CAN_Send(GR_OLD_BUS_PRIMARY, GR_GR_INVERTER_1, MSG_INVERTER_COMMAND, &message, sizeof(message)); @@ -229,4 +229,13 @@ void ECU_Tractive_System_Discharge(ECU_StateData *stateData) LOGOMATIC("Warning: Tractive System fails to discharge in time.\n"); ECU_CAN_Send(GR_OLD_BUS_PRIMARY, GR_DEBUGGER, MSG_DEBUG_2_0, "TS-D-TLE", 8); } + + // Discharge the car @ 100 Hz + static uint32_t last_discharge_request_millis; + if (stateData->millisSinceBoot - last_discharge_request_millis > 10) { + GR_OLD_BCU_PRECHARGE_MSG message = {.precharge = 0}; + ECU_CAN_Send(GR_OLD_BUS_PRIMARY, GR_BCU, MSG_BCU_PRECHARGE, &message, sizeof(message)); + last_discharge_request_millis = stateData->millisSinceBoot; + } + } From 69f028a9bb8c92f3fad42bc49c0dde6fef313ef7 Mon Sep 17 00:00:00 2001 From: khoulihan27 Date: Mon, 2 Mar 2026 21:49:10 -0800 Subject: [PATCH 04/17] added comment --- ECU/Core/Src/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ECU/Core/Src/main.c b/ECU/Core/Src/main.c index 3ea450de..48641c49 100644 --- a/ECU/Core/Src/main.c +++ b/ECU/Core/Src/main.c @@ -436,6 +436,7 @@ int main(void) if (MillisecondsSinceBoot() >= nextPing) { pingAll(); + // TODO: implement error handling if (nextPing != 0) { if (getRTT(GR_BCU) == PINGTIMEOUT_VALUE) { LOGOMATIC("ERROR: BCU is not responding to pings!\n"); From bed719250393f14243b9978abb28c79ae75e48ca Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 3 Mar 2026 05:09:53 +0000 Subject: [PATCH 05/17] Automatic Clang-Format: Standardized formatting automatically --- ECU/Application/Src/CANutils.c | 2 +- ECU/Application/Src/StateTicks.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/ECU/Application/Src/CANutils.c b/ECU/Application/Src/CANutils.c index 4b22d738..36fd4ca5 100644 --- a/ECU/Application/Src/CANutils.c +++ b/ECU/Application/Src/CANutils.c @@ -9,8 +9,8 @@ #include "StateUtils.h" #include "can.h" #include "main.h" -#include "string.h" #include "stm32g4xx_hal_fdcan.h" +#include "string.h" uint32_t lastTickECUStateDataSent = 0; diff --git a/ECU/Application/Src/StateTicks.c b/ECU/Application/Src/StateTicks.c index 9258fa2e..5f30a954 100644 --- a/ECU/Application/Src/StateTicks.c +++ b/ECU/Application/Src/StateTicks.c @@ -237,5 +237,4 @@ void ECU_Tractive_System_Discharge(ECU_StateData *stateData) ECU_CAN_Send(GR_OLD_BUS_PRIMARY, GR_BCU, MSG_BCU_PRECHARGE, &message, sizeof(message)); last_discharge_request_millis = stateData->millisSinceBoot; } - } From b39c345fa5434cfdc28a84716b32c762e2726881 Mon Sep 17 00:00:00 2001 From: Thomas Xu Date: Thu, 5 Mar 2026 20:24:40 -0800 Subject: [PATCH 06/17] reduce some bloat in StateData --- ECU/Application/Inc/StateData.h | 3 --- ECU/Application/Src/StateTicks.c | 25 ++++++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ECU/Application/Inc/StateData.h b/ECU/Application/Inc/StateData.h index 641d0389..8f381044 100644 --- a/ECU/Application/Inc/StateData.h +++ b/ECU/Application/Inc/StateData.h @@ -51,11 +51,8 @@ typedef volatile struct ECU_StateData { // TODO: Remove unneeded states - uint32_t millisSinceBoot; uint32_t can_msg_cooldown_tick; - int32_t dischargeStartMillis; - uint32_t lastECUStatusMsgMillis; uint32_t lastTSSIFlash; int32_t last_drive_active_control_ms; diff --git a/ECU/Application/Src/StateTicks.c b/ECU/Application/Src/StateTicks.c index 5f30a954..a4bcdcfd 100644 --- a/ECU/Application/Src/StateTicks.c +++ b/ECU/Application/Src/StateTicks.c @@ -35,13 +35,15 @@ CANHandle *data_can; // EV.5.6.3: The Discharge Circuit must be designed to handle the maximum Tractive System voltage for minimum 15 seconds #define TRACTIVE_SYSTEM_MAX_PERMITTED_DISCHARGE_TIME_MILLIS (15000) +static uint32_t millis_since_boot; void ECU_State_Tick(void) { - stateLump.millisSinceBoot = MillisecondsSinceBoot(); + millis_since_boot = MillisecondsSinceBoot(); - if (stateLump.millisSinceBoot - stateLump.lastECUStatusMsgMillis >= ECU_STATUS_MSG_PERIOD_MILLIS) { + static uint32_t last_ECU_status_msg_millis; + if (millis_since_boot - last_ECU_status_msg_millis >= ECU_STATUS_MSG_PERIOD_MILLIS) { LOGOMATIC("ECU Current State: %d\n", stateLump.ecu_state); - stateLump.lastECUStatusMsgMillis = stateLump.millisSinceBoot; + last_ECU_status_msg_millis = millis_since_boot; } if (bmsFailure(&stateLump) || imdFailure(&stateLump)) { @@ -152,7 +154,7 @@ static uint32_t buzzer_start_millis; void ECU_Transition_To_Drive_Active(ECU_StateData *stateData) { - buzzer_start_millis = stateData->millisSinceBoot; + buzzer_start_millis = millis_since_boot; stateData->ecu_state = GR_DRIVE_ACTIVE; } @@ -165,7 +167,7 @@ void ECU_Drive_Active(ECU_StateData *stateData) return; } - if (stateData->millisSinceBoot - buzzer_start_millis > 2000) { + if (millis_since_boot - buzzer_start_millis > 2000) { LL_GPIO_ResetOutputPin(RTD_CONTROL_GPIO_Port, RTD_CONTROL_Pin); } else { LL_GPIO_SetOutputPin(RTD_CONTROL_GPIO_Port, RTD_CONTROL_Pin); @@ -195,20 +197,21 @@ void ECU_Drive_Active(ECU_StateData *stateData) } static uint32_t last_can_inverter_request_millis; - if (stateData->millisSinceBoot - last_can_inverter_request_millis > 10) { + if (millis_since_boot - last_can_inverter_request_millis > 10) { GR_OLD_INVERTER_COMMAND_MSG message = {.ac_current = torque_request * 100 + 32768, .dc_current = torque_request * 100 + 32768, .drive_enable = 1, .rpm_limit = 0}; ECU_CAN_Send(GR_OLD_BUS_PRIMARY, GR_GR_INVERTER_1, MSG_INVERTER_COMMAND, &message, sizeof(message)); - last_can_inverter_request_millis = stateData->millisSinceBoot; + last_can_inverter_request_millis = millis_since_boot; } } +static uint32_t discharge_start_millis; void ECU_Transition_To_Tractive_System_Discharge(ECU_StateData *stateData) { stateData->ecu_state = GR_TS_DISCHARGE; LOGOMATIC("ECU: BCU discharge Tractive System\n"); GR_OLD_BCU_PRECHARGE_MSG message = {.precharge = 0}; ECU_CAN_Send(GR_OLD_BUS_PRIMARY, GR_BCU, MSG_BCU_PRECHARGE, &message, sizeof(message)); - stateData->dischargeStartMillis = stateData->millisSinceBoot; + discharge_start_millis = millis_since_boot; } void ECU_Tractive_System_Discharge(ECU_StateData *stateData) @@ -225,16 +228,16 @@ void ECU_Tractive_System_Discharge(ECU_StateData *stateData) If TS fails to discharge over time then stay and emit a warning, see #129 */ - if (stateData->millisSinceBoot - stateData->dischargeStartMillis > TRACTIVE_SYSTEM_MAX_PERMITTED_DISCHARGE_TIME_MILLIS) { + if (millis_since_boot - discharge_start_millis > TRACTIVE_SYSTEM_MAX_PERMITTED_DISCHARGE_TIME_MILLIS) { LOGOMATIC("Warning: Tractive System fails to discharge in time.\n"); ECU_CAN_Send(GR_OLD_BUS_PRIMARY, GR_DEBUGGER, MSG_DEBUG_2_0, "TS-D-TLE", 8); } // Discharge the car @ 100 Hz static uint32_t last_discharge_request_millis; - if (stateData->millisSinceBoot - last_discharge_request_millis > 10) { + if (millis_since_boot - last_discharge_request_millis > 10) { GR_OLD_BCU_PRECHARGE_MSG message = {.precharge = 0}; ECU_CAN_Send(GR_OLD_BUS_PRIMARY, GR_BCU, MSG_BCU_PRECHARGE, &message, sizeof(message)); - last_discharge_request_millis = stateData->millisSinceBoot; + last_discharge_request_millis = millis_since_boot; } } From ccdfc8bda19c1f9315b37a7ee700aa6e06973d88 Mon Sep 17 00:00:00 2001 From: Thomas Xu Date: Thu, 5 Mar 2026 20:42:21 -0800 Subject: [PATCH 07/17] Reduce all timing-related states in StateData Co-authored-by: khoulihan27 --- ECU/Application/Inc/StateData.h | 5 ----- ECU/Application/Src/Lights.c | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/ECU/Application/Inc/StateData.h b/ECU/Application/Inc/StateData.h index 8f381044..2cab5243 100644 --- a/ECU/Application/Inc/StateData.h +++ b/ECU/Application/Inc/StateData.h @@ -51,11 +51,6 @@ typedef volatile struct ECU_StateData { // TODO: Remove unneeded states - uint32_t can_msg_cooldown_tick; - - uint32_t lastTSSIFlash; - int32_t last_drive_active_control_ms; - float min_amk_heat_cap_throttle_percent; float ts_voltage; float max_cell_temp_c; /** Temperature of hottest cell, celsius */ diff --git a/ECU/Application/Src/Lights.c b/ECU/Application/Src/Lights.c index 48f1f63b..a6be65a5 100644 --- a/ECU/Application/Src/Lights.c +++ b/ECU/Application/Src/Lights.c @@ -23,7 +23,7 @@ void TSSILightControl(ECU_StateData *stateLump) // Here we chose a period of 350ms if (stateLump->tssi_fault) { LL_GPIO_ResetOutputPin(TSSI_G_CONTROL_GPIO_Port, TSSI_G_CONTROL_Pin); - if (stateLump->millisSinceBoot % 350 < 175) { + if (MillisecondsSinceBoot() % 350 < 175) { LL_GPIO_SetOutputPin(TSSI_R_CONTROL_GPIO_Port, TSSI_R_CONTROL_Pin); } else { LL_GPIO_ResetOutputPin(TSSI_R_CONTROL_GPIO_Port, TSSI_R_CONTROL_Pin); From b850f642c3791b0fceca78dc2484742e6d6d9478 Mon Sep 17 00:00:00 2001 From: Casey Zwicker Date: Thu, 5 Mar 2026 20:54:16 -0800 Subject: [PATCH 08/17] reconcile state of charge with storage fmt --- ECU/Application/Src/CANutils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ECU/Application/Src/CANutils.c b/ECU/Application/Src/CANutils.c index 36fd4ca5..e7913331 100644 --- a/ECU/Application/Src/CANutils.c +++ b/ECU/Application/Src/CANutils.c @@ -102,8 +102,8 @@ void SendECUStateDataOverCAN(ECU_StateData *stateData) .StatusBits = {stateData->status_bits[0], stateData->status_bits[1], stateData->status_bits[2]}, .PowerLevelTorqueMap = stateData->powerlevel_torquemap, .MaxCellTemp = (uint8_t)(stateData->max_cell_temp_c * 4), - .AccumulatorStateOfCharge = (uint8_t)(stateData->tractivebattery_soc * 51 / 20), - .GLVStateOfCharge = (uint8_t)(stateData->glv_soc * 51 / 20), + .AccumulatorStateOfCharge = (uint8_t)(stateData->tractivebattery_soc), + .GLVStateOfCharge = (uint8_t)(stateData->glv_soc), .TractiveSystemVoltage = (uint16_t)(stateData->ts_voltage * 100), .VehicleSpeed = (uint16_t)(stateData->vehicle_speed_mph * 100), .FRWheelRPM = (uint16_t)(stateData->fr_wheel_rpm * 10 + 32768), From 48d5f12d6b14b5f10390ba2bd065f9edc27e3a17 Mon Sep 17 00:00:00 2001 From: Casey Zwicker Date: Thu, 5 Mar 2026 20:54:16 -0800 Subject: [PATCH 09/17] reconcile state of charge with storage fmt --- ECU/Application/Src/CANdler.c | 4 ++-- ECU/Application/Src/CANutils.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ECU/Application/Src/CANdler.c b/ECU/Application/Src/CANdler.c index f00fa29e..a3e842af 100644 --- a/ECU/Application/Src/CANdler.c +++ b/ECU/Application/Src/CANdler.c @@ -58,8 +58,8 @@ void ECU_CAN_MessageHandler(ECU_StateData *state_data, GR_OLD_BUS_ID bus_id, GR_ break; } GR_OLD_BCU_STATUS_1_MSG *bcu_status_1 = (GR_OLD_BCU_STATUS_1_MSG *)data; - state_data->tractivebattery_soc = bcu_status_1->tractivebattery_soc * 0.01; - state_data->glv_soc = bcu_status_1->glv_soc * 20 / 51; + state_data->tractivebattery_soc = bcu_status_1->tractivebattery_soc; + state_data->glv_soc = bcu_status_1->glv_soc; state_data->ts_voltage = bcu_status_1->ts_voltage * 0.01; break; diff --git a/ECU/Application/Src/CANutils.c b/ECU/Application/Src/CANutils.c index 36fd4ca5..e7913331 100644 --- a/ECU/Application/Src/CANutils.c +++ b/ECU/Application/Src/CANutils.c @@ -102,8 +102,8 @@ void SendECUStateDataOverCAN(ECU_StateData *stateData) .StatusBits = {stateData->status_bits[0], stateData->status_bits[1], stateData->status_bits[2]}, .PowerLevelTorqueMap = stateData->powerlevel_torquemap, .MaxCellTemp = (uint8_t)(stateData->max_cell_temp_c * 4), - .AccumulatorStateOfCharge = (uint8_t)(stateData->tractivebattery_soc * 51 / 20), - .GLVStateOfCharge = (uint8_t)(stateData->glv_soc * 51 / 20), + .AccumulatorStateOfCharge = (uint8_t)(stateData->tractivebattery_soc), + .GLVStateOfCharge = (uint8_t)(stateData->glv_soc), .TractiveSystemVoltage = (uint16_t)(stateData->ts_voltage * 100), .VehicleSpeed = (uint16_t)(stateData->vehicle_speed_mph * 100), .FRWheelRPM = (uint16_t)(stateData->fr_wheel_rpm * 10 + 32768), From 25ab0211132d923e04c4ab494cea6431da8b02b8 Mon Sep 17 00:00:00 2001 From: Casey Zwicker Date: Thu, 5 Mar 2026 21:27:49 -0800 Subject: [PATCH 10/17] be so fr --- ECU/Core/Src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ECU/Core/Src/main.c b/ECU/Core/Src/main.c index 48641c49..ce840d3c 100644 --- a/ECU/Core/Src/main.c +++ b/ECU/Core/Src/main.c @@ -460,7 +460,7 @@ int main(void) write_adc_values_to_state_data(); ECU_State_Tick(); lightControl(&stateLump); - LOGOMATIC("Main Loop Tick Complete. I use Arch btw\n"); + //LOGOMATIC("Main Loop Tick Complete. I use Arch btw\n"); } /* USER CODE END 3 */ } From abbac895eed750e3aaa3ee1bba824b21a43aa962 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 6 Mar 2026 05:29:02 +0000 Subject: [PATCH 11/17] Automatic Clang-Format: Standardized formatting automatically --- ECU/Core/Src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ECU/Core/Src/main.c b/ECU/Core/Src/main.c index ce840d3c..2c15c64b 100644 --- a/ECU/Core/Src/main.c +++ b/ECU/Core/Src/main.c @@ -460,7 +460,7 @@ int main(void) write_adc_values_to_state_data(); ECU_State_Tick(); lightControl(&stateLump); - //LOGOMATIC("Main Loop Tick Complete. I use Arch btw\n"); + // LOGOMATIC("Main Loop Tick Complete. I use Arch btw\n"); } /* USER CODE END 3 */ } From f6f84f8d104e29cf4dd5bcea9ae098af11d7b46e Mon Sep 17 00:00:00 2001 From: Thomas Xu Date: Thu, 5 Mar 2026 21:34:07 -0800 Subject: [PATCH 12/17] Fix failling fdcan include for FDCAN_EXTENDED_ID --- ECU/Application/Src/StateUtils.c | 5 +++-- ECU/Core/Src/main.c | 1 + ECU/Test/Inc/stm32g4xx_hal_fdcan.h | 6 ++++++ ECU/Test/Src/StateTicksTest.c | 7 ++----- 4 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 ECU/Test/Inc/stm32g4xx_hal_fdcan.h diff --git a/ECU/Application/Src/StateUtils.c b/ECU/Application/Src/StateUtils.c index 3737ea4a..4fd85556 100644 --- a/ECU/Application/Src/StateUtils.c +++ b/ECU/Application/Src/StateUtils.c @@ -50,9 +50,10 @@ bool bspdFailure(volatile const ECU_StateData *stateData) bool CommunicationError(volatile const ECU_StateData *stateData) { - UNUSED(stateData); // TODO: Check for communication errors - return false; + UNUSED(stateData); + bool problem = false; + return problem; } bool APPS_BSE_Violation(volatile const ECU_StateData *stateData) diff --git a/ECU/Core/Src/main.c b/ECU/Core/Src/main.c index 2c15c64b..6c08dd27 100644 --- a/ECU/Core/Src/main.c +++ b/ECU/Core/Src/main.c @@ -440,6 +440,7 @@ int main(void) if (nextPing != 0) { if (getRTT(GR_BCU) == PINGTIMEOUT_VALUE) { LOGOMATIC("ERROR: BCU is not responding to pings!\n"); + ECU_CAN_Send(GR_OLD_BUS_PRIMARY, GR_DEBUGGER, MSG_DEBUG_2_0, "ECU-P-ITR", 8); } if (getRTT(GR_DASH_PANEL) == PINGTIMEOUT_VALUE) { LOGOMATIC("ERROR: Dash Panel is not responding to pings!\n"); diff --git a/ECU/Test/Inc/stm32g4xx_hal_fdcan.h b/ECU/Test/Inc/stm32g4xx_hal_fdcan.h new file mode 100644 index 00000000..f9ccecdc --- /dev/null +++ b/ECU/Test/Inc/stm32g4xx_hal_fdcan.h @@ -0,0 +1,6 @@ +#ifndef STM32G4xx_HAL_FDCAN_H +#define STM32G4xx_HAL_FDCAN_H + +#define FDCAN_EXTENDED_ID ((uint32_t)0x40000000U) /*!< Extended ID element */ + +#endif diff --git a/ECU/Test/Src/StateTicksTest.c b/ECU/Test/Src/StateTicksTest.c index c2f9e849..b998cb40 100644 --- a/ECU/Test/Src/StateTicksTest.c +++ b/ECU/Test/Src/StateTicksTest.c @@ -2,11 +2,12 @@ #include +#include "stm32g4xx_hal_fdcan.h" +#include "stm32g4xx_hal.h" #include "Logomatic.h" #include "StateData.h" #include "StateUtils.h" #include "can.h" -#include "stm32g4xx_hal.h" /* - GLV ON @@ -29,10 +30,6 @@ static void ECU_Pseudo_State_Tick(ECU_StateData *stateLumpTest) { - if (stateLumpTest->millisSinceBoot - stateLumpTest->lastECUStatusMsgMillis >= ECU_STATUS_MSG_PERIOD_MILLIS) { - LOGOMATIC("ECU Current State: %d\n", stateLumpTest->ecu_state); - stateLumpTest->lastECUStatusMsgMillis = stateLumpTest->millisSinceBoot; - } if (bmsFailure(stateLumpTest) || imdFailure(stateLumpTest)) { stateLumpTest->tssi_fault = true; From 5845e29f077525baf758ce0e4941852edb9516d4 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 6 Mar 2026 05:35:28 +0000 Subject: [PATCH 13/17] Automatic Clang-Format: Standardized formatting automatically --- ECU/Test/Src/StateTicksTest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ECU/Test/Src/StateTicksTest.c b/ECU/Test/Src/StateTicksTest.c index b998cb40..cf2afd4b 100644 --- a/ECU/Test/Src/StateTicksTest.c +++ b/ECU/Test/Src/StateTicksTest.c @@ -2,12 +2,12 @@ #include -#include "stm32g4xx_hal_fdcan.h" -#include "stm32g4xx_hal.h" #include "Logomatic.h" #include "StateData.h" #include "StateUtils.h" #include "can.h" +#include "stm32g4xx_hal.h" +#include "stm32g4xx_hal_fdcan.h" /* - GLV ON From dd73c3be945a92bf60f3d103da08ff81470da4d5 Mon Sep 17 00:00:00 2001 From: Thomas Xu Date: Thu, 5 Mar 2026 22:20:21 -0800 Subject: [PATCH 14/17] Replace Comm Error checking with precharge timeout checking. Co-authored-by: khoulihan27 --- ECU/Application/Inc/StateUtils.h | 7 ++++++- ECU/Application/Src/StateTicks.c | 9 ++++----- ECU/Application/Src/StateUtils.c | 8 -------- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/ECU/Application/Inc/StateUtils.h b/ECU/Application/Inc/StateUtils.h index 3c5273e3..4045563b 100644 --- a/ECU/Application/Inc/StateUtils.h +++ b/ECU/Application/Inc/StateUtils.h @@ -29,12 +29,17 @@ uint32_t MillisecondsSinceBoot(void); #define MAX_CURRENT_AMPS 42.0f // TODO: Change as appropriate #define MAX_REVERSE_CURRENT_AMPS 20.0f // TODO: Change as appropriate +#define MAX_PRECHARGE_TIME 15000 // in ms + +#define ECU_STATUS_MSG_PERIOD_MILLIS (1000) +// EV.5.6.3: The Discharge Circuit must be designed to handle the maximum Tractive System voltage for minimum 15 seconds +#define TRACTIVE_SYSTEM_MAX_PERMITTED_DISCHARGE_TIME_MILLIS (15000) + // Checks stateData for critical errors bool CriticalError(volatile const ECU_StateData *stateData); bool bmsFailure(volatile const ECU_StateData *stateData); bool imdFailure(volatile const ECU_StateData *stateData); bool bspdFailure(volatile const ECU_StateData *stateData); -bool CommunicationError(volatile const ECU_StateData *stateData); bool APPS_BSE_Violation(volatile const ECU_StateData *stateData); bool PressingBrake(volatile const ECU_StateData *stateData); float CalcBrakePercent(volatile const ECU_StateData *stateData); diff --git a/ECU/Application/Src/StateTicks.c b/ECU/Application/Src/StateTicks.c index a4bcdcfd..51112409 100644 --- a/ECU/Application/Src/StateTicks.c +++ b/ECU/Application/Src/StateTicks.c @@ -31,10 +31,6 @@ ECU_StateData stateLump = {.ecu_state = GR_GLV_ON, .bcu_software_latch = 1}; CANHandle *primary_can; CANHandle *data_can; -#define ECU_STATUS_MSG_PERIOD_MILLIS (1000) -// EV.5.6.3: The Discharge Circuit must be designed to handle the maximum Tractive System voltage for minimum 15 seconds -#define TRACTIVE_SYSTEM_MAX_PERMITTED_DISCHARGE_TIME_MILLIS (15000) - static uint32_t millis_since_boot; void ECU_State_Tick(void) { @@ -100,6 +96,8 @@ void ECU_GLV_On(ECU_StateData *stateData) } } +static uint32_t time_start_precharge; // for potential comms errors while precharging + void ECU_Transition_To_Precharge_Engaged(ECU_StateData *stateData) { /*send message to BCU to start precharging*/ @@ -107,6 +105,7 @@ void ECU_Transition_To_Precharge_Engaged(ECU_StateData *stateData) ECU_CAN_Send(GR_OLD_BUS_PRIMARY, GR_BCU, MSG_BCU_PRECHARGE, &message, sizeof(message)); stateData->ecu_state = GR_PRECHARGE_ENGAGED; LOGOMATIC("PRECHARGE START to PRECHARGE ENGAGED!\n"); + time_start_precharge = millis_since_boot; return; } @@ -118,7 +117,7 @@ void ECU_Precharge_Engaged(ECU_StateData *stateData) return; } - if (!stateData->ts_active_button_active || CommunicationError(stateData)) { + if (!stateData->ts_active_button_active || (millis_since_boot - time_start_precharge) >= MAX_PRECHARGE_TIME) { LOGOMATIC("ERROR or ts_active OFF! PRECHARGE ENGAGED to TS DISCHARGE START!\n"); ECU_CAN_Send(GR_OLD_BUS_PRIMARY, GR_DEBUGGER, MSG_DEBUG_2_0, "TS-P-ITR", 8); ECU_Transition_To_Tractive_System_Discharge(stateData); diff --git a/ECU/Application/Src/StateUtils.c b/ECU/Application/Src/StateUtils.c index 4fd85556..1813e0c1 100644 --- a/ECU/Application/Src/StateUtils.c +++ b/ECU/Application/Src/StateUtils.c @@ -48,14 +48,6 @@ bool bspdFailure(volatile const ECU_StateData *stateData) // TODO: shutdown switch stuff } -bool CommunicationError(volatile const ECU_StateData *stateData) -{ - // TODO: Check for communication errors - UNUSED(stateData); - bool problem = false; - return problem; -} - bool APPS_BSE_Violation(volatile const ECU_StateData *stateData) { // Checks 2 * APPS_1 is within 10% of APPS_2 and break + throttle at the same time From 2175d8b352a1de5286684d32ec283809f99c9f7a Mon Sep 17 00:00:00 2001 From: Casey Zwicker Date: Thu, 5 Mar 2026 22:32:55 -0800 Subject: [PATCH 15/17] catch critical error in precharge engaged --- ECU/Application/Src/StateTicks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ECU/Application/Src/StateTicks.c b/ECU/Application/Src/StateTicks.c index 51112409..27f838b7 100644 --- a/ECU/Application/Src/StateTicks.c +++ b/ECU/Application/Src/StateTicks.c @@ -117,7 +117,7 @@ void ECU_Precharge_Engaged(ECU_StateData *stateData) return; } - if (!stateData->ts_active_button_active || (millis_since_boot - time_start_precharge) >= MAX_PRECHARGE_TIME) { + if (!stateData->ts_active_button_active || CriticalError(stateData) || (millis_since_boot - time_start_precharge) >= MAX_PRECHARGE_TIME) { LOGOMATIC("ERROR or ts_active OFF! PRECHARGE ENGAGED to TS DISCHARGE START!\n"); ECU_CAN_Send(GR_OLD_BUS_PRIMARY, GR_DEBUGGER, MSG_DEBUG_2_0, "TS-P-ITR", 8); ECU_Transition_To_Tractive_System_Discharge(stateData); From 93f53abb8abb656d563103139acdf45b35df680e Mon Sep 17 00:00:00 2001 From: Thomas Xu Date: Mon, 9 Mar 2026 21:38:08 -0700 Subject: [PATCH 16/17] correct ts maximum permitted discharge time --- ECU/Application/Inc/StateUtils.h | 3 +-- ECU/Application/Src/StateTicks.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/ECU/Application/Inc/StateUtils.h b/ECU/Application/Inc/StateUtils.h index 4045563b..1f9f1fa7 100644 --- a/ECU/Application/Inc/StateUtils.h +++ b/ECU/Application/Inc/StateUtils.h @@ -32,8 +32,7 @@ uint32_t MillisecondsSinceBoot(void); #define MAX_PRECHARGE_TIME 15000 // in ms #define ECU_STATUS_MSG_PERIOD_MILLIS (1000) -// EV.5.6.3: The Discharge Circuit must be designed to handle the maximum Tractive System voltage for minimum 15 seconds -#define TRACTIVE_SYSTEM_MAX_PERMITTED_DISCHARGE_TIME_MILLIS (15000) +#define TRACTIVE_SYSTEM_MAX_PERMITTED_DISCHARGE_TIME_MILLIS (5000) // Checks stateData for critical errors bool CriticalError(volatile const ECU_StateData *stateData); diff --git a/ECU/Application/Src/StateTicks.c b/ECU/Application/Src/StateTicks.c index 27f838b7..ced2a3c0 100644 --- a/ECU/Application/Src/StateTicks.c +++ b/ECU/Application/Src/StateTicks.c @@ -228,7 +228,7 @@ void ECU_Tractive_System_Discharge(ECU_StateData *stateData) see #129 */ if (millis_since_boot - discharge_start_millis > TRACTIVE_SYSTEM_MAX_PERMITTED_DISCHARGE_TIME_MILLIS) { - LOGOMATIC("Warning: Tractive System fails to discharge in time.\n"); + LOGOMATIC("Warning: Tractive System fails to discharge in %d seconds.\n", TRACTIVE_SYSTEM_MAX_PERMITTED_DISCHARGE_TIME_MILLIS); ECU_CAN_Send(GR_OLD_BUS_PRIMARY, GR_DEBUGGER, MSG_DEBUG_2_0, "TS-D-TLE", 8); } From cd7a33fda5bea76cff1c094968d6f21c3a12c8ed Mon Sep 17 00:00:00 2001 From: Thomas Xu Date: Mon, 9 Mar 2026 23:45:40 -0700 Subject: [PATCH 17/17] fix timer variable name --- ECU/Application/Src/StateTicks.c | 4 ++-- ECU/Test/Src/StateTicksTest.c | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/ECU/Application/Src/StateTicks.c b/ECU/Application/Src/StateTicks.c index 07241a86..92024f40 100644 --- a/ECU/Application/Src/StateTicks.c +++ b/ECU/Application/Src/StateTicks.c @@ -193,11 +193,11 @@ void ECU_Drive_Active(ECU_StateData *stateData) static uint32_t last_apps_plausible_frame_millis; if (APPS_Plausible(stateData)) { - last_apps_plausible_frame_millis = stateData->millisSinceBoot; + last_apps_plausible_frame_millis = millis_since_boot; } // Stop throttle if implausible for > 100ms - if (stateData->apps_bse_violation || stateData->millisSinceBoot - last_apps_plausible_frame_millis > 100) { + if (stateData->apps_bse_violation || millis_since_boot - last_apps_plausible_frame_millis > 100) { torque_request = 0; } diff --git a/ECU/Test/Src/StateTicksTest.c b/ECU/Test/Src/StateTicksTest.c index cf2afd4b..9bc8466b 100644 --- a/ECU/Test/Src/StateTicksTest.c +++ b/ECU/Test/Src/StateTicksTest.c @@ -22,10 +22,6 @@ - TS DISCHARGE (ts voltage > 60), then less than 60 -> GLV ON */ -#define ECU_STATUS_MSG_PERIOD_MILLIS (1000) -// EV.5.6.3: The Discharge Circuit must be designed to handle the maximum Tractive System voltage for minimum 15 seconds -#define TRACTIVE_SYSTEM_MAX_PERMITTED_DISCHARGE_TIME_MILLIS (15000) - // static void ECU_Pseudo_Time_Progress(uint32_t dt) { stateLumpTest.millisSinceBoot += dt; } static void ECU_Pseudo_State_Tick(ECU_StateData *stateLumpTest)