/* * Copyright (c) 2026, QXZ * * BL 侧时间源:ecode 组件需要 year/month/day/hour/min/sec 与 Reflash_RTC()。 * BL 不开 RT_USING_RTC,直接读 HAL 的 RTC 句柄。 */ #include #include #include "stm32f4xx_hal.h" extern RTC_HandleTypeDef RTC_Handler; uint32_t year; uint32_t month; uint32_t day; uint32_t hour; uint32_t min; uint32_t sec; void Reflash_RTC(void) { RTC_TimeTypeDef t = {0}; RTC_DateTypeDef d = {0}; HAL_RTC_GetTime(&RTC_Handler, &t, RTC_FORMAT_BIN); HAL_RTC_GetDate(&RTC_Handler, &d, RTC_FORMAT_BIN); // 备份域刚丢电时 RTC 是垃圾值,宁可记成 2000-01-01 也不写无效年份 if ((d.Year > 99) || (d.Month < 1) || (d.Month > 12) || (d.Date < 1) || (d.Date > 31)) { year = 2000; month = 1; day = 1; hour = 0; min = 0; sec = 0; return; } year = (uint32_t)d.Year + 2000; month = d.Month; day = d.Date; hour = t.Hours; min = t.Minutes; sec = t.Seconds; }