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.

DRA829V: CAN Write interface is failing

Part Number: DRA829V
Other Parts Discussed in Thread: DRA829

Hi, 

We are working on DRA829 using psdk_rtos_auto_j7_06_02_00_21 and we are testing CAN_Profile app present in "psdk_rtos_auto_j7_06_02_00_21/mcusw/mcuss_demos/profiling/can/can_profile.c"

I modified can_profile app as attached -- > 

/*
*
* Copyright (c) 2019-2020 Texas Instruments Incorporated
*
* All rights reserved not granted herein.
*
* Limited License.
*
* Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive
* license under copyrights and patents it now or hereafter owns or controls to make,
* have made, use, import, offer to sell and sell ("Utilize") this software subject to the
* terms herein.  With respect to the foregoing patent license, such license is granted
* solely to the extent that any such patent is necessary to Utilize the software alone.
* The patent license shall not apply to any combinations which include this software,
* other than combinations with devices manufactured by or for TI ("TI Devices").
* No hardware patent is licensed hereunder.
*
* Redistributions must preserve existing copyright notices and reproduce this license
* (including the above copyright notice and the disclaimer and (if applicable) source
* code license limitations below) in the documentation and/or other materials provided
* with the distribution
*
* Redistribution and use in binary form, without modification, are permitted provided
* that the following conditions are met:
*
* *       No reverse engineering, decompilation, or disassembly of this software is
* permitted with respect to any software provided in binary form.
*
* *       any redistribution and use are licensed by TI for use only with TI Devices.
*
* *       Nothing shall obligate TI to provide you with source code for the software
* licensed and provided to you in object code.
*
* If software source code is provided to you, modification and redistribution of the
* source code are permitted provided that the following conditions are met:
*
* *       any redistribution and use of the source code, including any resulting derivative
* works, are licensed by TI for use only with TI Devices.
*
* *       any redistribution and use of any object code compiled from the source code
* and any resulting derivative works, are licensed by TI for use only with TI Devices.
*
* Neither the name of Texas Instruments Incorporated nor the names of its suppliers
*
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* DISCLAIMER.
*
* THIS SOFTWARE IS PROVIDED BY TI AND TI'S LICENSORS "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL TI AND TI'S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

/**
 *  \file     can_profile.c
 *
 *  \brief    This file implements CAN profiling application
 */

/* ========================================================================== */
/*                             Include Files                                  */
/* ========================================================================== */
#include "Std_Types.h"
#include "Det.h"
#include "Dem.h"
#include "Os.h"
#include "Can.h"
#include "CanIf_Cbk.h"
#include "EcuM_Cbk.h"
#include "Dio.h"

#include <ti/csl/arch/csl_arch.h>
#include <ti/csl/soc.h>
#include <ti/csl/cslr.h>

#include "can_profile.h"

/* ========================================================================== */
/*                           Macros & Typedefs                                */
/* ========================================================================== */
#define CAN_APP_E_DEM   (E_NOT_OK + 1U)
/**< Error code to indicate DEM */
#define CAN_APP_E_DET   (E_NOT_OK + 2U)
/**< Error code to indicate DEM */

/** \brief Message that would be displayed */
#if (CAN_LOOPBACK_ENABLE == STD_ON)
#define CAN_TX_RX_MSG "Transmit & Receive "
#else
#if (CAN_TX_ONLY_MODE == STD_ON)
#define CAN_TX_RX_MSG "Transmit "
#else
#define CAN_TX_RX_MSG "Receive "
#endif
#endif
/* ========================================================================== */
/*              Internal Function Declarations                                */
/* ========================================================================== */
uint64_t CanProfileGetTimeSpent(uint64_t preTs, uint64_t postTs);

/* ========================================================================== */
/*                            Global Variables                                */
/* ========================================================================== */
uint32                      CanApp_ProfileStatus = E_OK;
/**< Variable used for Demo status */
Can_PduType                 CanApp_Pdu, CanApp_Pdu1;
Can_PduType                 CanApp_Pdu2, CanApp_Pdu3, CanApp_Pdu4, CanApp_Pdu5;
/**< Variables which contains Can PDU data used in Can transmission */
uint8                       CanApp_InputData[64U] =
{0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x22, 0x44,
0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x22, 0x44,
0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x22, 0x44,
0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x22, 0x44,
0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x22, 0x44,
0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x22, 0x44,
0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x22, 0x44,
0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x22, 0x44,
};
/**< Variable which contains Can SDU data that is transported inside the PDU */
PduInfoType                 *CanApp_RxPdu = NULL;
/**< Pointer received data */
uint32                      CanApp_DemStatus = E_OK;
/**< Variable used to track dem notifications */
uint32                      CanApp_DetStatus = E_OK;
/**< Variable used to track det notifications */
static Dem_EventIdType     CanApp_EventId;
/**< Variable used to track dem event, reported event id */
static Dem_EventStatusType CanApp_EventStatus;
/**< Variable used to track dem event, reported event status */
static uint16 CanApp_ModuleId;
/**< Variable used to track det event, reported module id */
static uint8 CanApp_InstanceId;
/**< Variable used to track det event, reported instance id */
static uint8 CanApp_ApiId;
/**< Variable used to track det event, reported api id */
static uint8 CanApp_ErrorId;
/**< Variable used to track det event, reported error id */
#if (CAN_TX_ONLY_MODE == STD_ON)
const Can_PduType   *CanApp_PduInfo;
/**< Pointer to Can PDU used in Can transmission  */
uint8               CanApp_Hth = 0U;
/**< Hardware Mailbox Number configured to trigger transmission */
uint32              CanApp_Mask = 0x00000000U;
/**< Mask is used for checking received message id with transmitted message */
#endif
/* ========================================================================== */
/*                            External Variables                              */
/* ========================================================================== */
/* Global variables used in callback functions */
extern P2VAR(Can_HwType, CANIF_VAR_CLEARED, CANIF_APPL_DATA)
        CanIf_Mailbox;
