Skip to content

fix(i2s-esp32dev): wrap IDF 6 LL calls in PERIPH_RCC_ATOMIC critical section - #3514

Merged
zackees merged 1 commit into
masterfrom
fix/i2s-idf6-rcc-atomic
Jul 1, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/i2s-idf6-rcc-atomic

Conversation

@zackees

@zackees zackees commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Defect fix on the Phase 3 IDF 6 compat shim that landed in #3511. Verified against real ESP-IDF master source that the LL API calls need to be wrapped in PERIPH_RCC_ATOMIC() { } — otherwise the caller fails to compile against IDF 6 because __DECLARE_RCC_ATOMIC_ENV isn't in scope.

Verification against real ESP-IDF master (fa8039b5)

Fetched components/esp_hal_i2s/esp32/include/hal/i2s_ll.h from espressif/esp-idf@master:

static inline void i2s_ll_enable_bus_clock(int i2s_id, bool enable) { ... }
/// use a macro to wrap the function, force the caller to use it in a critical section
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
#define i2s_ll_enable_bus_clock(...) do { \
        (void)__DECLARE_RCC_ATOMIC_ENV; \
        i2s_ll_enable_bus_clock(__VA_ARGS__); \
    } while(0)

static inline void i2s_ll_reset_register(int i2s_id) { ... }
#define i2s_ll_reset_register(...) do { \
        (void)__DECLARE_RCC_ATOMIC_ENV; \
        i2s_ll_reset_register(__VA_ARGS__); \
    } while(0)

The macro-form of both functions requires __DECLARE_RCC_ATOMIC_ENV to be declared in scope. My compat shim from #3511 called them raw, which would fail compile.

Correct caller pattern (from components/esp_driver_i2s/i2s_platform.c in the same tree):

PERIPH_RCC_ATOMIC() {
    i2s_ll_enable_bus_clock(id, true);
    i2s_ll_reset_register(id);
    i2s_ll_enable_core_clock(I2S_LL_GET_HW(id), true);
}

The PERIPH_RCC_ATOMIC() macro (in esp_private/periph_ctrl.h) provides the __DECLARE_RCC_ATOMIC_ENV variable and manages the critical section.

Fix

#include "esp_private/periph_ctrl.h"  // added

inline bool fl_i2s_periph_enable(int port) {
    // ...
#else
    PERIPH_RCC_ATOMIC() {                        // <-- added wrap
        i2s_ll_enable_bus_clock(port, true);
        i2s_ll_reset_register(port);
    }
    return true;
#endif
}

Test plan

  • bash test --cpp: 344/344 pass (host suite unchanged — shim is IDF 6-only)
  • bash lint --cpp: clean
  • Symbol signatures verified against real ESP-IDF master source
  • CI (esp32dev IDF 5.x — should be no-op, LL path is IDF 6-only)
  • Real IDF 6 silicon bench — tracked under I2S classic-ESP32 unified path: Phases 2, 4-8 (follow-up to #3509) #3512 Phase 7 when pioarduino ships an IDF 6 platform binding

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved I2S reliability on ESP32 platforms by making clock and reset operations safer during enable/disable transitions.
    • Reduced the chance of intermittent audio or peripheral startup issues in newer ESP-IDF releases.

…section

The IDF 6 compat shim landed in #3511 calls `i2s_ll_enable_bus_clock` +
`i2s_ll_reset_register` directly. Verified against real ESP-IDF master
source at `components/esp_hal_i2s/esp32/include/hal/i2s_ll.h`: both
functions have macro-form wrappers in the header that require
`__DECLARE_RCC_ATOMIC_ENV` to be declared in scope, which means the
current shim would fail to compile on real IDF 6 because that variable
isn't in scope of the caller.

The correct pattern (as used by IDF 6's own `components/esp_driver_i2s/
i2s_platform.c`) is to wrap the LL calls in `PERIPH_RCC_ATOMIC() { }`
from `esp_private/periph_ctrl.h`. That macro provides the required
`__DECLARE_RCC_ATOMIC_ENV` variable and manages the peripheral RCC
critical section acquire/release.

## Symbol verification (against espressif/esp-idf@master)

Signatures confirmed to match the shim:
- `static inline void i2s_ll_enable_bus_clock(int i2s_id, bool enable)`
- `static inline void i2s_ll_reset_register(int i2s_id)`

The public-safe caller pattern from `i2s_platform.c`:
```c
PERIPH_RCC_ATOMIC() {
    i2s_ll_enable_bus_clock(id, true);
    i2s_ll_reset_register(id);
    i2s_ll_enable_core_clock(I2S_LL_GET_HW(id), true);
}
```

This shim now matches that pattern.

## Verification

- `bash test --cpp`: 344/344 pass (compat shim is IDF 6-only, host tests
  unchanged).
- Real IDF 6 silicon bench: still tracked under #3512 Phase 7 (external
  blocker — pioarduino IDF 6 platform binding not shipping yet).

Part of #3509 (which is closed) — this is a defect fix on the Phase 3
compat shim that landed in #3511.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit e57f3ff into master Jul 1, 2026
7 of 9 checks passed
@coderabbitai

coderabbitai Bot commented Jul 1, 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: 60258c2f-db84-4b24-8ac1-03b6d94caf76

📥 Commits

Reviewing files that changed from the base of the PR and between 01622e6 and dfe1803.

📒 Files selected for processing (1)
  • src/platforms/esp/32/drivers/i2s/i2s_periph_compat.h

📝 Walkthrough

Walkthrough

The ESP-IDF 6.x+ code path in i2s_periph_compat.h now includes esp_private/periph_ctrl.h and wraps I2S LL bus clock enable/disable and register reset calls inside PERIPH_RCC_ATOMIC() critical sections within fl_i2s_periph_enable and fl_i2s_periph_disable.

Changes

I2S RCC atomic wrapping

Layer / File(s) Summary
Include periph_ctrl.h for atomic macro
src/platforms/esp/32/drivers/i2s/i2s_periph_compat.h
The ESP-IDF 6.x+ include block adds esp_private/periph_ctrl.h alongside hal/i2s_ll.h, with comments noting the atomic requirement for macro-form LL calls.
Wrap enable/disable calls in PERIPH_RCC_ATOMIC()
src/platforms/esp/32/drivers/i2s/i2s_periph_compat.h
fl_i2s_periph_enable and fl_i2s_periph_disable now execute i2s_ll_enable_bus_clock, i2s_ll_reset_register, and the disable call inside PERIPH_RCC_ATOMIC() critical sections instead of calling them directly.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant fl_i2s_periph_enable
  participant PERIPH_RCC_ATOMIC
  participant i2s_ll

  Caller->>fl_i2s_periph_enable: call enable(port)
  fl_i2s_periph_enable->>PERIPH_RCC_ATOMIC: enter critical section
  PERIPH_RCC_ATOMIC->>i2s_ll: i2s_ll_enable_bus_clock(port, true)
  PERIPH_RCC_ATOMIC->>i2s_ll: i2s_ll_reset_register(port)
  PERIPH_RCC_ATOMIC-->>fl_i2s_periph_enable: exit critical section
Loading
✨ 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/i2s-idf6-rcc-atomic

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.

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jul 1, 2026
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jul 1, 2026
zackees added a commit that referenced this pull request Jul 1, 2026
… Phase A) (#3518)

Per #3516 meta / #3515 Phase A: enable a real IDF 6.0 CI target for
the classic-ESP32 I2S clockless driver, and remove the compile-time
`FASTLED_ESP32_I2S` selector so the driver is bound at runtime via the
modern channel API instead of by preprocessor flag.

## Changes

### Runtime-selected I2S driver
- **`src/FastLED.h`**: `FASTLED_ESP32_I2S` becomes a deprecation warning.
  Compat-shim message directs users to
  `FastLED.enableDriver<fl::Bus::FLEX_IO, 0>()` for runtime selection.
- **`src/platforms/esp/32/core/fastled_esp32.h`**: driver header include
  is now gated on `FASTLED_ESP32_HAS_I2S` (feature flag — auto-enabled
  on classic ESP32) instead of the removed selector. The driver code
  always compiles on classic ESP32; `--gc-sections` elides it when
  unused.
- **`src/platforms/esp/clockless.h`**: removed the `#if defined(FASTLED_ESP32_I2S)`
  branch of the `ClocklessController` alias. Legacy `addLeds<>` continues
  to route to the RMT / PARLIO / SPI default. The I2S path is reached
  through the modern channel API.

### IDF 6.0 CI target
- **`ci/boards.py`**: new `ESP32_IDF_6_PIOARDUINO` platform URL pointing
  at `pioarduino/platform-espressif32#prep_IDF6` (commit `98230ad4aa`,
  2026-05-25). That branch's `platform.json` pins
  `framework-arduinoespressif32` to `arduino-esp32/archive/master.zip`
  — arduino-esp32 master built on ESP-IDF v6.0.1+.
- **`ci/boards.py`**: new `ESP32DEV_IDF6` board using the above,
  `platform_needs_install=True`, no driver-selector defines.
- **`.github/workflows/build_esp32dev_idf6.yml`**: compile-smoke against
  Blink + SpecialDrivers/ESP/DriverTest. Fires on esp/ + i2s/ + ci/
  changes, plus manual PR triggers.

## Why the flag removal matters

- **gc-sections elision**: the driver code compiles unconditionally on
  classic ESP32 (via `FASTLED_ESP32_HAS_I2S`), and gc-sections drops
  it when the user's sketch doesn't reach into the I2S code path. This
  matches the FastLED convention documented in
  `src/fl/channels/README.md` — one binary, multiple drivers, linker
  keeps only what's referenced.
- **User-facing selection**: users get I2S by explicitly asking for it
  at runtime, not by defining a compile-time symbol. This aligns with
  the modern channel-manager surface (`FastLED.enableDriver<>`,
  `Channel::create<>`) that the rest of the driver work in #3516
  builds on.

## Verification

- `bash test --cpp`: 344/344 pass on host (this is a pure gate change —
  no behavioral impact on the host code path).
- `bash lint --cpp`: clean.
- CI compile against IDF 6: exercised by the new `build_esp32dev_idf6.yml`
  workflow once this PR merges to master. The `i2s_periph_compat.h`
  `PERIPH_RCC_ATOMIC()` path (from #3514) will be hit end-to-end for the
  first time.

## What this does NOT do

- Does NOT change legacy `addLeds<WS2812, PIN, GRB>()` behavior on IDF
  4.x/5.x — that path continues to route through RMT / PARLIO / SPI as
  before. Users who previously set `-DFASTLED_ESP32_I2S=1` get a
  deprecation warning and must migrate to
  `FastLED.enableDriver<fl::Bus::FLEX_IO, 0>()` for the same behavior.
- Does NOT touch the classic Yves driver ISR / DMA machinery. That's
  #3512 Phase 2 and follows the Phase B/C/D validation fence.

Part of #3516 / #3515 Phase A.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Jul 1, 2026
New `src/platforms/esp/32/drivers/i2s/README.md` documenting the
classic-ESP32 I2S parallel-out clockless driver as it stands today
(post #3479 restore + #3511/#3514 IDF6 compat +
#3518-#3520 selector cleanup + Phase 5 unity re-include).

Covers:

- **Files**: purpose of each `.h`/`.cpp.hpp` in the directory
- **User-facing binding today**: legacy `addLeds<>` via
  `-DFASTLED_ESP32_I2S=1` (production) vs modern channel-manager
  (not there yet — depends on Phase 4)
- **ESP-IDF version compat table**: IDF 4.x/5.x production; IDF 6.x
  compiles via the `i2s_periph_compat.h` shim (bench validation
  pending real WROOM + IDF 6 platform binding)
- **Streaming ISR DMA refill invariant**: the whole-point-of-I2S
  streaming pattern that any future refactor must preserve. Points at
  the ISR handler location and lists the three concrete guarantees.
- **Global state**: acknowledges the 10+ file-scope statics tracked
  under #3489, with the migration path via Phase 6.
- **Known bugs**: #1165 (`I2S_DEVICE=1` doesn't drive output)
  and #1384 (blocking `showPixels()`) with their respective
  fix paths through Phase 2 / Phase 4.
- **References**: cross-links to every open sub-issue, meta issue,
  and previous PR in the driver-dev umbrella.

Part of #3516 / #3512 Phase 8.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees deleted the fix/i2s-idf6-rcc-atomic 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