Skip to content

ESP32-S3 LCD_CLOCKLESS: interrupt watchdog timeout in ISR context with 8+ lanes × 256 LEDs WS2812 #2647

Closed

Description

@zackees

Summary

LCD_CLOCKLESS driver on ESP32-S3 (XIAO_ESP32S3, 8 MB OPI PSRAM, OPI flash) panics with Guru Meditation Error: Core 1 panic'ed (Interrupt wdt timeout on CPU1) within ~5 seconds of starting runSingleTest once the lane count × strip size hits 8 lanes × 256 LEDs or above. The panic always lands inside ESP-IDF SPI flash erase code (spi_flash_chip_generic_erase_block / esp_flash_erase_region) while the CPU is in ISR context, even though the LCD driver itself never erases flash.

A jumper wire connects GPIO 1 (TX) to GPIO 2 (RX) for RMT-RX loopback validation. Hardware connectivity is confirmed green before the failing test starts.

Reproduction

bash autoresearch esp32s3 --lcd --upload-port COM13 --lanes 16 --strip-sizes 256 --skip-lint --timeout 240

Same crash also reproduces with --lanes 8 --strip-sizes 256. Note: the public --lanes upper bound in examples/AutoResearch/AutoResearchRemote.cpp is currently 8 — bumping it to 16 (one-line change, included in the linked PR) is required to exercise the full 16-bit LCD_CAM bus that LCD_CLOCKLESS claims to support via wave8Transpose_16.

Environment:

  • Board: Seeed XIAO ESP32-S3 (revision 0.02, 8 MB OPI PSRAM, 8 MB OPI flash, Arduino board SEEED_XIAO_ESP32S3)
  • Arduino-ESP32 3.3.7 / ESP-IDF v5.5.2-729-g87912cd291
  • FastLED master at 21bf87b
  • Driver selection: opts.mBus = fl::Bus::LCD_CLOCKLESS
  • Chipset timing: WS2812B-V5 (T1=225, T2=355, T3=645)
  • Encoding path: wave8 (canUseWave3 = false for WS2812B-V5)
  • Per-frame DMA size: 768 source bytes × 128 output bytes per source byte × 16 lanes = 98 304 bytes
  • Default chunk size: 90 source bytes → 11 520 DMA bytes per chunk → 9 chunks per frame (last chunk smaller — see Diagnosis)

Symptom

Captured serial output (trimmed):

LcdSpiPeripheralEsp: Initialized with 16 lanes, 6530612 Hz clock, owner=2
WARN: task::run re-entrancy detected, skipping nested call
Guru Meditation Error: Core  1 panic'ed (Interrupt wdt timeout on CPU1).
Core  1 register dump:
PC      : 0x40385894  PS      : 0x00060234
EXCCAUSE: 0x00000006
EPC1    : 0x4218580f  EPC3    : 0x400570cb  EPC4    : 0x40385894
Core  1 was running in ISR context:
Backtrace: 0x40385891 → spi_flash_chip_generic_erase_block
           0x40386441 → spi_flash_chip_winbond_read
           0x403846ce → esp_flash_erase_region
           0x420f615a, 0x420f5c98, 0x4208b4e2 (user code — debug info stripped)

Core 0 is in idle hooks; only Core 1 is wedged. Reproducible 100 % of the time on this board.

Diagnosis

Two latent bugs surface together; the panic only stops reliably once both are addressed.

1. ISR re-arm path is in flash, not IRAM

channel_driver_lcd_clockless.cpp.hpp registers isrChunkDone as the on_color_trans_done user callback. The ESP-IDF trampoline lcd_spi_flush_ready is correctly IRAM_ATTR, but isrChunkDone, encodeChunk, and the EspWrapper::transmit thunk are compiled into the default .text section. When any concurrent flash op suspends the cache (NVS commit, esp_flash_erase_region, OTA write, etc.), the ISR cannot fetch its own code; interrupts stay masked past the 300 ms IWDT window; the panic backtrace ends up inside the flash erase routine that happened to be running at the time.

PARLIO solved the same class of issue by marking its workerIsrCallback FL_IRAM (src/platforms/esp/32/drivers/parlio/parlio_engine.h:241). The LCD_CLOCKLESS path needs the same treatment for isrChunkDone, encodeChunk, LcdSpiPeripheralEsp::transmit, and the wrapper transmit thunk inside createLcdClocklessEngine.

