cancel
Showing results for 
Search instead for 
Did you mean: 

f_utime

jdcowpland
Associate II
Posted on January 31, 2014 at 09:31

Anyone got any experience using the f_utime function from chan's fatfs? I've got a function that uses it to put a timestamp on a file I create on an SD card, but it returns INVALID_NAME every time. Not quite sure why. Anybody have any ideas? (Btw, I'm using a STM32F415VG if that helps). My code looks like this:

FRESULT set_timestamp (char *obj)
{
FILINFO fno;
RTC_TimeTypeDef RTC_TimeStructure;
RTC_DateTypeDef RTC_DateStructure;
RTC_GetTime(RTC_Format_BIN,&RTC_TimeStructure);
RTC_GetDate(RTC_Format_BIN,&RTC_DateStructure);
int hour = RTC_TimeStructure.RTC_Hours;
int min = RTC_TimeStructure.RTC_Minutes;
int sec = RTC_TimeStructure.RTC_Seconds;
int month = RTC_DateStructure.RTC_Month;
int mday = RTC_DateStructure.RTC_Date;
int year = RTC_DateStructure.RTC_Year;
year+=2000;
fno.fdate = (WORD)(((year - 1980) << 9) | month << 5 | mday);
fno.ftime = (WORD)(hour <<11 | min <<5 | sec/2 );
return f_utime(obj, &fno);
}

#fatfs
19 REPLIES 19
jdcowpland
Associate II
Posted on February 03, 2014 at 11:40

Ah yeah, thanks! turns out I was using the fatfs from 2011 so was getting a bit confused with the documentation! Any idea how to access a directory within a directory? i.e., say I wanted to open a folder in the path ''0:dir1/dir2''. I've tried using f_opendir and f_chdir, but each time it comes back saying no path. It's happy with ''0:dir1'' for opendir, or with ''/dir1'' for chdir, but can't seem to get it to go into the next directory.

Posted on February 03, 2014 at 15:44

Check the _FS_RPATH setting

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jdcowpland
Associate II
Posted on February 26, 2014 at 13:48

From what I understand from that link, the following should work, but it doesn't:

res = f_chdir(''1:\dir1'');

res = f_chdir(''\dir2'');

It has no problem with the first line, but the second line says no file. Has anyone tried directories within directories with fatfs?

chen
Associate II
Posted on February 26, 2014 at 15:15

Hi

It has been a while !

OK, I think the first one works because it explicitly has he drive. The path has to be complete - including the drive letter.

The latter does not work because FatFS does not know what the drive is.

It work on a PC because on a PC, there is a hidden variable that holds the current drive and gets filled in if it is not specified.

Incidentally, why is the drive label ''1'' ?

jdcowpland
Associate II
Posted on February 26, 2014 at 15:52

I have 

_FS_RPATH == 1 in my code, which according to the fatfs documentation means ''

When relative path feature is enabled (

_FS_RPATH == 1

), specified path is followed from the root directory if a heading separator is exist. If not, it is followed from the current directory set with 

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

 function.

'' Surely that means I don't need the drive number if I'm already in that drive? The reason I'm using drive 1 is that I have two drives(sd card and usb).

Posted on February 26, 2014 at 16:02

Is the structure \DIR1\DIR2? Or what exactly?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jdcowpland
Associate II
Posted on February 26, 2014 at 16:14

Yes, this is what it looks like from windows: E:\dir1\dir2

Posted on February 26, 2014 at 16:26

Wouldn't the expect syntax then be relative?

res = f_chdir(''1:/dir1'');

res = f_chdir(''dir2'');

or

res = f_chdir(''1:/dir1/dir2'');

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
chen
Associate II
Posted on February 26, 2014 at 16:28

''

I have 

_FS_RPATH == 1 in my code, which according to the fatfs documentation means ''

When relative path feature is enabled (

_FS_RPATH == 1

), specified path is followed from the root directory if a heading separator is exist. If not, it is followed from the current directory set with 

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

 function.

'' Surely that means I don't need the drive number if I'm already in that drive?''

When you say ''

I have 

_FS_RPATH == 1 in my code

'' - can the fatfs code see the define during compilation?

''i

f not, it is followed from the current directory set with 

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

 function.

'' Surely that means I don't need the drive number if I'm already in that drive?''

Has the f_chdir() been called before?

jdcowpland
Associate II
Posted on February 26, 2014 at 16:37

Working! Thanks Clive. Looks like it was confusion over ''\'' or ''/''. Just used f_chdir(''1:/dir1/dir2'') and it worked 🙂