Skip to content

runSingleTest advertises a lane cap it cannot honour: max_leds_per_lane uses a fixed /32 divisor for a geometry-dependent limit #4371

Closed

Description

@zackees

runSingleTest bounds laneSizes with a constant that only holds for one chipset geometry. Above the real limit the guard passes the request through and capture fails silently — passed: false, bytes: 0, no error — which is the outcome the guard exists to prevent.

examples/AutoResearch/AutoResearchRemoteRunSingleTest.cpp:512

const int max_leds_per_lane = mState->rx_buffer.size() / 32;

rx_buffer is fl::span<uint8_t> of 3300 bytes, so the advertised cap is 3300 / 32 = 103.

Measured on an RP2350W (PIO0, GPIO0 -> GPIO1 bridge)

Every row reproduced 3/3:

geometry advertised cap actual usable above it
WS2812B-V5 (800 kHz) 103 100–102 silent failure
WS2811-400KHZ (400 kHz) 103 60–64 silent failure
WS2811-400KHZ leds= 60 passed=True  bytes=720
WS2811-400KHZ leds= 65 passed=False bytes=0     <- accepted by the guard, fails in capture
WS2812B-V5    leds=100 passed=True  bytes=1200
WS2812B-V5    leds=103 passed=False bytes=0     <- the advertised maximum itself
WS2812B-V5    leds=110 -> {"error": "LaneSizeTooLarge", "message": "... exceeds max 103"}

Two defects

1. The advertised maximum does not work, even at 800 kHz. 103 is accepted and then fails, 3/3. A caller who trusts the number the device reports gets silence rather than LaneSizeTooLarge — strictly the worse of the two failures, since the guard's whole purpose is to turn this into a clean error.

2. A fixed divisor cannot express this limit. Decoded LED data is 3 bytes per LED; 32 bytes per LED means the buffer holds raw capture samples, whose cost scales with how long the frame lasts. A 400 kHz frame is twice as long as an 800 kHz frame of the same LED count, so no single constant describes both. At 400 kHz the cap is ~70% too high, and everything from 65 to 103 LEDs is accepted and silently fails.

Why this matters beyond the constant

The silent band is wide enough to be mistaken for a different bug. The AutoResearch default is 100 LEDs, which sits deep inside the 400 kHz failure band — so --chipset ws2811-400 appears to fail on every driver, and I spent a while concluding the RX decoder could not handle 400 kHz at all. It handles it fine below the real ceiling. Anyone testing a slower chipset will hit the same false trail.

Direction

runSingleTest already receives the timing ("timing": "WS2811-400KHZ") and resolves it to t1_ns/t2_ns/t3_ns a few lines later for make4PhaseTiming, so the information for a geometry-aware bound is available at the same call site — the cap could scale with the bit period rather than being constant.

I am deliberately not proposing a number. Deriving the true bytes-per-LED needs the PIO_RX sample rate and whether it is fixed or tracks the bit period, which I could not establish black-box: no simple model fits both thresholds. Frame duration does not (3.09 ms fails while 3.60 ms passes), bit count does not (2400 bits pass while 1560 fail), and even inverse-proportionality does not — halving the bit rate moves the usable cap by 1.6x, not 2x. Whoever owns that capture path can size it properly; the table above pins what any correct answer has to reproduce.

The guard's shape is right — a bounds check returning a clear error. Only the bound is wrong, and changing the constant will not fix it.

Found while working #3899. Related: #3899 (RP2350 HIL matrix).

