Skip to content

RP UART diagnostics are stale when the engine declines a channel: show() returns before resetting them #4375

Closed

Description

@zackees

runSingleTest reports rpUartStartAttempted, rpUartStartSucceeded, rpUartEncodedSize, rpUartActualBaud and rpUartLastError from the previous UART run whenever the engine declines the current channel. The values look like a report on the test just run; they are not.

Cause

channel_engine_rp_uart.cpp.hpp:73

void ChannelEngineRpUart::show() FL_NO_EXCEPT {
    if (mActive || mPendingChannels.empty()) {
        return;                       // <-- early return
    }
    ...
    mLastStartAttempted = false;      // <-- resets live below it
    mLastStartSucceeded = false;
    mLastEncodedSize = 0;
    mLastActualBaud = 0;
    mLastError.clear();

enqueue() only pushes a channel when canHandle() accepts it. When canHandle() rejects — wrong pin for the instance, timing needing a baud above the backend maximum — nothing is queued, mPendingChannels is empty, and show() returns at the guard without ever reaching the reset. The previous run's values are then what the harness reports.

Observed

Driving runSingleTest directly on an RP2350W. WS2812B-V5 has a 1225 ns period, so at P=5 it needs ~4.08 MHz — above the backend maximum, which is why it is documented to decline:

UART0  WS2812B-V5   attempted=True  baud=2000000  err=''

2000000 baud is arithmetically impossible for a 1225 ns period. It is the WS2811-400KHZ value (5 / 2500 ns), left over from an earlier call in the same device session. A fresh flash reports the truth:

RP UART: attempted=False started=False encodedBytes=0 actualBaud=0
         lastError='RP UART: chipset timing needs a baud above the UART backend maximum'

Same driver, same timing, opposite report — the difference is only what ran before it.

UART1 shows the other half of the same defect. It declines consistently, and because mLastError is never set on this path and never cleared, the reason is blank:

UART1  WS2811-400KHZ  attempted=False  baud=0  err=''
UART1  WS2812B-V5     attempted=False  baud=0  err=''

A caller cannot distinguish "the engine declined and said why" from "the engine declined silently" from "these numbers describe a different test".

Why this matters

It is a diagnostic that reports confidently about a run that did not happen. It cost me several wrong readings today: I recorded UART1 as failing in a way I could not explain, and separately reported "a decline path that reports nothing" on #3899 without being able to locate it — this is that path. Anyone comparing UART configurations by varying one parameter at a time will get results contaminated by the previous iteration.

Suggested direction

Reset the diagnostics before the mPendingChannels.empty() guard rather than after it, so a declined channel reports zeros rather than history. Separately, the first canHandle() guard returns false without setting mLastError:

if (!data || !data->isClockless() || !isValidTxPin(data->getPin())) {
    return false;                     // no mLastError set
}

The three guards below it all set a message; this one does not, which is why a decline for an unsupported TX pin is indistinguishable from no decline at all.

Reproducing

No rebuild needed. Against flashed firmware, call runSingleTest with driver: "UART0", timing: "WS2811-400KHZ" (succeeds), then the same with timing: "WS2812B-V5" (must decline) and observe the 400 kHz baud reported back.

Environment: RP2350W 2DCB876B587EA334, master. Related: #3899.

Activity

  1. zackees commented on Sep 11, 2026

    @zackees
    MemberAuthor

    Fixed in #4376, verified on hardware.

    One correction to this issue's framing. The report describes the WS2812B-V5 -> baud=2000000 observation as the symptom, which is right — but while fixing it I briefly wrote it up on the PR as evidence of a second defect in how per-call timing reaches the engine. That was wrong and is withdrawn. 2000000 is simply the inherited WS2811-400KHZ figure; a freshly flashed board reports attempted=False baud=0 on its first call, which is what identified the number as stale rather than computed. There is no known timing-propagation bug.

    Also worth recording for anyone reading the fix: the obvious clearing sites are both wrong, and I tried one of them first.

    • Before show()'s guard — show() runs every frame, so it would wipe a successful run's diagnostics before the caller read them. Trades a stale report for an empty one.
    • In enqueue()'s decline path — my first attempt. Hardware showed it only fixes half the cases: canHandle() is also called during driver selection with no enqueue() following, and that is the path that leaves the stale numbers visible. The giveaway was the error message updating correctly while attempted/baud did not, which proves canHandle() ran and enqueue() did not.

    The clearing belongs in canHandle(), where a decline is decided regardless of who asked.

  2. zackees commented on Sep 12, 2026

    @zackees
    MemberAuthor

    Fixed by #4376, merged as 1987a5782a. The PR body did not carry a closing keyword, so closing by hand.

    What landed, and where the clearing ended up. show() resets the diagnostics below its mActive || mPendingChannels.empty() guard — and an empty pending queue is exactly what a decline produces, so the reset was unreachable on the path that needed it. Moving it above that guard would have been worse: show() runs every frame, so it would wipe a successful run's numbers before the caller read them.

    The clearing is in canHandle() instead, which is the call that actually evaluates the channel:

    mLastStartAttempted = false;
    mLastStartSucceeded = false;
    mLastEncodedSize = 0;
    mLastActualBaud = 0;

    Three corrections went into getting that right, each found by running it rather than reading it:

    1. Clearing in enqueue()'s decline path covered only half the cases — canHandle() is also reached during driver selection with no enqueue() following, which is the path that left attempted=True baud=2000000 visible on a channel the engine had just refused.
    2. enqueue() had if (channelData && canHandle(channelData)), and that short-circuit skipped canHandle() for a null channel — leaving the diagnostics stale in precisely the case the change exists to fix, and making canHandle()'s own null branch unreachable.
    3. mLastError is cleared before the successful return rather than with the numerics at the top, so a failed DMA start recorded by show() stays readable until poll() reports it.

    The decline also names its reason now. A refusal for a TX pin the instance cannot drive used to return a bare false, indistinguishable from the engine never being consulted — attempted=false with an empty error either way.

    Verified on an RP2350W (2DCB876B587EA334, UART0, GPIO0 → GPIO1), alternating a declining and an accepting geometry on the same engine:

    WS2812B-V5     attempted=False started=False baud=0       encoded=0   err='RP UART: chipset timing needs a baud above the UART backend maximum'
    WS2811-400KHZ  attempted=True  started=True  baud=2000000 encoded=480 err=''
    WS2812B-V5     attempted=False started=False baud=0       encoded=0   err='RP UART: chipset timing needs a baud above the UART backend maximum'
    WS2811-400KHZ  attempted=True  started=True  baud=2000000 encoded=480 err=''
    

    Stable in both directions. Before the fix the declining rows inherited the accepting run's attempted=True baud=2000000.

    One residual, unrelated to this issue but visible in the same output: UART1 declines with an empty error on a build without this fix, and with the pin reason on one with it — so if you see a bare decline on the RP UART, check whether you are on a build predating 1987a5782a.

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