Skip to content

I2S1 modern driver: stack canary panic in ISR entry — blocker on Phase D bench #3569

Closed

Description

@zackees

Blocker

The modern classic-ESP32 I2S engine consistently triggers a Stack canary watchpoint triggered (loopTask) panic inside _frxt_int_enter during runSingleTest RPC. Every register-config permutation attempted so far either:

  • Produces the stack canary panic (when the DMA-done ISR fires), or
  • Runs without crashing but produces zero wire edges (captureFailed: true, rawEdgesAfterWait: 0).

I've been iterating on register-config values in circles without a scope. Filing this to hand off the register-level debug to someone with hardware instrumentation.

Bench evidence — every attempt

Attempt Config change Result
Baseline (Yves values) tx_bits_mod=32, tx_fifo_mod=3, tx_msb_right=1, tx_right_first=1, stqe_next=nullptr, ESP_INTR_FLAG_IRAM, ISR sets tx_start=0 boots, rawEdgesAfterWait: 0
Fix #3568 BUG#1 stqe_next = self (self-loop) Stack canary panic in _frxt_int_enter — infinite DMA→ISR loop
Fix #3568 BUG#1 + #2 self-loop + remove tx_start=0 from ISR Same stack canary panic
Fix #3568 BUG#1 + #2 + #3A above + tx_bits_mod=16, tx_fifo_mod=1 Stack canary panic (worse — new StringHolder StoreProhibited also seen)
Revert self-loop, add ISR int_ena.out_eof=0 stqe_next=nullptr + ISR self-mask Stack canary panic (something other than out_eof is firing repeatedly)
Full ISR mask via int_ena.val=0 + only handle out_eof bit as above Stack canary panic (spurious interrupts continue)

Consistent failure pattern

The panic backtrace is always the same shape:

Debug exception reason: Stack canary watchpoint triggered (loopTask)
PC: 0x4008daf8 (_frxt_int_enter — freertos ISR entry stub)
Backtrace:
  _xt_lowint1
  encodeChannelWave8_i2s1
  ChannelEngineI2sEsp32Dev::packScratchBuffer
  ChannelEngineI2sEsp32Dev::show
  ChannelManager::onEndFrame
  ...
  CFastLED::show()
  autoResearchChipsetTiming
  AutoResearchRemoteControl::runSingleTestImpl

The interrupt fires WHILE the wave8 encoder is running in the loop task. The interrupt entry stub can't push its context because the loop task stack is at the canary boundary. Something is firing an I2S1 interrupt during packScratchBuffer — before we even reach transmit() — meaning the peripheral is in an unexpected state left over from the previous run.

What I ruled out

  • Not a stack-usage bug on my side: hoisted 2 KB wave8 byte-LUT to engine member field with hash-invalidation cache. Loop task stack is measured well below 8 KB budget without the interrupt.
  • Not an incorrect stqe_next: both nullptr and self failed. Multi-descriptor ring not tried yet.
  • Not just the encoder-format mismatch: fixing (tx_bits_mod, tx_fifo_mod) to (16, 1) matches wave8's 2-byte-per-pulse layout — didn't produce edges either, and made the panic more frequent.

What I suspect the real root cause is

Stale DMA + ISR state persisting across initialize() calls. The peripheral is a fl::Singleton<> (process-lifetime, never destroyed). Once initialize() runs once and transmit() fires, some register state (probably int_st unread flags, or the DMA state machine in a mid-transfer state) survives even if the caller calls deinitialize() + initialize() again. Subsequent runs of runSingleTest inherit that stale state and immediately fire an interrupt.

Yves's driver worked because his peripheral was ALWAYS armed for streaming and never went through deinit/re-init cycles — his gInitializedI2sInitialized was one-shot for the process. My re-init cycle is broken.

Files touched in this debug session

  • src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp — initialize() register writes, transmit() descriptor + kick, i2s_dma_isr_trampoline
  • src/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.h + .cpp.hpp — wave8 LUT hoisted to member with timing-hash cache

Current uncommitted state on branch docs/i2s-bench-open-debug-note-3526. Should probably be reverted or held on a branch pending scope-verified fixes.

What the next attempt needs

