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/Inc/StateUtils.h b/CCU/Application/Inc/StateUtils.h index 296638bb8..dcdaf99f2 100644 --- a/CCU/Application/Inc/StateUtils.h +++ b/CCU/Application/Inc/StateUtils.h @@ -9,7 +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 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/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..6ef42f9fc 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,6 @@ 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..01184fe25 100644 --- a/CCU/Application/Src/StateTicks.c +++ b/CCU/Application/Src/StateTicks.c @@ -13,41 +13,40 @@ 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; default: + state_data->BCU_PRECHARGE_SET_TS_ACTIVE = false; state_data->state = CCU_STATE_IDLE; + SendPrechargeStatus(state_data); + setSoftwareLatch(false, state_data); break; }; } void STATE_IDLE(CCU_StateData *state_data) { - bool anyErrors = 0; + bool anyErrors = false; + BCU_Warnings(state_data); if (CriticalError(state_data)) { - anyErrors = 1; - setSoftwareLatch(0, state_data); - LOGOMATIC("Critical Error Occured; State set to IDLE \n"); + anyErrors = true; + setSoftwareLatch(false, state_data); + LOGOMATIC("Critical Error Occured!\n"); }; 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); @@ -60,9 +59,9 @@ 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; + 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/Application/Src/StateUtils.c b/CCU/Application/Src/StateUtils.c index 13d4d1768..01598e00a 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"); } } @@ -65,3 +65,44 @@ bool CriticalError(const CCU_StateData *state_data) return false; } } + +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); + 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"); + + request_print_statedata = false; +} 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..ebd8b28cb 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 ----------------------------------------------------------*/ @@ -124,7 +122,6 @@ int main(void) /* Initialize all configured peripherals */ MX_GPIO_Init(); - MX_FDCAN1_Init(); /* USER CODE BEGIN 2 */ // Initialize CAN @@ -136,15 +133,13 @@ int main(void) /* Infinite loop */ /* USER CODE BEGIN WHILE */ - setSoftwareLatch(1, &state_data); + // Initialize SoftwareLatch High + setSoftwareLatch(true, &state_data); while (1) { - /*LL_GPIO_SetOutputPin (GPIOC, LL_GPIO_PIN_13);*/ - LL_mDelay(100); - - // Initialize SoftwareLatch High CCU_State_Tick(&state_data); + CheckDebuggerPrint(&state_data); - LL_mDelay(200); + LL_mDelay(5); /* USER CODE END 3 */ } @@ -159,12 +154,12 @@ 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(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} + LL_RCC_HSE_Enable(); + /* Wait till HSE is ready */ + while (LL_RCC_HSE_IsReady() != 1) {} - LL_RCC_HSI_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 */ diff --git a/CCU/Core/Src/stm32g4xx_it.c b/CCU/Core/Src/stm32g4xx_it.c index f6153024c..cf00dc378 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,7 @@ void USART2_IRQHandler(void) LL_USART_TransmitData8(USART2, 'C'); } else if (receivedData == '?') { - LOGOMATIC("Received State Dump command\n"); - 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"); + request_print_statedata = true; LL_USART_TransmitData8(USART2, '?');