2017-03-21 07:31 AM
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:
HAL_CAN_STATE_BUSY_RX
HAL_CAN_Transmit_IT is called and enters condition
if
(hcan->
State
==
HAL_CAN_STATE_BUSY_RX
)
hcan->
State
=
HAL_CAN_STATE_READY
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 beenHAL_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?
2017-03-24 02:18 AM
Also came across what looks to be this problem recently, using the STM32F4 HAL drivers. CAN bus worked okay sending infrequent messages, but as soon as I was transmitting a CAN packet once per millisecond (with occasional extras), the rx interrupt would get disabled, and I'd stop receiving anything.
I didn't drill into it quite as much as Paolo, but it sounds pretty similar.
My solution so far has just been to recall HAL_
CAN_Receive_IT after every HAL_CAN_Transmit
_IT
2017-05-02 03:37 AM
First encountered this issue in 2014 with both F2 and F4. The exact same symptoms as what Paolo described.
Calling HAL_
CAN_Receive_IT again after every HAL_CAN_Transmit
_IT
wouldn't help againstHAL_CAN_STATE_BUSY_TX_RX
, as HAL_CAN_Receive_IT
would return without any action.Edit: Wouldn't correct interrupt priorities (identical preemption and subpriorities for both Rx and Tx) resolve the issue?
Edit: Edit: Nevermind, it wouldn't, because the state is changed from a regular function not an interrupt handler. However, a critical section around HAL_CAN_Transmit
_IT
might help.2017-05-02 10:47 PM
HAL drivers STM32Cube_FW_F4_V1.16.0 seem to have more inner states in attempt to overcome the issue
You may like looking at them and modifying your current F7 drivers accordingly
2017-05-03 02:14 AM
Hello,
Please update your firmware package for STM32F4 anf STM32F7 to use the last version as contains HAL CAN update with fix defects and enhancement.
Thanks
Imen
2017-05-08 07:55 AM
What is the version number of the HAL libraries with this fix? I use the HAL libraries through uvision and there doesn't seem to be an update to the software pack they come in. My current version is 1.6 which seems to be from last year (and I believe the version I had the issue with).
2017-05-08 08:08 AM
Hi
van_Beek.Jonathan
,The last version is
V1.0 forHAL drivers version 1.7.1 / 14-April 20172017-05-08 08:30 AM
Thanks for the quick response. I do not use STM32CubeF4 though, I use the HAL drivers through the uvision software packs - are these maintained by ST?
I am currently using the STM32F4xx_DFP software pack, version 2.11.0. Can you advise when this will be updated?
2017-05-18 08:36 AM
This just seems to add extra states to distinguish between the two RX FIFOs, I'm not sure it will solve the original problem?
2017-05-18 08:39 AM
Please can you comment on whether the original issue on this thread is addressed? I'm looking at the new code for the CAN HAL driver, and I'm not sure it will solve this issue?