Skip to main content
natblist
Visitor II
February 9, 2012
Question

SDIO and SD fat access example?

  • February 9, 2012
  • 84 replies
  • 16450 views
Posted on February 09, 2012 at 01:06

Hi Chaps,

Going slowly mad trying to get Chan Fat working with the sdio libs on a stm32f4.

I'm using the most recent (1.0.0) library for the F4, and the low level access demo within that library builds and (at least appears to ) work OK. 

I've spent many, many hours attempting to patch in 0.9 version of fatfs from chan (thks chan, you're a hero) - but I can't get it to work.

If possible, I'd really really appreciate a demo project/source (or direction to - though I've scoured the web and can't find anything that works!)

I'll post separately about the current problems I'm having with the my current build, but a working example would sort it.

Many thanks,

nat.

#hse-sdio-stm32 #stm32-fat-chanfat-fatfs-sdio #sdcard-stm32f4-sdio-fatfs #sdcard-stm32f4-sdio-fatfs
This topic has been closed for replies.

84 replies

amin23
Visitor II
November 6, 2012
Posted on November 06, 2012 at 08:39

Hi all,

You may find on the following link a full implementation of FatFS on STM32F2xx and STM32F4xx devices.

link:

http://www.st.com/internet/mcu/product/252133.jsp

Tesla DeLorean
Guru
November 6, 2012
Posted on November 06, 2012 at 14:13

You may find on the following link a full implementation of FatFS on STM32F2xx and STM32F4xx devices. link: STM32F2 and STM32F4 demonstration builder platform

As discussed on other threads, the examples target STM32x0G-EVAL, and have issues with larger SDHC cards due to the use of 32-bit byte addressing rather than block addressing. The versions I've ported to the STM32F4-Discovery address this and the lack of LCD panels.

However, as a general rule I'd recommend people try the original ST code, on the ST EVAL boards, and become comfortable with a known working platform. This will help identify issues with hardware vs software. It is critical that a socket is wired correctly, with pull-up resistors, as it is with the EVAL boards. Review the schematic, understand the circuit.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
aambreen
Associate
November 7, 2012
Posted on November 07, 2012 at 09:15

@AMSN

Please paste the complete link

Tesla DeLorean
Guru
November 7, 2012
Posted on November 07, 2012 at 13:27

Please paste the complete link

Per the link provided, Design Resources tab, bottom of the page Demonstration Builder

http://www.st.com/internet/com/SOFTWARE_RESOURCES/SW_COMPONENT/FIRMWARE/stm32f2-f4_demobuild.zip

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
rmeyer
Visitor II
November 8, 2012
Posted on November 08, 2012 at 17:49

clive1,

     Thank you this has been a most helpful thread.

I wonder if you could advise me where my issues are.

When trying to write a file, I am getting the error FR_INT_ERR returned.

I have stepped through the code and found the fail.  I have a 2GB SD card formatted with Fat32 and one file in the root directory.

In the ''remove_chain'' function on the line:

if (clst < 2 || clst >= fs->n_fatent) {    /* Check range */

        res = FR_INT_ERR;

clst = 4294967295

fs->n_fatent = 481794

so it fails and sets the res = FR_INT_ERR;

When trying to read a file I get a FR_NO_FILE

When I step through the code it leads me to ''SD_ReadMultiBlocks'' function, inside diskio.c, which I copied directly from the web site.

The function call to SD_ReadMultiBlocks returns SD_OK, but when SD_WaitReadOperation function it hangs.

Killing the debug session and restarting, not single stepping, the f_open function returns FR_NO_FILE.

I'm using IAR EWARM 6.40.2.3992 with an STM3240G-EVAL board.

Any Suggestions?

Thank you.

Tesla DeLorean
Guru
November 8, 2012
Posted on November 08, 2012 at 18:39

Hard to say, I made a number of changes to the SDIO code to address some basic flaws I found in it. You could download my Keil build and look at the files with a diff/merge tool like WinMerge or Araxis Merge. This would be illustrative of what I did.

In terms of the routines hanging, I would check that the IRQ routines are set up and working properly. Non SDHC cards (ie sub 4GB) need to have the block size sent to them for the reads to work properly.

My routines in diskio.c address potential DMA alignment issues, and also use fixed versions of the multi sector read/write routines.

I don't have an STM3240G-EVAL board, or IAR to work with, but have successfully used SDIO/FATFS on other F2 and F4 platforms, and cards up to 32GB.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
gmgunderground
Associate II
March 27, 2013
Posted on March 27, 2013 at 12:43

Hi clive1, I have tested your STM32f4_discovery_sdio_sd library, with FatFs on my STM3240G-EVAL following your keil project (I use Atollic), all is working correctly, but performane are very poor (370KB/s)

The test is made by the following code:


fresult = f_mount(0, &fat );

fresult = f_open( &file, 
''0:test.dat''
, FA_CREATE_ALWAYS | FA_WRITE );

while
(*** < 5);

GPIO_WriteBit(GPIOG, GPIO_Pin_8, Bit_SET);

while
(*** < 6)

{

fresult = f_write( &file, b, 
sizeof
(b), &n);

}

GPIO_WriteBit(GPIOG, GPIO_Pin_8, Bit_RESET);

fresult = f_close(&file);

*** is incremented by 1 every 1 second TIM2 interrupt. b is a 512 byte array When I take off my MicroSD 4G Class 10 the file is about 370 / 380 KB). Any idea about to increase the performance drastically ? Best regards Gian
Tesla DeLorean
Guru
March 27, 2013
Posted on March 27, 2013 at 13:28

When I take off my MicroSD 4G Class 10 the file is about 370 / 380 KB).  Any idea about to increase the performance drastically ?

Implement caching and lazy writes? Long aligned runs? Cluster writes?

I've seen 460 KBps writes across USB, the local speed is much higher writing directly to the card, FatFs is not designed for higher performance but rather small foot print.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
March 27, 2013
Posted on March 27, 2013 at 15:33

Generic 2GB Class 4(?) at the SD interface on a 120 MHz F2 design

51200 Bytes, 1189115 Cycles

5.166868 MBps Read

                                                            

51200 Bytes, 2585850 Cycles

2.376008 MBps Write
Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
March 27, 2013
Posted on March 27, 2013 at 16:46

Different 2GB MicroSD

50 KB block read/write, non contiguous regions, with SD_ReadMultiBlocks

51200 Bytes, 471825 Cycles

13.021777 MBps Read

                                                           

51200 Bytes, 31099889 Cycles

0.197557 MBps Write

                                                           

51200 Bytes, 476647 Cycles

12.890042 MBps Read

                                                           

51200 Bytes, 3929347 Cycles

1.563619 MBps Write

                                                           

51200 Bytes, 474559 Cycles

12.946757 MBps Read

                                                           

51200 Bytes, 3866183 Cycles

1.589164 MBps Write

                                                           

51200 Bytes, 474571 Cycles

12.946430 MBps Read

                                                           

51200 Bytes, 3845599 Cycles

1.597670 MBps Write

                                                           

51200 Bytes, 474535 Cycles                                                    

12.947412 MBps Read

                                                           

51200 Bytes, 3876209 Cycles

1.585054 MBps Write

                                                           

Overwriting on the same spot gets folded by the card, claims 5.6-5.8 MBps

 

20 MB linear write in 4KB blocks with FATFS

20480000 Bytes, 1310214451 Cycles

1.875723 MBps Write (FatFs)

                                                   

20480000 Bytes, 1299831750 Cycles

1.890706 MBps Write (FatFs)

20480000 Bytes, 1279462454 Cycles

1.920807 MBps Write (FatFs)

                                                   

20480000 Bytes, 1300349142 Cycles

1.889954 MBps Write (FatFs)

500 KB linear write in 512 byte blocks with FATFS (Same card spectacular results)

512000 Bytes, 1386510924 Cycles

0.044313 MBps Write (FatFs)

                                                   

512000 Bytes, 1356673081 Cycles

0.045287 MBps Write (FatFs)

                                                   

512000 Bytes, 1344495713 Cycles

0.045697 MBps Write (FatFs)

                                                   

512000 Bytes, 1374083889 Cycles

0.044713 MBps Write (FatFs)

                                                   

512000 Bytes, 1346310799 Cycles

0.045636 MBps Write (FatFs)

Cards vary wildly in their internal caching and buffering strategy. FATFS has sub cluster issues.

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