Skip to content

fix(i2s,rmt-rx,autoresearch): I2S loopback GREEN on WROOM bench (#3569) - #3571

Merged
zackees merged 1 commit into
masterfrom
fix/rmt-rx-oneshot-heap-clamp-3569
Jul 2, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/rmt-rx-oneshot-heap-clamp-3569

Conversation

@zackees

@zackees zackees commented Jul 2, 2026 •

Copy link
Copy Markdown
Member

Bench milestone: the modern classic-ESP32 I2S engine passes byte-exact loopback on real hardware. runSingleTest {driver: I2S, laneSizes: [10], pattern: ALL_ONES} on ESP32-WROOM COM11: passed: true, passedTests: 4/4, captureEvidenceBytes: 120, rawEdges: 256. RMT control also 4/4. This closes the wire-verification gap that #3569/#3568/#3515 Phase D were blocked on.

Bench-derived driver corrections

  1. Sample layout: I2S1 in tx_bits_mod=32 mono LCD mode emits only the high half-word of each 32-bit memory word — DATA_OUT(n) = memory bit 16+n; the low 16 bits are discarded. Found by bisection against a working RMT-RX loopback (lanes at bits 8..23 → silent; 0..15 → silent; all-32 broadcast → clean waveform). The expansion pass now packs the 16 lanes at bits 16..31.
  2. Timing derived from the chipset, not hardcoded: pixel clock = 8 pulses / bit-period from the channel's ChipsetTimingConfig (6.4 MHz for WS2812 — the previous 8 MHz hardcode gave a 1.0 µs bit, 25% out of spec), and the wave8 LUT is built from the channel's T1/T2/T3 so the wire waveform matches what the chipset and the RX decoder expect.
  3. tx_stop_en stays 0 — bench-tested =1 latches the auto-stop at tx_start (FIFO momentarily empty before DMA prefetch lands) and nothing ever ships.

Crash-family fix (RMT RX heap)

Callers pass edge_capacity ≈ 256k symbols; on one-shot chips (no RX ping-pong) the accumulation buffer grabbed 25% of free heap per capture arm for capacity that can never arrive — cascading into the null-alloc StoreProhibited / LoadStoreAlignment crashes once real capture data started flowing. Both the accumulation size and the non-DMA bounce buffer now clamp to the hardware one-shot capacity.

AutoResearch bench plumbing

  • Classic-ESP32 default pins 18/19 → 33/34 (matches the physical COM11 harness — the 18/19 pair was never connected, proven electrically; GPIO34 is input-only, ideal RX). Also stops the boot-time shared RX on a dead pin from hogging 4 RMT mem blocks.
  • Edge diagnostic buffers: stack FixedVector → fl::vector.
  • New peekMem RPC — reads MMIO/SRAM without resetting the chip; this is what showed the DMA completing (out_eof/out_total_eof raw, EOF descriptor consumed, pin routed) while the pin stayed silent, isolating the fault to the sample-bit mapping.

Verification

  • bash test --cpp --clean: 345/345.
  • bash lint: clean.
  • Live bench: I2S 4/4 byte-exact, RMT 4/4 byte-exact, no crashes across repeated runs.

Related: #3569, #3568, #3526, #3515 Phase D.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a remote memory inspection command for the AutoResearch tools, returning a range of 32-bit values when given a valid address and count.
    • Improved ESP32 timing handling so waveform output adapts more closely to the active channel’s configured timing.
  • Bug Fixes

    • Updated default ESP32 GPIO wiring for AutoResearch examples.
    • Reduced receive-buffer sizing risks on ESP32 RMT capture paths.
    • Adjusted I2S waveform encoding and stop behavior for more reliable transmission.

Bench milestone: runSingleTest {driver: I2S, 10 LEDs, ALL_ONES + 3 more
patterns} passes byte-exact on ESP32-WROOM COM11 (passedTests 4/4,
captureEvidenceBytes 120, rawEdges 256) — first wire-verified frame
from the modern classic-ESP32 I2S engine. RMT control also 4/4.

I2S driver (bench-derived corrections):
- Sample layout: I2S1 in tx_bits_mod=32 mono LCD mode emits only the
  HIGH half-word of each 32-bit memory word — DATA_OUT(n) = memory bit
  16+n, low 16 bits discarded. Found by bisection with the working RMT
  RX (bits 8..23 → silent, 0..15 → silent, all-32 broadcast → signal).
  Expansion now packs lanes at bits 16..31.
- Pixel clock derived from the channel's chipset timing (8 pulses /
  bit period) instead of hardcoded 8 MHz — the hardcode gave a 1.0 µs
  WS2812 bit (25% fast); wave8 LUT likewise built from the channel's
  T1/T2/T3 so the wire waveform matches what the chipset (and the RX
  decoder) expects. Lane 0's timing wins for multi-lane batches.
- tx_stop_en stays 0: bench-tested =1 latches the auto-stop at
  tx_start (FIFO momentarily empty before DMA prefetch lands) and
  nothing ever ships.

