Support dynamic selection of DMA channels on STM32 #500
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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
Test results
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.