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.

AWR1642: CANFD send data with changeable MsgId in Classic Mode

Part Number: AWR1642

Hello,

We need to use two CAN interfaces on our board, so we need to use both CAN and CANFD. And now I have some trouble in using CANFD send data with changeable MsgId in the Classic CAN Mode.The code modification:

int32_t MCAN_Init(SOC_Handle socHandle)
{
    int32_t errCode;
    int32_t retVal = 0;

    /* Configure the divide value for MCAN source clock */
    SOC_setPeripheralClock(socHandle, SOC_MODULE_MCAN, SOC_CLKSOURCE_VCLK, 4U, &errCode);

#define Pinmux_SetFunc(pin, func)                                       \
    do {                                                            \
            Pinmux_Set_OverrideCtrl(pin, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL); \
            Pinmux_Set_FuncSel(pin, func);                          \
    } while (0)

    /* Setup the PINMUX to bring out the XWR16xx CAN pins */
    Pinmux_SetFunc(SOC_XWR16XX_PIND14_PADBN, SOC_XWR16XX_PIND14_PADBN_CANFD_TX);
    Pinmux_SetFunc(SOC_XWR16XX_PINB14_PADBO, SOC_XWR16XX_PINB14_PADBO_CANFD_RX);

    CANFD_MCANInitParams        mcanCfgParams;
    CANFD_MCANBitTimingParams   mcanBitTimingParams;

    MCAN_InitParams(&mcanCfgParams);

    /* Initialize the CANFD driver */
    canFdHandle = CANFD_init(&mcanCfgParams, &errCode);
    if (canFdHandle == NULL)
    {
        System_printf ("Error: CANFD Module Initialization failed [Error code %d]\n", errCode);
        return -1;
    }

    MCAN_CalcBitTimeParams(&mcanBitTimingParams);
    /* Configure the CAN driver */

    retVal = CANFD_configBitTime (canFdHandle, &mcanBitTimingParams, &errCode);
    if (retVal < 0)
    {
        System_printf ("Error: CANFD Module configure bit time failed [Error code %d]\n", errCode);
        return -1;
    }

    /* Setup the transmit message object */
    appMcanTxTarCfgParams.direction = CANFD_Direction_TX;
    appMcanTxTarCfgParams.msgIdType = CANFD_MCANXidType_11_BIT;    //11bit为标准帧    2018.12.18
    appMcanTxTarCfgParams.msgIdentifier = DCAN_IDMin;

    txTarMsgObjHandle = CANFD_createMsgObject (canFdHandle, &appMcanTxTarCfgParams, &errCode);
    if (txTarMsgObjHandle == NULL)
    {
        System_printf ("Error: CANFD create Tx message object failed [Error code %d]\n", errCode);
        return -1;
    }
    return 0;
}

int32_t MCAN_SendData(uint32_t id, unsigned char *buf,uint32_t datalen)
{
//    int32_t    i;
    int32_t  index = 0;
    int32_t     retVal = 0;
    int32_t     errCode = 0;
    uint32_t MsgId = appMcanTxTarCfgParams.msgIdentifier;
    CANFD_OptionTLV                optionTLV;
    CANFD_MCANMsgObjectStats    msgObjStats;

    
    Task_sleep(1);
    if(datalen>=8)
    {
        retVal = CANFD_transmitData (txTarMsgObjHandle, MsgId, CANFD_MCANFrameType_CLASSIC, 8U, &buf[index], &errCode);
        if(retVal)
        {
            System_printf ("Error: Transmit data failed [Error code %d]\n", errCode);
            return -1;
        }
        datalen = datalen - 8;
        index = index + 8;
        MsgId = MsgId + 1;
        Task_sleep(1);
    }

    optionTLV.type = CANFD_Option_MCAN_PROTOCOL_STATUS;
    optionTLV.length = sizeof(CANFD_MCANMsgObjectStats);
    optionTLV.value = (void*) &msgObjStats;
    retVal = CANFD_getOptions(canFdHandle, &optionTLV, &errCode);
    if (retVal < 0)
    {
        System_printf ("Error: CANFD get stats failed [Error code %d]\n", errCode);
        return -1;
    }
    
    return 0;
}

I debug with CCS and it printf "Error: CANFD get stats failed [Error code -3501]". I tried to change the mcanCfgParams and data bit rate and it didn't work. Could you give me some help to solve this problem?Is there some configurations different between Classic Mode and FD Mode in the CANFD interface?

Thank you a lot,

