Skip to content

Drivers: spi: stm32: add support for DMA in asynchronous mode #73855

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

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

Conversation

ajarmouni-st
Copy link
Collaborator

@ajarmouni-st ajarmouni-st commented Jun 6, 2024

Adds support for DMA in asynchronous mode.

Tested on nucleo_f767zi& nucleo_f429zi successfully.
west build -p always -b nucleo_f429zi tests/drivers/spi/spi_loopback -T drivers.spi.stm32_spi_async_dma.loopback

drivers.spi.stm32_spi_async_dma.loopback test case passes on stm32h573i_dk, nucleo_f207zg, nucleo_f429zi, nucleo_f746zg
But fails on nucleo_wb55rg, nucleo_wl55jc, nucleo_g474re, nucleo_h743zi

@ajarmouni-st ajarmouni-st added area: SPI SPI bus area: DMA Direct Memory Access platform: STM32 ST Micro STM32 labels Jun 6, 2024
@ajarmouni-st
Copy link
Collaborator Author

Cc @dgastonochoa

@777aker
Copy link

777aker commented Jul 23, 2024

In the async callback if rx is NULL (ie I only want to use TX) no clean up is performed and therefore you can only send data once and it thinks the transaction is ongoing forever waiting for RX.

EDIT: I realized my fix creates problems with it being asynchronous

@777aker
Copy link

777aker commented Jul 25, 2024

Ok, I fixed it. Basically, you enable interrupts and setup spi interrupts. When dma callback is called disable dma and enable spi interrupts. Then, when the transfer is complete and the spi interrupt is called disable spi interrupts enable dma and shift the dma buffers. My work is working on upstreaming this. Hopefully, I can post code soon.

Green line is the user thread doing work. Tan line is clock, red is mosi, yellow chip select.
 
tmp_17467132-243d-4065-b51b-92774060d56b.png

@erwango
Copy link
Member

erwango commented Jul 30, 2024

@777aker @ajarmouni-st is no longer contributing to this project. Don't hesitate to take his commits in your PR for contribution.

Then, note that RTIO API is probably the way to go to support real async on this driver (see #67327)

Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Sep 29, 2024
@kaarelen
Copy link

kaarelen commented Oct 1, 2024

@777aker will you finish this pull request? I'm ready to provide any possible help, but I'm kinda new into Zephyr, so I need some guidance.

I really want to make this feature happen!

@github-actions github-actions bot removed the Stale label Oct 2, 2024
@JarmouniA JarmouniA force-pushed the dev_stm32_spi_async_dma branch from d5124fd to a39f972 Compare October 2, 2024 17:58
Implement async SPI with DMA.

Signed-off-by: Abderrahmane Jarmouni <[email protected]>
Add STM32 async DMA testcase.

Signed-off-by: Abderrahmane Jarmouni <[email protected]>
@JarmouniA JarmouniA force-pushed the dev_stm32_spi_async_dma branch from a39f972 to 8a35c28 Compare October 22, 2024 19:43
@erwango
Copy link
Member

erwango commented Nov 22, 2024

@JarmouniA, @777aker Are you still working on this ?
Looking at this PR, I was actually wondering if it would make things any simpler to limit DMA support to SPI ASYNC API. Any opinion ?

@JarmouniA
Copy link
Collaborator

@JarmouniA, @777aker Are you still working on this ?

@erwango Not at the moment.

Looking at this PR, I was actually wondering if it would make things any simpler to limit DMA support to SPI ASYNC API. Any opinion ?

That would probably upset many users that only want DMA for higher transfer speeds, & don't care much about the asynchronous part.

@JarmouniA
Copy link
Collaborator

Also, I think the implementation should be reworked with this suggestion, it will make it more robust & probably much simpler.

When dma callback is called disable dma and enable spi interrupts. Then, when the transfer is complete and the spi interrupt is called disable spi interrupts enable dma and shift the dma buffers.

Copy link

github-actions bot commented Feb 3, 2025

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Feb 3, 2025
@github-actions github-actions bot closed this Feb 17, 2025
@erwango erwango reopened this Feb 17, 2025
@github-actions github-actions bot removed the Stale label Feb 18, 2025
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Apr 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: DMA Direct Memory Access area: SPI SPI bus platform: STM32 ST Micro STM32 Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants