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.

TDA2PXEVM: How to use UART3 along with UART1

Part Number: TDA2PXEVM

Hi,

I want to use UART3 in TDA2px, to communicate with other peripherals so I have created UART3 init taking reference from System_uartInit() as following - 

Void uart3Init(void)
{
    Vps_printf(" ################### Inside uart init start ###################\n");
    Uart_ChanParams chanParams;
    Error_Block eb;
    GIO_Params  ioParams;
    static char uartName[16]; /* device name MUST be global or static variable */
    static DEV_Struct uartDevObj;
    static GIO_Struct uartTxObj;
    static GIO_Struct uartRxObj;
    static SyncSem_Struct uartTxSyncSemObj;
    static SyncSem_Struct uartRxSyncSemObj;
    static Semaphore_Struct uartTxSemObj;
    static Semaphore_Struct uartRxSemObj;
    static IOM_Packet       uartTxIomObj[UART_ASYNC_IOM_PACKET_MAX];
    static IOM_Packet       uartRxIomObj[UART_ASYNC_IOM_PACKET_MAX];
    DEV_Params    devParams;
    Uart_Params   uartParams;
    SyncSem_Params syncSemParams;
    Semaphore_Params semParams;

    Int32 devId;

    Error_init(&eb);

    /*
     * Initialize channel attributes.
     */
    GIO_Params_init(&ioParams);

//    Uart_init();

#if 0 // for testing
    strcpy(uartName, "/uart0s");
    devId = 0;
    Bsp_boardSelectDevice(BSP_DRV_ID_UART, BSP_DEVICE_UART_INST_ID_0);
#else
    strcpy(uartName, "/uart2sCM");
    devId = 2; // this refers to uart 3
    Bsp_boardSelectDevice(BSP_DRV_ID_UART, BSP_DEVICE_UART_INST_ID_2);
#endif

    uartParams              = Uart_PARAMS;
    uartParams.opMode       = UART_OPMODE_INTERRUPT;
    uartParams.hwiNumber    = 8u;
    uartParams.rxThreshold  = UART_RXTRIGLVL_8;
    uartParams.txThreshold  = UART_TXTRIGLVL_56;
    uartParams.baudRate     = UART_BAUDRATE_115_2K;
    uartParams.prcmDevId    = 0;
    /* INVARIANT_CONDITION.UNREACH
    * MISRAC_2004_Rule_13.7
    * MISRAC_WAIVER:
    * Code is currently unreachable.
    * This is kept to ensure future updates to modes.
    */
    if(uartParams.opMode == UART_OPMODE_POLLED)
    {
        printf(" SYSTEM: MCU COMM UART: POLLED Mode is Selected \n");
    }
    else if(uartParams.opMode == UART_OPMODE_INTERRUPT)
    {
        printf(" SYSTEM: MCU COMM UART: INTERRUPT Mode is Selected \n");
    }
    else
    {
        /* MISRA WARNING */
    }
    uartParams.enableCache = (Bool)FALSE;

    /* initialise the edma library and get the EDMA handle */
    chanParams.hEdma = NULL;

    /* If cross bar events are being used then make isCrossBarIntEn = TRUE and
     * choose appropriate interrupt number to be mapped (assign it to
     * intNumToBeMapped)
     */
    chanParams.crossBarEvtParam.isCrossBarIntEn = (Bool)FALSE;

    chanParams.crossBarEvtParam.intNumToBeMapped = 0xFFU;

    ioParams.chanParams = (Ptr)&chanParams;

    DEV_Params_init(&devParams);
    devParams.deviceParams = &uartParams;
    devParams.initFxn = NULL;
    devParams.devid = devId;

/* MISRA.CAST.CONST
 * MISRAC_2004 Rule_11.5
 * MISRAC_WAIVER:
 * External package errors like bios which are not
 * part of VSDK package can't be fixed
 */
    DEV_construct(&uartDevObj, uartName, (Ptr)&Uart_IOMFXNS, &devParams, &eb);
#if 1
    SyncSem_Params_init(&syncSemParams);

    Semaphore_Params_init(&semParams);
    semParams.mode = Semaphore_Mode_BINARY;

    Semaphore_construct(&uartTxSemObj, 0, &semParams);

    syncSemParams.sem = Semaphore_handle(&uartTxSemObj);

    SyncSem_construct(&uartTxSyncSemObj, &syncSemParams, &eb);

    ioParams.sync =
        SyncSem_Handle_upCast(
            SyncSem_handle(
                &uartTxSyncSemObj
            )
        )
        ;

    if(ioParams.numPackets > UART_ASYNC_IOM_PACKET_MAX)
    {
        UTILS_assert(ioParams.numPackets <= UART_ASYNC_IOM_PACKET_MAX);
    }
    memset(&uartTxIomObj[0], 0, ioParams.numPackets * sizeof (IOM_Packet));
    ioParams.packets = &uartTxIomObj[0];
#endif
    /* create the required channels(TX/RX) for the UART demo */
    GIO_construct(&uartTxObj, uartName, (UInt32)GIO_OUTPUT, &ioParams, &eb);
#if 1
    SyncSem_Params_init(&syncSemParams);

    Semaphore_Params_init(&semParams);
    semParams.mode = Semaphore_Mode_BINARY;

    Semaphore_construct(&uartRxSemObj, 0, &semParams);

    syncSemParams.sem = Semaphore_handle(&uartRxSemObj);

    SyncSem_construct(&uartRxSyncSemObj, &syncSemParams, &eb);

    ioParams.sync =
        SyncSem_Handle_upCast(
            SyncSem_handle(
                &uartRxSyncSemObj
            )
        )
        ;

    memset(&uartRxIomObj[0], 0, ioParams.numPackets * sizeof (IOM_Packet));
    ioParams.packets = &uartRxIomObj[0];
#endif
    GIO_construct(&uartRxObj, uartName, (UInt32)GIO_INPUT, &ioParams, &eb);

    uartTxHandleCM = GIO_handle(&uartTxObj);
    uartRxHandleCM = GIO_handle(&uartRxObj);
    /* INVARIANT_CONDITION.UNREACH
    * MISRAC_2004_Rule_13.7
    * MISRAC_WAIVER:
    * Code is currently unreachable.
    * This is kept to ensure future updates by the called function.
    */
    if ((NULL == uartRxHandleCM) || (NULL == uartTxHandleCM))
    {
        printf(" SYSTEM: MCU COMM UART: ERROR: GIO_create(%s) Failed !!!\n", uartName);
    }
    else
    {
        InitDoneCM = (Bool)TRUE;
    }
    Vps_printf(" ################### Inside uart init end ###################\n");
}

When I try to initialize UART3 after System_uartInit() system gets hang(not getting any system logs on terminal).

If I initialize UART1(commenting System_uartInit and all vision usecase runtime menu) instead of UART3 in the same code, just by changing devid, it is working fine.

I don't want to change UART1 default functionality as it is being used for system logs.

Please help me solve these problems, Thanks.

SDK : PROCESSOR_SDK_VISION_03_08_00_00

  • Hi,

    Are you running RTOS only build or Linux+RTOS?

    You have to make sure UART3 module clock is enabled.

    If this is RTOS only build, you can enable UART3 module clock in SBL or before System_uartInit() is called.

    If you are running Linux+RTOS, UART3 can be enabled by Linux.

    Regards,

    Stanley