Repository navigation
fix(rp2040): gate pio_program::used_gpio_ranges on PICO_PIO_VERSION, not SDK ver (Closes #2792) - #2793
Conversation
…not SDK ver
`pio_gen.h` initialized `pio_program::used_gpio_ranges` whenever
`PICO_SDK_VERSION_MAJOR >= 2`, but that field is gated *per-chip* in the
pico-sdk 2.x header:
typedef struct pio_program {
const uint16_t *instructions;
uint8_t length;
int8_t origin;
uint8_t pio_version;
#if PICO_PIO_VERSION > 0
uint8_t used_gpio_ranges;
#endif
} pio_program_t;
RP2040 defines `PICO_PIO_VERSION = 0` (no field), RP2350 defines
`PICO_PIO_VERSION = 1` (field present). So on RP2040 + pico-sdk 2.x the
designated initializer references a member that genuinely doesn't exist,
breaking the build:
pio_gen.h:57:5: error: 'pio_program' has no non-static data member
named 'used_gpio_ranges'
RP2350 / RP2350B happened to keep building because their `PICO_PIO_VERSION`
makes the field real.
Fix: split the guard so `pio_version` (unconditional in 2.x) stays on
`PICO_SDK_VERSION_MAJOR >= 2`, and `used_gpio_ranges` is additionally
gated on `PICO_PIO_VERSION > 0`, matching the SDK header exactly.
Local verification blocked by a separate Windows-only fbuild toolchain
cache problem (arduino-pico 4.5.3 `memmap_default.ld` missing from
`~/.fbuild/...`); the failure fires at the linker-script-template stage
before any FastLED compile unit is built, on rp2040, rp2350, and rp2350B
alike. PR CI on rp2040 / rp2350 / rp2350B is the authoritative check —
the diff is logically correct by inspection against the SDK header.
Closes #2792
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
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 (3)
✅ Files skipped from review due to trivial changes (2)
📝 WalkthroughWalkthroughInitialize ChangesPIO Program SDK 2.x Compatibility
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/platforms/arm/rp/rpcommon/pio_gen.h`:
- Around line 66-68: Wrap the .used_gpio_ranges initialization in
spi_hw_2_rp.cpp.hpp with the same PICO_PIO_VERSION guard used in pio_gen.h: when
adding the line that sets .used_gpio_ranges = 0 (currently under the
PICO_SDK_VERSION_MAJOR >= 2 check), nest it inside `#if` defined(PICO_PIO_VERSION)
&& PICO_PIO_VERSION > 0 so .used_gpio_ranges is only compiled for targets with
PICO_PIO_VERSION > 0; update the block around the struct/initializer in
spi_hw_2_rp.cpp.hpp to mirror pio_gen.h’s conditional compilation.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ae1283a3-7058-4857-a476-02cdad7b419c
📒 Files selected for processing (1)
src/platforms/arm/rp/rpcommon/pio_gen.h
Extend the same PICO_PIO_VERSION guard fix from pio_gen.h to the three SPI-via-PIO sites (spi_hw_2_rp, spi_hw_4_rp, spi_hw_8_rp), which had the identical bug pattern: `.used_gpio_ranges = 0` gated only on `PICO_SDK_VERSION_MAJOR >= 2`. RP2040 builds against pico-sdk 2.x define PICO_PIO_VERSION == 0, so the field is genuinely absent and referencing it breaks the build. Wrap each in `#if defined(PICO_PIO_VERSION) && PICO_PIO_VERSION > 0` to mirror pio_gen.h. CodeRabbit only flagged spi_hw_2_rp; spi_hw_4_rp and spi_hw_8_rp were caught by the same review pattern (Error Fixing Policy: fix all encountered errors). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Fixes the `build_rp2040.yml` workflow that was red on master with:
```
src/platforms/arm/rp/rpcommon/pio_gen.h:57:5: error:
'pio_program' has no non-static data member named 'used_gpio_ranges'
```
Closes #2792. Continues the README badge sweep started in #2779 / #2780 (AVR) / #2785 (STM32 GIGA) / #2788 (Apollo3).
What's broken
`pio_gen.h` was zero-initializing two pico-sdk 2.x fields (`pio_version` and `used_gpio_ranges`) behind a single guard:
```cpp
#if defined(PICO_SDK_VERSION_MAJOR) && PICO_SDK_VERSION_MAJOR >= 2
.pio_version = 0,
.used_gpio_ranges = 0,
#endif
```
But `used_gpio_ranges` is gated by a different macro in the SDK header — per-chip, not per-SDK:
```c
// pico-sdk/src/rp2_common/hardware_pio/include/hardware/pio.h
typedef struct pio_program {
const uint16_t *instructions;
uint8_t length;
int8_t origin;
uint8_t pio_version;
#if PICO_PIO_VERSION > 0
uint8_t used_gpio_ranges;
#endif
} pio_program_t;
```
RP2040 defines `PICO_PIO_VERSION = 0` (field genuinely absent). RP2350 defines `PICO_PIO_VERSION = 1` (field present). So RP2350 / RP2350B builds happened to stay green; RP2040 broke because the designated initializer references a member that doesn't exist on this chip.
What this PR changes
Split the guard so each field is gated by its correct condition:
```cpp
#if defined(PICO_SDK_VERSION_MAJOR) && PICO_SDK_VERSION_MAJOR >= 2
.pio_version = 0,
#if defined(PICO_PIO_VERSION) && PICO_PIO_VERSION > 0
.used_gpio_ranges = 0,
#endif
#endif
```
Comment block updated to explain both gates and reference #2792 + the original #2727 follow-up that introduced the workaround.
Test plan
Local verification was blocked by a separate Windows-only fbuild toolchain cache issue (arduino-pico 4.5.3 `memmap_default.ld` missing from `~/.fbuild/prod/cache/platforms/earlephilhower-arduino-pico/...`); the failure fires at the linker-script-template stage on `rp2040`, `rp2350`, and `rp2350B` alike — before any FastLED translation unit is compiled — so the compile-stage diff cannot be exercised on this workstation.
PR CI on rp2040 / rp2350 / rp2350B is the authoritative verification. The diff is logically correct by inspection against the SDK header: RP2040 (`PICO_PIO_VERSION = 0`) now omits the `used_gpio_ranges` initializer (was the bug); RP2350/RP2350B (`PICO_PIO_VERSION = 1`) still include it (no regression vs the green baseline).
`bash lint` clean.
Scope
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Documentation