AnsweredAssumed Answered

[Bug report] : CubeMx CAN STM32F1 HAL_CAN_Receive_IT Problem

Question asked by surleau.frederic on Oct 14, 2016
Latest reply on Oct 31, 2016 by surleau.frederic
References :
  STM32CudeMX 4.16.0
  STM32Cube_FW_F1_V1.4.0
  STM32F103CBT6

The project uses FREERTOS.

Hi All,

Once CAN is configured and filters are set, I call HAL_CAN_Receive_IT : OK

On receiving a CAN frame, HAL_CAN_RxCpltCallback is called : OK
  In HAL_CAN_RxCpltCallback, a signal is sent to a thread to handle the frame.
  The thread receiving the signal, reads the frame an then calls HAL_CAN_Receive_IT for next frames : OK

At some time, the application calls HAL_CAN_Transmit_IT to send a frame : OK
When the frame is sent, HAL_CAN_TxCpltCallback is then called : multiple times...

It is not only called when the frame is sent, it is also called when a frame is received, because in stm32f1xx_hal_can.c, the function HAL_CAN_Receive_IT enables "Transmit mailbox empty Interrupt" ( CAN_IT_TME ).
I think it should not !

All CAN IRQ Handlers generated by STM32CudeMX calls the same function HAL_CAN_IRQHandler in stm32f1xx_hal_can.c.
CAN_Transmit_IT is called because CAN_IT_TME has been enabled and the status of CAN_TXMAILBOX_* haven't changed.

Removing "CAN_IT_TME" in HAL_CAN_Receive_IT solved the problem for me.

Best regards, Frédéric.

Outcomes