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
chen
Associate II
Posted on January 31, 2014 at 10:13

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?

jdcowpland
Associate II
Posted on January 31, 2014 at 11:53

Yes RTC is working. I can debug and hover over the values and it shows me the current time without any problems.

chen
Associate II
Posted on January 31, 2014 at 12:21

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.

jdcowpland
Associate II
Posted on January 31, 2014 at 13:35

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?
jdcowpland
Associate II
Posted on January 31, 2014 at 13:35

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?
chen
Associate II
Posted on January 31, 2014 at 15:14

Hi

''But based on what you're saying, I should be calling it as

res = set_timestamp(Filename);

right?'' Yes, make sure the filename is drive:path\filename. Drive should be the same as what fatfs uses
Posted on January 31, 2014 at 15:27

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.
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 January 31, 2014 at 16:09

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.

Posted on January 31, 2014 at 16:37

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
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..