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/IWR6843: CANFD_init fails after CANFD_deinit

Part Number: IWR6843
Other Parts Discussed in Thread: MMWAVE-SDK

Tool/software: Code Composer Studio

Hello,
when I call CANFD_init after previous CANFD_deinit is called, it fails on (canfd.c) at row ptrCanFdMCB->hwiHandle0 = HwiP_create(ptrCanFdMCB->hwCfg.interruptNum0, CANFD_MCANInt0Isr, &hwiParams);

When is CANFD_init called for first time, all works ok.

May I ask for any hint?

M.

  • Hi Miroslav

    Are you using the CAN_FD driver in a lab?  Can you show how you have implemented it?

    Also have you tried using the CAN_FD test in the mmWave-SDK?

    Regards,

    AG

  • Hi Miroslav,

    The MCAN soft-reset is not supported by the new MCAN IP used in the xWR6843 ES2.0. Let me know your use case so that we can work out an alternative.

    Thanks

    Yogesh

  • Hi Yogesh,
    I need to restart CAN FD interface because it is initialised during power on sequence, but If there is no any can cable connected it is not working after plug in. So after some time without any data on can bus, I switch CAN pins to GPIO Input type and monitor any incomming pulses. If any occours then I want to init again whole CAN FD system but previosly mentioned error occurs.

    bool myCANFullInit(uint32_t kbitsPerSec)
    {
        isCanReadyForSending = false;
        int32_t retVal = 0;
        int32_t errCode = 0;
    
        Task_sleep(50);
    
        static bool isCanCommandSemaphoreInicialized = false;
        if(!isCanCommandSemaphoreInicialized)
        {
            Semaphore_construct(&CANcommand_semStruct, 0, NULL);//0 - because 0 CAN commands are ready for evaluating
            CANcommand_semHandle = Semaphore_handle(&CANcommand_semStruct);
    
            if (CANcommand_semHandle)
            {
                isCanCommandSemaphoreInicialized = true;
            }
        }
    
    
        memset(&myCANds, 0, sizeof(CANHandlesAndRelatedData_t));
        memset(&CAN_SendDataBuffersStruct, 0, sizeof(CAN_SendDataBuffersStruct_t));
    
        /* Setup the PINMUX to bring out the XWR68xx CAN pins */
        Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINE14_PADAE, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
        Pinmux_Set_FuncSel(SOC_XWR68XX_PINE14_PADAE, SOC_XWR68XX_PINE14_PADAE_CANFD_TX);
    
        Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PIND13_PADAD, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
        Pinmux_Set_FuncSel(SOC_XWR68XX_PIND13_PADAD, SOC_XWR68XX_PIND13_PADAD_CANFD_RX);
    
        SOC_setPeripheralClock(gMmwMssMCB.socHandle, SOC_MODULE_MCANA, SOC_CLKSOURCE_VCLK, 4U, &errCode);
        System_printf("Debug: CANFD-> SOC_setPeripheralClock errCode: %i\n", errCode);
    
        MCANAppInitParams(&myCANds.canCfgParams,
                          &myCANds.canMsgObjCfgParams_dataTX,
                          &myCANds.canMsgObjCfgParams_cliTX,
                          &myCANds.canMsgObjCfgParams_cliRX,
                          &myCANds.canMsgObjCfgParams_cliRX_GLOBAL);
    
        /* Initialize the CAN driver */
        errCode = 0;
        myCANds.canHandle = CANFD_init(gIsntanceID, &myCANds.canCfgParams, &errCode); //pro SDK 3.3.0.03 a vyse
        //myCANds.canHandle = CANFD_init(&myCANds.canCfgParams, &errCode);
        if (!myCANds.canHandle)
        {
            return false;
        }
    
        /* 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
        */
    
        myCANds.canBitTimingParams.nomBrp      = 0x2U;
        myCANds.canBitTimingParams.nomPropSeg  = 0x8U;
        myCANds.canBitTimingParams.nomPseg1    = 0x6U;
        myCANds.canBitTimingParams.nomPseg2    = 0x5U;
        myCANds.canBitTimingParams.nomSjw      = 0x1U;
    
        myCANds.canBitTimingParams.dataBrp     = 0x1U;
        myCANds.canBitTimingParams.dataPropSeg = 0x2U;
        myCANds.canBitTimingParams.dataPseg1   = 0x2U;
        myCANds.canBitTimingParams.dataPseg2   = 0x3U;
        myCANds.canBitTimingParams.dataSjw     = 0x1U;
    
        /* Configure the CAN driver */
        retVal = CANFD_configBitTime(myCANds.canHandle, &myCANds.canBitTimingParams, &errCode);
        if (retVal < 0)
        {
            System_printf ("Error: CANFD Module configure bit time failed [Error code %d]\n", errCode);
            return false;
        }
    
        /* Setup the DATA transmit message object */
        errCode = 0;
        myCANds.canMsgObjHandle_dataTX = CANFD_createMsgObject(myCANds.canHandle, &myCANds.canMsgObjCfgParams_dataTX, &errCode);
        if (myCANds.canMsgObjHandle_dataTX == NULL)
        {
            return false;
        }
    
        /* Setup the CLI transmit message object */
        errCode = 0;
        myCANds.canMsgObjHandle_cliTX = CANFD_createMsgObject(myCANds.canHandle, &myCANds.canMsgObjCfgParams_cliTX, &errCode);
        if (myCANds.canMsgObjHandle_cliTX == NULL)
        {
            return false;
        }
    
        /* Setup the CLI receive message object */
        errCode = 0;
        myCANds.canMsgObjHandle_cliRX = CANFD_createMsgObject(myCANds.canHandle, &myCANds.canMsgObjCfgParams_cliRX, &errCode);
        if (myCANds.canMsgObjHandle_cliRX == NULL)
        {
            return false;
        }
    
        /* Setup the CLI GLOBAL receive message object */
        errCode = 0;
        myCANds.canMsgObjHandle_cliRX_GLOBAL = CANFD_createMsgObject(myCANds.canHandle, &myCANds.canMsgObjCfgParams_cliRX_GLOBAL, &errCode);
        if (myCANds.canMsgObjHandle_cliRX_GLOBAL == NULL)
        {
            return false;
        }
    
    #ifdef SOC_XWR68XX
        GPIO_write(SOC_XWR68XX_GPIO_0, 0);// disable CAN silent mode
    #else
        GPIO_write(SOC_XWR16XX_GPIO_0, 0);// disable CAN silent mode
    #endif
    
        isCanReadyForSending = true;
        canInStableSpeedCnt = 0;
        return true;
    }

    bool myCANFullDeInit()
    {
        isCanReadyForSending = false;
        int32_t retval = 0;
        int32_t errCode = 0;
    
    #ifdef SOC_XWR68XX
        GPIO_write(SOC_XWR68XX_GPIO_0, 1);// enable CAN silent mode
        /* Setup the PINMUX to bring GPIO for CAN pins */
        Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINE14_PADAE, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
        Pinmux_Set_FuncSel(SOC_XWR68XX_PINE14_PADAE,SOC_XWR68XX_PINE14_PADAE_GPIO_20);//CAN_TX
    
        Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PIND13_PADAD, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
        Pinmux_Set_FuncSel(SOC_XWR68XX_PIND13_PADAD,SOC_XWR68XX_PIND13_PADAD_GPIO_19);//CAN_RX
    
        GPIO_setConfig(SOC_XWR68XX_GPIO_3, GPIO_CFG_INPUT);
        GPIO_setConfig(SOC_XWR68XX_GPIO_30, GPIO_CFG_OUTPUT);
        GPIO_write(SOC_XWR68XX_GPIO_30, 1);
    #else
        GPIO_write(SOC_XWR16XX_GPIO_0, 1);// enable CAN silent mode
        /* Setup the PINMUX to bring GPIO for CAN pins */
        Pinmux_Set_OverrideCtrl(SOC_XWR16XX_PINC13_PADAG, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
        Pinmux_Set_FuncSel(SOC_XWR16XX_PINC13_PADAG,SOC_XWR16XX_PINC13_PADAG_GPIO_30);//CAN_TX
        Pinmux_Set_OverrideCtrl(SOC_XWR16XX_PINE13_PADAF, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
        Pinmux_Set_FuncSel(SOC_XWR16XX_PINE13_PADAF,SOC_XWR16XX_PINE13_PADAF_GPIO_3);//CAN_RX
        GPIO_setConfig(SOC_XWR16XX_GPIO_3, GPIO_CFG_INPUT);
        GPIO_setConfig(SOC_XWR16XX_GPIO_30, GPIO_CFG_OUTPUT);
        GPIO_write(SOC_XWR16XX_GPIO_30, 1);
    #endif
    
        Task_sleep(50);
    
        CANFD_deleteMsgObject(myCANds.canMsgObjHandle_dataTX, &errCode);
        CANFD_deleteMsgObject(myCANds.canMsgObjHandle_cliTX, &errCode);
        CANFD_deleteMsgObject(myCANds.canMsgObjHandle_cliRX, &errCode);
        CANFD_deleteMsgObject(myCANds.canMsgObjHandle_cliRX_GLOBAL, &errCode);
    
        retval = CANFD_deinit(myCANds.canHandle, &errCode);
    
        if (retval < 0)
        {
            System_printf ("Error: CANFD deinit failed [Error code %d]\n", errCode);
            print ("Error: CANFD deinit failed.\n");
            return retval;
        }
        else
        {
            System_printf ("Debug: CANFD deinit DONE.\n");
            print ("Debug: CANFD deinit DONE.\n");
        }
    
        return retval;
    }

  • Hi Miroslav,

    We are working on alternate way to reset the CANFD. It may take some time to verify. In the mean-time could you please initialize CANFD module on receiving the CAN signal and not during startup to avoid reset.

    Thanks

    Yogesh