extern PduInfoType CanIf_PduInfo;
extern SemaphoreP_Handle CanIf_TxConfirmationSemaphore;
/**< TX Confirmation semaphore */
extern SemaphoreP_Handle CanIf_RxConfirmationSemaphore;
/**< Rx Confirmation semaphore */
//uint64_t CanProfileCumulativeTx;
/**< Global used to track cumulative time spent for transmission */
/* ========================================================================== */
/*                          Function Definitions                              */
/* ========================================================================== */
sint32 CanApp_ProfileTest(canAppTaskObj_t *testParams)
{
    uint32              ctlr_cnt;
    Can_ReturnType      status;
    uint32              loopCnt, itr;/* totalCanMsgPerSec;
    float totalCpuload;
    float               totalTimePerMsg;
    Utils_PrfLoad       computedLoad;
    uint64_t            preTimeStamp, postTimeStamp;
    volatile uint32 cookie;*/

#if (APP_INSTANCE_1_INST_IN_CFG_ONLY == STD_OFF)
    const Can_ConfigType *Can_ConfigPtr;
#if (STD_ON == CAN_VARIANT_PRE_COMPILE)
    Can_ConfigPtr = &CAN_INIT_CONFIG_PC;
#else
    Can_ConfigPtr = &CanConfigSet;
#endif
#endif

    CanApp_RxPdu = &CanIf_PduInfo;
    /* Message for CAN-FD(MCU MCAN0 module) */
#if (CAN_TX_ONLY_MODE == STD_ON)
    CanApp_PduInfo         = &CanApp_Pdu;
    /* Setting Up CAN FD Extended Frame*/
    CanApp_Pdu.id          = 0xC0 | 0xC0000000U;
    CanApp_Pdu.length      = 64U;
    CanApp_Pdu.swPduHandle = 1U;
    CanApp_Pdu.sdu         = &CanApp_InputData[0U];

    /* Message for CAN-FD(MCU MCAN1 module) */
    /* Setting Up CAN FD Extended Frame*/
    CanApp_Pdu1.id          = 0xB0 | 0xC0000000U;
    CanApp_Pdu1.length      = 64U;
    CanApp_Pdu1.swPduHandle = 2U;
    CanApp_Pdu1.sdu         = &CanApp_InputData[0U];

    /* Message for CAN-FD(MAIN MCAN0 module) */
    /* Setting Up CAN FD Frame*/
    CanApp_Pdu2.id          = 0xC0 | 0xC0000000U;
    CanApp_Pdu2.length      = 64U;
    CanApp_Pdu2.swPduHandle = 3U;
    CanApp_Pdu2.sdu         = &CanApp_InputData[0U];

    /* Message for CAN-FD(MAIN MCAN4 module) */
    /* Setting Up CAN FD Frame*/
    CanApp_Pdu3.id          = 0xD0 | 0xC0000000U;
    CanApp_Pdu3.length      = 64U;
    CanApp_Pdu3.swPduHandle = 4U;
    CanApp_Pdu3.sdu         = &CanApp_InputData[0U];

    /* Message for CAN-FD(MAIN MCAN9 module) */
    /* Setting Up CAN FD Frame*/
    CanApp_Pdu4.id          = 0xE0 | 0xC0000000U;
    CanApp_Pdu4.length      = 64U;
    CanApp_Pdu4.swPduHandle = 5U;
    CanApp_Pdu4.sdu         = &CanApp_InputData[0U];

    /* Message for CAN-FD(MAIN MCAN11 module) */
    /* Setting Up CAN FD Frame*/
    CanApp_Pdu5.id          = 0xF0 | 0xC0000000U;
    CanApp_Pdu5.length      = 64U;
    CanApp_Pdu5.swPduHandle = 6U;
    CanApp_Pdu5.sdu         = &CanApp_InputData[0U];

    CanApp_DemStatus = E_OK;
    CanApp_DetStatus = E_OK;
#endif
    
#if (APP_INSTANCE_1_INST_IN_CFG_ONLY == STD_OFF)
    uint32      canMaxControllerCnt;
    canMaxControllerCnt = Can_ConfigPtr->CanMaxControllerCount;
    for (ctlr_cnt = 0U; ctlr_cnt < canMaxControllerCnt; ctlr_cnt++)
#else
    ctlr_cnt = 0U;
#endif
    {
        CanApp_ProfileStatus = E_OK;

#if (CAN_TX_ONLY_MODE == STD_ON)
        /* Set Can frame */
		CanApp_SetupCanFrame(ctlr_cnt, &CanApp_Hth, &CanApp_Mask);
#endif

        /* Set Controller Mode to Start */
        status = Can_SetControllerMode(
        CanConfigSet_CanController_List_PC[ctlr_cnt]->ControllerId, CAN_T_START);
        if (status != CAN_OK)
        {
            CanApp_ProfileStatus = E_NOT_OK;
            AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                                       " Controller not started properly\n");
        }
        else
        {
           AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                                                  " Controller started properlyy:%d\n",ctlr_cnt);
        }

