cancel
Showing results for 
Search instead for 
Did you mean: 

Can you use SPI in DMA mode interfacing with a SD card? If so is there an example code?

ESaat.1
Associate
 
3 REPLIES 3

Most of us looking for speed/performance would use the SDIO/SDMMC peripheral.

Do multiple blocks, so you're writing 8KB or 32KB in aligned chunks

SPI with DMA should be viable

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
BNist.1
Associate II

Hey!

I am having the same question. Did you find any tutorial for interfacing the 2 of them?

I'm not convinced you are approaching the problem correctly,

Ask yourself why you need this level of guidance to succeed in a task.

The DMA and POLLED uses case for SPI aren't hugely different, you aren't changing the chip select across the transfer, and you're using the machine to iterate a block of data over the channel rather than walking in manually.

Find other SPI DMA examples and APPLY them here.

Generally you'll want the Write/Read together as the writes generate the clocks, and the interface is symmetrical. When READing blocks from the media, break down the transfer into 512 byte units so your output buffer of dummy bytes doesn't get to be too large. Using two DMA channels uses more resources, and is more cumbersome, but again this is the path you have chosen.

See this example, or similar one for the unspecified STM32 being used in each case..

STM32Cube_FW_L4_V1.14.0\Projects\NUCLEO-L496ZG\Examples\SPI\SPI_FullDuplex_ComDMA

Polled SPI based SD card example

STM32Cube_FW_L4_V1.14.0\Drivers\BSP\Adafruit_Shield\stm32_adafruit_sd.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..