STM32L4xx_HAL_Driver  1.14.0
Extended RTC TimeStamp functions

RTC TimeStamp and Tamper functions. More...

Functions

HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp (RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
 Set TimeStamp. More...
 
HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT (RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
 Set TimeStamp with Interrupt. More...
 
HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp (RTC_HandleTypeDef *hrtc)
 Deactivate TimeStamp. More...
 
HAL_StatusTypeDef HAL_RTCEx_SetInternalTimeStamp (RTC_HandleTypeDef *hrtc)
 Set Internal TimeStamp. More...
 
HAL_StatusTypeDef HAL_RTCEx_DeactivateInternalTimeStamp (RTC_HandleTypeDef *hrtc)
 Deactivate Internal TimeStamp. More...
 
HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp (RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTimeStamp, RTC_DateTypeDef *sTimeStampDate, uint32_t Format)
 Get the RTC TimeStamp value. More...
 
void HAL_RTCEx_TamperTimeStampIRQHandler (RTC_HandleTypeDef *hrtc)
 Handle TimeStamp interrupt request. More...
 
void HAL_RTCEx_TimeStampEventCallback (RTC_HandleTypeDef *hrtc)
 TimeStamp callback. More...
 
HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent (RTC_HandleTypeDef *hrtc, uint32_t Timeout)
 Handle TimeStamp polling request. More...
 

Detailed Description

RTC TimeStamp and Tamper functions.

 ===============================================================================
                 ##### RTC TimeStamp and Tamper functions #####
 ===============================================================================

 [..] This section provides functions allowing to configure TimeStamp feature

Function Documentation

◆ HAL_RTCEx_DeactivateInternalTimeStamp()

HAL_StatusTypeDef HAL_RTCEx_DeactivateInternalTimeStamp ( RTC_HandleTypeDef hrtc)

Deactivate Internal TimeStamp.

Parameters
hrtcRTC handle
Return values
HALstatus

Definition at line 377 of file stm32l4xx_hal_rtc_ex.c.

378 {
379  /* Process Locked */
380  __HAL_LOCK(hrtc);
381 
382  hrtc->State = HAL_RTC_STATE_BUSY;
383 
384  /* Disable the write protection for RTC registers */
386 
387  /* Configure the internal Time Stamp Enable bits */
388  __HAL_RTC_INTERNAL_TIMESTAMP_DISABLE(hrtc);
389 
390  /* Enable the write protection for RTC registers */
392 
393  hrtc->State = HAL_RTC_STATE_READY;
394 
395  /* Process Unlocked */
396  __HAL_UNLOCK(hrtc);
397 
398  return HAL_OK;
399 }
__IO HAL_RTCStateTypeDef State
__HAL_RTC_WRITEPROTECTION_DISABLE(hrtc)
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
__HAL_RTC_WRITEPROTECTION_ENABLE(hrtc)

◆ HAL_RTCEx_DeactivateTimeStamp()

HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp ( RTC_HandleTypeDef hrtc)

Deactivate TimeStamp.

Parameters
hrtcRTC handle
Return values
HALstatus

Definition at line 309 of file stm32l4xx_hal_rtc_ex.c.

310 {
311  uint32_t tmpreg;
312 
313  /* Process Locked */
314  __HAL_LOCK(hrtc);
315 
316  hrtc->State = HAL_RTC_STATE_BUSY;
317 
318  /* Disable the write protection for RTC registers */
320 
321  /* In case of interrupt mode is used, the interrupt source must disabled */
322  __HAL_RTC_TIMESTAMP_DISABLE_IT(hrtc, RTC_IT_TS);
323 
324  /* Get the RTC_CR register and clear the bits to be configured */
325  tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
326 
327  /* Configure the Time Stamp TSEDGE and Enable bits */
328  hrtc->Instance->CR = (uint32_t)tmpreg;
329 
330  /* Enable the write protection for RTC registers */
332 
333  hrtc->State = HAL_RTC_STATE_READY;
334 
335  /* Process Unlocked */
336  __HAL_UNLOCK(hrtc);
337 
338  return HAL_OK;
339 }
__IO HAL_RTCStateTypeDef State
__HAL_RTC_WRITEPROTECTION_DISABLE(hrtc)
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
__HAL_RTC_WRITEPROTECTION_ENABLE(hrtc)

◆ HAL_RTCEx_GetTimeStamp()

HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp ( RTC_HandleTypeDef hrtc,
RTC_TimeTypeDef sTimeStamp,
RTC_DateTypeDef sTimeStampDate,
uint32_t  Format 
)

Get the RTC TimeStamp value.

Parameters
hrtcRTC handle
sTimeStampPointer to Time structure
sTimeStampDatePointer to Date structure
Formatspecifies the format of the entered parameters. This parameter can be one of the following values:
  • RTC_FORMAT_BIN: Binary data format
  • RTC_FORMAT_BCD: BCD data format
Return values
HALstatus

Definition at line 412 of file stm32l4xx_hal_rtc_ex.c.

413 {
414  uint32_t tmptime, tmpdate;
415 
416  /* Check the parameters */
417  assert_param(IS_RTC_FORMAT(Format));
418 
419  /* Get the TimeStamp time and date registers values */
420  tmptime = (uint32_t)(hrtc->Instance->TSTR & RTC_TR_RESERVED_MASK);
421  tmpdate = (uint32_t)(hrtc->Instance->TSDR & RTC_DR_RESERVED_MASK);
422 
423  /* Fill the Time structure fields with the read parameters */
424  sTimeStamp->Hours = (uint8_t)((tmptime & (RTC_TSTR_HT | RTC_TSTR_HU)) >> RTC_TSTR_HU_Pos);
425  sTimeStamp->Minutes = (uint8_t)((tmptime & (RTC_TSTR_MNT | RTC_TSTR_MNU)) >> RTC_TSTR_MNU_Pos);
426  sTimeStamp->Seconds = (uint8_t)((tmptime & (RTC_TSTR_ST | RTC_TSTR_SU)) >> RTC_TSTR_SU_Pos);
427  sTimeStamp->TimeFormat = (uint8_t)((tmptime & (RTC_TSTR_PM)) >> RTC_TSTR_PM_Pos);
428  sTimeStamp->SubSeconds = (uint32_t) hrtc->Instance->TSSSR;
429 
430  /* Fill the Date structure fields with the read parameters */
431  sTimeStampDate->Year = 0U;
432  sTimeStampDate->Month = (uint8_t)((tmpdate & (RTC_TSDR_MT | RTC_TSDR_MU)) >> RTC_TSDR_MU_Pos);
433  sTimeStampDate->Date = (uint8_t)((tmpdate & (RTC_TSDR_DT | RTC_TSDR_DU)) >> RTC_TSDR_DU_Pos);
434  sTimeStampDate->WeekDay = (uint8_t)((tmpdate & (RTC_TSDR_WDU)) >> RTC_TSDR_WDU_Pos);
435 
436  /* Check the input parameters format */
437  if (Format == RTC_FORMAT_BIN)
438  {
439  /* Convert the TimeStamp structure parameters to Binary format */
440  sTimeStamp->Hours = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Hours);
441  sTimeStamp->Minutes = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Minutes);
442  sTimeStamp->Seconds = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Seconds);
443 
444  /* Convert the DateTimeStamp structure parameters to Binary format */
445  sTimeStampDate->Month = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Month);
446  sTimeStampDate->Date = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Date);
447  sTimeStampDate->WeekDay = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->WeekDay);
448  }
449 
450  /* Clear the TIMESTAMP Flags */
451  __HAL_RTC_INTERNAL_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_ITSF);
452  __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF);
453 
454  return HAL_OK;
455 }
return HAL_OK
uint8_t RTC_Bcd2ToByte(uint8_t Value)
Convert from 2 digit BCD to Binary.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_RTCEx_PollForTimeStampEvent()

HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent ( RTC_HandleTypeDef hrtc,
uint32_t  Timeout 
)

Handle TimeStamp polling request.

Parameters
hrtcRTC handle
TimeoutTimeout duration
Return values
HALstatus

Definition at line 641 of file stm32l4xx_hal_rtc_ex.c.

642 {
643  uint32_t tickstart = HAL_GetTick();
644 
645  while (__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) == 0U)
646  {
647  if (__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSOVF) != 0U)
648  {
649  /* Clear the TIMESTAMP OverRun Flag */
650  __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSOVF);
651 
652  /* Change TIMESTAMP state */
653  hrtc->State = HAL_RTC_STATE_ERROR;
654 
655  return HAL_ERROR;
656  }
657 
658  if (Timeout != HAL_MAX_DELAY)
659  {
660  if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
661  {
663  return HAL_TIMEOUT;
664  }
665  }
666  }
667 
668  /* Change RTC state */
669  hrtc->State = HAL_RTC_STATE_READY;
670 
671  return HAL_OK;
672 }
__IO HAL_RTCStateTypeDef State
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
return HAL_OK

◆ HAL_RTCEx_SetInternalTimeStamp()

HAL_StatusTypeDef HAL_RTCEx_SetInternalTimeStamp ( RTC_HandleTypeDef hrtc)

Set Internal TimeStamp.

Note
This API must be called before enabling the internal TimeStamp feature.
Parameters
hrtcRTC handle
Return values
HALstatus

Definition at line 347 of file stm32l4xx_hal_rtc_ex.c.

348 {
349  /* Process Locked */
350  __HAL_LOCK(hrtc);
351 
352  hrtc->State = HAL_RTC_STATE_BUSY;
353 
354  /* Disable the write protection for RTC registers */
356 
357  /* Configure the internal Time Stamp Enable bits */
358  __HAL_RTC_INTERNAL_TIMESTAMP_ENABLE(hrtc);
359 
360  /* Enable the write protection for RTC registers */
362 
363  /* Change RTC state */
364  hrtc->State = HAL_RTC_STATE_READY;
365 
366  /* Process Unlocked */
367  __HAL_UNLOCK(hrtc);
368 
369  return HAL_OK;
370 }
__IO HAL_RTCStateTypeDef State
__HAL_RTC_WRITEPROTECTION_DISABLE(hrtc)
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
__HAL_RTC_WRITEPROTECTION_ENABLE(hrtc)

◆ HAL_RTCEx_SetTimeStamp()

HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp ( RTC_HandleTypeDef hrtc,
uint32_t  TimeStampEdge,
uint32_t  RTC_TimeStampPin 
)

Set TimeStamp.

Note
This API must be called before enabling the TimeStamp feature.
Parameters
hrtcRTC handle
TimeStampEdgeSpecifies the pin edge on which the TimeStamp is activated. This parameter can be one of the following values:
  • RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the rising edge of the related pin.
  • RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the falling edge of the related pin.
RTC_TimeStampPinspecifies the RTC TimeStamp Pin. This parameter can be one of the following values:
  • RTC_TIMESTAMPPIN_DEFAULT: PC13 is selected as RTC TimeStamp Pin. The RTC TimeStamp Pin is per default PC13, but for reasons of compatibility, this parameter is required.
Return values
HALstatus

Definition at line 198 of file stm32l4xx_hal_rtc_ex.c.

199 {
200  uint32_t tmpreg;
201 
202  /* Check the parameters */
203  assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge));
204  assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin));
205 
206  /* Prevent unused argument(s) compilation warning if no assert_param check */
207  UNUSED(RTC_TimeStampPin);
208 
209  /* Process Locked */
210  __HAL_LOCK(hrtc);
211 
212  hrtc->State = HAL_RTC_STATE_BUSY;
213 
214  /* Get the RTC_CR register and clear the bits to be configured */
215  tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
216 
217  tmpreg |= TimeStampEdge;
218 
219  /* Disable the write protection for RTC registers */
221 
222  /* Configure the Time Stamp TSEDGE and Enable bits */
223  hrtc->Instance->CR = (uint32_t)tmpreg;
224 
225  __HAL_RTC_TIMESTAMP_ENABLE(hrtc);
226 
227  /* Enable the write protection for RTC registers */
229 
230  /* Change RTC state */
231  hrtc->State = HAL_RTC_STATE_READY;
232 
233  /* Process Unlocked */
234  __HAL_UNLOCK(hrtc);
235 
236  return HAL_OK;
237 }
__IO HAL_RTCStateTypeDef State
__HAL_RTC_WRITEPROTECTION_DISABLE(hrtc)
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
__HAL_RTC_WRITEPROTECTION_ENABLE(hrtc)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_RTCEx_SetTimeStamp_IT()

HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT ( RTC_HandleTypeDef hrtc,
uint32_t  TimeStampEdge,
uint32_t  RTC_TimeStampPin 
)

Set TimeStamp with Interrupt.

Note
This API must be called before enabling the TimeStamp feature.
Parameters
hrtcRTC handle
TimeStampEdgeSpecifies the pin edge on which the TimeStamp is activated. This parameter can be one of the following values:
  • RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the rising edge of the related pin.
  • RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the falling edge of the related pin.
RTC_TimeStampPinSpecifies the RTC TimeStamp Pin. This parameter can be one of the following values:
  • RTC_TIMESTAMPPIN_DEFAULT: PC13 is selected as RTC TimeStamp Pin. The RTC TimeStamp Pin is per default PC13, but for reasons of compatibility, this parameter is required.
Return values
HALstatus

Definition at line 257 of file stm32l4xx_hal_rtc_ex.c.