#if (CAN_LOOPBACK_ENABLE == STD_ON)
        /* Enable loopback mode in CAN */
        Can_TestLoopBackModeEnable(
        CanConfigSet_CanController_List_PC[ctlr_cnt]->ControllerId, 0U);
#endif

//#if (CAN_INITIAL_PRINT_DISABLE_BEFORE_CAN_RESPONSE == STD_OFF)
        AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                        "Will " CAN_TX_RX_MSG "%d Messages, %d times: %d\n",
                        testParams->numTxPackets, testParams->numIterations,ctlr_cnt);
//#endif

        //CanProfileCumulativeTx = 0U;

        /* Start Time stamp */
       /* preTimeStamp = TimerP_getTimeInUsecs();

        cookie = Utils_prfLoadCalcReset();
        cookie = Utils_prfLoadCalcStart();*/
        for (itr = 0U; itr < testParams->numIterations; itr++)
        {
            for (loopCnt = 0U; loopCnt < testParams->numTxPackets; loopCnt++)
            {
#if (CAN_LOOPBACK_ENABLE == STD_OFF)

/* Do either Tx only or Rx only */
/* Tx Only */
#if (CAN_TX_ONLY_MODE == STD_ON)
                /* Do Can Write to send the CanApp_InputData on CAN bus */
                status = Can_Write(CanApp_Hth, CanApp_PduInfo);
                if (status == CAN_OK)
                {
                   AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                                                               "CAN Write is success : Hth=%d, ID = %d,%d\n",CanApp_Hth,CanApp_PduInfo->id,CanApp_PduInfo->length);
                    /*SemaphoreP_pend(CanIf_TxConfirmationSemaphore,
                                    SemaphoreP_WAIT_FOREVER);*/
                 }
                else
                {
                   AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                                           "CAN Write is Failing : Hth=%d, ID = %d,%d\n",CanApp_Hth,CanApp_PduInfo->id,CanApp_PduInfo->length);
                    CanApp_ProfileStatus = E_NOT_OK;
                }
                if (CAN_APP_E_DEM == CanApp_DemStatus)
                {
                   AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                      "Dem error was reported, eventId = %d, eventStatus = %d,ctlr_cnt=%d,loopCnt= %d\n",
                      CanApp_EventId, CanApp_EventStatus,ctlr_cnt,loopCnt);
                   CanApp_DemStatus = E_OK;
                }
                if (CAN_APP_E_DET == CanApp_DetStatus)
                {
                   AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                      "Det error was reported\n");
                   AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                      "With Module ID as %d\n", CanApp_ModuleId);
                   AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                      "With Module ID as %d\n", CanApp_InstanceId);
                   AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                      "With Module ID as %d\n", CanApp_ApiId);
                   AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                      "With Module ID as %d\n", CanApp_ErrorId);
                   CanApp_DetStatus = E_OK;
                }
/* Rx Only */
#else
                /* Pend on the semaphore posted in Rx indication */
                SemaphoreP_pend(CanIf_RxConfirmationSemaphore,
                                SemaphoreP_WAIT_FOREVER);
#endif

/* Internal loopback */
#else
                /* Do Can Write to send the CanApp_InputData on CAN bus */
                status = Can_Write(CanApp_Hth, CanApp_PduInfo);
                if (status == CAN_OK)
                {
                    SemaphoreP_pend(CanIf_TxConfirmationSemaphore,
                                    SemaphoreP_WAIT_FOREVER);
                }
                else
                {
                    CanApp_ProfileStatus = E_NOT_OK;
                }

                /* Pend on the semaphore posted in Rx indication */
                SemaphoreP_pend(CanIf_RxConfirmationSemaphore,
                                SemaphoreP_WAIT_FOREVER);
