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:
- hcan->State is HAL_CAN_STATE_BUSY_RX
HAL_CAN_Transmit_IT is called and enters condition if(hcan->State == HAL_CAN_STATE_BUSY_RX)
- right after this, CAN_Transmit_IT is preempeted by a CAN receive interrupt
- Within the CAN receive interrupt handler CAN_Receive_IT is called
- CAN_Receive_IT sets hcan->State = HAL_CAN_STATE_READY
- 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?