Hugo Bouchard

Bug in FlexCAN drivers for PXN20 on MQX 4.1

Discussion created by Hugo Bouchard on Jul 2, 2015
Latest reply on Jul 13, 2015 by Radek Sestak

Hi,

 

There is a bug in the FlexCAN driver for PXN20 in MQX 4.1. The FlexCAN example seems to work fine but in fact, it's not. The ISR is called only because the Tx interrupt is enabled, Rx interrupt doesn't work. The Tx interrupt sets the event with the IFLAG register value (in which the bit of the Rx buffer is set). If you disable it, the ISR is not called anymore, the event is not set and the Rx task waits forever.

 

the interrupts are not setup properly by the driver. Actually, if you look at the following function, vector_index variable is divided by 4!!! In the example, Rx message buffer is 1 so 1/4 = 0. The interrupt that is setup is the interrupt for message buffer 0 and not 1...

 

PSP_INTERRUPT_TABLE_INDEX _bsp_get_flexcan_vector

(

    /* [IN] FlexCAN device number */

     uint8_t  dev_num,

    /* [IN] FlexCAN interrupt vector type */

     uint8_t  vector_type,

    /* [IN] FlexCAN interrupt vector index */

     uint32_t vector_index

)

{

    PSP_INTERRUPT_TABLE_INDEX index = (PSP_INTERRUPT_TABLE_INDEX) 0;

 

    if ((FLEXCAN_INT_BUF==vector_type) && (31>=vector_index)) {

         vector_index = vector_index>>2;

    } else if (0 != vector_index) {

         return 0;

    }

 

    switch (dev_num)

    {

            case 0:

                 switch (vector_type)

                 {

                      case FLEXCAN_INT_BUF:

                          index = MPXN20_INTC_FLEXCAN_A_BUF_0_VECTOR+vector_index;

                          break;

                      case FLEXCAN_INT_ERR:

                          index = MPXN20_INTC_FLEXCAN_A_ERROR_VECTOR;

                          break;

                      case FLEXCAN_INT_BOFF:

                          index = MPXN20_INTC_FLEXCAN_A_BUS_OFF_WARN_VECTOR;

                          break;

                      default:

                          break;

                 }

                 break;

             case 1:

                  switch (vector_type)

                  {

                       case FLEXCAN_INT_BUF:

                           index = MPXN20_INTC_FLEXCAN_B_BUF_0_VECTOR+vector_index;

                           break;

                       case FLEXCAN_INT_ERR:

                           index = MPXN20_INTC_FLEXCAN_B_ERROR_VECTOR;

                           break;

                       case FLEXCAN_INT_BOFF:

                           index = MPXN20_INTC_FLEXCAN_B_BUS_OFF_WARN_VECTOR;

                           break;

                       default:

                           break;

                  }

                  break;

             case 2:

(...)

 

The lines in red above need to be commented out. Only a check if vector_index is not out of range should be done.

 

Hugo

Outcomes