Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
01fe391
Finish documentation
dchansen06 Jul 9, 2026
139bd1b
REVERT ME --- Nucleo blinky demo
dchansen06 Jul 9, 2026
c670297
Revert "REVERT ME --- Nucleo blinky demo"
dchansen06 Jul 9, 2026
1999949
initial generation, needs fixing
dwilson765 Aug 16, 2026
433bdd6
everything is still yelling at me
dwilson765 Aug 17, 2026
c2b7941
ecu migration complete I think, only errors are can related
dwilson765 Aug 17, 2026
b249e6a
changed deprecated libs in cmake for ECU
dwilson765 Aug 18, 2026
03e82e2
Fixed small adc issue & replaced appropriate libs
dwilson765 Aug 18, 2026
c78c6a1
Just need to config logo and deal w/ CAN issues
dwilson765 Aug 18, 2026
e18bc95
Commented out logomatic for now, will fix config
dwilson765 Aug 19, 2026
e085c4f
Fixed LOGOMATIC, made changes to CAN using CUBECAN
dwilson765 Aug 24, 2026
b7a6ccd
ECU compiles in debug
dwilson765 Aug 25, 2026
9226168
Added back DTI special case
dwilson765 Aug 25, 2026
f63f888
fixed double promotion in LOGO msg
dwilson765 Aug 25, 2026
9b25121
Merge branch 'CubeMXSupport' into GR26ECU_Migration
dwilson765 Aug 25, 2026
51c0cfb
Drop internal driver, slight CubeMX tweaks
dchansen06 Aug 25, 2026
feb63c6
Also format
dchansen06 Aug 25, 2026
189b2bc
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Aug 25, 2026
c503ea7
Activated FDCAN in CubeMX generation
dwilson765 Aug 27, 2026
fbe6302
Set Timer periph for can stuff
dwilson765 Sep 1, 2026
1de3da2
small fixes
dwilson765 Sep 20, 2026
8c81841
Add CAN filters
dwilson765 Sep 20, 2026
b21ed53
Fixed fdcan2 config and dti filter
dwilson765 Sep 20, 2026
2436f62
more fixing can filter
dwilson765 Sep 20, 2026
7896bfb
Merge branch 'CubeMXSupport' into GR26ECU_Migration
dwilson765 Sep 21, 2026
64994fd
Synced missing files not pulled from CubeMXSupprot
dwilson765 Sep 27, 2026
540bcfd
More syncing
dwilson765 Sep 27, 2026
0b44568
Cmake changes, lwk doesnt build
dwilson765 Sep 29, 2026
4adcca6
Fixed good chunk of build errors
dwilson765 Sep 29, 2026
c552e80
Cmake now builds fully using new cmake architecture and add_project
dwilson765 Sep 29, 2026
f1da538
Main cmake change
dwilson765 Sep 30, 2026
ed889d2
Nuke it
dchansen06 Sep 30, 2026
a5ff6f1
WIP local change
dwilson765 Oct 5, 2026
8ed5dec
Added back changes to stateticks
dwilson765 Oct 5, 2026
608cfba
Initial CAN changes to hopefully phase out ECU_CAN_Send
dwilson765 Oct 5, 2026
07dd7b0
small change
dwilson765 Oct 5, 2026
46f120f
Small change
dwilson765 Oct 5, 2026
fe00402
Regenerated CubeMX for FDCAN and added USART1 peripheral for logo
dwilson765 Oct 5, 2026
08b8db8
ECU_CAN_Send_DTI now uses CubeCAN_Send_Custom and ECU_CAN_SEND is now…
dwilson765 Oct 6, 2026
ebbdd64
Temp ECU_CAN_Send wrapper, New ECU_GetCANHandle() func
dwilson765 Oct 6, 2026
ca01583
Removed unused declarations
dwilson765 Oct 6, 2026
fb8d851
Rid of ADC_Config, Added ADC Calibration check, disables DMA interrup…
dwilson765 Oct 12, 2026
d598fbe
Small adc fix, fixed missing main loop
dwilson765 Oct 12, 2026
5e7747e
Error_Handler logs ms called, removed Plan C, moved DTI_RX id and mas…
dwilson765 Oct 12, 2026
c601c3a
Added back Send ECU stateData, Analog data, Config with CubeCAN_Send
dwilson765 Oct 12, 2026
c12ee27
used macros insteadd of literals of FDCAN filters
dwilson765 Oct 12, 2026
a6a2b71
Fixed ECUStateDataOverCAN rate limit
dwilson765 Oct 12, 2026
b9b8e14
Fixed ADC_Output overwriting wrong memory, fixed ADC buffer enum for …
dwilson765 Oct 12, 2026
0a8228b
Fixed FDCAN Tx delay compensation and Fixed ConfigFilter throwing awa…
dwilson765 Oct 12, 2026
ee191dc
Added FDCAN_ConfigGlobal Filter
dwilson765 Oct 12, 2026
ee8bac5
Small fixes
dwilson765 Oct 12, 2026
86f2e70
New CubeMX generation with correct smol_borb pinouts, currently compiles
dwilson765 Oct 13, 2026
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
19 changes: 9 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ include("${LIB_PATH}/FancyLayers-RENAME/NeoPixel/neopixel.cmake")
include(BLINKY/blinky.cmake)
include(Testbench/testbench.cmake)

