skpang / Teensy36_with_mcp2517FD_CAN_FD_demo

MIT License
1 stars 0 forks source link

DRV_CANFDSPI_TransmitChannelConfigure accessing out of range value in canControlResetValues array #2

Closed ankit250ec closed 5 years ago

ankit250ec commented 5 years ago

Hi SK,

I was looking at the code and found out that DRV_CANFDSPI_TransmitQueueConfigure is accessing canControlResetValues[cREGADDR_CiFIFOCON / 4].
In drv_canfdspi_register.h : #define cREGADDR_CiFIFOCON 0x050

Hence, canControlResetValues[cREGADDR_CiFIFOCON / 4] is trying to access 21st (canControlResetValues[20]) value of the array whereas array is initialized with 20 elements.

`static uint32_t canControlResetValues[] = { / Address 0x000 to 0x00C /

ifdef CAN_TXQUEUE_IMPLEMENTED

0x04980760, 0x003E0F0F, 0x000E0303, 0x00021000,

else

0x04880760, 0x003E0F0F, 0x000E0303, 0x00021000,

endif

/* Address 0x010 to 0x01C */
0x00000000, 0x00000000, 0x40400040, 0x00000000,
/* Address 0x020 to 0x02C */
0x00000000, 0x00000000, 0x00000000, 0x00000000,
/* Address 0x030 to 0x03C */
0x00000000, 0x00200000, 0x00000000, 0x00000000,
/* Address 0x040 to 0x04C */
0x00000400, 0x00000000, 0x00000000, 0x00000000

};`

int8_t DRV_CANFDSPI_TransmitQueueConfigure(CANFDSPI_MODULE_ID index,
        CAN_TX_QUEUE_CONFIG* config)
{
#ifndef CAN_TXQUEUE_IMPLEMENTED
    config;
    return -100;
#else
    int8_t spiTransferError = 0;
    uint16_t a = 0;

    // Setup FIFO
    REG_CiTXQCON ciFifoCon;
    ciFifoCon.word = canControlResetValues[cREGADDR_CiFIFOCON / 4];

    ciFifoCon.txBF.TxEnable = 1;
    ciFifoCon.txBF.FifoSize = config->FifoSize;
    ciFifoCon.txBF.PayLoadSize = config->PayLoadSize;
    ciFifoCon.txBF.TxAttempts = config->TxAttempts;
    ciFifoCon.txBF.TxPriority = config->TxPriority;

    a = cREGADDR_CiTXQCON;
    spiTransferError = DRV_CANFDSPI_WriteWord(index, a, ciFifoCon.word);

    return spiTransferError;
#endif    
}

Is there anything I am missing?

Thanks and Regards, Ankit

skpang commented 5 years ago

The driver code is from Microchip's website: https://www.microchip.com/wwwproducts/en/MCP2517FD

ankit250ec commented 5 years ago

Ok SK...Thanks :)