Skip to content

feat(rp): centralize PIO and DMA resource ownership - #3662

Merged
zackees merged 1 commit into
masterfrom
feat/rp2040-phase0-resource-owner
Jul 15, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/rp2040-phase0-resource-owner

Conversation

@zackees

@zackees zackees commented Jul 15, 2026 •

Copy link
Copy Markdown
Member

Summary

  • add a host-testable RP resource ledger for PIO state machines, DMA channels, and GPIO ownership
  • add a Pico-SDK adapter serialized by an RP hardware spinlock
  • migrate existing RP clockless, parallel, and 2/4/8-lane SPI allocation paths to transactional claim/release handling

Validation

  • bash test tests/platforms/arm/rp/rpcommon/rp_resource_ledger.cpp
  • uv run --no-sync python ci/lint_cpp/run_all_checkers.py --no-rust
  • fbuild .build/pio/rp2040 build -e rp2040

bash lint's Rust checker cannot run locally because the installed Rust toolchain lacks x86_64-pc-windows-msvc; the Python-only C++ checker passed. fbuild deployment compilation passed, but the separate portless CDC-to-BOOTSEL transition regression is documented on FastLED/fbuild#1040.

Closes #3653

Summary by CodeRabbit

  • New Features

    • Improved RP2040/RP2350 hardware resource management across clockless LED, parallel, and SPI drivers.
    • Prevented conflicts when multiple drivers share PIO state machines, DMA channels, or GPIO pins.
    • Added safer resource cleanup and retry handling when initialization is unsuccessful.
  • Tests

    • Added coverage for resource conflicts, invalid claims, resource reuse, and concurrent access.

@zackees
zackees merged commit a878e2c into master Jul 15, 2026
9 checks passed
@zackees
zackees deleted the feat/rp2040-phase0-resource-owner branch July 15, 2026 11:13
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jul 15, 2026
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jul 15, 2026
@coderabbitai

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: df66a453-ed6c-4e54-9270-b5ed75c2e64f

📥 Commits

Reviewing files that changed from the base of the PR and between 7f4ac4a and 0012e4c.

📒 Files selected for processing (9)
  • src/platforms/arm/rp/rpcommon/clockless_rp_pio.h
  • src/platforms/arm/rp/rpcommon/clockless_rp_pio_auto.cpp.hpp
  • src/platforms/arm/rp/rpcommon/clockless_rp_pio_parallel.h
  • src/platforms/arm/rp/rpcommon/rp_pio_dma_resource_manager.h
  • src/platforms/arm/rp/rpcommon/rp_resource_ledger.h
  • 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
  • tests/platforms/arm/rp/rpcommon/rp_resource_ledger.cpp

📝 Walkthrough

Walkthrough

RP2040/RP2350 PIO drivers now share a resource manager backed by an atomic ownership ledger. Clockless and SPI drivers use it to claim, retry, clean up, and release PIO state machines, DMA channels, and GPIO pins.

Changes

RP resource ownership

Layer / File(s) Summary
Resource ledger contract and validation
src/platforms/arm/rp/rpcommon/rp_resource_ledger.h, tests/platforms/arm/rp/rpcommon/rp_resource_ledger.cpp
Adds atomic ownership tracking for PIO state machines, DMA channels, and pins, with bounds, release, reset, and concurrent-claim tests.
Pico SDK resource manager
src/platforms/arm/rp/rpcommon/rp_pio_dma_resource_manager.h
Adds synchronized SDK-backed claim and release APIs with ledger mirroring, rollback, and RP2040/RP2350 PIO mapping.
Clockless PIO integration
src/platforms/arm/rp/rpcommon/clockless_rp_pio.h, src/platforms/arm/rp/rpcommon/clockless_rp_pio_auto.cpp.hpp, src/platforms/arm/rp/rpcommon/clockless_rp_pio_parallel.h
Routes clockless resource acquisition and teardown through the manager, including retries and intermediate-failure cleanup.
SPI PIO integration
src/platforms/arm/rp/rpcommon/spi_hw_*_rp.cpp.hpp
Routes dual, quad, and octal SPI PIO/DMA/pin ownership through the manager during initialization and cleanup.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ClocklessController
  participant RpPioDmaResourceManager
  participant PicoSDK
  participant RpResourceLedger
  ClocklessController->>RpPioDmaResourceManager: claimPioStateMachine
  RpPioDmaResourceManager->>PicoSDK: claim PIO state machine
  RpPioDmaResourceManager->>RpResourceLedger: record PIO ownership
  ClocklessController->>RpPioDmaResourceManager: claimDmaChannel
  RpPioDmaResourceManager->>PicoSDK: claim DMA channel
  RpPioDmaResourceManager->>RpResourceLedger: record DMA ownership
  ClocklessController->>RpPioDmaResourceManager: claimPins
  RpPioDmaResourceManager->>RpResourceLedger: record pin ownership
  ClocklessController->>RpPioDmaResourceManager: release resources during cleanup
Loading

Possibly related issues

  • #3647 — The shared allocator and ownership coordination implement the issue’s RP PIO/DMA resource-manager objective.
  • #3654 — The ledger and manager support the planned RpPioRxDevice resource lifecycle.
  • #3658 — The manager coordinates PIO programs, state machines, DMA channels, and pins.
  • #3648 — The refactor supports shared resource contracts and PIO channel-driver implementation.
✨ 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 feat/rp2040-phase0-resource-owner

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.

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.

feat(rp2040): phase 0 — resource contracts and mock peripherals

1 participant