From c2fca3dffedfa15044bb70f8a997ea1c3920ebe3 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Fri, 5 Feb 2021 13:13:22 +0800 Subject: 修复RTC驱动以及libc time.c库若干问题 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/stm32/libraries/HAL_Drivers/drv_rtc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'bsp/stm32/libraries') diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_rtc.c b/bsp/stm32/libraries/HAL_Drivers/drv_rtc.c index 75f85cfa81..b0dcb8d114 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_rtc.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_rtc.c @@ -6,10 +6,12 @@ * Change Logs: * Date Author Notes * 2018-12-04 balanceTWK first version - * 2020-10-14 Dozingfiretruck Porting for stm32wbxx + * 2020-10-14 Dozingfiretruck Porting for stm32wbxx + * 2021-02-05 Meco Man fix the problem of mixing local time and UTC time */ #include "board.h" +#include #ifdef BSP_USING_ONCHIP_RTC @@ -54,7 +56,7 @@ static time_t get_rtc_timestamp(void) tm_new.tm_year = RTC_DateStruct.Year + 100; LOG_D("get rtc time."); - return mktime(&tm_new); + return timegm(&tm_new); } static rt_err_t set_rtc_time_stamp(time_t time_stamp) @@ -63,7 +65,7 @@ static rt_err_t set_rtc_time_stamp(time_t time_stamp) RTC_DateTypeDef RTC_DateStruct = {0}; struct tm *p_tm; - p_tm = localtime(&time_stamp); + p_tm = gmtime(&time_stamp); if (p_tm->tm_year < 100) { return -RT_ERROR; -- cgit v1.3.1