cancel
Showing results for 
Search instead for 
Did you mean: 

[BUG?] STM32F3 CAN transmit timeout

valentin
Senior
Posted on May 12, 2016 at 03:48

Hi,

I just noticed another oddity in the CubeMX HAL drivers:

when I send a CAN message on an empty bus the function HAL_CAN_Transmit(...) waits in a loop for the timeout and then cancel the sending of the frame:

/* Check End of transmission flag */

 

    while(!(__HAL_CAN_TRANSMIT_STATUS(hcan, transmitmailbox)))

 

    {

 

      /* Check for the Timeout */

 

      if(Timeout != HAL_MAX_DELAY)

 

      {

 

        if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))

 

        {

 

          hcan->State = HAL_CAN_STATE_TIMEOUT;

 

          /* Process unlocked */

 

          __HAL_UNLOCK(hcan);

 

          return HAL_TIMEOUT;

 

        }

 

      }

 

    }

 

 

But if I watch the bus activity, the controller continues to retry sending the message over and over again even though the timeout has occurred.

After having a look at the control registers, I suggest to add the following line to fix this and make the timeout work as expected (by me):

    /* Check End of transmission flag */

 

    while(!(__HAL_CAN_TRANSMIT_STATUS(hcan, transmitmailbox)))

 

    {

 

      /* Check for the Timeout */

 

      if(Timeout != HAL_MAX_DELAY)

 

      {

 

        if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))

 

        {

 

          hcan->State = HAL_CAN_STATE_TIMEOUT;

 

          /* Process unlocked */

 

          __HAL_UNLOCK(hcan);

 

          hcan->Instance->TSR |= (((uint32_t) 1 << (7 + transmitmailbox * 8))); // TODO: try to stop all retransmission tries

 

          return HAL_TIMEOUT;

 

        }

 

      }

 

    }

 

 

Setting the ABRQx bit in the CAN_TSR register cancels re-transmitting the message in transmit mailbox x.

Seems to work for me. During the loop the message is bein re-sent on the bus and after timeout - silence.

Opinions?

note: I have the ABOM bit SET so there is no hardware bus off management. I still think that after the timeout the retransmission tries should stop.
4 REPLIES 4
Walid FTITI_O
Senior II
Posted on May 13, 2016 at 17:54

Hi Valentin,

Thanks for contribution.

It is mentioned in reference manual:

ABRQ2

: Abort request for mailbox 2 Set by software to abort the transmission request for the corresponding mailbox. Cleared by hardware when the mailbox becomes empty. Setting this bit has no effect when the mailbox is not pending for transmission.

So, I presume that the timeout is reached but the transmission is not aborted. Can you check if your mailbox is empty or not when timeout is reached? Check also the status of TXOKx bit.

Meanwhile, I will check internally.

Thanks for the feedback.

-Hannibal-

valentin
Senior
Posted on May 19, 2016 at 06:45

Hi Hannibal,

thanks - I will check it once I have some free time.

Imen.D
ST Employee
Posted on January 19, 2017 at 19:11

Hello,

I want to thank you for your bug reported, this help us to improve our solutions.

I would inform you that this issue about HAL_CAN_Transmit  function reach timeout, is already fixed in the the last release of STM32CubeF3 V1.7.0.

Thanks for your contribution and all your feedback are welcome.

Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Posted on November 29, 2017 at 13:28

Hi,

I'm having the same Problem with STM32CubeF3 V1.9.0.

I have 1 STM32F2 and 1 STM32F3 on the CAN bus. If I add another STM32F3 to the bus, then after ~60-120

seconds one of the STM32F3 always returns with HAL_TIMEOUT from HAL_CAN_Transmit. hcan->State is always HAL_CAN_STATE_BUSY_TX and __HAL_CAN_TRANSMIT_STATUS(hcan, transmitmailbox) always returns false.