Skip to content

Conversation

wdx04
Copy link

@wdx04 wdx04 commented Oct 2, 2025

Summary of changes

On newer STM32 devices, the DMA channels may be chosen arbitrarily.
This PR allows the use of macros MBED_ANY_GPDMA_MODULE and MBED_ANY_DMA_CHANNEL in DMALinkInfo declarations, so that we can dynamically select unused DMA channels at runtime on the supported STM32 devices.

Impact of changes

The definition of the DMAHandlePointer type has been changed. DMAHandlePointer is now a struct that, in addition to containing a DMA handle pointer, also includes the DMA instance and channel index.

The stm_free_dma_link function now accpets a pointer to DMAHandlePointer.

The spi_s/qspi_s/ospi_s structs now contain dmaHandle members of the DMAHandlePointer type, instead of dmaInitialized members.

A new function is implemented to find an unused DMA channel:

/**
 * @brief Find a free DMA channel for a DMA link with MBED_ANY_DMA_CHANNEL
 *
 * @param dmaLink DMA link instance with MBED_ANY_DMA_CHANNEL
 * @param freeDmaLink DMA link instance with the actual DMA instance and channel indexes
 *
 * @return true if a free DMA channel is found
 * @return false if a free DMA channel is not found
 */
bool stm_find_free_dma_channel(DMALinkInfo const * dmaLink, DMALinkInfo * freeDmaLink);

When the RTOS is present, a mutex object is used for synchronization between threads. New functions stm_init_dma_mutex/stm_lock_dma_mutex/stm_unlock_dma_mutex are introduced to manage the mutex ojbect. stm_init_dma_mutex is called in the mbed_sdk_init function. stm_lock_dma_mutex/stm_unlock_dma_mutex are called in stm_init_dma_link/stm_free_dma_link functions.

Migration actions required

Documentation

None.


Pull request type

[] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[X] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[X] Tests / results supplied as part of this PR

I have tested the QSPI DMA on three boards:

STM32L475E-IOT01A: this board does not have a DMAMUX, so fixed DMA instance and channel indexes are used.
custom STM32H750VB board: the DMA instance is fixed(MDMA), but the DMA channel is dynamically selected.
custom STM32H563VI board: both DMA instance and channel are dynamically selected.

I'll test more boards later.


wdx04 added 2 commits October 2, 2025 09:43
Tested on STM32L475-IOT01A, STM32H563VI(custom), STM32H750VB(custom) boards.
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.

1 participant