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/CC3220SF: problem receiving multiple UART on CC3220SF

Part Number: CC3220SF

Tool/software: Code Composer Studio

Hello

I'm currently working on CC3220SF and want to use 2 UART port at the same time.

When i used UART_readPolling(from network_terminal example), only 1 port works and other one never worked.

So I tried to user UART_read instead, i cannot even read both them.

After trying some experipent using uartecho example, I found that UART_read only works when i call it directly from thead, but not in other funcion.

How can I read properly in function and how can I do other stuff while waiting data come in UART?

here's my code snippet.

int getCommand(UART_Handle huart, void *pBuffer, int bufSize)
{
    char now, prev = 0;

    for(;;)
    {
        UART_read(huart, &now, 1);
        UART_write(huart, &now, 1);
        if((prev == 'A') &&(now == 'T'))
        {
            break;
        }
        else
        {
            prev = now;
        }
    }

    return 0;
}

void *consoleThread(void *arg)
{
    char cmdBuf[400];

    char now, prev = 0;

    /* Loop forever echoing */
    while (1)
    {
        getCommand(uartConsoleHanlde, cmdBuf, 400);
        /* this works. but not one above this
        for(;;)
        {
            UART_read(uartConsoleHanlde, &now, 1);
            UART_write(uartConsoleHanlde, &now, 1);
            if((prev == 'A') &&(now == 'T'))
            {
                break;
            }
            else
            {
                prev = now;
            }
        }*/
    }
}


void *mainThread(void *arg0)
{
    long RetVal;

    pthread_t thread;
    pthread_attr_t pAttrs;

    UART_Params uartParams;


    /* Call driver init functions */
    GPIO_init();
    UART_init();

    UART_Params_init(&uartParams);
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.readReturnMode = UART_RETURN_FULL;
    uartParams.readEcho = UART_ECHO_OFF;
    uartParams.baudRate = 115200;

    uartNootHanlde = UART_open(CONFIG_UART_0, &uartParams);

    if (uartNootHanlde == NULL) {
        while (1);
    }

    UART_Params_init(&uartParams);
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.readReturnMode = UART_RETURN_FULL;
    uartParams.readEcho = UART_ECHO_OFF;
    uartParams.baudRate = 115200;

    uartConsoleHanlde = UART_open(CONFIG_UART_1, &uartParams);

    if (uartConsoleHanlde == NULL) {
        while (1);
    }

    /* command receive threads */
    pthread_attr_init(&pAttrs);
    RetVal = pthread_create(&thread, &pAttrs, nootThread, NULL);

    /* command receive threads */
    pthread_attr_init(&pAttrs);
    RetVal = pthread_create(&thread, &pAttrs, consoleThread, NULL);
    return NULL;
}

Thanks.

  • Hi,

    You should be able to call the UART_*() APIs nested within another function. In fact, the UART_*() APIs are just a wrapper for the underlying UARTCC32XX driver code.

    Something that may be causing your issue is incorrect thread spawning. Most notably, you do not assign a stack size to your spawned threads. If you are running out of stack memory for your thread, then you will run into unexpected behavior in your threads.

    Please call the following pthread APIs to create your thread:

    /* Set priority and stack size attributes */
    thread_t thread;
        pthread_attr_t pAttrs;
        struct sched_param priParam;
        int retc;
        int detachState;    
    
    pthread_attr_init(&pAttrs);
        priParam.sched_priority = 1;
    
        detachState = PTHREAD_CREATE_DETACHED;
        retc = pthread_attr_setdetachstate(&pAttrs, detachState);
        if(retc != 0)
        {
            /* pthread_attr_setdetachstate() failed */
            while(1)
            {
                ;
            }
        }
    
        pthread_attr_setschedparam(&pAttrs, &priParam);
    
        retc |= pthread_attr_setstacksize(&pAttrs, 4096);
        if(retc != 0)
        {
            /* pthread_attr_setstacksize() failed */
            while(1)
            {
                ;
            }
        }
    
        retc = pthread_create(&thread, &pAttrs, consoleThread, NULL);

    You can find an example of this code in the main_tirtos.c main() of the SDK examples. Let me know if that helps.

    Regards,

    Michael

  • I fixed thread creating and my test code works flawlessly. but my main code doesn't work as before.

    Maybe I need some more testing.

    thanks for your help.

  • Sorry for late reply. I managed to make my  code work.

    There's 2 major problem and  one is  you suggest.  The other one was some confix with UART_read and UART_readPolling which I should use only one of them.

    thank you for your help.