2016-05-11 06:48 PM
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.
2016-05-13 08:54 AM
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-
2016-05-18 09:45 PM
Hi Hannibal,
thanks - I will check it once I have some free time.2017-01-19 10:11 AM
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
2017-11-29 05:28 AM
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.