#endif
            }
        }
#if 0
        cookie = Utils_prfLoadCalcStop ();

        /* End Time stamp */
        postTimeStamp = TimerP_getTimeInUsecs();

        /* Time for transmission of numIterations*numTxPackets messages */
        CanProfileCumulativeTx =
                        CanProfileGetTimeSpent(preTimeStamp, postTimeStamp);
#endif
        if (E_OK == CanApp_ProfileStatus)
        {
           // Utils_prfLoadGetTaskLoad(TaskP_self(), &computedLoad);
#if (CAN_LOOPBACK_ENABLE == STD_ON)
            AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                        "NOTE : Operating in internal loop-back mode\n");
#endif

            AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                        CAN_TX_RX_MSG " %u packets %d times\n",
                        testParams->numTxPackets, testParams->numIterations);

            /* Number of packets transmitted * number of iterations *
                1 or 2 (2 in case of tx & rx) transmitted in msecs (computed
                above)
            */
#if 0
            AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                    "Average of %lld.%02d usecs per packet \n",
                    CanProfileCumulativeTx / (testParams->numTxPackets *
                                  testParams->numIterations),
                    CanProfileCumulativeTx % (testParams->numTxPackets *
                                  testParams->numIterations));
            totalTimePerMsg = ((float)CanProfileCumulativeTx / ((float)testParams->numTxPackets *
                                  (float)testParams->numIterations));
            totalCanMsgPerSec = (1000000.0f / totalTimePerMsg);

            /* Hardware interrupt handler load + Software interrupt handler +
                task load */
            totalCpuload = computedLoad.hwiLoad + computedLoad.swiLoad + 
                            computedLoad.tskLoad;

            AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                    "Average of %u packets in 1 second with CPU Load %f%% \r\n",
                    totalCanMsgPerSec, totalCpuload);

            AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                            "Measured Load: Total CPU: "
                            "%f%%, HWI: %f%%, SWI:%f%% TSK: %f%%\r\n",
                            computedLoad.cpuLoad,
                            computedLoad.hwiLoad,
                            computedLoad.swiLoad,
                            computedLoad.tskLoad);
#endif
            /* Set Controller Mode to Stop*/
            status = Can_SetControllerMode(
                CanConfigSet_CanController_List_PC[ctlr_cnt]->ControllerId,
                CAN_T_STOP);
            if (status != CAN_OK)
            {
               AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                                          "Controller not stopped correctlyn");
                CanApp_ProfileStatus = E_NOT_OK;
            }
            else
            {
               AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                                                         "Controller stopped correctlyn");
            }

#if (CAN_LOOPBACK_ENABLE == STD_ON)
            Can_TestLoopBackModeDisable(
            CanConfigSet_CanController_List_PC[ctlr_cnt]->ControllerId, 0U);
#endif

#if (CAN_LOOPBACK_ENABLE == STD_ON)
            if ((CanApp_PduInfo->length == CanApp_RxPdu->SduLength) &&
                (CanApp_PduInfo->id == (CanIf_Mailbox->CanId | CanApp_Mask)))
            {
                AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                "Message Id Received %x Message Length is %u\t \n",
                CanIf_Mailbox->CanId, CanApp_RxPdu->SduLength);
                for (loopCnt = 0U; 
                     ((loopCnt < CanApp_RxPdu->SduLength)&&(loopCnt < 10U));
                    loopCnt++)
                {
                    if (CanApp_RxPdu->SduDataPtr[loopCnt] !=
                        CanApp_InputData[loopCnt])
                    {
                        CanApp_ProfileStatus = E_NOT_OK;
                        AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                                "Transmitted and Received Data miss-match.\n");
                        break;
                    }
                    else
                    {
                        CanApp_ProfileStatus = E_OK;
                    }
                }
                AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                            "Test completed for %u instance \n\n", ctlr_cnt);
            }
            else
            {
                CanApp_ProfileStatus = E_NOT_OK;
            }
#endif
        }
    }
    AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                    " %d bytes used for stack \n", AppUtils_GetStackUsage());
    if (E_OK == CanApp_ProfileStatus)
    {
        AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME "Profiling completes sucessfully!!!\n");
        AppUtils_LogResult(APP_UTILS_STATUS_PASS);
    }
    else
    {
        if (CAN_APP_E_DEM == CanApp_DemStatus)
        {
            AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                    "Dem error was reported, eventId = %d, eventStatus = %d\n",
                    CanApp_EventId, CanApp_EventStatus);
            CanApp_DemStatus = E_OK;
        }
        if (CAN_APP_E_DET == CanApp_DetStatus)
        {
            AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                                                    "Det error was reported\n");
            AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                                    "With Module ID as %d\n", CanApp_ModuleId);
            AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                                "With Module ID as %d\n", CanApp_InstanceId);
            AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                                "With Module ID as %d\n", CanApp_ApiId);
            AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                                "With Module ID as %d\n", CanApp_ErrorId);
            CanApp_DetStatus = E_OK;
        }
    }

    return (CanApp_ProfileStatus);
}


void Dem_ReportErrorStatus(Dem_EventIdType     eventId,
                           Dem_EventStatusType eventStatus)
{
    if (DEM_EVENT_STATUS_FAILED == eventStatus)
    {
        CanApp_DemStatus = CAN_APP_E_DEM;
        CanApp_EventId = eventId;
        CanApp_EventStatus = eventStatus;
    }

    return;
}

uint64_t CanProfileGetTimeSpent(uint64_t preTs, uint64_t postTs)
{
    uint64_t rtnTs;

    if (postTs >= preTs)
    {
        rtnTs = postTs - preTs;
    }
    else
    {
        rtnTs = postTs + (0xFFFFFFFFFFFFFFFF - preTs);
    }

    return (rtnTs);
}

Std_ReturnType Det_ReportError(uint16 ModuleId, uint8 InstanceId, uint8 ApiId,
                               uint8 ErrorId)
{
    CanApp_DetStatus    = CAN_APP_E_DET;
    CanApp_ModuleId     = ModuleId;
    CanApp_InstanceId   = InstanceId;
    CanApp_ApiId        = ApiId;
    CanApp_ErrorId      = ErrorId;

    return E_OK;
}

#define CAN_START_SEC_ISR_CODE
#include "Can_MemMap.h"

CAN_ISR_TEXT_SECTION FUNC(void, CAN_CODE_FAST) CanApp_CanXIsr (
                                                            uintptr_t CanPtr)
{
    /*volatile uint64_t   preTimeStamp, postTimeStamp;

    preTimeStamp = TimerP_getTimeInUsecs();*/
    CanApp_IsrType canChIsr = (CanApp_IsrType)CanPtr;
    /* Associated CAN ISR */
    canChIsr();
    /*postTimeStamp = TimerP_getTimeInUsecs();
    CanProfileCumulativeTx +=
                CanProfileGetTimeSpent(preTimeStamp, postTimeStamp);*/
}

#define CAN_STOP_SEC_ISR_CODE
#include "Can_MemMap.h"

 -- > Configured for TX only Mode.

can_write interface returned success(E_OK) for very first time only, after that keeps on returning NOT_OK. Also after first can_write DEM error is reporting.

Dem error was reported, eventId = 65517, eventStatus = 1, Attached logs as well -- > 

-------------------EP2000---------------------------
--------------Version : 203300----------------------
-------------R5F_MCU_1_0_CORE-----------------------
-------DRV : CAN_TRCV-WdG-IPC-ADC-SPI---------------
-------APP : SOH-TEMP MON-VOLT MON-POWER_MAGR-------
-------MOD : IMU_SMI130-POWER_MANGER----------------
----------------------------------------------------
APTIV VIP-R5F: EP2000 - Tasks initialized !!!
CAN TRCV Pin Init:-
Read value 118 - 6 -36
Read value 118 - 7 -73
Read value 118 - 2 -255
Read value at 118 - 3 - 255
Read value 119 - 6 -36
Read value 119 - 7 -201
Read value 119 - 2 -255
Read value at 119 - 3 -255
Read value 116 - 6 -36
Read value 116 - 7 -73
Read value 116 - 2 -255
Read value at 116 - 3 - 255
Read value U11 - 7 -247
Read value at U11 - 3 - 247
CAN Profile App:Variant - Pre Compile being used !!!
CAN Profile App: GCP-CAN is Initializing !!!
WatchDog_Task_Intialize- STARTS !!!

WDG MCAL Version Info
---------------------
Vendor ID           : 44
Module ID           : 102
SW Major Version    : 0
SW Minor Version    : 1
SW Patch Version    : 0

