Skip to content

ESP32-S3 SPI driver: second-frame degradation (black frame between displays) — autoresearch needs two-frame capture #2288

Closed

Description

@zackees

Summary

Continuing from #2254 (Issue 2: SPI driver — incorrect LED output). On ESP32-S3, the SPI LED driver exhibits a two-frame degeneration pattern: the first frame renders (mostly) correctly, then a black / corrupted frame appears between displays, and the cycle repeats. Current bash autoresearch --spi does not catch this because it only captures and verifies a single FastLED.show() call per test case.

This is a big problem — the most common real-world usage pattern for the SPI driver is a steady show() loop, and that is exactly the pattern we are not testing.

Repro (hardware required)

Why the existing autoresearch tool misses this

Reviewed examples/AutoResearch/AutoResearchTest.cpp in the capture() function (around lines 376–391). For non-RMT drivers (PARLIO, SPI, UART, I2S) the flow is:

rx_channel->begin(rx_config);   // arm RX once
FastLED.show();                 // TX frame #1
FastLED.wait(TX_WAIT_TIMEOUT_MS);
rx_channel->wait(rx_wait_ms);   // decode single capture

One FastLED.show(). One decode. No concept of frame N vs. frame N+1. A driver that emits a correct frame #1 and a zeroed frame #2 is scored PASS today.

The runTest / runSingleTest RPC handlers (driver_sweep.py, AutoResearchRemote.cpp) inherit the same single-frame assumption — iterations=1 is the default and each iteration currently re-runs an independent capture rather than capturing consecutive back-to-back frames from a sustained show() loop.

What we need the autoresearch tool to do

Extend the capture pipeline so that a single test case can capture two (or N) consecutive frames from the same armed RX session and verify each of them independently. Concretely:

1. New capture mode: multi-frame continuous capture

  • Arm RX once with a buffer large enough for N frames plus inter-frame gaps.
  • Call FastLED.show() N times in a row (N ≥ 2) without re-arming RX between shows.
  • Rely on the existing gap-tolerance logic (already bumped to 100 µs for SPI) to segment the edge stream into frame boundaries.
  • Decode the stream into N frame buffers, not one.
  • Compare every frame against the expected pattern — all must pass for the test to pass.

2. New test pattern: second-frame degradation detector

Dedicated check that succeeds only if frame #2 is byte-identical (within tolerance) to frame #1 when the same CRGB buffer is shown twice. Failure modes we want to catch:

  • All-zero second frame ("black frame between displays" — the current SPI bug).
  • Partial second frame (DMA truncation / premature end).
  • Corrupted second frame (buffer reuse / overwrite during DMA).
  • Shifted second frame (clock/latch misalignment across frame boundary).

Each of these should produce a distinct, named failure class in the JSON-RPC result so the agent can distinguish "SPI driver zeroes the buffer after first show" from "SPI driver truncates DMA".

3. RPC surface changes

Add to the existing runSingleTest / runTest config:

{
  \"driver\": \"SPI\",
  \"laneSizes\": [100],
  \"pattern\": \"MSB_LSB_A\",
  \"frameCount\": 2,                // NEW: consecutive frames in one capture (default 1)
  \"frameComparison\": \"identical\" // NEW: \"identical\" | \"independent\" | \"none\"
}

Result stream should report per-frame pass/fail:

{
  \"type\": \"test_complete\",
  \"passed\": false,
  \"frames\": [
    {\"index\": 0, \"passed\": true,  \"mismatchedLeds\": 0},
    {\"index\": 1, \"passed\": false, \"mismatchedLeds\": 100, \"failureClass\": \"all_zero\"}
  ]
}

4. Promote SPI to a first-class autoresearch attribute

Since we have an ESP32-S3 attached and SPI is already a top-level flag (--spi), make the SPI sweep run multi-frame by default on ESP32-S3:

  • bash autoresearch --spi on esp32s3 → runs with frameCount=2 and frameComparison=\"identical\".
  • Add a regression test case specifically named spi_second_frame_regression to the sweep matrix in ci/autoresearch/driver_sweep.py.
  • Add --frames N / --frames-compare MODE CLI flags to bash autoresearch so other drivers (PARLIO, I2S) can opt into multi-frame testing once the plumbing exists.

Implementation sketch

Files to touch:

  • examples/AutoResearch/AutoResearchTest.cpp — capture() grows a frame_count parameter; the gap_tolerance / edge decoder splits multi-frame edge streams.
  • examples/AutoResearch/AutoResearchRemote.cpp — runSingleTest / runTest JSON handler accepts frameCount and frameComparison.
  • ci/autoresearch/driver_sweep.py — test matrix gains a multi-frame row for SPI; result printer handles per-frame failure arrays.
  • autoresearch (bash wrapper) + ci/autoresearch/args.py — new --frames / --frames-compare flags; default frames=2 when driver is SPI.
  • agents/docs/hardware-autoresearch.md — document the new flags and the second-frame failure classes.

Acceptance criteria

  • bash autoresearch --spi on ESP32-S3 detects the current "black frame between displays" bug without any code changes to the SPI driver (i.e., it reproduces the failure that ESP32-S3: I2S driver starves websockets, SPI output incorrect, Audio driver FPS impact #2254's video shows, as a hard FAIL in the sweep).
  • After the driver is fixed, the same command passes cleanly with both frames matching.
  • Running with --frames 2 on RMT (known-good driver) passes — proving the capture pipeline itself doesn't false-positive.
  • Failure class in the RPC result matches the visual symptom (all_zero for the current SPI bug).

Related

Environment

Activity

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

    @zackees
    MemberAuthor

    Completed across two merged PRs:

    • feat(autoresearch): add --frames N multi-frame capture #2293 (already merged) — added --frames N multi-frame capture + frameCount RPC parameter to runSingleTest. Harness can now detect two-frame degradation patterns.
    • feat: fix #2254 SPI long-strip bug + enable RMT RX DMA streaming #2300 (just merged) — fixed the underlying SPI TX bug (4 KB staging chunk → WS2812B reset latch between chunks) that was the original reason for wanting two-frame detection. bash autoresearch --spi --strip-sizes 550 --frames 2 now produces clean PASS with all 550 LEDs verified byte-for-byte across both frames. Also extended RMT RX capture past 170 LEDs via RxConfig::use_dma streaming (ESP-IDF partial-rx + 14336-symbol mem_block so the DMA descriptor chain covers ~680 LEDs in one rmt_receive).

    Telemetry on attached ESP32-S3 after both fixes:

    [RMT RX] wait(): symbols=13200 callbacks=15 use_dma=true
    [RUN 1] Driver=SPI, bytes_captured=1650
    [Run 1/2] PASS | Errors: 0/550 (100.0%)
    [Run 2/2] PASS | Errors: 0/550 (100.0%)
    TEST SPI lanes=1 leds=550 PASS
    

    Closing as completed.

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

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions