cancel
Showing results for 
Search instead for 
Did you mean: 

ST32f4discovery+sdcard+fatfs problem

arnold
Associate II
Posted on June 30, 2012 at 23:43

Hello, 

i have a small problem i think.

With the help of this forum and google i created a project with CoIDE.

What it should do is reading the directory of an SDCARD.

The SDCARD part is working. but the fatfs is not working and i don't know what i'm doing wrong. 

I believe everything is oke. 

so i hope someone could help me. 

I attached the whole project. 

#sdcard-stm32f4-sdio-fatfs
48 REPLIES 48
Andrew Neil
Evangelist III
Posted on July 01, 2012 at 01:05

''the fatfs is not working''

In what way, exactly, is it ''not working''?

eg, what error code(s) do you receive?

What debugging have you done?

Have you checked the FatFs documentation & support on the FatFs site?

Posted on July 01, 2012 at 05:50

What size cards are you using?

Have you logged what reads are going through disk_read()?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
arnold
Associate II
Posted on July 01, 2012 at 13:51

i realy don't know what the problem is. 

I use a 4Gb card formated as fat32

this is what the debugger says

res = disk_initialize(0); => fr_ok

res = f_mount(0,&fs32); => fr_ok

res = f_opendir(&dir, path); => FR_NO_FILESYSTEM

but there is a file system on the drive

Posted on July 01, 2012 at 14:55

A cursory review of disk_read() suggest several basic flaws, that either do or will cause failure.

a) No error propagation

b) Fails to handle media >4GB

c) Fails to address memory alignment requirements of downstream code

d) Doesn't test for media presence

http://elm-chan.org/fsw/ff/en/dread.html

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
arnold
Associate II
Posted on July 01, 2012 at 16:53

now i have insert a 2 Gb sd card same error.

and as far as i can see, there is a check for media precence. 

f_mount and f_opendir don't use diskread !!!!!

could you give me som clue on how to find out what goes wrong ?

Posted on July 01, 2012 at 19:02

could you give me som clue on how to find out what goes wrong ?

Add some debug output telemetry so you can figure where it goes, and what's happening. Make sure you propagate errors so it doesn't fail silently. Dump out structures, add breakpoints. A file system that doesn't read the media isn't going to get very far.

I might poke at this on Monday as time permits.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
zaurozavr
Associate II
Posted on July 01, 2012 at 21:27

You should check the boot sector integrity at RAM.  FAT FS (i.e. Microsoft FAT) is present if byte number 510 of boot sector equals  0xAA and byte 511 is  0x55.

There may be a problem in power source or hw connections. Personally, I encountered a problem with STM32F4-Discovery board due to DMA ''ate'' some bytes, so the signature 0xaa 0x55  shifted to  the wrong position.     

Posted on July 01, 2012 at 22:50

The MBR and the boot sector all have signatures and markers.

The DMA is intolerant of alignment violations.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on July 02, 2012 at 18:27

You shouldn't need to call disk_initialize(), FsFat calls this.

Subsequent calls to SD_Init() might be failing, and this would cause disk_read() not to be called.

You don't initialize path, and you don't clear out the FATFS structure.

Use a debugger, and step through the code.

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