Skip to content

ESP32-S3: I2S driver starves websockets, SPI output incorrect, Audio driver FPS impact #2254

Closed

Description

@zackees

Summary

Hoisted from #2167 (comment) by @ewowi to track remaining driver issues separately from the Channels API discussion.

Testing on ESP32-S3 with latest master reveals three distinct issues across the LED drivers when used via the Channels API:

Issue 1: I2S driver starves websockets (~1 FPS)

Status: Regression — this was previously fixed (delayMicroseconds busy-wait fix, Mar 9) but has resurfaced.

  • When using I2S as the channel driver, websocket throughput drops to ~1 FPS
  • LEDs show the correct output — the rendering itself is fine
  • The I2S driver appears to be monopolizing the RTOS task, starving the network task layer
  • This affects boards smaller than ESP32-P4 (tested on ESP32-S3, previously also on ESP32-D0)
  • RMT does not exhibit this problem

Root cause hypothesis (from @zackees): The network stack has two layers — ISR layer and task layer. The task layer is what's getting starved. A vTaskDelay(1) or delay(1) between frames in the main loop may alleviate it, suggesting the I2S driver needs cooperative yield points.

Issue 2: SPI driver — incorrect LED output

Status: Partially fixed in #2251 (buffer growth on channel reuse), but still not rendering correctly.

This is a separate rendering bug from the buffer issue fixed in #2251.

Issue 3: FastLED Audio driver reduces FPS (100 → 60)

Status: Ongoing side-effect.

  • With the FastLED Audio driver active, FPS drops from ~100 to ~60
  • @ewowi asks: is the audio driver running on the same RTOS task as the LED driver code? If so, the slowdown is expected, and running audio on a separate task would resolve it.

Driver behavior matrix (ESP32-S3, latest master)

Driver Websocket speed LED output Notes
RMT Normal Correct Works as expected
SPI Normal Incorrect Rendering bug persists after #2251
I2S ~1 FPS Correct Task starvation regression

Environment

  • Board: ESP32-S3
  • Project: MoonLight using FastLED Channels API
  • FastLED: latest master as of 2026-04-11

Related


@ewowi — continuing the conversation from #2167 here to keep things organized. Thanks for the detailed testing breakdown!

Activity

  1. added
    platform: esp32
    area: drivers
    status: triage
    on Apr 16, 2026
  2. zackees commented on Apr 18, 2026

    @zackees
    MemberAuthor

    Progress update — picking this up (step 0: plan)

    Kicking off work focused on Issue 2: SPI driver — incorrect LED output on ESP32-S3.

    Filed sibling issue #2288 with a concrete plan: the current autoresearch pipeline only captures a single FastLED.show() per test case, so the reported "black frame between displays" symptom (frame #1 correct, frame #2 zeroed/corrupted, cycle repeats) is invisible to the test matrix today. See #2288 for the full problem write-up and implementation sketch.

    Plan being executed now (will comment again at each step):

    1. Read current capture pipeline (AutoResearchTest.cpp::capture() + AutoResearchRemote.cpp RPC handlers) — in progress.
    2. Extend firmware capture() to accept frameCount and arm RX once, then do N back-to-back FastLED.show() calls, decoding N frames from the edge stream.
    3. Accept frameCount / frameComparison on runSingleTest JSON-RPC; return per-frame pass/fail with a named failureClass.
    4. Make bash autoresearch --spi on esp32s3 default to frameCount=2 so the regression is caught automatically.
    5. Run bash autoresearch --spi on the attached ESP32-S3 and confirm the second-frame bug now shows up as a hard FAIL.

    Board attached right now: ESP32-S3.

  3. zackees commented on Apr 18, 2026

    @zackees
    MemberAuthor

    Progress update — step 1/2: firmware + CLI wired for multi-frame capture

    What's done (not yet running on hardware):

    Firmware (examples/AutoResearch/):

    • AutoResearchTest.h / .cpp — autoResearchChipsetTiming() and autoResearchChipsetTimingLegacy() gain an int num_runs_per_pattern = 1 parameter. Threaded into MultiRunConfig::num_runs, which was previously hardcoded to 1. When > 1, print_all_runs also flips on so per-frame pass/fail shows up in the serial log.
    • AutoResearchRemote.cpp — runSingleTest RPC handler accepts an optional frameCount (int, validated to [1, 16]). Passed through to the chipset-timing functions. Response now also carries frameCount and per-pattern entries include runNumber so frame-1 vs frame-2 failures are distinguishable in JSON.

    Python (ci/autoresearch/):

    • args.py — new --frames N CLI flag.
    • phases.py — when building runSingleTest commands, defaults frameCount = 2 for --spi, 1 for everything else; --frames N overrides.
    • context.py::display_pattern_details — shows frames=N in the header and [frame N] suffix per pattern failure.

    Detection strategy (minimal, targeted): Each pattern applies the same LED buffer then issues frameCount consecutive FastLED.show() / capture cycles (RX is re-armed per cycle; TX driver state is untouched). That's exactly the user loop that reproduces the "black frame between displays" in #2254 — if the SPI driver corrupts its DMA buffer after the first show, frame 2 fails and the whole test fails.

    Acceptance criterion I'm about to verify on the attached ESP32-S3:
    bash autoresearch --spi must produce a hard FAIL with frame 2 showing all-zero (or garbage) LED values on at least one pattern. Running now — will post results in the next comment.

  4. zackees commented on Apr 18, 2026

    @zackees
    MemberAuthor

    Progress update — step 2/2: ran on ESP32-S3, multi-frame works, bug did NOT reproduce

    Feature shipped: --frames N landed in #2293 (merged to master), default frameCount=2 for --spi. bash autoresearch --spi --skip-lint --skip-schema --no-fbuild compiles, flashes, and exercises the new path on the attached ESP32-S3.

    Confirmed plumbing works. The serial trace shows the RPC going out with the right payload and the firmware obeying:

    RPC: {"method":"runSingleTest","params":[{"driver":"SPI","laneSizes":[100],
          "pattern":"MSB_LSB_A","iterations":1,"timing":"WS2812B-V5","frameCount":2}]}
    
    [Run 1/2] Testing... → [CAPTURE] SPI TX -> RMT RX ... Decoded 300 bytes
    [Run 1/2] PASS | Errors: 0/100 (100.0%)
    [Run 2/2] Testing... → [CAPTURE] SPI TX -> RMT RX ... Decoded 300 bytes
    [Run 2/2] PASS | Errors: 0/100 (100.0%)
    [OVERALL] PASS ✓ - All 2 runs succeeded
    

    All 4 bit patterns × 2 frames = 8 captures, 8 PASS on the attached S3 with 100-LED APA102-style strip in loopback. AUTORESEARCH SUCCEEDED.

    What this means

    The tool change did its job — we now have a regression gate for two-frame degradation. But the specific second-frame bug described in this issue ("black frame between displays") did not reproduce in the minimal autoresearch harness on my board. That is interesting and narrows the hypothesis space:

    • The bug likely depends on something this harness doesn't reproduce yet. Candidates:
      1. Larger strips. I tested 100 LEDs; @ewowi's MoonLight setup likely uses 300+.
      2. Multi-lane SPI via the Channels API. The harness was lane=1 here.
      3. Concurrent RTOS load (websockets, Audio task) — the bug may only surface when another task preempts between show() calls.
      4. Timing between frames — my harness calls show() back-to-back with the RX re-arm in between; a tighter or looser cadence could matter.
      5. Driver variant. --spi here binds to the channel-API SPI driver. ESP32-S3: I2S driver starves websockets, SPI output incorrect, Audio driver FPS impact #2254 mentions the Channels API SPI path specifically — want to double-check this is the same SPI driver name the device enumerates.

    Next investigation steps I'd suggest (not yet done)

    • Sweep --spi --strip-sizes 300,1000,3000 --frames 2 to see if size triggers it.
    • Try --spi --lanes 2 --frames 2 and --spi --lanes 4 --frames 2.
    • Add a "bg-task stress" mode that spawns a long-lived RTOS task so the second show() happens under contention (could be worth a follow-up issue).
    • Coordinate with @ewowi to capture their exact autoresearch invocation or a minimal repro sketch from MoonLight so we can mirror the environment.

    Action for #2254: Issue 2 (SPI incorrect output) remains open — the tool is now capable of detecting it, but on this board + configuration it is passing. Happy to run any specific sweep you'd like me to try next.

  5. zackees commented on Apr 18, 2026

    @zackees
    MemberAuthor

    Progress update — 550-LED run surfaced a harness false-positive

    Tried bash autoresearch --spi --strip-sizes 550 on the ESP32-S3. Device reports PASS, but the pass is not trustworthy:

    RPC: {"driver":"SPI","laneSizes":[550],...,"frameCount":2}
    [RUN 1] Driver=SPI, bytes_captured=512       ← only 512 of 1650 expected
    [Run 1/2] PASS | Errors: 0/550 (100.0%)
    [RUN 2] Driver=SPI, bytes_captured=512
    [Run 2/2] PASS | Errors: 0/550 (100.0%)
    
    Strip Captured Expected Coverage
    100 300 300 100%
    550 512 1650 31%

    Two distinct harness bugs, independent of #2254

    1. RX capture cap at ~512 bytes on the plain SPI driver path (esp32s3 with RX_BUFFER_SIZE = 96,100, so the host buffer is not the limit — this is almost certainly an RMT RX symbol-buffer limit in rx_channel->wait() / decode() for long clockless waveforms).
    2. Silent truncation in the comparator. examples/AutoResearch/AutoResearchTest.cpp:840-844 breaks the per-LED loop when byte_offset + 2 >= bytes_captured, and the remaining LEDs are quietly ignored rather than counted as mismatches. So for 550 LEDs the harness checks only the first ~170 and reports "Errors: 0/550".

    This is a silent false-positive — any second-frame degradation happening past byte ~512 is invisible to the sweep today. That directly affects this issue: if the SPI black-frame bug kicks in past the first chunk (plausible for a DMA corruption after the initial descriptors drain), the current harness would not flag it.

    Proposed fix (happy to PR if you greenlight)

    • In the comparator: when bytes_captured < num_leds * 3, count (num_leds - verified_leds) as mismatches and emit [TRUNCATED CAPTURE] verified X of Y LEDs in the log. Do NOT silently break to PASS.
    • Orthogonally, raise or diagnose the RMT RX cap. Likely needs a second RX arm within capture() to drain the remaining edges into a second chunk, or a larger/chained DMA descriptor for clockless RX at 2.4 MHz.

    Will file this as its own issue and link it back here. 100-LED path still works correctly end-to-end (genuine PASS for both frames).

  6. zackees commented on Apr 18, 2026

    @zackees
    MemberAuthor

    Plan — segmented capture to verify full 550-LED strip via RxConfig::skip_signals

    Investigation confirms the 512-byte cap is RMT_RX_DMA_SYMBOL_COUNT = 4096 at src/platforms/esp/32/drivers/rmt_rx/rmt_rx_channel.cpp.hpp:1134, not a software decoder limit. For SPI wave8, 4096 symbols ÷ 8 symbols/byte = 512 bytes = ~170 LEDs per pass.

    The relevant hardware-ish skip feature exists — RxConfig::skip_signals (src/fl/rx_device.h:218). Implementation at rmt_rx_channel.cpp.hpp:1016-1116 (handleSkipPhase) drains the first N symbols through a throwaway buffer via ISR before accumulation starts, so the DMA buffer never sees them. That lets us segment a long strip across multiple captures.

    Steps (executing now)

    Firmware — examples/AutoResearch/:

    1. AutoResearchRemote.cpp — accept optional skipLeds: int on runSingleTest (validate [0, 10000]); thread to the chipset-timing functions.
    2. AutoResearchTest.cpp/.h — thread skip_leds down to runMultiTest() and capture(). In capture(), set rx_config.skip_signals = skip_leds * 24 (WS2812B = 8 bits/byte × 3 bytes/LED). In the comparator, index TX LEDs as leds[i + skip_leds] so the right segment is compared.
    3. Echo skipLeds back in the JSON response.

    Python — ci/autoresearch/:
    4. args.py — new --skip-leds N CLI flag.
    5. phases.py — inject skipLeds into runSingleTest params when set.

    Verify on device — ESP32-S3, 550-LED strip:
    6. Rebuild + reflash.
    7. Four runs: --skip-leds 0, 170, 340, 510. Each pass checks one ~170-LED window.
    8. Report: all four PASS ⇒ full-strip verification is green; any FAIL ⇒ real bug localized to that window.

    Out of scope for this pass (flag here, fix separately): the silent-truncation false-positive in the comparator (AutoResearchTest.cpp:840-844 breaks instead of failing when bytes_captured < expected) — tracked so it doesn't hide bugs going forward.

    Starting work on a feature branch now. Next update will be the results of step 7.

  7. zackees commented on Apr 18, 2026

    @zackees
    MemberAuthor

    Progress update — skipLeds wired in, but it does NOT work for this capture flow

    Implementation landed on branch feat/autoresearch-spi-skip-leds: skipLeds RPC param + --skip-leds N CLI, threaded through capture() to RxConfig::skip_signals and to the comparator's TX index. The code is additive and safe (skipLeds=0 is default and equivalent to old behavior).

    Device run results (ESP32-S3, 550-LED strip, 4-pass sweep)

    Pass Duration Verdict Why
    --skip-leds 0 349 ms PASS* Captures 512 bytes (~170 LEDs); comparator silently claims "0/550" because it breaks on buffer exhaustion
    --skip-leds 170 40 s FAIL RX begin() failed for pin 2 — handleSkipPhase timeout
    --skip-leds 340 40 s FAIL same
    --skip-leds 510 40 s FAIL same

    * — not a trustworthy PASS; the 550 LEDs in the count were not actually all checked.

    Why the skip path fails (root cause)

    Looked at src/platforms/esp/32/drivers/rmt_rx/rmt_rx_channel.cpp.hpp:1016-1116 — handleSkipPhase() is synchronous and runs inside begin(). It issues rmt_receive() on a 64-symbol throwaway buffer and blocks waiting for the ISR to fire, then loops until mSkipCounter == 0.

    Our harness flow is:

    rx_channel->begin(rx_config);   ← inside this: handleSkipPhase() blocks waiting for signals
    FastLED.show();                 ← …but the TX hasn't started yet, so no signals ever arrive
    

    → The first skip chunk times out after 5 s × (SKIP_TIMEOUT_MS), begin() returns false, capture() returns 0. That's the 40 s duration (8 captures × ~5 s each).

    skip_signals is designed for a continuous-receiver scenario where the TX is already running (or running on a separate task) — not the "arm RX, then fire one-shot TX" pattern the autoresearch harness uses.

    The deeper issue this exposed

    Even with skipLeds=0, the 550-LED test lies: captures 512 bytes, silently breaks the comparator, reports "0/550 errors" as PASS. Before any driver verification is trustworthy on long strips, the harness needs either:

    1. Fail-on-truncation — treat bytes_captured < num_leds * 3 as FAIL rather than PASS with silent break. (Trivial fix; ~5 lines in AutoResearchTest.cpp:840.)
    2. Bigger effective capture — RX accumulation buffer is already huge (96 KB), but only 512 bytes land there. The DMA buffer is 4096 symbols at rmt_rx_channel.cpp.hpp:1135; en_partial_rx is enabled for ESP-IDF 5.3+ but only 1 callback's worth seems to make it to the accumulation buffer. Need to investigate why the ISR re-arm isn't firing for subsequent DMA fills during a 5.5 ms SPI transmission. This is the actual fix for verifying long strips.

    Recommendation

    Not going to push the skipLeds branch for PR — it's correct code but the underlying mechanism won't let us use it for one-shot validation. Want me to instead:

    • (A) Land the trivial fail-on-truncation fix so the harness stops lying, AND
    • (B) Investigate the en_partial_rx / accumulation-buffer behavior so we can actually capture > 512 bytes in one pass?

    (B) is the real unlock for verifying 550-LED strips correctly.

  8. zackees commented on Apr 18, 2026

    @zackees
    MemberAuthor

    Final status — fix (A) landed, fix (B) blocked on RMT memory-manager refactor

    What works now

    • Silent-truncation false-positive is fixed. ✅ 550-LED SPI test now hard-FAILs with [TRUNCATED CAPTURE] Only verified 170/550 LEDs (512 bytes captured, needed 1650). Marking 380 unchecked LEDs as mismatches. — no more "0/550 errors" pass that was hiding real bugs. 100-LED regression-free (PASS, 2 frames each × 4 patterns).
    • Accurate 100-LED SPI verification. --strip-sizes 100 passes legitimately on ESP32-S3 with the Channel API SPI driver in loopback, with frameCount=2 covering the ESP32-S3 SPI driver: second-frame degradation (black frame between displays) — autoresearch needs two-frame capture #2288 second-frame degradation check.

    Honest ceiling

    • Any strip > ~170 LEDs cannot be verified by this harness on ESP32-S3 today. RMT RX in non-DMA mode caps at 4096 symbols per receive. DMA RX would extend capture length but is blocked by:

    The DMA investigation (7 attempts, all committed for posterity)

    Branch feat/autoresearch-spi-skip-leds contains the full exploration:

    Attempt Fix tried Blocker hit
    1 skipLeds + multi-pass handleSkipPhase times out — expects signal before begin() returns
    2 Bump DMA buffer 4096 → 16384 No change — with_dma=false means 4096 is not the DMA buffer
    3 Add RxConfig::use_dma opt-in Toggle ignored — with_dma is baked at rmt_new_rx_channel() time
    4 Rebuild channel when use_dma changes ESP-IDF: \"user buffer not in the internal RAM\" (fl::vector landed in PSRAM)
    5 `heap_caps_malloc(DMA INTERNAL)` 3 MB
    6 Cap at 16 KB ESP-IDF: \"buffer size exceeds DMA capacity\" — mem_block_symbols=64 too small
    7 mem_block_symbols=1024 FastLED RmtMemoryManager: \"RMT RX memory allocation failed for channel 130\" — ESP32-S3 only has 384 total RMT symbols across all channels

    Each fix unblocked the previous step and surfaced the next layer of constraint. The last one is structural: ESP32-S3 RMT hardware simply doesn't have enough symbol memory for a 1024-symbol DMA RX buffer while other RMT users (TX for the RMT driver test, discovery, etc.) are also registered. The RmtMemoryManager's budget enforces this correctly.

    What stays committed (branch NOT pushed for merge yet)

    The following is groundwork, reasonable on its own, no behavior change unless opted-in:

    • RxConfig::use_dma — opt-in API field (default false).
    • Channel-rebuild when use_dma toggles, with heap_caps-DMA raw buffer allocation.
    • [RMT RX] symbols=N callbacks=C visible telemetry after wait() — future regressions on long streams will be diagnosable without FL_LOG_RX.

    What I'd recommend pushing for merge (opening a targeted PR)

    Just the truncation-fix commit (fix(autoresearch,rmt_rx): fail on truncation + 4× DMA buffer for long strips — drop the DMA-buffer bump, keep only the comparator fix). That alone stops the harness from lying on long strips, which is critical for CI trustworthiness regardless of whether #2254 ever gets fully solved.

    Next investigation if anyone wants to pick it up

    The path to actually verifying 550+ LEDs on ESP32-S3 requires refactoring RmtMemoryManager to accept larger dynamic RX allocations when DMA is in use. That's a bigger PR of its own and not something I'll do in this thread. Tracker worthy.

    What this answers for #2254 itself

    • Issue 2 (SPI incorrect output) on the subset we CAN verify (≤170 LEDs): the channel-API SPI driver on ESP32-S3 produces correct waveforms, no second-frame degradation. That does NOT rule out the bug @ewowi reported on MoonLight — the reproducible scenario likely involves strip lengths well above 170 LEDs, multi-lane config, or concurrent RTOS load that this harness can't reach yet.
  9. 24 remaining items

  10. zackees commented on May 9, 2026

    @zackees
    MemberAuthor

    Cross-link to #2428. The I2S/audio FPS-impact half of this is partially addressed by #2428's default-path removal of ChannelManager from the show() call chain — the begin-frame waitForReady() (which currently calls task::run(250, SYSTEM) → pumpCoroutines(1000) → vTaskDelay(1), see #2421 root cause analysis) disappears when channels bind directly to a single BusTraits<B>::instance() at compile time. Won't fix the I2S driver itself, but removes one of the two tick-aligned waits per frame in the default (non-registry) configuration.

  11. zackees commented on May 21, 2026

    @zackees
    MemberAuthor

    Cross-reference: the deep-yield fix for this issue is the root cause of #2420 and #2493

    The pumpCoroutines(1000) → vTaskDelay(max(1, us/tick_period)) deep-yield that fixed Issue 1 here (src/platforms/esp/32/coroutine_esp32.impl.hpp:83-86, comment explicitly references this issue) is now the per-frame cost driving two regressions:

    The deep-yield is still correct for I2S audio busy-wait paths (the actual cause of websocket starvation here). The regression is that the same yield was applied generically to ChannelManager::waitForCondition, where it sleeps for prior-frame DMA drain on drivers (PARLIO, RMT, SPI) that don't have a WiFi-starvation risk — their DMA runs entirely in hardware/ISR after the first buffer submit.

    #2428 (compile-time Bus binding) is the structural fix — decouples the default show() path from ChannelManager polling. Until that lands, a targeted task::run(0, SYSTEM) (= taskYIELD()) in ChannelManager::waitForCondition / IChannelDriver::waitForCondition retains the I2S fix while removing the per-frame tick cost from PARLIO/RMT/SPI.

  12. zackees commented on Aug 20, 2026

    @zackees
    MemberAuthor

    Closing after verifying all three reported sub-issues against current master:

    The original umbrella has no remaining actionable sub-issue.

  13. moved this from Triage to Done in FastLED Trackeron Aug 20, 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

    area: driversplatform: esp32status: triage

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions