IMX6SX FreeRTOS BSP 1.0.0 FlexCan driver IFLAG2 bug

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

IMX6SX FreeRTOS BSP 1.0.0 FlexCan driver IFLAG2 bug

949 Views
rowangifford
Contributor II


FYI's I found a bug in the IMX6SX FreeRTOS BSP v.1.0.0 flexcan driver. Interrupt registers for message buffers > 31 are not addressed correctly, meaning getting, setting or clearing interrupts on message boxes with an ID > 31 doesn't work.

In ./platform/drivers/src/flexcan.c the following functions

FLEXCAN_SetMsgBufIntCmd

FLEXCAN_GetMsgBufStatusFlag

FLEXCAN_ClearMsgBufStatusFlag

when checking the message buffer id the hex value 0x31 is used,but it should be decimal 31. In  FLEXCAN_ClearMsgBufStatusFlag only IFLAG1 is assigned, ignoring IFLAG2.

E.g. existing

void FLEXCAN_ClearMsgBufStatusFlag(CAN_Type* base, uint32_t msgBufIdx)

{

    volatile uint8_t index;

    assert(msgBufIdx < CAN_CS_COUNT);

    if (msgBufIdx > 0x31)

        index = msgBufIdx - 32;

    else

        index = msgBufIdx;

    /* The Interrupt flag must be cleared by writing it to '1'.

     * Writing '0' has no effect.

     */

    base->IFLAG1 = 0x1 << index;

}

should be

void FLEXCAN_ClearMsgBufStatusFlag(CAN_Type* base, uint32_t msgBufIdx)

{

    volatile uint8_t index;

    volatile uint32_t* interruptFlagPtr;

    assert(msgBufIdx < CAN_CS_COUNT);

    if (msgBufIdx > 31) {

        index = msgBufIdx - 32;

        interruptFlagPtr = &base->IFLAG2;

    }

    else {

        index = msgBufIdx;

        interruptFlagPtr = &base->IFLAG1;

    }

    /* The Interrupt flag must be cleared by writing it to '1'.

     * Writing '0' has no effect.

     */

    *interruptMaskPtr |= 0x1 << index;

}

Labels (1)
0 Replies