diff options
| author | Peter D. Gray | 2018-07-13 10:20:37 -0400 |
|---|---|---|
| committer | Damien George | 2018-07-14 17:17:46 +1000 |
| commit | 2a3979bcb3077930056c3cba03f073f55afd510a (patch) | |
| tree | 4b123565c8396485e32f1554092ee31b60b4f587 | |
| parent | 385fa5180663221bbec033c54c37fb38f589579b (diff) | |
stm32/fatfs_port: Fix bug when MICROPY_HW_ENABLE_RTC not enabled.
Prior to this patch, get_fattime() was calling a HAL RTC function with the
HW instance pointer as null because rtc_init_start() was never called.
Also marked it as a weak function, to allow a board to override it.
| -rw-r--r-- | ports/stm32/fatfs_port.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/ports/stm32/fatfs_port.c b/ports/stm32/fatfs_port.c index d0e311ed7..3feeab263 100644 --- a/ports/stm32/fatfs_port.c +++ b/ports/stm32/fatfs_port.c @@ -28,11 +28,16 @@ #include "lib/oofatfs/ff.h" #include "rtc.h" -DWORD get_fattime(void) { +MP_WEAK DWORD get_fattime(void) { + #if MICROPY_HW_ENABLE_RTC rtc_init_finalise(); RTC_TimeTypeDef time; RTC_DateTypeDef date; HAL_RTC_GetTime(&RTCHandle, &time, RTC_FORMAT_BIN); HAL_RTC_GetDate(&RTCHandle, &date, RTC_FORMAT_BIN); return ((2000 + date.Year - 1980) << 25) | ((date.Month) << 21) | ((date.Date) << 16) | ((time.Hours) << 11) | ((time.Minutes) << 5) | (time.Seconds / 2); + #else + // Jan 1st, 2018 at midnight. Not sure what timezone. + return ((2018 - 1980) << 25) | ((1) << 21) | ((1) << 16) | ((0) << 11) | ((0) << 5) | (0 / 2); + #endif } |
