2023-11-07 02:22 PM
File created on SD Card shows incorrect creation time.
shown in above fig in red all files which gets created on SD card carry same creation time.
Wondering if missing something in CubeMX settings
Solved! Go to Solution.
2023-11-07 05:32 PM
Seems like I need to do something like this for kiel5 to resolve the issue.
2023-11-07 02:27 PM
a) You'd need something on the system maintaining current time.
b) Function in DISKIO layer providing get_fattime() from the aforementioned.
2023-11-07 02:39 PM
Thank you for quick response.
a) You'd need something on the system maintaining current time.
We have RTC working that's how getting correct time for the timestamps, not sure if that's what you meant here.
b) Function in DISKIO layer providing get_fattime() from the aforementioned.
I see following function, I can implement something like this but not sure, how and where that needs to be called so that file created will reflect correct system time.
DWORD get_fattime (void) { time_t t; struct tm *stm; t = time(0); stm = localtime(&t); return (DWORD)(stm->tm_year - 80) << 25 | (DWORD)(stm->tm_mon + 1) << 21 | (DWORD)stm->tm_mday << 16 | (DWORD)stm->tm_hour << 11 | (DWORD)stm->tm_min << 5 | (DWORD)stm->tm_sec >> 1; }
2023-11-07 02:45 PM
Seems like filesystem interface does not write correct time. Probably something inside middleware.
2023-11-07 02:53 PM
It's a call-out function from within the FatFs implementation, it is there for YOU to furnish current time upon request. You can recover it from the RTC, or your own SYSTEMTIME ticker, or whatever.
It uses this to fill in the fields of the file system structure you currently see as 1-Jan-2016 4:00 AM
2023-11-07 03:48 PM
I added this function main.c file and added a print in the function to see if it gets called when I create a file.
uint64_t get_fattime(void) {
/* USER CODE BEGIN get_fattime */
RTC_TimeTypeDef rtc_time; // Structure to hold time information
RTC_DateTypeDef rtc_date; // Structure to hold date information
uint64_t attime;
HAL_RTC_GetTime(&hrtc, &rtc_time, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &rtc_date, RTC_FORMAT_BIN);
attime = (((uint64_t)rtc_date.Year - 1980) << 25)
| ((uint64_t)rtc_date.Month << 21)
| ((uint64_t)rtc_date.Date << 16)
| (uint64_t)(rtc_time.Hours << 11)
| (uint64_t)(rtc_time.Minutes << 5)
| (uint64_t)(rtc_time.Seconds >> 1);
printf("\n\nget_fattime got called\n\n");
return attime;
/* USER CODE END get_fattime */
}
I don't see the print that this function gets called when I create the file and see same time stamp
2023-11-07 03:51 PM
By the time create the file RTC is already working
2023-11-07 04:41 PM
Check _FS_NORTC in ffconf.h
2023-11-07 05:12 PM
I don't see ffconf.h file in my path or _FS_NORTC in the project, do I need to create this file and add it?
2023-11-07 05:32 PM
Seems like I need to do something like this for kiel5 to resolve the issue.