Skip to main content
valentin
Associate III
May 12, 2016
Question

[BUG?] STM32F3 CAN transmit timeout

  • May 12, 2016
  • 4 replies
  • 1254 views
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.
    This topic has been closed for replies.

    4 replies

    Walid FTITI_O
    Visitor II
    May 13, 2016
    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
    valentinAuthor
    Associate III
    May 19, 2016
    Posted on May 19, 2016 at 06:45

    Hi Hannibal,

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

    ST Technical Moderator
    January 19, 2017
    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

    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
    Alex S
    Associate II
    November 29, 2017
    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.