This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TDA4VM: Configure CSL MCAN example to receive data with multiple IDs

Part Number: TDA4VM

[Thread split from: https://e2e.ti.com/support/processors/f/791/t/935796]

I want to receive data with multiple IDs, such as 0x112~0x116, but the current acceptance filter only supports a single ID. How can I modify it?

The filter settings are as follows:

stdFiltelem.sfid2 = 0x0U;

stdFiltelem.sfid1 = 0x6U;

stdFiltelem.sfec = 0x7U;

stdFiltelem.sft = 0x0U;

The data read code is as follows:

while (gMcanIsrIntrRxFlag)

{}

gMcanIsrIntrRxFlag = 1U;



/* Checking for Errors */

MCAN_getErrCounters(gMcanModAddr, &errCounter);

if ((0U == errCounter.recErrCnt) &&

(0U == errCounter.canErrLogCnt))

{
    MCAN_getNewDataStatus(gMcanModAddr, &newDataStatus);

    MCAN_clearNewDataStatus(gMcanModAddr, &newDataStatus);

    MCAN_readMsgRam(gMcanModAddr,
                    MCAN_MEM_TYPE_BUF,
                    0U,
                    0U,
                    &rxMsg);
}

  • Hi  

    Can you please look at psdk_rtos_auto_j7_07_00_00_11/pdk_jacinto_07_00_00/packages/ti/csl/src/ip/mcan/mcan.h

    In this there is the structure for MCAN_StdMsgIDFilterElement i.e. the MCAN Standard Message ID Filter Element. You can configure a Range filter for your use case or set 5 different filters for each id 0x112, 0x113 ... 0x116.

    Regards,

    Karan

  • Hi Karan,

    Thank you for opening a new issue for me.

    I tried to use multiple filters for configuration, but I found that I could not configure more than 25 IDs. For example, in the following code, I set filter->filterNum to 32, and stdFiltelem[filterIdx].sfid1 from 0x400 to 0x420.

    All I receive is the data whose ID is in the range of 0x400~0x418.

    /* Initialize Tx Buffer Config params */
    for (filterIdx = 0; filterIdx < filter->filterNum; filterIdx++)
    {
    stdFiltelem[filterIdx].sfid2 = filterIdx;
    stdFiltelem[filterIdx].sfid1 = filter->recvId[filterIdx];
    stdFiltelem[filterIdx].sfec = 0x7U;
    stdFiltelem[filterIdx].sft = 0x0U;
    }

    for (filterIdx = 0; filterIdx < filter->filterNum; filterIdx++)
    {
    MCAN_addStdMsgIDFilter(mcanModAddr, filterIdx, &stdFiltelem[filterIdx]);
    }

    Regards!

    Kepei

  • Hi Kepei,

    Can you send me the source code? Or additional snippets for the code where you do the MCAN configuration (where you Initialize Message RAM Sections Configuration Parameters)

    Regards,

    Karan

  • Hi Karan,

    The attachment is my function to configure MCAN。

    Regards,

    Kepei

    #define APP_MCAN_STD_ID_FILT_START_ADDR          (0U)
    #define APP_MCAN_STD_ID_FILTER_NUM               (32U)
    #define APP_MCAN_EXT_ID_FILT_START_ADDR          (64U)  //(48U)
    #define APP_MCAN_EXT_ID_FILTER_NUM               (1U)
    #define APP_MCAN_TX_EVENT_START_ADDR             (100U)
    #define APP_MCAN_TX_EVENT_SIZE                   (5U)
    #define APP_MCAN_TX_BUFF_START_ADDR              (148U)
    #define APP_MCAN_TX_BUFF_SIZE                    (5U)
    #define APP_MCAN_TX_FIFO_SIZE                    (5U)
    #define APP_MCAN_FIFO_0_START_ADDR               (548U)
    #define APP_MCAN_FIFO_0_NUM                      (5U)
    #define APP_MCAN_FIFO_1_START_ADDR               (748U)
    #define APP_MCAN_FIFO_1_NUM                      (5U)
    #define APP_MCAN_RX_BUFF_START_ADDR              (948U)
    
    
    static int32_t tivxCantxMcanConfig(uint32_t *mcanBaseAddr, tivx_cantx_bitrate_e bitrate, tivx_cantx_std_filter *filter)
    {
        int32_t                    configStatus = CSL_PASS;
        MCAN_RevisionId            revId;
        MCAN_InitParams            initParams;
        MCAN_ConfigParams          configParams;
        MCAN_MsgRAMConfigParams    msgRAMConfigParams;
        MCAN_StdMsgIDFilterElement stdFiltelem[64];
        MCAN_BitTimingParams       bitTimes;
        uint16_t    filterIdx;
    
        uint32_t mcanModAddr = *mcanBaseAddr;
    
        /* Initialize MCAN Init params */
        initParams.fdMode          = 0x0U; //0x1U;
        initParams.brsEnable       = 0x0U;
        initParams.txpEnable       = 0x0U;
        initParams.efbi            = 0x0U;
        initParams.pxhddisable     = 0x0U;
        initParams.darEnable       = 0x1U;
        initParams.wkupReqEnable   = 0x1U;
        initParams.autoWkupEnable  = 0x1U;
        initParams.emulationEnable = 0x1U;
        initParams.emulationFAck   = 0x0U;
        initParams.clkStopFAck     = 0x0U;
        initParams.wdcPreload      = 0xFFU;
        initParams.tdcEnable       = 0x1U;
        initParams.tdcConfig.tdcf  = 0xAU;
        initParams.tdcConfig.tdco  = 0x6U;
        /* Initialize MCAN Config params */
        configParams.monEnable         = 0x0U;
        configParams.asmEnable         = 0x0U;
        configParams.tsPrescalar       = 0xFU;
        configParams.tsSelect          = 0x0U;
        configParams.timeoutSelect     = MCAN_TIMEOUT_SELECT_CONT;
        configParams.timeoutPreload    = 0xFFFFU;
        configParams.timeoutCntEnable  = 0x0U;
        configParams.filterConfig.rrfs = 0x1U;
        configParams.filterConfig.rrfe = 0x1U;
        configParams.filterConfig.anfe = 0x1U;
        configParams.filterConfig.anfs = 0x1U;
        /* Initialize Message RAM Sections Configuration Parameters */
        msgRAMConfigParams.flssa                = APP_MCAN_STD_ID_FILT_START_ADDR;
        msgRAMConfigParams.lss                  = filter->filterNum;   //APP_MCAN_STD_ID_FILTER_NUM;
        msgRAMConfigParams.flesa                = APP_MCAN_EXT_ID_FILT_START_ADDR;
        msgRAMConfigParams.lse                  = APP_MCAN_EXT_ID_FILTER_NUM;
        msgRAMConfigParams.txStartAddr          = APP_MCAN_TX_BUFF_START_ADDR;
        msgRAMConfigParams.txBufNum             = APP_MCAN_TX_BUFF_SIZE;
        msgRAMConfigParams.txFIFOSize           = 0U;
        msgRAMConfigParams.txBufMode            = 0U;
        msgRAMConfigParams.txBufElemSize        = MCAN_ELEM_SIZE_64BYTES;
        msgRAMConfigParams.txEventFIFOStartAddr = APP_MCAN_TX_EVENT_START_ADDR;
        msgRAMConfigParams.txEventFIFOSize      = APP_MCAN_TX_BUFF_SIZE;
        msgRAMConfigParams.txEventFIFOWaterMark = 3U;
        msgRAMConfigParams.rxFIFO0startAddr     = APP_MCAN_FIFO_0_START_ADDR;
        msgRAMConfigParams.rxFIFO0size          = APP_MCAN_FIFO_0_NUM;
        msgRAMConfigParams.rxFIFO0waterMark     = 3U;
        msgRAMConfigParams.rxFIFO0OpMode        = 0U;
        msgRAMConfigParams.rxFIFO1startAddr     = APP_MCAN_FIFO_1_START_ADDR;
        msgRAMConfigParams.rxFIFO1size          = APP_MCAN_FIFO_1_NUM;
        msgRAMConfigParams.rxFIFO1waterMark     = 3U;
        msgRAMConfigParams.rxFIFO1OpMode        = 0U;
        msgRAMConfigParams.rxBufStartAddr       = APP_MCAN_RX_BUFF_START_ADDR;
        msgRAMConfigParams.rxBufElemSize        = MCAN_ELEM_SIZE_64BYTES;
        msgRAMConfigParams.rxFIFO0ElemSize      = MCAN_ELEM_SIZE_64BYTES;
        msgRAMConfigParams.rxFIFO1ElemSize      = MCAN_ELEM_SIZE_64BYTES;
        /* Initialize Tx Buffer Config params */
        for (filterIdx = 0; filterIdx < filter->filterNum; filterIdx++)
        {
            stdFiltelem[filterIdx].sfid2 = filterIdx;
            stdFiltelem[filterIdx].sfid1 = filter->recvId[filterIdx];
            stdFiltelem[filterIdx].sfec  = 0x7U;
            stdFiltelem[filterIdx].sft   = 0x0U;
        }
        
        // stdFiltelem.sfid2 = 0x0U;
        // stdFiltelem.sfid1 = 0x6U;
        // stdFiltelem.sfec  = 0x7U;
        // stdFiltelem.sft   = 0x0U;
        /* Initialize bit timings
         * Configuring 1Mbps and 5Mbps as nominal and data bit-rate respectively */
        if(MCAN_BITRATE_500K == bitrate)
        {
            bitTimes.nomRatePrescalar   = 0xFU;
            bitTimes.nomTimeSeg1        = 0x5U;
            bitTimes.nomTimeSeg2        = 0x2U;
            bitTimes.nomSynchJumpWidth  = 0x0U;
            bitTimes.dataRatePrescalar  = 0xFU;     //0x1U;
            bitTimes.dataTimeSeg1       = 0x5U;     //0x3U;
            bitTimes.dataTimeSeg2       = 0x2U;     //0x2U;
            bitTimes.dataSynchJumpWidth = 0x0U;     //0x0U;
        }
        else if(MCAN_BITRATE_1000K == bitrate)
        {
            bitTimes.nomRatePrescalar   = 0x7U;
            bitTimes.nomTimeSeg1        = 0x5U;
            bitTimes.nomTimeSeg2        = 0x2U;
            bitTimes.nomSynchJumpWidth  = 0x0U;
            bitTimes.dataRatePrescalar  = 0x7U;     //0x1U;
            bitTimes.dataTimeSeg1       = 0x5U;     //0x3U;
            bitTimes.dataTimeSeg2       = 0x2U;     //0x2U;
            bitTimes.dataSynchJumpWidth = 0x0U;     //0x0U;
        }
        else
        {
            configStatus = CSL_EBADARGS;
            //error, bitrate not support
        }
    
        if(CSL_PASS == configStatus)
        {
            /* Get MCANSS Revision ID */
            MCAN_getRevisionId(mcanModAddr, &revId);
    
            /* wait for memory initialization to happen */
            while (FALSE == MCAN_isMemInitDone(mcanModAddr))
            {}
    
            /* Put MCAN in SW initialization mode */
            MCAN_setOpMode(mcanModAddr, MCAN_OPERATION_MODE_SW_INIT);
    
            while (MCAN_OPERATION_MODE_SW_INIT != MCAN_getOpMode(mcanModAddr))
            {}
    
            /* Initialize MCAN module */
            MCAN_init(mcanModAddr, &initParams);
    
            /* Configure MCAN module */
            MCAN_config(mcanModAddr, &configParams);
    
            /* Configure Bit timings */
            MCAN_setBitTime(mcanModAddr, &bitTimes);
            /* Set Extended ID Mask */
            MCAN_setExtIDAndMask(mcanModAddr, APP_MCAN_EXT_ID_AND_MASK);
            /* Configure Message RAM Sections */
            MCAN_msgRAMConfig(mcanModAddr, &msgRAMConfigParams);
            /* Configure Standard ID filter element */
    
            for (filterIdx = 0; filterIdx < filter->filterNum; filterIdx++)
            {
                MCAN_addStdMsgIDFilter(mcanModAddr, filterIdx, &stdFiltelem[filterIdx]);
            }
            
            // MCAN_addStdMsgIDFilter(mcanModAddr, 0U, &stdFiltelem);
            /* Take MCAN out of the SW initialization mode */
            MCAN_setOpMode(mcanModAddr, MCAN_OPERATION_MODE_NORMAL);
            while (MCAN_OPERATION_MODE_NORMAL != MCAN_getOpMode(mcanModAddr))
            {}
    
            /* Enable Interrupts */
            MCAN_enableIntr(mcanModAddr, MCAN_INTR_MASK_ALL, (uint32_t)TRUE);
    
            VX_PRINT(VX_ZONE_ERROR, "tivxCanTxCreate step 5\n");
            MCAN_enableIntr(mcanModAddr,
                            MCAN_INTR_SRC_RES_ADDR_ACCESS, (uint32_t)FALSE);
            /* Select Interrupt Line */
            VX_PRINT(VX_ZONE_ERROR, "tivxCanTxCreate step 6\n");
            MCAN_selectIntrLine(mcanModAddr,
                                MCAN_INTR_MASK_ALL,
                                MCAN_INTR_LINE_NUM_0);
            /* Enable Interrupt Line */
            MCAN_enableIntrLine(mcanModAddr,
                                MCAN_INTR_LINE_NUM_0,
                                1U);
    
            VX_PRINT(VX_ZONE_ERROR, "tivxCanTxCreate step 7\n");
            /* Enable Transmission interrupt */
            configStatus = MCAN_txBufTransIntrEnable(mcanModAddr,
                                                1U,
                                                (uint32_t)TRUE);
        }
    
        return configStatus;
    }
    

  • Hi Kepei,

    Visual inspection of the configuration looks fine. I am just thinking that is the Message RAM configuration correct, it might be possible that the filters which are being configured to accept IDs 0x419 to 0x420 are not actually being set in the Message RAM.

    Can you send me a memory dump of the Message Ram and the MCAN core registers for the MCAN you are using?

    Regards,

    Karan