Hello,
When I initially setup FlexCAN peripheral for non-FD function, my S32K148 unit works as intended, it receives CAN messages from other participants and transmits its own messages. However, when I put the MCU to sleep and wake it up again, I get stuck in a bus off state and can't recover.
This is how I deinitialize the FlexCAN peripheral before putting the MCU to sleep:
// 1. Switch the FlexCAN to FREEZE mode and deactivate it.
CAN0->MCR |= CAN_MCR_FRZ(1U) | CAN_MCR_HALT(1U);
if ((CAN0->MCR & CAN_MCR_MDIS_MASK) != 0x0)
{
CAN0->MCR &= ~CAN_MCR_MDIS_MASK;
}
while ((CAN0->MCR & CAN_MCR_FRZACK_MASK) == 0x0) { ; }
// 2. Disconnect clock source.
PCC->PCCn[PCC_FlexCAN0_INDEX] &= ~PCC_PCCn_CGC_MASK;
I put the MCU to sleep mode using asm("WFI");
When the wake up condition occours, the MCU wakes up correctly, I jump at the beginning of the main function in order to initialize all peripherals in the same way, but the CAN0 module gets stuck in bus off state. I checked the values of control registers of the CAN0 module after the first initialization and after the wakeup initialization. All values are the same except for:
ECR - after the first initialization, the counters are all zeroed, after wakeup it shows non zero value of the RXERRCNT, which increases after I continue the debug session, but never keeps a constant value.
ESR1 - after the first initialization also zeroed, after wakeup it shows ERRINT = 1.
ESR2 - after first initialization IMB = 1, after wakeup, both IMB and VPS = 1.
I have the automatic bus off recovery option enabled in the CTRL1 register and don't try to transmit any messages when the bus off state is active. But unfortunately, I never leave the bus off state, only after resetting the MCU, which causes loss of data.
Thanks for advice!
Tomas