Skip to content

fix(rp): return released pins to hi-Z instead of leaving them muxed - #4218

Merged
zackees merged 1 commit into
masterfrom
fix/rp-restore-pin-function
Sep 8, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/rp-restore-pin-function

Conversation

@zackees

@zackees zackees commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Four RP teardown paths release their pins in the resource ledger but never undo the muxing initialize() applied. The pad keeps being driven by a peripheral the ledger reports as free.

File Claimed with Restored?
rp_spi_peripheral gpio_set_function(GPIO_FUNC_SPI) no
rp_uart_peripheral gpio_set_function(UART_FUNCSEL_NUM) undoes gpio_set_outover only — pin stays muxed
spi_hw_8_rp pio_gpio_init × 8 data + clock no
spi_hw_2_rp pio_gpio_init × 2 data + clock no

Why this is worth fixing

A released-but-still-driven pin is an output-vs-output short as soon as another driver takes that net. That is reachable on the current bench rather than theoretical: the RP2350W fixture has a soldered GPIO0 ↔ GPIO1 bridge, and adding the GPIO3 → GPIO0 jumper that SPI0 loopback requires would put the PL022 and a PIO driver on one wire for the duration of a mixed driver sweep.

The idiom already exists in this codebase

Two RP paths get this right today and were used as the model — no new convention invented:

  • rp_pio_tx_peripheral.cpp.hpp:190-192
  • rp_pio_spi_peripheral.cpp.hpp:177-186

Both do gpio_set_function(pin, GPIO_FUNC_SIO) then gpio_set_dir(pin, GPIO_IN) before releasePins. This PR applies that same sequence to the four that omitted it, so a ledger release now means the hardware is genuinely released.

Verification

The SPI loopback legs themselves cannot be functionally exercised on this fixture — they need the GPIO3 → GPIO0 and GPIO11 → GPIO8 jumpers documented on #3899 — so this is verified as compile-correct and non-regressing rather than as a behavioural SPI test.

Provenance

Found while writing up the unreachable-path wiring constraints for #3899. I had asserted the jumpers were safe to leave fitted, then checked, and they were not. Same defect class as #4214, which fixes the matching omission in ~ClocklessController.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KkufoNxfnNRU9psT3R9F51

Summary by CodeRabbit

  • Bug Fixes
    • SPI and UART peripherals now restore pins to a safe, high-impedance input state during cleanup.
    • SPI pins correctly return to their default GPIO configuration after use, preventing them from remaining assigned to peripheral hardware.

Four RP teardown paths released their pins in the resource ledger but
never undid the muxing that initialize() applied, so the pad kept being
driven by a peripheral the ledger reported as free:

  rp_spi_peripheral   gpio_set_function(GPIO_FUNC_SPI), no restore at all
  rp_uart_peripheral  undid gpio_set_outover but not the UART funcsel
  spi_hw_8_rp         pio_gpio_init on 8 data pins + clock, no restore
  spi_hw_2_rp         pio_gpio_init on 2 data pins + clock, no restore

A released-but-still-driven pin is an output-vs-output short the moment
another driver takes that net, which on a loopback fixture is reachable
rather than theoretical: the RP2350W bench has a soldered GPIO0<->GPIO1
bridge, and adding the GPIO3->GPIO0 jumper that SPI0 loopback needs
would put the PL022 and a PIO driver on one wire across a driver sweep.

The codebase already had the right idiom in the two paths that got it
right -- rp_pio_tx_peripheral.cpp.hpp:190-192 and
rp_pio_spi_peripheral.cpp.hpp:177-186 both restore GPIO_FUNC_SIO and
set the pin to an input before releasing. This applies the same
sequence to the four that omitted it, so a ledger release now means the
hardware is genuinely released.

Found while writing up the unreachable-path wiring constraints for
#3899, after asserting the jumpers were safe and then checking.

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

coderabbitai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Review Change StackReview 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: Advanced

Run ID: 037af76c-4b69-4242-8535-4bf8dd27cb5a

📥 Commits

Reviewing files that changed from the base of the PR and between 3ee4009 and ff57688.

📒 Files selected for processing (4)
  • src/platforms/arm/rp/rpcommon/rp_spi_peripheral.cpp.hpp
  • src/platforms/arm/rp/rpcommon/rp_uart_peripheral.cpp.hpp
  • src/platforms/arm/rp/rpcommon/spi_hw_2_rp.cpp.hpp
  • src/platforms/arm/rp/rpcommon/spi_hw_8_rp.cpp.hpp

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


📝 Walkthrough

Walkthrough

Changes

RP pin state restoration

Layer / File(s) Summary
Peripheral deinitialization
src/platforms/arm/rp/rpcommon/rp_spi_peripheral.cpp.hpp, src/platforms/arm/rp/rpcommon/rp_uart_peripheral.cpp.hpp
SPI and UART deinitialization restore owned pins to SIO input mode before releasing their resource reservations.
PIO SPI cleanup
src/platforms/arm/rp/rpcommon/spi_hw_2_rp.cpp.hpp, src/platforms/arm/rp/rpcommon/spi_hw_8_rp.cpp.hpp
PIO SPI cleanup restores data and clock pins to SIO input mode before releasing them through the resource manager.

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

Merge Risk: ⚪ Minimal · up to ff576

RP SPI, UART, and PIO-SPI teardown now returns released pins to high-impedance SIO input state, preventing peripheral muxing from persisting after release. The change is ready to merge.

🚥 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%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 4 files. 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 and concisely describes the main change: restoring released RP pins to hi-Z instead of leaving them muxed.
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.
  • 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/rp-restore-pin-function

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 1b7e5dd into master Sep 8, 2026
22 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Sep 8, 2026
@zackees
zackees deleted the fix/rp-restore-pin-function branch November 5, 2026 05:53
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.

1 participant