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
Posted on March 30, 2013 at 21:58

Noted

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Bill Lewis
Associate III
Posted on March 31, 2013 at 01:10

I commented out that assert to get past it.

Posted on March 31, 2013 at 14:03

This code is used in other ST examples, from which is was ported. The SDIO peripheral controls the transfer length, and it's own FIFO (32 x 32-bit words). One of the issues with the Ultra cards was that the transfer signalled as complete before the FIFO cleared.

I think others have observed parts of the FW library will assert during normal operation.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ahmadreza_hadidi2020
Associate II
Posted on August 05, 2013 at 11:00

Hi everybody

I'm new in stm32f4.

i read your posts but i cant understand how to speedup fatfs and sdio with ''

clive1

''s sample code. i try to adapt the system clock as you said: SDIO Clock = 24MHz

my clock configuration is:

/************************* PLL Parameters *************************************/

/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */

#define PLL_M      8

#define PLL_N      336

/* SYSCLK = PLL_VCO / PLL_P */

#define PLL_P      2

/* USB OTG FS, SDIO and RNG Clock =  PLL_VCO / PLLQ */

#define PLL_Q      7

but i have very very slow speed(about 512KB/s)

i use stm32f4 Discovery board.

What

other changes

do

I need to

apply

?

if possible please tell the notes clearly or put and sample code.

(Sorry for my bad English)
Posted on August 05, 2013 at 14:35

Reading or Writing?

Are you using small transactions?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ahmadreza_hadidi2020
Associate II
Posted on August 13, 2013 at 15:44

Both!

bu at this time i need writing speed. i want to use my uSD card to save ADC data that should be save 35000 (35K sample per second) data in one second for 4 ADC channel. so i need 35000x4 data sample to be saved as a text line like this:

100;200;300;400

its a CSV file format. so i need FatFS to save this data.

At first i tried to save these data to an array (just one channel) in ram and then saving them on the memory card but the saving process take too many time(about 4 seconds!).

because i need 4 channel of ADC to save so i cant save them in stm32f4 ram. for this reason i want to save the 4 channels data each time i read the ADC channels.

to save that line of data in my file i use ''f_printf'' function but the saving process is too time consuming.

At last i use a simple for loop to save 35000 line of a sample line to my file but it took 4 seconds!!

sorry, what do you mean about ''small transactions''? do you want me to save whole the data in a transaction?

how can i speed up this process?

Posted on August 13, 2013 at 15:57

sorry, what do you mean about ''small transactions''?

 

Writing 6-12 bytes at a time, repetitively.

File systems, and block devices work a LOT more efficiently if the data is sector or cluster sized, and aligned. Say at least 4 KB, and perhaps up to 32 KB, you'll need to find your sweet-spot.

how can i speed up this process?

 

You could buffer things better, you could use optimized output routines (ie not printf, et al), utilize caching and lazy writing.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
julien23
Associate II
Posted on August 20, 2013 at 13:38

Hi

First thanks for this helpful thread,

I am trying to read file from an SDCARD with a STM32F4xx chip (Olimex E407 board). I checked the socket wiring, i think it's ok.

I also tried to run the FATFS-DBG example with a 2GB SDcard but i've experienced problem. I checked that disk_read() is functionnal with the small example given on this thread, but i can't open and write to a file.

After a bit of debugging, i found out that when chk_mounted() calls check_fs(), it returns

a NO_FILESYSTEM (after a check_fs()). When it don't, it often goes into the HardFault handler and i can't explain why.

[EDIT] The NO_FILESYSTEM seems to results in a FR_DISK_ERR returned by f_open() to the main().

Does anyone have an idea ?

Julien

Posted on August 20, 2013 at 18:28

Don't know, you'd have to examine the structures on the media to understand why it didn't like the master boot record (partition table), or MSDOS BPB's. I'll assume the card is formatted in FAT, and readable on a PC.

Faulting suggests you have buffers on the stack (local/automatic), and an inadequately sized stack.

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

Thanks for your answer. The SDCard seems to be ok, i also used another one after it has been formatted but without any change.

I fixed the stack issue, many thanks ! It permitted me to see where the problem is:

when calling f_open() (line 88), chk_mounted() is also called and it returns FR_DISK_ERR. Then, chk_mounted() ''checks if the filesystem object is valid or not'' and it seems to be invalid.

Later, it is searching for a FAT partition and there are two check_fs calls. The first one : fmt = check_fs(..., bsect = 0); returns 1 (Not a FAT VBR...) and the second call fails and returns 3.

The problem finally seems to appear in the disk_read call performed in check_fs(). I get a SD_ADDR_MISALIGNED error... (SD_ReadMultiBlocks() return this error when trying to send a CMD18 : SD_CMD_READ_MULT_BLOCK).

Any idea ...? I have heard about a fixed version of ReadMultiBlocks but i'm not sure that the problem is here, what do you think ? Anyway, i will try to find it and test it.

Thanks again for your help !

Julien