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.

LP-AM243: AM243x UART Polled Mode Issue

Part Number: LP-AM243


Tool/software:

Hello,

I'm developing an application and using the LP-AM243 to do my initial development work.  I'm using a UART in polled mode but I'm setting the timeout = 0, and the count = 94 which is the typical packet size sent to the LP-AM243 from the host PC.  From the documentation it states that if a timeout happens then the count variable of the trans structure will be modified with the actual number of bytes read.  Since the underlying FIFO is only 64 bytes I don't want any unnecessarily large timeout to wait for the full packet to come in, i manage building up the packet to the full size at my top layer of code, in addition there are times when the packet size changes for me and it always has a special character sequence at the end of packet so that the application knows what the packet is regardless of size.

I'm pretty sure this worked for me when I had originally used SDK Version 8 but when I use the latest version 11 I don't get the same behavior.

The trans.count value is always = 94 and never gets modified, as I debugged down into the layers of code I could see that in this function UART_readPolling(), for the case when the full trans.count number of bytes is not read that it changes the actual bytes read back to 0 during the UART_lld_Transaction_deInit() call.  However, that doesn't even matter because the trans structure doesn't get passed down through the layers of code anyway.

At some point in the stack this function gets called UART_lld_read(), and the size and timeout variables are just passed by value, there is no way for the trans.count to be modified anymore.

As I dug through the layers I discovered that I could still access the actual number of bytes read by creating the line of code in green below, i just wanted to make the team aware of this issue, perhaps most people don't have variable size packets coming in so this wouldn't be an issue in those applications.

transferOK = UART_read(com, &trans);
// count=trans.count; //This doesn't work unless the full amount expected is read, if only a partial number of bytes is read it still is set to the full value

count = ((UART_Config *)com)->object->uartLld_handle->readCount;  //This allows me to access the actual number of bytes read up at the top level of my code and solved my issue

//At this point in the stack the trans structure is not passed down any more and the hUART handle needs to be used recover readCount
int32_t UART_lld_read(UARTLLD_Handle hUart, void * rxBuf, uint32_t size, uint32_t timeout, const UART_ExtendedParams *extendedParams)

static int32_t UART_readPolling(UARTLLD_Handle hUart, UART_Transaction *trans)

...

else
{
/* Return UART_TRANSFER_TIMEOUT so that application gets whatever bytes are
* transmitted. Set the trans status to timeout so that
* application can handle the timeout. */
retVal = UART_TRANSFER_TIMEOUT;
trans->status = UART_TRANSFER_STATUS_TIMEOUT;
trans->count = hUart->readCount;
UART_lld_Transaction_deInit(&hUart->readTrans);
}

return (retVal);
}

  • Hi Paul,

    The question here exactly is that when Timeout occurs then the trans.count is not modified and is retained with the value of 94.

    Moreover your usecase is more like, that if the number of bytes expected to be read is x, then:

    1. if values read is x, then this is ideal and is handled well in the SDK.
    2. if values read is < x, and timeout occurs, then this case is not handled in the SDK and the trans.count still reflects x.

    Is my understanding of your description correct?

    Regards,

    Vaibhav

  • Yes, that is correct.

    I'm able to get the number of bytes read when a timeout occurs by using this line of code:
    count = ((UART_Config *)com)->object->uartLld_handle->readCount

  • Hi Paul,

    Thanks for your comments.

    Glad to know my summary for your problem statement is accurate.

    Allow me sometime to take this issue further towards a resolution.

    Regards,

    Vaibhav

  • Hi,

    Thanks for waiting.

    I see that the code which you put will help to retrieve the actual number of bytes read. Can you help me to test this out, which timeout parameter did you change to purposely fail/read partial number o bytes upon timeout is done for UART?

    If you can help me set that parameter and give me a certain number of bytes to be read at a certain baudrate and frequency then I can test this on my own setup and sign off for this to be included in the next SDK release.

    Looking forward to your response.

    I am also assuming a similar thing can be done for write, so for example if timeout occurs, then how many bytes have been actually written, kind of this.

    Regards,

    Vaibhav