Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

dpgeorge
Copy link
Member

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.

@dpgeorge
Copy link
Member Author

@hmaerki FYI this should fix the final issue with octoprobe/testbed_micropython#36

Copy link

codecov bot commented Jul 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.37%. Comparing base (941b7e3) to head (1ab1f85).
Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #17698   +/-   ##
=======================================
  Coverage   98.37%   98.37%           
=======================================
  Files         171      171           
  Lines       22210    22210           
=======================================
  Hits        21849    21849           
  Misses        361      361           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hmaerki
Copy link
Contributor

hmaerki commented Jul 21, 2025

There is a testrun against this PR: https://reports.octoprobe.org/github_selfhosted_testrun_189/octoprobe_summary_report.html
All test concerning this PR pass!

Please merge this PR.

Copy link
Contributor

@projectgus projectgus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good improvement.

The only practical difference I can think of between doing it this way and using the UART HAL break function is that the break signal length will be exact if the peripheral hardware generates it whereas mp_hal_delay_us may delay longer than break_delay_us due to interrupts or a context switch. However, as the UART break signal is defined as a minimum pulse length this doesn't seem like a problem for correctness.

@dpgeorge
Copy link
Member Author

mp_hal_delay_us may delay longer than break_delay_us due to interrupts or a context switch. However, as the UART break signal is defined as a minimum pulse length this doesn't seem like a problem for correctness.

Yes, that's also my understanding, that the break is a minimum low pulse, so it's OK for it to be longer than 13 bits.

@dpgeorge dpgeorge force-pushed the esp32-machine-uart-improve-break branch from 741d38b to 47db522 Compare July 23, 2025 02:47
dpgeorge added 2 commits July 23, 2025 12:50
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 commit changes the sendbreak implementation to just reconfigure the TX
pin as GPIO in output mode, and hold the pin low for the required duration.

Signed-off-by: Damien George <damien@micropython.org>
This is no longer needed, the esp32 port can now pass this test using just
a single UART.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge force-pushed the esp32-machine-uart-improve-break branch from 47db522 to 1ab1f85 Compare July 23, 2025 02:51
@dpgeorge dpgeorge merged commit 1ab1f85 into micropython:master Jul 23, 2025
32 checks passed
@dpgeorge dpgeorge deleted the esp32-machine-uart-improve-break branch July 23, 2025 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy