cancel
Showing results for 
Search instead for 
Did you mean: 

SDIO and SD fat access example?

natblist
Associate
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
84 REPLIES 84
aambreen
Associate II
Posted on November 02, 2012 at 06:27

Thanks alot for guiding me :)

amin23
Associate II
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

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
Up vote any posts that you find helpful, it shows what's working..
aambreen
Associate II
Posted on November 07, 2012 at 09:15

@AMSN

Please paste the complete link

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
Up vote any posts that you find helpful, it shows what's working..
rmeyer
Associate
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.

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
Up vote any posts that you find helpful, it shows what's working..
gmgunderground
Associate II
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
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
Up vote any posts that you find helpful, it shows what's working..
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
Up vote any posts that you find helpful, it shows what's working..