cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F2 CAN Bus HAL Driver problem

pieter2
Associate
Posted on September 29, 2016 at 12:29

Hi

This is my first post on this forum, so please excuse me if I don't follow the correct procedure.

I think there are a problem with the STM32F2 HAL firmware driver version 1.4.0. I am using IAR Embedded workbench. I was checking the HAL_CAN_Transmit() and HAL_CAN_Transmit_IT() functions to see how it handle a transmit mailbox overflow condition. I have discovered the following problem: In HAL_CAN_Transmit() it check for an available transmit mailbox and when done it does the following:

if(transmitmailbox != CAN_TXSTATUS_NOMAILBOX)

{

  //it load the CAN bus packet in the mailbox and send it.

}

else

{

   //do some stuff

  return HAL_ERROR;

}

So if no mailbox is available it return with an HAL_ERROR. But in HAL_CAN_Transmit_IT() it does the same check for available transmit mailboxes, but the ''if(transmitmailbox != CAN_TXSTATUS_NOMAILBOX)'' have no ''else'' clause. The program will fall through to the end of the function and return with HAL_OK. So if the mailboxes are full, the user will think that the packet was loaded and send, but in reality the packet will be lost.

I also see another problem, if I understand the CAN bus peripheral correctly, the use can load another CAN packet in the transmit mailbox even while the CAN bus is busy sending another mailbox. But in bother the above functions, a check is done on the status of the CAN bus: if((tmp == HAL_CAN_STATE_READY) || (tmp == HAL_CAN_STATE_BUSY_RX))

Only if the CAN bus s ready or busy receiving, can you load a new packet in an available transmit mailbox. What about HAL_CAN_STATE_BUSY_TX_RX and HAL_CAN_STATE_BUSY_TX ?
2 REPLIES 2
Walid FTITI_O
Senior II
Posted on September 29, 2016 at 15:01

Hi Pieter Roos, 

It seems you are confusing driver's versions. The points you are talking about had existed in an old driver version and where fixed since driver version V1.1.3 which was delivered in the STM32CubeF2 V1.4.0.

Try to download again the last version from this

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef2.html?dl=3LiNVFp/6xP96tnQbVnwzQ%3D%3D%2cB65ULC9wWdnbVmIHCqaY0YdiuoFome9XzNu7qQWecHxhxAL029XRf8cqpCzserml

-Hannibal-
pieter2
Associate
Posted on September 29, 2016 at 15:12

Hi Hannibal

Yes, I think you are correct, I had a look at the header in the HAL driver files and it is labeled ver 1.1.2, Dated 11 Dec 2015. I do have the latest driver installed, but I think I have to generate the code again in cube and make sure it use the latest driver.

Thanks for your feedback.

Regards

Pieter