RMT RX (classic ESP32 one-shot chips):
- Clamp mBufferSize + the non-DMA bounce buffer to the hardware
  one-shot capacity — callers pass edge_capacity ≈ 256k symbols and
  the accumulation buffer grabbed 25% of free heap per capture arm,
  cascading into the null-alloc StoreProhibited / LoadStoreAlignment
  crash family once real capture data started flowing.

AutoResearch:
- Classic-ESP32 default bench pins 18/19 → 33/34 (GPIO34 input-only =
  ideal RX; the physical COM11 harness is wired 33→34 — the 18/19 pair
  was never connected, verified electrically). This also stops the
  boot-time shared RX on a dead pin from hogging 4 RMT mem blocks.
- Edge diagnostic buffers: stack FixedVector → fl::vector (2 KB+ off
  the loopTask peak).
- New peekMem RPC: read MMIO/SRAM words without resetting the chip
  (esptool pokes reset the peripheral state under investigation) —
  this is what pinpointed the DMA-completed-but-silent-pin state.

Co-Authored-By: Claude Fable 5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 2, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9d1e8190-4b50-421b-8685-36c7d7f11ace

📥 Commits

Reviewing files that changed from the base of the PR and between 1e9fc62 and b7b77bc.

📒 Files selected for processing (9)
  • examples/AutoResearch/AutoResearchPlatform.h
  • examples/AutoResearch/AutoResearchRemoteSystemMethods.cpp
  • examples/AutoResearch/AutoResearchTest.cpp
  • src/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.h
  • src/platforms/esp/32/drivers/rmt_rx/rmt_rx_5/rmt_rx_channel_5.cpp.hpp
  • tests/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp

📝 Walkthrough

Walkthrough

This PR updates AutoResearch example GPIO defaults to GPIO 33/34, adds a peekMem RPC diagnostic method, and switches diagnostic edge buffers to heap allocation. It also fixes ESP32 I2S1 driver behavior: derived pixel clock timing, disabled TX auto-stop, corrected wave8 32-bit sample bit packing (with updated tests), and non-DMA RMT RX buffer size clamping.

Changes

AutoResearch example changes

Layer / File(s) Summary
Classic ESP32 GPIO pin defaults
examples/AutoResearch/AutoResearchPlatform.h
defaultTxPin()/defaultRxPin() for classic ESP32 changed from GPIO 18/19 to GPIO 33/34, with revised wiring comments.
peekMem RPC handler
examples/AutoResearch/AutoResearchRemoteSystemMethods.cpp
New peekMem RPC validates addr/count, reads aligned 32-bit words from a given address, and returns success or InvalidArgs error responses.
Heap-allocated edge timing buffers
examples/AutoResearch/AutoResearchTest.cpp
dumpRawEdgeTiming() and capture() diagnostics replace stack-based FixedVector edge buffers with heap-allocated fl::vector buffers.

ESP32 I2S1/RMT driver fixes

Layer / File(s) Summary
Derived pixel clock and LUT timing
src/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp.hpp
show() derives pixel_clk_hz from active channel total_period_ns() with a WS2812 fallback instead of a fixed 8 MHz clock; packScratchBuffer() overrides wave8 LUT timing (T1/T2/T3/RESET/name) from the first channel with non-zero timing.
TX auto-stop disable
src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp
initialize() sets conf1.tx_stop_en to 0, moving underrun handling to the completion path.
Wave8 32-bit bit-mapping fix and tests
src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp.hpp, wave8_encoder_i2s1.h, tests/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp
wave8I2s1ExpandTo32Samples packs lanes as (lo<<16)|(hi<<24) instead of (lo<<8)|(hi<<16); docs updated to describe the new 16..31 bit mapping; tests updated to assert the new byte layout using per-test timing overrides.
Non-DMA RMT RX buffer clamp
src/platforms/esp/32/drivers/rmt_rx/rmt_rx_5/rmt_rx_channel_5.cpp.hpp
begin() clamps mBufferSize and allocateAndArm() conditionally sizes the non-DMA buffer to kNonDmaRxSymbols when RX ping-pong is unsupported.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Host
  participant AutoResearchRemoteControl
  participant MemoryBus

  Host->>AutoResearchRemoteControl: RPC "peekMem" {addr, count}
  AutoResearchRemoteControl->>AutoResearchRemoteControl: validate addr alignment and count range
  alt invalid args
    AutoResearchRemoteControl-->>Host: {success:false, error:"InvalidArgs"}
  else valid args
    AutoResearchRemoteControl->>MemoryBus: read count 32-bit words from addr
    MemoryBus-->>AutoResearchRemoteControl: values[]
    AutoResearchRemoteControl-->>Host: {success:true, addr, values}
  end
Loading
sequenceDiagram
  participant ChannelEngineI2sEsp32Dev
  participant ChannelData
  participant I2sPeripheralEsp32DevEsp

  ChannelEngineI2sEsp32Dev->>ChannelData: read total_period_ns() from active channel
  ChannelEngineI2sEsp32Dev->>ChannelEngineI2sEsp32Dev: compute pixel_clk_hz = 8e9 / bit_period_ns
  ChannelEngineI2sEsp32Dev->>I2sPeripheralEsp32DevEsp: initialize(clk=pixel_clk_hz)
  ChannelEngineI2sEsp32Dev->>ChannelData: override wave8 LUT T1/T2/T3/RESET from channel timing
  ChannelEngineI2sEsp32Dev->>ChannelEngineI2sEsp32Dev: rebuild mWave8ByteLut if timing changed
Loading

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#3455: Both modify AutoResearchPlatform.h's defaultTxPin()/defaultRxPin() GPIO mapping logic for classic ESP32.
  • FastLED/FastLED#3528: Both touch the wave8_encoder_i2s1 implementation, this PR fixing the specific bit/lane mapping used for DMA output.
  • FastLED/FastLED#3549: Both touch packScratchBuffer() wave8 LUT timing derivation, with this PR implementing timing-derived overrides.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/rmt-rx-oneshot-heap-clamp-3569

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@zackees
zackees merged commit 933a0f4 into master Jul 2, 2026
12 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jul 2, 2026
zackees added a commit that referenced this pull request Jul 2, 2026
…back GREEN (#3572) (#3573)

Bench validation sweep on ESP32-WROOM COM11 (jumper GPIO33->34), all
four channel drivers now pass byte-exact 10-LED loopback, 4/4 patterns:
RMT, I2S, UART, SPI.

UART (the one real bug, fixes #3572): buildWave10Lut best-fit rounding
put WS2812B-V5's 1-symbol at 2 pulses (490 ns) — only 245 ns above the
0-symbol, inside real WS281x parts' sampling-threshold band and
flapping the bench decoder's 500 ns threshold (wrong bytes / failed
decodes). Enforce a 400 ns minimum absolute wire separation, widening
T1H upward: V5 -> (1,3) = 245 vs 735 ns, matching the proven legacy
WS2812 LUT shape. canRepresentTiming mirrors the bump (T1H tolerance
widened by exactly the deliberate separation growth). Canonical WS2812
(1,3), SK6812 (1,4) and slow chipsets (WS2811-400, 500 ns pulses)
unchanged. New unit test pins the V5 (1,3) shape.

SPI needed no code change — its earlier bench crashes were the #3571
heap-exhaustion family. The driver is already async at the channel
level (spi_device_queue_trans ISR-driven DMA + non-blocking poll());
the remaining #3179 scope (ISR-chunked ring-buffer streaming) is a
peak-memory optimization, unchanged by this PR.

Co-authored-by: Claude Fable 5 <[email protected]>
zackees added a commit that referenced this pull request Jul 2, 2026
…#3576 Phase 3) (#3581)

Classic ESP32's RMT receiver has no ping-pong and no DMA — captures are
one-shot into channel RAM, ~256 symbols ≈ 10 WS2812 LEDs (#3571). This
adds an I2S0-based oversampling backend that removes the ceiling:
bench-verified byte-exact at 100 and 160 LEDs (16x the RMT limit).

Backend (RxBackend::I2S_RX / RxDeviceType::I2S_RX, classic only):
- I2S0 standard master-RX serial mode samples the RX pin (via the
  I2S0I_DATA_IN15 matrix signal — the classic SD-in quirk) at 16 MHz
  into a 16 KB circular DMA ring; CLZ-based run-length extraction on
  the draining task; 4-phase pair decode matching RMT semantics.
- Packed level runs (4 bytes each) capped at 8000 (~165 LEDs, 32 KB) —
  sized against classic's free heap; unbounded storage OOM'd at 500.
- Claims I2S0 through the cross-driver port-claim registry; begin()
  fails cleanly (fall back to RMT) when the second clockless bank or
  clocked-SPI owns the block.

Bench-derived silicon findings (all encoded as comments):
- The RX serial sampler clocks SD at the CLKM rate directly
  (80/clkm_div_num); rx_bck_div only shapes the unused BCK output.
- Rates above ~16 MHz (clkm_div_num < 5) capture only zeros from real
  pads; the matrix-constant source still samples — input path ceiling.
- rx_msb_shift=1 (Philips) required; PDM block forced off.
- Bit order: bit31 of each 32-bit FIFO word is the earliest sample.
- Per-bit extraction cannot keep up at 16 Msps (mid-frame gaps past
  ~50 LEDs) — CLZ word-run scanning fixes it.

Plumbing:
- RxChannel::begin() recreates the device when config.backend differs;
  a fresh default config silently reverted explicit backends to
  PLATFORM_DEFAULT/RMT. New RxChannel::backend() accessor; the
  AutoResearch capture path now carries it (root-cause fix).
- runSingleTest gains an optional rxBackend param (RMT/ISR/I2S_RX).
- g_i2s_rx_debug[] bench counters (peekMem-able, 32 bytes) kept for
  future bring-up.
- fl/channels/README.md: RX capture backends section.

Bench (WROOM COM11, GPIO33->34): I2S_RX byte-exact 4/4 at 10, 100 and
160 LEDs; regression I2S/I2S0/RMT/UART/SPI (RMT backend) 4/4 each.
Host: 345/345, lint clean.

Co-authored-by: Claude Fable 5 <[email protected]>
@zackees
zackees deleted the fix/rmt-rx-oneshot-heap-clamp-3569 branch August 21, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant