Skip to content

ESP32 WiFi modules: drop the frame an RX FIFO overflow hits and skip to the next frame - #1078

Open
JC-000 wants to merge 9 commits into
GideonZ:masterfrom
JC-000:fix/wifi-uart-rx-overflow
Open

JC-000 wants to merge 9 commits into
GideonZ:masterfrom
JC-000:fix/wifi-uart-rx-overflow

Conversation

@JC-000

@JC-000 JC-000 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1074

Problem

An overflow of the module's UART RX FIFO loses bytes at an unknown place in the stream. The frame in progress then carried on with whatever arrived next: it was delivered cut short, glued to the next frame when its closing 0xC0 was lost, or the rest of a frame was taken for a frame, and the dispatcher ran a command nobody sent. Seen on a C64 Ultimate with the module's RTS flow control forced off for a hold under load: frames that began in the middle of an echo payload were answered as commands and the link was dead afterwards.

What changed and why

On the full-FIFO interrupt the handler looks at the raw overflow status first: the FIFO is emptied without reading it, the open frame is thrown away, and everything up to the next 0xC0 is skipped (it ends the damaged frame or starts the next). With no frame open there is nothing to skip. Same my_uart.c in raw_u64, raw_c3 and u64ctrl; all three change. The overflow interrupt stays disabled, as on master.

This branch contains the UART interrupt handler tests PR (#1077, the harness), which goes in first. The TX-FIFO fill PR (#1079) in turn contains this one, so the three merge in that order.

Products. the ESP32 WiFi modules: raw_u64 (Ultimate 64 / Ultimate 64 Elite), raw_c3 (Ultimate-II+L) and u64ctrl (Ultimate 64 Elite II / C64 Ultimate); the same my_uart.c is in all three. Tested on the C64 Ultimate.

How I tested it

Host: macOS, with the device-free tests run in an Ubuntu 24.04 container (g++ 13.3). The hardware runs used the test harness from the same machine.

Host tests (device-free, run before and after the change):

  • UART handler tests (9 cases) and models of the old handler: make -C software/wifi/uart_tests isr; make -C software/wifi/uart_tests isr-red
    • with the change: 9 tests pass per module build (raw_u64, raw_c3, u64ctrl)
    • without it: the same cases fail on the parent of the change; the five old-handler models fail as required

Hardware.

Device Firmware Ultimate FPGA C64 core
Ultimate 64 Elite 7b15448a7 126 1.50
C64 Ultimate 7b15448a7 126 1.50

Forcing an overflow (module RTS flow control off for a hold under load) on the C64 Ultimate: before, the link was dead after the overflow — the module stopped answering and never came back. With the change the overflow is counted once, the module keeps answering (no wedge) and the device stays reachable at 0% ping loss. With RTS flow control on, no overflow occurs (the Ultimate is held off) and the module answers as normal.

Standard profile / soak: not reported here — this change is module-side (ESP32) firmware, which the host-driven ./run-tests standard profile and soak suites do not exercise. The module build is flashed and checked on its own (see above).

Untested

  • Ultimate-II cartridge (U2+ / U2+L): not tested. I do not have one. Not built either for the cartridges, because the build environment I use cannot build those targets; CI builds them.
  • With flow control on, an overflow needs a sender overrunning RTS (margin 6 characters); not forced on the Ultimate 64 Elite or the Ultimate-II+L.
  • The module version number must be bumped in the same commit for the updater to take the new module; the number is decided at merge.

Written with Claude Opus 5.5 in Claude Code.

JC-000 and others added 5 commits November 9, 2026 12:05
…e next frame

An overflow of the UART RX FIFO loses bytes at an unknown place in the stream. The
handler had code for it (reset the FIFO) but RXFIFO_OVF was not in the enable mask of
my_uart_init, so it never ran, and it came after the receive code anyway: the frame in
progress carried on with whatever arrived next. It was delivered cut short, or glued
to the next frame when its closing 0xC0 was lost, or the rest of a frame was taken for a
frame, and the dispatcher ran a command nobody sent.

Enable RXFIFO_OVF and handle it first in the pass: the FIFO is emptied and not read, the
open frame is thrown away, and everything up to the next 0xC0 is skipped (it ends the
damaged frame or starts the next). With no frame open there is nothing to skip.

Seen on a C64U with the module's RTS flow control forced off for a hold under load: frames
that began in the middle of an echo payload were answered as commands, and the link was
dead afterwards. With flow control on, this needs a sender overrunning RTS (the margin
is 6 characters); the same my_uart.c is in raw_u64, raw_c3 and u64ctrl, all three change.

Host tests (software/wifi/tests, `make isr`): 5 cases, RED on this file's parent, plus
five models of the code before the fix (`make isr-red`). The module identity is bumped as a
placeholder; the maintainers assign the number at merge.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
GideonZ#1041 (wifi-fixes) adds its own software/wifi/tests; the two trees would collide on Makefile and stub/. Nothing else changes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Two fixes edited the same lines of the Makefile; each now adds a file, and the Makefile includes isr_*.mk.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…er does (raw status in the RX branch)

The first version enabled the RXFIFO_OVF interrupt and handled it at the top of the pass. The
mechanism that ran on hardware (a C64U, an RX overflow forced by switching the module's RTS flow
control off for a hold under load: the module stayed alive, rx_fifo_ovf counted 1) keeps the
interrupt disabled and looks at the raw status inside the RX branch, at the interrupt the full FIFO
brings. This takes that mechanism, so the hardware result applies to what is merged: same detection
point, same actions (the FIFO emptied and not read, the open frame thrown away, skip to the next
0xC0). The enable mask is as on master; the dead overflow branch at the end of the pass is as on master.
Only the bench's counter is left out (master has no link counters).

Host harness: the stub offers the raw status (uart_hal_get_intraw_mask); the cases are the same and
still fail on master; the models of the old handler follow the new detection (isr_ovf.mk).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The CI step "make host_tests" runs the other host suites; this one is added to it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@chrisgleissner chrisgleissner added bug Existing behavior is incorrect, broken, or regressed; includes supported documentation defects. network Networking and remote services: REST, Socket DMA, FTP, Telnet, and online access. labels Nov 10, 2026

@chrisgleissner chrisgleissner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@JC-000 thanks for the RX overflow fix. The branch conflicts with master. Please merge or rebase master once #1077 is in, and renumber the module identity as you describe.

…1078)