258 {
259  uint32_t tmpreg;
260 
261  /* Check the parameters */
262  assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge));
263  assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin));
264 
265  /* Prevent unused argument(s) compilation warning if no assert_param check */
266  UNUSED(RTC_TimeStampPin);
267 
268  /* Process Locked */
269  __HAL_LOCK(hrtc);
270 
271  hrtc->State = HAL_RTC_STATE_BUSY;
272 
273  /* Get the RTC_CR register and clear the bits to be configured */
274  tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
275 
276  tmpreg |= TimeStampEdge;
277 
278  /* Disable the write protection for RTC registers */
280 
281  /* Configure the Time Stamp TSEDGE and Enable bits */
282  hrtc->Instance->CR = (uint32_t)tmpreg;
283 
284  __HAL_RTC_TIMESTAMP_ENABLE(hrtc);
285 
286  /* Enable IT timestamp */
287  __HAL_RTC_TIMESTAMP_ENABLE_IT(hrtc, RTC_IT_TS);
288 
289  /* RTC timestamp Interrupt Configuration: EXTI configuration */
290  __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT();
291  __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE();
292 
293  /* Enable the write protection for RTC registers */
295 
296  hrtc->State = HAL_RTC_STATE_READY;
297 
298  /* Process Unlocked */
299  __HAL_UNLOCK(hrtc);
300 
301  return HAL_OK;
302 }
__IO HAL_RTCStateTypeDef State
__HAL_RTC_WRITEPROTECTION_DISABLE(hrtc)
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
__HAL_RTC_WRITEPROTECTION_ENABLE(hrtc)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_RTCEx_TamperTimeStampIRQHandler()

void HAL_RTCEx_TamperTimeStampIRQHandler ( RTC_HandleTypeDef hrtc)

Handle TimeStamp interrupt request.

Parameters
hrtcRTC handle
Return values
None

Definition at line 464 of file stm32l4xx_hal_rtc_ex.c.

465 {
466 
467  /* Process TAMP instance pointer */
468  TAMP_TypeDef *tamp = (TAMP_TypeDef *)((uint32_t)hrtc->Instance + hrtc->TampOffset);
469 
470  /* Clear the EXTI's Flag for RTC TimeStamp and Tamper */
471  __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG();
472 
473  if ((hrtc->Instance->MISR & RTC_MISR_TSMF) != 0u)
474  {
475 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
476  /* Call TimeStampEvent registered Callback */
477  hrtc->TimeStampEventCallback(hrtc);
478 #else
480 #endif
481  /* Not immediatly clear flags because the content of RTC_TSTR and RTC_TSDR arecleared when TSF bit is reset.*/
482  hrtc->Instance->SCR = RTC_SCR_CTSF;
483  }
484 
485  /* Get interrupt status */
486  uint32_t tmp = tamp->MISR;
487 
488  /* Immediatly clear flags */
489  tamp->SCR = tmp;
490 
491 #if defined(RTC_TAMPER1_SUPPORT)
492  /* Check Tamper1 status */
493  if ((tmp & RTC_TAMPER_1) == RTC_TAMPER_1)
494  {
495 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
496  /* Call Tamper 1 Event registered Callback */
497  hrtc->Tamper1EventCallback(hrtc);
498 #else
499  /* Tamper1 callback */
501 #endif
502  }
503 #endif /* RTC_TAMPER1_SUPPORT */
504 
505  /* Check Tamper2 status */
506  if ((tmp & RTC_TAMPER_2) == RTC_TAMPER_2)
507  {
508 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
509  /* Call Tamper 2 Event registered Callback */
510  hrtc->Tamper2EventCallback(hrtc);
511 #else
512  /* Tamper2 callback */
514 #endif
515  }
516 
517 #if defined(RTC_TAMPER3_SUPPORT)
518  /* Check Tamper3 status */
519  if ((tmp & RTC_TAMPER_3) == RTC_TAMPER_3)
520  {
521 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
522  /* Call Tamper 3 Event registered Callback */
523  hrtc->Tamper3EventCallback(hrtc);
524 #else
525  /* Tamper3 callback */
527 #endif
528  }
529 
530 #endif /* RTC_TAMPER3_SUPPORT */
531 
532  /* Change RTC state */
533  hrtc->State = HAL_RTC_STATE_READY;
534 }
void(* Tamper3EventCallback)(struct __RTC_HandleTypeDef *hrtc)
__IO HAL_RTCStateTypeDef State
void(* Tamper2EventCallback)(struct __RTC_HandleTypeDef *hrtc)
void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc)
void HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef *hrtc)
void(* TimeStampEventCallback)(struct __RTC_HandleTypeDef *hrtc)
void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc)
TimeStamp callback.
void(* Tamper1EventCallback)(struct __RTC_HandleTypeDef *hrtc)
void HAL_RTCEx_Tamper3EventCallback(RTC_HandleTypeDef *hrtc)

◆ HAL_RTCEx_TimeStampEventCallback()

__weak void HAL_RTCEx_TimeStampEventCallback ( RTC_HandleTypeDef hrtc)

TimeStamp callback.

Parameters
hrtcRTC handle
Return values
None

Definition at line 625 of file stm32l4xx_hal_rtc_ex.c.

626 {
627  /* Prevent unused argument(s) compilation warning */
628  UNUSED(hrtc);
629 
630  /* NOTE : This function should not be modified, when the callback is needed,
631  the HAL_RTCEx_TimeStampEventCallback could be implemented in the user file
632  */
633 }