Cassie

  • Hello Cassie,

    What is the version of the SDK you are using?

    -Raghu
  • Hello Raghu,
    I used sdk_01_012_00_02.
  • Hello Raghu,

    Sorry for a late reply. I used sdk_01_01_00_02.

    Cssie

  • Cassie,

    If you are using the AWR1642 ES2.0 please plan to migrate to the SDK version 2.1.0.4 which is the SDK LTS version for ES2.0 devices.

    Below code is an example for the mechanism you are trying in your code to send data on multiple message objects:
    static int32_t mcanMultiTransmission()
    {
    CANFD_Handle canHandle;
    CANFD_MsgObjHandle txMsgObjHandle[5U];
    int32_t retVal = 0;
    int32_t errCode = 0;
    CANFD_MCANInitParams mcanCfgParams;
    CANFD_MCANBitTimingParams mcanBitTimingParams;
    CANFD_MCANMsgObjCfgParams txMsgObjectParams[5U];
    int32_t index;

    gTxDoneFlag = 0;
    gRxDoneFlag = 0;

    MCANAppInitParams (&mcanCfgParams);

    /* Initialize the CANFD driver */
    canHandle = CANFD_init(&mcanCfgParams, &errCode);
    if (canHandle == NULL)
    {
    System_printf ("Error: CANFD Module Initialization failed [Error code %d]\n", errCode);
    return -1;
    }

    /* Configuring 1Mbps and 5Mbps as nominal and data bit-rate respectively
    Prop seg: 8
    Ph seg 1: 6
    Ph Seg2 : 5
    Sync jump: 1
    BRP(Baud rate Prescaler): 2

    Nominal Bit rate = (40)/(((8+6+5)+1)*BRP) = 1Mhz

    Timing Params for Data Bit rate:
    Prop seg: 2
    Ph seg 1: 2
    Ph Seg2 : 3
    Sync jump: 1
    BRP(Baud rate Prescaler): 1

    Nominal Bit rate = (40)/(((2+2+3)+1)*BRP) = 5Mhz
    */

    mcanBitTimingParams.nomBrp = 0x2U;
    mcanBitTimingParams.nomPropSeg = 0x8U;
    mcanBitTimingParams.nomPseg1 = 0x6U;
    mcanBitTimingParams.nomPseg2 = 0x5U;
    mcanBitTimingParams.nomSjw = 0x1U;

    mcanBitTimingParams.dataBrp = 0x2U;
    mcanBitTimingParams.dataPropSeg = 0x8U;
    mcanBitTimingParams.dataPseg1 = 0x6U;
    mcanBitTimingParams.dataPseg2 = 0x5U;
    mcanBitTimingParams.dataSjw = 0x1U;

    /* Configure the CAN driver */
    retVal = CANFD_configBitTime (canHandle, &mcanBitTimingParams, &errCode);
    if (retVal < 0)
    {
    System_printf ("Error: CANFD Module configure bit time failed [Error code %d]\n", errCode);
    return -1;
    }

    while (1)
    {
    /* Setup the transmit message object */
    for(index = 0; index < 5U ; index++)
    {
    txMsgObjectParams[index].direction = CANFD_Direction_TX;
    txMsgObjectParams[index].msgIdType = CANFD_MCANXidType_29_BIT;
    txMsgObjectParams[index].msgIdentifier = 0xC1 + index;

    txMsgObjHandle[index] = CANFD_createMsgObject (canHandle, &txMsgObjectParams[index], &errCode);
    if (txMsgObjHandle[index] == NULL)
    {
    System_printf ("Error: CANFD create Tx message object failed [Error code %d]\n", errCode);
    return -1;
    }
    }
    gTxPkts = 0;
    for(index = 0; index < 5U ; index++)
    {
    retVal = CANFD_transmitData (txMsgObjHandle[index], txMsgObjectParams[index].msgIdentifier, CANFD_MCANFrameType_CLASSIC, 8U, &txData[0], &errCode);
    if (retVal < 0)
    {
    System_printf ("Error: CANFD transmit data retry failed [Error code %d]\n", errCode);
    }
    Task_sleep(1);
    }

    /* Delete the transmit message object */
    for(index = 0; index < 5U ; index++)
    {
    retVal = CANFD_deleteMsgObject(txMsgObjHandle[index], &errCode);
    if (retVal < 0)
    {
    System_printf ("Error: CANFD delete Tx message object failed [Error code %d]\n", errCode);
    return -1;
    }
    }
    }
    }


    Please refer to this code and make modifications as required for your application.

    -Raghu
  • Hi,Raghu
    We have resolved this problem,Thank you!
    Cassie