Repository navigation
fix(stm32): rename Esp32SpiBus enumerators off CMSIS macro names (#4113) - #4115
Conversation
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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (7)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe ESP32 SPI bus enumerators ChangesSPI host enum rename
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: 🔵 Low · up to 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)
✅ Passed checks (4 passed)
Full details: Linked Issues checkExplanation The changes satisfy issue Full details: Docstring CoverageExplanation 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.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
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.hdeclaredand 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:so the preprocessor rewrote the enumerator into
((SPI_TypeDef *) SPI2_BASE) = 2,— which is exactly the reported diagnostics:Fix
Renamed to
HOST2/HOST3— also closer to what they actually are, ESP-IDF'sSPI2_HOSTandSPI3_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 SPI2infl/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.#if defined(ESP32)— leavesfl::Esp32SpiBusundeclared everywhere else, and core code references it unconditionally.Regression test
tests/fl/spi_bus_macro_collision.cppdefines 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+ definesSPI2as 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
SPI2/SPI3toHOST2/HOST3to prevent conflicts with platform-defined macros.Documentation
Bug Fixes
Tests