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-01-31 01:13 AM
Hi
Do you have a working real time clock? The code needs to be able to read the time from a RTC. Your code shows calls to a RTC but is there a RTC in your system? Is it set correctly?2014-01-31 02:53 AM
Yes RTC is working. I can debug and hover over the values and it shows me the current time without any problems.
2014-01-31 03:21 AM
Hi
OK, looking at your code the other thing to look at is the input to your function ''* obj'' Is it null by any chance? It is suppose to be the path - as a string.2014-01-31 04:35 AM
Ah ok that might be where I'm going wrong. I'm creating a file using this code:
res = f_mount(SD, &fs32);
res = f_open(&fil, Filename, FA_CREATE_ALWAYS | FA_WRITE);
res = f_write(&fil, SmartBuffer, size, &BytesWritten);
res = f_close(&fil);
and then trying to give it the timestamp by calling my function:
res = set_timestamp(&fil);
But based on what you're saying, I should be calling it as
res = set_timestamp(Filename);
right?
2014-01-31 04:35 AM
Ah ok that might be where I'm going wrong. I'm creating a file using this code:
res = f_mount(SD, &fs32);
res = f_open(&fil, Filename, FA_CREATE_ALWAYS | FA_WRITE);
res = f_write(&fil, SmartBuffer, size, &BytesWritten);
res = f_close(&fil);
and then trying to give it the timestamp by calling my function:
res = set_timestamp(&fil);
But based on what you're saying, I should be calling it as
res = set_timestamp(Filename);
right?
2014-01-31 06:14 AM
Hi
''But based on what you're saying, I should be calling it asres = set_timestamp(Filename);
right?''
Yes, make sure the filename is drive:path\filename.
Drive should be the same as what fatfs uses
2014-01-31 06:27 AM
Without spending a lot of time digging through the documentation, I would expect the f_utime() to work on correctly pathed and closed files. Observe if any errors are returned.
But, more specifically if you properly implement your RTC abstraction in diskio.c (get_fattime), you probably would have to play game later with setting the creation/modification time stamps.2014-01-31 07:09 AM
Great thanks! works now. Quick question on another fatfs issue. I have SD and USB set up for fatfs and they both work, but I have to mount and dismount each one each time I want to change. This seems to take quite a while to do and I was wondering if you know if it's necessary to do that or if there's a way to keep both mounted. I tried using f_chdrive, but didn't seem to work.
2014-01-31 07:37 AM
I haven't spent any time doing so, but FatFs seems to intrinsically support multiple drive through the diskio.c abstraction. I would assume you'd f_mount() to a different drive and memory context once for each and open files respectively with ''0:xyz'' , or ''1:abc'' type
http://elm-chan.org/fsw/ff/en/open.html