Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch to support optional use of the Pico RTC for filesystem timestamps #6

Open
xoblite opened this issue Jun 12, 2024 · 1 comment

Comments

@xoblite
Copy link

xoblite commented Jun 12, 2024

Hi all,

I can't issue a proper pull request at the moment, but it's a really simple patch for tf_card.c so I'll just put it here for now:

DWORD get_fattime (void)
{
	datetime_t t;
	if (rtc_get_datetime(&t))
	{
		return (((t.year - 1980) << 25) + (t.month << 21) + (t.day << 16) + (t.hour << 11) + (t.min << 5) + (t.sec >> 1));
	}
	else
	{
		// Quoting the FatFs documentation, see http://elm-chan.org/fsw/ff/doc/fattime.html :
		// "The get_fattime function shall return any valid time even if the system does not support
		// a real time clock. If a zero is returned, the file will not have a valid timestamp."
		return (((2024 - 1980) << 25) + (1 << 21) + (1 << 16)); // -> 2024, January 1, 00:00:00
	}
}

...plus the associated Pico SDK #include and target_link_library for hardware_rtc elsewhere of course.

Thanks,

BR//Karl @xoblite

@elehobica
Copy link
Owner

Hello @xoblite
Thank you for raising this.

Since get_fattime is defined with weak attribute, you can override it as you like without changing the library itself.

Following is an example that I did almost same thing. (Please focus at tf_card_override.c itself and ignore other parts)

https://github.com/elehobica/pico_spdif_recorder/blob/main/lib/pico_fatfs_customized/tf_card_override.c

Usually it should be okay to just put tf_card_override.c on your project local and compile.

I'm going to add guide on README.

Hope this helps you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants