cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_RTC_SetTime() - Changing daylight

Simon Sch�pbach
Associate II
Posted on April 25, 2017 at 10:19

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-hal
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on April 25, 2017 at 14:03

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);

View solution in original post

4 REPLIES 4
john doe
Lead
Posted on April 25, 2017 at 12:23

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);

}
Posted on April 25, 2017 at 13:05

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?

Posted on April 25, 2017 at 14:03

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);

Posted on April 25, 2017 at 14:11

Yes, for me it is unbelievable, that there is no such functionality support by HAL library.

Anyway, thank you very much for replies.