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.

UART_Read corrupting data

Part Number: MCU-PLUS-SDK-AM243X

Hello TI,

Currently, I am working on the UART example provided in the SDK for the R5 core with freeRTOS.

I modified the example code with a while loop as follows

void uart_echo(void *args)
{
    int32_t          transferOK;
    UART_Transaction trans;

    Drivers_open();
    Board_driversOpen();

    DebugP_log("[UART] Echo example started ...\r\n");

    UART_Transaction_init(&trans);

    while(1)
    {
        /* Send entry string */
        gNumBytesWritten = 0U;
        trans.buf   = &gUartBuffer[0U];
        strncpy(trans.buf,"This is uart echo test blocking mode\r\nReceives 8 characters then echo's back. Please input..\r\n", APP_UART_BUFSIZE);
        trans.count = strlen(trans.buf);
        transferOK = UART_write(gUartHandle[CONFIG_UART_CONSOLE], &trans);
        APP_UART_ASSERT_ON_FAILURE(transferOK, trans);

        /* Read 8 chars */
        gNumBytesRead = 0U;
        trans.buf   = &gUartReceiveBuffer[0U];
        trans.count = APP_UART_RECEIVE_BUFSIZE;
        transferOK = UART_read(gUartHandle[CONFIG_UART_CONSOLE], &trans);
        APP_UART_ASSERT_ON_FAILURE(transferOK, trans);

        /* Echo chars entered */
        gNumBytesWritten = 0U;
        trans.buf   = &gUartReceiveBuffer[0U];
        trans.count = APP_UART_RECEIVE_BUFSIZE;
        transferOK = UART_write(gUartHandle[CONFIG_UART_CONSOLE], &trans);
        APP_UART_ASSERT_ON_FAILURE(transferOK, trans);

        /* Send exit string */
        gNumBytesWritten = 0U;
        trans.buf   = &gUartBuffer[0U];
        strncpy(trans.buf, "\r\nAll tests have passed!!\r\n", APP_UART_BUFSIZE);
        trans.count = strlen(trans.buf);
        transferOK = UART_write(gUartHandle[CONFIG_UART_CONSOLE], &trans);
        APP_UART_ASSERT_ON_FAILURE(transferOK, trans);

        DebugP_log("All tests have passed!!\r\n");
    }

    Board_driversClose();
    Drivers_close();

    return;
}

whenever, I enter the input from the serial terminal, it is always appending carriage return as shown below and when in a loop it misses the data as carriage return is appended into the buffer as shown below.

I always entered user input "welcome2", but on the screen you can see the data loss caused by the carriage return 0x0d.

Do you have any workaroud for this problem?

Thanks & regards

Teja

  • Hi Teja,

    The "\0x0d" was not added by the example program, it must be added by the terminal emulator you used or by your terminal input. The example program requires inputting 8 characters. They can be anything including "\0x0d". If you inputted "welcome2" followed by a "enter", then there is a "\0x0d" in the UART FIFO. It will be forwarded to the next round of looping. Please try the same example with just type in 8 characters without "enter", then the program works as expected.

    I have tried the same on the AM243x EVM with the TeraTerm. It works as expected.

    Best regards,

    Ming