Starting WDG test  !!!
Variant - Pre Compile being used !!!
WDG timeout is configured for 20000 millisecs
WDG ESM Interrupt will be generated after 20000 * 5 i.e 100000 millisecs
APTIV VIP-R5F:SPI Init !!!
Temperature_Mon_Initialize
APT Profile App: Controller started proCAN Profile App: Controller started properlyy:0
Temp sensor boardcfg Failed -6
IPC_Test_:File Before Resource Table LoadedCAN Profile App:Will Transmit 5 Messages, 5 times: 0
vtm_sensor_init
IPC_Test_:File After Resource Table LoadedCAN Profile App:NOTE : CAN Write is successs : ctlr_cnt=0, loopCnt = 0
IPC_Test_:File IPC VirtIO Init DoneCAN Profile App:Dem error was reported, eventId = 65517, eventStatus = 1,ctlr_cnt=0,loopCnt= 0
IPC_Test_:File RPMsg Init DoneCAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 1
IPC_Test_:File Remote_Proc returned  mcu1_0!!!
IPN Profile App:NOTE : CAN Write is failing : cCAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 2
IPC_Test_:File rpmsg_vdevMonitorFxn  mcu1_0!!!
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 3
IPC_Test_:FileInside Vdev Monitor Function
IPN Profile App:NOTE : CAN Write is failingCAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 4
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 0
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 1
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 2
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 3
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 4
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 0
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 1
CAN R5F MCU_1_0 Alive
Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 2
CAN Profile App:Det error was reported
CAN Profile App:With Module ID as 102
CAN Profile App:With Module ID as 0
CAN Profile App:With Module ID as 5
CAN Profile App:With Module ID as 16
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 3
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 4
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 0
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 1
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 2
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 3
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 4
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 0
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 1
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 2
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 3
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=0,loopCnt = 4
CAN Profile App: Controller started properlyy:1
CAN Profile App:Will Transmit 5 Messages, 5 times: 1
CAN Profile App:NOTE : CAN Write is successs : ctlr_cnt=1, loopCnt = 0
CAN Profile App:Dem error was reported, eventId = 65517, eventStatus = 1,ctlr_cnt=1,loopCnt= 0
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 1
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 2
CAN Profile App:NOTE :R5F MCU_1_0 Alive
 CAN Write is failing : ctlr_cnt=1,loopCnt = 3
CAN Profile App:Det error was reported
CAN Profile App:With Module ID as 102
CAN Profile App:With Module ID as 0
CAN Profile App:With Module ID as 5
CAN Profile App:With Module ID as 16
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 4
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 0
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 1
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 2
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 3
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 4
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 0
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 1
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 2
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 3
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 4
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 0
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 1
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 2
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 3
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 4
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 0
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 1
CAN Profile App:NOTE : CAN WriteR5F MCU_1_0 Alive
 is failing : ctlr_cnt=1,loopCnt = 2
