AnsweredAssumed Answered

FlexCAN bus error handling?

Question asked by Bob Lawson on Nov 9, 2018
Latest reply on Nov 12, 2018 by Bob Lawson

Are there any examples for S32 Design Studio for handling CAN bus errors using the FlexCAN driver? Our application needs to actively monitor bus warn, passive and bus off conditions. In the case of a bus off condition, we need to periodically reinitialize the FlexCAN hardware.


In flexcan_irq.c, I see that all CAN related interrupts are forwarded to the same interrupt handler:


/* Implementation of CAN0 IRQ handler for OR'ed interrupts (Bus Off,
Transmit Warning, Receive Warning). */
void CAN0_ORed_IRQHandler(void)


/* Implementation of CAN0 IRQ handler for interrupts indicating that errors were
detected on the CAN bus. */
void CAN0_Error_IRQHandler(void)


In FLEXCAN_IRQHandler() in flexcan_driver.c, the interrupt handler processes all normal transmit and receive interrupts then at the bottom of the handler calls:


/* Clear all other interrupts in ERRSTAT register (Error, Busoff, Wakeup) */


In FLEXCAN_ClearErrIntStatusFlag() in flexcan_hw_access.c, the error interrupt bits are simply cleared with no way of reporting any error status up to the application:


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


Am I missing something? This is my first experience with the FlexCAN driver but at first glance it appears that it has no support at all for CAN bus error detection / recovery.