Skip to content

fix(esp32c3): gate fast_isr.S on __riscv_atomic, not bare __riscv - #2577

Merged
zackees merged 1 commit into
masterfrom
fix/esp32c3-fast-isr-atomic-gate
May 30, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/esp32c3-fast-isr-atomic-gate

Conversation

@zackees

@zackees zackees commented May 30, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Every esp32c3 example build on master fails at:
    fast_isr.S:150: Error: unrecognized opcode 'lr.w t0,(t4)', extension 'zalrsc' required
    fast_isr.S:160: Error: unrecognized opcode 'sc.w t5,t1,(t4)', extension 'zalrsc' required
    
  • Root cause: the file is gated only by #ifdef __riscv, which matches every Espressif RISC-V chip — including ESP32-C3 / C2 (RV32IMC, no atomic extension). The companion C++ glue gpio_isr_rx_mcpwm.cpp.hpp already excludes those chips via SOC_MCPWM_SUPPORTED (C3/C2 lack MCPWM), so the assembly was the only file leaking into those builds.
  • Fix: require __riscv_atomic (GCC's standard predefine for the A extension) alongside __riscv. C6 / H2 / C5 / P4 (RV32IMAC+) still compile the fast ISR; C3 / C2 cleanly skip it.

Fixes #2576

Test plan

  • bash lint clean (cpp_linting / etc.).
  • CI: every esp32c3 workflow should now reach actual compilation.
  • Sanity: esp32c6 / esp32h2 / esp32p4 workflows must continue to include the fast ISR (no regression).

Generated with Claude Code (https://claude.com/claude-code)

Summary by CodeRabbit

  • Bug Fixes
    • Improved GPIO interrupt handler compatibility detection for ESP32 platforms to ensure proper functionality only on supported hardware cores.

Review Change Stack

`fast_isr.S` uses RV32A load-reserved / store-conditional (`lr.w` /
`sc.w`) for the lock-free write-index update, but was gated only by
`#ifdef __riscv`. That matches **every** Espressif RISC-V chip —
including ESP32-C3 / C2 which are RV32IMC (no A extension). On those
chips the assembler rejects the opcodes:

  fast_isr.S:150: Error: unrecognized opcode `lr.w t0,(t4)', extension `zalrsc' required
  fast_isr.S:160: Error: unrecognized opcode `sc.w t5,t1,(t4)', extension `zalrsc' required

breaking every `esp32c3` example build on master before any user code
is compiled.

The companion C++ glue `gpio_isr_rx_mcpwm.cpp.hpp` already gates on
`SOC_MCPWM_SUPPORTED` which excludes C3/C2 (no MCPWM peripheral), so
the assembly was the only file leaking into those builds.

Fix: require `__riscv_atomic` (GCC's standard predefine for the A
extension) alongside `__riscv`. C6 / H2 / C5 / P4 (RV32IMAC+) still
compile the fast ISR; C3 / C2 cleanly skip it.

Fixes #2576
@coderabbitai

coderabbitai Bot commented May 30, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8a987f43-6a5b-4af6-b7d1-ace3eb86ef20

📥 Commits

Reviewing files that changed from the base of the PR and between b2254c1 and 82601a8.

📒 Files selected for processing (1)
  • src/platforms/esp/32/drivers/gpio_isr_rx/fast_isr.S

📝 Walkthrough

Walkthrough

Tightens preprocessor guard in fast GPIO ISR assembly from __riscv to __riscv && __riscv_atomic, excluding ESP32-C3/C2 RISC-V cores without atomic instruction support, and updates symmetric closing directive with clarifying comments.

Changes

Atomic Extension Guard Tightening

Layer / File(s) Summary
Tighten atomic extension preprocessor guard
src/platforms/esp/32/drivers/gpio_isr_rx/fast_isr.S
Opening preprocessor conditional at line 49 is changed from #ifdef __riscv to #if defined(__riscv) && defined(__riscv_atomic) with added comments explaining the RV32A lr.w/sc.w dependency and core alignment. Closing #endif at line 191 is updated to match.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

  • FastLED/FastLED#2502: Also affects src/platforms/esp/32/drivers/gpio_isr_rx/fast_isr.S compilation through library.json srcFilter configuration.

Poem

🐰 A guard made tight, atomic and right,
No RV32IMC cores in sight—
C3 and C2 skip the dance,
While C6 atomics prance! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding __riscv_atomic as a gating condition alongside __riscv for the fast_isr.S file, which directly addresses the ESP32-C3 compilation issue.
Linked Issues check ✅ Passed The code change fully satisfies the objectives from issue #2576: it implements the proposed fix by gating fast_isr.S on both __riscv and __riscv_atomic, preventing assembler errors on ESP32-C3/C2 while preserving compilation for chips with the A extension (C6/H2/C5/P4).
Out of Scope Changes check ✅ Passed All changes are directly within scope: the file modification adds the __riscv_atomic guard and an explanatory comment as specified in the issue, with no extraneous alterations or unrelated changes detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/esp32c3-fast-isr-atomic-gate

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 and usage tips.

@zackees
zackees merged commit bc8f831 into master May 30, 2026
5 of 7 checks passed
@zackees
zackees deleted the fix/esp32c3-fast-isr-atomic-gate branch May 30, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

esp32c3: fast_isr.S uses RISC-V atomic ops (lr.w/sc.w) but C3 lacks the A extension

1 participant