Skip to content

Design for SPI using DMA with atsamd51 #1973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sago35 opened this issue Jun 28, 2021 · 3 comments
Closed

Design for SPI using DMA with atsamd51 #1973

sago35 opened this issue Jun 28, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@sago35
Copy link
Member

sago35 commented Jun 28, 2021

I am working on a design for SPI with DMA on atsamd51.

I think we'll always want to use DMA. That is an easier to use API and likely faster overall.
#1176 (comment)

Tx() to always use dma if possible, but at least atsamd51 slows things down in some cases.
If the data is small or the communication speed is slow, using DMA will slow down spi.Tx().

To reduce the slowdown, I am considering implementing the following.
If anyone has any opinions, please let me know.

// The following will be executed with blocking as before
// The internal implementation will be the same as before, without DMA.
spi.Tx(w, r)

// The following will be executed using DMA.
// It will always run asynchronously and can wait for completion by calling spi.
spi.TxDMA(w, r)
spi.Wait()
@sago35
Copy link
Member Author

sago35 commented Jun 28, 2021

D6 (Channel 6) below is the processing time for spi.Tx() / spi.TxDMA().
When using DMA, about 2.5us of time is needed to prepare for the transfer.
However, after 2.5us has elapsed, the DMA will execute, allowing you to perform other operations.
I checked several lengths, and it seems that using DMA is not a problem when the length is 32 bytes or more.

freq : 24MHz

1byte + without DMA = 738ns
image

1byte + with DMA = 4446ns
image

32byte + without DMA = 13.494us
image

32byte + with DMA = 14.798us
image

64byte + without DMA = 26.638us
image

64byte + with DMA = 25.452us
image

@deadprogram deadprogram added the enhancement New feature or request label Jun 30, 2021
@soypat
Copy link
Contributor

soypat commented Nov 6, 2023

I'm linking a implementation of DMA on the RP2040 for your viewing pleasure. It is inspired by Rust's embassy implementation.

https://github.com/tinygo-org/pio/blob/main/rp2-pio/piolib/dma.go

@sago35
Copy link
Member Author

sago35 commented Nov 8, 2023

I plan to switch to the method used in the following PR.

#3985

@sago35 sago35 closed this as completed Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants