← index #8063PR #17698
Related · high · value 0.628
QUERY · ISSUE

Esp32: Add explicit "wait_tx_done" method to UART

openby mrkeuzopened 2021-12-05updated 2022-05-27
port-esp32

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 call init(). 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.
CANDIDATE · PULL REQUEST

esp32/machine_uart: Change `sendbreak()` implementation to simply pull the pin low for the break period

mergedby dpgeorgeopened 2025-07-17updated 2025-07-23
port-esp32

Summary

Currently, UART.sendbreak() on esp32 will reconfigure the UART to a slower baudrate and send out a null byte, to synthesise a break condition. That's not great because it changes the baudrate of the RX path as well, which could miss incoming bytes while sending the break.

This PR changes the sendbreak implementation to just reconfigure the TX pin as GPIO in output mode, and hold the pin low for the required duration.

Testing

Existing test is updated (simplified) and works well on ESP32_GENERIC.

Also tested that RPI_PICO_W still passes this test.

Trade-offs and Alternatives

There's uart_write_bytes_with_break() but that requires at least 1 byte to be sent before the break, so we can't use that.

There's also the lower level uart_hal_tx_break() but I'm not sure how to use that properly in conjunction with the higher level driver.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied