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
Posted on September 13, 2012 at 12:21

The SD code provided by the ST EVAL examples talks to the SD card via a 32-bit linear address, which obviously has 4GB issues, rather than using block addressing.

I'd point at some threads here, but there are many, and the search just *****.

Here is a FAT FS example, ported to the STM32F4-Discovery, with the blocking fixed and consistent. I'm not sure it's the most up-to-date one, and I do have examples under Keil, and for the USB MSC example too.

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Attachments/23511/fsfatdemo4disc_rev2.zip

The MSC example is here, check the readme.txt for wiring details, which can also be a problem if fouled up. You need pull-up resistors.

https://docs.google.com/open?id=0B7OY5pub_GfIaUozb1VsY3Flb1E

0690X00000602lyQAA.jpg

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 13, 2012 at 14:50

Well, that certainly looks fouled up!  ;) ;)

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

Thank you for your fast reply.

I've used the code you have attached. That worked with sdsc properly, but in case of sdhc, I get random errors when reading. I got CRC error after SD_Stop_transfer() function.

By the way I'm trying to read 4864 bytes. And It never read that much data.

With SDSC all is working as intended. Also I'm trying to use 4 GB SDHC class 4 card.

yigit
Associate II
Posted on September 13, 2012 at 16:09

Thank you for your fast reply.

I've used the code you have attached. That worked with sdsc properly, but in case of sdhc, I get random errors when reading. I got CRC error after SD_Stop_transfer() function.

By the way I'm trying to read 4864 bytes. And It never read that much data.

With SDSC all is working as intended. Also I'm trying to use 4 GB SDHC class 4 card.

Posted on September 13, 2012 at 19:44

How, specifically, do you have it wired up?

I'm using a MicroSD card socket, the signal lines are about 1'' long, with 33K pull ups. I'm using a different GPIO for the CARD DETECT pin.

0690X00000602iPQAQ.jpg
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
yigit
Associate II
Posted on September 13, 2012 at 20:36

I've connected slot as described with pullups on each line, except the clk line. I am not currently using sd_detect pin and also removed detection from the code.

I'm getting CRC errors randomly for commands that I sent. Also there is no problem with the sdsc mode. Only the sdhc mode has the CRC problem.

yigit
Associate II
Posted on September 13, 2012 at 22:12

I've discovered that only 4b wide mode of sdhc has the crc problem. 1b is working fine. But I need to speed it up. 

note: sdsc mode can be used in 4b wide mode without any problem. Only sdhc has the problem.

Posted on September 14, 2012 at 00:59

So basically an integrity issue, perhaps cross-talk, or relative skewing.

You could try dropping the SDIO bus clock, or a PCB solution with controlled path lengths/characteristics.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
shannon2
Associate II
Posted on June 09, 2013 at 18:35

THANK YOU!!!!!!!!!!!!

I cannot express the level of gratitude I have for you posting the above demo.  I mean seriously.  You went out of your way to put together a fairly complex piece of code and provided it free to all of us.  That kind of altruism should be rewarded.

Right now I'm bringing up a personal project of mine.  I was dreading bringing up the sd card / FAT file system.  I had tackled this before on a bread board and just barely got it working after weeks of labor.  I didn't use Chan's FAT last time and had to write a bit of code to finally get things in order but I never felt it was clean.

Now I have my own PCBA and decided to try and implement the full Chan FAT.  If I had not stumbled upon this old thread and your code I'm quite sure I would still be struggling weeks from now.  THANK YOU!!!!!!  

Absolutely worked the first time!  That is stunning in and of itself!!!

I was going to send you a private email but I think this needed to be said publicly. I don't know how many will see this old thread but it's worth a shot.

Shannon