cancel
Showing results for 
Search instead for 
Did you mean: 

F042K6 - stuck in CAN receive interrupt

retro
Associate III

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:)

1 ACCEPTED SOLUTION

Accepted Solutions
retro
Associate III

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

View solution in original post

12 REPLIES 12

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I am only sending one CAN message so the Rx FIFO should only have that message in it.

If i disable the IRQ then enable it again this gets fixed but I do not think it is a good practice

SKacp.1
Senior II

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);*/
}

I tried that already but it has no effect.​

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();
	  }
}

retro
Associate III

Hi, I tried this - no effect T_T

Sorry, I am quite a noob at this - how would I service the source completely? Do I just clear the FIFO?

Please share complete project.