cancel
Showing results for 
Search instead for 
Did you mean: 

SD doubt

muntu_the_killer
Associate II
Posted on October 21, 2013 at 16:37

Hi everyone,

I have a doubt and i hope someone can help me.

I'm writting my SD card files with .001, .002, .003, etc extension. I need to know which is the biggest extension of my files. I'm using Fat32. Is there any function that return wich is the biggest extension of my files?

Thanks in advance!

Miquel
9 REPLIES 9
Posted on October 21, 2013 at 16:56

No, you'll need to enumerate through the files yourself. Suggest looking at f_opendir() and f_readdir()

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
muntu_the_killer
Associate II
Posted on October 24, 2013 at 11:38

Hi Clive,

Thanks for responding. I will enumerate it myself, but I want to know which is the biggest extension to continue writing the next. For example, I have created three files: .001, .002 and .003 extension. When I execute my program, I need to check which is the biggest extension (.003) to start writing in the next (.004). I have an array 

char nomarxiu [12] = ''P9V26N09.001'';

and I want to check if last three positions (extension) in my SD card exist or not, to call later the function

rc = f_open(&Fil2, nomarxiu, FA_WRITE | FA_CREATE_ALWAYS);

with the correct values in the extension.

Thanks,

Miquel

Posted on October 24, 2013 at 19:08

Yes, you'll need to use f_readdir() and identify the highest index currently used. To do this you'll need to parse the filename/extension returned and extract the data that is pertinent to your requirement.

I understood the requirement as first expressed, I'm just not looking to own this coding task.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
muntu_the_killer
Associate II
Posted on October 25, 2013 at 11:33

Ok, I'll try using f_raddir() right now! With a single call to the function I will receive all the files? Should I make a for loop to get all the files? And if my files are in the root, which parameters should I put in the function?

FRESULT f_readdir ( DIR*

dp

,

/* [IN] Directory object */

FILINFO*

fno

/* [OUT] File information structure */

);

Thanks!

Miquel

Posted on October 25, 2013 at 12:03

It allows you to enumerate through the directory content one file at a time. They will appear in the order they are in the directory, which may not be linear/sorted, so make no assumptions there.

Please refer to the documentation if the function usage is not familiar to you, as it also provides a worked example. 

http://elm-chan.org/fsw/ff/en/readdir.html

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
muntu_the_killer
Associate II
Posted on October 28, 2013 at 11:29

I'm trying to use f_readdir(), but I need to have to dp parameter (directory object). I want to search in the root, and I think i have to use f_opendir() to give it in the path parameter. I read

http://elm-chan.org/fsw/ff/en/filename.html

 and it seems that I have to write something like this: 

rc = f_opendir(&dir, '' ''); but I have a question.

The f_closedir() doesn't exist in my keil libraries. Can I do it without opendir(), only with f_readdir()?

Thanks!

Miquel

Posted on October 28, 2013 at 13:29

I'm not sure how Keil plays into this the, some versions may not have/need f_closedir

res = f_opendir(&dir, ''''); // Root directory, empty string (no space) Try to use the library as intended, don't try to invent new methods. If the f_opendir is not working, examine the result code.

FRESULT res;
FILINFO fno;
FIL fil;
DIR dir;
char* path;
char *fn; /* This function is assuming non-Unicode cfg. */
#if _USE_LFN
static char lfn[_MAX_LFN + 1];
fno.lfname = lfn;
fno.lfsize = sizeof lfn;
#endif
path = '''';
res = f_opendir(&dir, path);
if (res != FR_OK)
printf(''res = %d f_opendir
'', res);
if (res == FR_OK)
{
while(1)
{
char *fn;
res = f_readdir(&dir, &fno);
if (res != FR_OK)
printf(''res = %d f_readdir
'', res);
if ((res != FR_OK) || (fno.fname[0] == 0))
break;
#if _USE_LFN
fn = *fno.lfname ? fno.lfname : fno.fname;
#else
fn = fno.fname;
#endif
printf(''%c%c%c%c '',
((fno.fattrib & AM_DIR) ? 'D' : '-'),
((fno.fattrib & AM_RDO) ? 'R' : '-'),
((fno.fattrib & AM_SYS) ? 'S' : '-'),
((fno.fattrib & AM_HID) ? 'H' : '-') );
printf(''%10d '', fno.fsize);
printf(''%s/%s
'', path, fn);
}
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
muntu_the_killer
Associate II
Posted on October 29, 2013 at 13:42

Hi Clive,

I've changed what you say and now it works perfectly, but when I want to write for example 1000kb, the program only writes 389kb, is like there was a maximum allowable value.

Is this true? And if so, how can I change it?

Thanks,

Miquel

Posted on October 29, 2013 at 16:39

I'm writing multiple megabytes, no magic required.

Make sure you are closing the files. Make sure the WRITE of the SD Card is occurring, and correct. Add a verify phase if that helps debug the issue.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..