Hi Alexis,
thanks for the explanations, but I think my problem is on how the callback IRQ function detect ErrorPassive and Buss-Off state: it seems that the standard callback uint32_t result parameter in
static void mcan_callback(CAN_Type *base, mcan_handle_t *handle, status_t status, uint32_t result, void *userData)
can't distinguish from BussOff, ErrorPassive or ErrorWarning (using flags kMCAN_ErrorWarningIntFlag, kMCAN_ErrorPassiveIntFlag or kMCAN_BusOffIntFlag) because in sdk.2.7 the MCAN_TransferHandleIRQ function in fsl_mcan.c file sets always all the three flags as result even if there is only one condition detected.
void MCAN_TransferHandleIRQ(CAN_Type *base, mcan_handle_t *handle)
{
[...]
do
{
if (0U != (valueIR & ((uint32_t)kMCAN_ErrorWarningIntFlag |
(uint32_t)kMCAN_ErrorPassiveIntFlag |
(uint32_t)kMCAN_BusOffIntFlag)))
{
result = (uint32_t)kMCAN_ErrorWarningIntFlag |
(uint32_t)kMCAN_ErrorPassiveIntFlag |
(uint32_t)kMCAN_BusOffIntFlag;
status = kStatus_MCAN_ErrorStatus;
}
Is this correct?
Starting from this point now I detect the real error condition/status in my callback manager:
if(((USE_MCAN->PSR & CAN_PSR_BO_MASK)>>CAN_PSR_BO_SHIFT)==1)
{
MCAN_Deinit(USE_MCAN);
open_can();
while((((USE_MCAN->PSR & CAN_PSR_LEC_MASK)>>CAN_PSR_LEC_SHIFT)==0x5) ||
(((USE_MCAN->PSR & CAN_PSR_BO_MASK)>>CAN_PSR_BO_SHIFT)==1));
}
else if(((USE_MCAN->PSR & CAN_PSR_EP_MASK)>>CAN_PSR_EP_SHIFT)==1)
{
USE_MCAN->CCCR |= CAN_CCCR_INIT_MASK;
while (!((USE_MCAN->CCCR & CAN_CCCR_INIT_MASK) >> CAN_CCCR_INIT_SHIFT));
MCAN_EnterNormalMode(USE_MCAN);
}
What do you think about this?
I think my wrong BusOff detections were not bus-off problems but error passive detections caused by the cable disconnection manager... so now the firmware should manage the ErrorPassive status... any suggestion to recovery the Error_Passive status?