cancel
Showing results for 
Search instead for 
Did you mean: 

stm32F0 sd Card FATFS

Cesar cfg
Associate II
Posted on June 28, 2015 at 14:49

Hi

I am using stm32f0 to wtrite and read from sd card using FATFS.Every thing is ok  : integration of FATFS files and making the correct hardware connection.I can communicate with the sd card for example to get its properties.

 My problem is that i can't write or read in it.

I make this simple program to read from it:

  memset(&FS32, 0, sizeof(FATFS));

  res = f_mount(0, &FS32);

  res = f_open(&fil,''CONFIG.TXT'',FA_READ);

  res = f_read(&fil, Buffer, sizeof(Buffer), &BytesRead);

  res=f_close(&fil);

after debuggging this program :

res = FR_OK

BytesRead =4 (number of caracters in the text file)

Buffer is empty??

I can't see where is the problem.

 NB: the sd card is formatted  FAT32.

5 REPLIES 5
Posted on June 29, 2015 at 04:05

What's returned at each command, and what's happening in the read/write function in DISKIO.C, you need to make sure the functionality there is bullet-proof

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Cesar cfg
Associate II
Posted on June 29, 2015 at 11:57

clive1, I have a doubt in the way of formatting the sd card. So can you tell me how i can do it using windows 7 

Cesar cfg
Associate II
Posted on June 29, 2015 at 13:17

My question is about the file system(FAT od FAT32) and the size of unity allocation (1024 , 2048.....)

Thanks 

Posted on June 29, 2015 at 15:18

I'd expect the cards to come suitably formatted. And function tolerably if reformatted in Windows using Microsoft's stock code.

There is an SD Formatter, provided by the SD/MMC group, that aligns the internal structures and clusters with respect to the size of the erase block used in the underlying NAND array. Generally the biggest failure in ST code has been the handling of block addressing in devices >2-4GB, as they use byte addressing, and the correct casting of math to 64-bit in that case.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 29, 2015 at 15:22

Microsoft generally picks a suitable cluster size based on the media size, with FAT32 you can perhaps shrink the cluster size, but this will cause the allocation table to expand significantly. Small cluster sizes don't help much with SD cards.

If your use case requires lots of small files, perhaps you need to rethink that, and how you manage data.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..