Activity

  1. zackees commented on Sep 11, 2026

    @zackees
    MemberAuthor

    Exact boundary at 800 kHz: usable max is 100, advertised is 103

    Narrowed the range from my original report. Driving runSingleTest directly (no rebuild, so this is cheap to reproduce):

    800kHz leds= 99 -> ['True', 'True']      2/2
    800kHz leds=100 -> ['True', 'True']      2/2
    800kHz leds=101 -> passed=False bytes=0
    800kHz leds=102 -> passed=False bytes=0
    800kHz leds=103 -> passed=False bytes=0   <- the advertised maximum
    

    So the guard admits three LED counts it cannot serve at 800 kHz, and each fails silently — passed: false, bytes: 0, no error — where 104 and above get a clean LaneSizeTooLarge.

    max_leds_per_lane = rx_buffer.size() / 32 = 3300/32 = 103. The divisor is off by roughly 3% for this geometry, and the error compounds for slower ones: at 400 kHz the usable maximum is between 60 and 64 against the same advertised 103.

    On deriving the correct divisor

    Two usable data points — 100 at a 1225 ns period, ~62 at 2500 ns — imply about 33 and 53 bytes per LED respectively. That is not proportional to the bit period (ratio 1.6 against 2.0), so a single constant cannot work and neither can a simple k / period. A two-parameter form (bytes_per_led = k * period + fixed) fits both, but two points fitting two parameters is arithmetic, not evidence.

    I looked for a third geometry to test it against. The other supported chipsets are clustered too tightly to discriminate — WS2818 1200 ns, WS2812B-V5 1225 ns, UCS7604 1250 ns, WS2814 1280 ns — and the predicted maxima differ by only a few LEDs across that span, which is inside what I could distinguish reliably. So I am not proposing a formula; it would be fitted, not derived.

    What the fix needs is the PIO_RX capture path's actual per-LED cost, which whoever owns that code can state directly rather than infer. The measurements here pin what any correct answer has to reproduce:

    geometry period usable max advertised
    WS2812B-V5 1225 ns 100 103
    WS2811-400KHZ 2500 ns 60–64 103
  2. zackees commented on Sep 11, 2026

    @zackees
    MemberAuthor

    Both boundaries now exact

    geometry period last passing first failing advertised cap
    WS2812B-V5 1225 ns 100 101 103
    WS2811-400KHZ 2500 ns 63 64 103

    Each boundary confirmed 2/2 on both sides. At 400 kHz the guard admits 40 LED counts it cannot serve (64 through 103), every one failing silently.

    Implied buffer cost against the 3300-byte rx_buffer: 33.0 bytes/LED at 1225 ns, 52.4 at 2500 ns. The ratio is 1.59 against a period ratio of 2.04, so it is neither constant nor proportional — consistent with a per-LED component plus a duration-dependent one.

    I am still not proposing a formula. Two exact points admit a two-parameter fit, but that is solving for the parameters, not testing the model, and the remaining supported chipsets (1200/1250/1280 ns) are clustered too tightly to discriminate a prediction. Worth noting neither implied figure maps cleanly to an obvious mechanism either: 33 bytes/LED is under one byte per signal edge (48 edges/LED), which rules out per-edge timestamps as the whole story.

    What is solid and actionable is the table: any correct bound must yield 100 at 1225 ns and 63 at 2500 ns.

  3. zackees commented on Sep 11, 2026

    @zackees
    MemberAuthor

    The ceiling is not period-dependent in the 800 kHz band — my two-parameter model is refuted

    I said a two-parameter fit (bytes_per_led = k * period + fixed) matched both known points but that I would not publish it without testing. Tested it, and it is wrong.

    The fit predicted WS2818 (1200 ns) -> 101 and WS2814 (1280 ns) -> 97. Measured, each boundary confirmed by the pass/fail transition:

    chipset period last passing first failing model predicted
    WS2818 1200 ns 100 101 101
    WS2812B-V5 1225 ns 100 101 100
    WS2814 1280 ns 100 101 97
    WS2811-400KHZ 2500 ns 63 64 63

    Three geometries spanning a 6.7% period range all cap at exactly 100. Period has no effect there, which no period-proportional model produces — WS2814 should have lost three LEDs and lost none. So the relationship is not smooth in the bit period; something changes between the 800 kHz band and 400 kHz rather than scaling with it.

    That is worth more than the fit would have been. Had I published the formula, it would have been right at the two periods I derived it from and wrong at a third.

    UCS7604 is a separate problem, not a data point

    I nearly used its failure at 98 LEDs as a fourth point. It is not a ceiling:

    UCS7604 leds=48 passed=False bytes=576
    UCS7604 leds=50 passed=False bytes=600
    UCS7604 leds=60 passed=False bytes=720
    UCS7604 leds=75 passed=False bytes=900
    UCS7604 leds=90 passed=False bytes=1080
    

    It fails at every size tested, including sizes far below any ceiling, and with non-zero captured bytes (12/LED) rather than the bytes: 0 the capacity failure produces. So capture is working and the comparison is failing — a different fault, plausibly its 16-bit encoding. --chipset ucs7604 appears unusable on this path at any length, which is worth its own look and is not what this issue is about.

    Constraint for any fix

    Any correct bound must yield 100 at 1200, 1225 and 1280 ns, and 63 at 2500 ns. A constant divisor cannot (it gives 103 everywhere); neither can anything proportional to the period.

  4. zackees commented on Sep 11, 2026

    @zackees
    MemberAuthor

    The bound is a property of the shared capture path, not the TX driver

    Ran the same boundaries on the other two PIO instances:

    driver WS2811-400KHZ WS2812B-V5
    PIO0 63 pass / 64 fail 100 pass / 101 fail
    PIO1 63 pass / 64 fail 100 pass / 101 fail
    PIO2 63 pass / 64 fail 100 pass / 101 fail

    Identical to the LED, with the same bytes: 0 failure shape above each boundary. So the limit is not per-PIO-instance — it belongs to the shared RX capture path and rx_buffer, which is consistent with max_leds_per_lane being computed from mState->rx_buffer.size().

    Practical consequence for a fix: the bound should be corrected once in the capture path rather than per driver, and any correction is testable against all three instances at no extra cost.

    Consolidated constraint, all boundaries confirmed by their pass/fail transition:

    geometry period usable max advertised
    WS2818 1200 ns 100 103
    WS2812B-V5 1225 ns 100 103
    WS2814 1280 ns 100 103
    WS2811-400KHZ 2500 ns 63 103

    (UCS7604 is excluded deliberately — it fails at every length for an unrelated reason, filed as #4373.)

  5. zackees commented on Sep 11, 2026

    @zackees
    MemberAuthor

    I said I would not propose a number because no simple model fit both thresholds. With a third geometry the model turns out to be exact for the 800 kHz class, and it is one the code already contains.

    The bound is the PIO edge pool, and it is written down

    src/platforms/arm/rp/rpcommon/rx_pio_channel.h:16

    constexpr size_t kRpPioRxEdgeCapacity = 100u * 3u * 16u + 1u;   // 4801

    That is 100 LEDs x 3 bytes/LED x 16 phases/byte. The ceiling is not on LEDs — it is on wire bytes, and the usable maximum is kRpPioRxEdgeCapacity / 16 = 300 bytes.

    The guard's rx_buffer.size() / 32 divides an unrelated buffer: rx_buffer is the 3300-byte decode output, and 32 has no connection to the capture pool. 3300 / 32 = 103 only looks plausible because it lands near 100 by coincidence.

    Measured, 3/3 per row (RP2350W 2DCB876B587EA334, PIO0, GPIO0 -> GPIO1)

    timing LEDs wire bytes bytes x 16 <= 4801 result
    WS2812B-V5 99 297 4752 yes pass
    WS2812B-V5 100 300 4800 yes pass
    WS2812B-V5 101 303 4848 no fail
    WS2812B-V5 103 309 4944 no fail
    UCS7604-800KHZ 46 291 4656 yes pass
    UCS7604-800KHZ 47 297 4752 yes pass
    UCS7604-800KHZ 48 303 4848 no fail
    UCS7604-800KHZ 50 315 5040 no fail

    Two geometries with nothing in common at the LED level — 100 LEDs versus 47 — break at exactly the same wire size, 303 bytes, the first value whose 16-phases-per-byte cost exceeds 4801. The prediction is not approximate: on both sides of the boundary it is right to the LED.

    (UCS7604 wire bytes are 15 + 6*leds: a 15-byte preamble and 16-bit channels. Its numbers come from testing #4373, which had to be fixed first — before that the encoder never reached the transmitter, so every UCS7604 run put raw 3-byte pixels on the wire and this geometry did not exist to measure.)

    So the cap is expressible, and it has to be encoder-aware: at 800 kHz a UCS7604 channel tops out at 47 LEDs where WS2812 tops out at 100. A guard phrased in LEDs cannot be right for both; one phrased in wire bytes is right for both.

    The 400 kHz ceiling is a different mechanism

    400 kHz still does not fit, but the shape is now much sharper than "no model fits":

    timing LEDs wire bytes bytes x 16 <= 4801 result
    WS2811-400KHZ 63 189 3024 yes pass 3/3
    WS2811-400KHZ 64 192 3072 yes fail 3/3
    WS2811-400KHZ 65 195 3120 yes fail 3/3

    It breaks at 192 bytes — 36% under the pool. And the DMA is not the constraint: rpPioWordCount reads exactly 8 * wire_bytes in every row above, passing and failing alike, including 1536 words for the failing 400 kHz case against a 4801-word pool. One word per bit, no run splitting, nothing lost in capture. Whatever rejects the 400 kHz frame does so after the words are in memory.

    That kills the hypothesis in capture()'s own comment — "a 400 kHz capture overflows and is discarded ... because long runs do not always land in one entry". The long runs do land in one entry. Something downstream of the word count draws a line at 190-192 wire bytes.

    Where that leaves the two defects

    Defect 1 (the advertised maximum does not work) is explained: 103 is accepted and 4801/16 = 300 bytes = 100 LEDs is the truth, so 101, 102 and 103 all sit in the silent band. All three fail 3/3.

    Defect 2 (a fixed divisor cannot express the limit) holds, and the correct form is now concrete for everything except 400 kHz:

    wire_bytes(encoder, leds) * 16 <= kRpPioRxEdgeCapacity
    

    The 400 kHz bound is lower and independent; a guard built only on the expression above would still accept the 64-LED case that fails 3/3. That part remains open, and my measurements point away from capture capacity as the cause.

  6. zackees commented on Sep 11, 2026

    @zackees
    MemberAuthor

    Correction and completion of my previous comment.

    The correction first. I wrote that "the DMA is not the constraint" because rpPioWordCount reads exactly 8 * wire_bytes in every row. rpPioWordCount is not the RX DMA — it comes from fl::BusTraits<fl::Bus::FLEX_IO, N>::instance().lastWordCount() (channel_engine_rp_pio.h:35), the transmitter. Eight words per byte is one TX word per bit, which is why it tracked byte count so cleanly and said nothing about capture. Everything I inferred from it about the 400 kHz case was unfounded. The edge-pool result in that comment is unaffected — it rests on the pass/fail boundaries, not on that number.

    With that removed, the 400 kHz ceiling has a clean explanation, and there are exactly two constraints. Each is the binding one in its own regime, which is why no single model fit.

    Constraint 1 — the edge pool (bounds the fast chipsets)

    As before: wire_bytes * 16 <= kRpPioRxEdgeCapacity (4801), i.e. 300 wire bytes. Two phases per bit, eight bits per byte. Confirmed to the LED on WS2812B-V5 (300 B pass / 303 B fail) and UCS7604 (297 B pass / 303 B fail).

    Constraint 2 — the DMA sample-time budget (bounds the slow chipsets)

    rx_pio_channel.cpp.hpp samples the pin into 32 samples per DMA word at a fixed clock:

    constexpr u32 kPioRxClockHz       = 20000000u;   // 50 ns per sample
    constexpr size_t kPioRxDmaTailWords = 64u;
    ...
    mDmaWordCount = (mCapacity + 1u) / 2u + kPioRxDmaTailWords;

    Any frame of 151 bytes or more clamps mCapacity to 4801, so mDmaWordCount is a constant 2465 words. That is a fixed quantity of wall-clock time, not of data:

    2465 words x 32 samples x 50 ns = 3.944 ms of capture
    

    The capture must also observe signal_range_max_ns (100 µs, the RxChannelConfig default, never overridden in capture()) of trailing idle before finishTailIfIdle() will terminate it, leaving ~3.84 ms for the frame itself. Measured boundary:

    timing LEDs frame duration result
    WS2811-400KHZ 63 3.780 ms pass 3/3
    WS2811-400KHZ 64 3.840 ms fail 3/3

    The break sits exactly on the budget.

    The two constraints are separable, and I measured them apart

    Same wire size, same edge count, two bit periods:

    timing LEDs wire edges frame result
    WS2812B-V5 64 192 B 3072 1.882 ms pass 3/3
    WS2811-400KHZ 64 192 B 3072 3.840 ms fail 3/3

    192 bytes and 3072 edges either way. Only the duration differs, and only one of them fails. Constraint 2 is about time; constraint 1 is about size. Neither alone predicts both chipsets, and together they predict every boundary in this issue and in the driver-sweep comment above.

    Why each is invisible in the other's regime: at 800 kHz the 300-byte pool ceiling caps the frame at 2.94 ms, so the 3.84 ms budget is never approached. At 400 kHz the 3.84 ms budget caps the frame at 192 bytes, so the 4801-edge pool is never approached. The two ceilings cross somewhere around a 1.6 µs bit period, which is why 800 kHz-class parts all report 100 and the single 400 kHz part reports 63.

    What a correct guard looks like

    wire_bytes(encoder, leds) * 16                  <= kRpPioRxEdgeCapacity
    wire_bytes(encoder, leds) * 8 * bit_period_ns   <= mDmaWordCount * 32 * (1e9 / kPioRxClockHz)
                                                       - signal_range_max_ns
    

    Both inputs are available at the runSingleTest call site: the encoder is resolved a few lines below the guard (that is what #4373 was about), and t1_ns + t2_ns + t3_ns is the bit period it already computes for make4PhaseTiming. Defect 1 and defect 2 both fall out of taking the smaller of the two.

    Worth noting what this does to the advertised number for a 4-lane UCS7604 request: 47 LEDs, not 103.

    All rows RP2350W 2DCB876B587EA334, PIO0, GPIO0 -> GPIO1, 3/3 each.

  7. 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