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/66AK2G02: UART Driver error in pdk_k2g/packages/ti/drv/uart/src/v0/UART_v0.c of K2G PDK when using UART_RETURN_FULL

Part Number: 66AK2G02

Tool/software: TI-RTOS

I've found a problem with the UART low level read code (UART_v0_readData) that causes data to become lost.

static inline int32_t UART_v0_readData(UART_Handle handle, int32_t size)
{
    int32_t                     readIn;
    UART_V0_Object              *object;
    UART_HwAttrs const          *hwAttrs;

    object = handle->object;
    hwAttrs = handle->hwAttrs;

    readIn = (int32_t)UART_charGetNonBlocking_v0(hwAttrs->baseAddr);
    /* Receive chars until empty or done. */
    while ((size != 0) &&
          (readIn != -1))
    {
        /* If data mode is set to TEXT replace return with a newline. */
        if (object->params.readDataMode == UART_DATA_TEXT)
        {
            if ((uint8_t)readIn == (uint8_t)'\r')
            {
                /* Echo character if enabled. */
                if (object->params.readEcho)
                {
                    UART_charPut_v0(hwAttrs->baseAddr, (uint8_t)'\r');
                }
                readIn = (int32_t)'\n';
            }
        }

        UART_drv_log2("UART:(%p) Read character 0x%x",
                   hwAttrs->baseAddr, (uint8_t)readIn);

       *(uint8_t *)object->readBuf = (uint8_t)readIn;
        object->readBuf = (uint8_t *)object->readBuf + 1;
        object->readCount++;
        size--;

        /* Echo character if enabled. */
        if (object->params.readEcho)
        {
            UART_charPut_v0(hwAttrs->baseAddr, (uint8_t)readIn);
        }

        /* If read return mode is newline, finish if a newline was received. */
        if ((object->params.readReturnMode == UART_RETURN_NEWLINE) &&
            ((uint8_t)readIn == (uint8_t)'\n'))
        {
            UART_drv_log1("UART:(%p) Newline character received, "
                       , hwAttrs->baseAddr);

            size = 0;
            break;
        }
        readIn = (int32_t)UART_charGetNonBlocking_v0(hwAttrs->baseAddr);
    }

    return (size);
}

The issue is that the final "readIn = (int32_t)UART_charGetNonBlocking_v0(hwAttrs->baseAddr);" call reads another character from the UART at the end of the call, consuming and not processing it, thus losing the data.

This is resolved by inserting "if(size==0) break;" in the line above that line, as the final read should be conditional on more bytes being read into the buffer. This only affects where UART_RETURN_FULL is the return mode; UART_RETURN_NEWLINE is unaffected.

  • Hi Jonathan,

    I've forwarded your query to the software experts. Their feedback should be posted here.

    BR
    Tsvetolin Shulev
  • Jonathan,

    Thanks for taking the time to report this issue from the driver logical flow, your fix does seem to make sense. I don`t think we have a test case that is setting the UART driver in UART_RETURN_FULL which is why we may have missed this corner case.

    If you have a simple test case, that we can reuse for reproducing this, can you please provide it here. Else we can try and set the driver in UART_RETURN_FULL mode and see if the last character is missed in the UART driver example when the UART loops back to get more user inputs.

    Thanks again for point this to out attention.

    Regards,
    Rahul

    PS: YOu can track this bug in Release notes using BUG ID PRSDK-3087