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.

PROCESSOR-SDK-AM64X: Bug in UART polling read

Part Number: PROCESSOR-SDK-AM64X


Tool/software:

Hi all,

I am using a UART instance configured in polling mode to read input from a terminal. I am using HTerm as terminal, not the integrated terminal of CCS.
I have a simple application where I read input with DebugP_readLine(pointer to buffer, 100u) and I can observe that UART_readPolling is in its read loop.

Now I send e.g. "foo" with a carriage return char via HTerm. I can see that the buffer is filled with my input but the application will hang forever in the polling read loop.

The problem is caused by a bug in uart_v0_lld.c (from MCU+ SDK v10.00.00.20) in the function UART_fifoRead:

1. While loop checks for 0 != readSizeRemaining
2. readSizeRemaining is never updated inside the loop, only tempReadSizeRemaining is. Therefore the loop will never break from this condition

Because I read input DebugP_readLine, readSizeRemaining will be 1 as it wants to read input character by character:

1. UART_fifoRead returns (size - tempReadSizeRemaining)
2. Because HTerm sends an input string altogether 4 characters have been read and the return value underflowed
3. UART_readPolling never returns although everything has been successfully read.

I guess the CCS terminal sends input after every keystroke unlike HTerm which never makes this bug visible.

  • Hi,

    Allow me sometime to check this on my setup. I will check the behaviour of the Polled reads and update you.

    Regards,

    Vaibhav

  • Hi Simon,

    I have observed that indeed this is a bug as the variable 

    readSizeRemaining is checked for but the variable 
    tempReadSizeRemaining should be checked for.
    I have also noticed that the latest SDK release has this issue fixed.
    static uint32_t UART_fifoRead(UARTLLD_Handle hUart, uint8_t *buffer,
                                  uint32_t readSizeRemaining)
    {
        uint32_t tempReadSizeRemaining = readSizeRemaining;
        uint32_t size    = tempReadSizeRemaining;
        Bool isRxReady = FALSE;
        uint8_t *tempBuffer = buffer;
    
        isRxReady = UART_statusIsDataReady(hUart);
    
        while (((Bool)TRUE == isRxReady) && (0U != readSizeRemaining))
        {
            /* once the H/w is ready  reading from the H/w                        */
            *tempBuffer = (UInt8) UART_readByte(hUart);
            tempBuffer++;
            --tempReadSizeRemaining;
    
            isRxReady = UART_statusIsDataReady(hUart);
        }
    
        return (size - tempReadSizeRemaining);
    }
    Marking the thread closed.
    Regards,
    Vaibhav