cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Fatfs with DMA

Yi-Wei Yu
Associate
Posted on June 10, 2017 at 07:26

I want using DMA to read/wrrite file with fatfs.

I try to  modify

if(BSP_SD_ReadBlocks((uint32_t*)buff,  (uint32_t) (sector), count, SD_DATATIMEOUT) == MSD_OK)

to

if(BSP_SD_ReadBlocks_DMA((uint32_t*)buff,  

(uint32_t) (sector),

count, SD_DATATIMEOUT) == MSD_OK)

but when I used ' f_mount' I got a error code '

FR_NO_FILESYSTEM

' .

What steps do I have to do when I wnat to use Fatfs with DMA?

#hal #dma #fatfs #sdio #sd #sd-card
4 REPLIES 4
Posted on June 10, 2017 at 12:19

Hello,

I don't expect different behavior working with or without DMA. But... is it working without DMA?

Other: is there already a filesystem into SDCard?

If not:

- call f_mount(x,y,0), and ignore the result: FR_NO_FILESYSTEM -> note 0 param: it's only used to register the filesystem

- call f_mkfs()

- call 

f_mount(x,y,1) -> here an OK is expected

Posted on June 10, 2017 at 15:03

Hi 

HAL default is block mode for FatFs not DMA, even you set DMA in cubeMX.

In block mode, FatFs is working.

Ole Ho
Associate II
Posted on December 11, 2017 at 17:22

Hello. I ve got the same problem. Have you or someoe resolved this issue?

I am testing this functionality through MSC layer and with BSP_SD_ReadBlocks it works like a charm, but with BSP_SD_ReadBlocks_DMA my computer gives same 'no filesystem' error and suggests formatting medium (off course, with no success). DMA config is standard (forum is buggy for a moment, so can not paste code): pinc disable; minc enable; pdataalign word; mdataalign word; fifo enable; threshold full; mem and periph burst inc4. Interrupts enabled and SDMMC interrupt has higher priority than DMA.

Posted on December 11, 2017 at 18:34

Reformatting things isn't going to fix things that are flagging 'this isn't reading the right data properly'

DMA needs to be aligned to 32-bit word boundaries, the DMA TC interrupt should flag that the transfer is complete, you should ensure the SDIO/MMC FIFO is cleared out. I would expect deliver of data to lag the MMC IRQ.

Test the interface at a block level, where you are reading sectors of known content and comparing that to what's actually being delivered. The MBR and BPB should be good static examples you can read and checksum using the non-DMA variant, and check on the DMA variant.

Reports on the forum suggest the current cube release is a bit of a cluster fsck in this area.

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