Skip to content

feat(autoresearch): add a 400 kHz chipset so UART is reachable on RP - #4224

Merged
zackees merged 1 commit into
masterfrom
feat/uart-slow-chipset-coverage
Sep 8, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/uart-slow-chipset-coverage

Conversation

@zackees

@zackees zackees commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

The UART backend on RP was never actually exercised

bash autoresearch rp2350w --uart fails with:

TEST UART0 lanes=1 leds=100 FAIL 2017ms class=zero_capture
RP UART: attempted=False started=False encodedBytes=0 actualBaud=0
lastError='RP UART: chipset timing needs a baud above the UART backend maximum'

attempted=False — it declined before transmitting. Not wiring (pin discovery correctly applies txPin: 0, and GPIO0 is a valid UART0 TX pin), and not a regression (A/B'd against #4218, which rewrote this teardown: identical failure with it reverted).

The cause is arithmetic. canRepresentTimingForMaxBaud accepts a chipset if 5 or 4 pulses per LED bit fits, where baud = pulses × 1e9 / period_ns:

period 5 pulses 4 pulses
WS2812 @ 1250 ns 4.00 MBaud 3.20 MBaud
WS2811-400 @ 2500 ns 2.00 MBaud 1.60 MBaud

RpUartPeripheral::maxBaudRate() is min(clk_peri/16, 6.25 MBaud), and clk_peri/16 binds at 3.0 MBaud on this silicon (the constant's own comment records "achieved 3000000"). So every 800 kHz part is rejected — and every --chipset choice was 800 kHz (ws2812, ws2814, ws2818, and ucs7604, which is UCS7604-800KHZ).

The backend was not broken. It was never handed a chipset it could clock.

This PR

Adds --chipset ws2811-400, mapped to the existing TIMING_WS2811_400KHZ. First UART transmission on RP:

before   attempted=False started=False encodedBytes=0    actualBaud=0
after    attempted=True  started=True  encodedBytes=1200 actualBaud=2000000

1200 bytes is 100 LEDs × 3 × 4, and 2.0 MBaud is exactly 5 pulses/bit at 2500 ns.

Loopback still fails — and now we can see why

TEST UART0 lanes=1 leds=100 FAIL 827ms class=decode_mismatch
Raw sample: H1000 L1500  H1000 L1500  H500 L2000  H500 L2000 ...

Period is 2500 ns as intended, and the two symbols are 500 ns and 1000 ns. But WS2811-400 specifies T0H = 500 ns and T1H = 1200 ns ±150 ns (1050–1350). The encoded 1 lands at 1000 ns — 50 ns below the low edge of tolerance.

That is quantization, and it is avoidable:

geometry pulse width encoded T0H encoded T1H T1H in 1050–1350?
5 pulses/bit 500 ns 500 ns 1000 ns ✗
4 pulses/bit 625 ns 625 ns 1250 ns ✓

canRepresentTimingForMaxBaud evaluates fitUartWave(timing, 5, ...) || fitUartWave(timing, 4, ...) — it takes the first geometry that fits rather than the one that reproduces the datasheet timing most closely. For this chipset the coarser geometry is strictly better on both symbols.

I have not changed that selection here. It affects every platform using the UART backend, ESP32 included, and I can only test RP — so it belongs in its own change with someone able to check the ESP32 side. Filing this PR with the measurement so that decision has evidence behind it.

Scope note

--chipset ws2811-400 is additive; the default stays ws2812, and no existing invocation changes behaviour.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51

Summary by CodeRabbit

  • New Features
    • Added support for the WS2811 400 kHz chipset option in the autoresearch test runner.
    • Enabled 400 kHz WS2811 timing for compatible RP platforms using UART.
    • Added timing details to the chipset option’s help text.

The RP PL011 cannot drive any 800 kHz part over UART. maxBaudRate() is
clk_peri/16 = 3.0 MBaud on this silicon, while WS2812's 1250 ns period
needs >=3.2 MBaud even at the coarsest geometry the encoder will accept
(4 pulses/bit). Every --chipset choice was 800 kHz, so `--uart` on RP
could only ever report `attempted=False ... needs a baud above the UART
backend maximum` -- the backend looked broken when it was simply never
given a chipset it could clock.

Add WS2811-400KHZ (2500 ns), which needs 1.6-2.0 MBaud and fits. First
UART transmission on RP:

  before  attempted=False started=False encodedBytes=0    actualBaud=0
  after   attempted=True  started=True  encodedBytes=1200 actualBaud=2000000

Loopback still fails to decode, and the captured waveform says why --
see the PR. That is an encoder geometry issue, not a transport one, and
is now observable for the first time because the data actually reaches
the wire.

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

coderabbitai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 4b5eb771-5f1c-46c9-9503-c4fb29fd9041

📥 Commits

Reviewing files that changed from the base of the PR and between d984bc2 and df2c262.

📒 Files selected for processing (3)
  • ci/autoresearch/args.py
  • ci/autoresearch/phases.py
  • examples/AutoResearch/AutoResearchRemoteRunSingleTest.cpp

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The autoresearch runner now accepts ws2811-400. Configuration maps it to WS2811-400KHZ, and the remote test runner selects the matching 400 kHz timing configuration and encoder.

Changes

WS2811 400 kHz support

Layer / File(s) Summary
Configure and resolve 400 kHz timing
ci/autoresearch/args.py, ci/autoresearch/phases.py, examples/AutoResearch/AutoResearchRemoteRunSingleTest.cpp
The CLI accepts ws2811-400. Phase generation emits WS2811-400KHZ. The remote runner resolves TIMING_WS2811_400KHZ and its encoder.

Priority: ⬇️ Low — Defer the narrow autoresearch and remote-test support change because it only adds 400 kHz WS2811 timing for RP UART transmission and leaves the default chipset unchanged.

Estimated code review effort: 2 (Simple) | ~5 minutes

Merge Risk: 🟡 Moderate · up to df2c2

The new ws2811-400 option can transmit within RP UART baud limits, but its encoded T1H remains out of tolerance and loopback decoding fails. The default chipset is unaffected, though the new option should be corrected or explicitly accepted as nonfunctional before merge.

Sequence Diagram(s)

sequenceDiagram
  participant AutoresearchCLI
  participant AutoresearchPhases
  participant RemoteRunner
  AutoresearchCLI->>AutoresearchPhases: Select ws2811-400
  AutoresearchPhases->>RemoteRunner: Generate WS2811-400KHZ
  RemoteRunner->>RemoteRunner: Resolve 400 kHz timing and encoder
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a 400 kHz chipset option to make RP UART transmission reachable.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/uart-slow-chipset-coverage

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.

@zackees

zackees commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

Correcting a claim in this PR's description, and a follow-up measurement

The description is wrong about geometry selection. I wrote that canRepresentTimingForMaxBaud "takes the first geometry that fits rather than the one that reproduces the datasheet timing most closely". That is true of the admission check (fit(5) || fit(4)), but the thing that actually chooses the geometry is buildWave10LutForMaxBaud, and it already picks the smaller total quantization error:

constexpr u32 kHysteresisNs = 50;
if (fit4.total_err_ns + kHysteresisNs < fit5.total_err_ns) { P = 4; } else { P = 5; }

So the selection is best-fit, not first-fit. Apologies — that sentence should not have gone in.

What is actually happening

For WS2811-400 (T0H 500 ns, T1H 1200 ns, period 2500 ns):

geometry T0H encoded err T1H encoded err total
P=5 500 ns 0 1000 ns 200 200
P=4 625 ns 125 1250 ns 50 175

P=4 has the lower total error, but the 50 ns hysteresis favouring P=5 means 175 + 50 = 225 is not < 200, so P=5 is chosen.

The summed-error metric is what misleads here. What matters per symbol is whether it lands inside the chipset's tolerance band:

T0H (350–650) T1H (1050–1350)
P=5 500 ✓ 1000 ✗ out of spec
P=4 625 ✓ 1250 ✓

A 200 ns error that leaves a symbol out of spec is not equivalent to a 125 ns error that stays in spec, but total_err_ns scores them as comparable.

Measured, by neutralising the hysteresis locally

Setting kHysteresisNs = 0 selects P=4, and the wire confirms the arithmetic exactly:

P=5:  actualBaud=2000000   Raw: H1000 L1500 ... H500  L2000     <- T1H out of spec
P=4:  actualBaud=1600000   Raw: H1250 L1250 ... H600  L1900     <- both in spec

But the loopback still fails. In fact the capture gets worse:

P=5:  class=decode_mismatch   Captured bytes: 197/300
P=4:  class=decode_mismatch   Captured bytes:   0/300

So the encoder geometry is a genuine defect, and it is not the blocker. Putting both symbols in spec does not make UART loopback pass on RP — there is a further problem in the RX/decode path, and P=4 makes byte capture worse rather than better. I have no evidence for why, and am not going to guess.

The experiment is reverted; this PR remains just the additive --chipset ws2811-400, which is what made any of this observable.

Net position: UART loopback on RP is not achievable today. Two distinct problems are now measured rather than hypothesised — geometry selection scoring quantization error without regard to tolerance bands, and an RX/decode failure that persists with an in-spec waveform.

@zackees
zackees merged commit 5f9b689 into master Sep 8, 2026
32 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Sep 8, 2026
zackees added a commit that referenced this pull request Sep 9, 2026
…asses (#4228)

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.


Claude-Session: https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
@zackees
zackees deleted the feat/uart-slow-chipset-coverage branch November 5, 2026 05:52
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