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

julien23
Visitor II
August 21, 2013
Posted on August 21, 2013 at 14:50

That's what i've done and - good news - it is finally functionnal. I am not sure of what i could have done wrong but finally, it's ok.

[EDIT] As i had mixed some of your code with some ST code, problems due to the way the cards are adressed may have happened.

Again, thanks for your help.

Julien
hitsumen
Associate III
November 17, 2013
Posted on November 17, 2013 at 10:25

Hi 

clive1,

 

Thank you for sharing your code and lot of information about SDIO.

I have tried to use the example from ST, but have some problems with my STM32F4DISCOVERY board:

STM32F4xx_SDIO_Example

so from terminal i have this: 

 Debug Module Init 

Open a test file (message.txt) 

not exist the test file (message.txt)

Create a new file (hello.txt)

Create a new file error

rc=1 FR_DISK_ERR

I have checked the pins are correct, I formatted my sd card with fat32 and copied message.txt to micro sd card. This error occurs with both, microsd 8gb sdhc 4 class card and, microsd 2gb card.

I tried your example then i have this:

ÿFatFs Testing

res = 1 f_open MESSAGE.TXT

res = 1 f_open DIR.TXT

Maybe problem is with my microsd card module, I have checked they use the 10k resistors instead of 30k-50k resistors for data, clock and other signals?

Thank you,

//Nikolaj

hitsumen
Associate III
November 18, 2013
Posted on November 18, 2013 at 19:07

clive1

Finally I found the mistake, my cards do not want to work with 4 bit mode.. In 1 bit SDIO works fine.

And the speed in 1 bit mode is 50kB/s.. So slow..

Can you suggest me something about 4 bit mode and slow speed? Maybe it is resistors?

Thank you.

Tesla DeLorean
Guru
November 18, 2013
Posted on November 18, 2013 at 22:35

Not sure, my wires were very short and of even length. I guess I would double check the pin assignments. 10K should likely work, though my example was weaker 33K on the wire-wrapped example, and 47K on the production board. I'd have to double check what was used on the STM32F4DIS-BB board, I suspect 47K.

When it initial brings up the card in 1-bit, it uses a clock of 400 KHz, and later switches to 24 MHz and 4-bit. You might want to check if you can select the higher speed, or if in fact you have.

The cards you mention should support 4-bit mode, so double check length, continuity, etc.
Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
hitsumen
Associate III
November 20, 2013
Posted on November 20, 2013 at 11:50

Hi clive1,

I checked my wires million times I use 20cm wires, changed them to different ones, etc.. Nothing helped..

I will try to change them to something like 5cm wires, then I will try to resolder resistors to 47k, maybe that will help.

What speed you have in 1 bit mode? If I would have something like 500kb/s that would be enough for my task.

Thank you,

//Nikolaj

Tesla DeLorean
Guru
November 20, 2013
Posted on November 20, 2013 at 13:51

20 CM seems rather excessive, my signal wires were closer to 30 MM

Suggest you scope the clock pin, look at SDIO_TRANSFER_CLK_DIV, used in SD_Init(), presumably you left that, and deprecated the call to SD_EnableWideBusOperation(SDIO_BusWide_4b)
Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
hitsumen
Associate III
November 20, 2013
Posted on November 20, 2013 at 14:30

clive1,

 

These settings does not impact the speed..

#define SDIO_INIT_CLK_DIV                ((uint8_t)0x76)

#define SDIO_TRANSFER_CLK_DIV            ((uint8_t)0x1)

I have tried to change them to 0 or to 0x76, speed is the same, even if i change this in SD_Init() and SD_PowerON():

SDIO_InitStructure.SDIO_ClockDiv = 0x00;

Only if I will change this to 4bit microSD card does not work...

SDIO_InitStructure.SDIO_BusWide = SDIO_BusWide_4b;

Can you please measure the card speed in 1 bit mode..

Strange stuff happens, if I use the slower card it goes for 70kb/s

If I use SDHC 4class card it goes 50kb/s. 

Thank you,

//Nikolaj

Tesla DeLorean
Guru
November 20, 2013
Posted on November 20, 2013 at 15:34

Can you please measure the card speed in 1 bit mode..

It interferes with this morning's work flow, but

SDIO @ 24 MHz, 1-bit, 8GB, Class 4, SanDisk

168 MHz STM32F4-DISCO + STM32F4-DIS-BB

1000x 32KB blocks

CRC32 A704009B Memory Image

32768000 Bytes, 2062624245 Cycles

2.668942 MBps Write (FatFs)

CRC32 A704009B COUNTER.TXT

32768000 Bytes, 2067366939 Cycles

2.662819 MBps Write (FatFs)

CRC32 A704009B COUNTER.TXT

32768000 Bytes, 1909376469 Cycles

2.883153 MBps Read (FatFs)

32768000 Bytes, 1909409333 Cycles

2.883103 MBps Read (FatFs)

SDIO @ 24 MHz, 4-bit, 8GB, Class 4, SanDisk

168 MHz STM32F4-DISCO + STM32F4-DIS-BB

1000x 32KB blocks

CRC32 F155B8E6 Memory Image

32768000 Bytes, 1143695149 Cycles

4.813367 MBps Write (FatFs)

CRC32 F155B8E6 COUNTER.TXT

32768000 Bytes, 1148850865 Cycles

4.791766 MBps Write (FatFs)

CRC32 F155B8E6 COUNTER.TXT

32768000 Bytes, 533835224 Cycles

10.312216 MBps Read (FatFs)

32768000 Bytes, 533883893 Cycles

10.311276 MBps Read (FatFs)

If you can't post similar numbers you need to seriously assess your hardware configuration, ie don't use my numbers to validate your design.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
hitsumen
Associate III
November 20, 2013
Posted on November 20, 2013 at 15:53

Hmm, I use 512 byte blocks, like in the example:

f_write(&file, buff, 512, &bw);

So you write like this:

f_write(&file, buff, 32768, &bw);

//SDIO_CK = SDIOCLK / (SDIO_TRANSFER_CLK_DIV + 2), so

SDIO_InitStructure.SDIO_ClockDiv = 0x05;

Right?

//Nikolaj

Tesla DeLorean
Guru
November 20, 2013
Posted on November 20, 2013 at 16:19

As discussed earlier in the thread the use of small block sizes is both detrimental to the SD Card and FatFs operation.

I like 32KB, its a good mix of sectors, cluster, and block alignment. The flash device likely blocks at 128KB. Use an SDFormatter application to format cards (the factory does this), the classic DOS/Windows tools don't pay attention to the alignment needs of the flash.

Below 512 bytes it gets worse, everything has to be deblocked, and is wasteful of IO operations. Caching can help, better buffering at the application level helps more.

Assuming Q tap of the PLL is at 48 MHz

#define SDIO_TRANSFER_CLK_DIV            ((uint8_t)0x0) // 24 MHz
Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..