Skip to content

machine/rp2: stop SPI1 transmit from restarting SPI0 DMA - #6010

Merged
deadprogram merged 1 commit into
tinygo-org:devfrom
davecheney:davecheney-rp2-spi-dma-self-chain
Oct 24, 2026
Merged

deadprogram merged 1 commit into
tinygo-org:devfrom
davecheney:davecheney-rp2-spi-dma-self-chain

Conversation

@davecheney

Copy link
Copy Markdown
Contributor

On RP2040 and RP2350, each SPI1 transmit restarted the SPI0 DMA channel. SPI0 then sent bytes from memory after the end of its last buffer. That memory can be freed, reused, or outside the allocation. This has been present since DMA SPI was added in 3b4e543.

With this change, SPI1 transmits no longer affect SPI0.

The traces below are from a Pico 2 W with both buses at 1 MHz. The test sends 64 bytes on SPI0, then 2 bytes on SPI1. Without the fix, SPI0 sends 512 extra clock pulses carrying bytes 0x40 to 0x7f, the unsent half of the buffer. With the fix, SPI0 stays idle.

SPI0 and SPI1 logic traces before and after the fix

Tested on a Pico 2 W. I did not test on a Pico (RP2040), but it uses the same code.

Fixes #6009

Each SPI1 transmit restarted the SPI0 DMA channel, so SPI0 sent
bytes from memory past the end of its previous buffer. The SPI
DMA channels now chain to themselves, and SPI1 no longer affects
SPI0.

Fixes tinygo-org#6009
@davecheney davecheney added this to the 0.44 milestone Oct 24, 2026
davecheney added a commit to davecheney/tinyhci that referenced this pull request Oct 24, 2026

@deadprogram deadprogram left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tested and it does what it claims @davecheney thank you very much. Now merging.

@deadprogram
deadprogram merged commit 99fd63e into tinygo-org:dev Oct 24, 2026
31 checks passed
@davecheney
davecheney deleted the davecheney-rp2-spi-dma-self-chain branch October 24, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

machine/rp2: SPI1 transmit DMA chains to channel 0

2 participants