cancel
Showing results for 
Search instead for 
Did you mean: 

SDcard with SDIO interface and FATFS

linas2
Associate II
Posted on June 07, 2012 at 18:46

Hello,

i connected sdcard to my stm32f4discovery board, used SDIO example for low level init, and fixed fatfs so i can write data and read that later with computer

But fatfs code is to complex for me to understand, does any one know hot to create txt, write a value (like from adc) and then close it so it could be seen by computer ?

thanks
16 REPLIES 16
Posted on June 07, 2012 at 23:22

Wouldn't something along the following lines do that?

void main (void)
{
FATFS fs[1]; /* Work area (file system object) for logical drives */
FIL ftxt; /* file objects */
BYTE buffer[128]; /* file copy buffer */
FRESULT res; /* FatFs function common result code */
UINT bw; /* File write count */
/* Register work area for each volume (Always succeeds regardless of disk status) */
f_mount(0, &fs[0]);
/* Create destination file on the drive 0 */
res = f_open(&ftxt, ''0:whatever.txt'', FA_CREATE_ALWAYS | FA_WRITE);
if (res) die(res);
sprintf(buffer,''The result was %d
'', res);
res = f_write(&ftxt, buffer, strlen(buffer), &bw); /* Write it to the txt file */
if (res) die(res);
/* Close open file */
f_close(&ftxt);
/* Unregister work area prior to discard it */
f_mount(0, NULL);
}

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
linas2
Associate II
Posted on June 08, 2012 at 11:47

I get errors when trying to compile:

Warnings: Function ''die'' declared implicitly Variable ''des'' was declared but never referenced And Error: No definition for ''die'' Maybe i miss something ?

void main (void)
{

NVIC_Configuration(); SD_LowLevel_Init(); SD_Init(); SD_PowerON(); SD_InitializeCards();

FATFS fs[1]; /* Work area (file system object) for logical drives */
FIL ftxt; /* file objects */
BYTE buffer[128]; /* file copy buffer */
FRESULT res; /* FatFs function common result code */
UINT bw; /* File write count */
/* Register work area for each volume (Always succeeds regardless of disk status) */
f_mount(0, &fs[0]);
/* Create destination file on the drive 0 */
res = f_open(&ftxt, ''0:whatever.txt'', FA_CREATE_ALWAYS | FA_WRITE);

if (res) die(res);

sprintf(buffer,''The result was %d
'', res);
res = f_write(&ftxt, buffer, strlen(buffer), &bw); /* Write it to the txt file */

if (res) die(res);

/* Close open file */
f_close(&ftxt);
/* Unregister work area prior to discard it */
f_mount(0, NULL);
}

Posted on June 08, 2012 at 13:58

Maybe i miss something ?

It's a template based on other FATFS examples. die() is simply a fatal error handler, implement one. You could use exit(), but where would that go?

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Andrew Neil
Evangelist
Posted on June 09, 2012 at 13:55

FatFs is pretty well-documented and widely-used.

There are examples on the FatFs site, and many others over the internet.

Have you studied these resources?

linas2
Associate II
Posted on June 09, 2012 at 14:35

yes, i tried to do that.

even if i have code , lets say for displaying image, i get nothing, i was testing lot of codes but none of them are responding.

sdcard connection is working, i can read all info about sdcard, size, speed class, block size , status and soon, but nothing  more

also simple I/O test ( just read write and see if they are same without FATFS) works as it should, no errors.

Posted on June 09, 2012 at 16:23

So basically integration fail.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
rishi
Associate II
Posted on June 09, 2012 at 20:06

can you post the code that is working for u without fatfs...means normal communicating with SDIO

linas2
Associate II
Posted on June 09, 2012 at 20:38

i used SDIO interface from eval board (just SDcard detect leg is from C port)

(it is in STM32 F4 example projects, copy some gpio init and other random code from main eval.c file and get it working)

all what is in example of SDIO is working for me.

rishi
Associate II
Posted on June 09, 2012 at 20:45

can u mail me that code ...actually i m also trying to make that bt i m not getting it...so i will b very pleased if u mail me that whole code...@rishi.iitk@gmail.com

TIA