diff --git a/CMakeLists.txt b/CMakeLists.txt index 975552ca8..356cedda1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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" diff --git a/ECU/Application/Inc/CANdler.h b/ECU/Application/Inc/CANdler.h index 47cb01326..cede82db0 100644 --- a/ECU/Application/Inc/CANdler.h +++ b/ECU/Application/Inc/CANdler.h @@ -1,17 +1,23 @@ #include #include +#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 diff --git a/ECU/Application/Inc/CANutils.h b/ECU/Application/Inc/CANutils.h index ebe084970..7d067eb55 100644 --- a/ECU/Application/Inc/CANutils.h +++ b/ECU/Application/Inc/CANutils.h @@ -1,5 +1,5 @@ #include - +#include "CubeCAN.h" #include "GRCAN_BUS_ID.h" #include "GRCAN_CUSTOM_ID.h" #include "GRCAN_MSG_ID.h" @@ -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); diff --git a/ECU/Application/Inc/CubeCAN_Config.h b/ECU/Application/Inc/CubeCAN_Config.h new file mode 100644 index 000000000..5c7a34811 --- /dev/null +++ b/ECU/Application/Inc/CubeCAN_Config.h @@ -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 diff --git a/ECU/Application/Inc/Plan_C.h b/ECU/Application/Inc/Plan_C.h deleted file mode 100644 index 8a7c44a75..000000000 --- a/ECU/Application/Inc/Plan_C.h +++ /dev/null @@ -1,2 +0,0 @@ -/* Disables brakes */ -// #define PLAN_C diff --git a/ECU/Application/Inc/StateData.h b/ECU/Application/Inc/StateData.h index 0cd60783f..62a11fb80 100644 --- a/ECU/Application/Inc/StateData.h +++ b/ECU/Application/Inc/StateData.h @@ -1,9 +1,9 @@ #include #include +#include "CubeCAN.h" #include "GRCAN_MSG_DATA.h" #include "StateMachine.h" -#include "can.h" #ifndef _STATEDATA_H_ #define _STATEDATA_H_ @@ -83,8 +83,7 @@ typedef volatile struct ECU_StateData { uint16_t bspd_signal; uint16_t APPS1_Signal; uint16_t APPS2_Signal; - uint16_t Brake_R_Signal; - uint16_t Brake_F_Signal; + uint16_t Brake_Signal; uint16_t aux_signal; uint16_t steering_angle_signal; uint16_t ping_timeout_delay_ms; @@ -124,8 +123,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 diff --git a/ECU/Application/Inc/StateTicks.h b/ECU/Application/Inc/StateTicks.h index 636cd77a1..0c9f87559 100644 --- a/ECU/Application/Inc/StateTicks.h +++ b/ECU/Application/Inc/StateTicks.h @@ -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. diff --git a/ECU/Application/Inc/can_cfg.h b/ECU/Application/Inc/can_cfg.h deleted file mode 100644 index 37703a8c5..000000000 --- a/ECU/Application/Inc/can_cfg.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CAN_CFG_H -#define CAN_CFG_H - -#define USECAN1 -#define TX_BUFFER_1_SIZE 16 - -#define USECAN2 -#define TX_BUFFER_2_SIZE 16 - -#endif diff --git a/ECU/Application/Src/CANdler.c b/ECU/Application/Src/CANdler.c index 85778c2cf..41fa1d3c7 100644 --- a/ECU/Application/Src/CANdler.c +++ b/ECU/Application/Src/CANdler.c @@ -3,6 +3,7 @@ #include #include +#include "CubeCAN.h" #include "GRCAN_BUS_ID.h" #include "GRCAN_CUSTOM_ID.h" #include "GRCAN_MSG_ID.h" @@ -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) @@ -33,10 +36,10 @@ 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: @@ -44,7 +47,7 @@ void ECU_CAN_MessageHandler(ECU_StateData *state_data, GRCAN_BUS_ID bus_id, GRCA 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: @@ -52,7 +55,7 @@ void ECU_CAN_MessageHandler(ECU_StateData *state_data, GRCAN_BUS_ID bus_id, GRCA 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: @@ -60,7 +63,7 @@ void ECU_CAN_MessageHandler(ECU_StateData *state_data, GRCAN_BUS_ID bus_id, GRCA 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: @@ -68,7 +71,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_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; @@ -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 @@ -94,7 +97,7 @@ 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: @@ -102,7 +105,7 @@ 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_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: @@ -110,10 +113,10 @@ void ECU_CAN_MessageHandler(ECU_StateData *state_data, GRCAN_BUS_ID bus_id, GRCA 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) { @@ -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; @@ -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]); @@ -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); +} diff --git a/ECU/Application/Src/CANutils.c b/ECU/Application/Src/CANutils.c index 0e340fee8..942dba879 100644 --- a/ECU/Application/Src/CANutils.c +++ b/ECU/Application/Src/CANutils.c @@ -2,6 +2,7 @@ #include +#include "CubeCAN.h" #include "GRCAN_BUS_ID.h" #include "GRCAN_CUSTOM_ID.h" #include "GRCAN_MSG_ID.h" @@ -10,7 +11,6 @@ #include "StateData.h" #include "StateTicks.h" #include "StateUtils.h" -#include "can.h" #include "main.h" #include "stm32g4xx_hal_fdcan.h" #include "string.h" @@ -19,89 +19,54 @@ extern ECU_StateData stateLump; uint32_t lastTickECUStateDataSent = 0; -void ECU_CAN_Send(GRCAN_BUS_ID bus, GRCAN_NODE_ID destNode, GRCAN_MSG_ID messageID, void *data, uint32_t size) -{ - if (size > FDCAN_MAX_DATA_BYTES) { - size = FDCAN_MAX_DATA_BYTES; - LOGOMATIC("Tried to send more than 64 bytes over CAN\n"); - } - - uint32_t ID = ((0xFF & GRCAN_ECU) << 20) | ((0xFFF & messageID) << 8) | (0xFF & destNode); - - FDCAN_TxHeaderTypeDef header = { - .Identifier = ID, - .IdType = FDCAN_EXTENDED_ID, - .TxFrameType = FDCAN_DATA_FRAME, - .ErrorStateIndicator = FDCAN_ESI_ACTIVE, - .DataLength = BytesToCANDLC(size), - .BitRateSwitch = FDCAN_BRS_OFF, - .TxEventFifoControl = FDCAN_NO_TX_EVENTS, - .FDFormat = (bus == GRCAN_BUS_PRIMARY) ? FDCAN_CLASSIC_CAN : FDCAN_FD_CAN, - .MessageMarker = 0, - }; +// FIXME: Help double check this is correct, current no build errors on debug - FDCANTxMessage msg = {0}; - msg.tx_header = header; - - memcpy(&(msg.data), data, size); - - switch (bus) { +CubeCAN_Handle *ECU_GetCANHandle(GRCAN_BUS_ID bus){ + switch(bus){ case GRCAN_BUS_PRIMARY: - can_enqueue(stateLump.primary_can, &msg); - break; + return stateLump.primary_can; case GRCAN_BUS_DATA: - can_enqueue(stateLump.data_can, &msg); - break; + return stateLump.data_can; default: - LOGOMATIC("CAN: Invalid bus ID %d\n", bus); - break; + return NULL; + } +} + + +HAL_StatusTypeDef ECU_CAN_Send(GRCAN_BUS_ID bus, GRCAN_NODE_ID destNode, GRCAN_MSG_ID messageID, const void *data, uint8_t size) +{ + CubeCAN_Handle *handle = ECU_GetCANHandle(bus); + if (handle == NULL){ + LOGOMATIC_ERROR("CAN: no handle for bus %d\n", bus); + return HAL_ERROR; } + + return CubeCAN_Send(handle, destNode, messageID, data, size); + } -// TODO: If you try to send anything but control messages, you are cooked buddy -// Doesn't actually use Motorola order for multiple fields, just sends the bytes in reverse order -void ECU_CAN_Send_DTI(GRCAN_CUSTOM_ID msgID, void *data, uint32_t size) +HAL_StatusTypeDef ECU_CAN_Send_DTI(GRCAN_CUSTOM_ID msgID, const void *data, uint8_t size) { - // if ((MSG_DTI_CONTROL_10 & 0xFF) != 0x16) { - // LOGOMATIC("NOT A DTI MESSAGE"); - // } - - FDCAN_TxHeaderTypeDef TxHeader = { - .IdType = FDCAN_EXTENDED_ID, - .TxFrameType = FDCAN_DATA_FRAME, - .ErrorStateIndicator = FDCAN_ESI_ACTIVE, // honestly this might be a value you have to read from a node - // FDCAN_ESI_ACTIVE is just a state that assumes there are minimal errors - .BitRateSwitch = FDCAN_BRS_OFF, - .TxEventFifoControl = FDCAN_NO_TX_EVENTS, // change to FDCAN_STORE_TX_EVENTS if you need to store info regarding transmitted messages - .MessageMarker = 0 // also change this to a real address if you change fifo control - }; - - TxHeader.Identifier = msgID; - TxHeader.DataLength = size; - - TxHeader.FDFormat = FDCAN_CLASSIC_CAN; - - FDCANTxMessage msg = {0}; - msg.tx_header = TxHeader; - - uint8_t temp; - for (uint32_t i = 0; i < size / 2; ++i) { - temp = ((uint8_t *)data)[i]; - ((uint8_t *)data)[i] = ((uint8_t *)data)[size - i - 1]; - ((uint8_t *)data)[size - i - 1] = temp; + if (data == NULL || size > 8) { + return HAL_ERROR; } - memcpy(&(msg.data), data, size); + uint8_t msg[8]; + const uint8_t *temp = (const uint8_t *)data; + for (uint8_t i = 0; i < size; ++i){ + msg[i] = temp[size - 1 - i]; + } - // can_send(primary_can, &msg); - can_enqueue(stateLump.primary_can, &msg); + return CubeCAN_Send_Custom(stateLump.primary_can, msgID, msg, size); } +// Didnt want to delete this in case the change I made aren't necessary + void SendECUStateDataOverCAN(const ECU_StateData *stateData) { uint32_t currentTime = MillisecondsSinceBoot(); - if (lastTickECUStateDataSent > currentTime - ECU_STATE_DATA_SEND_INTERVAL_MS) { + if (currentTime - lastTickECUStateDataSent < ECU_STATE_DATA_SEND_INTERVAL_MS) { return; } @@ -120,9 +85,11 @@ void SendECUStateDataOverCAN(const ECU_StateData *stateData) .RRWheelRPM = (uint16_t)(stateData->rr_wheel_rpm * 10 + 32768), .RLWheelRPM = (uint16_t)(stateData->rl_wheel_rpm * 10 + 32768)}; - ECU_CAN_Send(GRCAN_BUS_PRIMARY, GRCAN_ALL, GRCAN_ECU_STATUS_1, (void *)&messages.ECUStatusMsgOne, sizeof(messages.ECUStatusMsgOne)); - ECU_CAN_Send(GRCAN_BUS_PRIMARY, GRCAN_ALL, GRCAN_ECU_STATUS_2, (void *)&messages.ECUStatusMsgTwo, sizeof(messages.ECUStatusMsgTwo)); - ECU_CAN_Send(GRCAN_BUS_PRIMARY, GRCAN_ALL, GRCAN_ECU_STATUS_3, (void *)&messages.ECUStatusMsgThree, sizeof(messages.ECUStatusMsgThree)); + + CubeCAN_Handle *primary = ECU_GetCANHandle(GRCAN_BUS_PRIMARY); + CubeCAN_Send(primary, GRCAN_ALL, GRCAN_ECU_STATUS_1, messages.ECUStatusMsgOne, sizeof(messages.ECUStatusMsgOne)); + CubeCAN_Send(primary, GRCAN_ALL, GRCAN_ECU_STATUS_2, messages.ECUStatusMsgTwo, sizeof(messages.ECUStatusMsgTwo)); + CubeCAN_Send(primary, GRCAN_ALL, GRCAN_ECU_STATUS_3, messages.ECUStatusMsgThree, sizeof(messages.ECUStatusMsgThree)); SendECUConfigOverCAN(stateData); } @@ -137,13 +104,13 @@ void SendECUAnalogDataOverCAN(const ECU_StateData *stateData) .bse_signal = stateData->bse_signal, .apps_1_signal = stateData->APPS1_Signal, .apps_2_signal = stateData->APPS2_Signal, - .brakeline_f_signal = stateData->Brake_F_Signal, - .brakeline_r_signal = stateData->Brake_R_Signal, + .brakeline_f_signal = stateData->Brake_Signal, + .brakeline_r_signal = 0, .steering_angle_signal = stateData->steering_angle_signal, .aux_signal = stateData->aux_signal, .acc_pedal_travel = CalcAccPedalTravel(stateData) * 65535, .brake_pedal_pressure = CalcBrakePressure(stateData)}; - ECU_CAN_Send(GRCAN_BUS_DATA, GRCAN_TCM, GRCAN_ECU_ANALOG_DATA, &message, sizeof(message)); + CubeCAN_Send(ECU_GetCANHandle(GRCAN_BUS_DATA), GRCAN_TCM, GRCAN_ECU_ANALOG_DATA, &message, sizeof(message)); last_can_tcm_request_millis = millis_since_boot; } } @@ -169,5 +136,5 @@ void SendECUConfigOverCAN(const ECU_StateData *stateData) .regen_strength = (uint8_t)(stateData->regen_strength * 10), .enable_regen = stateData->enable_regen}; - ECU_CAN_Send(GRCAN_BUS_DATA, GRCAN_TCM, GRCAN_ECU_CONFIG, &message, sizeof(message)); + CubeCAN_Send(ECU_GetCANHandle(GRCAN_BUS_DATA), GRCAN_TCM, GRCAN_ECU_CONFIG, &message, sizeof(message)); } diff --git a/ECU/Application/Src/Lights.c b/ECU/Application/Src/Lights.c index c86bb1efe..5a4ae1205 100644 --- a/ECU/Application/Src/Lights.c +++ b/ECU/Application/Src/Lights.c @@ -1,13 +1,13 @@ #include "Lights.h" #include "CANutils.h" +#include "CubeCAN.h" #include "Logomatic.h" #include "StateData.h" #include "StateMachine.h" #include "StateUtils.h" #include "adc.h" #include "bitManipulations.h" -#include "can.h" #include "main.h" #include "stm32g4xx_ll_gpio.h" @@ -65,14 +65,14 @@ void TSSILightControl(ECU_StateData *stateLump) } } -void TSActiveButtonLightControl(ECU_StateData *stateLump) -{ - if (stateLump->ecu_state == GR_GLV_ON || stateLump->ecu_state == GR_GLV_OFF) { - LL_GPIO_SetOutputPin(TS_ACTIVE_BTN_LED_CONTROL_GPIO_Port, TS_ACTIVE_BTN_LED_CONTROL_Pin); - } else { - LL_GPIO_ResetOutputPin(TS_ACTIVE_BTN_LED_CONTROL_GPIO_Port, TS_ACTIVE_BTN_LED_CONTROL_Pin); - } -} +// void TSActiveButtonLightControl(ECU_StateData *stateLump) +// { +// if (stateLump->ecu_state == GR_GLV_ON || stateLump->ecu_state == GR_GLV_OFF) { +// LL_GPIO_SetOutputPin(TS_ACTIVE_BTN_LED_CONTROL_GPIO_Port, TS_ACTIVE_BTN_LED_CONTROL_Pin); +// } else { +// LL_GPIO_ResetOutputPin(TS_ACTIVE_BTN_LED_CONTROL_GPIO_Port, TS_ACTIVE_BTN_LED_CONTROL_Pin); +// } +// } void RTD_ButtonLightControl(ECU_StateData *stateLump) { @@ -118,7 +118,7 @@ void RTD_ButtonLightControl(ECU_StateData *stateLump) multiplier = 1.0f; break; default: - LOGOMATIC("Invalid powerlevel: %d. Defaulting to 0.\n", stateLump->powerlevel); + LOGOMATIC_WARNING("Invalid powerlevel: %d. Defaulting to 0.\n", stateLump->powerlevel); multiplier = 0.0f; } @@ -128,7 +128,7 @@ void RTD_ButtonLightControl(ECU_StateData *stateLump) ECU_CAN_Send(GRCAN_BUS_PRIMARY, GRCAN_Dash_Panel, GRCAN_RTD_LIGHT_CTRL, &light_control, sizeof(light_control)); } else { - LOGOMATIC("Invalid torquemap: %d. Defaulting to off.\n", stateLump->torquemap); + LOGOMATIC_WARNING("Invalid torquemap: %d. Defaulting to off.\n", stateLump->torquemap); light_control.red = 0; light_control.green = 0; light_control.blue = 0; diff --git a/ECU/Application/Src/StateTicks.c b/ECU/Application/Src/StateTicks.c index 648fe5349..c59046d68 100644 --- a/ECU/Application/Src/StateTicks.c +++ b/ECU/Application/Src/StateTicks.c @@ -5,6 +5,7 @@ #include "CANutils.h" #include "ComparatorMacros.h" +#include "CubeCAN.h" #include "GRCAN_BUS_ID.h" #include "GRCAN_MSG_DATA.h" #include "GRCAN_MSG_ID.h" @@ -14,7 +15,6 @@ #include "StateMachine.h" #include "StateUtils.h" #include "Unused.h" -#include "can.h" #include "stm32g4xx_ll_gpio.h" /** @@ -69,7 +69,7 @@ void ECU_State_Tick(void) 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); + LOGOMATIC_INFO("ECU Current State: %d\n", stateLump.ecu_state); last_ECU_status_msg_millis = millis_since_boot; } @@ -107,8 +107,8 @@ void ECU_State_Tick(void) ECU_Tractive_System_Discharge(&stateLump); break; default: - LOGOMATIC("ECU Current State Unknown: %d\n", stateLump.ecu_state); - LOGOMATIC("ECU: Resetting to GLV On\n"); + LOGOMATIC_ERROR("ECU Current State Unknown: %d\n", stateLump.ecu_state); + LOGOMATIC_ERROR("ECU: Resetting to GLV On\n"); stateLump.ecu_state = GR_GLV_ON; break; } @@ -118,7 +118,7 @@ void ECU_GLV_Off(ECU_StateData *stateData) { disable_inverter(); UNUSED(stateData); - LOGOMATIC("ECU_GLV_Off state reached... this should never happen!\n"); + LOGOMATIC_CRITICAL("ECU_GLV_Off state reached... this should never happen!\n"); // TODO ERROR --> GLV_OFF should never be reached } @@ -127,21 +127,21 @@ void ECU_GLV_On(ECU_StateData *stateData) disable_inverter(); if (stateData->ts_voltage >= SAFE_VOLTAGE_LIMIT) { - LOGOMATIC("Error: TS Voltage >= %d!\n", SAFE_VOLTAGE_LIMIT); + LOGOMATIC_ERROR("Error: TS Voltage >= %d!\n", SAFE_VOLTAGE_LIMIT); ECU_Transition_To_Tractive_System_Discharge(stateData); ECU_CAN_Send(GRCAN_BUS_PRIMARY, GRCAN_Debugger, GRCAN_DEBUG_2_0, "TS-Runwy", 8); return; } if (stateData->ts_active_button_pressed /* && stateData->ir_plus*/) { // TODO: Talk to Owen if this is correct for precharge start confirmation - LOGOMATIC("GLV ON to PRECHARGE START!\n"); + LOGOMATIC_INFO("GLV ON to PRECHARGE START!\n"); ECU_Transition_To_Precharge_Engaged(stateData); return; } if (stateData->rtd_button_pressed) { stateData->powerlevel = (stateData->powerlevel + 1) % 6; - LOGOMATIC("Power level now at %d\n", stateData->powerlevel); + LOGOMATIC_INFO("Power level now at %d\n", stateData->powerlevel); } } @@ -153,7 +153,7 @@ void ECU_Transition_To_Precharge_Engaged(ECU_StateData *stateData) GRCAN_ACU_PRECHARGE_MSG message = {.set_ts_active = 1}; // Go TS Active/Precharge ECU_CAN_Send(GRCAN_BUS_PRIMARY, GRCAN_ACU, GRCAN_ACU_PRECHARGE, &message, sizeof(message)); stateData->ecu_state = GR_PRECHARGE_ENGAGED; - LOGOMATIC("PRECHARGE START to PRECHARGE ENGAGED!\n"); + LOGOMATIC_INFO("PRECHARGE START to PRECHARGE ENGAGED!\n"); time_start_precharge = millis_since_boot; return; } @@ -164,18 +164,18 @@ void ECU_Precharge_Engaged(ECU_StateData *stateData) if (stateData->ir_plus) { stateData->ecu_state = GR_PRECHARGE_COMPLETE; - LOGOMATIC("PRECHARGE ENGAGED to PRECHARGE COMPLETE!\n"); + LOGOMATIC_INFO("PRECHARGE ENGAGED to PRECHARGE COMPLETE!\n"); return; } if (CriticalError(stateData) || (millis_since_boot - time_start_precharge) >= stateData->max_precharge_time_ms) { - LOGOMATIC("CRITICAL ERROR! PRECHARGE ENGAGED to TS DISCHARGE START!\n"); + LOGOMATIC_CRITICAL("CRITICAL ERROR! PRECHARGE ENGAGED to TS DISCHARGE START!\n"); ECU_CAN_Send(GRCAN_BUS_PRIMARY, GRCAN_Debugger, GRCAN_DEBUG_2_0, "TS-P-ITR", 8); ECU_Transition_To_Tractive_System_Discharge(stateData); return; } if (stateData->ts_active_button_pressed) { - LOGOMATIC("ERROR: ts_active PRESSED! PRECHARGE ENGAGED to TS DISCHARGE START!\n"); + LOGOMATIC_ERROR("ERROR: ts_active PRESSED! PRECHARGE ENGAGED to TS DISCHARGE START!\n"); ECU_CAN_Send(GRCAN_BUS_PRIMARY, GRCAN_Debugger, GRCAN_DEBUG_2_0, "TS-P-ITR", 8); ECU_Transition_To_Tractive_System_Discharge(stateData); return; @@ -188,12 +188,12 @@ void ECU_Precharge_Complete(ECU_StateData *stateData) disable_inverter(); if (stateData->ts_active_button_pressed) { - LOGOMATIC("TS Active Toggled Off. Discharging Tractive System.\n"); + LOGOMATIC_INFO("TS Active Toggled Off. Discharging Tractive System.\n"); ECU_Transition_To_Tractive_System_Discharge(stateData); return; } if (CriticalError(stateData)) { - LOGOMATIC("Error: Critical Error Occurred. Discharging Tractive System.\n"); + LOGOMATIC_CRITICAL("Error: Critical Error Occurred. Discharging Tractive System.\n"); ECU_Transition_To_Tractive_System_Discharge(stateData); ECU_CAN_Send(GRCAN_BUS_PRIMARY, GRCAN_Debugger, GRCAN_DEBUG_2_0, "HV-CritE", 8); return; @@ -202,7 +202,7 @@ void ECU_Precharge_Complete(ECU_StateData *stateData) if (PressingBrake(stateData) && stateData->rtd_button_pressed && (CalcAccPedalTravel(stateData) < stateData->apps_deadzone)) { GRCAN_INV_CONFIG_MSG inverter_message = {.max_ac_current = 0xFFFF, .max_dc_current = 0xFFFF, .absolute_max_rpm_limit = 0xFFFF, .motor_direction = 0}; ECU_CAN_Send(GRCAN_BUS_PRIMARY, GRCAN_GR_Inv, GRCAN_INV_CONFIG, &inverter_message, sizeof(inverter_message)); - LOGOMATIC("PRECHARGE COMPLETE to DRIVE START/ACTIVE!\n"); + LOGOMATIC_INFO("PRECHARGE COMPLETE to DRIVE START/ACTIVE!\n"); ECU_Transition_To_Drive_Active(stateData); } } @@ -218,13 +218,13 @@ void ECU_Transition_To_Drive_Active(ECU_StateData *stateData) void ECU_Drive_Active(ECU_StateData *stateData) { if (CriticalError(stateData)) { - LOGOMATIC("Error: Critical Error Occured. Discharging Tractive System.\n"); + LOGOMATIC_CRITICAL("Error: Critical Error Occured. Discharging Tractive System.\n"); ECU_Transition_To_Tractive_System_Discharge(stateData); ECU_CAN_Send(GRCAN_BUS_PRIMARY, GRCAN_Debugger, GRCAN_DEBUG_2_0, "DA-CritE", 8); return; } if (stateData->ts_active_button_pressed) { - LOGOMATIC("Error: TS active button pressed in Drive Active state. Discharging Tractive System.\n"); + LOGOMATIC_ERROR("Error: TS active button pressed in Drive Active state. Discharging Tractive System.\n"); ECU_Transition_To_Tractive_System_Discharge(stateData); ECU_CAN_Send(GRCAN_BUS_PRIMARY, GRCAN_Debugger, GRCAN_DEBUG_2_0, "DA-CritE", 8); return; @@ -239,7 +239,7 @@ void ECU_Drive_Active(ECU_StateData *stateData) if (stateData->rtd_button_pressed) { stateData->ecu_state = GR_PRECHARGE_COMPLETE; if (stateData->vehicle_speed_mph > 0) { - LOGOMATIC("Warning: Vehicle is moving during state transition.\n"); + LOGOMATIC_WARNING("Warning: Vehicle is moving during state transition.\n"); } return; } @@ -281,7 +281,7 @@ void ECU_Drive_Active(ECU_StateData *stateData) max_rev_current = 120; break; default: - LOGOMATIC("Invalid power level: %d. Defaulting to no regen.\n", stateData->powerlevel); + LOGOMATIC_ERROR("Invalid power level: %d. Defaulting to no regen.\n", stateData->powerlevel); max_rev_current = 0; break; } @@ -289,25 +289,15 @@ void ECU_Drive_Active(ECU_StateData *stateData) uint16_t max_fwd_current = 0; switch (stateData->powerlevel) { case 0: - max_fwd_current = 300; - break; case 1: - max_fwd_current = 300; - break; case 2: - max_fwd_current = 300; - break; case 3: - max_fwd_current = 300; - break; case 4: - max_fwd_current = 300; - break; case 5: max_fwd_current = 300; break; default: - LOGOMATIC("Invalid power level: %d. Defaulting to no forward torque.\n", stateData->powerlevel); + LOGOMATIC_ERROR("Invalid power level: %d. Defaulting to no forward torque.\n", stateData->powerlevel); max_fwd_current = 0; break; } @@ -362,7 +352,7 @@ static uint32_t discharge_start_millis; void ECU_Transition_To_Tractive_System_Discharge(ECU_StateData *stateData) { stateData->ecu_state = GR_TS_DISCHARGE; - LOGOMATIC("ECU: ACU discharge Tractive System\n"); + LOGOMATIC_INFO("ECU: ACU discharge Tractive System\n"); GRCAN_ACU_PRECHARGE_MSG message = {.set_ts_active = 0}; ECU_CAN_Send(GRCAN_BUS_PRIMARY, GRCAN_ACU, GRCAN_ACU_PRECHARGE, &message, sizeof(message)); discharge_start_millis = millis_since_boot; @@ -377,7 +367,7 @@ void ECU_Tractive_System_Discharge(ECU_StateData *stateData) */ if (stateData->ts_voltage < SAFE_VOLTAGE_LIMIT) { stateData->ecu_state = GR_GLV_ON; - LOGOMATIC("TS DISCHARGE to GLV ON!\n"); + LOGOMATIC_INFO("TS DISCHARGE to GLV ON!\n"); return; } /* @@ -389,7 +379,7 @@ void ECU_Tractive_System_Discharge(ECU_StateData *stateData) static uint32_t last_discharge_request_millis; if (RATE_LIMIT_100_HZ(millis_since_boot, last_discharge_request_millis)) { if (millis_since_boot - discharge_start_millis > TRACTIVE_SYSTEM_MAX_PERMITTED_DISCHARGE_TIME_MILLIS) { - LOGOMATIC("Warning: Tractive System fails to discharge in %d ms.\n", TRACTIVE_SYSTEM_MAX_PERMITTED_DISCHARGE_TIME_MILLIS); + LOGOMATIC_WARNING("Warning: Tractive System fails to discharge in %d ms.\n", TRACTIVE_SYSTEM_MAX_PERMITTED_DISCHARGE_TIME_MILLIS); ECU_CAN_Send(GRCAN_BUS_PRIMARY, GRCAN_Debugger, GRCAN_DEBUG_2_0, "TS-D-TLE", 8); } diff --git a/ECU/Application/Src/StateUtils.c b/ECU/Application/Src/StateUtils.c index 85929bafb..05bfc603b 100644 --- a/ECU/Application/Src/StateUtils.c +++ b/ECU/Application/Src/StateUtils.c @@ -11,13 +11,12 @@ #include "GRCAN_MSG_ID.h" #include "GRCAN_NODE_ID.h" #include "Logomatic.h" -#include "Plan_C.h" #include "StateData.h" #include "Unused.h" #include "main.h" #include "stm32g4xx_hal.h" #include "stm32g4xx_ll_gpio.h" -#include "vcp.h" +// #include "vcp.h" /** * @brief Delay after startup to allow IMD sense to stabilize before considering IMD sense failures valid @@ -52,8 +51,9 @@ bool CriticalError(volatile const ECU_StateData *stateData) problem |= bmsFailure(stateData); problem |= bspdFailure(stateData); if (problem) { - LOGOMATIC("Critical Error Detected in State %d | %f C | %f V | ACU SW %d | IR+ %d | IR- %d | IMD %d | BMS %d | BSPD %d\n", stateData->ecu_state, stateData->max_cell_temp_c, - stateData->ts_voltage, stateData->acu_software_latch, stateData->ir_plus, stateData->ir_minus, imdFailure(stateData), bmsFailure(stateData), bspdFailure(stateData)); + LOGOMATIC_CRITICAL("Critical Error Detected in State %d | %f C | %f V | ACU SW %d | IR+ %d | IR- %d | IMD %d | BMS %d | BSPD %d\n", stateData->ecu_state, + (double)stateData->max_cell_temp_c, (double)stateData->ts_voltage, stateData->acu_software_latch, stateData->ir_plus, stateData->ir_minus, imdFailure(stateData), + bmsFailure(stateData), bspdFailure(stateData)); // LL_GPIO_ResetOutputPin(SOFTWARE_OK_CONTROL_GPIO_Port, SOFTWARE_OK_CONTROL_Pin); } return problem; @@ -185,5 +185,5 @@ void Send_VCP_APPS(const ECU_StateData *stateData, uint16_t apps1_raw, uint16_t #define SIZE 64 static char buf[SIZE]; snprintf(buf, SIZE, "%" PRIu32 " A1 %d A2 %d A1R %d A2R %d\n", MillisecondsSinceBoot(), stateData->APPS1_Signal, stateData->APPS2_Signal, apps1_raw, apps2_raw); - VCP_Send(buf, strlen(buf)); + // VCP_Send(buf, strlen(buf)); } diff --git a/ECU/CMakeLists.txt b/ECU/CMakeLists.txt index b63573e3a..0a83d76cb 100644 --- a/ECU/CMakeLists.txt +++ b/ECU/CMakeLists.txt @@ -1,17 +1,17 @@ -cmake_minimum_required(VERSION 3.25) +# cmake_minimum_required(VERSION 3.25) -# Setup compiler settings -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS ON) +# # Setup compiler settings +# set(CMAKE_C_STANDARD 11) +# set(CMAKE_C_STANDARD_REQUIRED ON) +# set(CMAKE_C_EXTENSIONS ON) -# Define the build type -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Debug") -endif() +# # Define the build type +# if(NOT CMAKE_BUILD_TYPE) +# set(CMAKE_BUILD_TYPE "Debug") +# endif() -# what, does in fact not get the filename of somthing but rather the name of the project from the path -get_filename_component(GR_PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) +# # what, does in fact not get the filename of somthing but rather the name of the project from the path +# get_filename_component(GR_PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) #TODO: when CAN implementation is settled, turn HOOTL tests back on if(CMAKE_PRESET_NAME STREQUAL "HOOTLTest") @@ -38,12 +38,10 @@ if(CMAKE_PRESET_NAME STREQUAL "HOOTLTest") PRIVATE GLOBALSHARE_LIB CANfigurator - LOGOMATIC_OLD_LIB + LOGOMATIC_LIB m - # GR_ADC - # PERIPHERAL_CAN_LIB + CUBE_CAN_LIB BitManipulations_Lib - VCP_LIB ) add_test(StateTicksTest StateTicksTest) @@ -51,22 +49,32 @@ if(CMAKE_PRESET_NAME STREQUAL "HOOTLTest") endif() # Enable CMake support for ASM and C languages -enable_language( - C - ASM -) +# enable_language( +# C +# ASM +# ) -# Core project settings -project(${CMAKE_PROJECT_NAME}) +# # Core project settings +# project(${CMAKE_PROJECT_NAME}) # Questionable... # set(TARGET_FLAGS "-mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard ") # set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS "-T${CHIP_PATH}/CompileDependencies/STM32G474RETx_FLASH.ld") -add_library(${GR_PROJECT_NAME}_USER_CODE INTERFACE) +target_link_options( + ${TARGET_NAME} + PRIVATE + -T + "${CMAKE_CURRENT_SOURCE_DIR}/STM32G474xx_FLASH.ld" +) + +target_compile_definitions(${TARGET_NAME} PRIVATE STM32G474xx) + + +#add_library(${TARGET_NAME}_USER_CODE INTERFACE) target_sources( - ${GR_PROJECT_NAME}_USER_CODE - INTERFACE + ${TARGET_NAME} + PRIVATE # Core Core/Src/adc.c Core/Src/dma.c @@ -75,6 +83,14 @@ target_sources( Core/Src/main.c Core/Src/stm32g4xx_hal_msp.c Core/Src/stm32g4xx_it.c + Core/Src/tim.c + Core/Src/syscalls.c + Core/Src/sysmem.c + Core/Src/system_stm32g4xx.c + Core/Src/usart.c + + startup_stm32g474xx.s + # Application Application/Src/CANdler.c Application/Src/StateTicks.c @@ -85,18 +101,18 @@ target_sources( ) target_link_libraries( - ${GR_PROJECT_NAME}_USER_CODE - INTERFACE + ${TARGET_NAME} + PRIVATE CANfigurator - GR_ADC - PERIPHERAL_TIMEDCAN_LIB BitManipulations_Lib - VCP_LIB + CUBE_CAN_LIB + # CUBE_VCP_LIB # TODO Add VCP back in when we have a plan for how to use it + LOGOMATIC_LIB ) target_include_directories( - ${GR_PROJECT_NAME}_USER_CODE - INTERFACE + ${TARGET_NAME} + PRIVATE Application/Inc Core/Inc ) diff --git a/ECU/Core/Inc/adc.h b/ECU/Core/Inc/adc.h index d1e987162..d26028cd3 100644 --- a/ECU/Core/Inc/adc.h +++ b/ECU/Core/Inc/adc.h @@ -32,15 +32,24 @@ extern "C" { /* USER CODE END Includes */ +extern ADC_HandleTypeDef hadc1; + +extern ADC_HandleTypeDef hadc2; + +extern ADC_HandleTypeDef hadc5; + /* USER CODE BEGIN Private defines */ /* USER CODE END Private defines */ void MX_ADC1_Init(void); void MX_ADC2_Init(void); +void MX_ADC5_Init(void); /* USER CODE BEGIN Prototypes */ +void ADC_UpdateAnalogValues_EMA(volatile uint16_t *ADC_buffers, uint8_t num_signals, float alpha, volatile uint16_t *ADC_outputs); + /* USER CODE END Prototypes */ #ifdef __cplusplus @@ -48,3 +57,4 @@ void MX_ADC2_Init(void); #endif #endif /* __ADC_H__ */ + diff --git a/ECU/Core/Inc/dma.h b/ECU/Core/Inc/dma.h index ae819cab4..2a2856f62 100644 --- a/ECU/Core/Inc/dma.h +++ b/ECU/Core/Inc/dma.h @@ -49,3 +49,4 @@ void MX_DMA_Init(void); #endif #endif /* __DMA_H__ */ + diff --git a/ECU/Core/Inc/fdcan.h b/ECU/Core/Inc/fdcan.h index 9652dd8ad..6e2fd951b 100644 --- a/ECU/Core/Inc/fdcan.h +++ b/ECU/Core/Inc/fdcan.h @@ -37,6 +37,8 @@ extern FDCAN_HandleTypeDef hfdcan1; extern FDCAN_HandleTypeDef hfdcan2; /* USER CODE BEGIN Private defines */ +#define DTI_RX_ID 0x00000016u +#define DTI_RX_MASK 0x1FFFC0FFu /* USER CODE END Private defines */ @@ -52,3 +54,4 @@ void MX_FDCAN2_Init(void); #endif #endif /* __FDCAN_H__ */ + diff --git a/ECU/Core/Inc/gpio.h b/ECU/Core/Inc/gpio.h index 702fc0cc1..d291b7801 100644 --- a/ECU/Core/Inc/gpio.h +++ b/ECU/Core/Inc/gpio.h @@ -46,3 +46,4 @@ void MX_GPIO_Init(void); } #endif #endif /*__ GPIO_H__ */ + diff --git a/ECU/Core/Inc/main.h b/ECU/Core/Inc/main.h index 7331e5ca0..6bcbc3214 100644 --- a/ECU/Core/Inc/main.h +++ b/ECU/Core/Inc/main.h @@ -28,24 +28,17 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" -#include "stm32g4xx_ll_adc.h" + +/* Private includes ----------------------------------------------------------*/ +/* USER CODE BEGIN Includes */ +#include "GRCAN_MSG_DATA.h" +#include "GRCAN_NODE_ID.h" #include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_cortex.h" -#include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_dma.h" -#include "stm32g4xx_ll_exti.h" #include "stm32g4xx_ll_gpio.h" #include "stm32g4xx_ll_lpuart.h" -#include "stm32g4xx_ll_pwr.h" #include "stm32g4xx_ll_rcc.h" -#include "stm32g4xx_ll_system.h" #include "stm32g4xx_ll_usart.h" #include "stm32g4xx_ll_utils.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ -#include "GRCAN_NODE_ID.h" -#include "Plan_C.h" /* USER CODE END Includes */ /* Exported types ------------------------------------------------------------*/ @@ -53,30 +46,33 @@ extern "C" { /* ADC mappings from `ADC_buffers` and `ADC_outputs` arrays to signal/sense names */ enum { - /* Brake Signal Encoder - Signal */ - ADC_BUFFER_SIG_BSE = 0, - /* Brake System Plausibility Device - Signal */ - ADC_BUFFER_SIG_BSPD = 1, /* Accelerator Pedal Position Sensor 1 - Signal */ - ADC_BUFFER_SIG_APPS1 = 2, + ADC_BUFFER_SIG_APPS1 = 0, + /* Brake Pressure - Signal */ + ADC_BUFFER_SIG_BRAKE = 1, + /* Steering Angle - Signal */ + ADC_BUFFER_SIG_STEERING_ANGLE = 2, + /* Brake System Plausibility Device - Signal */ + ADC_BUFFER_SIG_BSPD = 3, + /* Brake System Plausibility Device - Sense */ + ADC_BUFFER_SENSE_BSPD = 4, + /* Accelerator Pedal Position Sensor 2 - Signal */ - ADC_BUFFER_SIG_APPS2 = 3, - /* Front Brake Pressure - Signal */ - ADC_BUFFER_SIG_BRAKE_F = 0, - /* Rear Brake Pressure - Signal */ - ADC_BUFFER_SIG_BRAKE_R = 4, + ADC_BUFFER_SIG_APPS2 = 5, + /* Brake Signal Encoder - Signal */ + ADC_BUFFER_SIG_BSE = 6, + /* Accumulator Management System - Sense */ + ADC_BUFFER_SENSE_BMS = 7, /* Auxiliary - Signal */ - ADC_BUFFER_SIG_AUX = 6, - /* Brake System Plausibility Device - Sense */ - ADC_BUFFER_SENSE_BSPD = 7, + ADC_BUFFER_SIG_AUX = 8, + /* Spare - Signal */ + ADC_BUFFER_SIG_SPARE2 = 9, + /* Insulation Monitoring Device - Sense */ - ADC_BUFFER_SENSE_IMD = 8, - /* Accumulator Management System - Sense */ - ADC_BUFFER_SENSE_BMS = 9, - /* Steering Angle - Signal */ - ADC_BUFFER_SIG_STEERING_ANGLE = 10, + ADC_BUFFER_SENSE_IMD = 10, }; + /* USER CODE END ET */ /* Exported constants --------------------------------------------------------*/ @@ -96,58 +92,47 @@ void Error_Handler(void); /* USER CODE END EFP */ -/* USER CODE BEGIN Private defines */ -#define MAIN_LOOP_PERIOD_US 10000 -#define CAN_TIMER_SEND_PERIOD_US (MAIN_LOOP_PERIOD_US >> 4) - /* Private defines -----------------------------------------------------------*/ -// GPIOC -#define BSE_SIGNAL_Pin LL_GPIO_PIN_0 /// Following net names, see @ref ADC_BUFFER_SIG_BSE -#define BSE_SIGNAL_GPIO_Port GPIOC /// Following net names, see @ref ADC_BUFFER_SIG_BSE -#define BSPD_SIGNAL_Pin LL_GPIO_PIN_1 -#define BSPD_SIGNAL_GPIO_Port GPIOC -#define APPS1_SIGNAL_Pin LL_GPIO_PIN_2 +#define BRAKE_LIGHT_Pin GPIO_PIN_14 +#define BRAKE_LIGHT_GPIO_Port GPIOC +#define SPARE_1_SIGNAL_Pin GPIO_PIN_1 +#define SPARE_1_SIGNAL_GPIO_Port GPIOF +#define BRAKE_SIGNAL_Pin GPIO_PIN_1 +#define BRAKE_SIGNAL_GPIO_Port GPIOC +#define APPS1_SIGNAL_Pin GPIO_PIN_3 #define APPS1_SIGNAL_GPIO_Port GPIOC -#define APPS2_SIGNAL_Pin LL_GPIO_PIN_3 -#define APPS2_SIGNAL_GPIO_Port GPIOC - -// GPIOA -#define BSPD_SENSE_Pin LL_GPIO_PIN_5 -#define BSPD_SENSE_GPIO_Port GPIOA -#define IMD_SENSE_Pin LL_GPIO_PIN_6 +#define STEERING_ANGLE_Pin GPIO_PIN_3 +#define STEERING_ANGLE_GPIO_Port GPIOA +#define APPS2_SIGNAL_Pin GPIO_PIN_4 +#define APPS2_SIGNAL_GPIO_Port GPIOA +#define SPARE_2_SIGNAL_Pin GPIO_PIN_7 +#define SPARE_2_SIGNAL_GPIO_Port GPIOA +#define BSPD_SIGNAL_Pin GPIO_PIN_0 +#define BSPD_SIGNAL_GPIO_Port GPIOB +#define BSE_SIGNAL_Pin GPIO_PIN_2 +#define BSE_SIGNAL_GPIO_Port GPIOB +#define SOFTWARE_OK_CONTROL_Pin GPIO_PIN_11 +#define SOFTWARE_OK_CONTROL_GPIO_Port GPIOB +#define BSPD_SENSE_Pin GPIO_PIN_14 +#define BSPD_SENSE_GPIO_Port GPIOB +#define AMS_SENSE_Pin GPIO_PIN_15 +#define AMS_SENSE_GPIO_Port GPIOB +#define IMD_SENSE_Pin GPIO_PIN_9 #define IMD_SENSE_GPIO_Port GPIOA -#define AMS_SENSE_Pin LL_GPIO_PIN_7 -#define AMS_SENSE_GPIO_Port GPIOA -#define ESTOP_SENSE_Pin LL_GPIO_PIN_15 -#define ESTOP_SENSE_GPIO_Port GPIOA - -// GPIOB -#define BRAKE_F_SIGNAL_Pin LL_GPIO_PIN_0 /// Following net names, see @ref ADC_BUFFER_SIG_BSE -#define BRAKE_F_SIGNAL_GPIO_Port GPIOB /// Following net names, see @ref ADC_BUFFER_SIG_BSE -#define BRAKE_R_SIGNAL_Pin LL_GPIO_PIN_1 /// Following net names, see @ref ADC_BUFFER_SIG_BSE -#define BRAKE_R_SIGNAL_GPIO_Port GPIOB /// Following net names, see @ref ADC_BUFFER_SIG_BSE -#define LED_TEST_Pin LL_GPIO_PIN_11 -#define LED_TEST_GPIO_Port GPIOB -#define AUX_SIGNAL_Pin LL_GPIO_PIN_14 -#define AUX_SIGNAL_GPIO_Port GPIOB -#define STEERING_ANGLE_Pin LL_GPIO_PIN_15 -#define STEERING_ANGLE_GPIO_Port GPIOB -#define BRAKE_LIGHT_Pin LL_GPIO_PIN_4 -#define BRAKE_LIGHT_GPIO_Port GPIOB -#define TSSI_G_CONTROL_Pin LL_GPIO_PIN_5 -#define TSSI_G_CONTROL_GPIO_Port GPIOB -#define TSSI_R_CONTROL_Pin LL_GPIO_PIN_6 +#define LED_TEST_Pin GPIO_PIN_15 +#define LED_TEST_GPIO_Port GPIOA +#define TSSI_G_CONTROL_Pin GPIO_PIN_2 +#define TSSI_G_CONTROL_GPIO_Port GPIOD +#define TSSI_R_CONTROL_Pin GPIO_PIN_4 #define TSSI_R_CONTROL_GPIO_Port GPIOB -#define TS_ACTIVE_BTN_LED_CONTROL_Pin LL_GPIO_PIN_9 -#define TS_ACTIVE_BTN_LED_CONTROL_GPIO_Port GPIOA -#define RTD_BTN_LED_CONTROL_Pin LL_GPIO_PIN_8 -#define RTD_BTN_LED_CONTROL_GPIO_Port GPIOA -#define RTD_CONTROL_Pin LL_GPIO_PIN_7 +#define RTD_CONTROL_Pin GPIO_PIN_7 #define RTD_CONTROL_GPIO_Port GPIOB -#define AUX_CONTROL_Pin LL_GPIO_PIN_8 -#define AUX_CONTROL_GPIO_Port GPIOB -#define SOFTWARE_OK_CONTROL_Pin LL_GPIO_PIN_9 -#define SOFTWARE_OK_CONTROL_GPIO_Port GPIOB + +/* USER CODE BEGIN Private defines */ +#define MAIN_LOOP_PERIOD_US 10000 +#define CAN_TIMER_SEND_PERIOD_US (MAIN_LOOP_PERIOD_US >> 4) + +/* Private defines -----------------------------------------------------------*/ /* USER CODE END Private defines */ diff --git a/ECU/Core/Inc/stm32_assert.h b/ECU/Core/Inc/stm32_assert.h new file mode 100644 index 000000000..92460620f --- /dev/null +++ b/ECU/Core/Inc/stm32_assert.h @@ -0,0 +1,52 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32_assert.h + * @author MCD Application Team + * @brief STM32 assert file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2019 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32_ASSERT_H +#define __STM32_ASSERT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ +/* Includes ------------------------------------------------------------------*/ +/* Exported macro ------------------------------------------------------------*/ +#ifdef USE_FULL_ASSERT +/** + * @brief The assert_param macro is used for function's parameters check. + * @param expr: If expr is false, it calls assert_failed function + * which reports the name of the source file and the source + * line number of the call that failed. + * If expr is true, it returns no value. + * @retval None + */ +#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) +/* Exported functions ------------------------------------------------------- */ +void assert_failed(uint8_t *file, uint32_t line); +#else +#define assert_param(expr) ((void)0U) +#endif /* USE_FULL_ASSERT */ + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32_ASSERT_H */ diff --git a/ECU/Core/Inc/stm32g4xx_hal_conf.h b/ECU/Core/Inc/stm32g4xx_hal_conf.h index c67a3a915..652d2cb04 100644 --- a/ECU/Core/Inc/stm32g4xx_hal_conf.h +++ b/ECU/Core/Inc/stm32g4xx_hal_conf.h @@ -23,7 +23,7 @@ #define STM32G4xx_HAL_CONF_H #ifdef __cplusplus -extern "C" { + extern "C" { #endif /* Exported types ------------------------------------------------------------*/ @@ -31,12 +31,12 @@ extern "C" { /* ########################## Module Selection ############################## */ /** - * @brief This is the list of modules to be used in the HAL driver - */ + * @brief This is the list of modules to be used in the HAL driver + */ #define HAL_MODULE_ENABLED -/*#define HAL_ADC_MODULE_ENABLED */ + #define HAL_ADC_MODULE_ENABLED /*#define HAL_COMP_MODULE_ENABLED */ /*#define HAL_CORDIC_MODULE_ENABLED */ /*#define HAL_CRC_MODULE_ENABLED */ @@ -63,7 +63,7 @@ extern "C" { /*#define HAL_SPI_MODULE_ENABLED */ /*#define HAL_SRAM_MODULE_ENABLED */ #define HAL_TIM_MODULE_ENABLED -/*#define HAL_UART_MODULE_ENABLED */ +#define HAL_UART_MODULE_ENABLED /*#define HAL_USART_MODULE_ENABLED */ /*#define HAL_WWDG_MODULE_ENABLED */ #define HAL_GPIO_MODULE_ENABLED @@ -74,135 +74,125 @@ extern "C" { #define HAL_PWR_MODULE_ENABLED #define HAL_CORTEX_MODULE_ENABLED -/* ########################## Register Callbacks selection - * ############################## */ +/* ########################## Register Callbacks selection ############################## */ /** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U - -/* ########################## Oscillator Values adaptation - * ####################*/ + * @brief This is the list of modules where register callback can be used + */ +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U +#define USE_HAL_COMP_REGISTER_CALLBACKS 0U +#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U +#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U +#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U +#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U +#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 0U +#define USE_HAL_USART_REGISTER_CALLBACKS 0U +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U + +/* ########################## Oscillator Values adaptation ####################*/ /** - * @brief Adjust the value of External High Speed oscillator (HSE) used in your - * application. This value is used by the RCC HAL module to compute the system - * frequency (when HSE is used as system clock source, directly or through the - * PLL). - */ -#if !defined(HSE_VALUE) -#define HSE_VALUE (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined(HSE_STARTUP_TIMEOUT) -#define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ + * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSE is used as system clock source, directly or through the PLL). + */ +#if !defined (HSE_VALUE) + #define HSE_VALUE (8000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */ +#endif /* HSE_STARTUP_TIMEOUT */ /** - * @brief Internal High Speed oscillator (HSI) value. - * This value is used by the RCC HAL module to compute the system - * frequency (when HSI is used as system clock source, directly or through the - * PLL). - */ -#if !defined(HSI_VALUE) -#define HSI_VALUE (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ + * @brief Internal High Speed oscillator (HSI) value. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSI is used as system clock source, directly or through the PLL). + */ +#if !defined (HSI_VALUE) + #define HSI_VALUE (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ /** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high - * precision clock to the USB peripheral by means of a special Clock Recovery - * System (CRS) circuitry. When the CRS is not used, the HSI48 RC oscillator - * runs on it default frequency which is subject to manufacturing process - * variations. - */ -#if !defined(HSI48_VALUE) -#define HSI48_VALUE \ - (48000000UL) /*!< Value of the Internal High Speed oscillator for USB \ - FS/RNG in Hz. The real value my vary depending on \ - manufacturing process variations.*/ -#endif /* HSI48_VALUE */ + * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. + * This internal oscillator is mainly dedicated to provide a high precision clock to + * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. + * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency + * which is subject to manufacturing process variations. + */ +#if !defined (HSI48_VALUE) + #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ /** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined(LSI_VALUE) + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined (LSI_VALUE) /*!< Value of the Internal Low Speed oscillator in Hz -The real value may vary depending on the variations in voltage and -temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ +The real value may vary depending on the variations in voltage and temperature.*/ +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system - * frequency - */ -#if !defined(LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined (LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ -#if !defined(LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ +#if !defined (LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ /** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S - * and SAI clock source frequency, this source is inserted directly through - * I2S_CKIN pad. - */ -#if !defined(EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/ -#endif /* EXTERNAL_CLOCK_VALUE */ + * @brief External clock source for I2S and SAI peripherals + * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined (EXTERNAL_CLOCK_VALUE) +#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/ +#endif /* EXTERNAL_CLOCK_VALUE */ /* Tip: To avoid modifying this file each time you need to use different HSE, === you can define the HSE value in your toolchain compiler preprocessor. */ /* ########################### System Configuration ######################### */ /** - * @brief This is the HAL system configuration section - */ + * @brief This is the HAL system configuration section + */ -#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U +#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U /* ########################## Assert Selection ############################## */ /** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ -/* #define USE_FULL_ASSERT 1U */ + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ + #define USE_FULL_ASSERT 1U /* ################## SPI peripheral configuration ########################## */ @@ -211,12 +201,12 @@ temperature.*/ * Deactivated: CRC code cleaned from driver */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U /* Includes ------------------------------------------------------------------*/ /** - * @brief Include module's header file - */ + * @brief Include module's header file + */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g4xx_hal_rcc.h" @@ -367,15 +357,15 @@ temperature.*/ #endif /* HAL_WWDG_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#ifdef USE_FULL_ASSERT /** - * @brief The assert_param macro is used for function's parameters check. - * @param expr: If expr is false, it calls assert_failed function - * which reports the name of the source file and the source - * line number of the call that failed. - * If expr is true, it returns no value. - * @retval None - */ + * @brief The assert_param macro is used for function's parameters check. + * @param expr: If expr is false, it calls assert_failed function + * which reports the name of the source file and the source + * line number of the call that failed. + * If expr is true, it returns no value. + * @retval None + */ #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ void assert_failed(uint8_t *file, uint32_t line); diff --git a/ECU/Core/Inc/stm32g4xx_it.h b/ECU/Core/Inc/stm32g4xx_it.h index e08bcd52a..d0677c2c3 100644 --- a/ECU/Core/Inc/stm32g4xx_it.h +++ b/ECU/Core/Inc/stm32g4xx_it.h @@ -55,6 +55,17 @@ void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); +void DMA1_Channel1_IRQHandler(void); +void DMA1_Channel2_IRQHandler(void); +void ADC1_2_IRQHandler(void); +void FDCAN1_IT0_IRQHandler(void); +void FDCAN1_IT1_IRQHandler(void); +void TIM6_DAC_IRQHandler(void); +void DMA2_Channel1_IRQHandler(void); +void ADC5_IRQHandler(void); +void FDCAN2_IT0_IRQHandler(void); +void FDCAN2_IT1_IRQHandler(void); +void DMAMUX_OVR_IRQHandler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ diff --git a/ECU/Core/Inc/tim.h b/ECU/Core/Inc/tim.h new file mode 100644 index 000000000..7c1769f65 --- /dev/null +++ b/ECU/Core/Inc/tim.h @@ -0,0 +1,52 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file tim.h + * @brief This file contains all the function prototypes for + * the tim.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __TIM_H__ +#define __TIM_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +extern TIM_HandleTypeDef htim6; + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_TIM6_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __TIM_H__ */ + diff --git a/ECU/Core/Inc/usart.h b/ECU/Core/Inc/usart.h new file mode 100644 index 000000000..2ee625c96 --- /dev/null +++ b/ECU/Core/Inc/usart.h @@ -0,0 +1,52 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file usart.h + * @brief This file contains all the function prototypes for + * the usart.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USART_H__ +#define __USART_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +extern UART_HandleTypeDef huart3; + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_USART3_UART_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USART_H__ */ + diff --git a/ECU/Core/Src/adc.c b/ECU/Core/Src/adc.c index ae1d230d3..fd42824c5 100644 --- a/ECU/Core/Src/adc.c +++ b/ECU/Core/Src/adc.c @@ -24,304 +24,588 @@ /* USER CODE END 0 */ +ADC_HandleTypeDef hadc1; +ADC_HandleTypeDef hadc2; +ADC_HandleTypeDef hadc5; +DMA_HandleTypeDef hdma_adc1; +DMA_HandleTypeDef hdma_adc2; +DMA_HandleTypeDef hdma_adc5; + /* ADC1 init function */ void MX_ADC1_Init(void) { - /* USER CODE BEGIN ADC1_Init 0 */ - - /* USER CODE END ADC1_Init 0 */ - - LL_ADC_InitTypeDef ADC_InitStruct = {0}; - LL_ADC_REG_InitTypeDef ADC_REG_InitStruct = {0}; - LL_ADC_CommonInitTypeDef ADC_CommonInitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetADCClockSource(LL_RCC_ADC12_CLKSOURCE_SYSCLK); - - /* Peripheral clock enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_ADC12); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - /**ADC1 GPIO Configuration - PC1 ------> ADC1_IN7 - PC2 ------> ADC1_IN8 - PC3 ------> ADC1_IN9 - PB0 ------> ADC1_IN15 - PB1 ------> ADC1_IN12 - PB14 ------> ADC1_IN5 - */ - GPIO_InitStruct.Pin = BSPD_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BSPD_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = APPS1_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(APPS1_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = APPS2_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(APPS2_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = BRAKE_F_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BRAKE_F_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = BRAKE_R_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BRAKE_R_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = AUX_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(AUX_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - /* ADC1 DMA Init */ - - /* ADC1 Init */ - LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_1, LL_DMAMUX_REQ_ADC1); - - LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_1, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); - - LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PRIORITY_LOW); - - LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MODE_CIRCULAR); - - LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PERIPH_NOINCREMENT); - - LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MEMORY_INCREMENT); - - LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PDATAALIGN_HALFWORD); - - LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MDATAALIGN_HALFWORD); - - /* USER CODE BEGIN ADC1_Init 1 */ - - /* USER CODE END ADC1_Init 1 */ - - /** Common config - */ - ADC_InitStruct.Resolution = LL_ADC_RESOLUTION_12B; - ADC_InitStruct.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT; - ADC_InitStruct.LowPowerMode = LL_ADC_LP_MODE_NONE; - LL_ADC_Init(ADC1, &ADC_InitStruct); - ADC_REG_InitStruct.TriggerSource = LL_ADC_REG_TRIG_SOFTWARE; - ADC_REG_InitStruct.SequencerLength = LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS; - ADC_REG_InitStruct.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE; - ADC_REG_InitStruct.ContinuousMode = LL_ADC_REG_CONV_CONTINUOUS; - ADC_REG_InitStruct.DMATransfer = LL_ADC_REG_DMA_TRANSFER_UNLIMITED; - ADC_REG_InitStruct.Overrun = LL_ADC_REG_OVR_DATA_PRESERVED; - LL_ADC_REG_Init(ADC1, &ADC_REG_InitStruct); - LL_ADC_SetGainCompensation(ADC1, 0); - LL_ADC_SetOverSamplingScope(ADC1, LL_ADC_OVS_DISABLE); - ADC_CommonInitStruct.CommonClock = LL_ADC_CLOCK_ASYNC_DIV4; - ADC_CommonInitStruct.Multimode = LL_ADC_MULTI_INDEPENDENT; - LL_ADC_CommonInit(__LL_ADC_COMMON_INSTANCE(ADC1), &ADC_CommonInitStruct); - - /* Disable ADC deep power down (enabled by default after reset state) */ - LL_ADC_DisableDeepPowerDown(ADC1); - /* Enable ADC internal voltage regulator */ - LL_ADC_EnableInternalRegulator(ADC1); - /* Delay for ADC internal voltage regulator stabilization. */ - /* Compute number of CPU cycles to wait for, from delay in us. */ - /* Note: Variable divided by 2 to compensate partially */ - /* CPU processing cycles (depends on compilation optimization). */ - /* Note: If system core clock frequency is below 200kHz, wait time */ - /* is only a few CPU processing cycles. */ - uint32_t wait_loop_index; - wait_loop_index = ((LL_ADC_DELAY_INTERNAL_REGUL_STAB_US * (SystemCoreClock / (100000 * 2))) / 10); - while (wait_loop_index != 0) { - wait_loop_index--; - } + /* USER CODE BEGIN ADC1_Init 0 */ + + /* USER CODE END ADC1_Init 0 */ + + ADC_MultiModeTypeDef multimode = {0}; + ADC_ChannelConfTypeDef sConfig = {0}; + + /* USER CODE BEGIN ADC1_Init 1 */ + + /* USER CODE END ADC1_Init 1 */ + + /** Common config + */ + hadc1.Instance = ADC1; + hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV8; + hadc1.Init.Resolution = ADC_RESOLUTION_12B; + hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; + hadc1.Init.GainCompensation = 0; + hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE; + hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; + hadc1.Init.LowPowerAutoWait = DISABLE; + hadc1.Init.ContinuousConvMode = ENABLE; + hadc1.Init.NbrOfConversion = 5; + hadc1.Init.DiscontinuousConvMode = DISABLE; + hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; + hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; + hadc1.Init.DMAContinuousRequests = ENABLE; + hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED; + hadc1.Init.OversamplingMode = ENABLE; + hadc1.Init.Oversampling.Ratio = ADC_OVERSAMPLING_RATIO_256; + hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_8; + hadc1.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER; + hadc1.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_CONTINUED_MODE; + if (HAL_ADC_Init(&hadc1) != HAL_OK) + { + Error_Handler(); + } + + /** Configure the ADC multi-mode + */ + multimode.Mode = ADC_MODE_INDEPENDENT; + if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK) + { + Error_Handler(); + } + + /** Configure Regular Channel + */ + sConfig.Channel = ADC_CHANNEL_9; + sConfig.Rank = ADC_REGULAR_RANK_1; + sConfig.SamplingTime = ADC_SAMPLETIME_92CYCLES_5; + sConfig.SingleDiff = ADC_SINGLE_ENDED; + sConfig.OffsetNumber = ADC_OFFSET_NONE; + sConfig.Offset = 0; + if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) + { + Error_Handler(); + } + + /** Configure Regular Channel + */ + sConfig.Channel = ADC_CHANNEL_7; + sConfig.Rank = ADC_REGULAR_RANK_2; + if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) + { + Error_Handler(); + } + + /** Configure Regular Channel + */ + sConfig.Channel = ADC_CHANNEL_4; + sConfig.Rank = ADC_REGULAR_RANK_3; + if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) + { + Error_Handler(); + } + + /** Configure Regular Channel + */ + sConfig.Channel = ADC_CHANNEL_15; + sConfig.Rank = ADC_REGULAR_RANK_4; + if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) + { + Error_Handler(); + } + + /** Configure Regular Channel + */ + sConfig.Channel = ADC_CHANNEL_5; + sConfig.Rank = ADC_REGULAR_RANK_5; + if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN ADC1_Init 2 */ + + /* USER CODE END ADC1_Init 2 */ - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_5); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_5, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_5, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_2, LL_ADC_CHANNEL_7); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_7, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_7, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_3, LL_ADC_CHANNEL_8); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_8, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_8, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_4, LL_ADC_CHANNEL_9); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_9, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_9, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_5, LL_ADC_CHANNEL_12); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_12, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_12, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_6, LL_ADC_CHANNEL_15); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_15, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_15, LL_ADC_SINGLE_ENDED); - /* USER CODE BEGIN ADC1_Init 2 */ - - /* USER CODE END ADC1_Init 2 */ } /* ADC2 init function */ void MX_ADC2_Init(void) { - /* USER CODE BEGIN ADC2_Init 0 */ - - /* USER CODE END ADC2_Init 0 */ - - LL_ADC_InitTypeDef ADC_InitStruct = {0}; - LL_ADC_REG_InitTypeDef ADC_REG_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetADCClockSource(LL_RCC_ADC12_CLKSOURCE_SYSCLK); - - /* Peripheral clock enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_ADC12); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - /**ADC2 GPIO Configuration - PC0 ------> ADC2_IN6 - PA5 ------> ADC2_IN13 - PA6 ------> ADC2_IN3 - PA7 ------> ADC2_IN4 - PB15 ------> ADC2_IN15 - */ - GPIO_InitStruct.Pin = BSE_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BSE_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = BSPD_SENSE_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BSPD_SENSE_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = IMD_SENSE_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(IMD_SENSE_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = AMS_SENSE_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(AMS_SENSE_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = STEERING_ANGLE_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(STEERING_ANGLE_GPIO_Port, &GPIO_InitStruct); - - /* ADC2 DMA Init */ - - /* ADC2 Init */ - LL_DMA_SetPeriphRequest(DMA2, LL_DMA_CHANNEL_1, LL_DMAMUX_REQ_ADC2); - - LL_DMA_SetDataTransferDirection(DMA2, LL_DMA_CHANNEL_1, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); - - LL_DMA_SetChannelPriorityLevel(DMA2, LL_DMA_CHANNEL_1, LL_DMA_PRIORITY_LOW); - - LL_DMA_SetMode(DMA2, LL_DMA_CHANNEL_1, LL_DMA_MODE_CIRCULAR); - - LL_DMA_SetPeriphIncMode(DMA2, LL_DMA_CHANNEL_1, LL_DMA_PERIPH_NOINCREMENT); - - LL_DMA_SetMemoryIncMode(DMA2, LL_DMA_CHANNEL_1, LL_DMA_MEMORY_INCREMENT); - - LL_DMA_SetPeriphSize(DMA2, LL_DMA_CHANNEL_1, LL_DMA_PDATAALIGN_HALFWORD); - - LL_DMA_SetMemorySize(DMA2, LL_DMA_CHANNEL_1, LL_DMA_MDATAALIGN_HALFWORD); - - /* USER CODE BEGIN ADC2_Init 1 */ - - /* USER CODE END ADC2_Init 1 */ - - /** Common config - */ - ADC_InitStruct.Resolution = LL_ADC_RESOLUTION_12B; - ADC_InitStruct.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT; - ADC_InitStruct.LowPowerMode = LL_ADC_LP_MODE_NONE; - LL_ADC_Init(ADC2, &ADC_InitStruct); - ADC_REG_InitStruct.TriggerSource = LL_ADC_REG_TRIG_SOFTWARE; - ADC_REG_InitStruct.SequencerLength = LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS; - ADC_REG_InitStruct.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE; - ADC_REG_InitStruct.ContinuousMode = LL_ADC_REG_CONV_CONTINUOUS; - ADC_REG_InitStruct.DMATransfer = LL_ADC_REG_DMA_TRANSFER_UNLIMITED; - ADC_REG_InitStruct.Overrun = LL_ADC_REG_OVR_DATA_PRESERVED; - LL_ADC_REG_Init(ADC2, &ADC_REG_InitStruct); - LL_ADC_SetGainCompensation(ADC2, 0); - LL_ADC_SetOverSamplingScope(ADC2, LL_ADC_OVS_DISABLE); - - /* Disable ADC deep power down (enabled by default after reset state) */ - LL_ADC_DisableDeepPowerDown(ADC2); - /* Enable ADC internal voltage regulator */ - LL_ADC_EnableInternalRegulator(ADC2); - /* Delay for ADC internal voltage regulator stabilization. */ - /* Compute number of CPU cycles to wait for, from delay in us. */ - /* Note: Variable divided by 2 to compensate partially */ - /* CPU processing cycles (depends on compilation optimization). */ - /* Note: If system core clock frequency is below 200kHz, wait time */ - /* is only a few CPU processing cycles. */ - uint32_t wait_loop_index; - wait_loop_index = ((LL_ADC_DELAY_INTERNAL_REGUL_STAB_US * (SystemCoreClock / (100000 * 2))) / 10); - while (wait_loop_index != 0) { - wait_loop_index--; - } + /* USER CODE BEGIN ADC2_Init 0 */ + + /* USER CODE END ADC2_Init 0 */ + + ADC_ChannelConfTypeDef sConfig = {0}; + + /* USER CODE BEGIN ADC2_Init 1 */ + + /* USER CODE END ADC2_Init 1 */ + + /** Common config + */ + hadc2.Instance = ADC2; + hadc2.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV8; + hadc2.Init.Resolution = ADC_RESOLUTION_12B; + hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT; + hadc2.Init.GainCompensation = 0; + hadc2.Init.ScanConvMode = ADC_SCAN_ENABLE; + hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV; + hadc2.Init.LowPowerAutoWait = DISABLE; + hadc2.Init.ContinuousConvMode = ENABLE; + hadc2.Init.NbrOfConversion = 5; + hadc2.Init.DiscontinuousConvMode = DISABLE; + hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START; + hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; + hadc2.Init.DMAContinuousRequests = ENABLE; + hadc2.Init.Overrun = ADC_OVR_DATA_PRESERVED; + hadc2.Init.OversamplingMode = ENABLE; + hadc2.Init.Oversampling.Ratio = ADC_OVERSAMPLING_RATIO_256; + hadc2.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_8; + hadc2.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER; + hadc2.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_CONTINUED_MODE; + if (HAL_ADC_Init(&hadc2) != HAL_OK) + { + Error_Handler(); + } + + /** Configure Regular Channel + */ + sConfig.Channel = ADC_CHANNEL_17; + sConfig.Rank = ADC_REGULAR_RANK_1; + sConfig.SamplingTime = ADC_SAMPLETIME_92CYCLES_5; + sConfig.SingleDiff = ADC_SINGLE_ENDED; + sConfig.OffsetNumber = ADC_OFFSET_NONE; + sConfig.Offset = 0; + if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK) + { + Error_Handler(); + } + + /** Configure Regular Channel + */ + sConfig.Channel = ADC_CHANNEL_12; + sConfig.Rank = ADC_REGULAR_RANK_2; + if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK) + { + Error_Handler(); + } + + /** Configure Regular Channel + */ + sConfig.Channel = ADC_CHANNEL_15; + sConfig.Rank = ADC_REGULAR_RANK_3; + if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK) + { + Error_Handler(); + } + + /** Configure Regular Channel + */ + sConfig.Channel = ADC_CHANNEL_10; + sConfig.Rank = ADC_REGULAR_RANK_4; + if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK) + { + Error_Handler(); + } + + /** Configure Regular Channel + */ + sConfig.Channel = ADC_CHANNEL_4; + sConfig.Rank = ADC_REGULAR_RANK_5; + if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN ADC2_Init 2 */ + + /* USER CODE END ADC2_Init 2 */ + +} +/* ADC5 init function */ +void MX_ADC5_Init(void) +{ + + /* USER CODE BEGIN ADC5_Init 0 */ + + /* USER CODE END ADC5_Init 0 */ + + ADC_ChannelConfTypeDef sConfig = {0}; + + /* USER CODE BEGIN ADC5_Init 1 */ + + /* USER CODE END ADC5_Init 1 */ + + /** Common config + */ + hadc5.Instance = ADC5; + hadc5.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4; + hadc5.Init.Resolution = ADC_RESOLUTION_12B; + hadc5.Init.DataAlign = ADC_DATAALIGN_RIGHT; + hadc5.Init.GainCompensation = 0; + hadc5.Init.ScanConvMode = ADC_SCAN_DISABLE; + hadc5.Init.EOCSelection = ADC_EOC_SINGLE_CONV; + hadc5.Init.LowPowerAutoWait = DISABLE; + hadc5.Init.ContinuousConvMode = ENABLE; + hadc5.Init.NbrOfConversion = 1; + hadc5.Init.DiscontinuousConvMode = DISABLE; + hadc5.Init.ExternalTrigConv = ADC_SOFTWARE_START; + hadc5.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; + hadc5.Init.DMAContinuousRequests = ENABLE; + hadc5.Init.Overrun = ADC_OVR_DATA_PRESERVED; + hadc5.Init.OversamplingMode = ENABLE; + hadc5.Init.Oversampling.Ratio = ADC_OVERSAMPLING_RATIO_256; + hadc5.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_8; + hadc5.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER; + hadc5.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_CONTINUED_MODE; + if (HAL_ADC_Init(&hadc5) != HAL_OK) + { + Error_Handler(); + } + + /** Configure Regular Channel + */ + sConfig.Channel = ADC_CHANNEL_2; + sConfig.Rank = ADC_REGULAR_RANK_1; + sConfig.SamplingTime = ADC_SAMPLETIME_92CYCLES_5; + sConfig.SingleDiff = ADC_SINGLE_ENDED; + sConfig.OffsetNumber = ADC_OFFSET_NONE; + sConfig.Offset = 0; + if (HAL_ADC_ConfigChannel(&hadc5, &sConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN ADC5_Init 2 */ + + /* USER CODE END ADC5_Init 2 */ + +} + +static uint32_t HAL_RCC_ADC12_CLK_ENABLED=0; - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC2, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_3); - LL_ADC_SetChannelSamplingTime(ADC2, LL_ADC_CHANNEL_3, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC2, LL_ADC_CHANNEL_3, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC2, LL_ADC_REG_RANK_2, LL_ADC_CHANNEL_4); - LL_ADC_SetChannelSamplingTime(ADC2, LL_ADC_CHANNEL_4, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC2, LL_ADC_CHANNEL_4, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC2, LL_ADC_REG_RANK_3, LL_ADC_CHANNEL_6); - LL_ADC_SetChannelSamplingTime(ADC2, LL_ADC_CHANNEL_6, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC2, LL_ADC_CHANNEL_6, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC2, LL_ADC_REG_RANK_4, LL_ADC_CHANNEL_13); - LL_ADC_SetChannelSamplingTime(ADC2, LL_ADC_CHANNEL_13, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC2, LL_ADC_CHANNEL_13, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC2, LL_ADC_REG_RANK_5, LL_ADC_CHANNEL_15); - LL_ADC_SetChannelSamplingTime(ADC2, LL_ADC_CHANNEL_15, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC2, LL_ADC_CHANNEL_15, LL_ADC_SINGLE_ENDED); - /* USER CODE BEGIN ADC2_Init 2 */ - - /* USER CODE END ADC2_Init 2 */ +void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle) +{ + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; + if(adcHandle->Instance==ADC1) + { + /* USER CODE BEGIN ADC1_MspInit 0 */ + + /* USER CODE END ADC1_MspInit 0 */ + + /** Initializes the peripherals clocks + */ + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC12; + PeriphClkInit.Adc12ClockSelection = RCC_ADC12CLKSOURCE_SYSCLK; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) + { + Error_Handler(); + } + + /* ADC1 clock enable */ + HAL_RCC_ADC12_CLK_ENABLED++; + if(HAL_RCC_ADC12_CLK_ENABLED==1){ + __HAL_RCC_ADC12_CLK_ENABLE(); + } + + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**ADC1 GPIO Configuration + PC1 ------> ADC1_IN7 + PC3 ------> ADC1_IN9 + PA3 ------> ADC1_IN4 + PB0 ------> ADC1_IN15 + PB14 ------> ADC1_IN5 + */ + GPIO_InitStruct.Pin = BRAKE_SIGNAL_Pin|APPS1_SIGNAL_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = STEERING_ANGLE_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(STEERING_ANGLE_GPIO_Port, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = BSPD_SIGNAL_Pin|BSPD_SENSE_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* ADC1 DMA Init */ + /* ADC1 Init */ + hdma_adc1.Instance = DMA1_Channel1; + hdma_adc1.Init.Request = DMA_REQUEST_ADC1; + hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY; + hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE; + hdma_adc1.Init.MemInc = DMA_MINC_ENABLE; + hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; + hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; + hdma_adc1.Init.Mode = DMA_CIRCULAR; + hdma_adc1.Init.Priority = DMA_PRIORITY_LOW; + if (HAL_DMA_Init(&hdma_adc1) != HAL_OK) + { + Error_Handler(); + } + + __HAL_LINKDMA(adcHandle,DMA_Handle,hdma_adc1); + + /* ADC1 interrupt Init */ + HAL_NVIC_SetPriority(ADC1_2_IRQn, 15, 0); + HAL_NVIC_EnableIRQ(ADC1_2_IRQn); + /* USER CODE BEGIN ADC1_MspInit 1 */ + + /* USER CODE END ADC1_MspInit 1 */ + } + else if(adcHandle->Instance==ADC2) + { + /* USER CODE BEGIN ADC2_MspInit 0 */ + + /* USER CODE END ADC2_MspInit 0 */ + + /** Initializes the peripherals clocks + */ + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC12; + PeriphClkInit.Adc12ClockSelection = RCC_ADC12CLKSOURCE_SYSCLK; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) + { + Error_Handler(); + } + + /* ADC2 clock enable */ + HAL_RCC_ADC12_CLK_ENABLED++; + if(HAL_RCC_ADC12_CLK_ENABLED==1){ + __HAL_RCC_ADC12_CLK_ENABLE(); + } + + __HAL_RCC_GPIOF_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**ADC2 GPIO Configuration + PF1-OSC_OUT ------> ADC2_IN10 + PA4 ------> ADC2_IN17 + PA7 ------> ADC2_IN4 + PB2 ------> ADC2_IN12 + PB15 ------> ADC2_IN15 + */ + GPIO_InitStruct.Pin = SPARE_1_SIGNAL_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(SPARE_1_SIGNAL_GPIO_Port, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = APPS2_SIGNAL_Pin|SPARE_2_SIGNAL_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = BSE_SIGNAL_Pin|AMS_SENSE_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* ADC2 DMA Init */ + /* ADC2 Init */ + hdma_adc2.Instance = DMA2_Channel1; + hdma_adc2.Init.Request = DMA_REQUEST_ADC2; + hdma_adc2.Init.Direction = DMA_PERIPH_TO_MEMORY; + hdma_adc2.Init.PeriphInc = DMA_PINC_DISABLE; + hdma_adc2.Init.MemInc = DMA_MINC_ENABLE; + hdma_adc2.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; + hdma_adc2.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; + hdma_adc2.Init.Mode = DMA_CIRCULAR; + hdma_adc2.Init.Priority = DMA_PRIORITY_LOW; + if (HAL_DMA_Init(&hdma_adc2) != HAL_OK) + { + Error_Handler(); + } + + __HAL_LINKDMA(adcHandle,DMA_Handle,hdma_adc2); + + /* ADC2 interrupt Init */ + HAL_NVIC_SetPriority(ADC1_2_IRQn, 15, 0); + HAL_NVIC_EnableIRQ(ADC1_2_IRQn); + /* USER CODE BEGIN ADC2_MspInit 1 */ + + /* USER CODE END ADC2_MspInit 1 */ + } + else if(adcHandle->Instance==ADC5) + { + /* USER CODE BEGIN ADC5_MspInit 0 */ + + /* USER CODE END ADC5_MspInit 0 */ + + /** Initializes the peripherals clocks + */ + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC345; + PeriphClkInit.Adc345ClockSelection = RCC_ADC345CLKSOURCE_SYSCLK; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) + { + Error_Handler(); + } + + /* ADC5 clock enable */ + __HAL_RCC_ADC345_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**ADC5 GPIO Configuration + PA9 ------> ADC5_IN2 + */ + GPIO_InitStruct.Pin = IMD_SENSE_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(IMD_SENSE_GPIO_Port, &GPIO_InitStruct); + + /* ADC5 DMA Init */ + /* ADC5 Init */ + hdma_adc5.Instance = DMA1_Channel2; + hdma_adc5.Init.Request = DMA_REQUEST_ADC5; + hdma_adc5.Init.Direction = DMA_PERIPH_TO_MEMORY; + hdma_adc5.Init.PeriphInc = DMA_PINC_DISABLE; + hdma_adc5.Init.MemInc = DMA_MINC_ENABLE; + hdma_adc5.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; + hdma_adc5.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; + hdma_adc5.Init.Mode = DMA_CIRCULAR; + hdma_adc5.Init.Priority = DMA_PRIORITY_LOW; + if (HAL_DMA_Init(&hdma_adc5) != HAL_OK) + { + Error_Handler(); + } + + __HAL_LINKDMA(adcHandle,DMA_Handle,hdma_adc5); + + /* ADC5 interrupt Init */ + HAL_NVIC_SetPriority(ADC5_IRQn, 15, 0); + HAL_NVIC_EnableIRQ(ADC5_IRQn); + /* USER CODE BEGIN ADC5_MspInit 1 */ + + /* USER CODE END ADC5_MspInit 1 */ + } +} + +void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle) +{ + + if(adcHandle->Instance==ADC1) + { + /* USER CODE BEGIN ADC1_MspDeInit 0 */ + + /* USER CODE END ADC1_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_ADC12_CLK_ENABLED--; + if(HAL_RCC_ADC12_CLK_ENABLED==0){ + __HAL_RCC_ADC12_CLK_DISABLE(); + } + + /**ADC1 GPIO Configuration + PC1 ------> ADC1_IN7 + PC3 ------> ADC1_IN9 + PA3 ------> ADC1_IN4 + PB0 ------> ADC1_IN15 + PB14 ------> ADC1_IN5 + */ + HAL_GPIO_DeInit(GPIOC, BRAKE_SIGNAL_Pin|APPS1_SIGNAL_Pin); + + HAL_GPIO_DeInit(STEERING_ANGLE_GPIO_Port, STEERING_ANGLE_Pin); + + HAL_GPIO_DeInit(GPIOB, BSPD_SIGNAL_Pin|BSPD_SENSE_Pin); + + /* ADC1 DMA DeInit */ + HAL_DMA_DeInit(adcHandle->DMA_Handle); + + /* ADC1 interrupt Deinit */ + /* USER CODE BEGIN ADC1:ADC1_2_IRQn disable */ + /** + * Uncomment the line below to disable the "ADC1_2_IRQn" interrupt + * Be aware, disabling shared interrupt may affect other IPs + */ + /* HAL_NVIC_DisableIRQ(ADC1_2_IRQn); */ + /* USER CODE END ADC1:ADC1_2_IRQn disable */ + + /* USER CODE BEGIN ADC1_MspDeInit 1 */ + + /* USER CODE END ADC1_MspDeInit 1 */ + } + else if(adcHandle->Instance==ADC2) + { + /* USER CODE BEGIN ADC2_MspDeInit 0 */ + + /* USER CODE END ADC2_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_ADC12_CLK_ENABLED--; + if(HAL_RCC_ADC12_CLK_ENABLED==0){ + __HAL_RCC_ADC12_CLK_DISABLE(); + } + + /**ADC2 GPIO Configuration + PF1-OSC_OUT ------> ADC2_IN10 + PA4 ------> ADC2_IN17 + PA7 ------> ADC2_IN4 + PB2 ------> ADC2_IN12 + PB15 ------> ADC2_IN15 + */ + HAL_GPIO_DeInit(SPARE_1_SIGNAL_GPIO_Port, SPARE_1_SIGNAL_Pin); + + HAL_GPIO_DeInit(GPIOA, APPS2_SIGNAL_Pin|SPARE_2_SIGNAL_Pin); + + HAL_GPIO_DeInit(GPIOB, BSE_SIGNAL_Pin|AMS_SENSE_Pin); + + /* ADC2 DMA DeInit */ + HAL_DMA_DeInit(adcHandle->DMA_Handle); + + /* ADC2 interrupt Deinit */ + /* USER CODE BEGIN ADC2:ADC1_2_IRQn disable */ + /** + * Uncomment the line below to disable the "ADC1_2_IRQn" interrupt + * Be aware, disabling shared interrupt may affect other IPs + */ + /* HAL_NVIC_DisableIRQ(ADC1_2_IRQn); */ + /* USER CODE END ADC2:ADC1_2_IRQn disable */ + + /* USER CODE BEGIN ADC2_MspDeInit 1 */ + + /* USER CODE END ADC2_MspDeInit 1 */ + } + else if(adcHandle->Instance==ADC5) + { + /* USER CODE BEGIN ADC5_MspDeInit 0 */ + + /* USER CODE END ADC5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_ADC345_CLK_DISABLE(); + + /**ADC5 GPIO Configuration + PA9 ------> ADC5_IN2 + */ + HAL_GPIO_DeInit(IMD_SENSE_GPIO_Port, IMD_SENSE_Pin); + + /* ADC5 DMA DeInit */ + HAL_DMA_DeInit(adcHandle->DMA_Handle); + + /* ADC5 interrupt Deinit */ + HAL_NVIC_DisableIRQ(ADC5_IRQn); + /* USER CODE BEGIN ADC5_MspDeInit 1 */ + + /* USER CODE END ADC5_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ +void ADC_UpdateAnalogValues_EMA(volatile uint16_t *ADC_buffers, uint8_t num_signals, float alpha, volatile uint16_t *ADC_outputs) +{ + for (uint8_t i = 0; i < num_signals; i++) { + // Apply EMA formula: EMA_new = alpha * ADC_new + (1 - alpha) * EMA_old + ADC_outputs[i] = (uint16_t)(alpha * ADC_buffers[i] + (1.0f - alpha) * ADC_outputs[i]); + } +} + /* USER CODE END 1 */ + diff --git a/ECU/Core/Src/dma.c b/ECU/Core/Src/dma.c index 2e480d9a2..883c5ed2e 100644 --- a/ECU/Core/Src/dma.c +++ b/ECU/Core/Src/dma.c @@ -34,18 +34,33 @@ /* USER CODE END 1 */ /** - * Enable DMA controller clock - */ + * Enable DMA controller clock + */ void MX_DMA_Init(void) { - /* Init with LL driver */ - /* DMA controller clock enable */ - LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMAMUX1); - LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1); - LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA2); + /* DMA controller clock enable */ + __HAL_RCC_DMAMUX1_CLK_ENABLE(); + __HAL_RCC_DMA1_CLK_ENABLE(); + __HAL_RCC_DMA2_CLK_ENABLE(); + + /* DMA interrupt init */ + /* DMA1_Channel1_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn); + /* DMA1_Channel2_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(DMA1_Channel2_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(DMA1_Channel2_IRQn); + /* DMA2_Channel1_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(DMA2_Channel1_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(DMA2_Channel1_IRQn); + /* DMAMUX_OVR_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(DMAMUX_OVR_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(DMAMUX_OVR_IRQn); + } /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ + diff --git a/ECU/Core/Src/fdcan.c b/ECU/Core/Src/fdcan.c index 2a66c7caf..a307cb57b 100644 --- a/ECU/Core/Src/fdcan.c +++ b/ECU/Core/Src/fdcan.c @@ -31,207 +31,296 @@ FDCAN_HandleTypeDef hfdcan2; void MX_FDCAN1_Init(void) { - /* USER CODE BEGIN FDCAN1_Init 0 */ - - /* USER CODE END FDCAN1_Init 0 */ - - /* USER CODE BEGIN FDCAN1_Init 1 */ - - /* USER CODE END FDCAN1_Init 1 */ - hfdcan1.Instance = FDCAN1; - hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan1.Init.Mode = FDCAN_MODE_NORMAL; - hfdcan1.Init.AutoRetransmission = ENABLE; - hfdcan1.Init.TransmitPause = DISABLE; - hfdcan1.Init.ProtocolException = ENABLE; - hfdcan1.Init.NominalPrescaler = 1; - hfdcan1.Init.NominalSyncJumpWidth = 16; - hfdcan1.Init.NominalTimeSeg1 = 119; - hfdcan1.Init.NominalTimeSeg2 = 40; - hfdcan1.Init.DataPrescaler = 8; - hfdcan1.Init.DataSyncJumpWidth = 16; - hfdcan1.Init.DataTimeSeg1 = 14; - hfdcan1.Init.DataTimeSeg2 = 5; - hfdcan1.Init.StdFiltersNbr = 0; - hfdcan1.Init.ExtFiltersNbr = 2; - hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN1_Init 2 */ - - /* USER CODE END FDCAN1_Init 2 */ + /* USER CODE BEGIN FDCAN1_Init 0 */ + + /* USER CODE END FDCAN1_Init 0 */ + + /* USER CODE BEGIN FDCAN1_Init 1 */ + + /* USER CODE END FDCAN1_Init 1 */ + hfdcan1.Instance = FDCAN1; + hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan1.Init.Mode = FDCAN_MODE_NORMAL; + hfdcan1.Init.AutoRetransmission = ENABLE; + hfdcan1.Init.TransmitPause = DISABLE; + hfdcan1.Init.ProtocolException = ENABLE; + hfdcan1.Init.NominalPrescaler = 1; + hfdcan1.Init.NominalSyncJumpWidth = 16; + hfdcan1.Init.NominalTimeSeg1 = 119; + hfdcan1.Init.NominalTimeSeg2 = 40; + hfdcan1.Init.DataPrescaler = 1; + hfdcan1.Init.DataSyncJumpWidth = 16; + hfdcan1.Init.DataTimeSeg1 = 9; + hfdcan1.Init.DataTimeSeg2 = 10; + hfdcan1.Init.StdFiltersNbr = 0; + hfdcan1.Init.ExtFiltersNbr = 3; + hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN1_Init 2 */ + + FDCAN_FilterTypeDef fdcan_primary_filter_ecu = {0}; + fdcan_primary_filter_ecu.IdType = FDCAN_EXTENDED_ID; + fdcan_primary_filter_ecu.FilterIndex = 0; + fdcan_primary_filter_ecu.FilterType = FDCAN_FILTER_MASK; + fdcan_primary_filter_ecu.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; + fdcan_primary_filter_ecu.FilterID1 = GRCAN_ECU & 0xFF; + fdcan_primary_filter_ecu.FilterID2 = 0x000000FF; + if (HAL_FDCAN_ConfigFilter(&hfdcan1, &fdcan_primary_filter_ecu) != HAL_OK){ + Error_Handler(); + } + + FDCAN_FilterTypeDef fdcan_primary_filter_all = {0}; + fdcan_primary_filter_all.IdType = FDCAN_EXTENDED_ID; + fdcan_primary_filter_all.FilterIndex = 1; + fdcan_primary_filter_all.FilterType = FDCAN_FILTER_MASK; + fdcan_primary_filter_all.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; + fdcan_primary_filter_all.FilterID1 = GRCAN_ALL & 0xFF; + fdcan_primary_filter_all.FilterID2 = 0x000000FF; + if (HAL_FDCAN_ConfigFilter(&hfdcan1, &fdcan_primary_filter_all) != HAL_OK){ + Error_Handler(); + } + + FDCAN_FilterTypeDef fdcan_primary_filter_dti = {0}; + fdcan_primary_filter_dti.IdType = FDCAN_EXTENDED_ID; + fdcan_primary_filter_dti.FilterIndex = 2; + fdcan_primary_filter_dti.FilterType = FDCAN_FILTER_MASK; + fdcan_primary_filter_dti.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; + fdcan_primary_filter_dti.FilterID1 = DTI_RX_ID; + fdcan_primary_filter_dti.FilterID2 = DTI_RX_MASK; + if (HAL_FDCAN_ConfigFilter(&hfdcan1, &fdcan_primary_filter_dti) != HAL_OK){ + Error_Handler(); + } + + if (HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_REJECT_REMOTE, FDCAN_REJECT_REMOTE) != HAL_OK){ + Error_Handler(); + } + + /* USER CODE END FDCAN1_Init 2 */ + } /* FDCAN2 init function */ void MX_FDCAN2_Init(void) { - /* USER CODE BEGIN FDCAN2_Init 0 */ - - /* USER CODE END FDCAN2_Init 0 */ - - /* USER CODE BEGIN FDCAN2_Init 1 */ - - /* USER CODE END FDCAN2_Init 1 */ - hfdcan2.Instance = FDCAN2; - hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan2.Init.Mode = FDCAN_MODE_NORMAL; - hfdcan2.Init.AutoRetransmission = ENABLE; - hfdcan2.Init.TransmitPause = DISABLE; - hfdcan2.Init.ProtocolException = ENABLE; - hfdcan2.Init.NominalPrescaler = 1; - hfdcan2.Init.NominalSyncJumpWidth = 16; - hfdcan2.Init.NominalTimeSeg1 = 119; - hfdcan2.Init.NominalTimeSeg2 = 40; - hfdcan2.Init.DataPrescaler = 8; - hfdcan2.Init.DataSyncJumpWidth = 16; - hfdcan2.Init.DataTimeSeg1 = 14; - hfdcan2.Init.DataTimeSeg2 = 5; - hfdcan2.Init.StdFiltersNbr = 0; - hfdcan2.Init.ExtFiltersNbr = 2; - hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN2_Init 2 */ - - /* USER CODE END FDCAN2_Init 2 */ + /* USER CODE BEGIN FDCAN2_Init 0 */ + + /* USER CODE END FDCAN2_Init 0 */ + + /* USER CODE BEGIN FDCAN2_Init 1 */ + + /* USER CODE END FDCAN2_Init 1 */ + hfdcan2.Instance = FDCAN2; + hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan2.Init.FrameFormat = FDCAN_FRAME_FD_BRS; + hfdcan2.Init.Mode = FDCAN_MODE_NORMAL; + hfdcan2.Init.AutoRetransmission = ENABLE; + hfdcan2.Init.TransmitPause = DISABLE; + hfdcan2.Init.ProtocolException = ENABLE; + hfdcan2.Init.NominalPrescaler = 1; + hfdcan2.Init.NominalSyncJumpWidth = 16; + hfdcan2.Init.NominalTimeSeg1 = 119; + hfdcan2.Init.NominalTimeSeg2 = 40; + hfdcan2.Init.DataPrescaler = 1; + hfdcan2.Init.DataSyncJumpWidth = 2; + hfdcan2.Init.DataTimeSeg1 = 14; + hfdcan2.Init.DataTimeSeg2 = 5; + hfdcan2.Init.StdFiltersNbr = 0; + hfdcan2.Init.ExtFiltersNbr = 2; + hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN2_Init 2 */ + if (HAL_FDCAN_ConfigTxDelayCompensation(&hfdcan2, hfdcan2.Init.DataPrescaler * hfdcan2.Init.DataTimeSeg1,0) != HAL_OK){ + Error_Handler(); + } + + if (HAL_FDCAN_EnableTxDelayCompensation(&hfdcan2) != HAL_OK){ + Error_Handler(); + } + + FDCAN_FilterTypeDef fdcan_data_filter_ecu = {0}; + fdcan_data_filter_ecu.IdType = FDCAN_EXTENDED_ID; + fdcan_data_filter_ecu.FilterIndex = 0; + fdcan_data_filter_ecu.FilterType = FDCAN_FILTER_MASK; + fdcan_data_filter_ecu.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; + fdcan_data_filter_ecu.FilterID1 = GRCAN_ECU & 0xFF; + fdcan_data_filter_ecu.FilterID2 = 0x000000FF; + if (HAL_FDCAN_ConfigFilter(&hfdcan2, &fdcan_data_filter_ecu) != HAL_OK){ + Error_Handler(); + } + + FDCAN_FilterTypeDef fdcan_data_filter_all = {0}; + fdcan_data_filter_all.IdType = FDCAN_EXTENDED_ID; + fdcan_data_filter_all.FilterIndex = 1; + fdcan_data_filter_all.FilterType = FDCAN_FILTER_MASK; + fdcan_data_filter_all.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; + fdcan_data_filter_all.FilterID1 = GRCAN_ALL & 0xFF; + fdcan_data_filter_all.FilterID2 = 0x000000FF; + if (HAL_FDCAN_ConfigFilter(&hfdcan2, &fdcan_data_filter_all) != HAL_OK){ + Error_Handler(); + } + + if (HAL_FDCAN_ConfigGlobalFilter(&hfdcan2, FDCAN_REJECT, FDCAN_REJECT, FDCAN_REJECT_REMOTE, FDCAN_REJECT_REMOTE) != HAL_OK){ + Error_Handler(); + } + + /* USER CODE END FDCAN2_Init 2 */ + } -static uint32_t HAL_RCC_FDCAN_CLK_ENABLED = 0; +static uint32_t HAL_RCC_FDCAN_CLK_ENABLED=0; -void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) +void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (fdcanHandle->Instance == FDCAN1) { - /* USER CODE BEGIN FDCAN1_MspInit 0 */ - - /* USER CODE END FDCAN1_MspInit 0 */ - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN1 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**FDCAN1 GPIO Configuration - PA11 ------> FDCAN1_RX - PA12 ------> FDCAN1_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_11; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = GPIO_PIN_12; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* FDCAN1 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspInit 1 */ - - /* USER CODE END FDCAN1_MspInit 1 */ - } else if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspInit 0 */ - - /* USER CODE END FDCAN2_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN2 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_12; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = GPIO_PIN_13; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN2 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspInit 1 */ - - /* USER CODE END FDCAN2_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; + if(fdcanHandle->Instance==FDCAN1) + { + /* USER CODE BEGIN FDCAN1_MspInit 0 */ + + /* USER CODE END FDCAN1_MspInit 0 */ + + /** Initializes the peripherals clocks + */ + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_FDCAN; + PeriphClkInit.FdcanClockSelection = RCC_FDCANCLKSOURCE_PCLK1; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) + { + Error_Handler(); + } + + /* FDCAN1 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**FDCAN1 GPIO Configuration + PA11 ------> FDCAN1_RX + PA12 ------> FDCAN1_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* FDCAN1 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 15, 0); + HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); + HAL_NVIC_SetPriority(FDCAN1_IT1_IRQn, 15, 0); + HAL_NVIC_EnableIRQ(FDCAN1_IT1_IRQn); + /* USER CODE BEGIN FDCAN1_MspInit 1 */ + + /* USER CODE END FDCAN1_MspInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN2) + { + /* USER CODE BEGIN FDCAN2_MspInit 0 */ + + /* USER CODE END FDCAN2_MspInit 0 */ + + /** Initializes the peripherals clocks + */ + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_FDCAN; + PeriphClkInit.FdcanClockSelection = RCC_FDCANCLKSOURCE_PCLK1; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) + { + Error_Handler(); + } + + /* FDCAN2 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN2 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 15, 0); + HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); + HAL_NVIC_SetPriority(FDCAN2_IT1_IRQn, 15, 0); + HAL_NVIC_EnableIRQ(FDCAN2_IT1_IRQn); + /* USER CODE BEGIN FDCAN2_MspInit 1 */ + + /* USER CODE END FDCAN2_MspInit 1 */ + } } -void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) +void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) { - if (fdcanHandle->Instance == FDCAN1) { - /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ - - /* USER CODE END FDCAN1_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN1 GPIO Configuration - PA11 ------> FDCAN1_RX - PA12 ------> FDCAN1_TX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11 | GPIO_PIN_12); - - /* FDCAN1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ - - /* USER CODE END FDCAN1_MspDeInit 1 */ - } else if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - - /* USER CODE END FDCAN2_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); - - /* FDCAN2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - - /* USER CODE END FDCAN2_MspDeInit 1 */ - } + if(fdcanHandle->Instance==FDCAN1) + { + /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ + + /* USER CODE END FDCAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN1 GPIO Configuration + PA11 ------> FDCAN1_RX + PA12 ------> FDCAN1_TX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12); + + /* FDCAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); + HAL_NVIC_DisableIRQ(FDCAN1_IT1_IRQn); + /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ + + /* USER CODE END FDCAN1_MspDeInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN2) + { + /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ + + /* USER CODE END FDCAN2_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); + + /* FDCAN2 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); + HAL_NVIC_DisableIRQ(FDCAN2_IT1_IRQn); + /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ + + /* USER CODE END FDCAN2_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + diff --git a/ECU/Core/Src/gpio.c b/ECU/Core/Src/gpio.c index caf5db01c..60b05abef 100644 --- a/ECU/Core/Src/gpio.c +++ b/ECU/Core/Src/gpio.c @@ -33,241 +33,107 @@ /* USER CODE END 1 */ /** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is enabled - * through the Code Generation settings) - */ + * Analog + * Input + * Output + * EVENT_OUT + * EXTI + * Free pins are configured automatically as Analog (this feature is enabled through + * the Code Generation settings) +*/ void MX_GPIO_Init(void) { - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(LED_TEST_GPIO_Port, LED_TEST_Pin); - - /**/ - LL_GPIO_ResetOutputPin(BRAKE_LIGHT_GPIO_Port, BRAKE_LIGHT_Pin); - - /**/ - LL_GPIO_ResetOutputPin(TSSI_G_CONTROL_GPIO_Port, TSSI_G_CONTROL_Pin); - - /**/ - LL_GPIO_ResetOutputPin(TSSI_R_CONTROL_GPIO_Port, TSSI_R_CONTROL_Pin); - - /**/ - LL_GPIO_ResetOutputPin(RTD_CONTROL_GPIO_Port, RTD_CONTROL_Pin); - - /**/ - LL_GPIO_ResetOutputPin(AUX_CONTROL_GPIO_Port, AUX_CONTROL_Pin); - - /**/ - LL_GPIO_SetOutputPin(SOFTWARE_OK_CONTROL_GPIO_Port, SOFTWARE_OK_CONTROL_Pin); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_13; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LED_TEST_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(LED_TEST_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = BRAKE_LIGHT_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BRAKE_LIGHT_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = TSSI_G_CONTROL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(TSSI_G_CONTROL_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = TSSI_R_CONTROL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(TSSI_R_CONTROL_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = RTD_CONTROL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(RTD_CONTROL_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = AUX_CONTROL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(AUX_CONTROL_GPIO_Port, &GPIO_InitStruct); + GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOF_CLK_ENABLE(); + __HAL_RCC_GPIOG_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + __HAL_RCC_GPIOD_CLK_ENABLE(); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(BRAKE_LIGHT_GPIO_Port, BRAKE_LIGHT_Pin, GPIO_PIN_RESET); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10|SOFTWARE_OK_CONTROL_Pin|TSSI_R_CONTROL_Pin|RTD_CONTROL_Pin, GPIO_PIN_RESET); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(LED_TEST_GPIO_Port, LED_TEST_Pin, GPIO_PIN_RESET); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(TSSI_G_CONTROL_GPIO_Port, TSSI_G_CONTROL_Pin, GPIO_PIN_RESET); + + /*Configure GPIO pins : PC13 PC15 PC0 PC2 + PC4 PC5 PC6 PC7 + PC8 PC9 PC12 */ + GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_2 + |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7 + |GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_12; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /*Configure GPIO pin : BRAKE_LIGHT_Pin */ + GPIO_InitStruct.Pin = BRAKE_LIGHT_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(BRAKE_LIGHT_GPIO_Port, &GPIO_InitStruct); + + /*Configure GPIO pin : PF0 */ + GPIO_InitStruct.Pin = GPIO_PIN_0; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /*Configure GPIO pin : PG10 */ + GPIO_InitStruct.Pin = GPIO_PIN_10; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF15_EVENTOUT; + HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + /*Configure GPIO pins : PA0 PA1 PA2 PA5 + PA6 PA8 PA10 */ + GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_5 + |GPIO_PIN_6|GPIO_PIN_8|GPIO_PIN_10; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /*Configure GPIO pins : PB1 PB5 PB6 PB8 + PB9 */ + GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_8 + |GPIO_PIN_9; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /*Configure GPIO pins : PB10 SOFTWARE_OK_CONTROL_Pin TSSI_R_CONTROL_Pin RTD_CONTROL_Pin */ + GPIO_InitStruct.Pin = GPIO_PIN_10|SOFTWARE_OK_CONTROL_Pin|TSSI_R_CONTROL_Pin|RTD_CONTROL_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /*Configure GPIO pin : LED_TEST_Pin */ + GPIO_InitStruct.Pin = LED_TEST_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(LED_TEST_GPIO_Port, &GPIO_InitStruct); + + /*Configure GPIO pin : TSSI_G_CONTROL_Pin */ + GPIO_InitStruct.Pin = TSSI_G_CONTROL_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(TSSI_G_CONTROL_GPIO_Port, &GPIO_InitStruct); - /**/ - GPIO_InitStruct.Pin = SOFTWARE_OK_CONTROL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(SOFTWARE_OK_CONTROL_GPIO_Port, &GPIO_InitStruct); } /* USER CODE BEGIN 2 */ diff --git a/ECU/Core/Src/main.c b/ECU/Core/Src/main.c index aa8f6f89b..6ebe4dc9b 100644 --- a/ECU/Core/Src/main.c +++ b/ECU/Core/Src/main.c @@ -18,17 +18,12 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" - -#include "GRCAN_BUS_ID.h" -#include "GRCAN_MSG_DATA.h" -#include "GRCAN_NODE_ID.h" -#include "StateData.h" -#include "StateTicks.h" #include "adc.h" #include "dma.h" #include "fdcan.h" +#include "tim.h" +#include "usart.h" #include "gpio.h" -#include "gr_adc.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -36,16 +31,16 @@ #include "CANdler.h" #include "CANutils.h" +#include "CubeCAN.h" #include "Lights.h" #include "Logomatic.h" #include "Pinging.h" -#include "Plan_C.h" +#include "StateData.h" #include "StateTicks.h" #include "StateUtils.h" -#include "adc.h" -#include "can.h" #include "stm32g4xx_hal.h" -#include "vcp.h" + +// #include "vcp.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -66,48 +61,33 @@ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ -LogomaticConfig logomaticConfig = {.clock_source = LOGOMATIC_PCLK1, - .bus = LOGOMATIC_BUS, - .gpio_port = LOGOMATIC_GPIOA, - .gpio_pin_rx_tx_mask = LL_GPIO_PIN_9 | LL_GPIO_PIN_10, - .baud_rate = 115200, - .data_width = LOGOMATIC_DATAWIDTH_8B, - .stop_bits = LOGOMATIC_STOPBITS_1, - .parity = LOGOMATIC_PARITY_NONE, - .transfer_direction = LOGOMATIC_DIRECTION_TX, - .hardware_flow_control = LOGOMATIC_HWCONTROL_NONE, - .prescaler = LOGOMATIC_PRESCALER_DIV1, - .tx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8, - .rx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8}; - -VCP_Config vcp_config = {.baud_rate = 2000000, - .clock_source = VCP_CLOCK_PCLK, - .gpio_tx_rx_pin_mask = LL_GPIO_PIN_2 | LL_GPIO_PIN_3, - .bus_port = VCP_Port_A, - .parity = VCP_Parity_None, - .prescaler = VCP_Prescalar_Div2, - .stop_bits = VCP_StopBits_1, - .oversampling = VCP_Oversampling_16, - .tx_fifo_threshold = VCP_Threshold_1_8, - .rx_fifo_threshold = VCP_Threshold_1_8, - .alternate_function = LL_GPIO_AF_7, - .rx_callback = NULL}; -/* USER CODE END PV */ - -// ADC 1 -#define WINDOW_SIZE 10 // weighted average for now can extend to other window functions -#define NUM_SIGNALS_ADC1 7 -#define NUM_SIGNALS_ADC2 4 -#define NUM_SIGNALS (NUM_SIGNALS_ADC1 + NUM_SIGNALS_ADC2) -// TODO: check which data size to use (floats...ints...etc) -volatile uint16_t ADC_buffers[NUM_SIGNALS] = {1024}; // Contains new values -uint16_t ADC_outputs[NUM_SIGNALS] = {1024}; // Updated averages -// DIGITAL +// VCP_Config vcp_config = {.baud_rate = 2000000, +// .clock_source = VCP_CLOCK_PCLK, +// .gpio_tx_rx_pin_mask = LL_GPIO_PIN_2 | LL_GPIO_PIN_3, +// .bus_port = VCP_Port_A, +// .parity = VCP_Parity_None, +// .prescaler = VCP_Prescalar_Div2, +// .stop_bits = VCP_StopBits_1, +// .oversampling = VCP_Oversampling_16, +// .tx_fifo_threshold = VCP_Threshold_1_8, +// .rx_fifo_threshold = VCP_Threshold_1_8, +// .alternate_function = LL_GPIO_AF_7, +// .rx_callback = NULL}; + +#define NUM_SIGNALS_ADC1 5 +#define NUM_SIGNALS_ADC2 5 +#define NUM_SIGNALS_ADC5 1 + +#define NUM_SIGNALS (NUM_SIGNALS_ADC1 + NUM_SIGNALS_ADC2 + NUM_SIGNALS_ADC5) +volatile uint16_t ADC_buffers[NUM_SIGNALS] = {0}; +uint16_t ADC_outputs[NUM_SIGNALS] = {0}; // STATE DATA extern ECU_StateData stateLump; +/* USER CODE END PV */ + /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); /* USER CODE BEGIN PFP */ @@ -117,385 +97,120 @@ void SystemClock_Config(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ -/* USER CODE END 0 */ - -// TODO: state data stores stuff as either FLOATS or BOOLS...check -// TODO: TS and RTD button signals will come over CAN -void ADC_Logomatic(void) -{ - static uint16_t min_apps_1 = 4095; - static uint16_t min_apps_2 = 4095; - if (stateLump.APPS1_Signal < min_apps_1) { - min_apps_1 = stateLump.APPS1_Signal; - } - if (stateLump.APPS2_Signal < min_apps_2) { - min_apps_2 = stateLump.APPS2_Signal; - } - static uint16_t max_apps_1 = 0; - static uint16_t max_apps_2 = 0; - if (stateLump.APPS1_Signal > max_apps_1) { - max_apps_1 = stateLump.APPS1_Signal; - } - if (stateLump.APPS2_Signal > max_apps_2) { - max_apps_2 = stateLump.APPS2_Signal; - } - static uint16_t min_BSE = 4095; - if (stateLump.bse_signal < min_BSE) { - min_BSE = stateLump.bse_signal; - } - static uint16_t max_BSE = 0; - if (stateLump.bse_signal > max_BSE) { - max_BSE = stateLump.bse_signal; - } - - static uint16_t min_BR = 4095; - if (stateLump.Brake_R_Signal < min_BR) { - min_BR = stateLump.Brake_R_Signal; - } - static uint16_t max_BR = 0; - if (stateLump.Brake_R_Signal > max_BR) { - max_BR = stateLump.Brake_R_Signal; - } - - static uint16_t min_BF = 4095; - if (stateLump.Brake_F_Signal < min_BF) { - min_BF = stateLump.Brake_F_Signal; - } - static uint16_t max_BF = 0; - if (stateLump.Brake_F_Signal > max_BF) { - max_BF = stateLump.Brake_F_Signal; - } - - static uint16_t min_BSPD = 4095; - if (stateLump.bspd_signal < min_BSPD) { - min_BSPD = stateLump.bspd_signal; - } - static uint16_t max_BSPD = 0; - if (stateLump.bspd_signal > max_BSPD) { - max_BSPD = stateLump.bspd_signal; - } - LOGOMATIC("APPS1 %d (min %d, max %d) APPS2 %d (min %d, max %d) BSE %d (min %d, max %d) BSPD %d (min %d, max %d) Brake F %d (min %d, max %d), Brake R %d (min %d, max %d), Aux %d, Steering " - "Angle %d\n", - stateLump.APPS1_Signal, min_apps_1, max_apps_1, stateLump.APPS2_Signal, min_apps_2, max_apps_2, stateLump.bse_signal, min_BSE, max_BSE, stateLump.bspd_signal, min_BSPD, max_BSPD, - stateLump.Brake_F_Signal, min_BF, max_BF, stateLump.Brake_R_Signal, min_BR, max_BR, stateLump.aux_signal, stateLump.steering_angle_signal); - - // static float travel1 = 0; - // static float travel2 = 0; - // static float travel = 0; - // travel1 = (stateLump.APPS1_Signal - THROTTLE_MIN_1) * (1.0f - 0.0f) / (THROTTLE_MAX_1 - THROTTLE_MIN_1) + 0.0f; - // travel2 = (stateLump.APPS2_Signal - THROTTLE_MIN_2) * (1.0f - 0.0f) / (THROTTLE_MAX_2 - THROTTLE_MIN_2) + 0.0f; - // travel = (travel1 + travel2) / 2.0f; - // LOGOMATIC("APPS1 Travel %f, APPS2 Travel %f, Average Travel %f\n", travel1, travel2, travel); -} - -void read_digital(void) +void Update_ADC_to_StateData(void) { - stateLump.estop_sense = LL_GPIO_IsInputPinSet(ESTOP_SENSE_GPIO_Port, ESTOP_SENSE_Pin); -} - -void write_adc_values_to_state_data(void) -{ - // analog stateLump.bse_signal = ADC_outputs[ADC_BUFFER_SIG_BSE]; stateLump.bspd_signal = ADC_outputs[ADC_BUFFER_SIG_BSPD]; stateLump.APPS1_Signal = ADC_outputs[ADC_BUFFER_SIG_APPS1]; stateLump.APPS2_Signal = ADC_outputs[ADC_BUFFER_SIG_APPS2]; - stateLump.Brake_F_Signal = ADC_outputs[ADC_BUFFER_SIG_BRAKE_F]; - stateLump.Brake_R_Signal = ADC_outputs[ADC_BUFFER_SIG_BRAKE_R]; + stateLump.Brake_Signal = ADC_outputs[ADC_BUFFER_SIG_BRAKE]; stateLump.aux_signal = ADC_outputs[ADC_BUFFER_SIG_AUX]; - stateLump.steering_angle_signal = ADC_outputs[ADC_BUFFER_SIG_STEERING_ANGLE]; // TODO: convert to rad/deg...? + stateLump.steering_angle_signal = ADC_outputs[ADC_BUFFER_SIG_STEERING_ANGLE]; - // TODO: determine conversion factors for all of these (uint to float) - stateLump.bspd_sense = ADC_outputs[ADC_BUFFER_SENSE_BSPD] / 4095.0 * 3.3; - stateLump.imd_sense = ADC_outputs[ADC_BUFFER_SENSE_IMD] / 4095.0 * 3.3; - stateLump.bms_sense = ADC_outputs[ADC_BUFFER_SENSE_BMS] / 4095.0 * 3.3; + stateLump.bspd_sense = ADC_outputs[ADC_BUFFER_SENSE_BSPD] / 4095.0f * 3.3f; + stateLump.imd_sense = ADC_outputs[ADC_BUFFER_SENSE_IMD] / 4095.0f * 3.3f; + stateLump.bms_sense = ADC_outputs[ADC_BUFFER_SENSE_BMS] / 4095.0f * 3.3f; } -void ADC_Configure(void) -{ - // Initialize which clock source to use - LL_RCC_SetADCClockSource(LL_RCC_ADC12_CLKSOURCE_SYSCLK); - /* Peripheral clock enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_ADC12); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - - // ADC 1 - ADC_Init_Values Init_Vals_ADC1 = {0}; - Init_Vals_ADC1.ADC = ADC1; - Init_Vals_ADC1.PS_Value = PS_8; // TODO: change later - Init_Vals_ADC1.Res = RESOLUTION_12; // TODO: change later - Init_Vals_ADC1.Num_Pin_Port_Objs = 2; - Pin_Ports p1[2] = {{.pin = BSE_SIGNAL_Pin | BSPD_SENSE_Pin | APPS1_SIGNAL_Pin | APPS2_SIGNAL_Pin, .port = GPIOC}, - {.pin = BRAKE_F_SIGNAL_Pin | BRAKE_R_SIGNAL_Pin | AUX_SIGNAL_Pin, .port = GPIOB}}; - Init_Vals_ADC1.Pins = p1; - Init_Vals_ADC1.Num_Channels = 7; // check multiple GPIO stuff - Channel c1[] = {ADC_CHANNEL_6, ADC_CHANNEL_7, ADC_CHANNEL_8, ADC_CHANNEL_9, ADC_CHANNEL_15, ADC_CHANNEL_12, ADC_CHANNEL_5}; - Init_Vals_ADC1.Channels = c1; - SamplingTime s1 = LL_ADC_SAMPLINGTIME_92CYCLES_5; - Init_Vals_ADC1.SamplingTimes = &s1; - ADC_Init(&Init_Vals_ADC1); - - // TODO Use ADC peripheral API for configuring ideally... but honestly its fine - LL_ADC_SetOverSamplingScope(ADC1, LL_ADC_OVS_GRP_REGULAR_CONTINUED); - LL_ADC_ConfigOverSamplingRatioShift(ADC1, LL_ADC_OVS_RATIO_256, LL_ADC_OVS_SHIFT_RIGHT_8); - - // ADC 2 - ADC_Init_Values Init_Vals_ADC2 = {0}; - Init_Vals_ADC2.ADC = ADC2; - Init_Vals_ADC2.PS_Value = PS_8; // TODO: change later - Init_Vals_ADC2.Res = RESOLUTION_12; // TODO: change later - Init_Vals_ADC2.Num_Pin_Port_Objs = 1; - Pin_Ports p2[2] = {{.pin = BSPD_SENSE_Pin | IMD_SENSE_Pin | AMS_SENSE_Pin, .port = GPIOA}, {.pin = STEERING_ANGLE_Pin, .port = GPIOB}}; - Init_Vals_ADC2.Pins = p2; - Init_Vals_ADC2.Num_Channels = 4; - Channel c2[] = {ADC_CHANNEL_13, ADC_CHANNEL_3, ADC_CHANNEL_4, ADC_CHANNEL_15}; - Init_Vals_ADC2.Channels = c2; - SamplingTime s2 = LL_ADC_SAMPLINGTIME_92CYCLES_5; - Init_Vals_ADC2.SamplingTimes = &s2; - ADC_Init(&Init_Vals_ADC2); - - // TODO Use ADC peripheral API for configuring ideally... but honestly its fine - LL_ADC_SetOverSamplingScope(ADC2, LL_ADC_OVS_GRP_REGULAR_CONTINUED); - LL_ADC_ConfigOverSamplingRatioShift(ADC2, LL_ADC_OVS_RATIO_256, LL_ADC_OVS_SHIFT_RIGHT_8); - - /* - // Initialize DMA (ADC1 = CHANNEL 1, ADC2 = CHANNEL 2) - // DMA reads into buffer - DMA_Init(DMA1, LL_DMA_CHANNEL_1, LL_ADC_DMA_GetRegAddr(ADC1, LL_ADC_DMA_REG_REGULAR_DATA), ADC1_buffers, LL_DMA_PDATAALIGN_HALFWORD, LL_DMA_MDATAALIGN_HALFWORD, NUM_SIGNALS_ADC1, ADC1, HIGH); - LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1); - DMA_Init(DMA1, LL_DMA_CHANNEL_2, LL_ADC_DMA_GetRegAddr(ADC2, LL_ADC_DMA_REG_REGULAR_DATA), ADC2_buffers, LL_DMA_PDATAALIGN_HALFWORD, LL_DMA_MDATAALIGN_HALFWORD, NUM_SIGNALS_ADC2, ADC2, HIGH); - LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_2); - */ - // Initialize DMA (for both ADCs) - DMA_Init_Values DMA_Init_Vals_ADC1 = {0}; - DMA_Init_Vals_ADC1.DMA = DMA1; - DMA_Init_Vals_ADC1.ADC = ADC1; - DMA_Init_Vals_ADC1.Channel = DMA_CHANNEL_1; - DMA_Init_Vals_ADC1.Src_Address = LL_ADC_DMA_GetRegAddr(ADC1, LL_ADC_DMA_REG_REGULAR_DATA); - DMA_Init_Vals_ADC1.Dest_Address = ADC_buffers; - DMA_Init_Vals_ADC1.Data_Size = Half_Word; - DMA_Init_Vals_ADC1.Priority = HIGH; // TODO: check what this does - DMA_Init_Vals_ADC1.Num_Data = NUM_SIGNALS_ADC1; - DMA_Init(&DMA_Init_Vals_ADC1); - LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1); - - DMA_Init_Values DMA_Init_Vals_ADC2 = {0}; - DMA_Init_Vals_ADC2.DMA = DMA1; - DMA_Init_Vals_ADC2.ADC = ADC2; - DMA_Init_Vals_ADC2.Channel = DMA_CHANNEL_2; - DMA_Init_Vals_ADC2.Src_Address = LL_ADC_DMA_GetRegAddr(ADC2, LL_ADC_DMA_REG_REGULAR_DATA); - DMA_Init_Vals_ADC2.Dest_Address = ADC_buffers + NUM_SIGNALS_ADC1; - DMA_Init_Vals_ADC2.Data_Size = Half_Word; - DMA_Init_Vals_ADC2.Priority = HIGH; // TODO: check what this does - DMA_Init_Vals_ADC2.Num_Data = NUM_SIGNALS_ADC2; - DMA_Init(&DMA_Init_Vals_ADC2); - LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_2); - - ADC_Enable_And_Calibrate(ADC1); - ADC_Enable_And_Calibrate(ADC2); -} -void CAN1_rx_callback(uint32_t ID, void *data, uint32_t size) + +void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { - if ((ID & 0x1FFFC0FF) == 0x00000016) { - ECU_CAN_DTI_MessageHandler(&stateLump, ID, data, size); - } else { - ECU_CAN_MessageHandler(&stateLump, GRCAN_BUS_PRIMARY, (0x000FFF00 & ID) >> 8, (0xFF00000 & ID) >> 20, data, size); + if (htim->Instance == TIM6) { + CubeCAN_Tick(); } } -void CAN2_rx_callback(uint32_t ID, void *data, uint32_t size) -{ - ECU_CAN_MessageHandler(&stateLump, GRCAN_BUS_DATA, (0x000FFF00 & ID) >> 8, (0xFF00000 & ID) >> 20, data, size); -} +// void read_digital(){ +// stateLump.estop_sense = LL_GPIO_IsInputPinSet(ESTOP_SENSE_GPIO_Port, ESTOP_SENSE_Pin); +// } + +/* USER CODE END 0 */ -void CAN_Configure(void) -{ - CANConfig canCfg; - - // SHARED config ddata for CAN1 and CAN2 - canCfg.hal_fdcan_init.ClockDivider = FDCAN_CLOCK_DIV1; - canCfg.hal_fdcan_init.FrameFormat = FDCAN_FRAME_FD_NO_BRS; - canCfg.hal_fdcan_init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - canCfg.hal_fdcan_init.Mode = FDCAN_MODE_NORMAL; - canCfg.hal_fdcan_init.AutoRetransmission = ENABLE; - canCfg.hal_fdcan_init.TransmitPause = DISABLE; - canCfg.hal_fdcan_init.ProtocolException = ENABLE; - canCfg.hal_fdcan_init.NominalPrescaler = 1; - canCfg.hal_fdcan_init.NominalSyncJumpWidth = 16; - canCfg.hal_fdcan_init.NominalTimeSeg1 = 119; // Updated for 160MHz: (1+119+40)*1 = 160 ticks -> 1 Mbps - canCfg.hal_fdcan_init.NominalTimeSeg2 = 40; - canCfg.hal_fdcan_init.DataPrescaler = 1; - canCfg.hal_fdcan_init.DataSyncJumpWidth = 16; - canCfg.hal_fdcan_init.DataTimeSeg1 = 9; // Updated for 160MHz: 160 MHz/((1+9+10)*1) = 8 Mbps - canCfg.hal_fdcan_init.DataTimeSeg2 = 10; - canCfg.hal_fdcan_init.StdFiltersNbr = 0; - canCfg.hal_fdcan_init.ExtFiltersNbr = 3; - - canCfg.rx_callback = NULL; - canCfg.rx_interrupt_priority = 15; // TODO: Maybe make these not hardcoded - canCfg.tx_interrupt_priority = 15; - // canCfg.tx_buffer_length = CAN_TX_BUFFER_LENGTH; - - // RX shared settings - canCfg.init_rx_gpio.Mode = GPIO_MODE_AF_PP; - canCfg.init_rx_gpio.Pull = GPIO_PULLUP; - canCfg.init_rx_gpio.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - - // TX Shared settings - canCfg.init_tx_gpio.Mode = GPIO_MODE_AF_PP; - canCfg.init_tx_gpio.Pull = GPIO_NOPULL; - canCfg.init_tx_gpio.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - - /*FDCAN_TxHeaderTypeDef TxHeader = { - .Identifier = 1, - - .IdType = FDCAN_STANDARD_ID, - .TxFrameType = FDCAN_DATA_FRAME, - .ErrorStateIndicator = FDCAN_ESI_ACTIVE, // honestly this might be a value you have to read from a node - // FDCAN_ESI_ACTIVE is just a state that assumes there are minimal errors - .DataLength = 1, - .BitRateSwitch = FDCAN_BRS_OFF, - .TxEventFifoControl = FDCAN_NO_TX_EVENTS, // change to FDCAN_STORE_TX_EVENTS if you need to store info regarding transmitted messages - .MessageMarker = 0 // also change this to a real address if you change fifo control - }; - - FDCANTxMessage msg = {.data = {0x80}, .tx_header = TxHeader}; - */ - - // PCLK1 from SYSCLK - can_set_clksource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - // CAN1 ===================================================================== - canCfg.fdcan_instance = FDCAN1; - canCfg.rx_gpio = GPIOA; - canCfg.init_rx_gpio.Pin = GPIO_PIN_11; - canCfg.init_rx_gpio.Alternate = GPIO_AF9_FDCAN1; - - canCfg.tx_gpio = GPIOA; - canCfg.init_tx_gpio.Pin = GPIO_PIN_12; - canCfg.init_tx_gpio.Alternate = GPIO_AF9_FDCAN1; - - // RX Callback CAN1 - canCfg.rx_callback = CAN1_rx_callback; // TODO: Make sure the wrapper for this is defined correctly - - FDCAN_FilterTypeDef fdcan_primary_filter_ecu = {0}; - fdcan_primary_filter_ecu.IdType = FDCAN_EXTENDED_ID; - fdcan_primary_filter_ecu.FilterIndex = 0; - fdcan_primary_filter_ecu.FilterType = FDCAN_FILTER_MASK; - fdcan_primary_filter_ecu.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; - fdcan_primary_filter_ecu.FilterID1 = GRCAN_ECU & 0xFF; - fdcan_primary_filter_ecu.FilterID2 = 0x000000FF; - - FDCAN_FilterTypeDef fdcan_primary_filter_all = {0}; - fdcan_primary_filter_all.IdType = FDCAN_EXTENDED_ID; - fdcan_primary_filter_all.FilterIndex = 1; - fdcan_primary_filter_all.FilterType = FDCAN_FILTER_MASK; - fdcan_primary_filter_all.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; - fdcan_primary_filter_all.FilterID1 = GRCAN_ALL & 0xFF; - fdcan_primary_filter_all.FilterID2 = 0x000000FF; - - FDCAN_FilterTypeDef fdcan_primary_filter_dti = {0}; - fdcan_primary_filter_ecu.IdType = FDCAN_EXTENDED_ID; - fdcan_primary_filter_ecu.FilterIndex = 2; - fdcan_primary_filter_ecu.FilterType = FDCAN_FILTER_MASK; - fdcan_primary_filter_ecu.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; - fdcan_primary_filter_ecu.FilterID1 = 0x00000016; - fdcan_primary_filter_ecu.FilterID2 = 0x1FFFC0FF; - - stateLump.primary_can = can_init(&canCfg); - - can_add_filter(stateLump.primary_can, &fdcan_primary_filter_ecu); - can_add_filter(stateLump.primary_can, &fdcan_primary_filter_all); - can_add_filter(stateLump.primary_can, &fdcan_primary_filter_dti); - - // CAN2 ====================================================== - canCfg.fdcan_instance = FDCAN2; - canCfg.rx_gpio = GPIOB; - canCfg.init_rx_gpio.Pin = GPIO_PIN_12; - canCfg.init_rx_gpio.Alternate = GPIO_AF9_FDCAN2; - - canCfg.tx_gpio = GPIOB; - canCfg.init_tx_gpio.Pin = GPIO_PIN_13; - canCfg.init_tx_gpio.Alternate = GPIO_AF9_FDCAN2; - - // RX Callback CAN2 - canCfg.rx_callback = CAN2_rx_callback; // TODO: Make sure the wrapper for this is defined correctly - - FDCAN_FilterTypeDef fdcan_data_filter_ecu = {0}; - fdcan_data_filter_ecu.IdType = FDCAN_EXTENDED_ID; - fdcan_data_filter_ecu.FilterIndex = 0; - fdcan_data_filter_ecu.FilterType = FDCAN_FILTER_MASK; - fdcan_data_filter_ecu.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; - fdcan_data_filter_ecu.FilterID1 = GRCAN_ECU & 0xFF; - fdcan_data_filter_ecu.FilterID2 = 0x000000FF; - - FDCAN_FilterTypeDef fdcan_data_filter_all = {0}; - fdcan_data_filter_all.IdType = FDCAN_EXTENDED_ID; - fdcan_data_filter_all.FilterIndex = 1; - fdcan_data_filter_all.FilterType = FDCAN_FILTER_MASK; - fdcan_data_filter_all.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; - fdcan_data_filter_all.FilterID1 = GRCAN_ALL & 0xFF; - fdcan_data_filter_all.FilterID2 = 0x000000FF; - - stateLump.data_can = can_init(&canCfg); - - can_add_filter(stateLump.data_can, &fdcan_data_filter_ecu); - can_add_filter(stateLump.data_can, &fdcan_data_filter_all); - - // timer can - can_start(stateLump.primary_can); - can_start(stateLump.data_can); -} /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU - * Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the - * Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - // TODO: Figure out GPIO Init - MX_GPIO_Init(); - MX_DMA_Init(); - // MX_FDCAN1_Init(); - MX_ADC1_Init(); - MX_ADC2_Init(); - // MX_FDCAN2_Init(); - /* USER CODE BEGIN 2 */ - Setup_Logomatic(&logomaticConfig); - Setup_VCP(&vcp_config); + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_DMA_Init(); + MX_ADC1_Init(); + MX_ADC2_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + MX_TIM6_Init(); + MX_ADC5_Init(); + MX_USART3_UART_Init(); + /* USER CODE BEGIN 2 */ + Logomatic_SetLogLevel(LogLevel_Info); + // Setup_VCP(&vcp_config); // Initialize CAN - CAN_Configure(); + CubeCAN_Config primaryCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_PRIMARY, .sending_node_id = GRCAN_ECU}; + + CubeCAN_Config dataCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_DATA, .sending_node_id = GRCAN_ECU}; + + stateLump.primary_can = CubeCAN_Entrance(&hfdcan1, &primaryCanConfig); + if (stateLump.primary_can == NULL) { + LOGOMATIC_CRITICAL("Failed to initialize primary CAN handle\n"); + Error_Handler(); + } + + stateLump.data_can = CubeCAN_Entrance(&hfdcan2, &dataCanConfig); + if (stateLump.data_can == NULL) { + LOGOMATIC_CRITICAL("Failed to initialize data CAN handle\n"); + Error_Handler(); + } + + //Initialize Timer + HAL_TIM_Base_Start_IT(&htim6); + + if (HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED) != HAL_OK || + HAL_ADCEx_Calibration_Start(&hadc2, ADC_SINGLE_ENDED) != HAL_OK || + HAL_ADCEx_Calibration_Start(&hadc5, ADC_SINGLE_ENDED) != HAL_OK || + HAL_ADC_Start_DMA(&hadc1, (uint32_t *)ADC_buffers, NUM_SIGNALS_ADC1) != HAL_OK || + HAL_ADC_Start_DMA(&hadc2, (uint32_t *)(ADC_buffers + NUM_SIGNALS_ADC1), NUM_SIGNALS_ADC2) != HAL_OK || + HAL_ADC_Start_DMA(&hadc5, (uint32_t *)(ADC_buffers + NUM_SIGNALS_ADC1 + NUM_SIGNALS_ADC2),NUM_SIGNALS_ADC5) != HAL_OK){ + + LOGOMATIC_CRITICAL("Failed to start ADC calibration or DMA\n"); + Error_Handler(); + } + + //Disabling DMA intterrupts for ADC1 and ADC2 for now + __HAL_DMA_DISABLE_IT(hadc1.DMA_Handle, DMA_IT_HT | DMA_IT_TC); + __HAL_DMA_DISABLE_IT(hadc2.DMA_Handle, DMA_IT_HT | DMA_IT_TC); + __HAL_DMA_DISABLE_IT(hadc5.DMA_Handle, DMA_IT_HT | DMA_IT_TC); + - ADC_Configure(); float adc_alpha = 5000.0f / MAIN_LOOP_PERIOD_US; // around 5 time constants in one cycle of the main loop - LOGOMATIC("Boot completed at %lu ms\n", MillisecondsSinceBoot()); + LOGOMATIC_INFO("Boot completed at %lu ms\n", MillisecondsSinceBoot()); + + while (MillisecondsSinceBoot() < 5000) { // Notes per Andrey and Ryan BrakeLightControl(&stateLump); @@ -510,101 +225,100 @@ int main(void) LL_mDelay(1); ADC_UpdateAnalogValues_EMA(ADC_buffers, NUM_SIGNALS, adc_alpha, ADC_outputs); - write_adc_values_to_state_data(); + Update_ADC_to_StateData(); } - LOGOMATIC("Initial ADC readings stabilized at %lu ms\n", MillisecondsSinceBoot()); + LOGOMATIC_INFO("Initial ADC readings stabilized at %lu ms\n", MillisecondsSinceBoot()); - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { - // adcs - read_digital(); - // main state lopp, queues can messages within it - static uint32_t delay_timer; - static uint32_t ping_timer; - static uint32_t adc_timer; - // ADC - if (MillisecondsSinceBoot() >= adc_timer) { - adc_timer = MillisecondsSinceBoot() + 1; - - ADC_UpdateAnalogValues_EMA(ADC_buffers, NUM_SIGNALS, adc_alpha, ADC_outputs); - write_adc_values_to_state_data(); - } - - if (MillisecondsSinceBoot() >= delay_timer) { -#ifdef PLAN_C - ECU_CAN_Send(GRCAN_BUS_PRIMARY, GRCAN_Debugger, GRCAN_DEBUG_2_0, "!PLAN_C!", 8); -#endif - - delay_timer = MillisecondsSinceBoot() + (MAIN_LOOP_PERIOD_US / 1000); - - // ADC_UpdateAnalogValues_EMA(ADC_buffers, NUM_SIGNALS, 0.01, ADC_outputs); - // void ADC_UpdateAnalogValues(uint16_t **adcDataValues, volatile uint16_t *new_values, int num_signals, int window_size, uint16_t *weighted_output) - // ADC_UpdateAnalogValues(ADC_buffers, ADC_outputs, NUM_SIGNALS, WINDOW_SIZE, ); // TODO: figure out which alpha values to use for the different signals - // write_adc_values_to_state_data(); - - // state tick - ECU_State_Tick(); - - // preipheral updates - SendECUStateDataOverCAN(&stateLump); - SendECUAnalogDataOverCAN(&stateLump); - if (MillisecondsSinceBoot() >= ping_timer) { - ping_timer = MillisecondsSinceBoot() + (MAIN_LOOP_PERIOD_US / 500); // half period - pingAll(); - } - lightControl(&stateLump); - - Send_VCP_APPS(&stateLump, ADC_outputs[ADC_BUFFER_SIG_APPS1], ADC_outputs[ADC_BUFFER_SIG_APPS2]); - // ADC_Logomatic(); - } + // read_digital(); + + static uint32_t delay_timer; + static uint32_t ping_timer; + static uint32_t adc_timer; + + if (MillisecondsSinceBoot() >= adc_timer){ + adc_timer = MillisecondsSinceBoot() + 1; + ADC_UpdateAnalogValues_EMA(ADC_buffers, NUM_SIGNALS, adc_alpha, ADC_outputs); // This needs to be updated/changes + Update_ADC_to_StateData(); + } + + + if (MillisecondsSinceBoot() >= delay_timer){ + delay_timer = MillisecondsSinceBoot() + (MAIN_LOOP_PERIOD_US / 1000); + + ECU_State_Tick(); + + SendECUStateDataOverCAN(&stateLump); + SendECUAnalogDataOverCAN(&stateLump); + + if (MillisecondsSinceBoot() >= ping_timer){ + ping_timer = MillisecondsSinceBoot() + (MAIN_LOOP_PERIOD_US / 500); + pingAll(); + } + + lightControl(&stateLump); + + + //Send_VCP_APPS(); + } + + + /* USER CODE END WHILE */ + + /* USER CODE BEGIN 3 */ } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSE_Enable(); - /* Wait till HSE is ready */ - while (LL_RCC_HSE_IsReady() != 1) {} - - LL_RCC_HSE_EnableCSS(); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (160 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(160000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + + /** Configure the main internal regulator output voltage + */ + HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST); + + /** Initializes the RCC Oscillators according to the specified parameters + * in the RCC_OscInitTypeDef structure. + */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; + RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1; + RCC_OscInitStruct.PLL.PLLN = 20; + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; + RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2; + RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) + { + Error_Handler(); + } + + /** Initializes the CPU, AHB and APB buses clocks + */ + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK + |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; + + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) + { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -612,30 +326,32 @@ void SystemClock_Config(void) /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return * state */ __disable_irq(); - while (1) {} - /* USER CODE END Error_Handler_Debug */ + while (1) { + LOGOMATIC_CRITICAL("Error Handler entered at %lu ms\n", MillisecondsSinceBoot()); + } + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ - LOGOMATIC("Assertion failed: file %s on line %d\r\n", file, line); - /* USER CODE END 6 */ + /* USER CODE BEGIN 6 */ + LOGOMATIC_ERROR("Assertion failed: file %s on line %d\r\n", file, (int)line); + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/ECU/Core/Src/stm32g4xx_hal_msp.c b/ECU/Core/Src/stm32g4xx_hal_msp.c index f266230dd..7c45c4351 100644 --- a/ECU/Core/Src/stm32g4xx_hal_msp.c +++ b/ECU/Core/Src/stm32g4xx_hal_msp.c @@ -17,7 +17,6 @@ ****************************************************************************** */ /* USER CODE END Header */ - /* Includes ------------------------------------------------------------------*/ #include "main.h" /* USER CODE BEGIN Includes */ @@ -58,27 +57,27 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ + * Initializes the Global MSP. + */ void HAL_MspInit(void) { - /* USER CODE BEGIN MspInit 0 */ + /* USER CODE BEGIN MspInit 0 */ - /* USER CODE END MspInit 0 */ + /* USER CODE END MspInit 0 */ - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); - /* System interrupt init*/ + /* System interrupt init*/ - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); - /* USER CODE BEGIN MspInit 1 */ + /* USER CODE BEGIN MspInit 1 */ - /* USER CODE END MspInit 1 */ + /* USER CODE END MspInit 1 */ } /* USER CODE BEGIN 1 */ diff --git a/ECU/Core/Src/stm32g4xx_it.c b/ECU/Core/Src/stm32g4xx_it.c index 01ab766d9..dbd5814d7 100644 --- a/ECU/Core/Src/stm32g4xx_it.c +++ b/ECU/Core/Src/stm32g4xx_it.c @@ -18,11 +18,8 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "stm32g4xx_it.h" - -#include "can.h" #include "main.h" -#include "stm32g4xx_ll_tim.h" +#include "stm32g4xx_it.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -58,8 +55,15 @@ /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ +extern DMA_HandleTypeDef hdma_adc1; +extern DMA_HandleTypeDef hdma_adc2; +extern DMA_HandleTypeDef hdma_adc5; +extern ADC_HandleTypeDef hadc1; +extern ADC_HandleTypeDef hadc2; +extern ADC_HandleTypeDef hadc5; extern FDCAN_HandleTypeDef hfdcan1; extern FDCAN_HandleTypeDef hfdcan2; +extern TIM_HandleTypeDef htim6; /* USER CODE BEGIN EV */ /* USER CODE END EV */ @@ -68,125 +72,292 @@ extern FDCAN_HandleTypeDef hfdcan2; /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ + * @brief This function handles Non maskable interrupt. + */ void NMI_Handler(void) { - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) {} - /* USER CODE END NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 1 */ } /** - * @brief This function handles Hard fault interrupt. - */ + * @brief This function handles Hard fault interrupt. + */ void HardFault_Handler(void) { - /* USER CODE BEGIN HardFault_IRQn 0 */ - - /* USER CODE END HardFault_IRQn 0 */ - while (1) { - /* USER CODE BEGIN W1_HardFault_IRQn 0 */ - /* USER CODE END W1_HardFault_IRQn 0 */ - } + /* USER CODE BEGIN HardFault_IRQn 0 */ + + /* USER CODE END HardFault_IRQn 0 */ + while (1) + { + /* USER CODE BEGIN W1_HardFault_IRQn 0 */ + /* USER CODE END W1_HardFault_IRQn 0 */ + } } /** - * @brief This function handles Memory management fault. - */ + * @brief This function handles Memory management fault. + */ void MemManage_Handler(void) { - /* USER CODE BEGIN MemoryManagement_IRQn 0 */ - - /* USER CODE END MemoryManagement_IRQn 0 */ - while (1) { - /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ - /* USER CODE END W1_MemoryManagement_IRQn 0 */ - } + /* USER CODE BEGIN MemoryManagement_IRQn 0 */ + + /* USER CODE END MemoryManagement_IRQn 0 */ + while (1) + { + /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ + /* USER CODE END W1_MemoryManagement_IRQn 0 */ + } } /** - * @brief This function handles Prefetch fault, memory access fault. - */ + * @brief This function handles Prefetch fault, memory access fault. + */ void BusFault_Handler(void) { - /* USER CODE BEGIN BusFault_IRQn 0 */ - - /* USER CODE END BusFault_IRQn 0 */ - while (1) { - /* USER CODE BEGIN W1_BusFault_IRQn 0 */ - /* USER CODE END W1_BusFault_IRQn 0 */ - } + /* USER CODE BEGIN BusFault_IRQn 0 */ + + /* USER CODE END BusFault_IRQn 0 */ + while (1) + { + /* USER CODE BEGIN W1_BusFault_IRQn 0 */ + /* USER CODE END W1_BusFault_IRQn 0 */ + } } /** - * @brief This function handles Undefined instruction or illegal state. - */ + * @brief This function handles Undefined instruction or illegal state. + */ void UsageFault_Handler(void) { - /* USER CODE BEGIN UsageFault_IRQn 0 */ - - /* USER CODE END UsageFault_IRQn 0 */ - while (1) { - /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ - /* USER CODE END W1_UsageFault_IRQn 0 */ - } + /* USER CODE BEGIN UsageFault_IRQn 0 */ + + /* USER CODE END UsageFault_IRQn 0 */ + while (1) + { + /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ + /* USER CODE END W1_UsageFault_IRQn 0 */ + } } /** - * @brief This function handles System service call via SWI instruction. - */ + * @brief This function handles System service call via SWI instruction. + */ void SVC_Handler(void) { - /* USER CODE BEGIN SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 0 */ - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ - /* USER CODE END SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 1 */ } /** - * @brief This function handles Debug monitor. - */ + * @brief This function handles Debug monitor. + */ void DebugMon_Handler(void) { - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** - * @brief This function handles Pendable request for system service. - */ + * @brief This function handles Pendable request for system service. + */ void PendSV_Handler(void) { - /* USER CODE BEGIN PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 0 */ - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ - /* USER CODE END PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 1 */ } /** - * @brief This function handles System tick timer. - */ + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ + /* USER CODE BEGIN SysTick_IRQn 0 */ + + /* USER CODE END SysTick_IRQn 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ + + /* USER CODE END SysTick_IRQn 1 */ +} + +/******************************************************************************/ +/* STM32G4xx Peripheral Interrupt Handlers */ +/* Add here the Interrupt Handlers for the used peripherals. */ +/* For the available peripheral interrupt handler names, */ +/* please refer to the startup file (startup_stm32g4xx.s). */ +/******************************************************************************/ + +/** + * @brief This function handles DMA1 channel1 global interrupt. + */ +void DMA1_Channel1_IRQHandler(void) +{ + /* USER CODE BEGIN DMA1_Channel1_IRQn 0 */ + + /* USER CODE END DMA1_Channel1_IRQn 0 */ + HAL_DMA_IRQHandler(&hdma_adc1); + /* USER CODE BEGIN DMA1_Channel1_IRQn 1 */ + + /* USER CODE END DMA1_Channel1_IRQn 1 */ +} + +/** + * @brief This function handles DMA1 channel2 global interrupt. + */ +void DMA1_Channel2_IRQHandler(void) +{ + /* USER CODE BEGIN DMA1_Channel2_IRQn 0 */ + + /* USER CODE END DMA1_Channel2_IRQn 0 */ + HAL_DMA_IRQHandler(&hdma_adc5); + /* USER CODE BEGIN DMA1_Channel2_IRQn 1 */ + + /* USER CODE END DMA1_Channel2_IRQn 1 */ +} + +/** + * @brief This function handles ADC1 and ADC2 global interrupt. + */ +void ADC1_2_IRQHandler(void) +{ + /* USER CODE BEGIN ADC1_2_IRQn 0 */ + + /* USER CODE END ADC1_2_IRQn 0 */ + HAL_ADC_IRQHandler(&hadc1); + HAL_ADC_IRQHandler(&hadc2); + /* USER CODE BEGIN ADC1_2_IRQn 1 */ + + /* USER CODE END ADC1_2_IRQn 1 */ +} + +/** + * @brief This function handles FDCAN1 interrupt 0. + */ +void FDCAN1_IT0_IRQHandler(void) +{ + /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ + + /* USER CODE END FDCAN1_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan1); + /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ + + /* USER CODE END FDCAN1_IT0_IRQn 1 */ +} + +/** + * @brief This function handles FDCAN1 interrupt 1. + */ +void FDCAN1_IT1_IRQHandler(void) +{ + /* USER CODE BEGIN FDCAN1_IT1_IRQn 0 */ + + /* USER CODE END FDCAN1_IT1_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan1); + /* USER CODE BEGIN FDCAN1_IT1_IRQn 1 */ + + /* USER CODE END FDCAN1_IT1_IRQn 1 */ +} + +/** + * @brief This function handles TIM6 global interrupt, DAC1 and DAC3 channel underrun error interrupts. + */ +void TIM6_DAC_IRQHandler(void) +{ + /* USER CODE BEGIN TIM6_DAC_IRQn 0 */ + + /* USER CODE END TIM6_DAC_IRQn 0 */ + HAL_TIM_IRQHandler(&htim6); + /* USER CODE BEGIN TIM6_DAC_IRQn 1 */ + + /* USER CODE END TIM6_DAC_IRQn 1 */ +} + +/** + * @brief This function handles DMA2 channel1 global interrupt. + */ +void DMA2_Channel1_IRQHandler(void) +{ + /* USER CODE BEGIN DMA2_Channel1_IRQn 0 */ + + /* USER CODE END DMA2_Channel1_IRQn 0 */ + HAL_DMA_IRQHandler(&hdma_adc2); + /* USER CODE BEGIN DMA2_Channel1_IRQn 1 */ + + /* USER CODE END DMA2_Channel1_IRQn 1 */ +} + +/** + * @brief This function handles ADC5 global interrupt. + */ +void ADC5_IRQHandler(void) +{ + /* USER CODE BEGIN ADC5_IRQn 0 */ + + /* USER CODE END ADC5_IRQn 0 */ + HAL_ADC_IRQHandler(&hadc5); + /* USER CODE BEGIN ADC5_IRQn 1 */ + + /* USER CODE END ADC5_IRQn 1 */ +} + +/** + * @brief This function handles FDCAN2 interrupt 0. + */ +void FDCAN2_IT0_IRQHandler(void) +{ + /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ + + /* USER CODE END FDCAN2_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan2); + /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ + + /* USER CODE END FDCAN2_IT0_IRQn 1 */ +} + +/** + * @brief This function handles FDCAN2 interrupt 1. + */ +void FDCAN2_IT1_IRQHandler(void) +{ + /* USER CODE BEGIN FDCAN2_IT1_IRQn 0 */ + + /* USER CODE END FDCAN2_IT1_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan2); + /* USER CODE BEGIN FDCAN2_IT1_IRQn 1 */ + + /* USER CODE END FDCAN2_IT1_IRQn 1 */ +} + +/** + * @brief This function handles DMAMUX overrun interrupt. + */ +void DMAMUX_OVR_IRQHandler(void) +{ + /* USER CODE BEGIN DMAMUX_OVR_IRQn 0 */ - /* USER CODE END SysTick_IRQn 0 */ - HAL_IncTick(); - /* USER CODE BEGIN SysTick_IRQn 1 */ + /* USER CODE END DMAMUX_OVR_IRQn 0 */ + // Handle DMA1_Channel1 + HAL_DMAEx_MUX_IRQHandler(&hdma_adc1); + /* USER CODE BEGIN DMAMUX_OVR_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END DMAMUX_OVR_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/ECU/Core/Src/syscalls.c b/ECU/Core/Src/syscalls.c new file mode 100644 index 000000000..d2b217993 --- /dev/null +++ b/ECU/Core/Src/syscalls.c @@ -0,0 +1,233 @@ +/** + ****************************************************************************** + * @file syscalls.c + * @author Auto-generated by STM32CubeMX + * @brief Minimal System calls file + * + * For more information about which c-functions + * need which of these lowlevel functions + * please consult the Newlib or Picolibc libc-manual + ****************************************************************************** + * @attention + * + * Copyright (c) 2020-2025 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +/* Includes */ +#include +#include +#include +#include +#include +#include +#include +#include + +/* Variables */ +extern int __io_putchar(int ch) __attribute__((weak)); +extern int __io_getchar(void) __attribute__((weak)); + +char *__env[1] = {0}; +char **environ = __env; + +/* Functions */ +void initialise_monitor_handles() {} + +int _getpid(void) +{ + return 1; +} + +int _kill(int pid, int sig) +{ + (void)pid; + (void)sig; + errno = EINVAL; + return -1; +} + +void _exit(int status) +{ + _kill(status, -1); + while (1) {} /* Make sure we hang here */ +} + +__attribute__((weak)) int _read(int file, char *ptr, int len) +{ + (void)file; + int DataIdx; + + for (DataIdx = 0; DataIdx < len; DataIdx++) { + *ptr++ = __io_getchar(); + } + + return len; +} + +__attribute__((weak)) int _write(int file, char *ptr, int len) +{ + (void)file; + int DataIdx; + + for (DataIdx = 0; DataIdx < len; DataIdx++) { + __io_putchar(*ptr++); + } + return len; +} + +int _close(int file) +{ + (void)file; + return -1; +} + +int _fstat(int file, struct stat *st) +{ + (void)file; + st->st_mode = S_IFCHR; + return 0; +} + +int _isatty(int file) +{ + (void)file; + return 1; +} + +int _lseek(int file, int ptr, int dir) +{ + (void)file; + (void)ptr; + (void)dir; + return 0; +} + +int _open(char *path, int flags, ...) +{ + (void)path; + (void)flags; + /* Pretend like we always fail */ + return -1; +} + +int _wait(int *status) +{ + (void)status; + errno = ECHILD; + return -1; +} + +int _unlink(char *name) +{ + (void)name; + errno = ENOENT; + return -1; +} + +clock_t _times(struct tms *buf) +{ + (void)buf; + return -1; +} + +int _stat(const char *file, struct stat *st) +{ + (void)file; + st->st_mode = S_IFCHR; + return 0; +} + +int _link(char *old, char *new) +{ + (void)old; + (void)new; + errno = EMLINK; + return -1; +} + +int _fork(void) +{ + errno = EAGAIN; + return -1; +} + +int _execve(char *name, char **argv, char **env) +{ + (void)name; + (void)argv; + (void)env; + errno = ENOMEM; + return -1; +} + +// --- Picolibc Specific Section --- +#if defined(__PICOLIBC__) + +/** + * @brief Picolibc helper function to output a character to a FILE stream. + * This redirects the output to the low-level __io_putchar function. + * @param c Character to write. + * @param file FILE stream pointer (ignored). + * @retval int The character written. + */ +static int starm_putc(char c, FILE *file) +{ + (void)file; + __io_putchar(c); + return c; +} + +/** + * @brief Picolibc helper function to input a character from a FILE stream. + * This redirects the input from the low-level __io_getchar function. + * @param file FILE stream pointer (ignored). + * @retval int The character read, cast to an unsigned char then int. + */ +static int starm_getc(FILE *file) +{ + unsigned char c; + (void)file; + c = __io_getchar(); + return c; +} + +// Define and initialize the standard I/O streams for Picolibc. +// FDEV_SETUP_STREAM connects the starm_putc and starm_getc helper functions to a FILE structure. +// _FDEV_SETUP_RW indicates the stream is for reading and writing. +static FILE __stdio = FDEV_SETUP_STREAM(starm_putc, starm_getc, NULL, _FDEV_SETUP_RW); + +// Assign the standard stream pointers (stdin, stdout, stderr) to the initialized stream. +// Picolibc uses these pointers for standard I/O operations (printf, scanf, etc.). +FILE *const stdin = &__stdio; +__strong_reference(stdin, stdout); +__strong_reference(stdin, stderr); + +// Create strong aliases mapping standard C library function names (without underscore) +// to the implemented system call stubs (with underscore). Picolibc uses these +// standard names internally, so this linking is required. +__strong_reference(_read, read); +__strong_reference(_write, write); +__strong_reference(_times, times); +__strong_reference(_execve, execve); +__strong_reference(_fork, fork); +__strong_reference(_link, link); +__strong_reference(_unlink, unlink); +__strong_reference(_stat, stat); +__strong_reference(_wait, wait); +__strong_reference(_open, open); +__strong_reference(_close, close); +__strong_reference(_lseek, lseek); +__strong_reference(_isatty, isatty); +__strong_reference(_fstat, fstat); +__strong_reference(_exit, exit); +__strong_reference(_kill, kill); +__strong_reference(_getpid, getpid); + +#endif //__PICOLIBC__ diff --git a/ECU/Core/Src/sysmem.c b/ECU/Core/Src/sysmem.c new file mode 100644 index 000000000..3a092d114 --- /dev/null +++ b/ECU/Core/Src/sysmem.c @@ -0,0 +1,85 @@ +/** + ****************************************************************************** + * @file sysmem.c + * @author Generated by STM32CubeMX + * @brief System Memory calls file + * + * For more information about which C functions + * need which of these lowlevel functions + * please consult the Newlib or Picolibc libc manual + ****************************************************************************** + * @attention + * + * Copyright (c) 2025 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +/* Includes */ +#include +#include +#include + +/** + * Pointer to the current high watermark of the heap usage + */ +static uint8_t *__sbrk_heap_end = NULL; + +/** + * @brief _sbrk() allocates memory to the newlib heap and is used by malloc + * and others from the C library + * + * @verbatim + * ############################################################################ + * # .data # .bss # newlib heap # MSP stack # + * # # # # Reserved by _Min_Stack_Size # + * ############################################################################ + * ^-- RAM start ^-- _end _estack, RAM end --^ + * @endverbatim + * + * This implementation starts allocating at the '_end' linker symbol + * The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack + * The implementation considers '_estack' linker symbol to be RAM end + * NOTE: If the MSP stack, at any point during execution, grows larger than the + * reserved size, please increase the '_Min_Stack_Size'. + * + * @param incr Memory size + * @return Pointer to allocated memory + */ +void *_sbrk(ptrdiff_t incr) +{ + extern uint8_t _end; /* Symbol defined in the linker script */ + extern uint8_t _estack; /* Symbol defined in the linker script */ + extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */ + const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size; + const uint8_t *max_heap = (uint8_t *)stack_limit; + uint8_t *prev_heap_end; + + /* Initialize heap end at first call */ + if (NULL == __sbrk_heap_end) { + __sbrk_heap_end = &_end; + } + + /* Protect heap from growing into the reserved MSP stack */ + if (__sbrk_heap_end + incr > max_heap) { + errno = ENOMEM; + return (void *)-1; + } + + prev_heap_end = __sbrk_heap_end; + __sbrk_heap_end += incr; + + return (void *)prev_heap_end; +} + +#if defined(__PICOLIBC__) +// Picolibc expects syscalls without the leading underscore. +// This creates a strong alias so that +// calls to `sbrk()` are resolved to our `_sbrk()` implementation. +__strong_reference(_sbrk, sbrk); +#endif diff --git a/ECU/Core/Src/system_stm32g4xx.c b/ECU/Core/Src/system_stm32g4xx.c new file mode 100644 index 000000000..2cd914e7b --- /dev/null +++ b/ECU/Core/Src/system_stm32g4xx.c @@ -0,0 +1,287 @@ +/** + ****************************************************************************** + * @file system_stm32g4xx.c + * @author MCD Application Team + * @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File + * + * This file provides two functions and one global variable to be called from + * user application: + * - SystemInit(): This function is called at startup just after reset and + * before branch to main program. This call is made inside + * the "startup_stm32g4xx.s" file. + * + * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used + * by the user application to setup the SysTick + * timer or configure other parameters. + * + * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must + * be called whenever the core clock is changed + * during program execution. + * + * After each device reset the HSI (16 MHz) is used as system clock source. + * Then SystemInit() function is called, in "startup_stm32g4xx.s" file, to + * configure the system clock before to branch to main program. + * + * This file configures the system clock as follows: + *============================================================================= + *----------------------------------------------------------------------------- + * System Clock source | HSI + *----------------------------------------------------------------------------- + * SYSCLK(Hz) | 16000000 + *----------------------------------------------------------------------------- + * HCLK(Hz) | 16000000 + *----------------------------------------------------------------------------- + * AHB Prescaler | 1 + *----------------------------------------------------------------------------- + * APB1 Prescaler | 1 + *----------------------------------------------------------------------------- + * APB2 Prescaler | 1 + *----------------------------------------------------------------------------- + * PLL_M | 1 + *----------------------------------------------------------------------------- + * PLL_N | 16 + *----------------------------------------------------------------------------- + * PLL_P | 7 + *----------------------------------------------------------------------------- + * PLL_Q | 2 + *----------------------------------------------------------------------------- + * PLL_R | 2 + *----------------------------------------------------------------------------- + * Require 48MHz for RNG | Disabled + *----------------------------------------------------------------------------- + *============================================================================= + ****************************************************************************** + * @attention + * + * Copyright (c) 2019 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +/** @addtogroup CMSIS + * @{ + */ + +/** @addtogroup stm32g4xx_system + * @{ + */ + +/** @addtogroup STM32G4xx_System_Private_Includes + * @{ + */ + +#include "stm32g4xx.h" + +#if !defined (HSE_VALUE) + #define HSE_VALUE 24000000U /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined (HSI_VALUE) + #define HSI_VALUE 16000000U /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ + +/** + * @} + */ + +/** @addtogroup STM32G4xx_System_Private_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +/** @addtogroup STM32G4xx_System_Private_Defines + * @{ + */ + +/************************* Miscellaneous Configuration ************************/ +/* Note: Following vector table addresses must be defined in line with linker + configuration. */ +/*!< Uncomment the following line if you need to relocate the vector table + anywhere in Flash or Sram, else the vector table is kept at the automatic + remap of boot address selected */ +/* #define USER_VECT_TAB_ADDRESS */ + +#if defined(USER_VECT_TAB_ADDRESS) +/*!< Uncomment the following line if you need to relocate your vector Table + in Sram else user remap will be done in Flash. */ +/* #define VECT_TAB_SRAM */ +#if defined(VECT_TAB_SRAM) +#define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field. + This value must be a multiple of 0x200. */ +#else +#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field. + This value must be a multiple of 0x200. */ +#endif /* VECT_TAB_SRAM */ + +#if !defined(VECT_TAB_OFFSET) +#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table offset field. + This value must be a multiple of 0x200. */ +#endif /* VECT_TAB_OFFSET */ + +#endif /* USER_VECT_TAB_ADDRESS */ +/******************************************************************************/ +/** + * @} + */ + +/** @addtogroup STM32G4xx_System_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup STM32G4xx_System_Private_Variables + * @{ + */ + /* The SystemCoreClock variable is updated in three ways: + 1) by calling CMSIS function SystemCoreClockUpdate() + 2) by calling HAL API function HAL_RCC_GetHCLKFreq() + 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency + Note: If you use this function to configure the system clock; then there + is no need to call the 2 first functions listed above, since SystemCoreClock + variable is updated automatically. + */ + uint32_t SystemCoreClock = HSI_VALUE; + + const uint8_t AHBPrescTable[16] = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U}; + const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U}; + +/** + * @} + */ + +/** @addtogroup STM32G4xx_System_Private_FunctionPrototypes + * @{ + */ + +/** + * @} + */ + +/** @addtogroup STM32G4xx_System_Private_Functions + * @{ + */ + +/** + * @brief Setup the microcontroller system. + * @param None + * @retval None + */ + +void SystemInit(void) +{ + /* FPU settings ------------------------------------------------------------*/ + #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) + SCB->CPACR |= ((3UL << (10*2))|(3UL << (11*2))); /* set CP10 and CP11 Full Access */ + #endif + + /* Configure the Vector Table location add offset address ------------------*/ +#if defined(USER_VECT_TAB_ADDRESS) + SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ +#endif /* USER_VECT_TAB_ADDRESS */ +} + +/** + * @brief Update SystemCoreClock variable according to Clock Register Values. + * The SystemCoreClock variable contains the core clock (HCLK), it can + * be used by the user application to setup the SysTick timer or configure + * other parameters. + * + * @note Each time the core clock (HCLK) changes, this function must be called + * to update SystemCoreClock variable value. Otherwise, any configuration + * based on this variable will be incorrect. + * + * @note - The system frequency computed by this function is not the real + * frequency in the chip. It is calculated based on the predefined + * constant and the selected clock source: + * + * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**) + * + * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***) + * + * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(***) + * or HSI_VALUE(*) multiplied/divided by the PLL factors. + * + * (**) HSI_VALUE is a constant defined in stm32g4xx_hal.h file (default value + * 16 MHz) but the real value may vary depending on the variations + * in voltage and temperature. + * + * (***) HSE_VALUE is a constant defined in stm32g4xx_hal.h file (default value + * 24 MHz), user has to ensure that HSE_VALUE is same as the real + * frequency of the crystal used. Otherwise, this function may + * have wrong result. + * + * - The result of this function could be not correct when using fractional + * value for HSE crystal. + * + * @param None + * @retval None + */ +void SystemCoreClockUpdate(void) +{ + uint32_t tmp, pllvco, pllr, pllsource, pllm; + + /* Get SYSCLK source -------------------------------------------------------*/ + switch (RCC->CFGR & RCC_CFGR_SWS) + { + case 0x04: /* HSI used as system clock source */ + SystemCoreClock = HSI_VALUE; + break; + + case 0x08: /* HSE used as system clock source */ + SystemCoreClock = HSE_VALUE; + break; + + case 0x0C: /* PLL used as system clock source */ + /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN + SYSCLK = PLL_VCO / PLLR + */ + pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC); + pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> 4) + 1U ; + if (pllsource == 0x02UL) /* HSI used as PLL clock source */ + { + pllvco = (HSI_VALUE / pllm); + } + else /* HSE used as PLL clock source */ + { + pllvco = (HSE_VALUE / pllm); + } + pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 8); + pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 25) + 1U) * 2U; + SystemCoreClock = pllvco/pllr; + break; + + default: + break; + } + /* Compute HCLK clock frequency --------------------------------------------*/ + /* Get HCLK prescaler */ + tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; + /* HCLK clock frequency */ + SystemCoreClock >>= tmp; +} + + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + + diff --git a/ECU/Core/Src/tim.c b/ECU/Core/Src/tim.c new file mode 100644 index 000000000..8211f4f86 --- /dev/null +++ b/ECU/Core/Src/tim.c @@ -0,0 +1,105 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file tim.c + * @brief This file provides code for the configuration + * of the TIM instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "tim.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +TIM_HandleTypeDef htim6; + +/* TIM6 init function */ +void MX_TIM6_Init(void) +{ + + /* USER CODE BEGIN TIM6_Init 0 */ + + /* USER CODE END TIM6_Init 0 */ + + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM6_Init 1 */ + + /* USER CODE END TIM6_Init 1 */ + htim6.Instance = TIM6; + htim6.Init.Prescaler = 159; + htim6.Init.CounterMode = TIM_COUNTERMODE_UP; + htim6.Init.Period = 624; + htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim6) != HAL_OK) + { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN TIM6_Init 2 */ + + /* USER CODE END TIM6_Init 2 */ + +} + +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) +{ + + if(tim_baseHandle->Instance==TIM6) + { + /* USER CODE BEGIN TIM6_MspInit 0 */ + + /* USER CODE END TIM6_MspInit 0 */ + /* TIM6 clock enable */ + __HAL_RCC_TIM6_CLK_ENABLE(); + + /* TIM6 interrupt Init */ + HAL_NVIC_SetPriority(TIM6_DAC_IRQn, 15, 0); + HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn); + /* USER CODE BEGIN TIM6_MspInit 1 */ + + /* USER CODE END TIM6_MspInit 1 */ + } +} + +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) +{ + + if(tim_baseHandle->Instance==TIM6) + { + /* USER CODE BEGIN TIM6_MspDeInit 0 */ + + /* USER CODE END TIM6_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM6_CLK_DISABLE(); + + /* TIM6 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM6_DAC_IRQn); + /* USER CODE BEGIN TIM6_MspDeInit 1 */ + + /* USER CODE END TIM6_MspDeInit 1 */ + } +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ + diff --git a/ECU/Core/Src/usart.c b/ECU/Core/Src/usart.c new file mode 100644 index 000000000..dc5896cb0 --- /dev/null +++ b/ECU/Core/Src/usart.c @@ -0,0 +1,141 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file usart.c + * @brief This file provides code for the configuration + * of the USART instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "usart.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +UART_HandleTypeDef huart3; + +/* USART3 init function */ + +void MX_USART3_UART_Init(void) +{ + + /* USER CODE BEGIN USART3_Init 0 */ + + /* USER CODE END USART3_Init 0 */ + + /* USER CODE BEGIN USART3_Init 1 */ + + /* USER CODE END USART3_Init 1 */ + huart3.Instance = USART3; + huart3.Init.BaudRate = 115200; + huart3.Init.WordLength = UART_WORDLENGTH_8B; + huart3.Init.StopBits = UART_STOPBITS_1; + huart3.Init.Parity = UART_PARITY_NONE; + huart3.Init.Mode = UART_MODE_TX_RX; + huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart3.Init.OverSampling = UART_OVERSAMPLING_16; + huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + huart3.Init.ClockPrescaler = UART_PRESCALER_DIV1; + huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(&huart3) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&huart3, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&huart3, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&huart3) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN USART3_Init 2 */ + + /* USER CODE END USART3_Init 2 */ + +} + +void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) +{ + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; + if(uartHandle->Instance==USART3) + { + /* USER CODE BEGIN USART3_MspInit 0 */ + + /* USER CODE END USART3_MspInit 0 */ + + /** Initializes the peripherals clocks + */ + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART3; + PeriphClkInit.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) + { + Error_Handler(); + } + + /* USART3 clock enable */ + __HAL_RCC_USART3_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**USART3 GPIO Configuration + PC10 ------> USART3_TX + PC11 ------> USART3_RX + */ + GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF7_USART3; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /* USER CODE BEGIN USART3_MspInit 1 */ + + /* USER CODE END USART3_MspInit 1 */ + } +} + +void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) +{ + + if(uartHandle->Instance==USART3) + { + /* USER CODE BEGIN USART3_MspDeInit 0 */ + + /* USER CODE END USART3_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_USART3_CLK_DISABLE(); + + /**USART3 GPIO Configuration + PC10 ------> USART3_TX + PC11 ------> USART3_RX + */ + HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11); + + /* USER CODE BEGIN USART3_MspDeInit 1 */ + + /* USER CODE END USART3_MspDeInit 1 */ + } +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ + diff --git a/ECU/ECU.ioc b/ECU/ECU.ioc new file mode 100644 index 000000000..8dd7134d4 --- /dev/null +++ b/ECU/ECU.ioc @@ -0,0 +1,443 @@ +#MicroXplorer Configuration settings - do not modify +ADC1.Channel-10\#ChannelRegularConversion=ADC_CHANNEL_9 +ADC1.Channel-11\#ChannelRegularConversion=ADC_CHANNEL_7 +ADC1.Channel-12\#ChannelRegularConversion=ADC_CHANNEL_4 +ADC1.Channel-13\#ChannelRegularConversion=ADC_CHANNEL_15 +ADC1.Channel-14\#ChannelRegularConversion=ADC_CHANNEL_5 +ADC1.ClockPrescaler=ADC_CLOCK_ASYNC_DIV8 +ADC1.CommonPathInternal=null|null|null|null +ADC1.ContinuousConvMode=ENABLE +ADC1.DMAContinuousRequests=ENABLE +ADC1.IPParameters=Rank-10\#ChannelRegularConversion,Channel-10\#ChannelRegularConversion,SamplingTime-10\#ChannelRegularConversion,OffsetNumber-10\#ChannelRegularConversion,NbrOfConversionFlag,ClockPrescaler,Rank-11\#ChannelRegularConversion,Channel-11\#ChannelRegularConversion,SamplingTime-11\#ChannelRegularConversion,OffsetNumber-11\#ChannelRegularConversion,Rank-12\#ChannelRegularConversion,Channel-12\#ChannelRegularConversion,SamplingTime-12\#ChannelRegularConversion,OffsetNumber-12\#ChannelRegularConversion,Rank-13\#ChannelRegularConversion,Channel-13\#ChannelRegularConversion,SamplingTime-13\#ChannelRegularConversion,OffsetNumber-13\#ChannelRegularConversion,Rank-14\#ChannelRegularConversion,Channel-14\#ChannelRegularConversion,SamplingTime-14\#ChannelRegularConversion,OffsetNumber-14\#ChannelRegularConversion,NbrOfConversion,ContinuousConvMode,DMAContinuousRequests,OversamplingMode,RightBitShift,Ratio,master,CommonPathInternal +ADC1.NbrOfConversion=5 +ADC1.NbrOfConversionFlag=1 +ADC1.OffsetNumber-10\#ChannelRegularConversion=ADC_OFFSET_NONE +ADC1.OffsetNumber-11\#ChannelRegularConversion=ADC_OFFSET_NONE +ADC1.OffsetNumber-12\#ChannelRegularConversion=ADC_OFFSET_NONE +ADC1.OffsetNumber-13\#ChannelRegularConversion=ADC_OFFSET_NONE +ADC1.OffsetNumber-14\#ChannelRegularConversion=ADC_OFFSET_NONE +ADC1.OversamplingMode=ENABLE +ADC1.Rank-10\#ChannelRegularConversion=1 +ADC1.Rank-11\#ChannelRegularConversion=2 +ADC1.Rank-12\#ChannelRegularConversion=3 +ADC1.Rank-13\#ChannelRegularConversion=4 +ADC1.Rank-14\#ChannelRegularConversion=5 +ADC1.Ratio=ADC_OVERSAMPLING_RATIO_256 +ADC1.RightBitShift=ADC_RIGHTBITSHIFT_8 +ADC1.SamplingTime-10\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 +ADC1.SamplingTime-11\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 +ADC1.SamplingTime-12\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 +ADC1.SamplingTime-13\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 +ADC1.SamplingTime-14\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 +ADC1.master=1 +ADC2.Channel-10\#ChannelRegularConversion=ADC_CHANNEL_10 +ADC2.Channel-11\#ChannelRegularConversion=ADC_CHANNEL_4 +ADC2.Channel-7\#ChannelRegularConversion=ADC_CHANNEL_17 +ADC2.Channel-8\#ChannelRegularConversion=ADC_CHANNEL_12 +ADC2.Channel-9\#ChannelRegularConversion=ADC_CHANNEL_15 +ADC2.ClockPrescaler=ADC_CLOCK_ASYNC_DIV8 +ADC2.CommonPathInternal=null|null|null|null +ADC2.ContinuousConvMode=ENABLE +ADC2.DMAContinuousRequests=ENABLE +ADC2.IPParameters=Rank-7\#ChannelRegularConversion,Channel-7\#ChannelRegularConversion,SamplingTime-7\#ChannelRegularConversion,OffsetNumber-7\#ChannelRegularConversion,NbrOfConversionFlag,ClockPrescaler,Rank-8\#ChannelRegularConversion,Channel-8\#ChannelRegularConversion,SamplingTime-8\#ChannelRegularConversion,OffsetNumber-8\#ChannelRegularConversion,Rank-9\#ChannelRegularConversion,Channel-9\#ChannelRegularConversion,SamplingTime-9\#ChannelRegularConversion,OffsetNumber-9\#ChannelRegularConversion,Rank-10\#ChannelRegularConversion,Channel-10\#ChannelRegularConversion,SamplingTime-10\#ChannelRegularConversion,OffsetNumber-10\#ChannelRegularConversion,Rank-11\#ChannelRegularConversion,Channel-11\#ChannelRegularConversion,SamplingTime-11\#ChannelRegularConversion,OffsetNumber-11\#ChannelRegularConversion,NbrOfConversion,ContinuousConvMode,OversamplingMode,RightBitShift,Ratio,DMAContinuousRequests,CommonPathInternal +ADC2.NbrOfConversion=5 +ADC2.NbrOfConversionFlag=1 +ADC2.OffsetNumber-10\#ChannelRegularConversion=ADC_OFFSET_NONE +ADC2.OffsetNumber-11\#ChannelRegularConversion=ADC_OFFSET_NONE +ADC2.OffsetNumber-7\#ChannelRegularConversion=ADC_OFFSET_NONE +ADC2.OffsetNumber-8\#ChannelRegularConversion=ADC_OFFSET_NONE +ADC2.OffsetNumber-9\#ChannelRegularConversion=ADC_OFFSET_NONE +ADC2.OversamplingMode=ENABLE +ADC2.Rank-10\#ChannelRegularConversion=4 +ADC2.Rank-11\#ChannelRegularConversion=5 +ADC2.Rank-7\#ChannelRegularConversion=1 +ADC2.Rank-8\#ChannelRegularConversion=2 +ADC2.Rank-9\#ChannelRegularConversion=3 +ADC2.Ratio=ADC_OVERSAMPLING_RATIO_256 +ADC2.RightBitShift=ADC_RIGHTBITSHIFT_8 +ADC2.SamplingTime-10\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 +ADC2.SamplingTime-11\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 +ADC2.SamplingTime-7\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 +ADC2.SamplingTime-8\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 +ADC2.SamplingTime-9\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 +ADC5.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_2 +ADC5.CommonPathInternal=null|null|null|null +ADC5.ContinuousConvMode=ENABLE +ADC5.DMAContinuousRequests=ENABLE +ADC5.IPParameters=Rank-0\#ChannelRegularConversion,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,OffsetNumber-0\#ChannelRegularConversion,NbrOfConversionFlag,DMAContinuousRequests,ContinuousConvMode,OversamplingMode,RightBitShift,Ratio,CommonPathInternal +ADC5.NbrOfConversionFlag=1 +ADC5.OffsetNumber-0\#ChannelRegularConversion=ADC_OFFSET_NONE +ADC5.OversamplingMode=ENABLE +ADC5.Rank-0\#ChannelRegularConversion=1 +ADC5.Ratio=ADC_OVERSAMPLING_RATIO_256 +ADC5.RightBitShift=ADC_RIGHTBITSHIFT_8 +ADC5.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 +CAD.formats= +CAD.pinconfig= +CAD.provider= +Dma.ADC1.0.Direction=DMA_PERIPH_TO_MEMORY +Dma.ADC1.0.EventEnable=DISABLE +Dma.ADC1.0.Instance=DMA1_Channel1 +Dma.ADC1.0.MemDataAlignment=DMA_MDATAALIGN_HALFWORD +Dma.ADC1.0.MemInc=DMA_MINC_ENABLE +Dma.ADC1.0.Mode=DMA_CIRCULAR +Dma.ADC1.0.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD +Dma.ADC1.0.PeriphInc=DMA_PINC_DISABLE +Dma.ADC1.0.Polarity=HAL_DMAMUX_REQ_GEN_RISING +Dma.ADC1.0.Priority=DMA_PRIORITY_LOW +Dma.ADC1.0.RequestNumber=1 +Dma.ADC1.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,SignalID,Polarity,RequestNumber,SyncSignalID,SyncPolarity,SyncEnable,EventEnable,SyncRequestNumber +Dma.ADC1.0.SignalID=NONE +Dma.ADC1.0.SyncEnable=ENABLE +Dma.ADC1.0.SyncPolarity=HAL_DMAMUX_SYNC_RISING +Dma.ADC1.0.SyncRequestNumber=1 +Dma.ADC1.0.SyncSignalID=NONE +Dma.ADC2.1.Direction=DMA_PERIPH_TO_MEMORY +Dma.ADC2.1.EventEnable=DISABLE +Dma.ADC2.1.Instance=DMA2_Channel1 +Dma.ADC2.1.MemDataAlignment=DMA_MDATAALIGN_HALFWORD +Dma.ADC2.1.MemInc=DMA_MINC_ENABLE +Dma.ADC2.1.Mode=DMA_CIRCULAR +Dma.ADC2.1.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD +Dma.ADC2.1.PeriphInc=DMA_PINC_DISABLE +Dma.ADC2.1.Polarity=HAL_DMAMUX_REQ_GEN_RISING +Dma.ADC2.1.Priority=DMA_PRIORITY_LOW +Dma.ADC2.1.RequestNumber=1 +Dma.ADC2.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,SignalID,Polarity,RequestNumber,SyncSignalID,SyncPolarity,SyncEnable,EventEnable,SyncRequestNumber +Dma.ADC2.1.SignalID=NONE +Dma.ADC2.1.SyncEnable=DISABLE +Dma.ADC2.1.SyncPolarity=HAL_DMAMUX_SYNC_NO_EVENT +Dma.ADC2.1.SyncRequestNumber=1 +Dma.ADC2.1.SyncSignalID=NONE +Dma.ADC5.2.Direction=DMA_PERIPH_TO_MEMORY +Dma.ADC5.2.EventEnable=DISABLE +Dma.ADC5.2.Instance=DMA1_Channel2 +Dma.ADC5.2.MemDataAlignment=DMA_MDATAALIGN_HALFWORD +Dma.ADC5.2.MemInc=DMA_MINC_ENABLE +Dma.ADC5.2.Mode=DMA_CIRCULAR +Dma.ADC5.2.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD +Dma.ADC5.2.PeriphInc=DMA_PINC_DISABLE +Dma.ADC5.2.Polarity=HAL_DMAMUX_REQ_GEN_RISING +Dma.ADC5.2.Priority=DMA_PRIORITY_LOW +Dma.ADC5.2.RequestNumber=1 +Dma.ADC5.2.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,SignalID,Polarity,RequestNumber,SyncSignalID,SyncPolarity,SyncEnable,EventEnable,SyncRequestNumber +Dma.ADC5.2.SignalID=NONE +Dma.ADC5.2.SyncEnable=DISABLE +Dma.ADC5.2.SyncPolarity=HAL_DMAMUX_SYNC_NO_EVENT +Dma.ADC5.2.SyncRequestNumber=1 +Dma.ADC5.2.SyncSignalID=NONE +Dma.Request0=ADC1 +Dma.Request1=ADC2 +Dma.Request2=ADC5 +Dma.RequestsNb=3 +FDCAN1.AutoRetransmission=ENABLE +FDCAN1.CalculateBaudRateNominal=1000000 +FDCAN1.CalculateTimeBitNominal=1000 +FDCAN1.CalculateTimeQuantumNominal=6.25 +FDCAN1.DataSyncJumpWidth=16 +FDCAN1.DataTimeSeg1=9 +FDCAN1.DataTimeSeg2=10 +FDCAN1.ExtFiltersNbr=3 +FDCAN1.IPParameters=CalculateTimeQuantumNominal,CalculateTimeBitNominal,CalculateBaudRateNominal,AutoRetransmission,ProtocolException,NominalPrescaler,NominalSyncJumpWidth,NominalTimeSeg1,NominalTimeSeg2,DataSyncJumpWidth,DataTimeSeg1,DataTimeSeg2,ExtFiltersNbr +FDCAN1.NominalPrescaler=1 +FDCAN1.NominalSyncJumpWidth=16 +FDCAN1.NominalTimeSeg1=119 +FDCAN1.NominalTimeSeg2=40 +FDCAN1.ProtocolException=ENABLE +FDCAN2.AutoRetransmission=ENABLE +FDCAN2.CalculateBaudRateNominal=1000000 +FDCAN2.CalculateTimeBitNominal=1000 +FDCAN2.CalculateTimeQuantumNominal=6.25 +FDCAN2.DataSyncJumpWidth=2 +FDCAN2.DataTimeSeg1=14 +FDCAN2.DataTimeSeg2=5 +FDCAN2.ExtFiltersNbr=2 +FDCAN2.FrameFormat=FDCAN_FRAME_FD_BRS +FDCAN2.IPParameters=CalculateTimeQuantumNominal,CalculateTimeBitNominal,CalculateBaudRateNominal,FrameFormat,AutoRetransmission,ProtocolException,NominalPrescaler,NominalSyncJumpWidth,NominalTimeSeg1,NominalTimeSeg2,DataSyncJumpWidth,DataTimeSeg1,DataTimeSeg2,ExtFiltersNbr +FDCAN2.NominalPrescaler=1 +FDCAN2.NominalSyncJumpWidth=16 +FDCAN2.NominalTimeSeg1=119 +FDCAN2.NominalTimeSeg2=40 +FDCAN2.ProtocolException=ENABLE +File.Version=6 +GPIO.groupedBy=Group By Peripherals +KeepUserPlacement=false +Mcu.CPN=STM32G474RET3 +Mcu.Family=STM32G4 +Mcu.IP0=ADC1 +Mcu.IP1=ADC2 +Mcu.IP10=USART3 +Mcu.IP2=ADC5 +Mcu.IP3=DMA +Mcu.IP4=FDCAN1 +Mcu.IP5=FDCAN2 +Mcu.IP6=NVIC +Mcu.IP7=RCC +Mcu.IP8=SYS +Mcu.IP9=TIM6 +Mcu.IPNb=11 +Mcu.Name=STM32G474R(B-C-E)Tx +Mcu.Package=LQFP64 +Mcu.Pin0=PC14-OSC32_IN +Mcu.Pin1=PF1-OSC_OUT +Mcu.Pin10=PB10 +Mcu.Pin11=PB11 +Mcu.Pin12=PB12 +Mcu.Pin13=PB13 +Mcu.Pin14=PB14 +Mcu.Pin15=PB15 +Mcu.Pin16=PA9 +Mcu.Pin17=PA11 +Mcu.Pin18=PA12 +Mcu.Pin19=PA13 +Mcu.Pin2=PG10-NRST +Mcu.Pin20=PA14 +Mcu.Pin21=PA15 +Mcu.Pin22=PC10 +Mcu.Pin23=PC11 +Mcu.Pin24=PD2 +Mcu.Pin25=PB3 +Mcu.Pin26=PB4 +Mcu.Pin27=PB7 +Mcu.Pin28=VP_SYS_VS_Systick +Mcu.Pin29=VP_SYS_VS_DBSignals +Mcu.Pin3=PC1 +Mcu.Pin30=VP_TIM6_VS_ClockSourceINT +Mcu.Pin4=PC3 +Mcu.Pin5=PA3 +Mcu.Pin6=PA4 +Mcu.Pin7=PA7 +Mcu.Pin8=PB0 +Mcu.Pin9=PB2 +Mcu.PinsNb=31 +Mcu.ThirdPartyNb=0 +Mcu.UserConstants= +Mcu.UserName=STM32G474RETx +MxCube.Version=6.18.1 +MxDb.Version=DB.6.0.181 +NVIC.ADC1_2_IRQn=true\:15\:0\:true\:false\:true\:true\:true\:true +NVIC.ADC5_IRQn=true\:15\:0\:true\:false\:true\:true\:true\:true +NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.DMA1_Channel1_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true +NVIC.DMA1_Channel2_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true +NVIC.DMA2_Channel1_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true +NVIC.DMAMUX_OVR_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true +NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.FDCAN1_IT0_IRQn=true\:15\:0\:true\:false\:true\:true\:true\:true +NVIC.FDCAN1_IT1_IRQn=true\:15\:0\:true\:false\:true\:true\:true\:true +NVIC.FDCAN2_IT0_IRQn=true\:15\:0\:true\:false\:true\:true\:true\:true +NVIC.FDCAN2_IT1_IRQn=true\:15\:0\:true\:false\:true\:true\:true\:true +NVIC.ForceEnableDMAVector=true +NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 +NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false +NVIC.TIM6_DAC_IRQn=true\:15\:0\:true\:false\:true\:true\:true\:true +NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +PA11.Locked=true +PA11.Mode=FDCAN_Activate +PA11.Signal=FDCAN1_RX +PA12.Locked=true +PA12.Mode=FDCAN_Activate +PA12.Signal=FDCAN1_TX +PA13.Locked=true +PA13.Mode=Trace_Asynchronous_SW +PA13.Signal=SYS_JTMS-SWDIO +PA14.Locked=true +PA14.Mode=Trace_Asynchronous_SW +PA14.Signal=SYS_JTCK-SWCLK +PA15.GPIOParameters=GPIO_Label +PA15.GPIO_Label=LED_TEST +PA15.Locked=true +PA15.Signal=GPIO_Output +PA3.GPIOParameters=GPIO_Label +PA3.GPIO_Label=STEERING_ANGLE +PA3.Locked=true +PA3.Mode=IN4-Single-Ended +PA3.Signal=ADC1_IN4 +PA4.GPIOParameters=GPIO_Label +PA4.GPIO_Label=APPS2_SIGNAL +PA4.Locked=true +PA4.Mode=IN17-Single-Ended +PA4.Signal=ADC2_IN17 +PA7.GPIOParameters=GPIO_Label +PA7.GPIO_Label=SPARE_2_SIGNAL +PA7.Locked=true +PA7.Mode=IN4-Single-Ended +PA7.Signal=ADC2_IN4 +PA9.GPIOParameters=GPIO_Label +PA9.GPIO_Label=IMD_SENSE +PA9.Locked=true +PA9.Mode=IN2-Single-Ended +PA9.Signal=ADC5_IN2 +PB0.GPIOParameters=GPIO_Label +PB0.GPIO_Label=BSPD_SIGNAL +PB0.Locked=true +PB0.Mode=IN15-Single-Ended +PB0.Signal=ADC1_IN15 +PB10.Locked=true +PB10.Signal=GPIO_Output +PB11.GPIOParameters=GPIO_Label +PB11.GPIO_Label=SOFTWARE_OK_CONTROL +PB11.Locked=true +PB11.Signal=GPIO_Output +PB12.Locked=true +PB12.Mode=FDCAN_Activate +PB12.Signal=FDCAN2_RX +PB13.Locked=true +PB13.Mode=FDCAN_Activate +PB13.Signal=FDCAN2_TX +PB14.GPIOParameters=GPIO_Label +PB14.GPIO_Label=BSPD_SENSE +PB14.Locked=true +PB14.Mode=IN5-Single-Ended +PB14.Signal=ADC1_IN5 +PB15.GPIOParameters=GPIO_Label +PB15.GPIO_Label=AMS_SENSE +PB15.Locked=true +PB15.Mode=IN15-Single-Ended +PB15.Signal=ADC2_IN15 +PB2.GPIOParameters=GPIO_Label +PB2.GPIO_Label=BSE_SIGNAL +PB2.Locked=true +PB2.Mode=IN12-Single-Ended +PB2.Signal=ADC2_IN12 +PB3.Locked=true +PB3.Mode=Trace_Asynchronous_SW +PB3.Signal=SYS_JTDO-SWO +PB4.GPIOParameters=GPIO_Label +PB4.GPIO_Label=TSSI_R_CONTROL +PB4.Locked=true +PB4.Signal=GPIO_Output +PB7.GPIOParameters=GPIO_Label +PB7.GPIO_Label=RTD_CONTROL +PB7.Locked=true +PB7.Signal=GPIO_Output +PC1.GPIOParameters=GPIO_Label +PC1.GPIO_Label=BRAKE_SIGNAL +PC1.Locked=true +PC1.Mode=IN7-Single-Ended +PC1.Signal=ADC1_IN7 +PC10.Locked=true +PC10.Mode=Asynchronous +PC10.Signal=USART3_TX +PC11.Locked=true +PC11.Mode=Asynchronous +PC11.Signal=USART3_RX +PC14-OSC32_IN.GPIOParameters=GPIO_Label +PC14-OSC32_IN.GPIO_Label=BRAKE_LIGHT +PC14-OSC32_IN.Locked=true +PC14-OSC32_IN.Signal=GPIO_Output +PC3.GPIOParameters=GPIO_Label +PC3.GPIO_Label=APPS1_SIGNAL +PC3.Locked=true +PC3.Mode=IN9-Single-Ended +PC3.Signal=ADC1_IN9 +PD2.GPIOParameters=GPIO_Label +PD2.GPIO_Label=TSSI_G_CONTROL +PD2.Locked=true +PD2.Signal=GPIO_Output +PF1-OSC_OUT.GPIOParameters=GPIO_Label +PF1-OSC_OUT.GPIO_Label=SPARE_1_SIGNAL +PF1-OSC_OUT.Locked=true +PF1-OSC_OUT.Mode=IN10-Single-Ended +PF1-OSC_OUT.Signal=ADC2_IN10 +PG10-NRST.Locked=true +PG10-NRST.Signal=EVENTOUT +PinOutPanel.RotationAngle=0 +ProjectManager.AskForMigrate=true +ProjectManager.BackupPrevious=false +ProjectManager.CompilerLinker=GCC +ProjectManager.CompilerOptimize=6 +ProjectManager.ComputerToolchain=false +ProjectManager.CoupleFile=true +ProjectManager.CustomerFirmwarePackage= +ProjectManager.DefaultFWLocation=true +ProjectManager.DeletePrevious=true +ProjectManager.DeviceId=STM32G474RETx +ProjectManager.FirmwarePackage=STM32Cube FW_G4 V1.6.3 +ProjectManager.FreePins=true +ProjectManager.FreePinsContext= +ProjectManager.HalAssertFull=true +ProjectManager.HeapSize=0x200 +ProjectManager.KeepUserCode=true +ProjectManager.LastFirmware=true +ProjectManager.LibraryCopy=2 +ProjectManager.MainLocation=Core/Src +ProjectManager.NoMain=false +ProjectManager.PreviousToolchain= +ProjectManager.ProjectBuild=false +ProjectManager.ProjectFileName=ECU.ioc +ProjectManager.ProjectName=ECU +ProjectManager.ProjectStructure= +ProjectManager.RegisterCallBack= +ProjectManager.StackSize=0x400 +ProjectManager.TargetToolchain=CMake +ProjectManager.ToolChainLocation= +ProjectManager.UAScriptAfterPath= +ProjectManager.UAScriptBeforePath= +ProjectManager.UnderRoot=false +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_ADC2_Init-ADC2-false-HAL-true,6-MX_FDCAN1_Init-FDCAN1-false-HAL-true,7-MX_FDCAN2_Init-FDCAN2-false-HAL-true,8-MX_TIM6_Init-TIM6-false-HAL-true,9-MX_ADC5_Init-ADC5-false-HAL-true,10-MX_USART3_UART_Init-USART3-false-HAL-true +RCC.ADC12Freq_Value=160000000 +RCC.ADC345Freq_Value=160000000 +RCC.AHBFreq_Value=160000000 +RCC.APB1Freq_Value=160000000 +RCC.APB1TimFreq_Value=160000000 +RCC.APB2Freq_Value=160000000 +RCC.APB2TimFreq_Value=160000000 +RCC.CRSFreq_Value=48000000 +RCC.CortexFreq_Value=160000000 +RCC.EXTERNAL_CLOCK_VALUE=12288000 +RCC.FCLKCortexFreq_Value=160000000 +RCC.FDCANFreq_Value=160000000 +RCC.FamilyName=M +RCC.HCLKFreq_Value=160000000 +RCC.HRTIM1Freq_Value=160000000 +RCC.HSE_VALUE=8000000 +RCC.HSI48_VALUE=48000000 +RCC.HSI_VALUE=16000000 +RCC.I2C1Freq_Value=160000000 +RCC.I2C2Freq_Value=160000000 +RCC.I2C3Freq_Value=160000000 +RCC.I2C4Freq_Value=160000000 +RCC.I2SFreq_Value=160000000 +RCC.IPParameters=ADC12Freq_Value,ADC345Freq_Value,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CRSFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,FCLKCortexFreq_Value,FDCANFreq_Value,FamilyName,HCLKFreq_Value,HRTIM1Freq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2C4Freq_Value,I2SFreq_Value,LPTIM1Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSE_VALUE,LSI_VALUE,MCO1PinFreq_Value,PLLN,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PWRFreq_Value,QSPIFreq_Value,RNGFreq_Value,SAI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,UART5Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value +RCC.LPTIM1Freq_Value=160000000 +RCC.LPUART1Freq_Value=160000000 +RCC.LSCOPinFreq_Value=32000 +RCC.LSE_VALUE=32768 +RCC.LSI_VALUE=32000 +RCC.MCO1PinFreq_Value=16000000 +RCC.PLLN=20 +RCC.PLLPoutputFreq_Value=160000000 +RCC.PLLQoutputFreq_Value=160000000 +RCC.PLLRCLKFreq_Value=160000000 +RCC.PWRFreq_Value=160000000 +RCC.QSPIFreq_Value=160000000 +RCC.RNGFreq_Value=160000000 +RCC.SAI1Freq_Value=160000000 +RCC.SYSCLKFreq_VALUE=160000000 +RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK +RCC.UART4Freq_Value=160000000 +RCC.UART5Freq_Value=160000000 +RCC.USART1Freq_Value=160000000 +RCC.USART2Freq_Value=160000000 +RCC.USART3Freq_Value=160000000 +RCC.USBFreq_Value=160000000 +RCC.VCOInputFreq_Value=16000000 +RCC.VCOOutputFreq_Value=320000000 +TIM6.IPParameters=Prescaler,PeriodNoDither +TIM6.PeriodNoDither=624 +TIM6.Prescaler=159 +USART3.IPParameters=VirtualMode-Asynchronous +USART3.VirtualMode-Asynchronous=VM_ASYNC +VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals +VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals +VP_SYS_VS_Systick.Mode=SysTick +VP_SYS_VS_Systick.Signal=SYS_VS_Systick +VP_TIM6_VS_ClockSourceINT.Mode=Enable_Timer +VP_TIM6_VS_ClockSourceINT.Signal=TIM6_VS_ClockSourceINT +board=custom diff --git a/ECU/STM32G474xx_FLASH.ld b/ECU/STM32G474xx_FLASH.ld new file mode 100644 index 000000000..2c518a14a --- /dev/null +++ b/ECU/STM32G474xx_FLASH.ld @@ -0,0 +1,250 @@ +/* +****************************************************************************** +** + +** File : LinkerScript.ld +** +** Author : STM32CubeMX +** +** Abstract : Linker script for STM32G474RETx series +** 512Kbytes FLASH and 128Kbytes RAM +** +** Set heap size, stack size and stack location according +** to application requirements. +** +** Set memory bank area and size if external memory is used. +** +** Target : STMicroelectronics STM32 +** +** Distribution: The file is distributed “as is,” without any warranty +** of any kind. +** +***************************************************************************** +** @attention +** +**

