Skip to content

fix(autoresearch): derive the UART decode timing — UART loopback now passes on RP - #4228

Merged
zackees merged 1 commit into
fix/uart-derive-decode-timingfrom
fix/3899-uart-decode-timing
Sep 9, 2026
Merged

zackees merged 1 commit into
fix/uart-derive-decode-timingfrom
fix/3899-uart-decode-timing

Conversation

@zackees

@zackees zackees commented Sep 9, 2026

Copy link
Copy Markdown
Member

Stacked on #4227, which adds the uartWireTiming() helper this uses.

Result

before   TEST UART0 lanes=1 leds=40 FAIL 533ms   40/40 LEDs wrong
after    TEST UART0 lanes=1 leds=40 PASS 527ms

Three consecutive passes on RP2350W 2DCB876B587EA334. PIO loopback unaffected (PASS 685ms).

This closes the UART clockless leg of #3899, which had been recorded as unreachable.

The change

The decoder hardcoded one chipset's quantised wire timing:

fl::ChipsetTiming uart_timing{250, 500, 500, 50, "UART_4Mbps"};

Those describe WS2812 at a nominal 1250 ns. At 400 kHz — the only rate an RP PL011 can clock (#4224) — they misclassify every symbol. It now derives them via uartWireTiming().

A defect I chased that did not exist

I had been reporting a residual "missing final byte": deriving the timing by hand for P=5 left 1/40 LEDs wrong and one byte short, and I attributed the remainder to a capture defect, then spent an iteration looking for it.

There was no such defect. My hand derivation omitted the minimum-symbol-separation bump that fitUartWave() applies (kMinSymbolSeparationNs = 400), so my decode windows were subtly wrong and clipped one LED. Calling the helper — which reproduces the encoder's rules exactly, bump included — decodes the frame completely.

The lesson is the one this change embodies: reimplementing the encoder's rounding at the decode site produces exactly the silent drift the encoder's comment warns about. I reproduced that bug by hand while investigating it.

On the baud ceiling

kMaxUartBaudRate is used rather than the backend's own ceiling, which is not portably reachable from the harness. The geometry depends on the ceiling only through a feasibility gate, so the two agree wherever UART transmits at all — a backend whose ceiling excluded P=5 while the default admitted it would disagree, and the comment records that.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51

…asses

The UART decoder hardcoded one chipset's quantised wire timing:

    fl::ChipsetTiming uart_timing{250, 500, 500, 50, "UART_4Mbps"};

Those values describe WS2812 at a nominal 1250 ns. At the 400 kHz rate
that is the only one an RP PL011 can clock (#4224), they misclassify
every symbol. Using uartWireTiming() to derive them from the chipset:

  before   TEST UART0 lanes=1 leds=40 FAIL 533ms  40/40 LEDs wrong
  after    TEST UART0 lanes=1 leds=40 PASS 527ms

Three consecutive passes; PIO loopback unaffected (PASS 685ms).

Worth recording that this closes the residual I had been calling a
"missing final byte". Deriving the timing by hand for P=5 left 1/40 LEDs
wrong, and I attributed the remainder to a capture defect. It was not
one -- my hand derivation omitted the minimum-symbol-separation bump
that fitUartWave() applies, so the decode windows were subtly wrong. The
helper reproduces the encoder's rules exactly and the frame decodes
completely. There was never a final-byte defect to chase.

kMaxUartBaudRate is used rather than the backend's own ceiling, which is
not portably reachable here; the geometry depends on the ceiling only
through a feasibility gate, so the two agree wherever UART transmits at
all. The comment records the case that would disagree.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51
@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 33cfb2fc-8942-48bd-bfc2-c126bcee0737

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Sep 9, 2026
zackees added a commit that referenced this pull request Sep 9, 2026
…adds

The bloat gate reports:

  esp32s3-bloat-regression: FAIL -- total_flash=342,407 B exceeds
  baseline=342,393 B by 14 B

That 14 B is this PR's helper, and the gate's own message asks for the
baseline to move in the same PR when the growth is intended.

It is intended, though worth being explicit that this PR alone adds a
function nothing calls yet: the caller lands in #4228, which is what
turns UART loopback on RP from 40/40 LEDs wrong into a pass. The helper
cannot be header-inlined to let the linker drop it -- it calls
fitUartWave(), which is internal to the encoder translation unit, and
sharing those rules is the entire point of the change.

14 B against a 342 KB image, in exchange for a decoder that classifies
against the waveform actually transmitted.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51
@zackees

zackees commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

Robustness checks on the newly-passing path

The original evidence was three single-frame runs at 40 LEDs, which is thin for a capability that had never worked. Two further checks on RP2350W 2DCB876B587EA334:

Multi-frame. Second-frame degradation is a known bug class here — it is why SPI defaults to two frames (#2254/#2288) — and UART had never run more than one:

$ bash autoresearch rp2350w --uart --chipset ws2811-400 --strip-sizes 40 --frames 4
TEST UART0 lanes=1 leds=40 PASS 2075ms

2075 ms against 527 ms for a single frame, so all four frames genuinely ran rather than the flag being ignored. No degradation across them.

Stability at the capacity boundary. 60 LEDs is the largest size that fits the RX pool; 80 overflows. That is where margin is thinnest, so it is the size most likely to be marginal rather than cleanly passing:

60LED run1 -> PASS 768ms
60LED run2 -> PASS 767ms
60LED run3 -> PASS 769ms

Three consecutive passes with a 2 ms spread. A capture sitting near its buffer limit would be expected to show variance or intermittent overflow; it shows neither.

Combined with the earlier three passes at 40 LEDs and the PIO regression check (PASS 685ms), that is nine passing runs across three sizes and two frame counts, with no failures.

zackees added a commit that referenced this pull request Sep 9, 2026
…uces (#4227)

* feat(channels): expose the wire timing the UART encoder actually produces

The UART encoder quantises T0H/T1H onto a grid of period/pulses_per_bit,
so what reaches the wire is not the chipset's nominal timing. Any
receiver decoding a UART-encoded frame has to classify against the
quantised values; AutoResearch currently hardcodes one chipset's worth
of them, which is why a 400 kHz frame decodes every symbol wrongly
(#3899).

uartWireTiming() derives them through the same fitUartWave() rules that
built the LUT, so decode windows cannot drift from the encoding -- the
alternative, recomputing the rounding at the decode site, is exactly the
drift the encoder's own comment warns against.

Correcting a claim I made on #3899 while working this out: I asserted
deriving would reproduce AutoResearch's hardcoded {250, 500, 500}
exactly for WS2812. It does not. WS2812B-V5 is T1=225 T2=355 T3=645, a
1225 ns period, and the derived wire timing is {245, 490, 490}. The
constants correspond to a nominal 1250 ns part. The deltas are 5 and
10 ns against a +/-250 ns classification tolerance, so no symbol can
change class -- but "well inside tolerance" is a weaker claim than
"identical", and I had asserted the stronger one from an assumed period
rather than the real values.

Tests assert the derived values exactly, the tolerance property that
makes substitution safe, and that an unreachable baud ceiling reports
infeasible rather than guessing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51

* chore(bloat): raise the ESP32-S3 baseline by the 14 B uartWireTiming adds

The bloat gate reports:

  esp32s3-bloat-regression: FAIL -- total_flash=342,407 B exceeds
  baseline=342,393 B by 14 B

That 14 B is this PR's helper, and the gate's own message asks for the
baseline to move in the same PR when the growth is intended.

It is intended, though worth being explicit that this PR alone adds a
function nothing calls yet: the caller lands in #4228, which is what
turns UART loopback on RP from 40/40 LEDs wrong into a pass. The helper
cannot be header-inlined to let the linker drop it -- it calls
fitUartWave(), which is internal to the encoder translation unit, and
sharing those rules is the entire point of the change.

14 B against a 342 KB image, in exchange for a decoder that classifies
against the waveform actually transmitted.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
@zackees
zackees merged commit 401fe07 into fix/uart-derive-decode-timing Sep 9, 2026
7 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Sep 9, 2026
@zackees
zackees deleted the fix/3899-uart-decode-timing branch November 17, 2026 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant