Repository navigation
Description
Summary
Follow-up to #2254 / PR #2300. The merged fix bumped the SPI channel staging buffer from 4 KB to 16 KB so a single spi_device_queue_trans() call covers up to ~680 WS2812B LEDs in one continuous DMA transaction. This resolves the "black frame between displays" bug for most real-world strips, but strips longer than ~680 LEDs (24 bytes/LED × wave8) still split into multiple SPI transactions advanced by the poll() loop. Between transactions, the SPI line idles for the time it takes the host task to notice completion and queue the next chunk — which can exceed WS2812B's ~50 µs reset threshold under RTOS contention.
This issue tracks a proper fix: back-to-back DMA chunk streaming where ESP-IDF's SPI ISR transitions directly from one queued transaction to the next without any host-task involvement, making the gap independent of poll() cadence.
Current behavior
src/platforms/esp/32/drivers/spi/channel_driver_spi.cpp.hpp:
dev_config.queue_size = 4— already allows 4 transactions queued at once.startFirstDma()queues one transaction viaspiStart()and setsmDmaInFlight = true.advancePipeline()(called frompoll()) waits for completion, encodes the next chunk into the alternate buffer, queues it.
Sequence:
[encode A] → [queue A] → [wait for A] → [encode B] → [queue B] → [wait for B] → ...
↑ inter-chunk gap scales with poll() latency
Proposed behavior
Pre-queue both buffers so the ESP-IDF SPI ISR chains directly from transA→transB (or B→A) the moment one completes, without any host involvement:
[encode A] → [queue A] → [encode B] → [queue B] ← both in flight from start
poll(): check what completed → refill → re-queue ← refill-on-completion
ESP-IDF ISR auto-starts next queued txn, ~µs gap, not tied to poll()
Implementation sketch
startFirstDma(): encode both stagingA and stagingB and queue both transactions before returning.advancePipeline()becomes a refiller:- On completion of transA with data remaining: encode next chunk into stagingA, re-queue transA.
- On completion of transB with data remaining: encode next chunk into stagingB, re-queue transB.
- Termination: track
ledBytesRemainingand only re-queue when data remains; at end-of-data, wait for both outstanding transactions to drain before marking channel complete.
- Teardown/release path (
releaseChannel,~ChannelEngineSpi): ensure both transactions drained before freeing staging buffers.
Maybe 50-100 lines modified in the state machine. Data structures (stagingA/B, transA/B, queue_size=4) are already in place.
Expected benefits
- Supports arbitrarily long strips (1500+ LEDs) on SPI without the poll()-scheduling dependency.
- Can revert
staging_sizeback to 4 KB if desired — total RAM footprint returns to 2×4 KB per channel instead of 2×16 KB. - Removes a whole class of RTOS-contention-related LED artifacts reported in MoonLight-style workloads.
Risks / things to validate
- ESP-IDF SPI master inter-transaction gap measurement on ESP32-S3, ESP32-C3, ESP32-C6. Should be < 1 µs in DMA mode but worth confirming with an oscilloscope or RMT RX timing dump.
- Does
spi_device_queue_trans()from a polling-mode chip (ESP32-C6 usesspi_device_polling_startperchannel_driver_spi.cpp.hpp:192) behave differently? May need a separate code path for C6. - Teardown correctness — need to drain both outstanding transactions before
spi_bus_remove_device. - Interaction with
transAInFlight/transBInFlightbookkeeping — already present but only one is true at a time today.
Test plan
On ESP32-S3 via bash autoresearch:
-
--spi --strip-sizes 550continues to PASS (regression guard for ESP32-S3: I2S driver starves websockets, SPI output incorrect, Audio driver FPS impact #2254 fix). -
--spi --strip-sizes 1000PASSes (requires also bumping RXmem_block_symbolsfrom 14336 to ~24576 sonum_dma_nodes * 4092 bytes≥ 24000 symbols for RX to capture the full stream). - Stress test: run with WiFi + HTTP traffic concurrently to confirm
poll()starvation no longer produces black frames.
Related
- ESP32-S3: I2S driver starves websockets, SPI output incorrect, Audio driver FPS impact #2254 — origin of the "black frame between displays" bug.
- feat: fix #2254 SPI long-strip bug + enable RMT RX DMA streaming #2300 — merged partial fix (16 KB staging). This issue proposes the complete fix.
- feat(autoresearch): add --frames N multi-frame capture #2293 —
--frames Nmulti-frame autoresearch (will help validate the fix produces stable output across consecutive frames).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTriage
Activity
fix(test/spi-pingpong): refill targets the just-drained buffer, not e…
feat(spi,esp32): pre-queue alternate-buffer SPI chunk for >680-LED st…
zackees commentedon Aug 20, 2026
Marking deferred after implementation/history and attached-hardware audit.
Merged PR #2810 implements the ESP32 A/B prequeue/refill/drain state machine, and follow-up regressions were repaired in #2843/#2869. The remaining acceptance evidence is hardware-specific: >683-LED byte equality plus inter-chunk timing under WiFi/HTTP contention on ESP32-S3/C3, and an explicit decision for ESP32-C6's single-in-flight polling path.
Current attached hardware has only an ESP32-C6 (COM9); no S3/C3 target is present. A diagnostic
bash autoresearch esp32c6 --spi --strip-sizes 1000 --frames 2spent the bounded five-minute window compiling the full C6 framework and never reached deploy, so its exact process tree was terminated. C6 cannot supply the missing S3/C3 DMA-chaining proof in any case.Resume when an ESP32-S3/C3 loopback target is attached. Run a 1000-LED/two-frame SPI test under network contention, capture full byte equality and the inter-chunk gap, then document C6 as unsupported for gap-free chaining or land a separately tested C6 implementation.