Skip to content

STM32 SPI: Add support for asynchronous DMA transfer#103396

Open
gautierg-st wants to merge 2 commits intozephyrproject-rtos:mainfrom
gautierg-st:spi_dma_async
Open

STM32 SPI: Add support for asynchronous DMA transfer#103396
gautierg-st wants to merge 2 commits intozephyrproject-rtos:mainfrom
gautierg-st:spi_dma_async

Conversation

@gautierg-st
Copy link
Contributor

@gautierg-st gautierg-st commented Feb 3, 2026

This PR adds the support of asynchronous DMA transfer for STM32 SPI.
It is largely inspired by #73855.

@zephyrbot zephyrbot added area: Devicetree Binding PR modifies or adds a Device Tree binding area: Tests Issues related to a particular existing or missing test area: SPI SPI bus area: Boards/SoCs platform: STM32 ST Micro STM32 labels Feb 3, 2026
@gautierg-st gautierg-st force-pushed the spi_dma_async branch 2 times, most recently from e6555f0 to dc13c51 Compare February 3, 2026 14:27
@gautierg-st
Copy link
Contributor Author

Rebased to fix conflicts

@gautierg-st
Copy link
Contributor Author

Rebased to fix conflicts again.

erwango
erwango previously approved these changes Feb 17, 2026
@gautierg-st gautierg-st added this to the v4.4.0 milestone Feb 20, 2026
CONFIG_SPI_STM32_BUSY_FLAG_TIMEOUT,
k_yield());
#else
/* wait until spi is no more busy (spi TX fifo is really empty) */
Copy link
Contributor

Choose a reason for hiding this comment

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

this says spi TX fifo is really empty but this is spi_stm32_dma_rx_done()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

Comment on lines 1709 to 1711
#ifndef CONFIG_SPI_ASYNC
ARG_UNUSED(dma_dev);
#endif /* !CONFIG_SPI_ASYNC */
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: don't bother #ifdef-ing this, it's fine to have an ARG_UNUSED() when the thing actually is used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

Comment on lines 383 to 402
#ifdef CONFIG_SPI_STM32_ERRATA_BUSY
WAIT_FOR(!ll_spi_dma_busy(spi),
CONFIG_SPI_STM32_BUSY_FLAG_TIMEOUT,
k_yield());
#else
/* wait until spi is no more busy (spi TX fifo is really empty) */
while (ll_spi_dma_busy(spi) && LL_SPI_IsEnabled(spi)) {
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_spi)
uint32_t width = SPI_WORD_SIZE_GET(data->ctx.config->operation);
/* The TXC flag is not raised at the end of 9, 17 or 25
* bit transfer, so disable the SPI in these cases to avoid being stuck.
*/
if (!cfg->fifo_enabled &&
((width == 9U) || (width == 17U) || (width == 25U))) {
k_usleep(1000);
ll_disable_spi(spi);
}
#endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_spi) */
}
#endif /* CONFIG_SPI_STM32_ERRATA_BUSY */
Copy link
Contributor

Choose a reason for hiding this comment

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

Already present in old code, but nevertheless:

  1. adding a (void) in front of WAIT_FOR would make it clearer that timeout is acceptable
  2. as far as I can tell, this runs in ISR context? so k_usleep() is not allowed
Copy link
Contributor Author

Choose a reason for hiding this comment

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

(void) added and k_usleep removed.

Add DMA support for asynchronous SPI transfer for STM32.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
Remove CONFIG_SPI_ASYNC=n from the conf file for STM32 DMA.
Since CONFIG_SPI_ASYNC is set in prj.conf, this change enabled ASYNC
for STM32 SPI DMA test.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Boards/SoCs area: Devicetree Binding PR modifies or adds a Device Tree binding area: SPI SPI bus area: Tests Issues related to a particular existing or missing test platform: STM32 ST Micro STM32

6 participants