Brings in GideonZ#1077 (updated onto master). Module IDENT renumbered after master: raw_u64 1.19, raw_c3 1.12, u64ctrl 1.30.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
JC-000 added a commit to JC-000/1541ultimate that referenced this pull request Nov 10, 2026
Brings in GideonZ#1078 and GideonZ#1077 (updated onto master). Module IDENT renumbered after master and GideonZ#1078: raw_u64 1.20, raw_c3 1.13, u64ctrl 1.31.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…u64 1.23, raw_c3 1.15, u64ctrl 1.33

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
JC-000 added a commit to JC-000/1541ultimate that referenced this pull request Nov 10, 2026
…dule identity raw_u64 1.24, raw_c3 1.16, u64ctrl 1.34

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@JC-000 JC-000 changed the title # ESP32 WiFi modules: drop the frame an RX FIFO overflow hits and skip to the next frame ESP32 WiFi modules: drop the frame an RX FIFO overflow hits and skip to the next frame Nov 10, 2026
@chrisgleissner

Copy link
Copy Markdown
Collaborator

@JC-000 thanks for this. #1077 is merged, and I re-reviewed this PR at head 7866cfb.

Code review. The overflow handling in my_uart.c is the same in all three modules. On the RX interrupt it reads the raw overflow status, resets the FIFO, empties the open frame and skips everything up to the next 0xC0. I found no defect. One wording point in the new comment above the overflow check (my_uart.c, all three modules): its last sentence ("Before, the cut frame went to the dispatcher ...") describes the earlier code. AGENTS.md asks code comments to describe the code as it stands, so please drop that sentence or move it to the commit message.

Host red/green at head.

Thresholds in the IDF 6 stack. The plan was to check whether that stack changes the margin this was tested under. #1028 keeps the UART thresholds (RX full 120, TX empty 10, flow control 122). #996 sets RX full and TX empty to 64. On the RX side, 64 leaves 64 bytes of FIFO headroom instead of 8. Overflows become rarer, and this handling still applies. The host cases inject bytes directly and do not model the threshold. The TX value is not applied in either tree, as #1079 says. In esp_driver_uart/src/uart.c (uart_intr_config, IDF 6 tree) the TX threshold is written only when UART_INTR_TXFIFO_EMPTY is in the enable mask, and it is not.

