AnsweredAssumed Answered

CubeMx CAN STM32F1 HAL_LOCK Problem

Question asked by adib on Jan 31, 2016
Latest reply on Feb 6, 2016 by adib
Hello All,

I am using latest CubeMx 4.12 generated example project using STM32F1 libs 1.3.
My Board is an Olimexino STM32 STM32F103RBT.

For testing I am using loopback mode.
before while(1) I enable receiving using HAL_CAN_REceive_IT().
within while(1) I transmit a datagram using HAL_CAN_Transmit().

This will trigger HAL_CAN_RxCpltCallback() while executing  HAL_CAN_Transmit().
But as this is triggered within __HAL_LOCK() __HAL_UNLOCK() statements of the transmit function,
I can not reenable receiving in HAL_CAN_RxCpltCallback() because the HAL is in Locked state.

This is a design flaw. I see 3 possible solutions:
1) prevent ISR execution within HAL_LOCK HAL_UNLOCK
2) before calling the callback fom ISR unlock the HAL
3) create additional functions to be executed within callback functions only

To be precise the way the libs are programmed will lead to unexpected behaviour.
So, call it a bug.

I was looking into the examples of teh STM32F1 libraries.
There in the CAN example within callback function the HAL_CAN_Receive_IT() is used to reenable the receive.

However I think you have to reconsider library design here.
In the real world I must not stop receiving, but must continue and cache received packets.
So a real solution will cache received packets and continue receiving until the user says so.

Best regards, Adib.