mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #8213 from jeromecoutant/PR_RTC_F1
STM32F1 RTC : save values in registerpull/8374/head
commit
ebff1e553b
|
@ -188,8 +188,6 @@
|
||||||
/** @defgroup RTC_Private_Functions RTC Private Functions
|
/** @defgroup RTC_Private_Functions RTC Private Functions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
static uint32_t RTC_ReadTimeCounter(RTC_HandleTypeDef* hrtc);
|
|
||||||
static HAL_StatusTypeDef RTC_WriteTimeCounter(RTC_HandleTypeDef* hrtc, uint32_t TimeCounter);
|
|
||||||
static uint32_t RTC_ReadAlarmCounter(RTC_HandleTypeDef* hrtc);
|
static uint32_t RTC_ReadAlarmCounter(RTC_HandleTypeDef* hrtc);
|
||||||
static HAL_StatusTypeDef RTC_WriteAlarmCounter(RTC_HandleTypeDef* hrtc, uint32_t AlarmCounter);
|
static HAL_StatusTypeDef RTC_WriteAlarmCounter(RTC_HandleTypeDef* hrtc, uint32_t AlarmCounter);
|
||||||
static HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef* hrtc);
|
static HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef* hrtc);
|
||||||
|
@ -1355,7 +1353,7 @@ HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef* hrtc)
|
||||||
* the configuration information for RTC.
|
* the configuration information for RTC.
|
||||||
* @retval Time counter
|
* @retval Time counter
|
||||||
*/
|
*/
|
||||||
static uint32_t RTC_ReadTimeCounter(RTC_HandleTypeDef* hrtc)
|
uint32_t RTC_ReadTimeCounter(RTC_HandleTypeDef* hrtc)
|
||||||
{
|
{
|
||||||
uint16_t high1 = 0U, high2 = 0U, low = 0U;
|
uint16_t high1 = 0U, high2 = 0U, low = 0U;
|
||||||
uint32_t timecounter = 0U;
|
uint32_t timecounter = 0U;
|
||||||
|
@ -1385,7 +1383,7 @@ static uint32_t RTC_ReadTimeCounter(RTC_HandleTypeDef* hrtc)
|
||||||
* @param TimeCounter: Counter to write in RTC_CNT registers
|
* @param TimeCounter: Counter to write in RTC_CNT registers
|
||||||
* @retval HAL status
|
* @retval HAL status
|
||||||
*/
|
*/
|
||||||
static HAL_StatusTypeDef RTC_WriteTimeCounter(RTC_HandleTypeDef* hrtc, uint32_t TimeCounter)
|
HAL_StatusTypeDef RTC_WriteTimeCounter(RTC_HandleTypeDef* hrtc, uint32_t TimeCounter)
|
||||||
{
|
{
|
||||||
HAL_StatusTypeDef status = HAL_OK;
|
HAL_StatusTypeDef status = HAL_OK;
|
||||||
|
|
||||||
|
|
|
@ -518,6 +518,9 @@ HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTim
|
||||||
HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
|
HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
|
||||||
HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
|
HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
|
||||||
HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
|
HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
|
||||||
|
|
||||||
|
uint32_t RTC_ReadTimeCounter(RTC_HandleTypeDef* hrtc);
|
||||||
|
HAL_StatusTypeDef RTC_WriteTimeCounter(RTC_HandleTypeDef* hrtc, uint32_t TimeCounter);
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -141,51 +141,15 @@ Information about STM32F1:
|
||||||
For date, there is no specific register, only a software structure.
|
For date, there is no specific register, only a software structure.
|
||||||
It is then not a problem to not use shifts.
|
It is then not a problem to not use shifts.
|
||||||
*/
|
*/
|
||||||
#if TARGET_STM32F1
|
|
||||||
time_t rtc_read(void)
|
time_t rtc_read(void)
|
||||||
{
|
{
|
||||||
RTC_DateTypeDef dateStruct = {0};
|
#if TARGET_STM32F1
|
||||||
RTC_TimeTypeDef timeStruct = {0};
|
|
||||||
struct tm timeinfo;
|
|
||||||
|
|
||||||
RtcHandle.Instance = RTC;
|
RtcHandle.Instance = RTC;
|
||||||
|
return RTC_ReadTimeCounter(&RtcHandle);
|
||||||
// Read actual date and time
|
|
||||||
// Warning: the time must be read first!
|
|
||||||
HAL_RTC_GetTime(&RtcHandle, &timeStruct, RTC_FORMAT_BIN);
|
|
||||||
HAL_RTC_GetDate(&RtcHandle, &dateStruct, RTC_FORMAT_BIN);
|
|
||||||
|
|
||||||
/* date information is null before first write procedure */
|
|
||||||
/* set 01/01/1970 as default values */
|
|
||||||
if (dateStruct.Year == 0) {
|
|
||||||
dateStruct.Year = 2 ;
|
|
||||||
dateStruct.Month = 1 ;
|
|
||||||
dateStruct.Date = 1 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup a tm structure based on the RTC
|
|
||||||
/* tm_wday information is ignored by _rtc_maketime */
|
|
||||||
/* tm_isdst information is ignored by _rtc_maketime */
|
|
||||||
timeinfo.tm_mon = dateStruct.Month - 1;
|
|
||||||
timeinfo.tm_mday = dateStruct.Date;
|
|
||||||
timeinfo.tm_year = dateStruct.Year + 68;
|
|
||||||
timeinfo.tm_hour = timeStruct.Hours;
|
|
||||||
timeinfo.tm_min = timeStruct.Minutes;
|
|
||||||
timeinfo.tm_sec = timeStruct.Seconds;
|
|
||||||
|
|
||||||
// Convert to timestamp
|
|
||||||
time_t t;
|
|
||||||
if (_rtc_maketime(&timeinfo, &t, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else /* TARGET_STM32F1 */
|
#else /* TARGET_STM32F1 */
|
||||||
|
|
||||||
time_t rtc_read(void)
|
|
||||||
{
|
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
|
|
||||||
/* Since the shadow registers are bypassed we have to read the time twice and compare them until both times are the same */
|
/* Since the shadow registers are bypassed we have to read the time twice and compare them until both times are the same */
|
||||||
|
@ -223,12 +187,23 @@ time_t rtc_read(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* TARGET_STM32F1 */
|
#endif /* TARGET_STM32F1 */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void rtc_write(time_t t)
|
void rtc_write(time_t t)
|
||||||
{
|
{
|
||||||
|
#if TARGET_STM32F1
|
||||||
|
|
||||||
|
RtcHandle.Instance = RTC;
|
||||||
|
if (RTC_WriteTimeCounter(&RtcHandle, t) != HAL_OK) {
|
||||||
|
error("RTC_WriteTimeCounter error\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /* TARGET_STM32F1 */
|
||||||
|
|
||||||
RTC_DateTypeDef dateStruct = {0};
|
RTC_DateTypeDef dateStruct = {0};
|
||||||
RTC_TimeTypeDef timeStruct = {0};
|
RTC_TimeTypeDef timeStruct = {0};
|
||||||
|
|
||||||
|
@ -253,12 +228,9 @@ void rtc_write(time_t t)
|
||||||
timeStruct.Hours = timeinfo.tm_hour;
|
timeStruct.Hours = timeinfo.tm_hour;
|
||||||
timeStruct.Minutes = timeinfo.tm_min;
|
timeStruct.Minutes = timeinfo.tm_min;
|
||||||
timeStruct.Seconds = timeinfo.tm_sec;
|
timeStruct.Seconds = timeinfo.tm_sec;
|
||||||
|
|
||||||
#if !(TARGET_STM32F1)
|
|
||||||
timeStruct.TimeFormat = RTC_HOURFORMAT_24;
|
timeStruct.TimeFormat = RTC_HOURFORMAT_24;
|
||||||
timeStruct.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
|
timeStruct.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
|
||||||
timeStruct.StoreOperation = RTC_STOREOPERATION_RESET;
|
timeStruct.StoreOperation = RTC_STOREOPERATION_RESET;
|
||||||
#endif /* TARGET_STM32F1 */
|
|
||||||
|
|
||||||
#if DEVICE_LPTICKER && !MBED_CONF_TARGET_LPTICKER_LPTIM
|
#if DEVICE_LPTICKER && !MBED_CONF_TARGET_LPTICKER_LPTIM
|
||||||
/* Before setting the new time, we need to update the LPTICKER_counter value */
|
/* Before setting the new time, we need to update the LPTICKER_counter value */
|
||||||
|
@ -280,6 +252,7 @@ void rtc_write(time_t t)
|
||||||
}
|
}
|
||||||
|
|
||||||
core_util_critical_section_exit();
|
core_util_critical_section_exit();
|
||||||
|
#endif /* TARGET_STM32F1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
int rtc_isenabled(void)
|
int rtc_isenabled(void)
|
||||||
|
|
Loading…
Reference in New Issue