2017-04-25 01:19 AM
I have some problems to understand the functionality of HAL_RTC_SetTime().
It is possible to set time and daylight handling data. This makes sense.
But how can I adjust the daylight without the other time data?
Or the the hours, minutes, seconds only?
hrtc->Instance->TR = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK);
/* Clear the bits to be configured */hrtc->Instance->CR &= (uint32_t)~RTC_CR_BCK;/* Configure the RTC_CR register */hrtc->Instance->CR |= (uint32_t)(sTime->DayLightSaving | sTime->StoreOperation);Because inside HAL_RTC_SetTime() the code above is processed always (except in initialisation).
How should I initialise the struct member if I only want to adjust the daylight?
RTC_TimeTypeDef sTime;
sTime.Hours = ?;
sTime.Minutes = ?;
sTime.Seconds = ?;
s.Time.DayLightSaving = RTC_DAYLIGHTSAVING_ADD1H;
s.Time.StoreOperation = RTC_STOREOPERATION_SET;
And on the other side what should be written in DayLightSaving if I just want to adjust the time (Hours, Minutes, Seconds)?
#stm32f4xx #rtc #rtc-halSolved! Go to Solution.
2017-04-25 07:03 AM
You would have to de-init and re-init the RTC or write your own extension to the HAL library.
if I understand your question correctly, you are wondering why there is no HAL wrapper for just
hrtc->Instance->CR |= (uint32_t)(sTime->DayLightSaving | sTime->StoreOperation);
2017-04-25 03:23 AM
when in doubt, look at how the HAL does things. you do not mention which mcu or cube version you are using. the code below is for an f7 in cube 1.7.0. Grep around your own repository and see what's there
/**
* @brief Memorize whether the daylight saving time change has been performed * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before. * @rmtoll CR BKP LL_RTC_TIME_EnableDayLightStore * @param RTCx RTC Instance * @retval None */__STATIC_INLINE void LL_RTC_TIME_EnableDayLightStore(RTC_TypeDef *RTCx){ SET_BIT(RTCx->CR, RTC_CR_BKP);}/**
* @brief Disable memorization whether the daylight saving time change has been performed. * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before. * @rmtoll CR BKP LL_RTC_TIME_DisableDayLightStore * @param RTCx RTC Instance * @retval None */__STATIC_INLINE void LL_RTC_TIME_DisableDayLightStore(RTC_TypeDef *RTCx){ CLEAR_BIT(RTCx->CR, RTC_CR_BKP);}/**
* @brief Check if RTC Day Light Saving stored operation has been enabled or not * @rmtoll CR BKP LL_RTC_TIME_IsDayLightStoreEnabled * @param RTCx RTC Instance * @retval State of bit (1 or 0). */__STATIC_INLINE uint32_t LL_RTC_TIME_IsDayLightStoreEnabled(RTC_TypeDef *RTCx){ return (READ_BIT(RTCx->CR, RTC_CR_BKP) == (RTC_CR_BKP));}/**
* @brief Subtract 1 hour (winter time change) * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before. * @rmtoll CR SUB1H LL_RTC_TIME_DecHour * @param RTCx RTC Instance * @retval None */__STATIC_INLINE void LL_RTC_TIME_DecHour(RTC_TypeDef *RTCx){ SET_BIT(RTCx->CR, RTC_CR_SUB1H);}/**
* @brief Add 1 hour (summer time change) * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before. * @rmtoll CR ADD1H LL_RTC_TIME_IncHour * @param RTCx RTC Instance * @retval None */__STATIC_INLINE void LL_RTC_TIME_IncHour(RTC_TypeDef *RTCx){ SET_BIT(RTCx->CR, RTC_CR_ADD1H);}2017-04-25 06:05 AM
Thank you very much for your answer.
But I don't know if I understand correctly what you mean.
You suggest to copy these functions to my project?
I don't have a problem to write a function which adjust the daylight. Of course I could manually set the correct values to the RTC registers. But I want to use the HAL library and in my opinion it is really messy to code around the library functions. With the only reason that they don't support a simple functionality like daylight adjustment.
Or have I missunderstood something?
2017-04-25 07:03 AM
You would have to de-init and re-init the RTC or write your own extension to the HAL library.
if I understand your question correctly, you are wondering why there is no HAL wrapper for just
hrtc->Instance->CR |= (uint32_t)(sTime->DayLightSaving | sTime->StoreOperation);
2017-04-25 07:11 AM
Yes, for me it is unbelievable, that there is no such functionality support by HAL library.
Anyway, thank you very much for replies.