cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMx CAN STM32F1 HAL_LOCK Problem

taraben
Senior
Posted on January 31, 2016 at 16:31

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.

--

#!stm32-!cubemx-!can-!bug
2 REPLIES 2
Amel NASRI
ST Employee
Posted on February 02, 2016 at 17:06

Hi adib,

The reported issue is under review looking for a fix.

Meanwhile, you may use the following workaround based on flags management:

1- in the HAL_CAN_RxCpltCallback(), add a flag RX_Ready

2- in the while(1) loop, set a flag TX_Done after the call of HAL_CAN_Transmit()

3- then check flags RX_Ready and TX_Done to call HAL_CAN_Receive_IT()

Please let me know if this workaround resolves your issue or you still have other limitations.

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

taraben
Senior
Posted on February 06, 2016 at 23:13

Hello Mayla,

in my case I disabled the NVIC for all CAN vector before transmitting.

After transmitting I enabled the NVIC for all CAN vectors.

The ISR was handled as expected after reenabling the NVIC channel.

But it should not be the responsibility of the application writer to take care about this.

This is the responsibility of the underlaying HAL functionality.

HTH, Adib.

--