2. LcdSpiPeripheralEsp::transmit calls xSemaphoreTake from ISR

lcd_spi_flush_ready calls xSemaphoreGiveFromISR(self->mCompleteSem) before invoking the user callback, so the take is guaranteed non-blocking — but the non-FromISR variant of xSemaphoreTake asserts when invoked from an interrupt under most FreeRTOS configurations. Even when the assertion is compiled out, it leaves task-internal lists in an inconsistent state. Use xSemaphoreTakeFromISR on the ISR path (gated by xPortInIsrContext()).

3. Variable last-chunk size forces panel_io re-creation from ISR

transmit() contains:

if (size_bytes != mLastTransmitSize && mPanelIo != nullptr) {
    esp_lcd_panel_io_del(mPanelIo);
    mPanelIo = nullptr;
}
if (mPanelIo == nullptr) {
    esp_lcd_new_panel_io_i80(...);
}

With the default chunk size of 90 and a typical maxSize of 768 bytes (16 lanes × 256 LEDs × 3 bytes / 16 lanes), the last of 9 chunks per frame is only 48 source bytes ⇒ 6 144 DMA bytes vs the standard 11 520. On every frame boundary the ISR drives esp_lcd_panel_io_del and esp_lcd_new_panel_io_i80, both of which touch flash and re-allocate GDMA descriptors — this alone is enough to provoke the same IWDT panic even without the IRAM-resident-code race in (1).

Fix: pick numChunks so maxSize / numChunks is an exact divisor (numChunks walks up from ceil(maxSize / requested) until maxSize % numChunks == 0). Worst case falls back to 1-byte chunks, but for typical RGB strips (n × 3 bytes) the loop terminates in 2-3 iterations.

Status

A draft fix for all three is in branch fix/lcd-clockless-isr-iram-2026-05-30 (commits 7bfb1bb53f and 821fd8919a). It compiles and flashes cleanly. The chip still panics in the same way after the fix — telling me the IRAM/ISR-safety work is necessary but not sufficient. There is at least one more interaction (probably in the autoresearch setup path or ChannelManager driver enrollment) that triggers a long enough flash erase to trip IWDT on this XIAO board. I'm filing this so the deeper root-cause investigation has a clean record to start from.

Suggested next steps

  1. Land the IRAM + FromISR + equal-chunk patches as defense in depth — they are correct regardless of the remaining trigger.
  2. Bisect what triggers the esp_flash_erase_region call seen in the backtrace. Candidates:
    • NVS commit during ChannelManager driver enrollment (every test re-runs enableAllDrivers() which logs many "already registered" idempotent no-ops).
    • PHY calibration data write (nvs:phy_init) when LCD_CAM peripheral first powers on.
    • OPI PSRAM access through the shared SPI memory controller being mis-decoded as flash erase by the panic dumper.
  3. Consider matching PARLIO's worker-task pattern: have isrChunkDone only signal a high-priority task that does the encode + re-arm. This decouples the encode budget from the IWDT window entirely.
  4. Bump the runSingleTest laneSizes upper bound from 8 to 16 in examples/AutoResearch/AutoResearchRemote.cpp so the autoresearch harness can actually exercise the 16-lane LCD_CAM bus. (Included in the linked branch.)

Related


Defaults used while researching this issue (please correct if wrong):

  • I assumed ESP-IDF xSemaphoreTake from ISR is undefined behaviour in release builds (it asserts in debug).
  • I assumed the panic backtrace's spi_flash_chip_generic_erase_block PC is genuine flash erase and not OPI-PSRAM read mis-labelled by the symbol table. This is consistent with the surrounding backtrace frames (esp_flash_erase_region), but on OPI-flash + OPI-PSRAM boards the two share the SPI memory controller so it deserves verification.
  • I assumed the test framework was correct to limit laneSizes to 8 historically; the bump to 16 is a one-line change with no functional impact when fewer lanes are requested.

Activity

  1. zackees commented on May 31, 2026

    @zackees
    MemberAuthor

    Update — bug isolated to multi-chunk ISR re-arm path

    After landing the IRAM + FromISR + equal-chunk patches on branch fix/lcd-clockless-isr-iram-2026-05-30, I ran a scan-to-find-the-edge:

    Config maxSize / per-lane Chunks Result
    --lcd --lanes 1 --strip-sizes 30 90 B 1 (single shot, no ISR re-arm) ✅ PASS (all 4 patterns, 1439 ms)
    --lcd --lanes 1 --strip-sizes 200 600 B 7-8 (ISR re-arms) ❌ RPC timeout (chip wedged, same IWDT panic signature)
    --lcd --lanes 8 --strip-sizes 256 768 B 12 (equal-chunk fix) ❌ Same panic
    --lcd --lanes 16 --strip-sizes 256 768 B 12 (equal-chunk fix) ❌ Same panic
    --rmt --lanes 1 --strip-sizes 100 300 B (RMT bypass) ✅ PASS — proves the test harness + jumper + RX path are healthy

    So the IRAM and ISR-safety patches do their job for the single-shot transmit; what's still broken is what happens inside isrChunkDone when it tries to submit the next chunk from the on_color_trans_done callback.

    The most likely remaining culprit is esp_lcd_panel_io_tx_color() itself when called from on_color_trans_done. With trans_queue_depth = 1, the LCD I80 driver may not have retired the current transaction from its internal queue by the time the user callback fires (the callback runs from the DMA-done ISR before queue cleanup), so the back-to-back tx_color() blocks waiting for a queue slot — from ISR context. That hangs the CPU long enough for IWDT to fire.

    Plausible fixes (haven't tried yet — flagging for whoever picks this up):

    1. Bump trans_queue_depth to 2+ so the next transmit can be queued without waiting for the running one to retire.
    2. Adopt PARLIO's worker-task pattern — isrChunkDone only signals a high-priority FreeRTOS task; the task does encode + tx_color. Decouples the next-chunk submit from the ISR window entirely.
    3. Have the user task pre-encode and queue the next chunk before yielding (eliminating ISR re-arm), accepting the back-pressure cost.

    Single-shot LCD_CLOCKLESS (numChunks == 1, i.e. maxSize <= chunkInputBytes) works correctly with the branch fixes. That's a safe escape hatch: if --strip-sizes per lane is small enough that the whole frame fits one chunk, the driver delivers WS2812 data correctly.

    I'm leaving the issue open and the PR (#2648) in draft. Reassigning the diagnosis above to anyone with deeper LCD I80 internals familiarity than I have right now.

  2. zackees commented on May 31, 2026

    @zackees
    MemberAuthor

    Update — IWDT panic eliminated, correctness issue remains

    Root cause of the IWDT panic confirmed and fixed (commit eb59d1b on fix/lcd-clockless-isr-iram-2026-05-30):

    io_config.trans_queue_depth = 1 is incompatible with re-arming tx_color() from on_color_trans_done. With depth=1 the currently-running transaction has not yet been retired from the I80 queue when the user callback fires, so the re-arm blocks waiting for a queue slot — from ISR context — and trips the 300 ms IWDT. Depth=2 leaves room for the ISR-driven re-arm and the panic disappears across all configurations I tested.

    Config Before queue_depth fix After queue_depth=2
    --lcd --lanes 1 --strip-sizes 30 (single chunk) ✅ pass ✅ pass (4/4 patterns)
    --lcd --lanes 1 --strip-sizes 200 (multi-chunk) ❌ IWDT panic ⚠️ runs, ~88 % byte corruption
    --lcd --lanes 16 --strip-sizes 256 (multi-chunk) ❌ IWDT panic ⚠️ runs, ~92 % byte corruption

    Remaining work — multi-chunk data corruption. The first chunk (encoded + submitted from beginTransmission() in task context) survives correctly on the wire. Every subsequent chunk encoded/submitted from isrChunkDone() emits garbled data — RX-loopback shows 87.5–91.8 % byte corruption with a "Mixed corruption pattern" diagnosis. ~21 LEDs of clean data fits inside one 64-byte chunk, which is consistent with "only chunk 1 transmits correctly."

    Suspect list (not yet bisected, ordered by likelihood):

    1. Inter-chunk gap exceeds WS2812 50 µs reset window — esp_lcd_panel_io_tx_color() sends a brief 0x2C command phase before each transaction even with lcd_cmd_bits=0; if the total gap drifts past 50 µs the strip latches mid-frame and subsequent bits land on a fresh frame at offset 0.
    2. ChannelData::getData() is not IRAM-resident — the per-byte gather loop in encodeChunk calls a virtual function through shared_ptr<ChannelData>; if the dispatch lands in flash while cache is suspended the ISR reads garbage instead of stalling (no panic, just bad bytes). Marking the path FL_IRAM only helps the caller — the vtable thunk and getter still live in flash.
    3. Ring-buffer race — with queue_depth=2 and 3 ring buffers we could in theory wrap around and re-encode buffer N while it is still in the I80 transaction queue. Worth audit.

    Closest defensible quick-win: adopt PARLIO's worker-task pattern so encoding happens at task priority, not from the I80 DMA-done ISR. That sidesteps both (1) (worker task can pre-fill the next chunk while the current one transmits, avoiding gap) and (2) (no flash-cache exposure from ISR context).

    For now LCD_CLOCKLESS is correct only when maxSize_per_lane <= kDefaultChunkInputBytes (90 bytes ≈ 30 RGB LEDs). Above that threshold the driver no longer panics but the data on the wire is wrong.

    PR #2648 updated with the queue_depth fix.

  3. zackees commented on May 31, 2026

    @zackees
    MemberAuthor

    🎉 Hardware verified — 16 lanes × 256 LEDs WS2812 passes end-to-end

    With chunk size bumped to 1024 bytes (fit-the-frame-in-one-chunk workaround on top of the IWDT-panic fix), LCD_CLOCKLESS now passes the canonical 16-lane × 256-LED WS2812B-V5 autoresearch matrix:

    bash autoresearch esp32s3 --lcd --upload-port COM13 --lanes 16 --strip-sizes 256
    TEST LCD_CLOCKLESS lanes=16 leds=4096 PASS 1694ms
    Tests: 4/4 passed
    Duration: 1694ms (show: 1592ms)
    RESULT PASS 1 test(s)
    

    RX-loopback captures all 4 test patterns (MSB_LSB_A / _B / _C / RGB-alternating) byte-perfect on lane 0.

    Summary of the branch (fix/lcd-clockless-isr-iram-2026-05-30):

    • FL_IRAM on isrChunkDone, encodeChunk, EspWrapper::transmit, LcdSpiPeripheralEsp::transmit (kept; defense in depth — neighbouring flash ops should not be able to stall the ISR even though the panic root cause was different).
    • xSemaphoreTakeFromISR on the ISR re-arm path (kept; correct ISR-safety regardless of cache state).
    • Equal-chunk sizing (kept; avoids the variable-size last chunk that would otherwise force esp_lcd_panel_io_del + esp_lcd_new_panel_io_i80 from ISR).
    • io_config.trans_queue_depth = 1 → 2 — root cause of the IWDT panic. The re-arm tx_color() from on_color_trans_done blocked on a full queue with depth=1.
    • kDefaultChunkInputBytes 90 → 1024 — workaround that keeps typical frames in a single chunk so the still-buggy multi-chunk ISR re-arm path is bypassed.
    • Test harness: runSingleTest lane bound 8 → 16 so autoresearch can drive the full LCD_CAM 16-bit bus.

    Open follow-up: the multi-chunk ISR re-arm path (frames > 1024 source bytes per lane, or any setChunkInputBytesForTest() override below frame size) still emits garbled bytes 2..N. Suspect inter-chunk gap exceeding the WS2812 50 µs reset (every tx_color re-enters the LCD I80 dc/cmd phase) or per-byte-position virtual-call latency through shared_ptr<ChannelData> while flash cache is suspended. The PARLIO worker-task pattern is probably the cleanest path forward; documenting here for whoever picks it up.

    Closing the panic + 16×256 doesn't work aspect of this issue with the merged-when-reviewed PR. Leaving the issue open with the "multi-chunk corruption" item carved out as future work.

  4. zackees commented on Jun 3, 2026

    @zackees
    MemberAuthor

    Closing this as fixed for the original LCD_CLOCKLESS IWDT panic / 8-16 lanes x 256 WS2812 scope.

    Verification:

    bash autoresearch esp32s3 --lcd --upload-port COM<x> --lanes 16 --strip-sizes 256 --skip-lint
    TEST LCD_CLOCKLESS lanes=16 leds=4096 PASS 1694ms
    Tests: 4/4 passed
    
    • I also re-ran the focused host regression test on current master:
    bash test channel_driver_lcd_clockless --cpp --quick --no-interactive
    All tests passed (1/1)
    

    The remaining frames-larger-than-one-chunk corruption is now tracked separately in #2693, so this issue can close cleanly as completed.

  5. moved this from Triage to Done in FastLED Trackeron Jun 3, 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