diff --git a/Core/Inc/stm32f4xx_it.h b/Core/Inc/stm32f4xx_it.h index 232bacd..53e0c55 100644 --- a/Core/Inc/stm32f4xx_it.h +++ b/Core/Inc/stm32f4xx_it.h @@ -52,6 +52,7 @@ void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void DebugMon_Handler(void); +void CAN1_RX0_IRQHandler(void); void TIM5_IRQHandler(void); void DMA2_Stream0_IRQHandler(void); /* USER CODE BEGIN EFP */ diff --git a/Core/Src/can_handler.c b/Core/Src/can_handler.c index 460ee90..373c666 100644 --- a/Core/Src/can_handler.c +++ b/Core/Src/can_handler.c @@ -21,6 +21,8 @@ #define CAN_MSG_QUEUE_SIZE 25 /* messages */ static osMessageQueueId_t can_outbound_queue; +static uint32_t id_list[4] = { 0x000, 0x000, 0x000, 0x002 }; + extern CAN_HandleTypeDef hcan1; can_t *can1; @@ -32,7 +34,7 @@ void can1_init() assert(can1); can1->hcan = &hcan1; - + assert(!can_add_filter(can1, id_list)); assert(!can_init(can1)); #endif diff --git a/Core/Src/main.c b/Core/Src/main.c index b2d69b2..4a52f72 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -406,7 +406,7 @@ static void MX_CAN1_Init(void) hcan1.Init.TimeTriggeredMode = DISABLE; hcan1.Init.AutoBusOff = ENABLE; hcan1.Init.AutoWakeUp = DISABLE; - hcan1.Init.AutoRetransmission = DISABLE; + hcan1.Init.AutoRetransmission = ENABLE; hcan1.Init.ReceiveFifoLocked = DISABLE; hcan1.Init.TransmitFifoPriority = DISABLE; if (HAL_CAN_Init(&hcan1) != HAL_OK) diff --git a/Core/Src/stm32f4xx_hal_msp.c b/Core/Src/stm32f4xx_hal_msp.c index 2fd16dd..682805d 100644 --- a/Core/Src/stm32f4xx_hal_msp.c +++ b/Core/Src/stm32f4xx_hal_msp.c @@ -195,6 +195,9 @@ void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan) GPIO_InitStruct.Alternate = GPIO_AF9_CAN1; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + /* CAN1 interrupt Init */ + HAL_NVIC_SetPriority(CAN1_RX0_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(CAN1_RX0_IRQn); /* USER CODE BEGIN CAN1_MspInit 1 */ /* USER CODE END CAN1_MspInit 1 */ @@ -224,6 +227,8 @@ void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan) */ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12); + /* CAN1 interrupt DeInit */ + HAL_NVIC_DisableIRQ(CAN1_RX0_IRQn); /* USER CODE BEGIN CAN1_MspDeInit 1 */ /* USER CODE END CAN1_MspDeInit 1 */ diff --git a/Core/Src/stm32f4xx_it.c b/Core/Src/stm32f4xx_it.c index 25a348d..b83ccd0 100644 --- a/Core/Src/stm32f4xx_it.c +++ b/Core/Src/stm32f4xx_it.c @@ -56,6 +56,7 @@ /* External variables --------------------------------------------------------*/ extern DMA_HandleTypeDef hdma_adc1; +extern CAN_HandleTypeDef hcan1; extern TIM_HandleTypeDef htim5; /* USER CODE BEGIN EV */ @@ -173,6 +174,20 @@ void DebugMon_Handler(void) /* please refer to the startup file (startup_stm32f4xx.s). */ /******************************************************************************/ +/** + * @brief This function handles CAN1 RX0 interrupts. + */ +void CAN1_RX0_IRQHandler(void) +{ + /* USER CODE BEGIN CAN1_RX0_IRQn 0 */ + + /* USER CODE END CAN1_RX0_IRQn 0 */ + HAL_CAN_IRQHandler(&hcan1); + /* USER CODE BEGIN CAN1_RX0_IRQn 1 */ + + /* USER CODE END CAN1_RX0_IRQn 1 */ +} + /** * @brief This function handles TIM5 global interrupt. */ diff --git a/MSB-FW.ioc b/MSB-FW.ioc index ecc3d94..0dece5d 100644 --- a/MSB-FW.ioc +++ b/MSB-FW.ioc @@ -28,7 +28,7 @@ CAN1.CalculateBaudRate=500000 CAN1.CalculateTimeBit=2000 CAN1.CalculateTimeQuantum=125.0 CAN1.IPParameters=CalculateTimeQuantum,CalculateTimeBit,CalculateBaudRate,Prescaler,BS1,BS2,ABOM,NART -CAN1.NART=DISABLE +CAN1.NART=ENABLE CAN1.Prescaler=2 Dma.ADC1.0.Direction=DMA_PERIPH_TO_MEMORY Dma.ADC1.0.FIFOMode=DMA_FIFOMODE_DISABLE @@ -104,6 +104,7 @@ Mcu.UserName=STM32F405RGTx MxCube.Version=6.11.1 MxDb.Version=DB.6.0.111 NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false +NVIC.CAN1_RX0_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true NVIC.DMA2_Stream0_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false NVIC.ForceEnableDMAVector=true diff --git a/Makefile b/Makefile index 612ceb5..615e3c4 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ ########################################################################################################################## -# File automatically-generated by tool: [projectgenerator] version: [4.3.0-B58] date: [Fri Oct 18 02:28:33 GMT 2024] +# File automatically-generated by tool: [projectgenerator] version: [4.3.0-B58] date: [Fri Nov 08 02:15:30 GMT 2024] ########################################################################################################################## # ------------------------------------------------