8 years, 10 months ago.

Should I set_time() before running FileSystem?

In my application, I can get precise timestamp from CDMA module, which is calibrated by GPS in the basestation.

So I want to my logging file on SD card with timestamp, rather than random timestamp. If I can not use timestamp accompany with specified files. then I have to use folders to seperate them.

Should I set_time() before running File system? And to be frank, I haven't find any clue how the system clock is used in writing files to SD card.

Question relating to:

1 Answer

8 years, 10 months ago.

If you want to have timestamps: Yes. I believe it is somewhere burried in FATFileSystem where the time is retrieved again. Your board needs to have an onboard RTC for this (if it does not have this, and you have an external one, you can also make it use the external one, using the attach_rtc function: https://github.com/mbedmicro/mbed/blob/4a184d980e8d670adadd2ae4801f2f8a34988002/libraries/mbed/api/rtc_time.h

Used like:

attach_rtc(&read_fun, &write_fun, NULL, NULL);

Last two functions you can generally just keep on NULL. Read_fun needs to be any function which returns a timestamp_t, while writefun is one which takes a timestamp_t as argument.

Accepted Answer

Thanks, Erik,

There is a STM32F103RB on board, and it supports internal RTC with 32768 crystal. I have tried it out. The RTC can be set, read and its running .

(Maybe you have found another thread about mktime())

posted by Kai Liu 18 Jun 2015