F042K6 - stuck in CAN receive interrupt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-29 6:04 AM
Hello,
I am trying to set up CAN communication on my F042K6 using the HAL library. I have followed the stm guide (attached). I got most of the functionality working, however if i try to use the Rx interrupt using "void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef*hcan)" the MCU gets stuck in this interrupt when it receives a message. I do not know what i am doing wrong and why I cannot leave the interrupt. I think it might have something to do with the NVIC interrupt priorities maybe? If someone could help me out it would be greatly appreciated. Please see attached my code, NVIC settings and the guide i followed.
Thank you:)
Solved! Go to Solution.
- Labels:
-
CAN
-
STM32Cube MCU Packages
-
STM32F0 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-30 3:17 AM
For anyone that runs into a simillar issue:
I found the problem, it was just me being an idiot. I wrote: HAL_CAN_GetRxMessage(&hcan,CAN_RX_FIFO0,&RxHeader,RxData); instead of HAL_CAN_GetRxMessage(hcan,CAN_RX_FIFO0,&RxHeader,RxData); so had the extra &. The GetRxMessage also clears the message from the buffer so the interrupt kept cycling as it was seeing a message in the buffer as per Cortex-M mechanics
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-29 6:14 AM
The mechanics of the Cortex-M parts is that the interrupts will tail-chain endlessly if you fail to service the source completely. See Interrupt Storm
Dump registers of offending peripheral and NVIC, understand what is being left pending/flagging.
The FIFO can contain more than one item, if the servicing gets diverted into other work more data may arrive in the mean time.
If you have no new data from a TXE interrupt, disable it until you do.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-29 6:19 AM
I am only sending one CAN message so the Rx FIFO should only have that message in it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-29 6:21 AM
If i disable the IRQ then enable it again this gets fixed but I do not think it is a good practice
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-29 10:49 AM
Hi,
I propose remove from interrupt function HAL_CAN_RxFifo0MsgPendingCallback call to the HAL_Delay(1000).
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef*hcan)
{
/*add error handler here*/
HAL_CAN_GetRxMessage(&hcan,CAN_RX_FIFO0,&RxHeader,RxData);
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_3);
/*HAL_CAN_MspDeInit(hcan);*/
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-29 10:51 AM
I tried that already but it has no effect.​
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-29 11:02 AM
Hi,
Please remove from function "config_CAN_interrupt" interrupt "CAN_IT_TX_MAILBOX_EMPTY" and check again.
static void config_CAN_interrupt(void)
{
if(HAL_CAN_Start(&hcan)!=HAL_OK) /*start CAN*/
{
Error_Handler();
}
if(HAL_CAN_ActivateNotification(&hcan,CAN_IT_RX_FIFO0_MSG_PENDING) !=HAL_OK) /*configure CAN interrupt*/
{
Error_Handler();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-30 12:59 AM
Hi, I tried this - no effect T_T
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-30 1:01 AM
Sorry, I am quite a noob at this - how would I service the source completely? Do I just clear the FIFO?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-30 1:53 AM
Please share complete project.