Hardware instrumentation — scope on GPIO 18 during a runSingleTest call, and specifically:

  1. Does GPIO 18 have ANY signal at all? If yes, we're producing edges but wave8-encoded wrong. If no, the peripheral isn't outputting even a clock.
  2. Does the I2S1 clock (LCD_WS or CLK signal) toggle? If yes, the peripheral runs but the data path is misconfigured. If no, clock divider or LCD-mode config is wrong.
  3. Which interrupt bit fires during the panic? Read i2s->int_st.val in a paused-in-debugger state. If out_eof fires but only once, the panic must be from dscr_err re-firing due to a bad descriptor.
  4. Is stqe_next = nullptr actually valid? ESP32 TRM doesn't say explicitly for LCD-parallel mode. Yves's code always uses circular chains — never one-shot. May need to allocate two descriptors and chain first→sentinel (sentinel with owner=0).

Recommended next step

Someone with a scope should:

  1. Revert my docs/i2s-bench-open-debug-note-3526 branch's uncommitted changes back to Yves-baseline registers.
  2. Add explicit deinit-then-fresh-init in the peripheral impl (may need to also esp_intr_free() + realloc across runs).
  3. Instrument the peripheral to log int_st.val state on the FIRST ISR fire of each runSingleTest to identify which flag is triggering the flood.
  4. Consider a 2-descriptor ring with a sentinel owner=0 descriptor as the one-shot terminator — Yves never tested nullptr; his ring always had a valid next pointer.

Related

Files to review

  • Live impl: src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp
  • Live engine: src/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp.hpp
  • Yves reference (deleted, still in git): git show ce70b5a5c8^:src/platforms/esp/32/drivers/i2s/i2s_esp32dev.cpp.hpp

Session summary

Over ~20 configuration permutations across 6+ hours of bench iteration, I could not produce a passing runSingleTest on WROOM COM11. The problem is genuinely register-level and needs hardware instrumentation to resolve. Handing off.

Activity

  1. zackees commented on Jul 2, 2026

    @zackees
    MemberAuthor

    Root cause analysis — the mystery is solved, and it was five separate problems

    Full re-investigation from scratch (Fable 5 session, 2026-07-01). Every prior conclusion in this issue was re-derived from evidence; several were wrong. All software fixes are in PR #3570. Findings below, most important first.

    0. TL;DR

    The bench itself is broken: the GPIO18 → GPIO19 jumper wire is not electrically connected. Proven with esptool register pokes (no firmware involved). Every "no wire edges" observation ever recorded on this WROOM — for I2S, RMT, and even plain GPIO toggles — was a floating RX pin. On top of that, four real software bugs were found and fixed (PR forthcoming): two in the RMT RX capture backend that made any capture on classic ESP32 impossible, and the I2S TX encoding bugs that would have produced wrong waveforms once captures work.

    1. The physical bench blocker (ACTION REQUIRED: reconnect the jumper)

    Electrical test via esptool memory pokes in the ROM bootloader (no firmware, no drivers):

    IO_MUX GPIO18/19 → GPIO function, input-enabled
    GPIO_ENABLE |= 1<<18 ; GPIO_OUT |= 1<<18   (drive GPIO18 HIGH)
    GPIO_IN = 0x0004CEAB   → bit18=1 (GPIO18 drives + reads back), bit19=0 (GPIO19 sees nothing)
    GPIO_OUT &= ~(1<<18)   (drive LOW)
    GPIO_IN = 0x0000CEAB   → both low
    

    GPIO18 works perfectly. GPIO19 does not follow it. The jumper is missing, loose, or on the wrong pins. Also confirmed independently: the boot-time gpioBaseline self-test (1 ms plain-GPIO toggles) fails with BOTH the RMT RX backend and the GPIO-ISR RX backend — two unrelated capture stacks, same zero edges.

    2. RMT RX capture was broken in software for EVERY driver on classic ESP32 (fixed)

    The E (rmt) rmt_receive(368): partial receive not supported errors that appear in every prior transcript were not noise — they were the capture dying:

    • rmt_rx_channel_5.cpp.hpp set rx_params.flags.en_partial_rx = true unconditionally on IDF ≥ 5.3. Classic ESP32 has no RX ping-pong hardware (SOC_RMT_SUPPORT_RX_PINGPONG absent from its soc_caps.h), so ESP-IDF hard-rejects the receive → every rmt_receive() failed before arming. Fixed: gate on SOC_RMT_SUPPORT_RX_PINGPONG.
    • AutoResearchTest.cpp forces rx_config.use_dma = true for all non-RMT TX drivers (I2S included). Classic ESP32 RMT has no DMA (SOC_RMT_SUPPORT_DMA absent) → rmt_new_rx_channel() failed → RX begin() failed for every I2S capture attempt. Fixed: driver-level graceful fallback to non-DMA.
    • Classic non-DMA one-shot receive caps at the channel's mem blocks; 64 symbols ≈ 2.6 LEDs. Fixed: classic claims 4 blocks (256 symbols ≈ 10 LEDs).

    After these fixes, bench runs show captureWaitResult: -1 → 1 and decodeOutputCapacity: 0 → 32100 — the receive now arms and waits; only the floating pin keeps rawEdgesAfterWait at 0.

    Implication: rawEdgesAfterWait: 0 was NEVER evidence about the I2S TX driver. The RX side could not observe anything.

    3. The crashes were memory exhaustion, not driver/ISR bugs (fixed)

    Decoded the recurring StoreProhibited at PC 0x400d2ece from the ELF disassembly: the faulting instruction stores a vtable pointer into the result of fl::aligned_alloc(8, 120) which returned NULL — the json control-block allocation inside fl::json::set failing on an exhausted heap. The earlier StringHolder StoreProhibited is the same failure shape. Reproduced with driver=RMT too — nothing to do with the I2S engine.

    The "Stack canary watchpoint (loopTask)" panic is the flip side: the RPC → runSingleTest → autoResearchChipsetTiming → capture → FastLED.show() chain is bench-measured ~8,032 bytes deep (backtrace frame arithmetic) — the 8 KB default loopTask stack has zero headroom for an interrupt frame at peak depth. _xt_lowint1 in the backtrace services ALL level-1 interrupts (including the FreeRTOS tick), so the "something fires an I2S interrupt during packScratchBuffer" theory in this issue's description was a misread; any tick at peak depth tripped it. The 2 KB Wave8ByteExpansionLut by-value return materializing on the stack was a real contributor and is fixed (built in place on the engine member).

    Fix pairing on ESP32-WROOM AutoResearch: RX capture buffer 96 KB → 32 KB tier (frees 64 KB heap) + SET_LOOP_TASK_STACK_SIZE(16 KB). Either alone fails: 16 KB stack with the 96 KB buffer = heap OOM (the json crash); 8 KB stack = canary. With the pair, runSingleTest completes crash-free every run.

    4. The I2S TX driver DID have real encoding bugs (fixed, host-test-verified, wire verification pending jumper)

    From Yves's proven driver (git show ce70b5a5c8^:...): his data mask is 1 << (i + 8) with pins routed to DATA_OUT0 + i — i.e. in tx_bits_mod=32 LCD mode, DATA_OUT(n) presents sample bit n + 8; bits 0–7 of each 32-bit sample never reach any pin. The wave8 encoder emitted 2 bytes per pulse, so:

    • Lane 0's data sat at sample bits 0–7 → invisible on every DATA_OUT pin (GPIO18/DATA_OUT0 taps bit 8 = zero-padded lane 8 → constant low). This alone fully explains "boots clean, transmits, zero edges" even with a working RX.
    • Two pulse periods were packed per 32-bit sample → half the intended pulse rate → WS2812-invalid timing.

    Fixes (all in the PR):

    • New wave8I2s1ExpandTo32Samples(): one u32 sample per pulse, 16 lanes at bits 8..23 (lo<<8 | hi<<16), byte-exact host tests against the shared kernel.
    • Engine scratch reworked into 3 regions (32-bit DMA samples / raw wave8 / lane-strided input).
    • Peripheral: linear DMA descriptor chain (4088-byte links, eof only on the last, null-terminated) — a 10-LED 32-bit-sample frame is 7,680 bytes, past the single lldesc 4,092-byte reach the old code silently rejected.
    • tx_bits_mod=32 / tx_fifo_mod=3 and the whole register init stay bit-identical to Yves's proven values (the earlier =16/=1 experiments in this issue were chasing the wrong layer).

    5. Corrections to this issue's prior hypotheses

    • "Stale DMA/ISR state across initialize() cycles" — refuted; the crash reproduces with driver=RMT and is heap exhaustion.
    • "stqe_next = nullptr halts DMA" — untestable then (RX was blind), but nullptr-terminated chains are standard; kept with eof-masked ISR.
    • "Needs a scope" — no scope needed for any of the above; esptool GPIO pokes + ELF disassembly answered everything. A scope (or just the jumper) is only needed for the final waveform check.

    Next steps

    1. Merge PR fix(i2s,rmt-rx): 32-bit sample encoding + classic-ESP32 capture fixes (#3569) #3570 (host tests 345/345, lint clean, bench crash-free; a review round already hardened the transmit kick ordering, tx_stop_en, the RMT RX use_dma rebuild loop, and the RX memory-pool claims).
    2. Reconnect/reseat the GPIO18→GPIO19 jumper on the WROOM COM11 bench (or move it to the correct header pins). Re-run the esptool poke test above to confirm continuity before anything else.
    3. Re-run runSingleTest {driver: I2S, laneSizes: [10], pinTx: 18, pinRx: 19, pattern: ALL_ONES} — with the software fixes merged, rawEdgesAfterWait > 0 is expected, and byte-exact loopback is the acceptance test for I2S classic-ESP32 bring-up on IDF 4/5/6 via AutoResearch loopback + ISR DMA refill #3515 Phase D.
    4. If bytes mismatch (not just missing), the remaining suspects are byte-order flags (tx_msb_right/tx_right_first lane permutation — a lane remap, not a timing issue) — diagnosable from the captured byte pattern, still no scope needed.
  2. zackees commented on Jul 2, 2026

    @zackees
    MemberAuthor

    ✅ RESOLVED — I2S loopback GREEN on the WROOM bench (PR #3571)

    With the jumper confirmed on GPIO 33 → 34 (thanks — the sketch defaults said 18/19, which was never the physical wiring; both pins verified electrically via esptool register pokes):

    runSingleTest {driver: I2S, laneSizes: [10], pinTx: 33, pinRx: 34, pattern: ALL_ONES}
    → passed: true, passedTests: 4/4, captureEvidenceBytes: 120, rawEdgesAfterWait: 256
    

    First wire-verified byte-exact frame from the modern classic-ESP32 I2S engine. RMT control test also 4/4.

    Final root causes (in the order they fell)

    1. Bench wiring: the loopback jumper is on 33→34, not the documented 18/19. Sketch defaults updated (GPIO34 is input-only — ideal RX pin).
    2. RMT RX heap strangulation: edge_capacity ≈ 256k symbols made the accumulation buffer grab 25% of free heap per capture arm on a one-shot chip that can never receive more than its mem block. This was the whole StoreProhibited / LoadStoreAlignment crash family — it only fired once real capture data started flowing. Clamped to hardware capacity.
    3. I2S sample layout: in tx_bits_mod=32 mono LCD mode, I2S1 emits only the high half-word of each 32-bit memory word — DATA_OUT(n) = memory bit 16+n, low 16 bits discarded. (The bit-n+8 model inferred from Yves's code was wrong; established by bisection with the working RMT RX: bits 8..23 → silent, 0..15 → silent, all-32 broadcast → signal.) Lanes now packed at bits 16..31.
    4. Timing must derive from the chipset: pixel clock = 8 pulses / bit-period from the channel's ChipsetTimingConfig (6.4 MHz for WS2812; the 8 MHz hardcode was 25% fast — bench-measured 1.0 µs bit) and the wave8 LUT is built from the channel's T1/T2/T3. Confirmed on the wire: H850 L400 (1-bit) / H300 L950 (0-bit) at a spec-perfect 1250 ns period.
    5. tx_stop_en=1 latches at tx_start (FIFO empty before DMA prefetch) — must stay 0.

    Diagnostics that cracked it: the new peekMem RPC (register dumps without resetting the chip) showed the DMA completing with the pin silent, isolating the fault to the sample-bit mapping; the working RMT RX then served as a logic probe for the bisection.

    Remaining follow-ups (tracked, not blockers)

    Closing this issue: the blocker it tracked (stack canary → later re-diagnosed as the crash family above, plus "no wire edges") is fully resolved and wire-verified. PRs: #3570, #3571.

  3. zackees commented on Jul 2, 2026

    @zackees
    MemberAuthor

    Fixed by #3570 + #3571 — I2S byte-exact loopback verified on the WROOM bench.

  4. moved this from Triage to Done in FastLED Trackeron Jul 2, 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