cancel
Showing results for 
Search instead for 
Did you mean: 

Avoid ''SD card transfer complete wait'' in case of DMA

dhaval
Associate II
Posted on June 07, 2016 at 08:02

Hi,

I am working on STM32L4xx MCU. I have connected MicroSD card of 8GB size over SDMMC interface. And I am using DMA for write to the SD card.

Now, DMA is used to keep the MCU free during that time of data transfer. But what I saw is, after initiating the DMA for data transfer the BSP code is waiting for transfer complete of DMA by calling ''HAL_SD_CheckWriteOperation()'' function, which will keep MCU busy. And thus it defeats the purpose of DMA!!

Is this wait is really required? Can't we simply initiate the DMA transfer and avoid this wait?

Please help me to understand this.

Thanks,

Dhaval

#sdmmc1 #microsd #dma #stm32
4 REPLIES 4
petr239955
Associate III
Posted on June 07, 2016 at 09:54

Hi Dhaval,

do you read this https://my.st.com/c964d235 ?

Petr

dhaval
Associate II
Posted on June 07, 2016 at 10:16

Hi Petr,

Thanks for you quick reply.

I read that post. According to it, to enable DMA read/write operation for SD card I need to modify SD_read()/SD_write() functions in sd_diskio.c file. I already modify SD_write() function accordingly, but not SD_read() function, as firmware is just writing to the SD card but not reading back from it. So DMA for read is not required in my case.

Now, the problem is, the BSP implementation for DMA write operation waits for transfer to complete, by calling ''HAL_SD_CheckWriteOperation()'' function. And thus CPU will remain busy till transfer completes, and that defeats the purpose of DMA!

So, what is the importance of that wait for transfer to complete operation? And can I disable it?

Regards,

Dhaval

Walid FTITI_O
Senior II
Posted on June 07, 2016 at 13:40

Hi dhavalv,

I report your feedback regareding BSP_SD_WriteBlocks_DMA() function.

I suggest that you take a look to this [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32Cube%20%2B%20F4-Discovery%20%2B%20FatFS&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=107]thread

-Hannibal-

Posted on June 07, 2016 at 14:53

You have to serialize access to the SD Card.

You have to wait for the current command to complete and the FIFO to empty.

You have to pass a success/failure message to the file system.

There are a number of ways to do this without spin-loops.

One could make a complicated asynchronous driver stack, tends to be too complex for most people.

Perhaps an easier way is to use an RTOS, and put all the file system / disk io into a thread of it's own, servicing requests, and yield while waiting.

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