AnsweredAssumed Answered

STM32F2 CAN Bus HAL Driver problem

Question asked by Pieter Roos on Sep 29, 2016
Latest reply on Sep 29, 2016 by Pieter Roos
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 ?

Outcomes