Repository navigation
fix(channels): guard Bus enum against CMSIS UART/SPI/I2S register macros - #2575
Conversation
On SAM3X8E (Arduino Due), the CMSIS header `sam3x8e.h` defines
peripheral pointer macros:
#define UART ((Uart *)0x400E0800U)
#define SPI ((Spi *)0x40008000U)
// ...
These get pulled in transitively through `platforms/is_platform.h`
before `fl/channels/bus.h` declares:
enum class Bus : fl::u8 {
..., SPI, I2S, UART, ...
};
The preprocessor doesn't understand `enum class` scoping — bare
`UART`/`SPI`/`I2S` macro-expand inside the enum body, producing:
sam3x8e.h:489:20: error: expected identifier before '(' token
bus.h:54:5: note: in expansion of macro 'UART'
cascading to "'Bus' was not declared in this scope" for every TU that
includes bus.h. Every `sam3x8e_due` example build on master fails this
way before any code is compiled.
Fix: wrap both `bus.h` (enum definition + DefaultBus specializations +
busName() switch) and `bus_priorities.h` (constexpr lookup over
`Bus::SPI` / `Bus::I2S` / `Bus::UART`) with
`#pragma push_macro` / `#undef` / `#pragma pop_macro` for the three
colliding names. `pop_macro` at the end restores CMSIS's original
register macros for any downstream TU that needs them as register
pointers.
GCC, Clang, MSVC, IAR, and ARM Compiler all support the
push_macro/pop_macro pragmas. No public API change — `fl::Bus::SPI`,
`fl::Bus::I2S`, `fl::Bus::UART` still mean exactly what they did.
ESP32 is unaffected (its register types are typedefs, not bare-name
macros). All other non-platform-specific code paths that mention these
enumerators are inside `bus.h` / `bus_priorities.h` or under
`platforms/esp/32/` (ESP32-only — no CMSIS-SAM collision).
Fixes #2574
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR adds preprocessor macro guards to ChangesMacro guards for Bus enum definitions
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 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 |
Summary
sam3x8e_dueandsam3x8e_due (digix merged)workflow on master fails before any code is compiled: Atmel CMSIS definesUART/SPI/I2Sas bare-name peripheral pointer macros, andenum class Bus { ..., SPI, I2S, UART, ... }infl/channels/bus.his preprocessor-expanded to garbage.bus_priorities.hconstexpr lookup with#pragma push_macro/#undef/#pragma pop_macrofor the three colliding names.pop_macroat the end restores CMSIS's original register macros for downstream TUs.fl::Bus::SPI/fl::Bus::I2S/fl::Bus::UARTstill mean exactly what they did.Fixes #2574
Test plan
bash lintclean (cpp_linting / meson_linting / etc.).bash test fl_channels_bus_traits --cpp.sam3x8e_dueandsam3x8e_due (digix merged)workflows should now reach actual compilation.Generated with Claude Code (https://claude.com/claude-code)
Summary by CodeRabbit
Release Notes