2012-06-07 09:46 AM
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 ? thanks2012-06-07 02:22 PM
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);
}
2012-06-08 02:47 AM
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);
}
2012-06-08 04:58 AM
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?2012-06-09 04:55 AM
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?2012-06-09 05:35 AM
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.2012-06-09 07:23 AM
So basically integration fail.
2012-06-09 11:06 AM
2012-06-09 11:38 AM
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.2012-06-09 11:45 AM