2014-01-31 12:31 AM
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
2014-02-03 02:40 AM
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.
2014-02-03 06:44 AM
Check the _FS_RPATH setting
http://elm-chan.org/fsw/ff/en/filename.html
2014-02-26 04:48 AM
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?2014-02-26 06:15 AM
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'' ?2014-02-26 06:52 AM
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).2014-02-26 07:02 AM
Is the structure \DIR1\DIR2? Or what exactly?
2014-02-26 07:14 AM
Yes, this is what it looks like from windows: E:\dir1\dir2
2014-02-26 07:26 AM
Wouldn't the expect syntax then be relative?
res = f_chdir(''1:/dir1''); res = f_chdir(''dir2''); or res = f_chdir(''1:/dir1/dir2'');2014-02-26 07:28 AM
''
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? ''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?'' Has the f_chdir() been called before?2014-02-26 07:37 AM
Working! Thanks Clive. Looks like it was confusion over ''\'' or ''/''. Just used f_chdir(''1:/dir1/dir2'') and it worked :)