cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 sdio sdhc 4gb problem

yigit
Associate II
Posted on September 13, 2012 at 08:37

Hello,

I've a problem with sdhc used with sdio in stm32f4-discovery platform. I've tried 2 versions of fat file system and sd driver, but I am not able to run sdhc properly.

The things I tried;

1) Nemui's sdio implementation with chan's fat version 0.09a.

2) stm324xg-eval implementation with also chan's fat 0.09.(which is used from stm32-demonstration builder)

Both codes are working perfectly with standard sdsc card (which are below 2gb) but when I insert a FAT32 formated sdhc card, the following occur.

1) SD_init() returns OK

2) f_mount() returns OK

3) f_open with create new file option returns OK

4) f_write returns OK with byteswritten value returned as expected.

5) f_sync returns OK

but when I connect the sdhc card to pc there seems nothings has been written.

Also there exists only one file in sdhc named as ''audio.wav'', f_open to this file returns FR_NO_FILE

the standard sdsc versions are working perfectly, the init sequence seems to support sdhc but there must be something I forget.

Can you please help me ?

Regards,

Yigit

#stm32-sdio-sdhc #sdio-sdhc-stm32 #stm32-sdio-sdhc #stm32-sdio-wide-mode-sdhc
30 REPLIES 30
jdcowpland
Associate II
Posted on December 18, 2013 at 16:53

Ok, thanks for the help! If I wanted to enable long file names, is it as simple as defining _USE_LFN or is there some more code I need to add/modify?

jdcowpland
Associate II
Posted on December 18, 2013 at 17:46

I just found this in the ffconf.h file:

#define _USE_LFN 0 /* 0 to 3 */
#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
/* The _USE_LFN option switches the LFN support.
/
/ 0: Disable LFN feature. _MAX_LFN and _LFN_UNICODE have no effect.
/ 1: Enable LFN with static working buffer on the BSS. Always NOT reentrant.
/ 2: Enable LFN with dynamic working buffer on the STACK.
/ 3: Enable LFN with dynamic working buffer on the HEAP.
/
/ The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes. To enable LFN,
/ Unicode handling functions ff_convert() and ff_wtoupper() must be added
/ to the project. When enable to use heap, memory control functions
/ ff_memalloc() and ff_memfree() must be added to the project. */

Anyone know where the files it mentions might be? I can't find them. Otherwise I'm guessing all I need to do is change the 0 to a 1,2 or 3 to enable LFN...
Posted on December 18, 2013 at 18:11

STM32F2-F4_Demonstration_Builder_V1.3.0\Utilities\Third_Party\fat_fs\src\option\ccsbcs.c

STM32F2-F4_Demonstration_Builder_V1.3.0\Utilities\Third_Party\fat_fs\src\option\syscall.c

Or other fw library \Utilities\Third_Party\fat_fs\src\option directories?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jdcowpland
Associate II
Posted on December 19, 2013 at 10:10

Thanks, found them! I'm now getting an error in your main.c file on this bit of code:

#if _USE_LFN
static char lfn[_MAX_LFN + 1];
fno.lfname = lfn;
fno.lfsize = sizeof lfn;
#endif

It's complaining abouterror: expected '=', ',', ';', 'asm' or '__attribute__' before '->' token. It gives me this error for the fno.lfname = lfn and the next line. I can't find where or why the error might be coming from. Any ideas?
Posted on December 19, 2013 at 17:22

Any ideas?

I haven't played with it in a very long while, I think the code fragment in question needs to be inside one of the loops processing the directory listing. It may well just be parked somewhere arbitrarily.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jdcowpland
Associate II
Posted on December 20, 2013 at 09:49

Looks like you were right about it being parked arbitrarily. I moved it inside the main function and it all worked.

antony
Associate II
Posted on February 28, 2014 at 08:12

I had a same problem, and after a few days I solved it. I think, it'll help you too. The reason was in GPIO initialization. In Clive's example maximum GPIO speed is 25 MHz, but it's not enaught for many SDHC cards. In my project i set GPIO speed to 100MHz and now all works fine.

bmpierre3
Associate
Posted on February 01, 2015 at 20:35

Hey Clive

I was running the old code and hit the 4GB limit and then found your code. It seems to work great so far but do you know what the size limit is? I tried a 16GB and 32GB so far but don't have anything bigger on hand.

Posted on February 01, 2015 at 22:09

I've tinkered with 64GB and 128GB cards, although they tend to be XFAT when used in a Windows PC. The math for the current driver is going to go pear shaped at 2TB, based on 4 billion 512-byte sectors...

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
bmpierre3
Associate
Posted on February 08, 2015 at 23:26

Thanks for the fast response Clive. I will have to do some tinkering as my current project requires the use of either FAT16 or FAT32. I know FAT32 is theoretically capable of up to 2TB but I haven't tried it yet so we'll see. Also, I have another question for you. Is there anything you know of to increase the speed of the transfer? I am using an external USB HS chip and getting about 5MB/s. I tried increasing the buffer size from 2KB to 64KB but saw no improvement. Thoughts?

Thanks again