Hardware. Your hardware rows ran bench build 7b15448a7, which none of the PR heads contain. I want to repeat the forced overflow red/green on master + this PR on the Ultimate 64 Elite (raw_u64, flashed) and the U2+L (raw_c3, CI build). Could you share the bench change that turns module RTS flow control off for the hold, as a patch or a branch? I will apply it to both the red and the green build and not add it here. Our C64 Ultimate is not available for module flashing, so the u64ctrl leg will rest on your runs and on the shared code. I will say so in the final review.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@chrisgleissner

chrisgleissner commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

@JC-000 thanks for dropping the sentence in 49074a0.

To save you some time, I'm happy to help with the hardware side. I'll write the small bench-only change that turns module RTS off for the hold and run the overflow red/green on our devices. I'll post the patch and the results here, and none of it will be added to this PR. Our C64 Ultimate can now take module builds after all, so the u64ctrl leg can run there as well as on the Ultimate 64 Elite and the U2+L.

I'll do the same on #1079 and #1071. I'm also glad to take care of the module version renumbering on #1080 and #1042 once #1078 and #1079 are in. If you already have any of this underway, just say so and I'll use yours.

@JC-000

JC-000 commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. We have this underway: one bench-only hold command for both #1071 and #1078 (an optional RTS-off flag for the forced overflow, plus an end-of-hold event that reports whether the RX FIFO overflowed), ported onto current master for raw_u64, u64ctrl and raw_c3. It applies cleanly to master, to this PR's head and to #1078's head, and it builds and passes host tests. It has not run on hardware yet; that happens on our Elite today. I'll post the branch link with the results afterwards. If you'd rather not wait, go ahead with your own.

Written with Claude Sonnet 5.5 and Claude Opus 5.5 in Claude Code.

@chrisgleissner

Copy link
Copy Markdown
Collaborator

@JC-000 thanks, that's great. I'll wait for your hold command and results rather than run my own; see my note on #1071. The module version renumbering on #1080 and #1042 is also yours. I only offered in case it helped. If you'd like the C64 Ultimate or U2+L leg run with your branch, I'm glad to do it.

@JC-000

JC-000 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

The hold branch is up: https://github.com/JC-000/1541ultimate/tree/45bb9428bea4778857bdff5b1c0650878dfa9aec/repro/module-hold (branch repro/module-hold, on 085aad7). It adds module command 0xB1 to raw_u64, u64ctrl and raw_c3, and UCI 03 E5 <ms u32 LE> on the host. Bit 31 of the argument turns module RTS off for the hold (for this PR), and an end-of-hold event 0x6E reports the RX FIFO fill, with bit 15 set when the overflow flag was raised. After fetching, cherry-pick 085aad730..FETCH_HEAD. It applies cleanly to current master, to #1071's head (b9cdfe2) and to this PR's head (49074a0). The three modules build, and the module version has to be bumped for the updater to take it; the README has a script for that. The driver is smoke_hold.py in the same folder and needs only the c64-test-harness.

What ran on our Ultimate 64 Elite, on our bench image plus this branch. That image still has the waiting TX code, so these are #1071's "before" numbers, under a steady 600 packets/s UDP stream to the WiFi address:

Hold Ethernet ping, longest gap Ping loss REST, slowest
none 108 ms 0 % 17 ms
3 × 3000 ms, RTS on 2899–2922 ms 64 % 2740–2910 ms
1500 ms, RTS on 1459–1474 ms 44–50 % 1376 ms
1500 ms, RTS off 105 ms 0 % 26–39 ms

Every hold answered 00,OK, and the module was alive afterwards. For this PR: our module already has the overflow handling, and we did not capture the 0x6E event (our syslog delivered nothing), so we have not confirmed on our side that the RTS-off hold overflowed the FIFO. On the console, look for Ev 6E … Seq: with bit 15 (0x8000) set. If the overflow does not happen, a longer hold or a heavier stream should cause it. The README has the details. The driver as committed is a cleaned-up copy of the one that ran and has not itself run on a device.

Written with Claude Sonnet 5.5 and Claude Opus 5.5 in Claude Code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Existing behavior is incorrect, broken, or regressed; includes supported documentation defects. network Networking and remote services: REST, Socket DMA, FTP, Telnet, and online access.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WiFi module UART: an RX FIFO overflow splices frames into junk commands, and queued replies go out one per received frame

2 participants