2015-06-28 05:49 AM
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.2015-06-28 07:05 PM
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
2015-06-29 02:57 AM
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
2015-06-29 04:17 AM
My question is about the file system(FAT od FAT32) and the size of unity allocation (1024 , 2048.....)
Thanks2015-06-29 06:18 AM
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.2015-06-29 06:22 AM
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.