Esp32: Add explicit "wait_tx_done" method to UART
Hello folks,
Faced with issue, I cannot control time when UART TX done from MicroPython.
Use case is next:
- I've tried to communicate by raw RS485 and I should know when exactly disable TX pin.
Currently, there are couple workarounds (judged by sources and undocumented). In these methods called uart_wait_tx_done():
- Via
init()method. E.g. send bytes and callinit(). But if implementation will be changed in future such method stopped worked. Especially this method is very strange to call in the middle of the UART operation. - Via
sendbreak()method. But also undocumented plus it always sends\x00
Proposal:
- I think it would be good to add explicit method for waiting UART TX done.
rp2/machine_uart: Make it so TX is done only when no longer busy.
Summary
When flushing a UART on the rp2 port, it returns just before the last character is sent out the wire.
Fix this by waiting until the BUSY flag is cleared.
Testing
TODO: the tests/extmod/machine_uart_tx.py test needs updating to cover this case. Currently that test checks that transmit time is less than the expected time, and on rp2 the transmit+flush time is quite a bit less than expected (because it returns while there's still a byte left to transmit). Rather it should be changed so transmit time is very close to the expected time.
Edit: that's now done. Also docs updated.