From c0fa76dca5d791fcf5e5566e368a2999c9bec782 Mon Sep 17 00:00:00 2001 From: captainwerty Date: Thu, 9 Apr 2026 20:19:07 -0700 Subject: [PATCH 01/21] changes --- CCU/Application/Inc/can_cfg.h | 2 +- CCU/Application/Src/CANDler.c | 6 +- CCU/Application/Src/StateTicks.c | 2 +- CCU/CMakeLists.txt | 2 - CCU/Core/Inc/dma.h | 51 ------- CCU/Core/Inc/fdcan.h | 54 ------- CCU/Core/Src/dma.c | 51 ------- CCU/Core/Src/fdcan.c | 237 ------------------------------- CCU/Core/Src/main.c | 5 +- 9 files changed, 5 insertions(+), 405 deletions(-) delete mode 100644 CCU/Core/Inc/dma.h delete mode 100644 CCU/Core/Inc/fdcan.h delete mode 100644 CCU/Core/Src/dma.c delete mode 100644 CCU/Core/Src/fdcan.c diff --git a/CCU/Application/Inc/can_cfg.h b/CCU/Application/Inc/can_cfg.h index 0e987b82d..cbcb95a2c 100644 --- a/CCU/Application/Inc/can_cfg.h +++ b/CCU/Application/Inc/can_cfg.h @@ -2,6 +2,6 @@ #define CAN_CFG_H #define USECAN1 -#define TX_BUFFER_1_SIZE 10 +#define TX_BUFFER_1_SIZE 16 #endif diff --git a/CCU/Application/Src/CANDler.c b/CCU/Application/Src/CANDler.c index 680e7876a..91d92631a 100644 --- a/CCU/Application/Src/CANDler.c +++ b/CCU/Application/Src/CANDler.c @@ -23,8 +23,6 @@ void Read_CAN(uint32_t ID, void *data, uint32_t size) switch (messageId) { case GRCAN_BCU_STATUS_2: - // FIXME: if bad message do a thing - if (size != sizeof(GRCAN_BCU_STATUS_2_MSG)) { LOGOMATIC("Bad CCU CAN Rx length! ID: %lu, Size %lu\n", ID, size); break; @@ -172,9 +170,7 @@ void SendPrechargeStatus(CCU_StateData *state_data) msg.data[0] = (state_data->BCU_PRECHARGE_SET_TS_ACTIVE); - if (sizeof(msg) != sizeof(GRCAN_BCU_PRECHARGE_MSG)) { - LOGOMATIC("Bad CCU CAN Tx length!, Size %u\n", sizeof(msg)); - } + LOGOMATIC("PRECHARGE SET: %d\n", state_data->BCU_PRECHARGE_SET_TS_ACTIVE); can_send(primary_can, &msg); diff --git a/CCU/Application/Src/StateTicks.c b/CCU/Application/Src/StateTicks.c index 2964d5a3f..78b73a00e 100644 --- a/CCU/Application/Src/StateTicks.c +++ b/CCU/Application/Src/StateTicks.c @@ -41,7 +41,7 @@ void STATE_IDLE(CCU_StateData *state_data) if (CriticalError(state_data)) { anyErrors = 1; setSoftwareLatch(0, state_data); - LOGOMATIC("Critical Error Occured; State set to IDLE \n"); + LOGOMATIC("Critical Error Occured!\n"); }; if (!anyErrors && state_data->recv_charge_cmd) { diff --git a/CCU/CMakeLists.txt b/CCU/CMakeLists.txt index 839453ca1..d49ed63dd 100644 --- a/CCU/CMakeLists.txt +++ b/CCU/CMakeLists.txt @@ -60,8 +60,6 @@ target_sources( ${GR_PROJECT_NAME}_USER_CODE INTERFACE # Core - Core/Src/dma.c - Core/Src/fdcan.c Core/Src/gpio.c Core/Src/main.c Core/Src/stm32g4xx_hal_msp.c diff --git a/CCU/Core/Inc/dma.h b/CCU/Core/Inc/dma.h deleted file mode 100644 index ae819cab4..000000000 --- a/CCU/Core/Inc/dma.h +++ /dev/null @@ -1,51 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file dma.h - * @brief This file contains all the function prototypes for - * the dma.c file - ****************************************************************************** - * @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. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __DMA_H__ -#define __DMA_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* DMA memory to memory transfer handles -------------------------------------*/ - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_DMA_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __DMA_H__ */ diff --git a/CCU/Core/Inc/fdcan.h b/CCU/Core/Inc/fdcan.h deleted file mode 100644 index 9652dd8ad..000000000 --- a/CCU/Core/Inc/fdcan.h +++ /dev/null @@ -1,54 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file fdcan.h - * @brief This file contains all the function prototypes for - * the fdcan.c file - ****************************************************************************** - * @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. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __FDCAN_H__ -#define __FDCAN_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern FDCAN_HandleTypeDef hfdcan1; - -extern FDCAN_HandleTypeDef hfdcan2; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_FDCAN1_Init(void); -void MX_FDCAN2_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __FDCAN_H__ */ diff --git a/CCU/Core/Src/dma.c b/CCU/Core/Src/dma.c deleted file mode 100644 index 2e480d9a2..000000000 --- a/CCU/Core/Src/dma.c +++ /dev/null @@ -1,51 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file dma.c - * @brief This file provides code for the configuration - * of all the requested memory to memory DMA transfers. - ****************************************************************************** - * @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. - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "dma.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/*----------------------------------------------------------------------------*/ -/* Configure DMA */ -/*----------------------------------------------------------------------------*/ - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/** - * 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); -} - -/* USER CODE BEGIN 2 */ - -/* USER CODE END 2 */ diff --git a/CCU/Core/Src/fdcan.c b/CCU/Core/Src/fdcan.c deleted file mode 100644 index 2a66c7caf..000000000 --- a/CCU/Core/Src/fdcan.c +++ /dev/null @@ -1,237 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file fdcan.c - * @brief This file provides code for the configuration - * of the FDCAN instances. - ****************************************************************************** - * @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. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Includes ------------------------------------------------------------------*/ -#include "fdcan.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -FDCAN_HandleTypeDef hfdcan1; -FDCAN_HandleTypeDef hfdcan2; - -/* FDCAN1 init function */ -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 */ -} -/* 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 */ -} - -static uint32_t HAL_RCC_FDCAN_CLK_ENABLED = 0; - -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 */ - } -} - -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 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/CCU/Core/Src/main.c b/CCU/Core/Src/main.c index d5dfc9de2..8be529ef4 100644 --- a/CCU/Core/Src/main.c +++ b/CCU/Core/Src/main.c @@ -124,7 +124,6 @@ int main(void) /* Initialize all configured peripherals */ MX_GPIO_Init(); - MX_FDCAN1_Init(); /* USER CODE BEGIN 2 */ // Initialize CAN @@ -139,12 +138,12 @@ int main(void) setSoftwareLatch(1, &state_data); while (1) { /*LL_GPIO_SetOutputPin (GPIOC, LL_GPIO_PIN_13);*/ - LL_mDelay(100); + // Initialize SoftwareLatch High CCU_State_Tick(&state_data); - LL_mDelay(200); + LL_mDelay(5); /* USER CODE END 3 */ } From 7a0ea03dfbce7daccacce8534d9730bf8992e35b Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 10 Apr 2026 03:25:35 +0000 Subject: [PATCH 02/21] Automatic Clang-Format: Standardized formatting automatically --- CCU/Application/Src/CANDler.c | 1 - CCU/Core/Src/main.c | 1 - 2 files changed, 2 deletions(-) diff --git a/CCU/Application/Src/CANDler.c b/CCU/Application/Src/CANDler.c index 91d92631a..6ef42f9fc 100644 --- a/CCU/Application/Src/CANDler.c +++ b/CCU/Application/Src/CANDler.c @@ -170,7 +170,6 @@ void SendPrechargeStatus(CCU_StateData *state_data) msg.data[0] = (state_data->BCU_PRECHARGE_SET_TS_ACTIVE); - LOGOMATIC("PRECHARGE SET: %d\n", state_data->BCU_PRECHARGE_SET_TS_ACTIVE); can_send(primary_can, &msg); diff --git a/CCU/Core/Src/main.c b/CCU/Core/Src/main.c index 8be529ef4..31c798e9c 100644 --- a/CCU/Core/Src/main.c +++ b/CCU/Core/Src/main.c @@ -139,7 +139,6 @@ int main(void) while (1) { /*LL_GPIO_SetOutputPin (GPIOC, LL_GPIO_PIN_13);*/ - // Initialize SoftwareLatch High CCU_State_Tick(&state_data); From 3ce877ddc3819dba73d8ee49ef707feb1f3a2f95 Mon Sep 17 00:00:00 2001 From: captainwerty Date: Thu, 9 Apr 2026 20:27:48 -0700 Subject: [PATCH 03/21] Changed default case in switch statement to set precharge to 0 --- CCU/Application/Src/StateTicks.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CCU/Application/Src/StateTicks.c b/CCU/Application/Src/StateTicks.c index 78b73a00e..3ce359892 100644 --- a/CCU/Application/Src/StateTicks.c +++ b/CCU/Application/Src/StateTicks.c @@ -30,7 +30,10 @@ void CCU_State_Tick(CCU_StateData *state_data) break; default: + state_data->BCU_PRECHARGE_SET_TS_ACTIVE = 0; state_data->state = CCU_STATE_IDLE; + SendPrechargeStatus(state_data); + setSoftwareLatch(0, state_data); break; }; } From 5246b172f5337a1cc581bd5dfde32171e278b418 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Thu, 9 Apr 2026 20:34:23 -0700 Subject: [PATCH 04/21] removing dma and fdcan include from main --- CCU/Core/Src/main.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CCU/Core/Src/main.c b/CCU/Core/Src/main.c index 31c798e9c..173f8db53 100644 --- a/CCU/Core/Src/main.c +++ b/CCU/Core/Src/main.c @@ -24,8 +24,6 @@ #include "StateMachine.h" #include "StateTicks.h" #include "StateUtils.h" -#include "dma.h" -#include "fdcan.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ @@ -157,11 +155,11 @@ void SystemClock_Config(void) LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); + LL_RCC_HSE_Enable(); /* Wait till HSI is ready */ while (LL_RCC_HSI_IsReady() != 1) {} - LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_HSE_SetCalibTrimming(64); LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_4, 85, LL_RCC_PLLR_DIV_2); LL_RCC_PLL_EnableDomain_SYS(); LL_RCC_PLL_Enable(); From 480da9b648e07c2e5f5bb532e69f17f391fe4363 Mon Sep 17 00:00:00 2001 From: Amy Saffer Date: Thu, 9 Apr 2026 20:59:42 -0700 Subject: [PATCH 05/21] Removed some unnecessary comments --- CCU/Application/Inc/CCUStateData.h | 1 - CCU/Application/Src/StateTicks.c | 3 --- CCU/Core/Src/main.c | 4 +--- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/CCU/Application/Inc/CCUStateData.h b/CCU/Application/Inc/CCUStateData.h index 405c0e142..1d75ee414 100644 --- a/CCU/Application/Inc/CCUStateData.h +++ b/CCU/Application/Inc/CCUStateData.h @@ -8,7 +8,6 @@ typedef struct { CCU_STATE state; - // name lwk might be too long bool recv_charge_cmd; // BCU_STATUS_2 diff --git a/CCU/Application/Src/StateTicks.c b/CCU/Application/Src/StateTicks.c index 3ce359892..4d83a3dbe 100644 --- a/CCU/Application/Src/StateTicks.c +++ b/CCU/Application/Src/StateTicks.c @@ -15,17 +15,14 @@ void CCU_State_Tick(CCU_StateData *state_data) LOGOMATIC("CCU Current State: %d\n", state_data->state); - // FIXME: switch (state_data->state) { // if given an error, switch state to IDLE; warnings will remain placeholders until better understood // General checks for State Transition, if any error detected, transition back to IDLE state case CCU_STATE_IDLE: - // TODO: Create IDLE func elsewhere & Call state IDLE function STATE_IDLE(state_data); break; case CCU_STATE_CHARGING: - // TODO: Create Charging func elsewhere & Call charging func STATE_CHARGING(state_data); break; diff --git a/CCU/Core/Src/main.c b/CCU/Core/Src/main.c index 173f8db53..b6e98cc03 100644 --- a/CCU/Core/Src/main.c +++ b/CCU/Core/Src/main.c @@ -133,11 +133,9 @@ int main(void) /* Infinite loop */ /* USER CODE BEGIN WHILE */ + // Initialize SoftwareLatch High setSoftwareLatch(1, &state_data); while (1) { - /*LL_GPIO_SetOutputPin (GPIOC, LL_GPIO_PIN_13);*/ - - // Initialize SoftwareLatch High CCU_State_Tick(&state_data); LL_mDelay(5); From e62f3d64512771390fe60588f55f1cf2fa417fc5 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Thu, 9 Apr 2026 22:01:03 -0700 Subject: [PATCH 06/21] SystemClock HSI to HSE --- CCU/Core/Src/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CCU/Core/Src/main.c b/CCU/Core/Src/main.c index b6e98cc03..333af0819 100644 --- a/CCU/Core/Src/main.c +++ b/CCU/Core/Src/main.c @@ -155,10 +155,10 @@ void SystemClock_Config(void) LL_PWR_EnableRange1BoostMode(); LL_RCC_HSE_Enable(); /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} + while (LL_RCC_HSE_IsReady() != 1) {} - LL_RCC_HSE_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_4, 85, LL_RCC_PLLR_DIV_2); + 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 */ From a81153b60cd61bf9d7bfe9c804101f44e15071f9 Mon Sep 17 00:00:00 2001 From: ana_carthikeyan Date: Thu, 9 Apr 2026 22:02:38 -0700 Subject: [PATCH 07/21] VCP state dump log is now functional --- CCU/Application/Inc/StateUtils.h | 1 + CCU/Application/Src/StateUtils.c | 34 ++++++++++++++++++++++++++++++++ CCU/Core/Src/stm32g4xx_it.c | 31 ++--------------------------- 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/CCU/Application/Inc/StateUtils.h b/CCU/Application/Inc/StateUtils.h index 296638bb8..6207585b0 100644 --- a/CCU/Application/Inc/StateUtils.h +++ b/CCU/Application/Inc/StateUtils.h @@ -10,6 +10,7 @@ #define STATE_UTILS_H void setSoftwareLatch(bool close, CCU_StateData *state_data); +void VCP_StateDump(const CCU_StateData *state_data); bool CriticalError(const CCU_StateData *state_data); bool BCU_Warnings(const CCU_StateData *state_data); #endif diff --git a/CCU/Application/Src/StateUtils.c b/CCU/Application/Src/StateUtils.c index 13d4d1768..2764160ed 100644 --- a/CCU/Application/Src/StateUtils.c +++ b/CCU/Application/Src/StateUtils.c @@ -65,3 +65,37 @@ bool CriticalError(const CCU_StateData *state_data) return false; } } + +void VCP_StateDump(const CCU_StateData *state_data) { + LOGOMATIC("\n========== CCU STATE DUMP ==========\n"); + + LOGOMATIC("state: %d\n", state_data->state); + LOGOMATIC("recv_charge_cmd: %d\n", state_data->recv_charge_cmd); + + LOGOMATIC("\n--- BCU_STATUS_2 ---\n"); + LOGOMATIC("20V: %u\n", state_data->BCU_S2_20Volt); + LOGOMATIC("12V: %u\n", state_data->BCU_S2_12Volt); + LOGOMATIC("SDC Volt: %u\n", state_data->BCU_S2_SDC_Volt); + LOGOMATIC("Min Cell Volt: %u\n", state_data->BCU_S2_MIN_CELL_Volt); + LOGOMATIC("Max Cell Temp: %u\n", state_data->BCU_S2_MAX_CELL_TEMP); + + LOGOMATIC("\n--- Errors ---\n"); + LOGOMATIC("OVERTEMP: %d\n", state_data->BCU_S2_OVERTEMP_ERROR); + LOGOMATIC("OVERVOLT: %d\n", state_data->BCU_S2_OVERVOLT_ERROR); + LOGOMATIC("UNDERVOLT: %d\n", state_data->BCU_S2_UNDERVOLT_ERROR); + LOGOMATIC("OVERCURR: %d\n", state_data->BCU_S2_OVERCURR_ERROR); + LOGOMATIC("UNDERCURR: %d\n", state_data->BCU_S2_UNDERCURR_ERROR); + + LOGOMATIC("\n--- Warnings ---\n"); + LOGOMATIC("UNDER20V: %d\n", state_data->BCU_S2_UNDER20v_WARNING); + LOGOMATIC("UNDER12V: %d\n", state_data->BCU_S2_UNDER12v_WARNING); + LOGOMATIC("UNDERVOLT SDC: %d\n", state_data->BCU_S2_UNDERVOLTSDC_WARNING); + + LOGOMATIC("\n--- State Bits ---\n"); + LOGOMATIC("SOFTWARE LATCH: %d\n", state_data->BCU_S2_SOFTWARE_LATCH); + LOGOMATIC("PRECHARGE TS ACTIVE: %d\n", state_data->BCU_PRECHARGE_SET_TS_ACTIVE); + + LOGOMATIC("====================================\n\n"); + + +} diff --git a/CCU/Core/Src/stm32g4xx_it.c b/CCU/Core/Src/stm32g4xx_it.c index f6153024c..9b9dadcec 100644 --- a/CCU/Core/Src/stm32g4xx_it.c +++ b/CCU/Core/Src/stm32g4xx_it.c @@ -25,6 +25,7 @@ /* USER CODE BEGIN Includes */ #include "CCUStateData.h" #include "Logomatic.h" +#include "StateUtils.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -205,36 +206,8 @@ void USART2_IRQHandler(void) LL_USART_TransmitData8(USART2, 'C'); } else if (receivedData == '?') { - LOGOMATIC("Received State Dump command\n"); - LOGOMATIC("\n========== CCU STATE DUMP ==========\n"); + VCP_StateDump(&state_data); - LOGOMATIC("state: %d\n", state_data.state); - LOGOMATIC("recv_charge_cmd: %d\n", state_data.recv_charge_cmd); - - LOGOMATIC("\n--- BCU_STATUS_2 ---\n"); - LOGOMATIC("20V: %u\n", state_data.BCU_S2_20Volt); - LOGOMATIC("12V: %u\n", state_data.BCU_S2_12Volt); - LOGOMATIC("SDC Volt: %u\n", state_data.BCU_S2_SDC_Volt); - LOGOMATIC("Min Cell Volt: %u\n", state_data.BCU_S2_MIN_CELL_Volt); - LOGOMATIC("Max Cell Temp: %u\n", state_data.BCU_S2_MAX_CELL_TEMP); - - LOGOMATIC("\n--- Errors ---\n"); - LOGOMATIC("OVERTEMP: %d\n", state_data.BCU_S2_OVERTEMP_ERROR); - LOGOMATIC("OVERVOLT: %d\n", state_data.BCU_S2_OVERVOLT_ERROR); - LOGOMATIC("UNDERVOLT: %d\n", state_data.BCU_S2_UNDERVOLT_ERROR); - LOGOMATIC("OVERCURR: %d\n", state_data.BCU_S2_OVERCURR_ERROR); - LOGOMATIC("UNDERCURR: %d\n", state_data.BCU_S2_UNDERCURR_ERROR); - - LOGOMATIC("\n--- Warnings ---\n"); - LOGOMATIC("UNDER20V: %d\n", state_data.BCU_S2_UNDER20v_WARNING); - LOGOMATIC("UNDER12V: %d\n", state_data.BCU_S2_UNDER12v_WARNING); - LOGOMATIC("UNDERVOLT SDC: %d\n", state_data.BCU_S2_UNDERVOLTSDC_WARNING); - - LOGOMATIC("\n--- State Bits ---\n"); - LOGOMATIC("SOFTWARE LATCH: %d\n", state_data.BCU_S2_SOFTWARE_LATCH); - LOGOMATIC("PRECHARGE TS ACTIVE: %d\n", state_data.BCU_PRECHARGE_SET_TS_ACTIVE); - - LOGOMATIC("====================================\n\n"); LL_USART_TransmitData8(USART2, '?'); From 5cb7dd5bb3bcf26feb0f541cee1d0f3e2304e138 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 10 Apr 2026 05:05:16 +0000 Subject: [PATCH 08/21] Automatic Clang-Format: Standardized formatting automatically --- CCU/Application/Src/StateUtils.c | 5 ++--- CCU/Core/Src/stm32g4xx_it.c | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/CCU/Application/Src/StateUtils.c b/CCU/Application/Src/StateUtils.c index 2764160ed..3e0bf8322 100644 --- a/CCU/Application/Src/StateUtils.c +++ b/CCU/Application/Src/StateUtils.c @@ -66,7 +66,8 @@ bool CriticalError(const CCU_StateData *state_data) } } -void VCP_StateDump(const CCU_StateData *state_data) { +void VCP_StateDump(const CCU_StateData *state_data) +{ LOGOMATIC("\n========== CCU STATE DUMP ==========\n"); LOGOMATIC("state: %d\n", state_data->state); @@ -96,6 +97,4 @@ void VCP_StateDump(const CCU_StateData *state_data) { LOGOMATIC("PRECHARGE TS ACTIVE: %d\n", state_data->BCU_PRECHARGE_SET_TS_ACTIVE); LOGOMATIC("====================================\n\n"); - - } diff --git a/CCU/Core/Src/stm32g4xx_it.c b/CCU/Core/Src/stm32g4xx_it.c index 9b9dadcec..a7dea7889 100644 --- a/CCU/Core/Src/stm32g4xx_it.c +++ b/CCU/Core/Src/stm32g4xx_it.c @@ -208,7 +208,6 @@ void USART2_IRQHandler(void) VCP_StateDump(&state_data); - LL_USART_TransmitData8(USART2, '?'); } else { From 77618e723e7f18e71fa1a303dc038c5736d338cb Mon Sep 17 00:00:00 2001 From: David Wilson Date: Thu, 9 Apr 2026 22:17:43 -0700 Subject: [PATCH 09/21] removed log for every state tick --- CCU/Application/Src/StateTicks.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/CCU/Application/Src/StateTicks.c b/CCU/Application/Src/StateTicks.c index 4d83a3dbe..fe07639c8 100644 --- a/CCU/Application/Src/StateTicks.c +++ b/CCU/Application/Src/StateTicks.c @@ -13,8 +13,6 @@ void CCU_State_Tick(CCU_StateData *state_data) { - LOGOMATIC("CCU Current State: %d\n", state_data->state); - switch (state_data->state) { // if given an error, switch state to IDLE; warnings will remain placeholders until better understood // General checks for State Transition, if any error detected, transition back to IDLE state From 421f2d78896659cf5bd3c5a356d03e5bb972f99f Mon Sep 17 00:00:00 2001 From: captainwerty Date: Thu, 9 Apr 2026 20:19:07 -0700 Subject: [PATCH 10/21] changes --- CCU/Application/Inc/can_cfg.h | 2 +- CCU/Application/Src/CANDler.c | 6 +- CCU/Application/Src/StateTicks.c | 2 +- CCU/CMakeLists.txt | 2 - CCU/Core/Inc/dma.h | 51 ------- CCU/Core/Inc/fdcan.h | 54 ------- CCU/Core/Src/dma.c | 51 ------- CCU/Core/Src/fdcan.c | 237 ------------------------------- CCU/Core/Src/main.c | 5 +- 9 files changed, 5 insertions(+), 405 deletions(-) delete mode 100644 CCU/Core/Inc/dma.h delete mode 100644 CCU/Core/Inc/fdcan.h delete mode 100644 CCU/Core/Src/dma.c delete mode 100644 CCU/Core/Src/fdcan.c diff --git a/CCU/Application/Inc/can_cfg.h b/CCU/Application/Inc/can_cfg.h index 0e987b82d..cbcb95a2c 100644 --- a/CCU/Application/Inc/can_cfg.h +++ b/CCU/Application/Inc/can_cfg.h @@ -2,6 +2,6 @@ #define CAN_CFG_H #define USECAN1 -#define TX_BUFFER_1_SIZE 10 +#define TX_BUFFER_1_SIZE 16 #endif diff --git a/CCU/Application/Src/CANDler.c b/CCU/Application/Src/CANDler.c index 680e7876a..91d92631a 100644 --- a/CCU/Application/Src/CANDler.c +++ b/CCU/Application/Src/CANDler.c @@ -23,8 +23,6 @@ void Read_CAN(uint32_t ID, void *data, uint32_t size) switch (messageId) { case GRCAN_BCU_STATUS_2: - // FIXME: if bad message do a thing - if (size != sizeof(GRCAN_BCU_STATUS_2_MSG)) { LOGOMATIC("Bad CCU CAN Rx length! ID: %lu, Size %lu\n", ID, size); break; @@ -172,9 +170,7 @@ void SendPrechargeStatus(CCU_StateData *state_data) msg.data[0] = (state_data->BCU_PRECHARGE_SET_TS_ACTIVE); - if (sizeof(msg) != sizeof(GRCAN_BCU_PRECHARGE_MSG)) { - LOGOMATIC("Bad CCU CAN Tx length!, Size %u\n", sizeof(msg)); - } + LOGOMATIC("PRECHARGE SET: %d\n", state_data->BCU_PRECHARGE_SET_TS_ACTIVE); can_send(primary_can, &msg); diff --git a/CCU/Application/Src/StateTicks.c b/CCU/Application/Src/StateTicks.c index 2964d5a3f..78b73a00e 100644 --- a/CCU/Application/Src/StateTicks.c +++ b/CCU/Application/Src/StateTicks.c @@ -41,7 +41,7 @@ void STATE_IDLE(CCU_StateData *state_data) if (CriticalError(state_data)) { anyErrors = 1; setSoftwareLatch(0, state_data); - LOGOMATIC("Critical Error Occured; State set to IDLE \n"); + LOGOMATIC("Critical Error Occured!\n"); }; if (!anyErrors && state_data->recv_charge_cmd) { diff --git a/CCU/CMakeLists.txt b/CCU/CMakeLists.txt index 839453ca1..d49ed63dd 100644 --- a/CCU/CMakeLists.txt +++ b/CCU/CMakeLists.txt @@ -60,8 +60,6 @@ target_sources( ${GR_PROJECT_NAME}_USER_CODE INTERFACE # Core - Core/Src/dma.c - Core/Src/fdcan.c Core/Src/gpio.c Core/Src/main.c Core/Src/stm32g4xx_hal_msp.c diff --git a/CCU/Core/Inc/dma.h b/CCU/Core/Inc/dma.h deleted file mode 100644 index ae819cab4..000000000 --- a/CCU/Core/Inc/dma.h +++ /dev/null @@ -1,51 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file dma.h - * @brief This file contains all the function prototypes for - * the dma.c file - ****************************************************************************** - * @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. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __DMA_H__ -#define __DMA_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* DMA memory to memory transfer handles -------------------------------------*/ - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_DMA_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __DMA_H__ */ diff --git a/CCU/Core/Inc/fdcan.h b/CCU/Core/Inc/fdcan.h deleted file mode 100644 index 9652dd8ad..000000000 --- a/CCU/Core/Inc/fdcan.h +++ /dev/null @@ -1,54 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file fdcan.h - * @brief This file contains all the function prototypes for - * the fdcan.c file - ****************************************************************************** - * @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. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __FDCAN_H__ -#define __FDCAN_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern FDCAN_HandleTypeDef hfdcan1; - -extern FDCAN_HandleTypeDef hfdcan2; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_FDCAN1_Init(void); -void MX_FDCAN2_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __FDCAN_H__ */ diff --git a/CCU/Core/Src/dma.c b/CCU/Core/Src/dma.c deleted file mode 100644 index 2e480d9a2..000000000 --- a/CCU/Core/Src/dma.c +++ /dev/null @@ -1,51 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file dma.c - * @brief This file provides code for the configuration - * of all the requested memory to memory DMA transfers. - ****************************************************************************** - * @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. - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "dma.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/*----------------------------------------------------------------------------*/ -/* Configure DMA */ -/*----------------------------------------------------------------------------*/ - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/** - * 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); -} - -/* USER CODE BEGIN 2 */ - -/* USER CODE END 2 */ diff --git a/CCU/Core/Src/fdcan.c b/CCU/Core/Src/fdcan.c deleted file mode 100644 index 2a66c7caf..000000000 --- a/CCU/Core/Src/fdcan.c +++ /dev/null @@ -1,237 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file fdcan.c - * @brief This file provides code for the configuration - * of the FDCAN instances. - ****************************************************************************** - * @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. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Includes ------------------------------------------------------------------*/ -#include "fdcan.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -FDCAN_HandleTypeDef hfdcan1; -FDCAN_HandleTypeDef hfdcan2; - -/* FDCAN1 init function */ -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 */ -} -/* 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 */ -} - -static uint32_t HAL_RCC_FDCAN_CLK_ENABLED = 0; - -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 */ - } -} - -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 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/CCU/Core/Src/main.c b/CCU/Core/Src/main.c index d5dfc9de2..8be529ef4 100644 --- a/CCU/Core/Src/main.c +++ b/CCU/Core/Src/main.c @@ -124,7 +124,6 @@ int main(void) /* Initialize all configured peripherals */ MX_GPIO_Init(); - MX_FDCAN1_Init(); /* USER CODE BEGIN 2 */ // Initialize CAN @@ -139,12 +138,12 @@ int main(void) setSoftwareLatch(1, &state_data); while (1) { /*LL_GPIO_SetOutputPin (GPIOC, LL_GPIO_PIN_13);*/ - LL_mDelay(100); + // Initialize SoftwareLatch High CCU_State_Tick(&state_data); - LL_mDelay(200); + LL_mDelay(5); /* USER CODE END 3 */ } From adf0c809c2b1058134998205092ef4d1214b90a4 Mon Sep 17 00:00:00 2001 From: captainwerty Date: Thu, 9 Apr 2026 20:27:48 -0700 Subject: [PATCH 11/21] Changed default case in switch statement to set precharge to 0 --- CCU/Application/Src/StateTicks.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CCU/Application/Src/StateTicks.c b/CCU/Application/Src/StateTicks.c index 78b73a00e..3ce359892 100644 --- a/CCU/Application/Src/StateTicks.c +++ b/CCU/Application/Src/StateTicks.c @@ -30,7 +30,10 @@ void CCU_State_Tick(CCU_StateData *state_data) break; default: + state_data->BCU_PRECHARGE_SET_TS_ACTIVE = 0; state_data->state = CCU_STATE_IDLE; + SendPrechargeStatus(state_data); + setSoftwareLatch(0, state_data); break; }; } From 5bdc88174c03882759078aa0e6a6706241b9c47c Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 10 Apr 2026 03:25:35 +0000 Subject: [PATCH 12/21] Automatic Clang-Format: Standardized formatting automatically --- CCU/Application/Src/CANDler.c | 1 - CCU/Core/Src/main.c | 1 - 2 files changed, 2 deletions(-) diff --git a/CCU/Application/Src/CANDler.c b/CCU/Application/Src/CANDler.c index 91d92631a..6ef42f9fc 100644 --- a/CCU/Application/Src/CANDler.c +++ b/CCU/Application/Src/CANDler.c @@ -170,7 +170,6 @@ void SendPrechargeStatus(CCU_StateData *state_data) msg.data[0] = (state_data->BCU_PRECHARGE_SET_TS_ACTIVE); - LOGOMATIC("PRECHARGE SET: %d\n", state_data->BCU_PRECHARGE_SET_TS_ACTIVE); can_send(primary_can, &msg); diff --git a/CCU/Core/Src/main.c b/CCU/Core/Src/main.c index 8be529ef4..31c798e9c 100644 --- a/CCU/Core/Src/main.c +++ b/CCU/Core/Src/main.c @@ -139,7 +139,6 @@ int main(void) while (1) { /*LL_GPIO_SetOutputPin (GPIOC, LL_GPIO_PIN_13);*/ - // Initialize SoftwareLatch High CCU_State_Tick(&state_data); From 6c1f2bd4c900cbaeed9bd85260dfffe9bf6a3988 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Thu, 9 Apr 2026 20:34:23 -0700 Subject: [PATCH 13/21] removing dma and fdcan include from main --- CCU/Core/Src/main.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CCU/Core/Src/main.c b/CCU/Core/Src/main.c index 31c798e9c..173f8db53 100644 --- a/CCU/Core/Src/main.c +++ b/CCU/Core/Src/main.c @@ -24,8 +24,6 @@ #include "StateMachine.h" #include "StateTicks.h" #include "StateUtils.h" -#include "dma.h" -#include "fdcan.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ @@ -157,11 +155,11 @@ void SystemClock_Config(void) LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); + LL_RCC_HSE_Enable(); /* Wait till HSI is ready */ while (LL_RCC_HSI_IsReady() != 1) {} - LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_HSE_SetCalibTrimming(64); LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_4, 85, LL_RCC_PLLR_DIV_2); LL_RCC_PLL_EnableDomain_SYS(); LL_RCC_PLL_Enable(); From 9a8b3f40e4eed1fc4e107656a5211ca34c68a18e Mon Sep 17 00:00:00 2001 From: Amy Saffer Date: Thu, 9 Apr 2026 20:59:42 -0700 Subject: [PATCH 14/21] Removed some unnecessary comments --- CCU/Application/Inc/CCUStateData.h | 1 - CCU/Application/Src/StateTicks.c | 3 --- CCU/Core/Src/main.c | 4 +--- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/CCU/Application/Inc/CCUStateData.h b/CCU/Application/Inc/CCUStateData.h index 405c0e142..1d75ee414 100644 --- a/CCU/Application/Inc/CCUStateData.h +++ b/CCU/Application/Inc/CCUStateData.h @@ -8,7 +8,6 @@ typedef struct { CCU_STATE state; - // name lwk might be too long bool recv_charge_cmd; // BCU_STATUS_2 diff --git a/CCU/Application/Src/StateTicks.c b/CCU/Application/Src/StateTicks.c index 3ce359892..4d83a3dbe 100644 --- a/CCU/Application/Src/StateTicks.c +++ b/CCU/Application/Src/StateTicks.c @@ -15,17 +15,14 @@ void CCU_State_Tick(CCU_StateData *state_data) LOGOMATIC("CCU Current State: %d\n", state_data->state); - // FIXME: switch (state_data->state) { // if given an error, switch state to IDLE; warnings will remain placeholders until better understood // General checks for State Transition, if any error detected, transition back to IDLE state case CCU_STATE_IDLE: - // TODO: Create IDLE func elsewhere & Call state IDLE function STATE_IDLE(state_data); break; case CCU_STATE_CHARGING: - // TODO: Create Charging func elsewhere & Call charging func STATE_CHARGING(state_data); break; diff --git a/CCU/Core/Src/main.c b/CCU/Core/Src/main.c index 173f8db53..b6e98cc03 100644 --- a/CCU/Core/Src/main.c +++ b/CCU/Core/Src/main.c @@ -133,11 +133,9 @@ int main(void) /* Infinite loop */ /* USER CODE BEGIN WHILE */ + // Initialize SoftwareLatch High setSoftwareLatch(1, &state_data); while (1) { - /*LL_GPIO_SetOutputPin (GPIOC, LL_GPIO_PIN_13);*/ - - // Initialize SoftwareLatch High CCU_State_Tick(&state_data); LL_mDelay(5); From 74cdc3dda50a0d9ce049dbbd4e0bf7ad475667f1 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Thu, 9 Apr 2026 22:01:03 -0700 Subject: [PATCH 15/21] SystemClock HSI to HSE --- CCU/Core/Src/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CCU/Core/Src/main.c b/CCU/Core/Src/main.c index b6e98cc03..333af0819 100644 --- a/CCU/Core/Src/main.c +++ b/CCU/Core/Src/main.c @@ -155,10 +155,10 @@ void SystemClock_Config(void) LL_PWR_EnableRange1BoostMode(); LL_RCC_HSE_Enable(); /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} + while (LL_RCC_HSE_IsReady() != 1) {} - LL_RCC_HSE_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_4, 85, LL_RCC_PLLR_DIV_2); + 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 */ From 68737d111fdf68d2942d7de34167407855d87a37 Mon Sep 17 00:00:00 2001 From: ana_carthikeyan Date: Thu, 9 Apr 2026 22:02:38 -0700 Subject: [PATCH 16/21] VCP state dump log is now functional --- CCU/Application/Inc/StateUtils.h | 1 + CCU/Application/Src/StateUtils.c | 34 ++++++++++++++++++++++++++++++++ CCU/Core/Src/stm32g4xx_it.c | 31 ++--------------------------- 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/CCU/Application/Inc/StateUtils.h b/CCU/Application/Inc/StateUtils.h index 296638bb8..6207585b0 100644 --- a/CCU/Application/Inc/StateUtils.h +++ b/CCU/Application/Inc/StateUtils.h @@ -10,6 +10,7 @@ #define STATE_UTILS_H void setSoftwareLatch(bool close, CCU_StateData *state_data); +void VCP_StateDump(const CCU_StateData *state_data); bool CriticalError(const CCU_StateData *state_data); bool BCU_Warnings(const CCU_StateData *state_data); #endif diff --git a/CCU/Application/Src/StateUtils.c b/CCU/Application/Src/StateUtils.c index 13d4d1768..2764160ed 100644 --- a/CCU/Application/Src/StateUtils.c +++ b/CCU/Application/Src/StateUtils.c @@ -65,3 +65,37 @@ bool CriticalError(const CCU_StateData *state_data) return false; } } + +void VCP_StateDump(const CCU_StateData *state_data) { + LOGOMATIC("\n========== CCU STATE DUMP ==========\n"); + + LOGOMATIC("state: %d\n", state_data->state); + LOGOMATIC("recv_charge_cmd: %d\n", state_data->recv_charge_cmd); + + LOGOMATIC("\n--- BCU_STATUS_2 ---\n"); + LOGOMATIC("20V: %u\n", state_data->BCU_S2_20Volt); + LOGOMATIC("12V: %u\n", state_data->BCU_S2_12Volt); + LOGOMATIC("SDC Volt: %u\n", state_data->BCU_S2_SDC_Volt); + LOGOMATIC("Min Cell Volt: %u\n", state_data->BCU_S2_MIN_CELL_Volt); + LOGOMATIC("Max Cell Temp: %u\n", state_data->BCU_S2_MAX_CELL_TEMP); + + LOGOMATIC("\n--- Errors ---\n"); + LOGOMATIC("OVERTEMP: %d\n", state_data->BCU_S2_OVERTEMP_ERROR); + LOGOMATIC("OVERVOLT: %d\n", state_data->BCU_S2_OVERVOLT_ERROR); + LOGOMATIC("UNDERVOLT: %d\n", state_data->BCU_S2_UNDERVOLT_ERROR); + LOGOMATIC("OVERCURR: %d\n", state_data->BCU_S2_OVERCURR_ERROR); + LOGOMATIC("UNDERCURR: %d\n", state_data->BCU_S2_UNDERCURR_ERROR); + + LOGOMATIC("\n--- Warnings ---\n"); + LOGOMATIC("UNDER20V: %d\n", state_data->BCU_S2_UNDER20v_WARNING); + LOGOMATIC("UNDER12V: %d\n", state_data->BCU_S2_UNDER12v_WARNING); + LOGOMATIC("UNDERVOLT SDC: %d\n", state_data->BCU_S2_UNDERVOLTSDC_WARNING); + + LOGOMATIC("\n--- State Bits ---\n"); + LOGOMATIC("SOFTWARE LATCH: %d\n", state_data->BCU_S2_SOFTWARE_LATCH); + LOGOMATIC("PRECHARGE TS ACTIVE: %d\n", state_data->BCU_PRECHARGE_SET_TS_ACTIVE); + + LOGOMATIC("====================================\n\n"); + + +} diff --git a/CCU/Core/Src/stm32g4xx_it.c b/CCU/Core/Src/stm32g4xx_it.c index f6153024c..9b9dadcec 100644 --- a/CCU/Core/Src/stm32g4xx_it.c +++ b/CCU/Core/Src/stm32g4xx_it.c @@ -25,6 +25,7 @@ /* USER CODE BEGIN Includes */ #include "CCUStateData.h" #include "Logomatic.h" +#include "StateUtils.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -205,36 +206,8 @@ void USART2_IRQHandler(void) LL_USART_TransmitData8(USART2, 'C'); } else if (receivedData == '?') { - LOGOMATIC("Received State Dump command\n"); - LOGOMATIC("\n========== CCU STATE DUMP ==========\n"); + VCP_StateDump(&state_data); - LOGOMATIC("state: %d\n", state_data.state); - LOGOMATIC("recv_charge_cmd: %d\n", state_data.recv_charge_cmd); - - LOGOMATIC("\n--- BCU_STATUS_2 ---\n"); - LOGOMATIC("20V: %u\n", state_data.BCU_S2_20Volt); - LOGOMATIC("12V: %u\n", state_data.BCU_S2_12Volt); - LOGOMATIC("SDC Volt: %u\n", state_data.BCU_S2_SDC_Volt); - LOGOMATIC("Min Cell Volt: %u\n", state_data.BCU_S2_MIN_CELL_Volt); - LOGOMATIC("Max Cell Temp: %u\n", state_data.BCU_S2_MAX_CELL_TEMP); - - LOGOMATIC("\n--- Errors ---\n"); - LOGOMATIC("OVERTEMP: %d\n", state_data.BCU_S2_OVERTEMP_ERROR); - LOGOMATIC("OVERVOLT: %d\n", state_data.BCU_S2_OVERVOLT_ERROR); - LOGOMATIC("UNDERVOLT: %d\n", state_data.BCU_S2_UNDERVOLT_ERROR); - LOGOMATIC("OVERCURR: %d\n", state_data.BCU_S2_OVERCURR_ERROR); - LOGOMATIC("UNDERCURR: %d\n", state_data.BCU_S2_UNDERCURR_ERROR); - - LOGOMATIC("\n--- Warnings ---\n"); - LOGOMATIC("UNDER20V: %d\n", state_data.BCU_S2_UNDER20v_WARNING); - LOGOMATIC("UNDER12V: %d\n", state_data.BCU_S2_UNDER12v_WARNING); - LOGOMATIC("UNDERVOLT SDC: %d\n", state_data.BCU_S2_UNDERVOLTSDC_WARNING); - - LOGOMATIC("\n--- State Bits ---\n"); - LOGOMATIC("SOFTWARE LATCH: %d\n", state_data.BCU_S2_SOFTWARE_LATCH); - LOGOMATIC("PRECHARGE TS ACTIVE: %d\n", state_data.BCU_PRECHARGE_SET_TS_ACTIVE); - - LOGOMATIC("====================================\n\n"); LL_USART_TransmitData8(USART2, '?'); From 869de0172cbec3b9b47d6f84b1fceaf11473e038 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 10 Apr 2026 05:05:16 +0000 Subject: [PATCH 17/21] Automatic Clang-Format: Standardized formatting automatically --- CCU/Application/Src/StateUtils.c | 5 ++--- CCU/Core/Src/stm32g4xx_it.c | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/CCU/Application/Src/StateUtils.c b/CCU/Application/Src/StateUtils.c index 2764160ed..3e0bf8322 100644 --- a/CCU/Application/Src/StateUtils.c +++ b/CCU/Application/Src/StateUtils.c @@ -66,7 +66,8 @@ bool CriticalError(const CCU_StateData *state_data) } } -void VCP_StateDump(const CCU_StateData *state_data) { +void VCP_StateDump(const CCU_StateData *state_data) +{ LOGOMATIC("\n========== CCU STATE DUMP ==========\n"); LOGOMATIC("state: %d\n", state_data->state); @@ -96,6 +97,4 @@ void VCP_StateDump(const CCU_StateData *state_data) { LOGOMATIC("PRECHARGE TS ACTIVE: %d\n", state_data->BCU_PRECHARGE_SET_TS_ACTIVE); LOGOMATIC("====================================\n\n"); - - } diff --git a/CCU/Core/Src/stm32g4xx_it.c b/CCU/Core/Src/stm32g4xx_it.c index 9b9dadcec..a7dea7889 100644 --- a/CCU/Core/Src/stm32g4xx_it.c +++ b/CCU/Core/Src/stm32g4xx_it.c @@ -208,7 +208,6 @@ void USART2_IRQHandler(void) VCP_StateDump(&state_data); - LL_USART_TransmitData8(USART2, '?'); } else { From 11cb9ae211249c78aba7e14550b9ab0139734cc7 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Thu, 9 Apr 2026 22:17:43 -0700 Subject: [PATCH 18/21] removed log for every state tick --- CCU/Application/Src/StateTicks.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/CCU/Application/Src/StateTicks.c b/CCU/Application/Src/StateTicks.c index 4d83a3dbe..fe07639c8 100644 --- a/CCU/Application/Src/StateTicks.c +++ b/CCU/Application/Src/StateTicks.c @@ -13,8 +13,6 @@ void CCU_State_Tick(CCU_StateData *state_data) { - LOGOMATIC("CCU Current State: %d\n", state_data->state); - switch (state_data->state) { // if given an error, switch state to IDLE; warnings will remain placeholders until better understood // General checks for State Transition, if any error detected, transition back to IDLE state From 78d19d6783415fb89769b5abc2e32ddc77a6f667 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Fri, 10 Apr 2026 01:05:22 -0700 Subject: [PATCH 19/21] Changed VCP_StateDump to CheckDebugPrint & changed softwareLatch from 0/1 to false/true --- CCU/Application/Inc/StateUtils.h | 4 +++- CCU/Application/Src/StateTicks.c | 7 ++++--- CCU/Application/Src/StateUtils.c | 14 +++++++++++--- CCU/Core/Src/main.c | 3 ++- CCU/Core/Src/stm32g4xx_it.c | 2 +- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/CCU/Application/Inc/StateUtils.h b/CCU/Application/Inc/StateUtils.h index 6207585b0..dcdaf99f2 100644 --- a/CCU/Application/Inc/StateUtils.h +++ b/CCU/Application/Inc/StateUtils.h @@ -9,8 +9,10 @@ #ifndef STATE_UTILS_H #define STATE_UTILS_H +extern volatile bool request_print_statedata; + void setSoftwareLatch(bool close, CCU_StateData *state_data); -void VCP_StateDump(const CCU_StateData *state_data); +void CheckDebuggerPrint(const CCU_StateData *state_data); bool CriticalError(const CCU_StateData *state_data); bool BCU_Warnings(const CCU_StateData *state_data); #endif diff --git a/CCU/Application/Src/StateTicks.c b/CCU/Application/Src/StateTicks.c index fe07639c8..3ac195346 100644 --- a/CCU/Application/Src/StateTicks.c +++ b/CCU/Application/Src/StateTicks.c @@ -28,7 +28,7 @@ void CCU_State_Tick(CCU_StateData *state_data) state_data->BCU_PRECHARGE_SET_TS_ACTIVE = 0; state_data->state = CCU_STATE_IDLE; SendPrechargeStatus(state_data); - setSoftwareLatch(0, state_data); + setSoftwareLatch(false, state_data); break; }; } @@ -36,9 +36,10 @@ void CCU_State_Tick(CCU_StateData *state_data) void STATE_IDLE(CCU_StateData *state_data) { bool anyErrors = 0; + BCU_Warnings(state_data); if (CriticalError(state_data)) { anyErrors = 1; - setSoftwareLatch(0, state_data); + setSoftwareLatch(false, state_data); LOGOMATIC("Critical Error Occured!\n"); }; @@ -58,7 +59,7 @@ void STATE_CHARGING(CCU_StateData *state_data) BCU_Warnings(state_data); if (CriticalError(state_data)) { - setSoftwareLatch(0, state_data); + setSoftwareLatch(false, state_data); state_data->BCU_PRECHARGE_SET_TS_ACTIVE = 0; SendPrechargeStatus(state_data); diff --git a/CCU/Application/Src/StateUtils.c b/CCU/Application/Src/StateUtils.c index 3e0bf8322..811fe97e9 100644 --- a/CCU/Application/Src/StateUtils.c +++ b/CCU/Application/Src/StateUtils.c @@ -13,11 +13,11 @@ void setSoftwareLatch(bool close, CCU_StateData *state_data) if (close && !LL_GPIO_IsInputPinSet(SOFTWARE_OK_CONTROL_GPIO_Port, SOFTWARE_OK_CONTROL_Pin)) { LL_GPIO_ResetOutputPin(SOFTWARE_OK_CONTROL_GPIO_Port, SOFTWARE_OK_CONTROL_Pin); - state_data->BCU_S2_SOFTWARE_LATCH = 1; + state_data->BCU_S2_SOFTWARE_LATCH = true; LOGOMATIC("Software Latch: High\n"); } else if (!close && LL_GPIO_IsInputPinSet(SOFTWARE_OK_CONTROL_GPIO_Port, SOFTWARE_OK_CONTROL_Pin)) { LL_GPIO_ResetOutputPin(SOFTWARE_OK_CONTROL_GPIO_Port, SOFTWARE_OK_CONTROL_Pin); - state_data->BCU_S2_SOFTWARE_LATCH = 0; + state_data->BCU_S2_SOFTWARE_LATCH = false; LOGOMATIC("Software Latch: Low\n"); } } @@ -66,8 +66,14 @@ bool CriticalError(const CCU_StateData *state_data) } } -void VCP_StateDump(const CCU_StateData *state_data) +volatile bool request_print_statedata; + +void CheckDebuggerPrint(const CCU_StateData *state_data) { + if (!request_print_statedata){ + return; + } + LOGOMATIC("\n========== CCU STATE DUMP ==========\n"); LOGOMATIC("state: %d\n", state_data->state); @@ -97,4 +103,6 @@ void VCP_StateDump(const CCU_StateData *state_data) LOGOMATIC("PRECHARGE TS ACTIVE: %d\n", state_data->BCU_PRECHARGE_SET_TS_ACTIVE); LOGOMATIC("====================================\n\n"); + + request_print_statedata = false; } diff --git a/CCU/Core/Src/main.c b/CCU/Core/Src/main.c index 333af0819..b674da619 100644 --- a/CCU/Core/Src/main.c +++ b/CCU/Core/Src/main.c @@ -134,9 +134,10 @@ int main(void) /* Infinite loop */ /* USER CODE BEGIN WHILE */ // Initialize SoftwareLatch High - setSoftwareLatch(1, &state_data); + setSoftwareLatch(true, &state_data); while (1) { CCU_State_Tick(&state_data); + CheckDebuggerPrint(&state_data); LL_mDelay(5); diff --git a/CCU/Core/Src/stm32g4xx_it.c b/CCU/Core/Src/stm32g4xx_it.c index a7dea7889..cf00dc378 100644 --- a/CCU/Core/Src/stm32g4xx_it.c +++ b/CCU/Core/Src/stm32g4xx_it.c @@ -206,7 +206,7 @@ void USART2_IRQHandler(void) LL_USART_TransmitData8(USART2, 'C'); } else if (receivedData == '?') { - VCP_StateDump(&state_data); + request_print_statedata = true; LL_USART_TransmitData8(USART2, '?'); From 3193b9cb7b8954ac64195e36f612c1f282cd5b51 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 10 Apr 2026 08:10:15 +0000 Subject: [PATCH 20/21] Automatic Clang-Format: Standardized formatting automatically --- CCU/Application/Src/StateUtils.c | 2 +- CCU/Core/Src/stm32g4xx_it.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CCU/Application/Src/StateUtils.c b/CCU/Application/Src/StateUtils.c index 811fe97e9..01598e00a 100644 --- a/CCU/Application/Src/StateUtils.c +++ b/CCU/Application/Src/StateUtils.c @@ -70,7 +70,7 @@ volatile bool request_print_statedata; void CheckDebuggerPrint(const CCU_StateData *state_data) { - if (!request_print_statedata){ + if (!request_print_statedata) { return; } diff --git a/CCU/Core/Src/stm32g4xx_it.c b/CCU/Core/Src/stm32g4xx_it.c index 68ed34562..cf00dc378 100644 --- a/CCU/Core/Src/stm32g4xx_it.c +++ b/CCU/Core/Src/stm32g4xx_it.c @@ -26,7 +26,6 @@ #include "CCUStateData.h" #include "Logomatic.h" #include "StateUtils.h" -#include "StateUtils.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ From 9dfee710c97fd47490675ad4e9d5af16e59b0ee8 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sat, 11 Apr 2026 00:28:04 -0700 Subject: [PATCH 21/21] Removed duplicated code and change 0/1 to false/true bool vals --- CCU/Application/Src/StateTicks.c | 13 ++++++------- CCU/Core/Src/main.c | 7 +------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/CCU/Application/Src/StateTicks.c b/CCU/Application/Src/StateTicks.c index b7a390cfc..01184fe25 100644 --- a/CCU/Application/Src/StateTicks.c +++ b/CCU/Application/Src/StateTicks.c @@ -25,8 +25,7 @@ void CCU_State_Tick(CCU_StateData *state_data) break; default: - state_data->BCU_PRECHARGE_SET_TS_ACTIVE = 0; - state_data->BCU_PRECHARGE_SET_TS_ACTIVE = 0; + state_data->BCU_PRECHARGE_SET_TS_ACTIVE = false; state_data->state = CCU_STATE_IDLE; SendPrechargeStatus(state_data); setSoftwareLatch(false, state_data); @@ -36,10 +35,10 @@ void CCU_State_Tick(CCU_StateData *state_data) void STATE_IDLE(CCU_StateData *state_data) { - bool anyErrors = 0; + bool anyErrors = false; BCU_Warnings(state_data); if (CriticalError(state_data)) { - anyErrors = 1; + anyErrors = true; setSoftwareLatch(false, state_data); LOGOMATIC("Critical Error Occured!\n"); }; @@ -47,7 +46,7 @@ void STATE_IDLE(CCU_StateData *state_data) if (!anyErrors && state_data->recv_charge_cmd) { state_data->state = CCU_STATE_CHARGING; - state_data->BCU_PRECHARGE_SET_TS_ACTIVE = 1; + state_data->BCU_PRECHARGE_SET_TS_ACTIVE = true; SendPrechargeStatus(state_data); LOGOMATIC("CCU Current State: %d\n", state_data->state); @@ -62,7 +61,7 @@ void STATE_CHARGING(CCU_StateData *state_data) setSoftwareLatch(false, state_data); - state_data->BCU_PRECHARGE_SET_TS_ACTIVE = 0; + state_data->BCU_PRECHARGE_SET_TS_ACTIVE = false; SendPrechargeStatus(state_data); state_data->state = CCU_STATE_IDLE; @@ -72,7 +71,7 @@ void STATE_CHARGING(CCU_StateData *state_data) if (!(state_data->recv_charge_cmd)) { state_data->state = CCU_STATE_IDLE; - state_data->BCU_PRECHARGE_SET_TS_ACTIVE = 0; + state_data->BCU_PRECHARGE_SET_TS_ACTIVE = false; SendPrechargeStatus(state_data); LOGOMATIC("CCU Current State: %d\n", state_data->state); diff --git a/CCU/Core/Src/main.c b/CCU/Core/Src/main.c index 7a52dfaf0..ebd8b28cb 100644 --- a/CCU/Core/Src/main.c +++ b/CCU/Core/Src/main.c @@ -139,7 +139,6 @@ int main(void) CCU_State_Tick(&state_data); CheckDebuggerPrint(&state_data); - LL_mDelay(5); LL_mDelay(5); /* USER CODE END 3 */ @@ -156,13 +155,9 @@ void SystemClock_Config(void) while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} LL_PWR_EnableRange1BoostMode(); LL_RCC_HSE_Enable(); - LL_RCC_HSE_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSE_IsReady() != 1) {} + /* 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_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();