提交 dbaad29e 编写于 作者: I iysheng

[bsp][stm32] Replace gmtime with gmtime_r

Signed-off-by: Niysheng <iysheng@163.com>
上级 b60adb2d
...@@ -65,21 +65,21 @@ static rt_err_t set_rtc_time_stamp(time_t time_stamp) ...@@ -65,21 +65,21 @@ static rt_err_t set_rtc_time_stamp(time_t time_stamp)
{ {
RTC_TimeTypeDef RTC_TimeStruct = {0}; RTC_TimeTypeDef RTC_TimeStruct = {0};
RTC_DateTypeDef RTC_DateStruct = {0}; RTC_DateTypeDef RTC_DateStruct = {0};
struct tm *p_tm; struct tm p_tm = {0};
p_tm = gmtime(&time_stamp); gmtime_r(&time_stamp, &p_tm);
if (p_tm->tm_year < 100) if (p_tm.tm_year < 100)
{ {
return -RT_ERROR; return -RT_ERROR;
} }
RTC_TimeStruct.Seconds = p_tm->tm_sec ; RTC_TimeStruct.Seconds = p_tm.tm_sec ;
RTC_TimeStruct.Minutes = p_tm->tm_min ; RTC_TimeStruct.Minutes = p_tm.tm_min ;
RTC_TimeStruct.Hours = p_tm->tm_hour; RTC_TimeStruct.Hours = p_tm.tm_hour;
RTC_DateStruct.Date = p_tm->tm_mday; RTC_DateStruct.Date = p_tm.tm_mday;
RTC_DateStruct.Month = p_tm->tm_mon + 1 ; RTC_DateStruct.Month = p_tm.tm_mon + 1 ;
RTC_DateStruct.Year = p_tm->tm_year - 100; RTC_DateStruct.Year = p_tm.tm_year - 100;
RTC_DateStruct.WeekDay = p_tm->tm_wday + 1; RTC_DateStruct.WeekDay = p_tm.tm_wday + 1;
if (HAL_RTC_SetTime(&RTC_Handler, &RTC_TimeStruct, RTC_FORMAT_BIN) != HAL_OK) if (HAL_RTC_SetTime(&RTC_Handler, &RTC_TimeStruct, RTC_FORMAT_BIN) != HAL_OK)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册