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.

RTOS/CC3220: Uart issue with declaring globally

Part Number: CC3220
Other Parts Discussed in Thread: CC2538, CC2640

Tool/software: TI-RTOS

I have uart1 setup and have bene using it to read. I want to use it to write now. When I declare the uart handler variables globally it seems to make the uart read stop working so my code just gets hung there. 

I use this same setup with tirtos on another TI chip so I'm pretty familiar with how to set this up. It seems there is just an issue with the global declaration. 

Any help would be much appreciated,

Jon

  • Hello,

    What do you mean it works on another TI chip? which one?

    can you post a code snippet?

    Shlomi

  • I have it working on a cc2640r2. it is setup, declared, and used same way in tirtos. so I know I can setup hart handler globally.

    only difference in the code is on cc2640 I declare hart handler at top of .c file and on cc2538 I have to declare hart handler in task or it seems to not work and just hangs on uart read

  • any ideas? I've been going over code and nothing to me seems to stick out as to why Global declaration has issues

  • Hi,

    All the SDK examples that uses the uart are using uart_term.c where the handle is globally defined.

    Can you please clarify or share a code snippet?

    Shlomi

  • /* Example/Board Header files */
    #include "Board.h"
    #include "inlo.h"
    #include "mqueue.h"
    #include "client_cbs.h"
    #include "inlo_uart.h"

    Display_Handle AWSIOT_display;
    uint8_t uart_buf[60];
    uint32_t ip;
    uint32_t rip;
    /* Message Queue                                                              */
    mqd_t g_PBQueue2;

    UART_Handle uart_inlo;
    UART_Params uartParam;

    /*
     *  ======== mainThread ========
     */
    void *Uart(void *arg0)
    {
        char input;
        struct msgQueue queueElemRecv2;

    //UART_Handle uart_inlo;
    //UART_Params uartParam;
       // char ip;
       //  uint32_t ip;
        static uint32_t tip,lip;
        uint8_t cmd;
        uint8_t countt = 0;
        uint8_t length,packnum,msgnum,rssi,i;
        uint8_t mac[16];
        uint8_t mac2[16];
        volatile unsigned int address;
        //uint8_t uart_buf[60];
        mq_attr attr;
        unsigned mode = 0;

        /* Initialize and open UART */
        UART_Params_init(&uartParam);

        /* sync object for inter thread communication                             */
        attr.mq_maxmsg = 10;
        attr.mq_msgsize = sizeof(struct msgQueue);
        g_PBQueue2 = mq_open("g_PBQueue2", O_CREAT | O_NONBLOCK, mode, &attr);


        uartParam.writeDataMode = UART_DATA_BINARY;
        uartParam.readDataMode = UART_DATA_BINARY;
        uartParam.readReturnMode = UART_RETURN_FULL;
        uartParam.readEcho = UART_ECHO_OFF;
        uartParam.readMode = UART_MODE_BLOCKING;
        uartParam.writeMode = UART_MODE_BLOCKING;
        uartParam.baudRate = 115200;

         //Display_printf(AWSIOT_display, 0, 0, "before ");
        uart_inlo = UART_open(Board_UART1, (UART_Params *) &uartParam);

        if (uart_inlo == NULL) {
            /* UART_open() failed */
            Display_printf(AWSIOT_display, 0, 0, "faild ");
            while (1);
        }

        while (1) {
            Display_printf(AWSIOT_display, 0, 0, "looper ");
                tip = 0;

                while(tip != 0x661c22 && atoi(&ip) != 0x661c22 ){
                 lip = UART_read(uart_inlo, &ip,9);
                 tip = atoi(&ip);
               //  Display_printf(AWSIOT_display, 0, 0, "loop   %06x  %06x", tip, atoi(&ip));

                 ip = 0;
                }

      }

    }

    there is my code. If I declare the Uart handler Globally as the code is doing my uart read doesn't work and just stays hung on the read. If I declare in the process they work but I need them global

  • Hello,

    I believe you have a memory runover.

    When you read, you provide the buffer pointer as the address of the variable "ip" which is defined as 4 bytes. But you try to read 9 bytes.

    When the handler is defined globally, the compiler probably place it right after the "ip" variable (or at least whithin hte 9 bytes range).

    When it is defined inside the main(), it is located on the stack where the handler is defined before the "ip" variable.

    Please make sure you read into an allocated memory with sufficient length.

    Shlomi