When I initialize flexcan, the set of maximum number of mailboxes invaild sometimes.Before set the maximum number of mailboxes, I did soft reset can and then,wait for reset cycle to complete.After this configuration, I find that the value of MAXMB in resgister MCR will goes back to the default value:0x0f sometimes.
But,if I delay 1ms after soft reset ,the invaild of MAXMB never happens.Did I missing some steps?
Here is my code:
/* Reset the FLEXCAN */
base->MCR = (base->MCR & ~CAN_MCR_SOFTRST_MASK) | CAN_MCR_SOFTRST(1U);
/* Wait for reset cycle to complete */
while (((base->MCR & CAN_MCR_SOFTRST_MASK) >> CAN_MCR_SOFTRST_SHIFT) != 0U){}
// hwDelay(1000);
base->MCR = (base->MCR & ~CAN_MCR_MAXMB_MASK) | CAN_MCR_MAXMB(31);
Hi,
MAXMB can be changed in Freeze mode only, so rather put module into Freeze mode, i.e. check if module is active (MDIS=0) and FRZ and HALT bits set, then check for FRZACK to be set.
Not sure of the device you have but for example S32K1xx's procedure to enter Freeze mode is given in chapter 55.1.9.1 Freeze mode entry of the device RM.
BR, Petr