STM32SD adjust file timestamps?

Post here first, or if you can't find a relevant section!
Post Reply
m20ks
Posts: 2
Joined: Sun Mar 17, 2024 12:25 pm

STM32SD adjust file timestamps?

Post by m20ks »

So far I've successfully implemented file writing to my SD card using the STM32SD library. However, the timestamp for file creation and modification defaults to 1 January 1970 at 01:00 (UNIX time +1 hour?). I tried the STM32RTC library for setting the internal clock (rtc.setEpoch(1710682932)) and even via the Arduino Time library (adjustTime(1710682933)), but without any succes. How can I adjust the timestamp used for writing files, and is this even possible with the STM32SD library?

STM32SD library: https://github.com/stm32duino/STM32SD
STM32RTC library: https://github.com/stm32duino/STM32RTC
dannyf
Posts: 446
Joined: Sat Jul 04, 2020 7:46 pm

Re: STM32SD adjust file timestamps?

Post by dannyf »

you probably want to figure out when stm32sd writes the time stamp in the directory, where it obtains the timing information and provide that from the rtc library.
m20ks
Posts: 2
Joined: Sun Mar 17, 2024 12:25 pm

Re: STM32SD adjust file timestamps?

Post by m20ks »

Something I'll spend more time on coming week, but together with the SDFat library the following callback seems to work:

Code: Select all

void dateTime(uint16_t* date, uint16_t* time, uint8_t* ms10) {
  DateTime now = rtc.now();

  // Return date using FS_DATE macro to format fields.
  *date = FS_DATE(now.year(), now.month(), now.day());

  // Return time using FS_TIME macro to format fields.
  *time = FS_TIME(now.hour(), now.minute(), now.second());

  // Return low time bits in units of 10 ms, 0 <= ms10 <= 199.
  *ms10 = now.second() & 1 ? 100 : 0;
}

Sources:
https://forum.arduino.cc/t/which-sd-lib ... /72070/15
https://www.if.ufrj.br/~pef/producao_ac ... stamp.ino
https://github.com/greiman/SdFat/blob/m ... pTest.ino
https://gist.github.com/Marzogh/8dc8011934eecf47e154
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: STM32SD adjust file timestamps?

Post by ag123 »

apparently STM32SD
https://github.com/stm32duino/STM32SD
depends on FatFs
https://github.com/stm32duino/FatFs

which has a getfattime() callback
https://github.com/stm32duino/FatFs/blo ... /ff.h#L295
https://github.com/stm32duino/FatFs/blo ... /ff.c#L492
https://github.com/stm32duino/FatFs/blo ... ff.c#L3364

hence, you would need to return a DWORD (i'd think 32 bits) that matches a fat date time format
a google search stumbled into this
https://shullich.blogspot.com/2009/12/t ... ormat.html
https://web.mit.edu/freebsd/head/sys/ke ... _fattime.c

hence, you need to implement DWORD getfattime() that returns a 32 bit timestamp value perhaps in that format.

Code: Select all

               24                16                 8                 0
+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
|Y|Y|Y|Y|Y|Y|Y|M| |M|M|M|D|D|D|D|D| |h|h|h|h|h|m|m|m| |m|m|m|s|s|s|s|s|
+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
 \___________/\________/\_________/ \________/\____________/\_________/
    year        month       day      hour       minute        second
getting time from rtc should be 'easy', there are 'standard' libs for that.
then convert that to fat datetime stamp and return it, it would take experimenting as it is uncertain if this is after all the format.
Post Reply

Return to “General discussion”