Skip to content

RP UART0 loses every '1' bit at 400 kHz: the chosen UART geometry puts T1H 30 ns outside the decoder's own window #4379

Closed

Description

@zackees

UART0 is the only clockless driver on the RP2350 that can carry a 400 kHz chipset — 800 kHz needs a baud the PL011 cannot reach (#4375) — and it fails the loopback at every length, while PIO0 passes on the same wire, same pins, same timing.

Measured

RP2350W 2DCB876B587EA334, GPIO0 → GPIO1, WS2811-400KHZ, MSB_LSB_A:

UART0 leds=40 passed=False 0/4 captured=119  expected=120  mismatchedBytes=120
UART0 leds=10 passed=False 0/4 captured=29   expected=30   mismatchedBytes=30
PIO0  leds=40 passed=True  4/4

The engine runs: attempted=True started=True baud=2000000 encodedBytes=480 err=''. It is not a decline and not a capacity failure.

The wire

First edges of the captured frame (the pattern's first byte is 0xF0 → 1 1 1 1 0 0 0 0):

H950 L1500  H1000 L1500  H1000 L1500  H1000 L1500   <- the four '1' bits
H500 L2000  H500 L2000   H500 L2000   H500 L2000    <- the four '0' bits

The period is right (2500 ns) and the '0' bits are exact. The '1' bits are ~1000 ns where the chipset specifies 1200 ns.

Why the decoder rejects them

capture() builds its decode windows with make4PhaseTiming(tx_timing, 170), which is value ± tolerance:

t1h window = 1200 ± 170 = [1030, 1370]

1000 ns misses the bottom of that window by 30 ns. Every 1 in the frame is unclassifiable, which is why 100% of bytes mismatch rather than a few.

Where the 1000 ns comes from

buildWave10LutForMaxBaud() evaluates both frame geometries and picks the smaller total quantization error, with a 50 ns hysteresis favouring P=5. Verified against fl::uartWireTiming() on the host:

geometry baud pulse T0H T1H in window?
P=5 (chosen) 2.0 M 500 ns 500 (exact) 1000 T1H no — 30 ns low
P=4 1.6 M 625 ns 625 (+125) 1250 (+50) both yes

P=5 totals 200 ns of error, P=4 totals 175 ns. P=4 is the better fit by 25 ns — inside the 50 ns hysteresis, so P=5 wins. And the geometry that wins is the one whose '1' symbol nothing downstream can classify.

Forcing P=4 by lowering the baud ceiling below 2.0 Mbaud gives 625/1250, both comfortably inside their windows. At the RP's real ceiling (clk_peri/16 = 3.0 Mbaud) P=5 is still selected.

Two defensible readings, and I am not picking between them

(a) The harness decodes UART output against nominal timing. capture() already reconstructs the quantized wire timing for every other quantizing driver — there is a whole uses_wave8 / uses_wave3 block computing actual_t0h/actual_t1h for SPI, PARLIO, I2S and LCD_CLOCKLESS — and UART falls through to the else branch that uses the nominal T1/T2/T3 unchanged. fl::uartWireTiming() is the production function that would close that gap, and it is already exported.

(b) The geometry choice optimises the wrong thing. Summed absolute error treats 125 ns spread over two symbols as worse than 200 ns concentrated in one, but only the concentrated one leaves a symbol outside tolerance. A max-error or in-tolerance criterion would pick P=4 here. This also has implications past the harness: whether a real WS2811 accepts a T1H 17% under spec is a datasheet question I cannot answer from a loopback.

(a) makes the test pass. (b) is about what goes on the wire. They are not alternatives — (a) without (b) means the harness starts accepting a waveform it currently rejects, which is only correct if the waveform is actually correct.

Reproducing

No rebuild needed — drive runSingleTest against flashed firmware:

{"driver": "UART0", "laneSizes": [10], "pattern": "MSB_LSB_A",
 "iterations": 1, "timing": "WS2811-400KHZ"}

{"driver": "PIO0", ...} with everything else identical passes, which isolates it to the UART TX path.

Host-side, without hardware:

const auto t = fl::makeTimingConfig<fl::TIMING_WS2811_400KHZ>();
fl::uartWireTiming(t, fl::kMaxUartBaudRate);  // T1=500,  T1+T2=1000
fl::uartWireTiming(t, 1800000u);              // T1=625,  T1+T2=1250

Found while verifying #4376. Related: #4375 (UART diagnostics), #3899 (RP2350 HIL matrix), #3572 (the P=4/P=5 geometry work).

🤖 Generated with Claude Code

https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51

Activity

  1. zackees commented on Sep 12, 2026

    @zackees
    MemberAuthor

    Resolved in #4381. I said I was not picking between the two readings — it turns out both were required, and the order matters.

    (b) alone is not enough, and it looks like a regression. Fixing the geometry first (P=5 → P=4, wire 500/1000 → 625/1250) made the capture go from 119 bytes to zero. The waveform was now correct and the harness rejected all of it, because capture() decodes UART output against a hardcoded T0H=250 / T1H=750 / T1L=500 — the ESP32-at-4-Mbps WS2812 shape — and the corrected wire falls outside every one of those windows. The broken wire had been scraping past them at the boundary (H500 against a [0, 500] window, H1000 against [500, 1000]), which is exactly why it decoded something and got all of it wrong.

    (a) alone would have been worse. It would have made the harness accept a T1H 200 ns below spec and report the driver as passing. The concern in the original writeup was right: (a) without (b) only makes the test green.

    So: the geometry criterion now prefers a fit whose worst single symbol stays inside a receiver tolerance rather than the smaller sum, and capture() derives the decode window from fl::uartWireTiming() the way it already does for wave8 and wave3.

    Two things worth recording beyond the fix.

    The audit came out narrower than expected. Across all 37 chipset timings in led_timing.h, WS2811_400KHZ is the only selection that moves. I had assumed a max-error criterion would be too blunt — and a naive one is: it also flips WS2812_800KHZ (125 → 62 ns) and GW6205_800KHZ (160 → 100 ns), both improvements but not changes to make as a side effect on the most-used chipset in the library. Measuring the worst symbol pre-bump, so the deliberate #3569/#3572 separation widening is not charged as rounding error, narrows it to one.

    The encoder's own bound was never tight enough to catch this. fitUartWave() admits half a pulse width, which at a 2500 ns period is 250 ns — wider than the ±170 the harness decodes with and wider than the ~±150 the part specifies. A geometry emitting a symbol nothing accepts was always admissible; the summed-error tiebreak just happened to be what selected it here.

    Result on hardware — RP2350W 2DCB876B587EA334, UART0, GPIO0 → GPIO1, 3/3 per row, byte-exact at every length up to the #4371 capture ceiling:

    leds=1 2 5 10 20 40 60 63  ->  4/4 everywhere, baud 1600000
    

    All of them were 0/4 before. First time the RP UART clockless loopback has passed byte-exact — a data point for #3899's driver matrix.

  2. moved this from Triage to Done in FastLED Trackeron Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions