Does UART write slow?

I am using rtl8721d chip with ambd_sdk. For UART functionality I am using serial_send_stream() function, there is a functionality where I need to send 512 chunks repetitively for 200 times for OTA, where I am observing after writing few times it is getting stopped. FYI UART Tx Fifo and RX Fifo are 16 bytes. Is it because uart takes time to write 512 bytes?

Hi @VedantLm10

Can you elaborate more on what you mean by getting stopped?

looking at the code, serial_send_stream is an asynchronous function that uses the UART Tx FIFO empty interrupt to continue sending more data. This means that if you try to write 512 bytes using serial_send_stream, only the first 16 bytes will be written into the FIFO first, then the remainder are written when the TX FIFO is emptied.

Depending on how your code is written, rapid repeated calls to serial_send_stream may be trying to send more data when the previous chunk is not yet done.

Hi @wyy , Thanks for the quick response,

  1. Yes, there are repeated calls to serial_send_stream which tries to send 512 bytes for every serial_send_stream call, which is why it is trying to write more number of bytes without the previous bytes being sent. For which i had added delays before every call where i can see that these repeated serial_send_stream are working correctly and i am able to transfer these chunks.
  2. Although i don’t think the delay would be an proper solution to which i was using serial_comp_handler function for tx callback, but it didn’t make any difference.
  3. By being stopped means, due to repetitive call, the next 512 wasnt getting sent, and it used to return busy.

Hi @VedantLm10

To me it sounds like it is working as intended. Your code is trying to send data faster than the UART port is able to handle, thus it is returning HAL_BUSY to inform you that the previous chunk of 512 bytes are not done yet.

The better method would be to check the return value, and if it is busy, wait for a short time duration before trying to send the same chunk again, repeating this process until one chunk is sent, then moving on to the next chunk.

1 Like