Skip to content

drivers: spi: spi_pico_pio: Implement DMA support for 4-wire operation #85807

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

TerryGeng
Copy link
Contributor

@TerryGeng TerryGeng commented Feb 14, 2025

This commit largely mirrors the approach of implementing DMA in the pl022 driver.

Though #85112 is still pending, I figured out that maybe it is enough for users to only specify the DMA channels and figure out the DREQ by myself in the code. I have been working on a personal project that uses DMA with PIO so I think it is to the benefit of the community if I submit it here.

Also included here is an updated version of the spi loopback test that includes a case for PIO with DMA.

struct spi_pico_pio_config {
const struct device *piodev;
const struct pinctrl_dev_config *pin_cfg;
const bool dma_enabled;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you really need this? is dma_config.dev is non NULL it would be the same no?
(this bool is misaligning your struct thus why there is perhaps a way to not introduce it)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I agree with you. I was just mimicking what was done in the pl022 driver, and I think your comment will apply to the pl022 driver equally well.

@TerryGeng TerryGeng force-pushed the pio_spi_dma branch 2 times, most recently from 6481024 to ecc07bb Compare March 30, 2025 15:59
Copy link
Collaborator

@ajf58 ajf58 left a comment

Choose a reason for hiding this comment

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

A couple of nits, but nothing that should be blocking.

size_t chunk_len;
int err = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
size_t chunk_len;
int err = 0;
int err = 0;


key = k_spin_lock(&data->lock);

chunk_len = spi_context_max_continuous_chunk(&data->spi_ctx);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
chunk_len = spi_context_max_continuous_chunk(&data->spi_ctx);
size_t chunk_len = spi_context_max_continuous_chunk(&data->spi_ctx);

nit (?): C99 is 25 years old. Let's declare variables where they're required.

data->rx_count = 0;

pio_sm_clear_fifos(data->pio, data->pio_sm);

while (data->rx_count < chunk_len || data->tx_count < chunk_len) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
while (data->rx_count < chunk_len || data->tx_count < chunk_len) {
while ((data->rx_count < chunk_len) || (data->tx_count < chunk_len)) {

This commit largely mirrors the approach of implementing DMA in the pl022
driver.

Signed-off-by: Terry Geng <[email protected]>
…DMA.

With the addition of a new overlay file that specifies DMA channels.

Signed-off-by: Terry Geng <[email protected]>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Personally, I'd do something like

#include "rpi_pico_pio.overlay"

but perhaps that's a misuse of the device tree compiler. Either way, I like this new style: I think it makes it clear that this is most the same as the former, with a bit more added.

No action required, just sharing my train of thought.

@TerryGeng
Copy link
Contributor Author

@tbursztyka @soburi It has been quite a while since the last activity. Would you guys help with reviewing this PR?

Copy link
Collaborator

@tbursztyka tbursztyka left a comment

Choose a reason for hiding this comment

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

I can't judge much on the pio side, we would need knowledgeable ppl here. But if the test passes that's already a good sign

- EXTRA_CONF_FILE="overlay-rpi-pico-pio.conf"
extra_configs:
- CONFIG_SPI_RPI_PICO_PIO_DMA=y
- CONFIG_DMA=y
Copy link
Collaborator

Choose a reason for hiding this comment

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

Superfluous as the option one line before selects it.

@teburd teburd removed their request for review April 29, 2025 17:11
@ajf58
Copy link
Collaborator

ajf58 commented May 4, 2025

@TerryGeng it looks like this has merge conflicts due to changes on main. Please rebase and push an updated version of your source branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: SPI SPI bus platform: Raspberry Pi Pico Raspberry Pi Pico (RPi Pico)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants