Skip to content

Stop dropping bytes on UART-connected pendants - #69

Open
f1adang wants to merge 2 commits into
bdring:mainfrom
f1adang:fix/uart-receive-overflow
Open

f1adang wants to merge 2 commits into
bdring:mainfrom
f1adang:fix/uart-receive-overflow

Conversation

@f1adang

@f1adang f1adang commented Sep 17, 2026

Copy link
Copy Markdown

On a wired M5Dial, large responses such as preferences.json lost bytes, so
the macro list was empty or incomplete. The UART driver's overflow events
confirmed it: the pendant read about 50 KB/s while FluidNC sent up to
100 KB/s at 1 Mbaud.

  • wifi_poll() ran once per received byte even with the transport set to
    UART. It now runs every 20 ms there.
  • Read the UART in 256-byte blocks instead of one uart_read_bytes() call
    per byte, and enlarge the receive buffer to 16 KB.

Afterwards the driver reported no overflows over repeated preferences.json
transfers, and every macro loaded each time.

f1adang and others added 2 commits September 17, 2026 18:49
fnc_poll() reads one byte and then calls poll_extra(), which called wifi_poll()
unconditionally in USE_WIFI builds. With the transport set to UART that is
about 100,000 calls a second at 1 Mbaud, and the reader could not keep up.

Over UART wifi_poll() only services OTA, so call it every 20 ms instead.
WiFi and ESP-NOW keep the per-byte call, where it refills the receive buffer.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Reading one byte per uart_read_bytes() call capped the pendant at about
50 KB/s, while FluidNC sends at up to 100 KB/s at 1 Mbaud. The 256-byte
receive buffer filled within milliseconds of a large transfer such as
preferences.json, bytes were dropped mid-document, and the macro list came back
empty or partial. The UART driver's own overflow events confirmed the loss.

- Read up to 256 bytes per driver call and hand them out from a local buffer.
- Enlarge the driver receive buffer to 16 KB, enough for a whole
  preferences.json while the loop is busy.
- Let the main loop drain up to 1024 bytes per pass instead of 64. It still
  stops as soon as nothing is buffered.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant