Skip to content

fix(stm32): rename Esp32SpiBus enumerators off CMSIS macro names (#4113) - #4115

Merged
zackees merged 1 commit into
masterfrom
fix/4113-spi-bus-cmsis-collision
Sep 1, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/4113-spi-bus-cmsis-collision

Conversation

@zackees

@zackees zackees commented Sep 1, 2026 •

Copy link
Copy Markdown
Member

Master is red on seven boards and has been since #4088: arduino_uno_q, nucleo_f429zi, nucleo_f439zi, stm32f103c8_bluepill, stm32f103cb_maplemini, stm32f103tb_tinystm, check_stm32f103c8_bluepill_size.

Cause

fl/spi_bus.h declared

enum class Esp32SpiBus : u8 { AUTO = 0, SPI2 = 2, SPI3 = 3 };

and it reaches every platform via fl/channels/cled_controller.h. On STM32 the CMSIS device headers get there first and define those names as object-like macros:

#define SPI2 ((SPI_TypeDef *) SPI2_BASE)

so the preprocessor rewrote the enumerator into ((SPI_TypeDef *) SPI2_BASE) = 2, — which is exactly the reported diagnostics:

stm32f439xx.h:1278:29: error: expected identifier before '(' token
lib/FastLED/fl/spi_bus.h:15:1: error: expected declaration before '}' token

Fix

Renamed to HOST2 / HOST3 — also closer to what they actually are, ESP-IDF's SPI2_HOST and SPI3_HOST. Wire values unchanged. API churn is negligible: #4088 landed hours ago and the only caller outside the library is its own example.

The alternatives were worse, and worth recording:

  • #undef SPI2 in fl/spi_bus.h — one line, keeps the names, but a core library header would be deleting a CMSIS peripheral macro out from under user sketches on STM32. Rude and a latent surprise.
  • Guard the enum on #if defined(ESP32) — leaves fl::Esp32SpiBus undeclared everywhere else, and core code references it unconditionally.

Regression test

tests/fl/spi_bus_macro_collision.cpp defines CMSIS-shaped macros before including the header, reproducing the failure without an ARM toolchain. I verified both directions: it fails to compile on the old names and passes on the new ones.

It also defines HSPI/VSPI, because Arduino-ESP32 3.1.0+ defines SPI2 as well — this was never STM32-specific, which is why it gets a standing guard rather than a fix-and-forget.

288/288 unit tests, including the new one.

Closes #4113
Refs #4088

Summary by CodeRabbit

  • Breaking Changes

    • Renamed ESP32 SPI bus selectors from SPI2/SPI3 to HOST2/HOST3 to prevent conflicts with platform-defined macros.
    • Update sketches and applications using the previous names.
  • Documentation

    • Updated ESP32 SPI configuration guidance and examples with the new selector names.
  • Bug Fixes

    • Improved compatibility with STM32 and newer Arduino-ESP32 environments.
  • Tests

    • Added regression coverage for SPI selector macro collisions and explicit host selection.

Seven board builds were red on master: arduino_uno_q, nucleo_f429zi,
nucleo_f439zi, stm32f103c8_bluepill, stm32f103cb_maplemini,
stm32f103tb_tinystm, check_stm32f103c8_bluepill_size. Failing since #4088.

`fl/spi_bus.h` declared `enum class Esp32SpiBus { AUTO, SPI2 = 2, SPI3 = 3 }`,
and it reaches every platform through `fl/channels/cled_controller.h`. On STM32
the CMSIS device headers get there first and define those names as object-like
macros:

    #define SPI2 ((SPI_TypeDef *) SPI2_BASE)

so the preprocessor rewrote the enumerator into

    ((SPI_TypeDef *) SPI2_BASE) = 2,

which is exactly the reported `expected identifier before '(' token`, followed
by the cascade that ends at `spi_bus.h:15: expected declaration before '}'`.

Renamed to HOST2 / HOST3, which is also closer to what they are -- ESP-IDF's
SPI2_HOST and SPI3_HOST. The wire values are unchanged. The API churn is
negligible: #4088 landed hours ago and the only caller outside the library is
its own example.

The two alternatives were worse. `#undef SPI2` inside a core FastLED header
would delete a CMSIS peripheral macro out from under user sketches on STM32.
Guarding the enum on `#if defined(ESP32)` leaves the type undeclared everywhere
else, and core code references it unconditionally.

Added `tests/fl/spi_bus_macro_collision.cpp`, which defines CMSIS-shaped macros
before including the header and so reproduces the failure without an ARM
toolchain -- verified it fails to compile on the old names and passes on the
new ones. Arduino-ESP32 3.1.0+ defines SPI2 too, so this was never
STM32-specific and deserves a standing guard rather than a fix-and-forget.

288/288 unit tests, including the new one.

Closes #4113

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ByD5ZKrnFJuchjRmPiQdd5
@coderabbitai

coderabbitai Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 96b5d2f2-3073-4418-96d4-ddae2b16f00f

📥 Commits

Reviewing files that changed from the base of the PR and between 6990cdc and 9cf3c57.

📒 Files selected for processing (7)
  • examples/MultipleEsp32SpiBuses/MultipleEsp32SpiBuses.ino
  • src/fl/spi_bus.h
  • src/platforms/esp/32/README.md
  • src/platforms/esp/32/core/fastspi_esp32_idf.h
  • tests/fl/channels/adapters/spi_channel_adapter.cpp
  • tests/fl/spi_bus_macro_collision.cpp
  • tests/platforms/shared/spi_manager.cpp

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The ESP32 SPI bus enumerators SPI2 and SPI3 were renamed to HOST2 and HOST3. Numeric values, backend host mappings, examples, documentation, and tests were updated. A regression test covers collisions with vendor SPI macros.

Changes

SPI host enum rename

Layer / File(s) Summary
Rename SPI bus enum values
src/fl/spi_bus.h, tests/fl/spi_bus_macro_collision.cpp
The enum uses HOST2 and HOST3 with unchanged values. The regression test verifies macro safety and numeric values.
Update backend and usage sites
src/platforms/esp/32/core/fastspi_esp32_idf.h, examples/MultipleEsp32SpiBuses/MultipleEsp32SpiBuses.ino, src/platforms/esp/32/README.md
The backend, example, and documentation use the renamed identifiers. Controller mappings remain unchanged.
Update SPI host tests
tests/fl/channels/adapters/spi_channel_adapter.cpp, tests/platforms/shared/spi_manager.cpp
Tests use HOST2 and HOST3 without changing their assertions or allocation logic.

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

Merge Risk: 🔵 Low · up to 9cf3c

This fixes a cross-platform compile failure without changing SPI host values or routing, but callers using the former Esp32SpiBus::SPI2 or SPI3 names must migrate and may otherwise fail to compile; the PR is mergeable with explicit owner awareness of that bounded API compatibility risk.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 6 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: renaming Esp32SpiBus enumerators to avoid CMSIS macro collisions.
Linked Issues check ✅ Passed The changes satisfy issue #4113. They rename SPI2 and SPI3 to HOST2 and HOST3, preserve numeric values, avoid undefining platform macros, update all references and documentation, and add regression co…
Out of Scope Changes check ✅ Passed All changes support the linked issue. The updates cover the enum, affected references, documentation, examples, and regression tests. No unrelated code changes are present.
Full details: Linked Issues check

Explanation

The changes satisfy issue #4113. They rename SPI2 and SPI3 to HOST2 and HOST3, preserve numeric values, avoid undefining platform macros, update all references and documentation, and add regression coverage for macro collisions.

Full details: Docstring Coverage

Explanation

Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 6 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/4113-spi-bus-cmsis-collision

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 624b6ce into master Sep 1, 2026
32 of 33 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Sep 1, 2026
@zackees
zackees deleted the fix/4113-spi-bus-cmsis-collision branch September 1, 2026 12:57
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.

fix(stm32): fl::Esp32SpiBus enumerators collide with CMSIS SPI2/SPI3 macros, breaking 7 ARM builds on master

1 participant