cancel
Showing results for 
Search instead for 
Did you mean: 

FILE created on SD Card shows incorrect creation time.

aahsan
Associate III

File created on SD Card shows incorrect creation time.

aahsan_1-1699395632760.png

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 

1 ACCEPTED SOLUTION

Accepted Solutions
aahsan
Associate III

Seems like I need to do something like this for kiel5 to resolve the issue.

aahsan_0-1699407111316.png

 

View solution in original post

10 REPLIES 10

a) You'd need something on the system maintaining current time.

b) Function in DISKIO layer providing get_fattime() from the aforementioned.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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;
}  

 

MKanc.1
Associate III

Seems like filesystem interface does not write correct time. Probably something inside middleware.

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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

aahsan_0-1699400837473.png

 

By the time create the file RTC is already working

aahsan_1-1699401052183.png

 

Check _FS_NORTC in ffconf.h

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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?

aahsan
Associate III

Seems like I need to do something like this for kiel5 to resolve the issue.

aahsan_0-1699407111316.png