cancel
Showing results for 
Search instead for 
Did you mean: 

Possible STM library bug in CAN interrupt routine

Vu.Andy
Associate III
Posted on March 23, 2018 at 17:23

I am using STM32F072 device and I am using STM library calls for all my CAN routines.  But I notice that occasionally, the main interrupt routine HAL_CAN_IRQHandler(&hcan) would not get called.

At the end of my HAL_CAN_RxCpltCallback(), I call

  if(HAL_CAN_Receive_IT(CanHandle, CAN_FIFO0) != HAL_OK)

  {

    /* Reception Error */

    _Error_Handler(__FILE__, __LINE__);

  }

so I think my codes are correct.

So what I do is at the end of my main while() loop, I would call : HAL_CAN_Receive_IT(&L_hcan, CAN_FIFO0)

and so far it seems to have solve my problem. 

So I think the possible problem was for whatever reason, the CAN receive IT was disabled somewhere in STM library routine which I am not able to figure it out yet.  I have seen similar issue in I2C library where I intentionally overwhelm

the I2C bus, STM library routine would incorrectly disable I2C interrupt.  And what I did there is similarly call I2C_IT at

the end of my main while() loop and that solved that problem.

Could anyone know where in the code that CAN would disable the Receive IT?

Thanks.

1 REPLY 1
Vu.Andy
Associate III
Posted on March 23, 2018 at 17:46

I also would like to add that in my error call back routine, I also call CAN_receive_IT

void HAL_CAN_ErrorCallback(CAN_HandleTypeDef *hcan)

{

  if(HAL_CAN_Receive_IT(&L_hcan, CAN_FIFO0) != HAL_OK)

  {

    /* Reception Error */

    _Error_Handler(__FILE__, __LINE__);

  }

}

so I am not sure where interrupt could be disabled.  It could be a timing thing which might be tricky to figure out.