Skip to main content
Javier1
Principal
July 1, 2022
Solved

CAN_Error_Code doesnt really do anyting? (stm32f0xx)

  • July 1, 2022
  • 3 replies
  • 1520 views

Hi im trying to develop a bit of error management in my canbus driver.

I noticed there is an ErrorCode inside the canbus structure.

0693W00000QKGYhQAP.png 

That error code could have any of these values:

0693W00000QKGaEQAX.png 

 

But it turns out the hcan.ErrorCode is always HAL_CAN_ERROR_NONE, even if the canbus is not plugged to anything wich should give any of these:

//#define HAL_CAN_ERROR_EPV (0x00000002U) /*!< Error Passive */
//#define HAL_CAN_ERROR_BOF (0x00000004U) /*!< Bus-off error */
 //#define HAL_CAN_ERROR_ACK (0x00000020U) /*!< Acknowledgment error */

Am i missing something out here? maybe something needs to be enabled somewhere in the HAL to get errors¿

This topic has been closed for replies.
Best answer by Javier1

This is not fixed yet:

What i ended up doing is my own thing ignoring the canbus error handler logic .

reseting the whole canbus peripheral when the mailboxes are full.

HAL_CAN_DeInit(_hcan);
		HAL_CAN_Init(_hcan);
		CanSETUPnoFilter(_hcan);

Because even if i "abort" the mailboxes the canbus TX is still jammed somehow.

HAL_CAN_AbortTxRequest(hcan_object_reference, CAN_TX_MAILBOX0+CAN_TX_MAILBOX1+CAN_TX_MAILBOX2);//empty all mailboxes

3 replies

Javier1
Javier1Author
Principal
July 1, 2022

Maybe i need to implement the error callback myself??

void (* ErrorCallback)(struct __CAN_HandleTypeDef *hcan); /*!< CAN Error callback */

 and make it modify the hcan struct.ErrorCode

hit me up in https://www.linkedin.com/in/javiermuñoz/
Javier1
Javier1Author
Principal
July 1, 2022

https://community.st.com/s/question/0D50X00009XkWlmSAF/stm32cube-fwl4-v1110-bug-in-new-can-driver

This helps, maybe i need to ignore HAL and use CAN_TSR register directly

hit me up in https://www.linkedin.com/in/javiermuñoz/
Javier1
Javier1AuthorBest answer
Principal
July 5, 2022

This is not fixed yet:

What i ended up doing is my own thing ignoring the canbus error handler logic .

reseting the whole canbus peripheral when the mailboxes are full.

HAL_CAN_DeInit(_hcan);
		HAL_CAN_Init(_hcan);
		CanSETUPnoFilter(_hcan);

Because even if i "abort" the mailboxes the canbus TX is still jammed somehow.

HAL_CAN_AbortTxRequest(hcan_object_reference, CAN_TX_MAILBOX0+CAN_TX_MAILBOX1+CAN_TX_MAILBOX2);//empty all mailboxes

hit me up in https://www.linkedin.com/in/javiermuñoz/