mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-21 01:47:09 +08:00
Merge pull request #3591 from tyustli/master
[bsp] fix stm32 f1 series rtc bug
This commit is contained in:
commit
7fa4c90ed8
@ -12,13 +12,6 @@
|
|||||||
|
|
||||||
#ifdef BSP_USING_ONCHIP_RTC
|
#ifdef BSP_USING_ONCHIP_RTC
|
||||||
|
|
||||||
|
|
||||||
#ifndef HAL_RTCEx_BKUPRead
|
|
||||||
#define HAL_RTCEx_BKUPRead(x1, x2) (~BKUP_REG_DATA)
|
|
||||||
#endif
|
|
||||||
#ifndef HAL_RTCEx_BKUPWrite
|
|
||||||
#define HAL_RTCEx_BKUPWrite(x1, x2, x3)
|
|
||||||
#endif
|
|
||||||
#ifndef RTC_BKP_DR1
|
#ifndef RTC_BKP_DR1
|
||||||
#define RTC_BKP_DR1 RT_NULL
|
#define RTC_BKP_DR1 RT_NULL
|
||||||
#endif
|
#endif
|
||||||
@ -33,6 +26,16 @@ static struct rt_device rtc;
|
|||||||
|
|
||||||
static RTC_HandleTypeDef RTC_Handler;
|
static RTC_HandleTypeDef RTC_Handler;
|
||||||
|
|
||||||
|
RT_WEAK uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister)
|
||||||
|
{
|
||||||
|
return (~BKUP_REG_DATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
RT_WEAK void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
static time_t get_rtc_timestamp(void)
|
static time_t get_rtc_timestamp(void)
|
||||||
{
|
{
|
||||||
RTC_TimeTypeDef RTC_TimeStruct = {0};
|
RTC_TimeTypeDef RTC_TimeStruct = {0};
|
||||||
@ -84,6 +87,15 @@ static rt_err_t set_rtc_time_stamp(time_t time_stamp)
|
|||||||
|
|
||||||
LOG_D("set rtc time.");
|
LOG_D("set rtc time.");
|
||||||
HAL_RTCEx_BKUPWrite(&RTC_Handler, RTC_BKP_DR1, BKUP_REG_DATA);
|
HAL_RTCEx_BKUPWrite(&RTC_Handler, RTC_BKP_DR1, BKUP_REG_DATA);
|
||||||
|
|
||||||
|
#ifdef SOC_SERIES_STM32F1
|
||||||
|
/* F1 series does't save year/month/date datas. so keep those datas to bkp reg */
|
||||||
|
HAL_RTCEx_BKUPWrite(&RTC_Handler, RTC_BKP_DR2, RTC_DateStruct.Year);
|
||||||
|
HAL_RTCEx_BKUPWrite(&RTC_Handler, RTC_BKP_DR3, RTC_DateStruct.Month);
|
||||||
|
HAL_RTCEx_BKUPWrite(&RTC_Handler, RTC_BKP_DR4, RTC_DateStruct.Date);
|
||||||
|
HAL_RTCEx_BKUPWrite(&RTC_Handler, RTC_BKP_DR5, RTC_DateStruct.WeekDay);
|
||||||
|
#endif
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,6 +120,36 @@ static void rt_rtc_init(void)
|
|||||||
HAL_RCC_OscConfig(&RCC_OscInitStruct);
|
HAL_RCC_OscConfig(&RCC_OscInitStruct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SOC_SERIES_STM32F1
|
||||||
|
/* update RTC_BKP_DRx*/
|
||||||
|
static void rt_rtc_f1_bkp_update(void)
|
||||||
|
{
|
||||||
|
RTC_DateTypeDef RTC_DateStruct = {0};
|
||||||
|
|
||||||
|
HAL_PWR_EnableBkUpAccess();
|
||||||
|
__HAL_RCC_BKP_CLK_ENABLE();
|
||||||
|
|
||||||
|
RTC_DateStruct.Year = HAL_RTCEx_BKUPRead(&RTC_Handler, RTC_BKP_DR2);
|
||||||
|
RTC_DateStruct.Month = HAL_RTCEx_BKUPRead(&RTC_Handler, RTC_BKP_DR3);
|
||||||
|
RTC_DateStruct.Date = HAL_RTCEx_BKUPRead(&RTC_Handler, RTC_BKP_DR4);
|
||||||
|
RTC_DateStruct.WeekDay = HAL_RTCEx_BKUPRead(&RTC_Handler, RTC_BKP_DR5);
|
||||||
|
if (HAL_RTC_SetDate(&RTC_Handler, &RTC_DateStruct, RTC_FORMAT_BIN) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
HAL_RTC_GetDate(&RTC_Handler, &RTC_DateStruct, RTC_FORMAT_BIN);
|
||||||
|
if (HAL_RTCEx_BKUPRead(&RTC_Handler, RTC_BKP_DR4) != RTC_DateStruct.Date)
|
||||||
|
{
|
||||||
|
HAL_RTCEx_BKUPWrite(&RTC_Handler, RTC_BKP_DR1, BKUP_REG_DATA);
|
||||||
|
HAL_RTCEx_BKUPWrite(&RTC_Handler, RTC_BKP_DR2, RTC_DateStruct.Year);
|
||||||
|
HAL_RTCEx_BKUPWrite(&RTC_Handler, RTC_BKP_DR3, RTC_DateStruct.Month);
|
||||||
|
HAL_RTCEx_BKUPWrite(&RTC_Handler, RTC_BKP_DR4, RTC_DateStruct.Date);
|
||||||
|
HAL_RTCEx_BKUPWrite(&RTC_Handler, RTC_BKP_DR5, RTC_DateStruct.WeekDay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static rt_err_t rt_rtc_config(struct rt_device *dev)
|
static rt_err_t rt_rtc_config(struct rt_device *dev)
|
||||||
{
|
{
|
||||||
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
||||||
@ -167,6 +209,14 @@ static rt_err_t rt_rtc_config(struct rt_device *dev)
|
|||||||
return -RT_ERROR;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef SOC_SERIES_STM32F1
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* F1 series need update by bkp reg datas */
|
||||||
|
rt_rtc_f1_bkp_update();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user