© COPYRIGHT(c) 2025 STMicroelectronics

+** +** Redistribution and use in source and binary forms, with or without modification, +** are permitted provided that the following conditions are met: +** 1. Redistributions of source code must retain the above copyright notice, +** this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright notice, +** this list of conditions and the following disclaimer in the documentation +** and/or other materials provided with the distribution. +** 3. Neither the name of STMicroelectronics nor the names of its contributors +** may be used to endorse or promote products derived from this software +** without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +** +***************************************************************************** +*/ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Specify the memory areas */ +MEMORY +{ +RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K +FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K +} + +/* Highest address of the user mode stack */ +_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of RAM */ +_sstack = _estack - _Min_Stack_Size; +/* Generate a link error if heap and stack don't fit into RAM */ +_Min_Heap_Size = 0x200; /* required amount of heap */ +_Min_Stack_Size = 0x400; /* required amount of stack */ + +/* Define output sections */ +SECTIONS +{ + /* The startup code goes first into FLASH */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data goes into FLASH */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + + KEEP (*(.init)) + KEEP (*(.fini)) + + . = ALIGN(4); + _etext = .; /* define a global symbols at end of code */ + } >FLASH + + /* Constant data goes into FLASH */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ + { + . = ALIGN(4); + *(.ARM.extab* .gnu.linkonce.armextab.*) + . = ALIGN(4); + } >FLASH + + .ARM (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ + { + . = ALIGN(4); + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + . = ALIGN(4); + } >FLASH + + .preinit_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ + { + . = ALIGN(4); + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + . = ALIGN(4); + } >FLASH + + .init_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ + { + . = ALIGN(4); + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + . = ALIGN(4); + } >FLASH + + .fini_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ + { + . = ALIGN(4); + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + . = ALIGN(4); + } >FLASH + + /* used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections goes into RAM, load LMA copy after code */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + *(.RamFunc) /* .RamFunc sections */ + *(.RamFunc*) /* .RamFunc* sections */ + + . = ALIGN(4); + } >RAM AT> FLASH + + /* Initialized TLS data section */ + .tdata : ALIGN(4) + { + *(.tdata .tdata.* .gnu.linkonce.td.*) + . = ALIGN(4); + _edata = .; /* define a global symbol at data end */ + PROVIDE(__data_end = .); + PROVIDE(__tdata_end = .); + } >RAM AT> FLASH + + PROVIDE( __tdata_start = ADDR(.tdata) ); + PROVIDE( __tdata_size = __tdata_end - __tdata_start ); + + PROVIDE( __data_start = ADDR(.data) ); + PROVIDE( __data_size = __data_end - __data_start ); + + PROVIDE( __tdata_source = LOADADDR(.tdata) ); + PROVIDE( __tdata_source_end = LOADADDR(.tdata) + SIZEOF(.tdata) ); + PROVIDE( __tdata_source_size = __tdata_source_end - __tdata_source ); + + PROVIDE( __data_source = LOADADDR(.data) ); + PROVIDE( __data_source_end = __tdata_source_end ); + PROVIDE( __data_source_size = __data_source_end - __data_source ); + /* Uninitialized data section */ + .tbss (NOLOAD) : ALIGN(4) + { + /* This is used by the startup in order to initialize the .bss secion */ + _sbss = .; /* define a global symbol at bss start */ + __bss_start__ = _sbss; + *(.tbss .tbss.*) + . = ALIGN(4); + PROVIDE( __tbss_end = . ); + } >RAM + + PROVIDE( __tbss_start = ADDR(.tbss) ); + PROVIDE( __tbss_size = __tbss_end - __tbss_start ); + PROVIDE( __tbss_offset = ADDR(.tbss) - ADDR(.tdata) ); + + PROVIDE( __tls_base = __tdata_start ); + PROVIDE( __tls_end = __tbss_end ); + PROVIDE( __tls_size = __tls_end - __tls_base ); + PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); + PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1) ); + PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); + PROVIDE( __arm64_tls_tcb_offset = MAX(16, __tls_align) ); + + .bss (NOLOAD) : ALIGN(4) + { + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end */ + __bss_end__ = _ebss; + PROVIDE( __bss_end = .); + } >RAM + PROVIDE( __non_tls_bss_start = ADDR(.bss) ); + + PROVIDE( __bss_start = __tbss_start ); + PROVIDE( __bss_size = __bss_end - __bss_start ); + + /* User_heap_stack section, used to check that there is enough RAM left */ + ._user_heap_stack (NOLOAD) : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + + + /* Remove information from the standard libraries */ + /DISCARD/ : + { + libc.a:* ( * ) + libm.a:* ( * ) + libgcc.a:* ( * ) + } + +} diff --git a/ECU/Test/Src/StateTicksTest.c b/ECU/Test/Src/StateTicksTest.c index 41e86c9b0..b030edf50 100644 --- a/ECU/Test/Src/StateTicksTest.c +++ b/ECU/Test/Src/StateTicksTest.c @@ -11,7 +11,7 @@ /* - GLV ON - - LOGOMATIC working + - LOGOMATIC_INFO working - TSSI - PRECHARGE ENGAGED - PRECHARGE COMPLETE @@ -29,9 +29,9 @@ static void ECU_Pseudo_State_Tick(ECU_StateData *stateLumpTest) // EV.5.11.5: Flash, 2 Hz to 5 Hz, 50% duty cycle // Here we chose a period of 350ms if (bmsFailure(stateLumpTest) || imdFailure(stateLumpTest)) { - LOGOMATIC("TSSI: TS Faulty\n"); + LOGOMATIC_INFO("TSSI: TS Faulty\n"); } else { - LOGOMATIC("TSSI: TS Normal\n"); + LOGOMATIC_INFO("TSSI: TS Normal\n"); } if (stateLumpTest->ts_active_button_press_interrupt) { @@ -68,8 +68,8 @@ static void ECU_Pseudo_State_Tick(ECU_StateData *stateLumpTest) ECU_Tractive_System_Discharge(stateLumpTest); break; default: - LOGOMATIC("ECU Current State Unknown: %d\n", stateLumpTest->ecu_state); - LOGOMATIC("ECU: Resetting to GLV On\n"); + LOGOMATIC_INFO("ECU Current State Unknown: %d\n", stateLumpTest->ecu_state); + LOGOMATIC_INFO("ECU: Resetting to GLV On\n"); stateLumpTest->ecu_state = GR_GLV_ON; break; } @@ -119,10 +119,10 @@ int main(void) // ########################### // ## Step 0.0 ## // ########################### - LOGOMATIC("State Ticks test started\n"); + LOGOMATIC_INFO("State Ticks test started\n"); ECU_StateData stateLumpTest = defaultState; - LOGOMATIC("Check GLV ON at boot\n"); + LOGOMATIC_INFO("Check GLV ON at boot\n"); stateLumpTest.ecu_state = GR_GLV_ON; stateLumpTest.acu_software_latch = 1; ECU_Pseudo_State_Tick(&stateLumpTest); @@ -130,73 +130,73 @@ int main(void) // ########################## // ## Step 0.1 ## // ########################## - LOGOMATIC("Press and release RTD -> STAY IN GLV ON\n"); + LOGOMATIC_INFO("Press and release RTD -> STAY IN GLV ON\n"); stateLumpTest.rtd_button_press_interrupt = true; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_GLV_ON) { - LOGOMATIC("0.1 Failure: ecu state not in GLV ON\n"); + LOGOMATIC_INFO("0.1 Failure: ecu state not in GLV ON\n"); return 1; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.1 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.1 Failure: BMS or IMD reports faulty\n"); return 1; } // ########################## // ## Step 0.2 ## // ########################## - LOGOMATIC("Press throttle (1 and 2): STAY IN GLV ON\n"); + LOGOMATIC_INFO("Press throttle (1 and 2): STAY IN GLV ON\n"); stateLumpTest.APPS1_Signal = stateLumpTest.apps_1_max; stateLumpTest.APPS2_Signal = stateLumpTest.apps_2_max; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_GLV_ON) { - LOGOMATIC("0.2 Failure: ecu state not in GLV ON\n"); + LOGOMATIC_INFO("0.2 Failure: ecu state not in GLV ON\n"); return 2; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.2 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.2 Failure: BMS or IMD reports faulty\n"); return 1; } stateLumpTest.APPS1_Signal = stateLumpTest.apps_1_min; stateLumpTest.APPS2_Signal = stateLumpTest.apps_2_min; - LOGOMATIC("Press brake: STAY IN GLV ON\n"); + LOGOMATIC_INFO("Press brake: STAY IN GLV ON\n"); stateLumpTest.bse_signal = stateLumpTest.brake_bse_min + 69; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_GLV_ON) { - LOGOMATIC("0.2 Failure: ecu state not in GLV ON\n"); + LOGOMATIC_INFO("0.2 Failure: ecu state not in GLV ON\n"); return 2; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.2 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.2 Failure: BMS or IMD reports faulty\n"); return 2; } - LOGOMATIC("Release brake: STAY IN GLV ON\n"); + LOGOMATIC_INFO("Release brake: STAY IN GLV ON\n"); stateLumpTest.bse_signal = 0; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_GLV_ON) { - LOGOMATIC("0.2 Failure: ecu state not in GLV ON\n"); + LOGOMATIC_INFO("0.2 Failure: ecu state not in GLV ON\n"); return 2; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.2 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.2 Failure: BMS or IMD reports faulty\n"); return 2; } // ########################## // ## Step 0.3 ## // ########################## - LOGOMATIC("Press TS ACTIVE: Go to PRECHARGE ENGAGE\n"); + LOGOMATIC_INFO("Press TS ACTIVE: Go to PRECHARGE ENGAGE\n"); stateLumpTest.ts_active_button_press_interrupt = true; stateLumpTest.ir_minus = true; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_PRECHARGE_ENGAGED) { - LOGOMATIC("0.3 Failure: ecu state not in precharge engaged\n"); + LOGOMATIC_INFO("0.3 Failure: ecu state not in precharge engaged\n"); return 3; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.3 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.3 Failure: BMS or IMD reports faulty\n"); return 3; } @@ -204,281 +204,281 @@ int main(void) // ## Step 0.4 ## // ########################## if (stateLumpTest.ecu_state != GR_PRECHARGE_ENGAGED) { - LOGOMATIC("0.4 Failure: ecu state not in precharge engaged\n"); + LOGOMATIC_INFO("0.4 Failure: ecu state not in precharge engaged\n"); return 4; } // ########################## // ## Step 0.5 ## // ########################## - LOGOMATIC("Test Precharge Complete (IR PLUS)\n"); + LOGOMATIC_INFO("Test Precharge Complete (IR PLUS)\n"); stateLumpTest.ir_plus = true; stateLumpTest.ts_voltage = 400; // dummy value ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_PRECHARGE_COMPLETE) { - LOGOMATIC("0.5 Failure: ecu state not in precharge complete\n"); + LOGOMATIC_INFO("0.5 Failure: ecu state not in precharge complete\n"); return 5; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.5 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.5 Failure: BMS or IMD reports faulty\n"); return 5; } // ########################## // ## Step 0.6 ## // ########################## - LOGOMATIC("Press RTD -> STAY IN PRECHARGE COMPLETE\n"); + LOGOMATIC_INFO("Press RTD -> STAY IN PRECHARGE COMPLETE\n"); stateLumpTest.rtd_button_press_interrupt = true; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_PRECHARGE_COMPLETE) { - LOGOMATIC("0.6 Failure: ecu state not in precharge complete\n"); + LOGOMATIC_INFO("0.6 Failure: ecu state not in precharge complete\n"); return 6; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.6 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.6 Failure: BMS or IMD reports faulty\n"); return 6; } - LOGOMATIC("Release RTD -> STAY IN PRECHARGE COMPLETE\n"); + LOGOMATIC_INFO("Release RTD -> STAY IN PRECHARGE COMPLETE\n"); stateLumpTest.rtd_button_press_interrupt = false; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_PRECHARGE_COMPLETE) { - LOGOMATIC("0.6 Failure: ecu state not in precharge complete\n"); + LOGOMATIC_INFO("0.6 Failure: ecu state not in precharge complete\n"); return 6; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.6 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.6 Failure: BMS or IMD reports faulty\n"); return 6; } // ########################## // ## Step 0.7 ## // ########################## - LOGOMATIC("Press and release the RTD button WHILE pressing the brake\n"); + LOGOMATIC_INFO("Press and release the RTD button WHILE pressing the brake\n"); stateLumpTest.bse_signal = stateLumpTest.brake_bse_min + 69; - LOGOMATIC("Press RTD\n"); + LOGOMATIC_INFO("Press RTD\n"); stateLumpTest.rtd_button_press_interrupt = true; ECU_Pseudo_State_Tick(&stateLumpTest); - LOGOMATIC("Release RTD\n"); + LOGOMATIC_INFO("Release RTD\n"); ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_DRIVE_ACTIVE) { - LOGOMATIC("0.7 Failure: ecu state not in drive active\n"); + LOGOMATIC_INFO("0.7 Failure: ecu state not in drive active\n"); return 7; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.7 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.7 Failure: BMS or IMD reports faulty\n"); return 7; } // ########################## // ## Step 0.8 ## // ########################## - LOGOMATIC("Release Brakes -> STAY IN DRIVE ACTIVE\n"); + LOGOMATIC_INFO("Release Brakes -> STAY IN DRIVE ACTIVE\n"); stateLumpTest.bse_signal = 0; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_DRIVE_ACTIVE) { - LOGOMATIC("0.8 Failure: ecu state not in drive active\n"); + LOGOMATIC_INFO("0.8 Failure: ecu state not in drive active\n"); return 8; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.8 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.8 Failure: BMS or IMD reports faulty\n"); return 8; } // ########################## // ## Step 0.9 ## // ########################## - LOGOMATIC("Press Throttle -> STAY IN DRIVE ACTIVE\n"); + LOGOMATIC_INFO("Press Throttle -> STAY IN DRIVE ACTIVE\n"); stateLumpTest.APPS1_Signal = stateLumpTest.apps_1_max; stateLumpTest.APPS2_Signal = stateLumpTest.apps_2_max; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_DRIVE_ACTIVE) { - LOGOMATIC("0.9 Failure: ecu state not in drive active\n"); + LOGOMATIC_INFO("0.9 Failure: ecu state not in drive active\n"); return 9; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.9 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.9 Failure: BMS or IMD reports faulty\n"); return 9; } // ########################## // ## Step 0.10 ## // ########################## - LOGOMATIC("Release Throttle -> STAY IN DRIVE ACTIVE\n"); + LOGOMATIC_INFO("Release Throttle -> STAY IN DRIVE ACTIVE\n"); stateLumpTest.APPS1_Signal = 0; stateLumpTest.APPS2_Signal = 0; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_DRIVE_ACTIVE) { - LOGOMATIC("0.10 Failure: ecu state not in drive active\n"); + LOGOMATIC_INFO("0.10 Failure: ecu state not in drive active\n"); return 10; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.10 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.10 Failure: BMS or IMD reports faulty\n"); return 10; } // ########################## // ## Step 0.11 ## // ########################## - LOGOMATIC("Press Throttle and Brake -> STAY IN DRIVE ACTIVE\n"); + LOGOMATIC_INFO("Press Throttle and Brake -> STAY IN DRIVE ACTIVE\n"); stateLumpTest.APPS1_Signal = stateLumpTest.apps_1_max; stateLumpTest.APPS2_Signal = stateLumpTest.apps_2_max; stateLumpTest.bse_signal = stateLumpTest.brake_bse_min + 69; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_DRIVE_ACTIVE) { - LOGOMATIC("0.11 Failure: ecu state not in drive active\n"); + LOGOMATIC_INFO("0.11 Failure: ecu state not in drive active\n"); return 11; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.11 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.11 Failure: BMS or IMD reports faulty\n"); return 11; } // ########################## // ## Step 0.12 ## // ########################## - LOGOMATIC("Release Throttle and Brake-> STAY IN DRIVE ACTIVE\n"); + LOGOMATIC_INFO("Release Throttle and Brake-> STAY IN DRIVE ACTIVE\n"); stateLumpTest.APPS1_Signal = stateLumpTest.apps_1_min; stateLumpTest.APPS2_Signal = stateLumpTest.apps_2_min; stateLumpTest.bse_signal = 0; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_DRIVE_ACTIVE) { - LOGOMATIC("0.12 Failure: ecu state not in drive active\n"); + LOGOMATIC_INFO("0.12 Failure: ecu state not in drive active\n"); return 12; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.12 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.12 Failure: BMS or IMD reports faulty\n"); return 12; } // ########################## // ## Step 0.13 ## // ########################## - LOGOMATIC("Press Throttle -> STAY IN DRIVE ACTIVE\n"); + LOGOMATIC_INFO("Press Throttle -> STAY IN DRIVE ACTIVE\n"); stateLumpTest.APPS1_Signal = stateLumpTest.apps_1_max; stateLumpTest.APPS2_Signal = stateLumpTest.apps_2_max; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_DRIVE_ACTIVE) { - LOGOMATIC("0.13 Failure: ecu state not in drive active\n"); + LOGOMATIC_INFO("0.13 Failure: ecu state not in drive active\n"); return 13; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.13 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.13 Failure: BMS or IMD reports faulty\n"); return 13; } // ########################## // ## Step 0.14 ## // ########################## - LOGOMATIC("Release Throttle -> STAY IN DRIVE ACTIVE\n"); + LOGOMATIC_INFO("Release Throttle -> STAY IN DRIVE ACTIVE\n"); stateLumpTest.APPS1_Signal = stateLumpTest.apps_1_min; stateLumpTest.APPS2_Signal = stateLumpTest.apps_2_min; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_DRIVE_ACTIVE) { - LOGOMATIC("0.14 Failure: ecu state not in drive active\n"); + LOGOMATIC_INFO("0.14 Failure: ecu state not in drive active\n"); return 14; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.14 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.14 Failure: BMS or IMD reports faulty\n"); return 14; } // ########################## // ## Step 0.15 ## // ########################## - LOGOMATIC("Press RTD -> MOVE TO PRECHARGE COMPLETE\n"); + LOGOMATIC_INFO("Press RTD -> MOVE TO PRECHARGE COMPLETE\n"); stateLumpTest.rtd_button_press_interrupt = true; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_PRECHARGE_COMPLETE) { - LOGOMATIC("0.15 Failure: ecu state not in precharge complete\n"); + LOGOMATIC_INFO("0.15 Failure: ecu state not in precharge complete\n"); return 15; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.15 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.15 Failure: BMS or IMD reports faulty\n"); return 15; } - LOGOMATIC("Release RTD -> STAY IN PRECHARGE COMPLETE\n"); + LOGOMATIC_INFO("Release RTD -> STAY IN PRECHARGE COMPLETE\n"); ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_PRECHARGE_COMPLETE) { - LOGOMATIC("0.15 Failure: ecu state not in precharge complete\n"); + LOGOMATIC_INFO("0.15 Failure: ecu state not in precharge complete\n"); return 15; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.15 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.15 Failure: BMS or IMD reports faulty\n"); return 15; } // ########################## // ## Step 0.16 ## // ########################## - LOGOMATIC("Press Throttle -> STAY IN Precharge Complete\n"); + LOGOMATIC_INFO("Press Throttle -> STAY IN Precharge Complete\n"); stateLumpTest.APPS1_Signal = stateLumpTest.apps_1_max; stateLumpTest.APPS2_Signal = stateLumpTest.apps_2_max; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_PRECHARGE_COMPLETE) { - LOGOMATIC("0.16 Failure: ecu state not in precharge complete\n"); + LOGOMATIC_INFO("0.16 Failure: ecu state not in precharge complete\n"); return 16; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.16 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.16 Failure: BMS or IMD reports faulty\n"); return 16; } // ########################## // ## Step 0.17 ## // ########################## - LOGOMATIC("Release Throttle -> STAY IN Precharge Complete\n"); + LOGOMATIC_INFO("Release Throttle -> STAY IN Precharge Complete\n"); stateLumpTest.APPS1_Signal = stateLumpTest.apps_1_min; stateLumpTest.APPS2_Signal = stateLumpTest.apps_2_min; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_PRECHARGE_COMPLETE) { - LOGOMATIC("0.17 Failure: ecu state not in precharge complete\n"); + LOGOMATIC_INFO("0.17 Failure: ecu state not in precharge complete\n"); return 17; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.17 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.17 Failure: BMS or IMD reports faulty\n"); return 17; } // ########################## // ## Step 0.18 ## // ########################## - LOGOMATIC("Press TS Active Button -> MOVE to TS DISCHARGE\n"); + LOGOMATIC_INFO("Press TS Active Button -> MOVE to TS DISCHARGE\n"); stateLumpTest.ts_active_button_press_interrupt = true; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_TS_DISCHARGE) { - LOGOMATIC("0.18 Failure: ecu state not in ts discharge\n"); + LOGOMATIC_INFO("0.18 Failure: ecu state not in ts discharge\n"); return 18; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.18 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.18 Failure: BMS or IMD reports faulty\n"); return 18; } - LOGOMATIC("Release TS Active Button -> STAY IN TS DISCHARGE\n"); + LOGOMATIC_INFO("Release TS Active Button -> STAY IN TS DISCHARGE\n"); ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_TS_DISCHARGE) { - LOGOMATIC("0.18 Failure: ecu state not in ts discharge\n"); + LOGOMATIC_INFO("0.18 Failure: ecu state not in ts discharge\n"); return 18; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.18 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.18 Failure: BMS or IMD reports faulty\n"); return 18; } // ########################## // ## Step 0.19 ## // ########################## - LOGOMATIC("TS Voltage Less than 60 -> MOVE to GLV ON\n"); + LOGOMATIC_INFO("TS Voltage Less than 60 -> MOVE to GLV ON\n"); stateLumpTest.ts_voltage = 40; ECU_Pseudo_State_Tick(&stateLumpTest); stateLumpTest.ir_minus = !stateLumpTest.ir_minus; stateLumpTest.ir_plus = !stateLumpTest.ir_plus; if (stateLumpTest.ecu_state != GR_GLV_ON) { - LOGOMATIC("0.19 Failure: ecu state not in GLV ON\n"); + LOGOMATIC_INFO("0.19 Failure: ecu state not in GLV ON\n"); return 19; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("0.19 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("0.19 Failure: BMS or IMD reports faulty\n"); return 19; } } @@ -487,46 +487,46 @@ int main(void) // ########################## // ## Step 1.0 ## // ########################## - LOGOMATIC("Reset system\n"); + LOGOMATIC_INFO("Reset system\n"); ECU_StateData stateLumpTest = defaultState; - LOGOMATIC("State Tick Test 1 started\n"); + LOGOMATIC_INFO("State Tick Test 1 started\n"); ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_GLV_ON) { - LOGOMATIC("1.0 Failure: ecu state not in GLV ON\n"); + LOGOMATIC_INFO("1.0 Failure: ecu state not in GLV ON\n"); return 21; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("1.0 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("1.0 Failure: BMS or IMD reports faulty\n"); return 21; } // ########################## // ## Step 1.1 ## // ########################## - LOGOMATIC("TS Voltage Greater than 60 -> MOVE to TS DISCHARGE\n"); + LOGOMATIC_INFO("TS Voltage Greater than 60 -> MOVE to TS DISCHARGE\n"); stateLumpTest.ts_voltage = 500; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_TS_DISCHARGE) { - LOGOMATIC("1.1 Failure: ecu state not in TS DISCHARGE\n"); + LOGOMATIC_INFO("1.1 Failure: ecu state not in TS DISCHARGE\n"); return 21; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("1.1 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("1.1 Failure: BMS or IMD reports faulty\n"); return 21; } // ########################## // ## Step 1.2 ## // ########################## - LOGOMATIC("TS Voltage Less than 60 -> MOVE to GLV ON\n"); + LOGOMATIC_INFO("TS Voltage Less than 60 -> MOVE to GLV ON\n"); stateLumpTest.ts_voltage = 40; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_GLV_ON) { - LOGOMATIC("1.2 Failure: ecu state not in GLV ON\n"); + LOGOMATIC_INFO("1.2 Failure: ecu state not in GLV ON\n"); return 22; } if (bmsFailure(&stateLumpTest) || imdFailure(&stateLumpTest)) { - LOGOMATIC("1.2 Failure: BMS or IMD reports faulty\n"); + LOGOMATIC_INFO("1.2 Failure: BMS or IMD reports faulty\n"); return 21; } } diff --git a/ECU/Test/Src/dummy_test.c b/ECU/Test/Src/dummy_test.c index f1080e5e3..e33ef6353 100644 --- a/ECU/Test/Src/dummy_test.c +++ b/ECU/Test/Src/dummy_test.c @@ -2,6 +2,6 @@ int main(void) { - LOGOMATIC("Dummy test executed successfully.\n"); + LOGOMATIC_INFO("Dummy test executed successfully.\n"); return 0; } diff --git a/ECU/startup_stm32g474xx.s b/ECU/startup_stm32g474xx.s new file mode 100644 index 000000000..e7a2c61fc --- /dev/null +++ b/ECU/startup_stm32g474xx.s @@ -0,0 +1,592 @@ +/** + ****************************************************************************** + * @file startup_stm32g474xx.s + * @author MCD Application Team + * @brief STM32G474xx devices vector table GCC toolchain. + * This module performs: + * - Set the initial SP + * - Set the initial PC == Reset_Handler, + * - Set the vector table entries with the exceptions ISR address, + * - Configure the clock system + * - Branches to main in the C library (which eventually + * calls main()). + * After Reset the Cortex-M4 processor is in Thread mode, + * priority is Privileged, and the Stack is set to Main. + ****************************************************************************** + * @attention + * + * Copyright (c) 2019 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + .syntax unified + .cpu cortex-m4 + .fpu softvfp + .thumb + +.global g_pfnVectors +.global Default_Handler + +/* start address for the initialization values of the .data section. +defined in linker script */ +.word _sidata +/* start address for the .data section. defined in linker script */ +.word _sdata +/* end address for the .data section. defined in linker script */ +.word _edata +/* start address for the .bss section. defined in linker script */ +.word _sbss +/* end address for the .bss section. defined in linker script */ +.word _ebss + +.equ BootRAM, 0xF1E0F85F +/** + * @brief This is the code that gets called when the processor first + * starts execution following a reset event. Only the absolutely + * necessary set is performed, after which the application + * supplied main() routine is called. + * @param None + * @retval : None +*/ + + .section .text.Reset_Handler + .weak Reset_Handler + .type Reset_Handler, %function +Reset_Handler: + ldr r0, =_estack + mov sp, r0 /* set stack pointer */ + +/* Call the clock system initialization function.*/ + bl SystemInit + +/* Copy the data segment initializers from flash to SRAM */ + ldr r0, =_sdata + ldr r1, =_edata + ldr r2, =_sidata + movs r3, #0 + b LoopCopyDataInit + +CopyDataInit: + ldr r4, [r2, r3] + str r4, [r0, r3] + adds r3, r3, #4 + +LoopCopyDataInit: + adds r4, r0, r3 + cmp r4, r1 + bcc CopyDataInit + +/* Zero fill the bss segment. */ + ldr r2, =_sbss + ldr r4, =_ebss + movs r3, #0 + b LoopFillZerobss + +FillZerobss: + str r3, [r2] + adds r2, r2, #4 + +LoopFillZerobss: + cmp r2, r4 + bcc FillZerobss + +/* Call static constructors */ + bl __libc_init_array +/* Call the application's entry point.*/ + bl main + +LoopForever: + b LoopForever + +.size Reset_Handler, .-Reset_Handler + +/** + * @brief This is the code that gets called when the processor receives an + * unexpected interrupt. This simply enters an infinite loop, preserving + * the system state for examination by a debugger. + * + * @param None + * @retval : None +*/ + .section .text.Default_Handler,"ax",%progbits +Default_Handler: +Infinite_Loop: + b Infinite_Loop + .size Default_Handler, .-Default_Handler +/****************************************************************************** +* +* The minimal vector table for a Cortex-M4. Note that the proper constructs +* must be placed on this to ensure that it ends up at physical address +* 0x0000.0000. +* +******************************************************************************/ + .section .isr_vector,"a",%progbits + .type g_pfnVectors, %object + + +g_pfnVectors: + .word _estack + .word Reset_Handler + .word NMI_Handler + .word HardFault_Handler + .word MemManage_Handler + .word BusFault_Handler + .word UsageFault_Handler + .word 0 + .word 0 + .word 0 + .word 0 + .word SVC_Handler + .word DebugMon_Handler + .word 0 + .word PendSV_Handler + .word SysTick_Handler + .word WWDG_IRQHandler + .word PVD_PVM_IRQHandler + .word RTC_TAMP_LSECSS_IRQHandler + .word RTC_WKUP_IRQHandler + .word FLASH_IRQHandler + .word RCC_IRQHandler + .word EXTI0_IRQHandler + .word EXTI1_IRQHandler + .word EXTI2_IRQHandler + .word EXTI3_IRQHandler + .word EXTI4_IRQHandler + .word DMA1_Channel1_IRQHandler + .word DMA1_Channel2_IRQHandler + .word DMA1_Channel3_IRQHandler + .word DMA1_Channel4_IRQHandler + .word DMA1_Channel5_IRQHandler + .word DMA1_Channel6_IRQHandler + .word DMA1_Channel7_IRQHandler + .word ADC1_2_IRQHandler + .word USB_HP_IRQHandler + .word USB_LP_IRQHandler + .word FDCAN1_IT0_IRQHandler + .word FDCAN1_IT1_IRQHandler + .word EXTI9_5_IRQHandler + .word TIM1_BRK_TIM15_IRQHandler + .word TIM1_UP_TIM16_IRQHandler + .word TIM1_TRG_COM_TIM17_IRQHandler + .word TIM1_CC_IRQHandler + .word TIM2_IRQHandler + .word TIM3_IRQHandler + .word TIM4_IRQHandler + .word I2C1_EV_IRQHandler + .word I2C1_ER_IRQHandler + .word I2C2_EV_IRQHandler + .word I2C2_ER_IRQHandler + .word SPI1_IRQHandler + .word SPI2_IRQHandler + .word USART1_IRQHandler + .word USART2_IRQHandler + .word USART3_IRQHandler + .word EXTI15_10_IRQHandler + .word RTC_Alarm_IRQHandler + .word USBWakeUp_IRQHandler + .word TIM8_BRK_IRQHandler + .word TIM8_UP_IRQHandler + .word TIM8_TRG_COM_IRQHandler + .word TIM8_CC_IRQHandler + .word ADC3_IRQHandler + .word FMC_IRQHandler + .word LPTIM1_IRQHandler + .word TIM5_IRQHandler + .word SPI3_IRQHandler + .word UART4_IRQHandler + .word UART5_IRQHandler + .word TIM6_DAC_IRQHandler + .word TIM7_DAC_IRQHandler + .word DMA2_Channel1_IRQHandler + .word DMA2_Channel2_IRQHandler + .word DMA2_Channel3_IRQHandler + .word DMA2_Channel4_IRQHandler + .word DMA2_Channel5_IRQHandler + .word ADC4_IRQHandler + .word ADC5_IRQHandler + .word UCPD1_IRQHandler + .word COMP1_2_3_IRQHandler + .word COMP4_5_6_IRQHandler + .word COMP7_IRQHandler + .word HRTIM1_Master_IRQHandler + .word HRTIM1_TIMA_IRQHandler + .word HRTIM1_TIMB_IRQHandler + .word HRTIM1_TIMC_IRQHandler + .word HRTIM1_TIMD_IRQHandler + .word HRTIM1_TIME_IRQHandler + .word HRTIM1_FLT_IRQHandler + .word HRTIM1_TIMF_IRQHandler + .word CRS_IRQHandler + .word SAI1_IRQHandler + .word TIM20_BRK_IRQHandler + .word TIM20_UP_IRQHandler + .word TIM20_TRG_COM_IRQHandler + .word TIM20_CC_IRQHandler + .word FPU_IRQHandler + .word I2C4_EV_IRQHandler + .word I2C4_ER_IRQHandler + .word SPI4_IRQHandler + .word 0 + .word FDCAN2_IT0_IRQHandler + .word FDCAN2_IT1_IRQHandler + .word FDCAN3_IT0_IRQHandler + .word FDCAN3_IT1_IRQHandler + .word RNG_IRQHandler + .word LPUART1_IRQHandler + .word I2C3_EV_IRQHandler + .word I2C3_ER_IRQHandler + .word DMAMUX_OVR_IRQHandler + .word QUADSPI_IRQHandler + .word DMA1_Channel8_IRQHandler + .word DMA2_Channel6_IRQHandler + .word DMA2_Channel7_IRQHandler + .word DMA2_Channel8_IRQHandler + .word CORDIC_IRQHandler + .word FMAC_IRQHandler + + .size g_pfnVectors, .-g_pfnVectors + +/******************************************************************************* +* +* Provide weak aliases for each Exception handler to the Default_Handler. +* As they are weak aliases, any function with the same name will override +* this definition. +* +*******************************************************************************/ + + .weak NMI_Handler + .thumb_set NMI_Handler,Default_Handler + + .weak HardFault_Handler + .thumb_set HardFault_Handler,Default_Handler + + .weak MemManage_Handler + .thumb_set MemManage_Handler,Default_Handler + + .weak BusFault_Handler + .thumb_set BusFault_Handler,Default_Handler + + .weak UsageFault_Handler + .thumb_set UsageFault_Handler,Default_Handler + + .weak SVC_Handler + .thumb_set SVC_Handler,Default_Handler + + .weak DebugMon_Handler + .thumb_set DebugMon_Handler,Default_Handler + + .weak PendSV_Handler + .thumb_set PendSV_Handler,Default_Handler + + .weak SysTick_Handler + .thumb_set SysTick_Handler,Default_Handler + + .weak WWDG_IRQHandler + .thumb_set WWDG_IRQHandler,Default_Handler + + .weak PVD_PVM_IRQHandler + .thumb_set PVD_PVM_IRQHandler,Default_Handler + + .weak RTC_TAMP_LSECSS_IRQHandler + .thumb_set RTC_TAMP_LSECSS_IRQHandler,Default_Handler + + .weak RTC_WKUP_IRQHandler + .thumb_set RTC_WKUP_IRQHandler,Default_Handler + + .weak FLASH_IRQHandler + .thumb_set FLASH_IRQHandler,Default_Handler + + .weak RCC_IRQHandler + .thumb_set RCC_IRQHandler,Default_Handler + + .weak EXTI0_IRQHandler + .thumb_set EXTI0_IRQHandler,Default_Handler + + .weak EXTI1_IRQHandler + .thumb_set EXTI1_IRQHandler,Default_Handler + + .weak EXTI2_IRQHandler + .thumb_set EXTI2_IRQHandler,Default_Handler + + .weak EXTI3_IRQHandler + .thumb_set EXTI3_IRQHandler,Default_Handler + + .weak EXTI4_IRQHandler + .thumb_set EXTI4_IRQHandler,Default_Handler + + .weak DMA1_Channel1_IRQHandler + .thumb_set DMA1_Channel1_IRQHandler,Default_Handler + + .weak DMA1_Channel2_IRQHandler + .thumb_set DMA1_Channel2_IRQHandler,Default_Handler + + .weak DMA1_Channel3_IRQHandler + .thumb_set DMA1_Channel3_IRQHandler,Default_Handler + + .weak DMA1_Channel4_IRQHandler + .thumb_set DMA1_Channel4_IRQHandler,Default_Handler + + .weak DMA1_Channel5_IRQHandler + .thumb_set DMA1_Channel5_IRQHandler,Default_Handler + + .weak DMA1_Channel6_IRQHandler + .thumb_set DMA1_Channel6_IRQHandler,Default_Handler + + .weak DMA1_Channel7_IRQHandler + .thumb_set DMA1_Channel7_IRQHandler,Default_Handler + + .weak ADC1_2_IRQHandler + .thumb_set ADC1_2_IRQHandler,Default_Handler + + .weak USB_HP_IRQHandler + .thumb_set USB_HP_IRQHandler,Default_Handler + + .weak USB_LP_IRQHandler + .thumb_set USB_LP_IRQHandler,Default_Handler + + .weak FDCAN1_IT0_IRQHandler + .thumb_set FDCAN1_IT0_IRQHandler,Default_Handler + + .weak FDCAN1_IT1_IRQHandler + .thumb_set FDCAN1_IT1_IRQHandler,Default_Handler + + .weak EXTI9_5_IRQHandler + .thumb_set EXTI9_5_IRQHandler,Default_Handler + + .weak TIM1_BRK_TIM15_IRQHandler + .thumb_set TIM1_BRK_TIM15_IRQHandler,Default_Handler + + .weak TIM1_UP_TIM16_IRQHandler + .thumb_set TIM1_UP_TIM16_IRQHandler,Default_Handler + + .weak TIM1_TRG_COM_TIM17_IRQHandler + .thumb_set TIM1_TRG_COM_TIM17_IRQHandler,Default_Handler + + .weak TIM1_CC_IRQHandler + .thumb_set TIM1_CC_IRQHandler,Default_Handler + + .weak TIM2_IRQHandler + .thumb_set TIM2_IRQHandler,Default_Handler + + .weak TIM3_IRQHandler + .thumb_set TIM3_IRQHandler,Default_Handler + + .weak TIM4_IRQHandler + .thumb_set TIM4_IRQHandler,Default_Handler + + .weak I2C1_EV_IRQHandler + .thumb_set I2C1_EV_IRQHandler,Default_Handler + + .weak I2C1_ER_IRQHandler + .thumb_set I2C1_ER_IRQHandler,Default_Handler + + .weak I2C2_EV_IRQHandler + .thumb_set I2C2_EV_IRQHandler,Default_Handler + + .weak I2C2_ER_IRQHandler + .thumb_set I2C2_ER_IRQHandler,Default_Handler + + .weak SPI1_IRQHandler + .thumb_set SPI1_IRQHandler,Default_Handler + + .weak SPI2_IRQHandler + .thumb_set SPI2_IRQHandler,Default_Handler + + .weak USART1_IRQHandler + .thumb_set USART1_IRQHandler,Default_Handler + + .weak USART2_IRQHandler + .thumb_set USART2_IRQHandler,Default_Handler + + .weak USART3_IRQHandler + .thumb_set USART3_IRQHandler,Default_Handler + + .weak EXTI15_10_IRQHandler + .thumb_set EXTI15_10_IRQHandler,Default_Handler + + .weak RTC_Alarm_IRQHandler + .thumb_set RTC_Alarm_IRQHandler,Default_Handler + + .weak USBWakeUp_IRQHandler + .thumb_set USBWakeUp_IRQHandler,Default_Handler + + .weak TIM8_BRK_IRQHandler + .thumb_set TIM8_BRK_IRQHandler,Default_Handler + + .weak TIM8_UP_IRQHandler + .thumb_set TIM8_UP_IRQHandler,Default_Handler + + .weak TIM8_TRG_COM_IRQHandler + .thumb_set TIM8_TRG_COM_IRQHandler,Default_Handler + + .weak TIM8_CC_IRQHandler + .thumb_set TIM8_CC_IRQHandler,Default_Handler + + .weak ADC3_IRQHandler + .thumb_set ADC3_IRQHandler,Default_Handler + + .weak FMC_IRQHandler + .thumb_set FMC_IRQHandler,Default_Handler + + .weak LPTIM1_IRQHandler + .thumb_set LPTIM1_IRQHandler,Default_Handler + + .weak TIM5_IRQHandler + .thumb_set TIM5_IRQHandler,Default_Handler + + .weak SPI3_IRQHandler + .thumb_set SPI3_IRQHandler,Default_Handler + + .weak UART4_IRQHandler + .thumb_set UART4_IRQHandler,Default_Handler + + .weak UART5_IRQHandler + .thumb_set UART5_IRQHandler,Default_Handler + + .weak TIM6_DAC_IRQHandler + .thumb_set TIM6_DAC_IRQHandler,Default_Handler + + .weak TIM7_DAC_IRQHandler + .thumb_set TIM7_DAC_IRQHandler,Default_Handler + + .weak DMA2_Channel1_IRQHandler + .thumb_set DMA2_Channel1_IRQHandler,Default_Handler + + .weak DMA2_Channel2_IRQHandler + .thumb_set DMA2_Channel2_IRQHandler,Default_Handler + + .weak DMA2_Channel3_IRQHandler + .thumb_set DMA2_Channel3_IRQHandler,Default_Handler + + .weak DMA2_Channel4_IRQHandler + .thumb_set DMA2_Channel4_IRQHandler,Default_Handler + + .weak DMA2_Channel5_IRQHandler + .thumb_set DMA2_Channel5_IRQHandler,Default_Handler + + .weak ADC4_IRQHandler + .thumb_set ADC4_IRQHandler,Default_Handler + + .weak ADC5_IRQHandler + .thumb_set ADC5_IRQHandler,Default_Handler + + .weak UCPD1_IRQHandler + .thumb_set UCPD1_IRQHandler,Default_Handler + + .weak COMP1_2_3_IRQHandler + .thumb_set COMP1_2_3_IRQHandler,Default_Handler + + .weak COMP4_5_6_IRQHandler + .thumb_set COMP4_5_6_IRQHandler,Default_Handler + + .weak COMP7_IRQHandler + .thumb_set COMP7_IRQHandler,Default_Handler + + .weak HRTIM1_Master_IRQHandler + .thumb_set HRTIM1_Master_IRQHandler,Default_Handler + + .weak HRTIM1_TIMA_IRQHandler + .thumb_set HRTIM1_TIMA_IRQHandler,Default_Handler + + .weak HRTIM1_TIMB_IRQHandler + .thumb_set HRTIM1_TIMB_IRQHandler,Default_Handler + + .weak HRTIM1_TIMC_IRQHandler + .thumb_set HRTIM1_TIMC_IRQHandler,Default_Handler + + .weak HRTIM1_TIMD_IRQHandler + .thumb_set HRTIM1_TIMD_IRQHandler,Default_Handler + + .weak HRTIM1_TIME_IRQHandler + .thumb_set HRTIM1_TIME_IRQHandler,Default_Handler + + .weak HRTIM1_FLT_IRQHandler + .thumb_set HRTIM1_FLT_IRQHandler,Default_Handler + + .weak HRTIM1_TIMF_IRQHandler + .thumb_set HRTIM1_TIMF_IRQHandler,Default_Handler + + .weak CRS_IRQHandler + .thumb_set CRS_IRQHandler,Default_Handler + + .weak SAI1_IRQHandler + .thumb_set SAI1_IRQHandler,Default_Handler + + .weak TIM20_BRK_IRQHandler + .thumb_set TIM20_BRK_IRQHandler,Default_Handler + + .weak TIM20_UP_IRQHandler + .thumb_set TIM20_UP_IRQHandler,Default_Handler + + .weak TIM20_TRG_COM_IRQHandler + .thumb_set TIM20_TRG_COM_IRQHandler,Default_Handler + + .weak TIM20_CC_IRQHandler + .thumb_set TIM20_CC_IRQHandler,Default_Handler + + .weak FPU_IRQHandler + .thumb_set FPU_IRQHandler,Default_Handler + + .weak I2C4_EV_IRQHandler + .thumb_set I2C4_EV_IRQHandler,Default_Handler + + .weak I2C4_ER_IRQHandler + .thumb_set I2C4_ER_IRQHandler,Default_Handler + + .weak SPI4_IRQHandler + .thumb_set SPI4_IRQHandler,Default_Handler + + .weak FDCAN2_IT0_IRQHandler + .thumb_set FDCAN2_IT0_IRQHandler,Default_Handler + + .weak FDCAN2_IT1_IRQHandler + .thumb_set FDCAN2_IT1_IRQHandler,Default_Handler + + .weak FDCAN3_IT0_IRQHandler + .thumb_set FDCAN3_IT0_IRQHandler,Default_Handler + + .weak FDCAN3_IT1_IRQHandler + .thumb_set FDCAN3_IT1_IRQHandler,Default_Handler + + .weak RNG_IRQHandler + .thumb_set RNG_IRQHandler,Default_Handler + + .weak LPUART1_IRQHandler + .thumb_set LPUART1_IRQHandler,Default_Handler + + .weak I2C3_EV_IRQHandler + .thumb_set I2C3_EV_IRQHandler,Default_Handler + + .weak I2C3_ER_IRQHandler + .thumb_set I2C3_ER_IRQHandler,Default_Handler + + .weak DMAMUX_OVR_IRQHandler + .thumb_set DMAMUX_OVR_IRQHandler,Default_Handler + + .weak QUADSPI_IRQHandler + .thumb_set QUADSPI_IRQHandler,Default_Handler + + .weak DMA1_Channel8_IRQHandler + .thumb_set DMA1_Channel8_IRQHandler,Default_Handler + + .weak DMA2_Channel6_IRQHandler + .thumb_set DMA2_Channel6_IRQHandler,Default_Handler + + .weak DMA2_Channel7_IRQHandler + .thumb_set DMA2_Channel7_IRQHandler,Default_Handler + + .weak DMA2_Channel8_IRQHandler + .thumb_set DMA2_Channel8_IRQHandler,Default_Handler + + .weak CORDIC_IRQHandler + .thumb_set CORDIC_IRQHandler,Default_Handler + + .weak FMAC_IRQHandler + .thumb_set FMAC_IRQHandler,Default_Handler +