Skip to content

fix(rp2040): gate pio_program::used_gpio_ranges on PICO_PIO_VERSION, not SDK ver (Closes #2792) - #2793

Merged
zackees merged 2 commits into
masterfrom
fix/rp2040-used-gpio-ranges-guard
Jun 5, 2026
Merged

zackees merged 2 commits into
masterfrom
fix/rp2040-used-gpio-ranges-guard

Conversation

@zackees

@zackees zackees commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

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

    • Improved PIO-related initialization to ensure compatibility with SDK 2.x and across RP hardware variants.
  • Documentation

    • Expanded comments clarifying conditional initialization behavior and differences across SDK versions and targets.

…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]>
@coderabbitai

coderabbitai Bot commented Jun 5, 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: Pro

Run ID: dcda82c8-a87c-4ec4-b0d6-3cf6afe3e1b1

📥 Commits

Reviewing files that changed from the base of the PR and between 5363a90 and 2c3b78c.

📒 Files selected for processing (3)
  • src/platforms/arm/rp/rpcommon/spi_hw_2_rp.cpp.hpp
  • src/platforms/arm/rp/rpcommon/spi_hw_4_rp.cpp.hpp
  • src/platforms/arm/rp/rpcommon/spi_hw_8_rp.cpp.hpp
✅ Files skipped from review due to trivial changes (2)
  • src/platforms/arm/rp/rpcommon/spi_hw_4_rp.cpp.hpp
  • src/platforms/arm/rp/rpcommon/spi_hw_8_rp.cpp.hpp

📝 Walkthrough

Walkthrough

Initialize pio_program fields only when those fields exist for the target/SDK: explicitly set .pio_version under Pico SDK 2.x guards and only zero .used_gpio_ranges when PICO_PIO_VERSION is defined and > 0; apply same guard across SPI PIO program initializers and expand explanatory comments.

Changes

PIO Program SDK 2.x Compatibility

Layer / File(s) Summary
Core add_clockless_pio_program initializer update
src/platforms/arm/rp/rpcommon/pio_gen.h
.pio_version is explicitly initialized to 0 under PICO_SDK_VERSION_MAJOR >= 2; .used_gpio_ranges is zero-initialized only when PICO_PIO_VERSION is defined and > 0. Comment block expanded to document macro-gating behavior.
SPI PIO program initializers (dual/quad/octal)
src/platforms/arm/rp/rpcommon/spi_hw_2_rp.cpp.hpp, src/platforms/arm/rp/rpcommon/spi_hw_4_rp.cpp.hpp, src/platforms/arm/rp/rpcommon/spi_hw_8_rp.cpp.hpp
Each SPI PIO program initializer now guards .used_gpio_ranges = 0 with #if defined(PICO_PIO_VERSION) && PICO_PIO_VERSION > 0, leaving .pio_version initialization where applicable and adding comments on field availability.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Poem

🐰
A rabbit tunes the struct with care,
Guards in place for fields that’re there,
Versions checked, no surprises found,
PIOs initialize safe and sound,
Hopping on to greener ground.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. 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 accurately summarizes the main change: conditional gating of pio_program::used_gpio_ranges on PICO_PIO_VERSION for RP2040/RP2350 compatibility.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/rp2040-used-gpio-ranges-guard

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 787de45 and 5363a90.

📒 Files selected for processing (1)
  • src/platforms/arm/rp/rpcommon/pio_gen.h

Comment thread src/platforms/arm/rp/rpcommon/pio_gen.h Resolved
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]>
@zackees
zackees merged commit 0796395 into master Jun 5, 2026
10 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 5, 2026
@zackees
zackees deleted the fix/rp2040-used-gpio-ranges-guard branch June 5, 2026 19:56
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.

broken build: rp2040 — pio_program::used_gpio_ranges gated on wrong macro (PICO_SDK_VERSION_MAJOR instead of PICO_PIO_VERSION)

1 participant