RTC (Where / How is it working)

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
hippy
Posts: 130
Joined: Sat Feb 20, 2021 2:46 pm
Location: UK

Re: RTC (Where / How is it working)

Post by hippy » Thu Sep 16, 2021 11:13 am

hippy wrote:
Thu Sep 16, 2021 10:59 am
Someone really needs to do a complete audit of MicroPython to find where 'datetime_t' is used and correct any conversion errors.
One place where I have found a bug is in 'fatfs_port.c' -

Code: Select all

MP_WEAK DWORD get_fattime(void) {
    datetime_t t;
    rtc_get_datetime(&t);
    return ((2000 + t.year - 1980) << 25) | ((t.month) << 21) | ((t.day) << 16) | ((t.hour) << 11) | ((t.min) << 5) | (t.sec / 2);
}
That doesn't use weekday but it does erroneously expect 't.year' to be a two digit value, 00-99, where in fact it is a four digit value. This means all FAT timestamps and anything using 'get_fattime' will be wrong or corrupted.

Thankfully 'datetime_t' appears to be port specific and only used in 'main.c', 'machine_rtc.c', 'modutime.c', 'fatfs_port.c' and ''mphalport.c".

It appears that all but the last require fixing.

Post Reply