CAN Profile App:Det error was reported
CAN Profile App:With Module ID as 102
CAN Profile App:With Module ID as 0
CAN Profile App:With Module ID as 5
CAN Profile App:With Module ID as 16
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 3
CAN Profile App:NOTE : CAN Write is failing : ctlr_cnt=1,loopCnt = 4
CAN Profile App: 8192 bytes used for stack
R5F MCU_1_0 Alive
R5F MCU_1_0 Alive
R5F MCU_1_0 Alive
Average Temperature 35044
R5F MCU_1_0 Alive
R5F MCU_1_0 Alive
R5F MCU_1_0 Alive
�ͭT��0(�)+����?�T��0(�)+����?�T��0(�)+����?�T��0(�)+���!+�� +-��!��    ?v2���?�T��0(�)+����?�T��0(�)+����?�T��0(�)+����?�T��0(�)+����?�T��0(�)+����?�T��0(�)+���)����3�?�������������/�%��� ��������)����3�?�����2����6�%�������2�8�:�2��������!���5������������������4�%�9���.�����!+�� +-��!��  ?

  • Can_Write() returning E_OK (0) for first call.

    Can_Write() returing E_BUSY(2) for successive calls.-- > Failing

    We added delay between two successive calls as well, still it is failing.

  • Hi Venu,

    One thing I see a problem with is that you are not pending on the tx confirmation semaphore. You don't have anything like SemaphoreP_pend(CanIf_TxConfirmationSemaphore, SemaphoreP_WAIT_FOREVER);

    You need that, as Can_Write() will return when it adds request for the message to go out on the bus. But the actual transfer on the wire completes when you get the CanIf_TxConfirmationSemaphore posted from the ISR. See mcusw/mcuss_demos/Bsw_Stubs/CanIf/src/CanIf_Cbk.c function CanIf_TxConfirmation().

    Please add the semaphore pend and check again. 

    Can you also fill in responses to the below question:

    1. How did you load the application? Was it loaded via SBL or CCS (with GEL files)?

    2. I see there was an initial issue as discussed in https://e2e.ti.com/support/processors/f/791/p/943882/3487453#3487453, were you able to get past that?

    3. Is any other application also running along side the can_profile_app? I see some other inits in the logs.

    Regards,

    Karan

  • Hi Karan,

    i didn't come out of SemaphoreP_pend(CanIf_TxConfirmationSemaphore, SemaphoreP_WAIT_FOREVER); in Profile app.it is waiting continuosly.so i removed.


    I will add again and check.

    1) Xer5f logs

    2) Yes, i added comment today.

    3) yes, like ADC, Power manager..... 

  • Hi Venu,

    VENU HD said:

    i didn't come out of SemaphoreP_pend(CanIf_TxConfirmationSemaphore, SemaphoreP_WAIT_FOREVER); in Profile app.it is waiting continuosly.so i removed.

    If the semaphore is not getting posted then there is a problem, you should not remove that piece of code. I suggest you check your setup (physical connections to the external CAN emulator).

    Try to quickly validate the SDK example without any modification. This will help you check the sanity of the setup.

    But essentially if you do not wait for the CAN packet to go on the bus and it is still sitting in the CAN MSG RAM buffer then the next time if you try to send the CAN packet via the same buffer (this is what you are doing in the app) then it will return a busy state for the CAN.

    Regards,

    Karan 

  • Hi Karan,

    How do we select clock source for CAN peripheral in MCU and MAIN domain ?

    Is it done in Bootloader? Can you please give an example reference.

    Thanks,

  • Hi Venu,

    Are you planning to change something here? The default clock is selected by the bootloader. 

    See file: psdk_rtos_auto_j7_07_00_00_11/pdk_jacinto_07_00_00/packages/ti/board/src/j721e_evm/board_pll.c (search for MCAN, you will se clock of 80MHz)

    Regards,

    Karan

  • Hi Karan,

    Thanks for your answer. we wanted to check clock configuration and we now know it is 80 MHz

    1) We have one more question in MCU2_1 domain. Currently we are seeing crash in Can_Init () and we are getting DEM error in Can_mcanRamInitDone () function.

        DEM Error reported. EventId:65517  EventStatus:1

        Can you please tell how to ensure that the message RAM is initialized for all MCU2_1 domain CAN channels ?

    2) with further investigation we saw in  Can_mcanRamInitDone()

          -- > elapsedCount was coming higher than CAN_TIMEOUT_DURATION

          -- > MCAN_isMemInitDone(baseAddr) was not evaluated even once

       Can you please tell is there some setting we need to do get correct elapsedCount value ? or is there some other problem ?

    3) Can you please tell us how to enable SOC_J721E macro , it is required to enable MAIN domain ISR's..

      

    Best Regards,

    Venu H

  • Hi Venu,

    Based on the discussions above, can I conclude that you are using the SBL bootloader ? Since you didn't directly answer the question

    1. How did you load the application? Was it loaded via SBL or CCS (with GEL files)?

    Do you have the ability to connect JTAG and load application via CCS ?

    Regards

    Vineet

  • Hi Venu H,

    Before answering the question above, I wanted to get some clarifications:

    1. Bootloader used - Are you using SBL or GEL files?

    2. Which core are you running from (MCU1_0 or MCU2_1)?

    3. Which CAN instances are you accessing (MCU domain CANs or MAIN domain CANs)?

    4. Is the initial issue of the Semaphore resolved now, did you add that piece of code? I remember you were failing before after sending one message and now things are hanging in the Can_Init(). Are these problems different?

    One more thing I will suggest is to try and run loopback first, that will isolate some problems and then we can look at the Tx or Rx only mode.

    Regards,

    Karan

  • Hi Karan,

    1) Uboot

    2) Profile App is running from MCU2_1

    3) MAIN domain CANs -- > CAN0

    4) Semaphore issue was present while testing profile app on MCU2_0, This issue not yet resolve due to Hardware issues related to MCU1_0 CAN Transceivers. We have stopped working on MCU1_0, currently concentrating on MCU2_1.

    Yes, Problems are different. (in MCU2_1, Can_init() is failing)

    Issue : Not able to see any data on CAN_TxD line in all MCU2_1 domain channels. But we see data on CAN_TxD line in all MCU1_0 domain channels (we used Tx Mode only).

    We are using Profile app from TI SDK directly.

    Do you have the ability to connect JTAG and load application via CCS ? --- > In EP2000 board we are flashing using SD card.

    Best Regards,

    Venu H

  • Hi Venu H,

    I think now with uboot there comes a lot of variables as this application is not supported from uboot. (see https://e2e.ti.com/support/processors/f/791/t/931992 for more details)

    Can you quickly try something - halt at u-boot prompt and try to access the register space for the MCAN instance you are trying to use? So run the commands:

    # Halt at u-boot and run below: 0x02700000 is for MCAN0 (main domain CAN)
    => md 0x02700000

    If this crashes then we know that the MCAN0 is not being powered on. This is what I expect to see.

    If that is the issue then I can help you in explicitly powering on that instance.

    Regards,

    Karan

  • HI Karan,

    Yes, We tried to halt at u-boot prompt  and accessed register space for the MCAN instance MCAN0

    below are the Uboot Log and we are seeing crash.

    =>
    => md 0x02700000
    02700000:ERROR: Unhandled External Abort received on 0x80000000 at EL3!
    ERROR: exception reason=0 syndrome=0xbf000000
    PANIC in EL3.
    x30 = 0x0000000070004644
    x0 = 0x0000000000000000
    x1 = 0x0000000000000060
    x2 = 0x0000000000000060
    x3 = 0x000000000000000b
    x4 = 0x0000000000000062
    x5 = 0x0000000000000008
    x6 = 0x000000000000003b
    x7 = 0x0000000000000000
    x8 = 0x00000000fdec0850
    x9 = 0x0000000041023020
    x10 = 0x000000000000073d
    x11 = 0x0000000000000006
    x12 = 0x000000000001869f
    x13 = 0x0000000000009078
    x14 = 0x00000000fdec0bec
    x15 = 0x0000000000000008
    x16 = 0x000000000000fffc
    x17 = 0x0000000000000000
    x18 = 0x0000000000000000
    x19 = 0x0000000000000000
    x20 = 0x00000000bf000000
    x21 = 0x0000000002700000
    x22 = 0x00000000fffa6f6d
    x23 = 0x0000000000000008
    x24 = 0x0000000000000004
    x25 = 0x0000000000000004
    x26 = 0x0000000000000004
    x27 = 0x00000000fdec0a18
    x28 = 0x0000000000000000
    x29 = 0x000000007000a520
    scr_el3 = 0x000000000000073d
    sctlr_el3 = 0x0000000030cd183f
    cptr_el3 = 0x0000000000000000
    tcr_el3 = 0x0000000080803520
    daif = 0x00000000000002c0
    mair_el3 = 0x00000000004404ff
    spsr_el3 = 0x00000000600003c9
    elr_el3 = 0x00000000fff8d0d0
    ttbr0_el3 = 0x000000007000f0e0
    esr_el3 = 0x00000000bf000000
    far_el3 = 0x0000000000000000
    spsr_el1 = 0x0000000000000000
    elr_el1 = 0x0000000000000000
    spsr_abt = 0x0000000000000000
    spsr_und = 0x0000000000000000
    spsr_irq = 0x0000000000000000
    spsr_fiq = 0x0000000000000000
    sctlr_el1 = 0x0000000030d00800
    actlr_el1 = 0x0000000000000000
    cpacr_el1 = 0x0000000000000000
    csselr_el1 = 0x0000000000000000
    sp_el1 = 0x0000000000000000
    esr_el1 = 0x0000000000000000
    ttbr0_el1 = 0x0000000000000000
    ttbr1_el1 = 0x0000000000000000
    mair_el1 = 0x0000000000000000
    amair_el1 = 0x0000000000000000
    tcr_el1 = 0x0000000000000000
    tpidr_el1 = 0x0000000000000000
    tpidr_el0 = 0x0000000000000000
    tpidrro_el0 = 0x0000000000000000
    par_el1 = 0x0000000000000000
    mpidr_el1 = 0x0000000080000000
    afsr0_el1 = 0x0000000000000000
    afsr1_el1 = 0x0000000000000000
    contextidr_el1 = 0x0000000000000000
    vbar_el1 = 0x0000000000000000
    cntp_ctl_el0 = 0x0000000000000000
    cntp_cval_el0 = 0x0000000000000000
    cntv_ctl_el0 = 0x0000000000000000
    cntv_cval_el0 = 0x0000000000000000
    cntkctl_el1 = 0x0000000000000000
    sp_el0 = 0x000000007000a520
    isr_el1 = 0x0000000000000000
    dacr32_el2 = 0x0000000000000000
    ifsr32_el2 = 0x0000000000000000
    cpuectlr_el1 = 0x0000001b00000040
    cpumerrsr_el1 = 0x0000000000000000
    l2merrsr_el1 = 0x0000000000000000

  • Hi Venu H,

    Please use the patch attached to enable CAN explicitly from the application: /cfs-file/__key/communityserver-discussions-components-files/791/0001_2D00_mcuss_5F00_demos_2D00_profiling_2D00_can_2D00_enable_2D00_clocks_2D00_explictly.patch

    After this patch when you load the firmware, you should be able to access the same register space from U-boot. Modify the TISCI_DEV* macros for corresponding to the MCANs you want to use.

    Note: you should load the firmware for MCU2_1 from u-boot.

    Note: The MCU2_1 and A72 (linux) share the same UART, how do you plan to validate the app is working? Do you want to disable UART for MCU2_1 app and then just run it in Tx only mode and validate using an external CAN emulator?

    Similar issue to this were discussed earlier in the following threads:

    https://e2e.ti.com/support/processors/f/791/p/906858/3356772#3356772 

    Regards,

    Karan

  • Hi Venu H,

    Glad to know that it works for you now!

    Just to add more details here the CAN application you are using relies on the bootloader for enabling the CAN modules. When the application is tested in SDK, it is done via SBL (Secondary Boot Loader) or GEL files + CCS – in both the cases the MAIN domain CAN instances are enabled by default. When you tried to load the same application with u-boot then this by default doesn’t enable this module and hence you saw the crash when you tried to access the MCAN0 memory space (as the module was turned off).

    When we added the patch, that enabled the MCAN module explicitly from the application itself (removing the dependency from the bootloader used). The other thing here to be careful of is the resources which might be used by Linux – the MCU2_1 application should not contend for resources which are being used by Linux or any other core. But things work for you now so I assume everything is fine there.

    Just have a read of the article - https://e2e.ti.com/support/processors/f/791/t/931992, this will provide a deeper understanding on the issue you faced.

    Regards,

    Karan