uart_wait_tx_done() returns without waiting

Jami17
Posts: 20
Joined: Wed Jul 12, 2017 10:55 pm

uart_wait_tx_done() returns without waiting

Postby Jami17 » Thu May 09, 2019 12:38 pm

uart_wait_tx_done() does not wait but returns immediately under certain conditions.
It works when using it in another task, but fails when using it in the same thread that received a uart-message and then sends a uart-reply (15 bytes)

For a halfduplex RS485 I use this:
TX_ENABLE;
uart_write_bytes()
uart_wait_tx_done()
RX_ENABLE;

Result: the line is already set back to RX even before the first bit gets sent.

It works when adding a 150us delay
TX_ENABLE;
uart_write_bytes()
delayUs(150); // extra delay
uart_wait_tx_done()
RX_ENABLE;


I am using: ESP-IDF v3.3-beta2-18-g0f927791b-dirty

WiFive
Posts: 3277
Joined: Tue Dec 01, 2015 7:35 am

Re: uart_wait_tx_done() returns without waiting

Postby WiFive » Sun May 12, 2019 2:59 am

https://github.com/espressif/esp-idf/bl ... 1052-L1055

Maybe if the fifo hasn't been filled yet from the ringbuffer because of interrupt latency on the other core it will return immediately. So checking the fifo_cnt is not sufficient to determine whether the transmission is already done. The workaround would be only call uart_wait_tx_done on the core the interrupt runs on.

Jami17
Posts: 20
Joined: Wed Jul 12, 2017 10:55 pm

Re: uart_wait_tx_done() returns without waiting

Postby Jami17 » Mon May 13, 2019 9:13 pm

I suspected the same. However I don't like the suggested workaround, too complicated. It would be wise that uart_write_bytes() sets a flag that only gets cleared when the data is moved to the ringbuffer. So wait_tx_done() waits also while that flag is set. For now the delayUs() works fine for me.

biterror
Posts: 19
Joined: Thu Apr 30, 2020 11:00 am

Re: uart_wait_tx_done() returns without waiting

Postby biterror » Wed Jun 16, 2021 5:21 pm

It seems this bug is still there in v4.2. :-( I need to make sure I'm not sending out two modbus rtu packets end to end, but it doesn't seem so easy with almost nothing working as documented.. (Been fighting with the I2S driver for a long time just to find that the UART driver isn't much better. Getting frustrated.)

Jami17
Posts: 20
Joined: Wed Jul 12, 2017 10:55 pm

Re: uart_wait_tx_done() returns without waiting

Postby Jami17 » Wed Jun 16, 2021 8:44 pm

Yes, the problem still is there, at least in the version dl'ed in March, not sure what version-no.

I recently varied the delay value
delayUs(150);

It worked down to 40us when the same core is used.
I have not tried to go lower to find out the limits.

It would be great so see this finally fixed.

biterror
Posts: 19
Joined: Thu Apr 30, 2020 11:00 am

Re: uart_wait_tx_done() returns without waiting

Postby biterror » Sun Jun 20, 2021 10:19 am

It would also be nice if the driver supported inserting an idle period between transmitted packets (required by Modbus RTU mode, for example). The hardware supports this, but it requires driver support as well.

Return to “Report Bugs”

Who is online

Users browsing this forum: No registered users and 6 guests