AnsweredAssumed Answered

STM32 F7 HAL CAN bug

Question asked by Paolo Chiantore on Mar 21, 2017
Latest reply on Jun 15, 2017 by baranov.yury

We are using HAL CAN drivers for STM32 F7 (stm32f7xx_hal_can.c).

During CAN tx/rx stress tests we experienced an issue resulting in CAN receive hang.

The issue is due to a race condition on hcan->State variable between HAL_CAN_Transmit_IT  and CAN_Receive_IT.

The issue arises in the following conditions:

  1. hcan->State  is HAL_CAN_STATE_BUSY_RX
  2. HAL_CAN_Transmit_IT is called and enters condition  if(hcan->State == HAL_CAN_STATE_BUSY_RX)

  3. right after this, CAN_Transmit_IT is preempeted  by a CAN receive interrupt
  4. Within the CAN receive interrupt handler CAN_Receive_IT is called
  5. CAN_Receive_IT  sets  hcan->State = HAL_CAN_STATE_READY
  6. HAL_CAN_Transmit_IT resumes execution after the if at point2 and sets  hcan->State = HAL_CAN_STATE_BUSY_TX_RX

 

The final result is that when exiting HAL_CAN_Transmit_IT hcan->State is HAL_CAN_STATE_BUSY_TX_RX while it should have been HAL_CAN_STATE_BUSY_TX . From now on every attempt of further receptions with HAL_CAN_Receive_IT will fail.

 

Has someone experienced this issue before?

Are there avilable solutions to this HAL bug from ST?

 

 

 

Outcomes