cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 CAN Stops communication

eng23
Senior
Posted on August 16, 2017 at 21:39

Hello,

I'm working with STM32F0 and CAN communication, sometimes the CAN peripheral stops, doesn't send or receive messages.

In the past I asked the same issue and the answer was that it could be the HAL_LOCK funtion and it will be fix in the next revision. My version of stm32f0xx_hal_can.c is * @version V1.4.0, and now I've updated to V1.8, but the problem still happens.

Has anyone experienced this problem? How  can I fix it?

Thanks.

#can #busy #stm32
12 REPLIES 12
valentin
Senior
Posted on August 17, 2017 at 22:23

Ah, yes I have!

The FMPIE registers control whether an interrupt is created on received messages. So you basically want FMPIE0 and FMPIE1 to be enabled all the time.

Unfortunately, ST recently changed the behaviour of their HAL. The CAN error ISR now disables FMPIE completely and you have to restart it manually, which is a pain and caused me to stay with the older HAL firmware (F2 v1.4.0).

Have a look inside the ErrorInterrupt handler. In there, at the very bottom you'll see it disabling the FMPIE.

Solution: You can either hack the HAL and take those lines out or find a way to reliably re-enable FMPIE under all circumstances.

I couldn't be bothered so haven't really got a working solution at hand. But if you find one, I'd be interested!

Btw, once you have that sorted, you should still have a look at the electrical side of things on your bus. You either have termination issues or faulty nodes. Someone is causing the transmit/receive errors.

Posted on August 17, 2017 at 22:29

Dig into why it gets stuck in HAL_CAN_STATE_BUSY_RX0 and HAL_CAN_Receive_IT() errors (presumably HAL_BUSY).

How would it normally transition in/out of HAL_CAN_STATE_BUSY_RX0? Why is the RX interrupt not enabled? See where/why that gets turned off but remains in the busy state. Strikes me like there is an exit path that's not covered correctly.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on August 24, 2017 at 14:03

 ,

 ,

Hey all,

Well I've got a solution that fix the problem, here we have:

I've commented all the functions calling HAL_LOCK and HAL_UNLOCK in .c file and in the header 'stm32f0xx_hal_can.h' comment the flag CAN_TSR_TXOKx in the macro

__HAL_CAN_TRANSMIT_STATUS

:

♯ define __HAL_CAN_TRANSMIT_STATUS(__HANDLE__, __TRANSMITMAILBOX__)\

(((__TRANSMITMAILBOX__) == CAN_TXMAILBOX_0)? ((((__HANDLE__)->,Instance-

>,TSR) &, (CAN_TSR_RQCP0

/*| CAN_TSR_TXOK0*/

| CAN_TSR_TME0)) ==

(CAN_TSR_RQCP0

/*| CAN_TSR_TXOK0*/

| CAN_TSR_TME0)) :\

((__TRANSMITMAILBOX__) == CAN_TXMAILBOX_1)? ((((__HANDLE__)->,Instance-

>,TSR) &, (CAN_TSR_RQCP1

/*| CAN_TSR_TXOK1*/

| CAN_TSR_TME1)) ==

(CAN_TSR_RQCP1

/*| CAN_TSR_TXOK1*/

| CAN_TSR_TME1)) :\

((((__HANDLE__)->,Instance->,TSR) &, (CAN_TSR_RQCP2

/*| CAN_TSR_TXOK2*/

| CAN_TSR_TME2)) == (CAN_TSR_RQCP2

/*| CAN_TSR_TXOK2*/

|

CAN_TSR_TME2)))

Remember that it is for V1.4.

Thanks for the support!