Hi Petrs,
I identified the issue behind the stop in receiving. After reading the code value of the MBs, I found that when it stops receiving the CAN IDs, it's in the OVERRUN state (0x6). Can you help me resolve this and get it back to a normal state where it can receive the CAN IDs again?
Here’s the code snippet I used for recovery:
`
static inline uint32_t FLEXCAN_GetMessageBufferCode(const CAN_Type *base, uint32_t mbIdx) {
if (mbIdx >= FEATURE_CAN_MAX_MB_NUM) {
return UINT32_MAX; // Invalid index
}
volatile uint32_t *flexcan_mb = FLEXCAN_GetMsgBuffRegion(base, mbIdx);
uint32_t flexcan_mb_config = *flexcan_mb; // Read the control/status register
uint32_t code = (flexcan_mb_config & FLEX_CAN_CS_CODE_MASK) >> 24; // Extract the CODE field
return code;
}
void UnlockOverrunMailbox(CAN_Type *base, uint32_t mbIdx) {
// Enter Freeze Mode to safely modify the mailbox
if (!FLEXCAN_EnterFreezeMode(base)) {
printf("Failed to enter Freeze Mode\n");
return;
}
// Check if the MB is in OVERRUN state
uint32_t mbCode = FLEXCAN_GetMessageBufferCode(base, mbIdx);
if (mbCode == FLEXCAN_RX_BUFFER_OVERRUN) {
printf("MB %u is in OVERRUN state. Unlocking it...\n", mbIdx);
// Reset the MB state to EMPTY (0x4) or INACTIVE (0x0)
base->RAMn[mbIdx * 4] = (base->RAMn[mbIdx * 4] & ~FLEX_CAN_CS_CODE_MASK) | (0b0100 << 24);
// Unlock the MB by reading the Free Running Timer
volatile uint32_t unlock = base->TIMER;
printf("MB %u unlocked and reset to EMPTY state.\n", mbIdx);
}
// Exit Freeze Mode
FLEXCAN_ExitFreezeMode(base);
}
```
However, the recovery is still not working.
I have a few questions related to this issue:
1. I configured three message buffers (MBs) for receiving, all filtered with the same CAN ID. In this case, the second MB went into the OVERRUN state, but why aren't the remaining two MBs receiving messages?
2. Is there any other process or method, apart from the code snippet above, to recover from this situation and resume receiving CAN IDs?
Thanks for your help!