The CAN busoff interrupt event lost.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

The CAN busoff interrupt event lost.

Jump to solution
2,680 Views
cheney
Contributor III

Dear support team:

I have a problem when i process the busoff event. It will lose the Busoff event process in some cases.
The main CAN interrupt process flow is showed below.

CANInterrupt.bmp

When the bus off event is occured after the condition check ((esr_reg & CAN_ESR1_BOFFINT_MASK) != 0) in the callback function, the last operation (clear all interrupt flags) will clear the busoff flag(BOFFINT: bit2 of ESR1). So when we enter the interrupt again because of the busoff event, we will find the BOFFINT bit is not set and the busoff event will not be processed.

The solution in our side is to change the last operation from <Clear all error interrupt flags> to <clear the processed error interrupt flags>. Now it works fine.

Because it need change the SDK, so i hope you can give a solution that will not changed the SDK.

Best regards!

Cheney.

Labels (1)
Tags (1)
0 Kudos
1 Solution
2,342 Views
alexandrunan
NXP Employee
NXP Employee

As I told you your request affects the driver if I implemented some errors events can be lost, maybe you are not interested in that events but some else can use it, this is why user need to read first the ESR register. 

But we will evaluate if this impacts the driver or not !

View solution in original post

0 Kudos
11 Replies
2,343 Views
alexandrunan
NXP Employee
NXP Employee

As I told you your request affects the driver if I implemented some errors events can be lost, maybe you are not interested in that events but some else can use it, this is why user need to read first the ESR register. 

But we will evaluate if this impacts the driver or not !

0 Kudos
2,342 Views
cheney
Contributor III

Hi, Alexandru:

Thank you for you reply.

The RTM3.0.0 did not read the ESR register at first. This is why i hope you can evaluate this change.

pastedImage_1.png

0 Kudos
2,342 Views
alexandrunan
NXP Employee
NXP Employee

In the callback do you have a function that keeps isr asserted to much from what I saw from your example, probably in the callback you hook a big function call. Another issue can be is to remove from FLEXCAN_IRQHandler the part with esr check and handler error that is for other platform. In case of S32K144 have dedicated error handler if activated.

#if (defined(CPU_S32K116) || defined(CPU_S32K118))
uint32_t ecr = FLEXCAN_GetErrorCounters(base);

/* Check if any error occurred */
if (ecr != 0U)
{
FLEXCAN_Error_IRQHandler(instance);
}
#endif /* (defined(CPU_S32K116) || defined(CPU_S32K118)) */

BR,

Alexandru Nan

0 Kudos
2,342 Views
cheney
Contributor III

alexandrunan‌ I don't know if my description is clear for you? If anything is not clear, please let me know.

BR.

Cheney.

0 Kudos
2,342 Views
cheney
Contributor III

Hi, Alexandru:

Thank you for your reply.

I defined a CAN error process callback function as Figure2. And i install it when system is start.

FLEXCAN_DRV_InstallErrorCallback(canHwChannel, CanErrIsrCbk, NULL);

The following is the key code.

pastedImage_7.png

Figure 1: Error handler in flexcan_driver.c

pastedImage_5.png

Figure 2: CAN error handler callback funtion

  you can imagine such a scenario:

  1. CAN bus occurred a error interrupt(eg: stuff error).
  2. The FLEXCAN_Error_IRQHandler will be executed and it will call CanErrIsrCbk.
  3. Call api FLEXCAN_DRV_GetErrorStatus to read the ESR register(Figure 2: which is marked red) and process the error event.
  4. Bus off interrupt occurred after reading the ESR and before clear ESR register(Figure 1: which is marked red).
  5. Call api FLEXCAN_ClearErrIntStatusFlag to clear all interrupt status flag.( ** Now the ESR's busoff flag is cleared ** )
  6. The FLEXCAN_Error_IRQHandler will be executed again because of the busoff interrupt.
  7. Call api FLEXCAN_DRV_GetErrorStatus to read the ESR register, the busoff flag in ESR will be zero, so the busoff event will not be processed.

 Is there a way to evade the problem in the condition using the original the SDK?

Best Regards!

Cheney.

0 Kudos
2,342 Views
alexandrunan
NXP Employee
NXP Employee

To avoid this problem I suggest you to read ESR register and modify the FLEXCAN_ClearErrIntStatusFlag function to allow another parameter as mask to clear, and the Error_Handler.

Be aware that reading the ESR register can alter the content of the register from previous read by clear the status of some bits. RM : "Read this register to capture all error condition and status bits. This action clears the
respective bits that were set since the last read access."

This is way the driver was implemented by clear all condition and to user to read the status of errors to capture all the events.

void FLEXCAN_Error_IRQHandler(uint8_t instance)
{
DEV_ASSERT(instance < CAN_INSTANCE_COUNT);

CAN_Type * base = g_flexcanBase[instance];
flexcan_state_t * state = g_flexcanStatePtr[instance];

/* Invoke callback */

aux = read ESR;
if (state->error_callback != NULL)
{
state->error_callback(instance, FLEXCAN_EVENT_ERROR, state);
}

/* Clear all other interrupts in ESR1 register (Error, Busoff, Wakeup) */
FLEXCAN_ClearErrIntStatusFlag(base,aux);

return;
}

void FLEXCAN_ClearErrIntStatusFlag(CAN_Type * base, uint32_t aux)
{
if((base->ESR1 & FLEXCAN_ALL_INT) != 0U)
{
(base->ESR1) = FLEXCAN_ALL_INT&aux;
#ifdef ERRATA_E9005
/* Dummy read as a workaround for errata e9005 to ensure the flags are
cleared before continuing. */
(void)(base->ESR1);
#endif
}
}

BR,

Alexandru Nan

0 Kudos
2,342 Views
cheney
Contributor III

Hi, Alexandru:

alexandrunan‌ Could you give me a feedback about the SDK update request? 

0 Kudos
2,342 Views
cheney
Contributor III

Hi, Alexandru:

Appreciate for your reply.

It's a good solution for me. But it need to modify the SDK, Will you evaluate whether to add this change to the next SDK release?

BR,

Cheney.

0 Kudos
2,342 Views
alexandrunan
NXP Employee
NXP Employee

Hello Cheney,

First of all please tell what version of SDK do you use and on what platform, so we can identify your use case scenario !

0 Kudos
2,342 Views
cheney
Contributor III

Hi, Alexandru:

   Could you please help me analyze the issue and give me a solution. alexandrunan

Best regards!

Cheney.

0 Kudos
2,342 Views
cheney
Contributor III

Hi, Alexandru:

   The development environment is showed below.

   MCU: S32K144

   SDK: S32SDK_S32K1xx_RTM_3.0.0

   IDE: S32DS 2018.R1 180815

0 Kudos