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.

CCS/AWR1843BOOST: AR1843: CAN CONFİGURATİON

Part Number: AWR1843BOOST
Other Parts Discussed in Thread: AWR1843

Tool/software: Code Composer Studio

Hello, I just started radar work. I'm new to this.

I proceed by running the existing TI mmwave_automotive_toolbox_3_2_0 Labs.

I need the classic Can. I could not find a lab with classic Can communication. No problem in CanFD, I was able to run it. But I could not initiate the classic Can in any way. Resources are very limited in this regard, I would be glad if you could help.

  • Hello,

    Could you please check the CAN driver test available in the SDK at the following path?

    C:\ti\mmwave_sdk_03_05_00_04\packages\ti\drivers\can\test

    Thanks

    -Nitin 

  • In the mmwave SDK CAN/CAN-FD driver comes with the unit test application as well. You can refer these test application for your application development.

    C:\ti\mmwave_sdk_03_05_00_01\packages\ti\drivers\can\test

    And taking the same reference you can port the TI-Rex application to basic CAN interface.

    https://dev.ti.com/tirex/explore/node?node=AIbEoly4B7.jPYk1aCiO-A__AocYeEd__LATEST

    https://dev.ti.com/tirex/explore/node?node=ADWAvz1GWDvSfSVkncqhEw__AocYeEd__LATEST

    Regards,

    Jitendra

  • Hi, Thank you for your return.

    I am compiling the code you see below on AWR1843. I referenced C: \ ti \ mmwave_sdk_03_05_00_01 \ packages \ ti \ drivers \ can \ test. Everything seems right. I pull the S2 key on the board to the can. I connect the Can output cables to the oscilloscope. The routine test setup I always do for Can. No result, Can does not work. The same operations work for canfd. The trouble seems like software initialization.

    Can you review the code I shared below?

    If necessary, I can direct the project file from the custom to you?

    #include <Can_Configs/can.h>
    #include <ti/drivers/pinmux/pinmux.h>
    #include <ti/drivers/esm/esm.h>
    #include <ti/utils/testlogger/logger.h>

    static void DCANAppInitParams(CAN_DCANCfgParams* dcanCfgParams,
    CAN_DCANMsgObjCfgParams* dcanTxCfgParams,
    CAN_DCANMsgObjCfgParams* dcanRxCfgParams,
    CAN_DCANData* dcanTxData);

    void Can_Initialize(void);

    int32_t DCANAppCalcBitTimeParams(uint32_t clkFreq,
    uint32_t bitRate,
    uint32_t refSamplePnt,
    uint32_t propDelay,
    CAN_DCANBitTimeParams* bitTimeParams);

    MmwDemo_MCB gMmwMssMCB;

    int main (void)
    {
    Task_Params taskParams;
    int32_t errCode;
    SOC_Cfg socCfg;

    /* Initialize the ESM: */
    ESM_init(0U); //dont clear errors as TI RTOS does it

    /* Initialize and populate the demo MCB */
    memset ((void*)&gMmwMssMCB, 0, sizeof(MmwDemo_MCB));

    /* Initialize the SOC confiugration: */
    memset ((void *)&socCfg, 0, sizeof(SOC_Cfg));

    /* Populate the SOC configuration: */
    socCfg.clockCfg = SOC_SysClock_INIT;

    /* Initialize the SOC Module: This is done as soon as the application is started
    * to ensure that the MPU is correctly configured. */
    gMmwMssMCB.socHandle = SOC_init (&socCfg, &errCode);
    if (gMmwMssMCB.socHandle == NULL)
    {
    System_printf ("Error: SOC Module Initialization failed [Error code %d]\n", errCode);
    return -1;
    }

    Can_Initialize(); // <- LOOP + INITILATION ??????????
    }

    void Can_Initialize(void)
    {

    CAN_Handle canHandle;
    CAN_MsgObjHandle txMsgObjHandle;
    CAN_MsgObjHandle rxMsgObjHandle;
    int32_t retVal = 0;
    int32_t errCode = 0;

    /******/
    Pinmux_Set_OverrideCtrl(SOC_XWR18XX_PINE15_PADAG, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
    Pinmux_Set_FuncSel(SOC_XWR18XX_PINE15_PADAG, SOC_XWR18XX_PINE15_PADAG_CAN_TX);

    Pinmux_Set_OverrideCtrl(SOC_XWR18XX_PINE13_PADAF, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
    Pinmux_Set_FuncSel(SOC_XWR18XX_PINE13_PADAF, SOC_XWR18XX_PINE13_PADAF_CAN_RX);
    /******/

    /* Configure the divide value for DCAN source clock */
    SOC_setPeripheralClock(gMmwMssMCB.socHandle, SOC_MODULE_DCAN, SOC_CLKSOURCE_VCLK, 9U, &errCode);

    /* Initialize peripheral memory */
    SOC_initPeripheralRam(gMmwMssMCB.socHandle, SOC_MODULE_DCAN, &errCode);


    /* Initialize the DCAN parameters that need to be specified by the application */
    DCANAppInitParams(&appDcanCfgParams,
    &appDcanTxCfgParams,
    &appDcanRxCfgParams,
    &appDcanTxData);

    // Initialize the CAN driver
    canHandle = CAN_init(&appDcanCfgParams, &errCode);
    if (canHandle == NULL)
    {
    System_printf ("Error: CAN Module Initialization failed [Error code %d]\n", errCode);
    }

    retVal = DCANAppCalcBitTimeParams(DCAN_APP_INPUT_CLK / 1000000,
    DCAN_APP_BIT_RATE / 1000,
    DCAN_APP_SAMP_PT,
    DCAN_APP_PROP_DELAY,
    &appDcanBitTimeParams);
    if (retVal < 0)
    {
    System_printf ("Error: CAN Module bit time parameters are incorrect \n");
    }

    // Configure the CAN driver
    retVal = CAN_configBitTime (canHandle, &appDcanBitTimeParams, &errCode);
    if (retVal < 0)
    {
    System_printf ("Error: CAN Module configure bit time failed [Error code %d]\n", errCode);
    }

    // Setup the transmit message object
    txMsgObjHandle = CAN_createMsgObject (canHandle, DCAN_TX_MSG_OBJ, &appDcanTxCfgParams, &errCode);
    if (txMsgObjHandle == NULL)
    {
    System_printf ("Error: CAN create Tx message object failed [Error code %d]\n", errCode);
    }

    // Setup the receive message object
    rxMsgObjHandle = CAN_createMsgObject (canHandle, DCAN_RX_MSG_OBJ, &appDcanRxCfgParams, &errCode);
    if (rxMsgObjHandle == NULL)
    {
    System_printf ("Error: CAN create Rx message object failed [Error code %d]\n", errCode);
    }

    retVal = CAN_transmitData (txMsgObjHandle, &appDcanTxData, &errCode);
    if (retVal < 0)
    {
    System_printf ("Error: CAN transmit data for iteration %d failed [Error code %d]\n", iterationCount_can, errCode);
    }

    int cf;

    /**** LOOP ******/
    while(1)
    {

    for( cf = 0 ; cf < 10000 ; cf++);
    for( cf = 0 ; cf < 10000 ; cf++);
    for( cf = 0 ; cf < 10000 ; cf++);
    for( cf = 0 ; cf < 10000 ; cf++);
    for( cf = 0 ; cf < 10000 ; cf++);
    for( cf = 0 ; cf < 10000 ; cf++);
    for( cf = 0 ; cf < 10000 ; cf++);
    for( cf = 0 ; cf < 10000 ; cf++);
    for( cf = 0 ; cf < 10000 ; cf++);

    System_printf ("Can Send \n");

    CAN_transmitData (txMsgObjHandle, &appDcanTxData, &errCode);
    }


    }


    int32_t DCANAppCalcBitTimeParams(uint32_t clkFreq,
    uint32_t bitRate,
    uint32_t refSamplePnt,
    uint32_t propDelay,
    CAN_DCANBitTimeParams* bitTimeParams)
    {
    Double tBitRef = 1000 * 1000 / bitRate;
    Double newBaud = 0, newNProp = 0, newNSeg = 0, newSjw = 0, newP = 0;
    Double nQRef, nProp, fCan, nQ, nSeg, baud, sp, p, newSp = 0;
    float tQ;

    for (p = 1; p <= 1024; p++)
    {
    tQ = ((p / clkFreq) * 1000.0);
    nQRef = tBitRef / tQ;

    if ((nQRef >= 8) && (nQRef <= 25))
    {
    nProp = ceil(propDelay / tQ);
    fCan = clkFreq / p;
    nQ = fCan / bitRate * 1000;
    nSeg = ceil((nQ - nProp - 1) / 2);

    if ((nProp <= 8) && (nProp > 0) && (nSeg <= 8) && (nSeg > 0))
    {
    baud = fCan / (1 + nProp + 2 * nSeg) * 1000;

    sp = (1 + nProp + nSeg) / (1 + nProp + nSeg + nSeg) * 100;

    if ((abs(baud - bitRate)) < (abs(newBaud - bitRate)))
    {
    newBaud = baud;
    newNProp = nProp;
    newNSeg = nSeg;
    newSjw = (nSeg < 4) ? nSeg : 4;
    newP = p - 1;
    newSp = sp;
    }
    else if ((abs(baud - bitRate)) == (abs(newBaud - bitRate)))
    {
    if ((abs(sp - refSamplePnt)) < (abs(newSp - refSamplePnt)))
    {
    newBaud = baud;
    newNProp = nProp;
    newNSeg = nSeg;
    newSjw = (nSeg < 4) ? nSeg : 4;
    newP = p - 1;
    newSp = sp;
    }
    }
    }
    }
    }
    if ((newBaud == 0) || (newBaud > 1000))
    {
    return -1;
    }

    bitTimeParams->baudRatePrescaler = (((uint32_t) newP) & 0x3F);
    bitTimeParams->baudRatePrescalerExt =
    ((((uint32_t) newP) & 0x3C0) ? (((uint32_t) newP) & 0x3C0) >> 6 : 0);
    bitTimeParams->syncJumpWidth = ((uint32_t) newSjw) - 1;

    /* propSeg = newNProp, phaseSeg = newNSeg, samplePoint = newSp
    * nominalBitTime = (1 + newNProp + 2 * newNSeg), nominalBitRate = newBaud
    * brpFreq = clkFreq / (brp + 1), brpeFreq = clkFreq / (newP + 1)
    * brp = bitTimeParams->baudRatePrescaler;
    */

    bitTimeParams->timeSegment1 = newNProp + newNSeg - 1;
    bitTimeParams->timeSegment2 = newNSeg - 1;

    return 0;
    }


    static void DCANAppInitParams(CAN_DCANCfgParams* dcanCfgParams,
    CAN_DCANMsgObjCfgParams* dcanTxCfgParams,
    CAN_DCANMsgObjCfgParams* dcanRxCfgParams,
    CAN_DCANData* dcanTxData)
    {
    /*Intialize DCAN Config Params*/

    if (testSelection == DCAN_APP_TEST_PARITY)
    {
    dcanCfgParams->parityEnable = 1;
    dcanCfgParams->intrLine0Enable = 1;
    dcanCfgParams->intrLine1Enable = 0;
    dcanCfgParams->testModeEnable = 0;
    dcanCfgParams->eccModeEnable = 1;
    dcanCfgParams->eccDiagModeEnable = 0;
    dcanCfgParams->sbeEventEnable = 1;
    dcanCfgParams->stsChangeIntrEnable = 0;
    }
    else if (testSelection == DCAN_APP_TEST_EXTERNAL_DATA)
    {
    dcanCfgParams->parityEnable = 0;
    dcanCfgParams->intrLine0Enable = 1;
    dcanCfgParams->intrLine1Enable = 1;
    dcanCfgParams->testModeEnable = 0;
    dcanCfgParams->eccModeEnable = 0;
    dcanCfgParams->stsChangeIntrEnable = 0;
    }
    else
    {
    dcanCfgParams->parityEnable = 0;
    dcanCfgParams->intrLine0Enable = 1;
    dcanCfgParams->intrLine1Enable = 1;
    dcanCfgParams->eccModeEnable = 0;
    dcanCfgParams->testModeEnable = 1;
    if (testSelection == DCAN_APP_TEST_INTERNAL_LOOPBACK)
    {
    dcanCfgParams->testMode = CAN_DCANTestMode_LPBACK;
    dcanCfgParams->stsChangeIntrEnable = 0;
    }
    else
    {
    dcanCfgParams->testMode = CAN_DCANTestMode_EXT_LPBACK;
    dcanCfgParams->stsChangeIntrEnable = 1;
    }
    }

    dcanCfgParams->autoRetransmitDisable = 1;
    dcanCfgParams->autoBusOnEnable = 0;
    dcanCfgParams->errIntrEnable = 1;
    dcanCfgParams->autoBusOnTimerVal = 0;
    dcanCfgParams->if1DmaEnable = 0;
    dcanCfgParams->if2DmaEnable = 0;
    dcanCfgParams->if3DmaEnable = 0;
    dcanCfgParams->ramAccessEnable = 0;
    dcanCfgParams->appCallBack = DCANAppErrStatusCallback;

    /*Intialize DCAN tx Config Params*/
    dcanTxCfgParams->xIdFlagMask = 0x1;
    dcanTxCfgParams->dirMask = 0x1;
    dcanTxCfgParams->msgIdentifierMask = 0x1FFFFFFF;

    dcanTxCfgParams->msgValid = 1;
    dcanTxCfgParams->xIdFlag = CAN_DCANXidType_11_BIT;
    dcanTxCfgParams->direction = CAN_Direction_TX;
    dcanTxCfgParams->msgIdentifier = 0xC1;

    dcanTxCfgParams->uMaskUsed = 1;
    if (testSelection == DCAN_APP_TEST_PARITY)
    dcanTxCfgParams->intEnable = 0;
    else
    dcanTxCfgParams->intEnable = 1;

    dcanTxCfgParams->remoteEnable = 0;
    dcanTxCfgParams->fifoEOBFlag = 1;
    dcanTxCfgParams->appCallBack = DCANAppCallback;

    /*Intialize DCAN Rx Config Params*/
    dcanRxCfgParams->xIdFlagMask = 0x1;
    dcanRxCfgParams->msgIdentifierMask = 0x1FFFFFFF;
    dcanRxCfgParams->dirMask = 0x1;

    dcanRxCfgParams->msgValid = 1;
    dcanRxCfgParams->xIdFlag = CAN_DCANXidType_11_BIT;
    dcanRxCfgParams->direction = CAN_Direction_RX;
    dcanRxCfgParams->msgIdentifier = 0xC1;

    dcanRxCfgParams->uMaskUsed = 1;
    if (testSelection == DCAN_APP_TEST_PARITY)
    dcanRxCfgParams->intEnable = 0;
    else
    dcanRxCfgParams->intEnable = 1;

    dcanRxCfgParams->remoteEnable = 0;
    dcanRxCfgParams->fifoEOBFlag = 1;
    dcanRxCfgParams->appCallBack = DCANAppCallback;

    /*Intialize DCAN Tx transfer Params*/
    dcanTxData->dataLength = DCAN_MAX_MSG_LENGTH;
    dcanTxData->msgData[0] = 0xA5;
    dcanTxData->msgData[1] = 0x5A;
    dcanTxData->msgData[2] = 0xFF;
    dcanTxData->msgData[3] = 0xFF;
    dcanTxData->msgData[4] = 0xC3;
    dcanTxData->msgData[5] = 0x3C;
    dcanTxData->msgData[6] = 0xB4;
    dcanTxData->msgData[7] = 0x4B;
    }

  • Also, except for C: \ ti \ mmwave_sdk_03_05_00_01 \ packages \ ti \ drivers \ can \ test, this shared project and documents are used CANFD.

  • I'm pretty sure that mmWave SDK CAN driver test application should work without any hassle.

    Test application: DCAN_APP_TEST_EXTERNAL_DATA option for external CAN data get verification.

    Regards,

    Jitendra