add_gr_project(STM32G474xE ECU)
add_gr_project(STM32G474xE CCU)
add_gr_project(STM32G474xE CANine)
add_gr_project(STM32G431x8 OutboardSensors TireTemp)
Expand All @@ -170,15 +169,15 @@ add_gr_project(STM32U5A9xJ BLINKY U5BLINKY)
add_gr_project(STM32L476xG BLINKY L4BLINKY)
add_gr_project(STM32L476xG BLINKY L4HELLO)

# add_project(
# NAME "ECU"
# PATH "ECU"
# SERIES "g4"
# SPECIFIER "g474re"
# HAL_GIT_TAG "v1.2.7" # https://github.com/STMicroelectronics/stm32g4xx-hal-driver/tree/v1.2.7
# CMSIS_GIT_TAG "v1.2.6" # https://github.com/STMicroelectronics/cmsis-device-g4/tree/v1.2.6
# CMSIS_MAJOR "5"
# )
add_project(
NAME "ECU"
PATH "ECU"
SERIES "g4"
SPECIFIER "g474re"
HAL_GIT_TAG "v1.2.7" # https://github.com/STMicroelectronics/stm32g4xx-hal-driver/tree/v1.2.7
CMSIS_GIT_TAG "v1.2.6" # https://github.com/STMicroelectronics/cmsis-device-g4/tree/v1.2.6
CMSIS_MAJOR "5"
)

# add_project(
# NAME "CCU"
Expand Down
10 changes: 8 additions & 2 deletions ECU/Application/Inc/CANdler.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#include <stdbool.h>
#include <stdint.h>

#include "CubeCAN.h"
#include "GRCAN_BUS_ID.h"
#include "GRCAN_CUSTOM_ID.h"
#include "GRCAN_MSG_ID.h"
#include "GRCAN_NODE_ID.h"
#include "StateData.h"
#include "fdcan.h"

#ifndef CANDLER_H
#define CANDLER_H

void ECU_CAN_MessageHandler(ECU_StateData *state_data, GRCAN_BUS_ID bus_id, GRCAN_MSG_ID msg_id, GRCAN_NODE_ID sender_id, uint8_t *data, uint32_t data_length);
#define CANDLER_IS_DTI_ID(raw_id) (((raw_id) & DTI_RX_MASK) == DTI_RX_ID)

void ECU_CAN_DTI_MessageHandler(ECU_StateData *state_data, GRCAN_CUSTOM_ID id, uint8_t *data, uint32_t data_length);
void CANdler_Callback(const CubeCAN_Config_Context *const context, const CubeCAN_Identifier *const identifier, const uint8_t *const data, const uint8_t size);

void ECU_CAN_MessageHandler(ECU_StateData *state_data, GRCAN_BUS_ID bus_id, GRCAN_MSG_ID msg_id, GRCAN_NODE_ID sender_id, const uint8_t *data, uint32_t data_length);

void ECU_CAN_DTI_MessageHandler(ECU_StateData *state_data, uint32_t id, const uint8_t *data, uint32_t data_length);

#endif
7 changes: 4 additions & 3 deletions ECU/Application/Inc/CANutils.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <stdint.h>

#include "CubeCAN.h"
#include "GRCAN_BUS_ID.h"
#include "GRCAN_CUSTOM_ID.h"
#include "GRCAN_MSG_ID.h"
Expand All @@ -10,8 +10,9 @@
#define CANUTILS_H

#define ECU_STATE_DATA_SEND_INTERVAL_MS 20
void ECU_CAN_Send(GRCAN_BUS_ID bus, GRCAN_NODE_ID destNode, GRCAN_MSG_ID messageID, void *data, uint32_t size);
void ECU_CAN_Send_DTI(GRCAN_CUSTOM_ID msgID, void *data, uint32_t size);
CubeCAN_Handle *ECU_GetCANHandle(GRCAN_BUS_ID bus);
HAL_StatusTypeDef ECU_CAN_Send(GRCAN_BUS_ID bus, GRCAN_NODE_ID destNode, GRCAN_MSG_ID messageID, const void *data, uint8_t size);
HAL_StatusTypeDef ECU_CAN_Send_DTI(GRCAN_CUSTOM_ID msgID, const void *data, uint8_t size);
void SendECUStateDataOverCAN(const ECU_StateData *stateData);
void SendECUAnalogDataOverCAN(const ECU_StateData *stateData);
void SendECUConfigOverCAN(const ECU_StateData *stateData);
Expand Down
7 changes: 7 additions & 0 deletions ECU/Application/Inc/CubeCAN_Config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef CUBE_CAN_CONFIG_H
#define CUBE_CAN_CONFIG_H

#define CUBEMX_CAN_TX_QUEUE_SIZE 16U
#define CUBEMX_CAN_MAX_INSTANCES 2U

#endif
2 changes: 0 additions & 2 deletions ECU/Application/Inc/Plan_C.h

This file was deleted.

6 changes: 3 additions & 3 deletions ECU/Application/Inc/StateData.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <stdbool.h>
#include <stdint.h>

#include "CubeCAN.h"
#include "GRCAN_MSG_DATA.h"
#include "StateMachine.h"
#include "can.h"

#ifndef _STATEDATA_H_
#define _STATEDATA_H_
Expand Down Expand Up @@ -124,8 +124,8 @@ typedef volatile struct ECU_StateData {

GR_ECU_State ecu_state;

CANHandle *primary_can;
CANHandle *data_can;
CubeCAN_Handle *data_can;
CubeCAN_Handle *primary_can;
} ECU_StateData;

#endif
4 changes: 1 addition & 3 deletions ECU/Application/Inc/StateTicks.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#include "CubeCAN.h"
#include "StateData.h"
#include "StateMachine.h"
#include "adc.h"
#include "can.h"

#ifndef _STATE_TICKS_H_
#define _STATE_TICKS_H_

extern CANHandle *primary_can;
extern CANHandle *data_can;

/**
* @brief Tick function for the ECU state machine.
Expand Down
10 changes: 0 additions & 10 deletions ECU/Application/Inc/can_cfg.h

This file was deleted.

59 changes: 42 additions & 17 deletions ECU/Application/Src/CANdler.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <math.h>
#include <stdint.h>

#include "CubeCAN.h"
#include "GRCAN_BUS_ID.h"
#include "GRCAN_CUSTOM_ID.h"
#include "GRCAN_MSG_ID.h"
Expand All @@ -12,19 +13,21 @@
#include "StateData.h"
#include "bitManipulations.h"

extern ECU_StateData stateLump;

#define WHEEL_RADIUS_INCHES 8.0f
#define WHEEL_CIRCUMFERENCE_INCHES (2.0f * (float)M_PI * WHEEL_RADIUS_INCHES)
#define WHEEL_RPM_TO_MPH_RATIO (WHEEL_CIRCUMFERENCE_INCHES / 63360.0f * 60.0f)
#define NUM_MOTOR_POLE_PAIRS 10
#define DRIVEN_SPROCKET_TEETH 51.0f
#define DRIVING_SPROCKET_TEETH 19.0f
#define GEAR_RATIO (DRIVEN_SPROCKET_TEETH / DRIVING_SPROCKET_TEETH)
#define GEAR_RATIO (51.0f / 19.0f)

void ReportBadMessageLength(GRCAN_BUS_ID bus_id, GRCAN_MSG_ID msg_id, GRCAN_NODE_ID sender_id)
{
// TODO Ideally change some state data to note a bad message, ie if ACU
// that can be a comms error
LOGOMATIC("Bad ECU CAN Rx length! Bus: %d, Msg: %X, Sender: %X\n", bus_id, msg_id, sender_id);
LOGOMATIC_ERROR("Bad ECU CAN Rx length! Bus: %d, Msg: %X, Sender: %X\n", bus_id, msg_id, sender_id);
}

void ReportUnhandledMessage(GRCAN_BUS_ID bus_id, GRCAN_MSG_ID msg_id, GRCAN_NODE_ID sender_id)
Expand All @@ -33,42 +36,42 @@ void ReportUnhandledMessage(GRCAN_BUS_ID bus_id, GRCAN_MSG_ID msg_id, GRCAN_NODE
UNUSED(bus_id);
UNUSED(msg_id);
UNUSED(sender_id);
// LOGOMATIC("Unhandled ECU CAN Rx msg! Bus: %d, Msg: %X, Sender: %X\n", bus_id, msg_id, sender_id);
LOGOMATIC_ERROR("Unhandled ECU CAN Rx msg! Bus: %d, Msg: %X, Sender: %X\n", bus_id, msg_id, sender_id);
}

void ECU_CAN_MessageHandler(ECU_StateData *state_data, GRCAN_BUS_ID bus_id, GRCAN_MSG_ID msg_id, GRCAN_NODE_ID sender_id, uint8_t *data, uint32_t data_length)
void ECU_CAN_MessageHandler(ECU_StateData *state_data, GRCAN_BUS_ID bus_id, GRCAN_MSG_ID msg_id, GRCAN_NODE_ID sender_id, const uint8_t *data, uint32_t data_length)
{
switch (msg_id) {
case GRCAN_DEBUG_2_0:
if (data_length > 8) {
ReportBadMessageLength(bus_id, msg_id, sender_id);
break;
}
LOGOMATIC("Received from %02X on bus %d: %.*s\n", sender_id, bus_id, (int)data_length, data);
LOGOMATIC_INFO("Received from %02X on bus %d: %.*s\n", sender_id, bus_id, (int)data_length, data);
break;

case GRCAN_DEBUG_FD:
if (data_length > 64) {
ReportBadMessageLength(bus_id, msg_id, sender_id);
break;
}
LOGOMATIC("Received from %02X on bus %d: %.*s\n", sender_id, bus_id, (int)data_length, data);
LOGOMATIC_ERROR("Received from %02X on bus %d: %.*s\n", sender_id, bus_id, (int)data_length, data);
break;

case GRCAN_PING:
if (data_length != sizeof(GRCAN_PING_MSG)) {
ReportBadMessageLength(bus_id, msg_id, sender_id);
break;
}
respondToPing(bus_id, sender_id, ((GRCAN_PING_MSG *)data)->timestamp);
respondToPing(bus_id, sender_id, ((const GRCAN_PING_MSG *)data)->timestamp);
break;

case GRCAN_ACU_STATUS_1:
if (data_length != sizeof(GRCAN_ACU_STATUS_1_MSG)) {
ReportBadMessageLength(bus_id, msg_id, sender_id);
break;
}
GRCAN_ACU_STATUS_1_MSG *acu_status_1 = (GRCAN_ACU_STATUS_1_MSG *)data;
const GRCAN_ACU_STATUS_1_MSG *acu_status_1 = (const GRCAN_ACU_STATUS_1_MSG *)data;
state_data->tractivebattery_soc = acu_status_1->accumulator_soc;
state_data->glv_soc = acu_status_1->glv_soc;
state_data->ts_voltage = acu_status_1->ts_voltage * 0.1f;
Expand All @@ -79,7 +82,7 @@ void ECU_CAN_MessageHandler(ECU_StateData *state_data, GRCAN_BUS_ID bus_id, GRCA
ReportBadMessageLength(bus_id, msg_id, sender_id);
break;
}
GRCAN_ACU_STATUS_2_MSG *acu_status_2 = (GRCAN_ACU_STATUS_2_MSG *)data;
const GRCAN_ACU_STATUS_2_MSG *acu_status_2 = (const GRCAN_ACU_STATUS_2_MSG *)data;
state_data->max_cell_temp_c = acu_status_2->max_cell_temp * 0.25f;
state_data->acu_error_warning_bits = acu_status_2->status_flags;
// ACU does weird stuff
Expand All @@ -94,26 +97,26 @@ void ECU_CAN_MessageHandler(ECU_StateData *state_data, GRCAN_BUS_ID bus_id, GRCA
ReportBadMessageLength(bus_id, msg_id, sender_id);
break;
}
GRCAN_INV_STATUS_1_MSG *inv_status_1 = (GRCAN_INV_STATUS_1_MSG *)data;
const GRCAN_INV_STATUS_1_MSG *inv_status_1 = (const GRCAN_INV_STATUS_1_MSG *)data;
UNUSED(inv_status_1);
break;
case GRCAN_INV_STATUS_3:
if (data_length != sizeof(GRCAN_INV_STATUS_3_MSG)) {
ReportBadMessageLength(bus_id, msg_id, sender_id);
break;
}
GRCAN_INV_STATUS_3_MSG *inv_status_3 = (GRCAN_INV_STATUS_3_MSG *)data;
const GRCAN_INV_STATUS_3_MSG *inv_status_3 = (const GRCAN_INV_STATUS_3_MSG *)data;
state_data->inverter_fault_map = inv_status_3->fault_bits;
break;
case GRCAN_DASH_STATUS:
if (data_length != sizeof(GRCAN_DASH_STATUS_MSG)) {
ReportBadMessageLength(bus_id, msg_id, sender_id);
break;
}
GRCAN_DASH_STATUS_MSG *dash_data = (GRCAN_DASH_STATUS_MSG *)data;
const GRCAN_DASH_STATUS_MSG *dash_data = (const GRCAN_DASH_STATUS_MSG *)data;

LOGOMATIC("Dash button flags: TS Press %d | TS Hold %d | RTD Press %d | RTD Hold %d\n", dash_data->button_flags & 1, (dash_data->button_flags >> 2) & 1,
(dash_data->button_flags >> 1) & 1, (dash_data->button_flags >> 3) & 1);
LOGOMATIC_INFO("Dash button flags: TS Press %d | TS Hold %d | RTD Press %d | RTD Hold %d\n", dash_data->button_flags & 1, (dash_data->button_flags >> 2) & 1,
(dash_data->button_flags >> 1) & 1, (dash_data->button_flags >> 3) & 1);

// LET IT BE KNOWN: these things are LSB FIRST, TODO: I'll get it right later
if (state_data->ecu_state == GR_GLV_ON) {
Expand All @@ -137,7 +140,7 @@ void ECU_CAN_MessageHandler(ECU_StateData *state_data, GRCAN_BUS_ID bus_id, GRCA
ReportBadMessageLength(bus_id, msg_id, sender_id);
break;
}
GRCAN_ECU_CONFIG_MSG *ecu_config = (GRCAN_ECU_CONFIG_MSG *)data;
const GRCAN_ECU_CONFIG_MSG *ecu_config = (const GRCAN_ECU_CONFIG_MSG *)data;
state_data->ping_timeout_delay_ms = ecu_config->ping_timeout_delay * 10;
state_data->brake_f_min = ecu_config->brake_f_min * 25;
state_data->brake_r_min = ecu_config->brake_r_min * 25;
Expand Down Expand Up @@ -165,12 +168,12 @@ void ECU_CAN_MessageHandler(ECU_StateData *state_data, GRCAN_BUS_ID bus_id, GRCA
}
}

void ECU_CAN_DTI_MessageHandler(ECU_StateData *state_data, GRCAN_CUSTOM_ID id, uint8_t *data, uint32_t data_length)
void ECU_CAN_DTI_MessageHandler(ECU_StateData *state_data, uint32_t id, const uint8_t *data, uint32_t data_length)
{
switch (id) {
case DTI_DATA_1_CAN_ID:
if (data_length != 8) {
ReportBadMessageLength(GRCAN_BUS_PRIMARY, (GRCAN_MSG_ID)id, GRCAN_DTI_Inv);
LOGOMATIC_ERROR("BAD DTI_DATA_1 CAN Rx length: %d\n", (int)data_length);
break;
}
int32_t erpm = ((uint32_t)data[0] << 24) | ((uint32_t)data[1] << 16) | ((uint32_t)data[2] << 8) | ((uint32_t)data[3]);
Expand All @@ -183,3 +186,25 @@ void ECU_CAN_DTI_MessageHandler(ECU_StateData *state_data, GRCAN_CUSTOM_ID id, u
break;
}
}

void CANdler_Callback(const CubeCAN_Config_Context *const context, const CubeCAN_Identifier *const identifier, const uint8_t *const data, const uint8_t size)
{

if (context == NULL || identifier == NULL || data == NULL || size == 0) {
LOGOMATIC_ERROR("CANdler_Callback: Invalid parameters received. context: %p, identifier: %p, data: %p, size: %u\n", (const void *)context, (const void *)identifier, (const void *)data,
size);
return;
}

const GRCAN_BUS_ID bus_id = context->busid_user_context;
const GRCAN_NODE_ID sender_id = identifier->tx_node_id;
const GRCAN_MSG_ID msg_id = identifier->msg_id;


if (CANDLER_IS_DTI_ID(identifier->raw_id)) {
ECU_CAN_DTI_MessageHandler(&stateLump, identifier->raw_id, data, size);
return;
}

ECU_CAN_MessageHandler(&stateLump, bus_id, msg_id, sender_id, data, size);
}
Loading
Loading