Skip to content

perf(rp): pack PIO engine DMA bit-planes tightly (#4621) - #4634

Merged
zackees merged 1 commit into
masterfrom
fix/4621-rp-pio-packed-dma
Sep 25, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/4621-rp-pio-packed-dma

Conversation

@zackees

@zackees zackees commented Sep 25, 2026

Copy link
Copy Markdown
Member

Closes #4621. Part of #4601 / #4580.

What changed

  • ChannelEngineRpPio packs each data byte into an 8*lanes-bit column of bit-planes. Planes go MSB first, and lane 0 sits in the MSB of each plane.
  • The column is streamed with DMA transfers of 8 bits (1 lane), 16 bits (2 lanes), 32 bits (4 lanes), or 2×32 bits (8 lanes). Autopull is set to match (8/16/32).
    • Narrow DMA writes are replicated across the FIFO word, so the left-shifting OSR consumes exactly the transfer's bits.
    • The stream is an exact number of transfers, so there is no padding and no partial extra LED symbol.
  • DMA memory is now 1 byte per data byte per lane, down from 32. Example: a 100-LED strip (300 B) drops from 9,600 B of heap DMA buffer to 300 B. An 8-lane batch of 100 LEDs drops from 9,600 B to 2,400 B.
  • XTRA0 strips (GE8822, GW6205) keep the word-per-plane layout, because their zero tails break byte alignment.
  • RpPioTxConfig::packed is opt-in (default false). clockless_rp_pio_auto still sends word-per-plane and sets packed = false explicitly.
  • Completion detection: with packed transfers the last transfer can hold 8 planes. The SM passes the out at terminal_pc without stalling for each of them, so "FIFO empty and PC == terminal" could fire up to 7 bit times early and shorten the latch. isTerminalComplete() now clears the sticky FDEBUG.TXSTALL once the FIFO has drained, and reports done only after the SM stalls on autopull again.

Bloat (bash bloat rp2040 --example BlinkParallel --build)

before after
build flash 338,208 B 338,608 B (+400 B packer)
static RAM 47,527 B 47,527 B

The saving is in the heap-allocated DMA buffer, which the static RAM figure does not show. See the per-data-byte numbers above.

Verification

  • Host tests updated and extended (tests/platforms/arm/rp/rpcommon/channel_engine_rp_pio.cpp):
    • single-lane byte order (00 FF AA 55 -> 0x55AAFF00, 4 × 8-bit transfers);
    • 2-lane 16-bit column;
    • 4- and 8-lane full columns;
    • a new plane/lane ordering test for 4 and 8 lanes;
    • XTRA0 checked to stay unpacked;
    • transfer counts in the concurrency tests.
  • bash test --cpp: all pass. bash lint: clean.
  • bash compile rp2040|rp2350 --examples Blink,BlinkParallel: pass.

Code review (/code-review medium)

  • HIGH: packed defaulted to true, which broke clockless_rp_pio_auto's word-per-plane stream. Fixed: it is now opt-in, and that caller sets it explicitly.
  • LOW (but a real wire-timing bug with packing): early terminal detection. Fixed: detection now uses a TXSTALL-based check.

Hardware

Hardware validation is deferred (maintainer decision), tracked in #4623. Two things to check on hardware: that 8/16-bit DMA writes replicate into the PIO FIFO, and the TXSTALL completion check.

🤖 Generated with Claude Code

ChannelEngineRpPio used one 32-bit DMA word per bit-plane (32 bytes per data
byte). It now packs each data byte into an 8*lanes-bit column of planes and
streams it with 8/16/32-bit DMA transfers and a matching autopull threshold,
so DMA memory equals the data size for 1, 2, 4 and 8 lanes. XTRA0 strips keep
the word-per-plane layout (their zero tails break byte alignment); packing is
opt-in via RpPioTxConfig::packed so the auto-parallel path is unchanged.

Completion detection now waits for an autopull stall (FDEBUG.TXSTALL, cleared
once the FIFO drains): a packed final transfer holds up to 8 planes, so
'FIFO empty and PC at the out instruction' could fire bits early.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zackees
zackees merged commit 977dcaf into master Sep 25, 2026
65 of 66 checks passed
@zackees
zackees deleted the fix/4621-rp-pio-packed-dma branch September 25, 2026 06:26
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Sep 25, 2026
@coderabbitai

coderabbitai Bot commented Sep 25, 2026

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Repository: FastLED/FastLED/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: d4af794f-e319-4ea1-b457-af8f5053b0df

📥 Commits

Reviewing files that changed from the base of the PR and between 1b8e7be and 10006ff.

📒 Files selected for processing (7)
  • src/platforms/arm/rp/rpcommon/channel_engine_rp_pio.cpp.hpp
  • src/platforms/arm/rp/rpcommon/clockless_rp_pio_auto.cpp.hpp
  • src/platforms/arm/rp/rpcommon/irp_pio_tx_peripheral.h
  • src/platforms/arm/rp/rpcommon/rp_pio_peripheral_mock.h
  • src/platforms/arm/rp/rpcommon/rp_pio_tx_peripheral.cpp.hpp
  • src/platforms/arm/rp/rpcommon/rp_pio_tx_peripheral.h
  • tests/platforms/arm/rp/rpcommon/channel_engine_rp_pio.cpp
 _________________________________
< Bug-free code is the new black. >
 ---------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

RP PIO engine: reduce DMA memory (~32 bytes per data byte)

1 participant