#include #include #include #include #include int rtc_get_time(struct tm *time) { time_t unix_time; if (!time) return -1; unix_time = rtc_get_counter_val(); if (!gmtime_r(&unix_time, time)) return -1; return 0; } static int rtc_set_time(struct tm *time) { time_t unix_time; if (!time) return -1; unix_time = mktime(time); rtc_set_counter_val((uint32_t)unix_time); return 0; } int rtc_init(struct tm *time) { rtc_auto_awake(RCC_LSI, 0x7fff); rtc_set_time(time); return 0; }