# Does UART write slow?

**URL:** <https://forum.amebaiot.com/t/does-uart-write-slow/1585>\
**Category:** Peripherals\
**Tags:** uart, rtl872xd\
**Created:** [December 9, 2022, 10:16am UTC](https://forum.amebaiot.com/t/does-uart-write-slow/1585 "2022-12-09T10:16:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![VedantLm10](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/vedantlm10/32/1225_2.png) [@VedantLm10](https://forum.amebaiot.com/u/VedantLm10)\
**Post date:** [December 9, 2022, 10:16am UTC](https://forum.amebaiot.com/t/does-uart-write-slow/1585/1 "2022-12-09T10:16:51Z")

</div>

Hello,  
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?

---

<div class="post-metadata">

**Author:** ![wyy](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wyy](https://forum.amebaiot.com/u/wyy)\
**Post date:** [December 12, 2022, 3:41am UTC](https://forum.amebaiot.com/t/does-uart-write-slow/1585/2 "2022-12-12T03:41:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![VedantLm10](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/vedantlm10/32/1225_2.png) [@VedantLm10](https://forum.amebaiot.com/u/VedantLm10)\
**Post date:** [December 13, 2022, 9:33am UTC](https://forum.amebaiot.com/t/does-uart-write-slow/1585/3 "2022-12-13T09:33:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![wyy](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wyy](https://forum.amebaiot.com/u/wyy)\
**Post date:** [December 14, 2022, 8:19am UTC](https://forum.amebaiot.com/t/does-uart-write-slow/1585/4 "2022-12-14T08:19:57Z")

</div>

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.
