From bc0a3afb5c5d313c57b78f03d86e6d4831eac800 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 13 Oct 2024 00:13:30 -0400 Subject: [PATCH 01/10] Commented Out Non-Can Stuff In Main and Can Handler --- Core/Src/can_handler.c | 15 ++++++++++----- Core/Src/main.c | 22 +++++++++++----------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Core/Src/can_handler.c b/Core/Src/can_handler.c index ee8c24e..265c239 100644 --- a/Core/Src/can_handler.c +++ b/Core/Src/can_handler.c @@ -79,6 +79,8 @@ void can1_callback(CAN_HandleTypeDef *hcan) queue_and_set_flag(can_inbound_queue, &new_msg, can_receive_thread, NEW_CAN_MSG_FLAG); + + printf("Callback: %s", new_msg.data); } int8_t queue_can_msg(can_msg_t msg) @@ -127,6 +129,8 @@ void vCanDispatch(void *pv_params) fault_data.diag = "Outbound mailbox full!"; queue_fault(&fault_data); } + + printf("Dispatch: %s", msg_from_queue.data); } } } @@ -140,7 +144,7 @@ const osThreadAttr_t can_receive_attributes = { void vCanReceive(void *pv_params) { - dti_t *mc = (dti_t *)pv_params; + //dti_t *mc = (dti_t *)pv_params; can_msg_t msg; @@ -149,8 +153,8 @@ void vCanReceive(void *pv_params) osWaitForever); while (osOK == osMessageQueueGet(can_inbound_queue, &msg, 0U, 0U)) { - switch (msg.id) { - /* Messages Relevant to Motor Controller */ + //switch (msg.id) { + /* Messages Relevant to Motor Controller */ /* case DTI_CANID_ERPM: dti_record_rpm(mc, msg); break; @@ -159,7 +163,8 @@ void vCanReceive(void *pv_params) break; default: break; - } - } + }*/ + printf("Recieve: %s", msg.data); + } } } \ No newline at end of file diff --git a/Core/Src/main.c b/Core/Src/main.c index 9ddd550..939baeb 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -139,26 +139,26 @@ int main(void) /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + //HAL_Init(); /* USER CODE BEGIN Init */ - HAL_Delay(500); + //HAL_Delay(500); /* USER CODE END Init */ /* Configure the system clock */ - SystemClock_Config(); + //SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_DMA_Init(); + /*MX_GPIO_Init(); + MX_DMA_Init();*/ MX_CAN1_Init(); - MX_I2C1_Init(); + /*MX_I2C1_Init(); MX_I2C2_Init(); MX_ADC1_Init(); MX_USART3_UART_Init(); @@ -167,16 +167,16 @@ int main(void) /* USER CODE BEGIN 2 */ /* Create Interfaces to Represent Relevant Hardware */ - mpu_t *mpu = init_mpu(&hi2c1, &hadc3, &hadc1, GPIOC, GPIOB); + /*mpu_t *mpu = init_mpu(&hi2c1, &hadc3, &hadc1, GPIOC, GPIOB); assert(mpu); pdu_t *pdu = init_pdu(&hi2c2); assert(pdu); dti_t *mc = dti_init(); assert(mc); steeringio_t *wheel = steeringio_init(); - assert(wheel); + assert(wheel);8*/ init_can1(&hcan1); - bms_init(); + //bms_init(); printf("\r\n\n\nInit Success...\r\n\n\n"); @@ -207,7 +207,7 @@ int main(void) /* USER CODE BEGIN RTOS_THREADS */ /* Monitors */ - non_func_data_args_t *nfd_args = malloc(sizeof(non_func_data_args_t)); + /*non_func_data_args_t *nfd_args = malloc(sizeof(non_func_data_args_t)); nfd_args->mpu = mpu; nfd_args->pdu = pdu; non_functional_data_thead = osThreadNew(vNonFunctionalDataCollection, nfd_args, &non_functional_data_attributes); @@ -234,7 +234,7 @@ int main(void) assert(serial_monitor_handle); /* Control Logic */ - fault_handle = osThreadNew(vFaultHandler, NULL, &fault_handle_attributes); + /*fault_handle = osThreadNew(vFaultHandler, NULL, &fault_handle_attributes); assert(fault_handle); rtds_thread = osThreadNew(vRTDS, pdu, &rtds_attributes); From 5102a860e12a1fb29340814ae356cd2716ed7425 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 13 Oct 2024 00:28:02 -0400 Subject: [PATCH 02/10] Fix Build Issues --- Core/Src/can_handler.c | 34 +++++---- Core/Src/main.c | 152 ++++++++++++++++++++--------------------- 2 files changed, 92 insertions(+), 94 deletions(-) diff --git a/Core/Src/can_handler.c b/Core/Src/can_handler.c index 265c239..3a6fbcc 100644 --- a/Core/Src/can_handler.c +++ b/Core/Src/can_handler.c @@ -110,7 +110,7 @@ void vCanDispatch(void *pv_params) CAN_HandleTypeDef *hcan = (CAN_HandleTypeDef *)pv_params; for (;;) { - osThreadFlagsWait(CAN_DISPATCH_FLAG, osFlagsWaitAny, + osThreadFlagsWait(CAN_DISPATCxH_FLAG, osFlagsWaitAny, osWaitForever); /* Send CAN message */ while (osMessageQueueGet(can_outbound_queue, &msg_from_queue, @@ -144,27 +144,25 @@ const osThreadAttr_t can_receive_attributes = { void vCanReceive(void *pv_params) { - //dti_t *mc = (dti_t *)pv_params; + dti_t *mc = (dti_t *)pv_params; can_msg_t msg; for (;;) { - osThreadFlagsWait(NEW_CAN_MSG_FLAG, osFlagsWaitAny, - osWaitForever); - while (osOK == - osMessageQueueGet(can_inbound_queue, &msg, 0U, 0U)) { - //switch (msg.id) { - /* Messages Relevant to Motor Controller */ /* - case DTI_CANID_ERPM: - dti_record_rpm(mc, msg); - break; - case BMS_DCL_MSG: - handle_dcl_msg(); - break; - default: - break; - }*/ + osThreadFlagsWait(NEW_CAN_MSG_FLAG, osFlagsWaitAny, osWaitForever); + while (osOK == osMessageQueueGet(can_inbound_queue, &msg, 0U, 0U)) { + switch (msg.id) { + /* Messages Relevant to Motor Controller */ + case DTI_CANID_ERPM: + dti_record_rpm(mc, msg); + break; + case BMS_DCL_MSG: + handle_dcl_msg(); + break; + default: + break; + } printf("Recieve: %s", msg.data); - } + } } } \ No newline at end of file diff --git a/Core/Src/main.c b/Core/Src/main.c index 939baeb..12ca8bb 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -164,16 +164,16 @@ int main(void) MX_USART3_UART_Init(); MX_ADC3_Init(); MX_IWDG_Init(); - /* USER CODE BEGIN 2 */ + USER CODE BEGIN 2 /* Create Interfaces to Represent Relevant Hardware */ /*mpu_t *mpu = init_mpu(&hi2c1, &hadc3, &hadc1, GPIOC, GPIOB); assert(mpu); pdu_t *pdu = init_pdu(&hi2c2); - assert(pdu); + assert(pdu);*/ dti_t *mc = dti_init(); assert(mc); - steeringio_t *wheel = steeringio_init(); + /*steeringio_t *wheel = steeringio_init(); assert(wheel);8*/ init_can1(&hcan1); //bms_init(); @@ -225,7 +225,7 @@ int main(void) // shutdown_monitor_handle = osThreadNew(vShutdownMonitor, pdu, &shutdown_monitor_attributes); // assert(shutdown_monitor_handle); - /* Messaging */ + Messaging */ can_dispatch_handle = osThreadNew(vCanDispatch, &hcan1, &can_dispatch_attributes); assert(can_dispatch_handle); can_receive_thread = osThreadNew(vCanReceive, mc, &can_receive_attributes); @@ -252,7 +252,7 @@ int main(void) sm_args->mc = mc; sm_director_handle = osThreadNew(vStateMachineDirector, sm_args, &sm_director_attributes); assert(sm_director_handle); - /* USER CODE END RTOS_THREADS */ + USER CODE END RTOS_THREADS */ /* USER CODE BEGIN RTOS_EVENTS */ /* add events, ... */ @@ -320,14 +320,14 @@ void SystemClock_Config(void) * @param None * @retval None */ -static void MX_ADC1_Init(void) -{ +/*static void MX_ADC1_Init(void) +{*/ /* USER CODE BEGIN ADC1_Init 0 */ /* USER CODE END ADC1_Init 0 */ - ADC_ChannelConfTypeDef sConfig = {0}; + //ADC_ChannelConfTypeDef sConfig = {0}; /* USER CODE BEGIN ADC1_Init 1 */ @@ -335,7 +335,7 @@ static void MX_ADC1_Init(void) /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */ - hadc1.Instance = ADC1; + /*hadc1.Instance = ADC1; hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV6; hadc1.Init.Resolution = ADC_RESOLUTION_12B; hadc1.Init.ScanConvMode = ENABLE; @@ -350,36 +350,36 @@ static void MX_ADC1_Init(void) if (HAL_ADC_Init(&hadc1) != HAL_OK) { Error_Handler(); - } + }*/ /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ - sConfig.Channel = ADC_CHANNEL_8; + /*sConfig.Channel = ADC_CHANNEL_8; sConfig.Rank = 1; sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { Error_Handler(); - } + }*/ /* USER CODE BEGIN ADC1_Init 2 */ /* USER CODE END ADC1_Init 2 */ -} +//} /** * @brief ADC3 Initialization Function * @param None * @retval None */ -static void MX_ADC3_Init(void) -{ +/*static void MX_ADC3_Init(void) +{*/ /* USER CODE BEGIN ADC3_Init 0 */ /* USER CODE END ADC3_Init 0 */ - ADC_ChannelConfTypeDef sConfig = {0}; + //ADC_ChannelConfTypeDef sConfig = {0}; /* USER CODE BEGIN ADC3_Init 1 */ @@ -387,7 +387,7 @@ static void MX_ADC3_Init(void) /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */ - hadc3.Instance = ADC3; + /*hadc3.Instance = ADC3; hadc3.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV6; hadc3.Init.Resolution = ADC_RESOLUTION_12B; hadc3.Init.ScanConvMode = ENABLE; @@ -402,57 +402,57 @@ static void MX_ADC3_Init(void) if (HAL_ADC_Init(&hadc3) != HAL_OK) { Error_Handler(); - } + }*/ /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ - sConfig.Channel = ADC_CHANNEL_2; + /*sConfig.Channel = ADC_CHANNEL_2; sConfig.Rank = 1; sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK) { Error_Handler(); - } + }*/ /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ - sConfig.Channel = ADC_CHANNEL_3; + /*sConfig.Channel = ADC_CHANNEL_3; sConfig.Rank = 2; if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK) { Error_Handler(); - } + }*/ /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ - sConfig.Channel = ADC_CHANNEL_0; + /*sConfig.Channel = ADC_CHANNEL_0; sConfig.Rank = 3; if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK) { Error_Handler(); - } + }*/ /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ - sConfig.Channel = ADC_CHANNEL_1; + /*sConfig.Channel = ADC_CHANNEL_1; sConfig.Rank = 4; if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK) { Error_Handler(); - } + }*/ /* USER CODE BEGIN ADC3_Init 2 */ /* USER CODE END ADC3_Init 2 */ -} +//} /** * @brief CAN1 Initialization Function * @param None * @retval None */ -static void MX_CAN1_Init(void) -{ +/*static void MX_CAN1_Init(void) +{*/ /* USER CODE BEGIN CAN1_Init 0 */ @@ -461,7 +461,7 @@ static void MX_CAN1_Init(void) /* USER CODE BEGIN CAN1_Init 1 */ /* USER CODE END CAN1_Init 1 */ - hcan1.Instance = CAN1; + /*hcan1.Instance = CAN1; hcan1.Init.Prescaler = 2; hcan1.Init.Mode = CAN_MODE_NORMAL; hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ; @@ -476,20 +476,20 @@ static void MX_CAN1_Init(void) if (HAL_CAN_Init(&hcan1) != HAL_OK) { Error_Handler(); - } + }*/ /* USER CODE BEGIN CAN1_Init 2 */ /* USER CODE END CAN1_Init 2 */ -} +//} /** * @brief I2C1 Initialization Function * @param None * @retval None */ -static void MX_I2C1_Init(void) -{ +/*static void MX_I2C1_Init(void) +{*/ /* USER CODE BEGIN I2C1_Init 0 */ @@ -498,7 +498,7 @@ static void MX_I2C1_Init(void) /* USER CODE BEGIN I2C1_Init 1 */ /* USER CODE END I2C1_Init 1 */ - hi2c1.Instance = I2C1; + /*hi2c1.Instance = I2C1; hi2c1.Init.ClockSpeed = 100000; hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2; hi2c1.Init.OwnAddress1 = 0; @@ -510,20 +510,20 @@ static void MX_I2C1_Init(void) if (HAL_I2C_Init(&hi2c1) != HAL_OK) { Error_Handler(); - } + }*/ /* USER CODE BEGIN I2C1_Init 2 */ /* USER CODE END I2C1_Init 2 */ -} +//} /** * @brief I2C2 Initialization Function * @param None * @retval None */ -static void MX_I2C2_Init(void) -{ +/*static void MX_I2C2_Init(void) +{*/ /* USER CODE BEGIN I2C2_Init 0 */ @@ -532,7 +532,7 @@ static void MX_I2C2_Init(void) /* USER CODE BEGIN I2C2_Init 1 */ /* USER CODE END I2C2_Init 1 */ - hi2c2.Instance = I2C2; + /*hi2c2.Instance = I2C2; hi2c2.Init.ClockSpeed = 100000; hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2; hi2c2.Init.OwnAddress1 = 0; @@ -544,20 +544,20 @@ static void MX_I2C2_Init(void) if (HAL_I2C_Init(&hi2c2) != HAL_OK) { Error_Handler(); - } + }*/ /* USER CODE BEGIN I2C2_Init 2 */ /* USER CODE END I2C2_Init 2 */ -} +//} /** * @brief IWDG Initialization Function * @param None * @retval None */ -static void MX_IWDG_Init(void) -{ +/*static void MX_IWDG_Init(void) +{*/ /* USER CODE BEGIN IWDG_Init 0 */ @@ -566,26 +566,26 @@ static void MX_IWDG_Init(void) /* USER CODE BEGIN IWDG_Init 1 */ /* USER CODE END IWDG_Init 1 */ - hiwdg.Instance = IWDG; + /*hiwdg.Instance = IWDG; hiwdg.Init.Prescaler = IWDG_PRESCALER_32; hiwdg.Init.Reload = 4095; if (HAL_IWDG_Init(&hiwdg) != HAL_OK) { Error_Handler(); - } + }*/ /* USER CODE BEGIN IWDG_Init 2 */ /* USER CODE END IWDG_Init 2 */ -} +//} /** * @brief USART3 Initialization Function * @param None * @retval None */ -static void MX_USART3_UART_Init(void) -{ +/*static void MX_USART3_UART_Init(void) +{*/ /* USER CODE BEGIN USART3_Init 0 */ @@ -594,7 +594,7 @@ static void MX_USART3_UART_Init(void) /* USER CODE BEGIN USART3_Init 1 */ /* USER CODE END USART3_Init 1 */ - huart3.Instance = USART3; + /*huart3.Instance = USART3; huart3.Init.BaudRate = 115200; huart3.Init.WordLength = UART_WORDLENGTH_8B; huart3.Init.StopBits = UART_STOPBITS_1; @@ -605,94 +605,94 @@ static void MX_USART3_UART_Init(void) if (HAL_UART_Init(&huart3) != HAL_OK) { Error_Handler(); - } + }*/ /* USER CODE BEGIN USART3_Init 2 */ /* USER CODE END USART3_Init 2 */ -} +//} /** * Enable DMA controller clock */ -static void MX_DMA_Init(void) -{ +/*static void MX_DMA_Init(void) +{*/ /* DMA controller clock enable */ - __HAL_RCC_DMA2_CLK_ENABLE(); + /*__HAL_RCC_DMA2_CLK_ENABLE(); -} +}*/ /** * @brief GPIO Initialization Function * @param None * @retval None */ -static void MX_GPIO_Init(void) +/*static void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; -/* USER CODE BEGIN MX_GPIO_Init_1 */ + USER CODE BEGIN MX_GPIO_Init_1 */ /* USER CODE END MX_GPIO_Init_1 */ /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOH_CLK_ENABLE(); + /*__HAL_RCC_GPIOH_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE();*/ /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOC, GPIO_PIN_3|GPIO_PIN_8|GPIO_PIN_9, GPIO_PIN_RESET); + //HAL_GPIO_WritePin(GPIOC, GPIO_PIN_3|GPIO_PIN_8|GPIO_PIN_9, GPIO_PIN_RESET); /*Configure GPIO pins : PC3 PC8 PC9 */ - GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_8|GPIO_PIN_9; + /*GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_8|GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);*/ /*Configure GPIO pins : PA4 PA5 PA6 PA7 */ - GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7; + /*GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLUP; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);*/ /*Configure GPIO pin : PC4 */ - GPIO_InitStruct.Pin = GPIO_PIN_4; + /*GPIO_InitStruct.Pin = GPIO_PIN_4; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLUP; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);*/ /*Configure GPIO pin : PB1 */ - GPIO_InitStruct.Pin = GPIO_PIN_1; + /*GPIO_InitStruct.Pin = GPIO_PIN_1; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLUP; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);*/ /*Configure GPIO pin : PB2 */ - GPIO_InitStruct.Pin = GPIO_PIN_2; + /*GPIO_InitStruct.Pin = GPIO_PIN_2; 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(GPIOB, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);*/ /*Configure GPIO pin : PA9 */ - GPIO_InitStruct.Pin = GPIO_PIN_9; + /*GPIO_InitStruct.Pin = GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);*/ /*Configure GPIO pins : PA11 PA12 */ - GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12; + /*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_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);*/ /* USER CODE BEGIN MX_GPIO_Init_2 */ /* USER CODE END MX_GPIO_Init_2 */ -} +//} /* USER CODE BEGIN 4 */ From 70651d31a36006d354f6385d48cd22981706df0e Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 13 Oct 2024 00:30:34 -0400 Subject: [PATCH 03/10] Truly Fix Build Issues --- Core/Src/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/Src/main.c b/Core/Src/main.c index 12ca8bb..949e2a5 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -86,7 +86,7 @@ osMessageQueueId_t imu_queue; /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); -static void MX_GPIO_Init(void); +/*static void MX_GPIO_Init(void); static void MX_DMA_Init(void); static void MX_CAN1_Init(void); static void MX_I2C1_Init(void); @@ -94,7 +94,7 @@ static void MX_I2C2_Init(void); static void MX_ADC1_Init(void); static void MX_USART3_UART_Init(void); static void MX_ADC3_Init(void); -static void MX_IWDG_Init(void); +static void MX_IWDG_Init(void);*/ void StartDefaultTask(void *argument); /* USER CODE BEGIN PFP */ @@ -166,7 +166,7 @@ int main(void) MX_IWDG_Init(); USER CODE BEGIN 2 - /* Create Interfaces to Represent Relevant Hardware */ + Create Interfaces to Represent Relevant Hardware */ /*mpu_t *mpu = init_mpu(&hi2c1, &hadc3, &hadc1, GPIOC, GPIOB); assert(mpu); pdu_t *pdu = init_pdu(&hi2c2); From 22b17941082a2fd3d7ad0a3c1305f94e5e33bbfc Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 13 Oct 2024 00:33:29 -0400 Subject: [PATCH 04/10] Finally Fix Build Issues --- Core/Src/main.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Core/Src/main.c b/Core/Src/main.c index 949e2a5..14d374a 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -87,9 +87,9 @@ osMessageQueueId_t imu_queue; /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); /*static void MX_GPIO_Init(void); -static void MX_DMA_Init(void); +static void MX_DMA_Init(void);*/ static void MX_CAN1_Init(void); -static void MX_I2C1_Init(void); +/*static void MX_I2C1_Init(void); static void MX_I2C2_Init(void); static void MX_ADC1_Init(void); static void MX_USART3_UART_Init(void); @@ -451,8 +451,8 @@ void SystemClock_Config(void) * @param None * @retval None */ -/*static void MX_CAN1_Init(void) -{*/ +static void MX_CAN1_Init(void) +{ /* USER CODE BEGIN CAN1_Init 0 */ @@ -461,7 +461,7 @@ void SystemClock_Config(void) /* USER CODE BEGIN CAN1_Init 1 */ /* USER CODE END CAN1_Init 1 */ - /*hcan1.Instance = CAN1; + hcan1.Instance = CAN1; hcan1.Init.Prescaler = 2; hcan1.Init.Mode = CAN_MODE_NORMAL; hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ; @@ -476,12 +476,12 @@ void SystemClock_Config(void) if (HAL_CAN_Init(&hcan1) != HAL_OK) { Error_Handler(); - }*/ + } /* USER CODE BEGIN CAN1_Init 2 */ /* USER CODE END CAN1_Init 2 */ -//} +} /** * @brief I2C1 Initialization Function From 4bad8e067f86759f3e3e0e9493d65547614ca814 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 13 Oct 2024 00:40:15 -0400 Subject: [PATCH 05/10] Fix Small Typo --- Core/Src/can_handler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/Src/can_handler.c b/Core/Src/can_handler.c index 3a6fbcc..257e328 100644 --- a/Core/Src/can_handler.c +++ b/Core/Src/can_handler.c @@ -110,7 +110,7 @@ void vCanDispatch(void *pv_params) CAN_HandleTypeDef *hcan = (CAN_HandleTypeDef *)pv_params; for (;;) { - osThreadFlagsWait(CAN_DISPATCxH_FLAG, osFlagsWaitAny, + osThreadFlagsWait(CAN_DISPATCH_FLAG, osFlagsWaitAny, osWaitForever); /* Send CAN message */ while (osMessageQueueGet(can_outbound_queue, &msg_from_queue, From a4238b6f7e417130249c4e4747de9fa5f20a9376 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 13 Oct 2024 16:28:52 -0400 Subject: [PATCH 06/10] Fix Formatting --- Core/Src/can_handler.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Core/Src/can_handler.c b/Core/Src/can_handler.c index 257e328..9483314 100644 --- a/Core/Src/can_handler.c +++ b/Core/Src/can_handler.c @@ -80,6 +80,7 @@ void can1_callback(CAN_HandleTypeDef *hcan) queue_and_set_flag(can_inbound_queue, &new_msg, can_receive_thread, NEW_CAN_MSG_FLAG); + /* Print Callback Messages */ printf("Callback: %s", new_msg.data); } @@ -130,6 +131,7 @@ void vCanDispatch(void *pv_params) queue_fault(&fault_data); } + /* Print Dispatch Messages */ printf("Dispatch: %s", msg_from_queue.data); } } @@ -162,6 +164,8 @@ void vCanReceive(void *pv_params) default: break; } + + /* Print Receive Messages */ printf("Recieve: %s", msg.data); } } From 8efbb6e80cd43b5014a8a080945c43d09111127b Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 13 Oct 2024 16:53:01 -0400 Subject: [PATCH 07/10] Fix Can Handler --- Core/Src/can_handler.c | 58 ++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/Core/Src/can_handler.c b/Core/Src/can_handler.c index 9483314..c3617bb 100644 --- a/Core/Src/can_handler.c +++ b/Core/Src/can_handler.c @@ -105,35 +105,33 @@ void vCanDispatch(void *pv_params) fault_data_t fault_data = { .id = CAN_DISPATCH_FAULT, .severity = DEFCON1 }; - can_msg_t msg_from_queue; - HAL_StatusTypeDef msg_status; + can_msg_t msg_from_queue = { + .id = 0x069, + .len = 4, + .data = { 69 } + }; + HAL_StatusTypeDef msg_status; CAN_HandleTypeDef *hcan = (CAN_HandleTypeDef *)pv_params; for (;;) { - osThreadFlagsWait(CAN_DISPATCH_FLAG, osFlagsWaitAny, - osWaitForever); - /* Send CAN message */ - while (osMessageQueueGet(can_outbound_queue, &msg_from_queue, - NULL, 0U) == osOK) { - /* Wait if CAN outbound queue is full */ - while (HAL_CAN_GetTxMailboxesFreeLevel(hcan) == 0) { - osDelay(1); - } - - msg_status = can_send_msg(can1, &msg_from_queue); - - if (msg_status == HAL_ERROR) { - fault_data.diag = "Failed to send CAN message"; - queue_fault(&fault_data); - } else if (msg_status == HAL_BUSY) { - fault_data.diag = "Outbound mailbox full!"; - queue_fault(&fault_data); - } - - /* Print Dispatch Messages */ - printf("Dispatch: %s", msg_from_queue.data); + /* Wait if CAN outbound queue is full */ + while (HAL_CAN_GetTxMailboxesFreeLevel(hcan) == 0) { + osDelay(1); + } + + msg_status = can_send_msg(can1, &msg_from_queue); + + if (msg_status == HAL_ERROR) { + fault_data.diag = "Failed to send CAN message"; + queue_fault(&fault_data); + } else if (msg_status == HAL_BUSY) { + fault_data.diag = "Outbound mailbox full!"; + queue_fault(&fault_data); } + + /* Print Dispatch Messages */ + printf("Dispatch: %s", msg_from_queue.data); } } @@ -153,18 +151,6 @@ void vCanReceive(void *pv_params) for (;;) { osThreadFlagsWait(NEW_CAN_MSG_FLAG, osFlagsWaitAny, osWaitForever); while (osOK == osMessageQueueGet(can_inbound_queue, &msg, 0U, 0U)) { - switch (msg.id) { - /* Messages Relevant to Motor Controller */ - case DTI_CANID_ERPM: - dti_record_rpm(mc, msg); - break; - case BMS_DCL_MSG: - handle_dcl_msg(); - break; - default: - break; - } - /* Print Receive Messages */ printf("Recieve: %s", msg.data); } From 1668342e334d8f5ef6bafe46362003a27a23720d Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 13 Oct 2024 16:56:15 -0400 Subject: [PATCH 08/10] Fix Not Used mc --- Core/Src/can_handler.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/Src/can_handler.c b/Core/Src/can_handler.c index c3617bb..656781e 100644 --- a/Core/Src/can_handler.c +++ b/Core/Src/can_handler.c @@ -144,7 +144,7 @@ const osThreadAttr_t can_receive_attributes = { void vCanReceive(void *pv_params) { - dti_t *mc = (dti_t *)pv_params; + //dti_t *mc = (dti_t *)pv_params; can_msg_t msg; @@ -152,7 +152,7 @@ void vCanReceive(void *pv_params) osThreadFlagsWait(NEW_CAN_MSG_FLAG, osFlagsWaitAny, osWaitForever); while (osOK == osMessageQueueGet(can_inbound_queue, &msg, 0U, 0U)) { /* Print Receive Messages */ - printf("Recieve: %s", msg.data); + printf("Recieve: %s", msg.data);x } } } \ No newline at end of file From 811a7c820a0a542e055bbf54a8b805a2b68b4218 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 13 Oct 2024 16:58:11 -0400 Subject: [PATCH 09/10] Fix Typo --- Core/Src/can_handler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/Src/can_handler.c b/Core/Src/can_handler.c index 656781e..1d1a858 100644 --- a/Core/Src/can_handler.c +++ b/Core/Src/can_handler.c @@ -152,7 +152,7 @@ void vCanReceive(void *pv_params) osThreadFlagsWait(NEW_CAN_MSG_FLAG, osFlagsWaitAny, osWaitForever); while (osOK == osMessageQueueGet(can_inbound_queue, &msg, 0U, 0U)) { /* Print Receive Messages */ - printf("Recieve: %s", msg.data);x + printf("Recieve: %s", msg.data); } } } \ No newline at end of file From 68311ac10a2357a89e122291ed549a8a822bb693 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 20 Oct 2024 17:21:25 -0400 Subject: [PATCH 10/10] Fixed a couple of issues --- Core/Src/can_handler.c | 11 +++++++---- Core/Src/main.c | 18 +++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Core/Src/can_handler.c b/Core/Src/can_handler.c index 1d1a858..b6fd953 100644 --- a/Core/Src/can_handler.c +++ b/Core/Src/can_handler.c @@ -77,11 +77,12 @@ void can1_callback(CAN_HandleTypeDef *hcan) new_msg.len = rx_header.DLC; new_msg.id = rx_header.StdId; - queue_and_set_flag(can_inbound_queue, &new_msg, can_receive_thread, - NEW_CAN_MSG_FLAG); + //queue_and_set_flag(can_inbound_queue, &new_msg, can_receive_thread, + // NEW_CAN_MSG_FLAG); /* Print Callback Messages */ - printf("Callback: %s", new_msg.data); + if (new_msg.id == 2) + printf("Callback: %s", new_msg.data); } int8_t queue_can_msg(can_msg_t msg) @@ -106,7 +107,7 @@ void vCanDispatch(void *pv_params) .severity = DEFCON1 }; can_msg_t msg_from_queue = { - .id = 0x069, + .id = 0x002, .len = 4, .data = { 69 } }; @@ -115,6 +116,8 @@ void vCanDispatch(void *pv_params) CAN_HandleTypeDef *hcan = (CAN_HandleTypeDef *)pv_params; for (;;) { + osDelay(500); + /* Wait if CAN outbound queue is full */ while (HAL_CAN_GetTxMailboxesFreeLevel(hcan) == 0) { osDelay(1); diff --git a/Core/Src/main.c b/Core/Src/main.c index 14d374a..ffea953 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -91,9 +91,9 @@ static void MX_DMA_Init(void);*/ static void MX_CAN1_Init(void); /*static void MX_I2C1_Init(void); static void MX_I2C2_Init(void); -static void MX_ADC1_Init(void); +static void MX_ADC1_Init(void);*/ static void MX_USART3_UART_Init(void); -static void MX_ADC3_Init(void); +/*static void MX_ADC3_Init(void); static void MX_IWDG_Init(void);*/ void StartDefaultTask(void *argument); @@ -160,9 +160,9 @@ int main(void) MX_CAN1_Init(); /*MX_I2C1_Init(); MX_I2C2_Init(); - MX_ADC1_Init(); + MX_ADC1_Init();*/ MX_USART3_UART_Init(); - MX_ADC3_Init(); + /*MX_ADC3_Init(); MX_IWDG_Init(); USER CODE BEGIN 2 @@ -584,8 +584,8 @@ static void MX_CAN1_Init(void) * @param None * @retval None */ -/*static void MX_USART3_UART_Init(void) -{*/ +static void MX_USART3_UART_Init(void) +{ /* USER CODE BEGIN USART3_Init 0 */ @@ -594,7 +594,7 @@ static void MX_CAN1_Init(void) /* USER CODE BEGIN USART3_Init 1 */ /* USER CODE END USART3_Init 1 */ - /*huart3.Instance = USART3; + huart3.Instance = USART3; huart3.Init.BaudRate = 115200; huart3.Init.WordLength = UART_WORDLENGTH_8B; huart3.Init.StopBits = UART_STOPBITS_1; @@ -605,12 +605,12 @@ static void MX_CAN1_Init(void) if (HAL_UART_Init(&huart3) != HAL_OK) { Error_Handler(); - }*/ + } /* USER CODE BEGIN USART3_Init 2 */ /* USER CODE END USART3_Init 2 */ -//} +} /** * Enable DMA controller clock