Is HAL_SPI_Transmit_DMA faster than HAL_SPI_Transmit?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-30 7:51 AM
Hi!
Is HAL_SPI_Transmit_DMA faster than HAL_SPI_Transmit?
If yes: Do I need to enable DMA for the SPI to make this work?
Solved! Go to Solution.
- Labels:
-
DMA
-
SPI
-
STM32Cube MCU Packages
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-01 2:55 AM
Setting up DMA takes time so will always be slower for small transfers. For larger transfers DMA is better but only if there is something else you want to do while the transfer is happening. Otherwise speed will be the same.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-30 7:58 AM
Hello,
Yes, transferring larger amounts of data is faster using DMA. The data transfer process is outsourced to the DMA controller and the MCU can continue working. Again, yes, DMA must be configured for use with the specific SPI bus. You should give a look at the CubeRepository examples:
For example for STM32F4 Series:
..\STM32Cube\Repository\STM32Cube_FW_F4_V1.26.1\Projects\STM32F429I-Discovery\Examples\SPI
There are three examples for SPI communication via polling, interrupt and DMA available.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-30 8:17 AM
Thank you. I tried with HAL_SPI_Transmit_DMA and it was much slower than HAL_SPI_Transmit.
In this case, I transfered maximum 1 to 4 bytes of data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-30 11:20 PM
Your question isnt right. Speed of SPI is defined aka clock. Little change is interword times when is used IRQ vs DMA.
Your code must have fail when dont work...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-31 4:04 PM
Yes. But isin't DMA SPI the same as regular SPI without time out?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-01 12:55 AM
Speed is same because SPI have FIFO
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-01 2:55 AM
Setting up DMA takes time so will always be slower for small transfers. For larger transfers DMA is better but only if there is something else you want to do while the transfer is happening. Otherwise speed will be the same.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-01 11:27 AM
So there no reason to call SPI_DMA then if I want to transmit data?
