2022-05-06 12:45 PM
Hello,
I'm trying to set up an interrupt when my FDCAN controller received a CAN message. MCU is an STM32G01B
I went into STCubeMX and I enabled these interrupts:
This generated some new functions instm32g0xx_it.c:
void TIM16_FDCAN_IT0_IRQHandler(void)
{
/* USER CODE BEGIN TIM16_FDCAN_IT0_IRQn 0 */
/* USER CODE END TIM16_FDCAN_IT0_IRQn 0 */
HAL_FDCAN_IRQHandler(&hfdcan1);
/* USER CODE BEGIN TIM16_FDCAN_IT0_IRQn 1 */
/* USER CODE END TIM16_FDCAN_IT0_IRQn 1 */
}
/**
* @brief This function handles TIM17, FDCAN1_IT1 and FDCAN2_IT1 Interrupt.
*/
void TIM17_FDCAN_IT1_IRQHandler(void)
{
/* USER CODE BEGIN TIM17_FDCAN_IT1_IRQn 0 */
/* USER CODE END TIM17_FDCAN_IT1_IRQn 0 */
HAL_FDCAN_IRQHandler(&hfdcan1);
/* USER CODE BEGIN TIM17_FDCAN_IT1_IRQn 1 */
/* USER CODE END TIM17_FDCAN_IT1_IRQn 1 */
}
This appears to call this function for RX FIFO on 0 and 1
/* Rx FIFO 0 interrupts management ******************************************/
if (RxFifo0ITs != 0U)
{
/* Clear the Rx FIFO 0 flags */
__HAL_FDCAN_CLEAR_FLAG(hfdcan, RxFifo0ITs);
#if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
/* Call registered callback*/
hfdcan->RxFifo0Callback(hfdcan, RxFifo0ITs);
#else
/* Rx FIFO 0 Callback */
HAL_FDCAN_RxFifo0Callback(hfdcan, RxFifo0ITs);
#endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
}
/* Rx FIFO 1 interrupts management ******************************************/
if (RxFifo1ITs != 0U)
{
/* Clear the Rx FIFO 1 flags */
__HAL_FDCAN_CLEAR_FLAG(hfdcan, RxFifo1ITs);
#if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
/* Call registered callback*/
hfdcan->RxFifo1Callback(hfdcan, RxFifo1ITs);
#else
/* Rx FIFO 1 Callback */
HAL_FDCAN_RxFifo1Callback(hfdcan, RxFifo1ITs);
#endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
}
I enabled interrupts after "HAL_FDCAN_Start(&hfdcan1);"
HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0);
HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO1_NEW_MESSAGE, 0);
(These both return HAL_OK, but I have also tried just using FDCAN_IT_RX_FIFO0_NEW_MESSAGE and not FDCAN_IT_RX_FIFO1_NEW_MESSAGE)
I then created the callback functions:
void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) {
serprintf("int0\n\r");
}
void HAL_FDCAN_RxFifo1Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) {
serprintf("int1\n\r");
}
They don't do anything except confirm being called.
I put breakponts at "HAL_FDCAN_IRQHandler(&hfdcan1);" for both functions, "void TIM16_FDCAN_IT0_IRQHandler(void)" and "void TIM17_FDCAN_IT0_IRQHandler(void)"
and neither of these functions get called when receiving a CAN message.
I'm not sure that I missed something. Any pointers?