STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_hal_rtc_ex.c
Go to the documentation of this file.
1 
111 /* Includes ------------------------------------------------------------------*/
112 #include "stm32l4xx_hal.h"
113 
123 #ifdef HAL_RTC_MODULE_ENABLED
124 
125 /* Private typedef -----------------------------------------------------------*/
126 /* Private define ------------------------------------------------------------*/
127 #if defined(STM32L412xx) || defined(STM32L422xx)
128 #else
129 #if defined(RTC_TAMPER1_SUPPORT) && defined(RTC_TAMPER3_SUPPORT)
130 #define RTC_TAMPCR_MASK ((uint32_t)RTC_TAMPCR_TAMPTS |\
131  (uint32_t)RTC_TAMPCR_TAMPFREQ | (uint32_t)RTC_TAMPCR_TAMPFLT | (uint32_t)RTC_TAMPCR_TAMPPRCH |\
132  (uint32_t)RTC_TAMPCR_TAMPPUDIS | (uint32_t)RTC_TAMPCR_TAMPIE |\
133  (uint32_t)RTC_TAMPCR_TAMP1IE | (uint32_t)RTC_TAMPCR_TAMP1NOERASE | (uint32_t)RTC_TAMPCR_TAMP1MF |\
134  (uint32_t)RTC_TAMPCR_TAMP2IE | (uint32_t)RTC_TAMPCR_TAMP2NOERASE | (uint32_t)RTC_TAMPCR_TAMP2MF |\
135  (uint32_t)RTC_TAMPCR_TAMP3IE | (uint32_t)RTC_TAMPCR_TAMP3NOERASE | (uint32_t)RTC_TAMPCR_TAMP3MF)
136 #elif defined(RTC_TAMPER1_SUPPORT)
137 #define RTC_TAMPCR_MASK ((uint32_t)RTC_TAMPCR_TAMPTS |\
138  (uint32_t)RTC_TAMPCR_TAMPFREQ | (uint32_t)RTC_TAMPCR_TAMPFLT | (uint32_t)RTC_TAMPCR_TAMPPRCH |\
139  (uint32_t)RTC_TAMPCR_TAMPPUDIS | (uint32_t)RTC_TAMPCR_TAMPIE |\
140  (uint32_t)RTC_TAMPCR_TAMP1IE | (uint32_t)RTC_TAMPCR_TAMP1NOERASE | (uint32_t)RTC_TAMPCR_TAMP1MF |\
141  (uint32_t)RTC_TAMPCR_TAMP2IE | (uint32_t)RTC_TAMPCR_TAMP2NOERASE | (uint32_t)RTC_TAMPCR_TAMP2MF)
142 #elif defined(RTC_TAMPER3_SUPPORT)
143 #define RTC_TAMPCR_MASK ((uint32_t)RTC_TAMPCR_TAMPTS |\
144  (uint32_t)RTC_TAMPCR_TAMPFREQ | (uint32_t)RTC_TAMPCR_TAMPFLT | (uint32_t)RTC_TAMPCR_TAMPPRCH |\
145  (uint32_t)RTC_TAMPCR_TAMPPUDIS | (uint32_t)RTC_TAMPCR_TAMPIE |\
146  (uint32_t)RTC_TAMPCR_TAMP2IE | (uint32_t)RTC_TAMPCR_TAMP2NOERASE | (uint32_t)RTC_TAMPCR_TAMP2MF |\
147  (uint32_t)RTC_TAMPCR_TAMP3IE | (uint32_t)RTC_TAMPCR_TAMP3NOERASE | (uint32_t)RTC_TAMPCR_TAMP3MF)
148 #else
149 #define RTC_TAMPCR_MASK ((uint32_t)RTC_TAMPCR_TAMPTS |\
150  (uint32_t)RTC_TAMPCR_TAMPFREQ | (uint32_t)RTC_TAMPCR_TAMPFLT | (uint32_t)RTC_TAMPCR_TAMPPRCH |\
151  (uint32_t)RTC_TAMPCR_TAMPPUDIS | (uint32_t)RTC_TAMPCR_TAMPIE |\
152  (uint32_t)RTC_TAMPCR_TAMP2IE | (uint32_t)RTC_TAMPCR_TAMP2NOERASE | (uint32_t)RTC_TAMPCR_TAMP2MF)
153 #endif /* RTC_TAMPER1_SUPPORT && RTC_TAMPER3_SUPPORT */
154 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) */
155 
156 /* Private macro -------------------------------------------------------------*/
157 /* Private variables ---------------------------------------------------------*/
158 /* Private function prototypes -----------------------------------------------*/
159 /* Exported functions --------------------------------------------------------*/
160 
198 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
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 }
238 
257 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
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 }
303 
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 }
340 
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 }
371 
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 }
400 
412 HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTimeStamp, RTC_DateTypeDef *sTimeStampDate, uint32_t Format)
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 }
456 
462 #if defined(STM32L412xx) || defined(STM32L422xx)
463 
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 }
535 
536 #else /* #if defined(STM32L412xx) || defined(STM32L422xx) */
537 
539 {
540  /* Clear the EXTI's Flag for RTC TimeStamp and Tamper */
541  __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG();
542 
543  /* Get the TimeStamp interrupt source enable status and pending flag status */
544  if (__HAL_RTC_TIMESTAMP_GET_IT_SOURCE(hrtc, RTC_IT_TS) != 0U)
545  {
546  if (__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) != 0U)
547  {
548  /* TIMESTAMP callback */
549 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
550  hrtc->TimeStampEventCallback(hrtc);
551 #else /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
553 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
554 
555  /* Clear the TIMESTAMP interrupt pending bit (this will clear timestamp time and date registers) */
556  __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF);
557  }
558  }
559 
560 #if defined(RTC_TAMPER1_SUPPORT)
561  /* Get the Tamper1 interrupt source enable status and pending flag status */
562  if (__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP1) != 0U)
563  {
564  if (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F) != 0U)
565  {
566  /* Clear the Tamper1 interrupt pending bit */
567  __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP1F);
568 
569  /* Tamper1 callback */
570 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
571  hrtc->Tamper1EventCallback(hrtc);
572 #else /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
574 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
575  }
576  }
577 #endif /* RTC_TAMPER1_SUPPORT */
578 
579  /* Get the Tamper2 interrupt source enable status and pending flag status */
580  if (__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP2) != 0U)
581  {
582  if (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP2F) != 0U)
583  {
584  /* Clear the Tamper2 interrupt pending bit */
585  __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP2F);
586 
587  /* Tamper2 callback */
588 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
589  hrtc->Tamper2EventCallback(hrtc);
590 #else /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
592 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
593  }
594  }
595 
596 #if defined(RTC_TAMPER3_SUPPORT)
597  /* Get the Tamper3 interrupts source enable status */
598  if (__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP3) != 0U)
599  {
600  if (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP3F) != 0U)
601  {
602  /* Clear the Tamper3 interrupt pending bit */
603  __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP3F);
604 
605  /* Tamper3 callback */
606 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
607  hrtc->Tamper3EventCallback(hrtc);
608 #else
610 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
611  }
612  }
613 #endif /* RTC_TAMPER3_SUPPORT */
614 
615  /* Change RTC state */
616  hrtc->State = HAL_RTC_STATE_READY;
617 }
618 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) */
619 
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 }
634 
641 HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
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 }
673 
699 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
700 {
701  uint32_t tickstart;
702 
703  /* Check the parameters */
704  assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock));
705  assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter));
706 
707  /* Process Locked */
708  __HAL_LOCK(hrtc);
709 
710  hrtc->State = HAL_RTC_STATE_BUSY;
711 
712  /* Disable the write protection for RTC registers */
714 
715  /* Clear WUTE in RTC_CR to disable the wakeup timer */
716  CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE);
717 
718  /* Poll WUTWF until it is set in RTC_ICSR to make sure the access to wakeup autoreload
719  counter and to WUCKSEL[2:0] bits is allowed. This step must be skipped in
720  calendar initialization mode. */
721 #if defined(STM32L412xx) || defined(STM32L422xx)
722  if (READ_BIT(hrtc->Instance->ICSR, RTC_ICSR_INITF) == 0U)
723 #else
724  if (READ_BIT(hrtc->Instance->ISR, RTC_ISR_INITF) == 0U)
725 #endif
726  {
727  tickstart = HAL_GetTick();
728 #if defined(STM32L412xx) || defined(STM32L422xx)
729  while (READ_BIT(hrtc->Instance->ICSR, RTC_ICSR_WUTWF) == 0U)
730 #else
731  while (READ_BIT(hrtc->Instance->ISR, RTC_ISR_WUTWF) == 0U)
732 #endif
733  {
734  if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
735  {
736  /* Enable the write protection for RTC registers */
738 
740 
741  /* Process Unlocked */
742  __HAL_UNLOCK(hrtc);
743 
744  return HAL_TIMEOUT;
745  }
746  }
747  }
748 
749  /* Configure the clock source */
750  MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL, (uint32_t)WakeUpClock);
751 
752  /* Configure the Wakeup Timer counter */
753  WRITE_REG(hrtc->Instance->WUTR, (uint32_t)WakeUpCounter);
754 
755  /* Enable the Wakeup Timer */
756  SET_BIT(hrtc->Instance->CR, RTC_CR_WUTE);
757 
758  /* Enable the write protection for RTC registers */
760 
761  hrtc->State = HAL_RTC_STATE_READY;
762 
763  /* Process Unlocked */
764  __HAL_UNLOCK(hrtc);
765 
766  return HAL_OK;
767 }
768 
781 #if defined(STM32L412xx) || defined(STM32L422xx)
782 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock, uint32_t WakeUpAutoClr)
783 #else
784 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
785 #endif
786 {
787  uint32_t tickstart;
788 
789  /* Check the parameters */
790  assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock));
791  assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter));
792 #if defined(STM32L412xx) || defined(STM32L422xx)
793  /* (0x0000<=WUTOCLR<=WUT) */
794  assert_param(WakeUpAutoClr <= WakeUpCounter);
795 #endif
796 
797  /* Process Locked */
798  __HAL_LOCK(hrtc);
799 
801 
802  /* Disable the write protection for RTC registers */
804 
805  /* Clear WUTE in RTC_CR to disable the wakeup timer */
806  CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE);
807 
808  /* Clear flag Wake-Up */
809  __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
810 
811  /* Poll WUTWF until it is set in RTC_ICSR to make sure the access to wakeup autoreload
812  counter and to WUCKSEL[2:0] bits is allowed. This step must be skipped in
813  calendar initialization mode. */
814 #if defined(STM32L412xx) || defined(STM32L422xx)
815  if (READ_BIT(hrtc->Instance->ICSR, RTC_ICSR_INITF) == 0U)
816 #else
817  if (READ_BIT(hrtc->Instance->ISR, RTC_ISR_INITF) == 0U)
818 #endif
819  {
820  tickstart = HAL_GetTick();
821 #if defined(STM32L412xx) || defined(STM32L422xx)
822  while (READ_BIT(hrtc->Instance->ICSR, RTC_ICSR_WUTWF) == 0U)
823 #else
824  while (READ_BIT(hrtc->Instance->ISR, RTC_ISR_WUTWF) == 0U)
825 #endif
826  {
827  if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
828  {
829  /* Enable the write protection for RTC registers */
831 
833 
834  /* Process Unlocked */
835  __HAL_UNLOCK(hrtc);
836 
837  return HAL_TIMEOUT;
838  }
839  }
840  }
841 
842 #if defined(STM32L412xx) || defined(STM32L422xx)
843  /* Configure the Wakeup Timer counter and auto clear value */
844  hrtc->Instance->WUTR = (uint32_t)(WakeUpCounter | (WakeUpAutoClr << RTC_WUTR_WUTOCLR_Pos));
845 #else
846  /* Configure the Wakeup Timer counter */
847  hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
848 #endif
849 
850  /* Configure the clock source */
851  MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL, (uint32_t)WakeUpClock);
852 
853 #if defined(STM32L412xx) || defined(STM32L422xx)
854  /* In case of WUT autoclr, the IRQ handler should not be called */
855  if (WakeUpAutoClr != 0u)
856  {
857  /* RTC WakeUpTimer EXTI Configuration: Event configuration */
858  __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_EVENT();
859  }
860  else
861  {
862  /* RTC WakeUpTimer EXTI Configuration: Interrupt configuration */
864  }
865 #else /* defined(STM32L412xx) || defined(STM32L422xx) */
867 #endif /* defined(STM32L412xx) || defined(STM32L422xx) */
868 
870 
871  /* Configure the Interrupt in the RTC_CR register */
872  __HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc, RTC_IT_WUT);
873 
874  /* Enable the Wakeup Timer */
876 
877  /* Enable the write protection for RTC registers */
879 
880  hrtc->State = HAL_RTC_STATE_READY;
881 
882  /* Process Unlocked */
883  __HAL_UNLOCK(hrtc);
884 
885  return HAL_OK;
886 }
887 
894 {
895  uint32_t tickstart;
896 
897  /* Process Locked */
898  __HAL_LOCK(hrtc);
899 
900  hrtc->State = HAL_RTC_STATE_BUSY;
901 
902  /* Disable the write protection for RTC registers */
904 
905  /* Disable the Wakeup Timer */
906  __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
907 
908  /* In case of interrupt mode is used, the interrupt source must disabled */
909  __HAL_RTC_WAKEUPTIMER_DISABLE_IT(hrtc, RTC_IT_WUT);
910 
911  tickstart = HAL_GetTick();
912  /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
913  while (__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == 0U)
914  {
915  if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
916  {
917  /* Enable the write protection for RTC registers */
919 
921 
922  /* Process Unlocked */
923  __HAL_UNLOCK(hrtc);
924 
925  return HAL_TIMEOUT;
926  }
927  }
928 
929  /* Enable the write protection for RTC registers */
931 
932  hrtc->State = HAL_RTC_STATE_READY;
933 
934  /* Process Unlocked */
935  __HAL_UNLOCK(hrtc);
936 
937  return HAL_OK;
938 }
939 
946 {
947  /* Get the counter value */
948  return ((uint32_t)(hrtc->Instance->WUTR & RTC_WUTR_WUT));
949 }
950 
957 {
958  /* Clear the EXTI's line Flag for RTC WakeUpTimer */
959  __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG();
960 
961 
962 #if defined(STM32L412xx) || defined(STM32L422xx)
963  if ((hrtc->Instance->MISR & RTC_MISR_WUTMF) != 0u)
964  {
965  /* Immediately clear flags */
966  hrtc->Instance->SCR = RTC_SCR_CWUTF;
967 #else
968  /* Get the pending status of the WAKEUPTIMER Interrupt */
969  if (__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) != 0U)
970  {
971  /* Clear the WAKEUPTIMER interrupt pending bit */
972  __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
973 #endif
974 
975  /* WAKEUPTIMER callback */
976 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
977  /* Call WakeUpTimerEvent registered Callback */
978  hrtc->WakeUpTimerEventCallback(hrtc);
979 #else
981 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
982  }
983 
984  /* Change RTC state */
985  hrtc->State = HAL_RTC_STATE_READY;
986 }
987 
994 {
995  /* Prevent unused argument(s) compilation warning */
996  UNUSED(hrtc);
997 
998  /* NOTE : This function should not be modified, when the callback is needed,
999  the HAL_RTCEx_WakeUpTimerEventCallback could be implemented in the user file
1000  */
1001 }
1002 
1003 
1010 HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
1011 {
1012  uint32_t tickstart = HAL_GetTick();
1013 
1014  while (__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) == 0U)
1015  {
1016  if (Timeout != HAL_MAX_DELAY)
1017  {
1018  if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
1019  {
1020  hrtc->State = HAL_RTC_STATE_TIMEOUT;
1021  return HAL_TIMEOUT;
1022  }
1023  }
1024  }
1025 
1026  /* Clear the WAKEUPTIMER Flag */
1027  __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
1028 
1029  /* Change RTC state */
1030  hrtc->State = HAL_RTC_STATE_READY;
1031 
1032  return HAL_OK;
1033 }
1034 
1087 HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef *hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmoothCalibMinusPulsesValue)
1088 {
1089  uint32_t tickstart;
1090 
1091  /* Check the parameters */
1092  assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(SmoothCalibPeriod));
1093  assert_param(IS_RTC_SMOOTH_CALIB_PLUS(SmoothCalibPlusPulses));
1094  assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmoothCalibMinusPulsesValue));
1095 
1096  /* Process Locked */
1097  __HAL_LOCK(hrtc);
1098 
1099  hrtc->State = HAL_RTC_STATE_BUSY;
1100 
1101  /* Disable the write protection for RTC registers */
1103 
1104  /* check if a calibration is pending*/
1105 #if defined(STM32L412xx) || defined(STM32L422xx)
1106  if ((hrtc->Instance->ICSR & RTC_ICSR_RECALPF) != 0U)
1107 #else
1108  if ((hrtc->Instance->ISR & RTC_ISR_RECALPF) != 0U)
1109 #endif
1110  {
1111  tickstart = HAL_GetTick();
1112 
1113  /* check if a calibration is pending*/
1114 #if defined(STM32L412xx) || defined(STM32L422xx)
1115  while ((hrtc->Instance->ICSR & RTC_ICSR_RECALPF) != 0U)
1116 #else
1117  while ((hrtc->Instance->ISR & RTC_ISR_RECALPF) != 0U)
1118 #endif
1119  {
1120  if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
1121  {
1122  /* Enable the write protection for RTC registers */
1124 
1125  /* Change RTC state */
1126  hrtc->State = HAL_RTC_STATE_TIMEOUT;
1127 
1128  /* Process Unlocked */
1129  __HAL_UNLOCK(hrtc);
1130 
1131  return HAL_TIMEOUT;
1132  }
1133  }
1134  }
1135 
1136  /* Configure the Smooth calibration settings */
1137  MODIFY_REG(hrtc->Instance->CALR, (RTC_CALR_CALP | RTC_CALR_CALW8 | RTC_CALR_CALW16 | RTC_CALR_CALM), (uint32_t)(SmoothCalibPeriod | SmoothCalibPlusPulses | SmoothCalibMinusPulsesValue));
1138 
1139  /* Enable the write protection for RTC registers */
1141 
1142  /* Change RTC state */
1143  hrtc->State = HAL_RTC_STATE_READY;
1144 
1145  /* Process Unlocked */
1146  __HAL_UNLOCK(hrtc);
1147 
1148  return HAL_OK;
1149 }
1150 
1151 #if defined(STM32L412xx) || defined(STM32L422xx)
1152 
1161 HAL_StatusTypeDef HAL_RTCEx_SetLowPowerCalib(RTC_HandleTypeDef *hrtc, uint32_t LowPowerCalib)
1162 {
1163  /* Check the parameters */
1164  assert_param(IS_RTC_LOW_POWER_CALIB(LowPowerCalib));
1165 
1166  /* Process Locked */
1167  __HAL_LOCK(hrtc);
1168 
1169  hrtc->State = HAL_RTC_STATE_BUSY;
1170 
1171  /* Disable the write protection for RTC registers */
1173 
1174  /* Configure the Smooth calibration settings */
1175  MODIFY_REG(hrtc->Instance->CALR, RTC_CALR_LPCAL, LowPowerCalib);
1176 
1177  /* Enable the write protection for RTC registers */
1179 
1180  /* Change RTC state */
1181  hrtc->State = HAL_RTC_STATE_READY;
1182 
1183  /* Process Unlocked */
1184  __HAL_UNLOCK(hrtc);
1185 
1186  return HAL_OK;
1187 }
1188 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) */
1189 
1202 HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef *hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS)
1203 {
1204  uint32_t tickstart;
1205 
1206  /* Check the parameters */
1207  assert_param(IS_RTC_SHIFT_ADD1S(ShiftAdd1S));
1208  assert_param(IS_RTC_SHIFT_SUBFS(ShiftSubFS));
1209 
1210  /* Process Locked */
1211  __HAL_LOCK(hrtc);
1212 
1213  hrtc->State = HAL_RTC_STATE_BUSY;
1214 
1215  /* Disable the write protection for RTC registers */
1217 
1218  tickstart = HAL_GetTick();
1219 
1220  /* Wait until the shift is completed*/
1221 #if defined(STM32L412xx) || defined(STM32L422xx)
1222  while ((hrtc->Instance->ICSR & RTC_ICSR_SHPF) != 0U)
1223 #else
1224  while ((hrtc->Instance->ISR & RTC_ISR_SHPF) != 0U)
1225 #endif
1226  {
1227  if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
1228  {
1229  /* Enable the write protection for RTC registers */
1231 
1232  hrtc->State = HAL_RTC_STATE_TIMEOUT;
1233 
1234  /* Process Unlocked */
1235  __HAL_UNLOCK(hrtc);
1236 
1237  return HAL_TIMEOUT;
1238  }
1239  }
1240 
1241  /* Check if the reference clock detection is disabled */
1242  if ((hrtc->Instance->CR & RTC_CR_REFCKON) == 0U)
1243  {
1244  /* Configure the Shift settings */
1245  hrtc->Instance->SHIFTR = (uint32_t)(uint32_t)(ShiftSubFS) | (uint32_t)(ShiftAdd1S);
1246 
1247  /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
1248  if ((hrtc->Instance->CR & RTC_CR_BYPSHAD) == 0U)
1249  {
1250  if (HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
1251  {
1252  /* Enable the write protection for RTC registers */
1254 
1255  hrtc->State = HAL_RTC_STATE_ERROR;
1256 
1257  /* Process Unlocked */
1258  __HAL_UNLOCK(hrtc);
1259 
1260  return HAL_ERROR;
1261  }
1262  }
1263  }
1264  else
1265  {
1266  /* Enable the write protection for RTC registers */
1268 
1269  /* Change RTC state */
1270  hrtc->State = HAL_RTC_STATE_ERROR;
1271 
1272  /* Process Unlocked */
1273  __HAL_UNLOCK(hrtc);
1274 
1275  return HAL_ERROR;
1276  }
1277 
1278  /* Enable the write protection for RTC registers */
1280 
1281  /* Change RTC state */
1282  hrtc->State = HAL_RTC_STATE_READY;
1283 
1284  /* Process Unlocked */
1285  __HAL_UNLOCK(hrtc);
1286 
1287  return HAL_OK;
1288 }
1289 
1299 HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef *hrtc, uint32_t CalibOutput)
1300 {
1301  /* Check the parameters */
1302  assert_param(IS_RTC_CALIB_OUTPUT(CalibOutput));
1303 
1304  /* Process Locked */
1305  __HAL_LOCK(hrtc);
1306 
1307  hrtc->State = HAL_RTC_STATE_BUSY;
1308 
1309  /* Disable the write protection for RTC registers */
1311 
1312  /* Clear flags before config */
1313  hrtc->Instance->CR &= (uint32_t)~RTC_CR_COSEL;
1314 
1315  /* Configure the RTC_CR register */
1316  hrtc->Instance->CR |= (uint32_t)CalibOutput;
1317 
1318  __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(hrtc);
1319 
1320  /* Enable the write protection for RTC registers */
1322 
1323  /* Change RTC state */
1324  hrtc->State = HAL_RTC_STATE_READY;
1325 
1326  /* Process Unlocked */
1327  __HAL_UNLOCK(hrtc);
1328 
1329  return HAL_OK;
1330 }
1331 
1338 {
1339  /* Process Locked */
1340  __HAL_LOCK(hrtc);
1341 
1342  hrtc->State = HAL_RTC_STATE_BUSY;
1343 
1344  /* Disable the write protection for RTC registers */
1346 
1347  __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(hrtc);
1348 
1349  /* Enable the write protection for RTC registers */
1351 
1352  /* Change RTC state */
1353  hrtc->State = HAL_RTC_STATE_READY;
1354 
1355  /* Process Unlocked */
1356  __HAL_UNLOCK(hrtc);
1357 
1358  return HAL_OK;
1359 }
1360 
1366 HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef *hrtc)
1367 {
1368  HAL_StatusTypeDef status;
1369 
1370  /* Process Locked */
1371  __HAL_LOCK(hrtc);
1372 
1373  hrtc->State = HAL_RTC_STATE_BUSY;
1374 
1375  /* Disable the write protection for RTC registers */
1377 
1378  /* Enter Initialization mode */
1379  status = RTC_EnterInitMode(hrtc);
1380  if (status == HAL_OK)
1381  {
1382  __HAL_RTC_CLOCKREF_DETECTION_ENABLE(hrtc);
1383 
1384  /* Exit Initialization mode */
1385  status = RTC_ExitInitMode(hrtc);
1386  }
1387 
1388  /* Enable the write protection for RTC registers */
1390 
1391  if (status == HAL_OK)
1392  {
1393  hrtc->State = HAL_RTC_STATE_READY;
1394  }
1395 
1396  /* Process Unlocked */
1397  __HAL_UNLOCK(hrtc);
1398 
1399  return status;
1400 }
1401 
1407 HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef *hrtc)
1408 {
1409  HAL_StatusTypeDef status;
1410 
1411  /* Process Locked */
1412  __HAL_LOCK(hrtc);
1413 
1414  hrtc->State = HAL_RTC_STATE_BUSY;
1415 
1416  /* Disable the write protection for RTC registers */
1418 
1419  /* Enter Initialization mode */
1420  status = RTC_EnterInitMode(hrtc);
1421  if (status == HAL_OK)
1422  {
1423  __HAL_RTC_CLOCKREF_DETECTION_DISABLE(hrtc);
1424 
1425  /* Exit Initialization mode */
1426  status = RTC_ExitInitMode(hrtc);
1427  }
1428 
1429  /* Enable the write protection for RTC registers */
1431 
1432  if (status == HAL_OK)
1433  {
1434  hrtc->State = HAL_RTC_STATE_READY;
1435  }
1436 
1437  /* Process Unlocked */
1438  __HAL_UNLOCK(hrtc);
1439 
1440  return status;
1441 }
1442 
1450 HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef *hrtc)
1451 {
1452  /* Process Locked */
1453  __HAL_LOCK(hrtc);
1454 
1455  hrtc->State = HAL_RTC_STATE_BUSY;
1456 
1457  /* Disable the write protection for RTC registers */
1459 
1460  /* Set the BYPSHAD bit */
1461  SET_BIT(hrtc->Instance->CR, RTC_CR_BYPSHAD);
1462 
1463  /* Enable the write protection for RTC registers */
1465 
1466  /* Change RTC state */
1467  hrtc->State = HAL_RTC_STATE_READY;
1468 
1469  /* Process Unlocked */
1470  __HAL_UNLOCK(hrtc);
1471 
1472  return HAL_OK;
1473 }
1474 
1482 HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef *hrtc)
1483 {
1484  /* Process Locked */
1485  __HAL_LOCK(hrtc);
1486 
1487  hrtc->State = HAL_RTC_STATE_BUSY;
1488 
1489  /* Disable the write protection for RTC registers */
1491 
1492  /* Clear the BYPSHAD bit */
1493  CLEAR_BIT(RTC->CR, RTC_CR_BYPSHAD);
1494 
1495  /* Enable the write protection for RTC registers */
1497 
1498  /* Change RTC state */
1499  hrtc->State = HAL_RTC_STATE_READY;
1500 
1501  /* Process Unlocked */
1502  __HAL_UNLOCK(hrtc);
1503 
1504  return HAL_OK;
1505 }
1506 
1532 {
1533  /* Prevent unused argument(s) compilation warning */
1534  UNUSED(hrtc);
1535 
1536  /* NOTE : This function should not be modified, when the callback is needed,
1537  the HAL_RTCEx_AlarmBEventCallback could be implemented in the user file
1538  */
1539 }
1540 
1547 HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
1548 {
1549  uint32_t tickstart = HAL_GetTick();
1550 
1551  while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBF) == 0U)
1552  {
1553  if (Timeout != HAL_MAX_DELAY)
1554  {
1555  if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
1556  {
1557  hrtc->State = HAL_RTC_STATE_TIMEOUT;
1558  return HAL_TIMEOUT;
1559  }
1560  }
1561  }
1562 
1563  /* Clear the Alarm Flag */
1564  __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF);
1565 
1566  /* Change RTC state */
1567  hrtc->State = HAL_RTC_STATE_READY;
1568 
1569  return HAL_OK;
1570 }
1571 
1603 #if defined(STM32L412xx) || defined(STM32L422xx)
1604 
1610 HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper)
1611 {
1612  uint32_t tmpreg;
1613  /* Process TAMP instance pointer */
1614  TAMP_TypeDef *tamp = (TAMP_TypeDef *)((uint32_t)hrtc->Instance + hrtc->TampOffset);
1615 
1616  /* Check the parameters */
1617  assert_param(IS_RTC_TAMPER(sTamper->Tamper));
1618  assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger));
1619  assert_param(IS_RTC_TAMPER_ERASE_MODE(sTamper->NoErase));
1620  assert_param(IS_RTC_TAMPER_MASKFLAG_STATE(sTamper->MaskFlag));
1621  assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection));
1622  assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter));
1623  assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency));
1624  assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration));
1625  assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp));
1626  /* Trigger and Filter have exclusive configurations */
1627  assert_param(((sTamper->Filter != RTC_TAMPERFILTER_DISABLE) && ((sTamper->Trigger == RTC_TAMPERTRIGGER_LOWLEVEL) || (sTamper->Trigger == RTC_TAMPERTRIGGER_HIGHLEVEL)))
1628  || ((sTamper->Filter == RTC_TAMPERFILTER_DISABLE) && ((sTamper->Trigger == RTC_TAMPERTRIGGER_RISINGEDGE) || (sTamper->Trigger == RTC_TAMPERTRIGGER_FALLINGEDGE))));
1629 
1630  /* Configuration register 2 */
1631  tmpreg = tamp->CR2;
1632  tmpreg &= ~((sTamper->Tamper << TAMP_CR2_TAMP1TRG_Pos) | (sTamper->Tamper << TAMP_CR2_TAMP1MSK_Pos) | (sTamper->Tamper << TAMP_CR2_TAMP1NOERASE_Pos));
1633 
1634  /* Configure the tamper trigger bit */
1635  if ((sTamper->Trigger == RTC_TAMPERTRIGGER_HIGHLEVEL) || (sTamper->Trigger == RTC_TAMPERTRIGGER_FALLINGEDGE))
1636  {
1637  tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1TRG_Pos);
1638  }
1639 
1640  /* Configure the tamper flags masking bit */
1641  if (sTamper->MaskFlag != RTC_TAMPERMASK_FLAG_DISABLE)
1642  {
1643  tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1MSK_Pos);
1644  }
1645 
1646  /* Configure the tamper backup registers erasure bit */
1647  if (sTamper->NoErase != RTC_TAMPER_ERASE_BACKUP_ENABLE)
1648  {
1649  tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1NOERASE_Pos);
1650  }
1651  tamp->CR2 = tmpreg;
1652 
1653  /* Configure filtering parameters */
1654  tamp->FLTCR = (sTamper->Filter) | (sTamper->SamplingFrequency) | \
1655  (sTamper->PrechargeDuration) | (sTamper->TamperPullUp);
1656 
1657  /* Configure Timestamp saving on tamper detection */
1658  if ((hrtc->Instance->CR & RTC_CR_TAMPTS) != (sTamper->TimeStampOnTamperDetection))
1659  {
1661  tmpreg = (hrtc->Instance->CR & ~RTC_CR_TAMPTS);
1662  hrtc->Instance->CR = (tmpreg | (sTamper->TimeStampOnTamperDetection));
1664  }
1665 
1666  /* Enable selected tamper */
1667  tamp->CR1 |= (sTamper->Tamper);
1668 
1669  return HAL_OK;
1670 }
1671 #else /* #if defined(STM32L412xx) || defined(STM32L422xx) */
1672 
1679 HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper)
1680 {
1681  uint32_t tmpreg;
1682 
1683  /* Check the parameters */
1684  assert_param(IS_RTC_TAMPER(sTamper->Tamper));
1685  assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger));
1686  assert_param(IS_RTC_TAMPER_ERASE_MODE(sTamper->NoErase));
1687  assert_param(IS_RTC_TAMPER_MASKFLAG_STATE(sTamper->MaskFlag));
1688  assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter));
1689  assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency));
1690  assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration));
1691  assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp));
1692  assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection));
1693 
1694  /* Process Locked */
1695  __HAL_LOCK(hrtc);
1696 
1697  hrtc->State = HAL_RTC_STATE_BUSY;
1698 
1699  /* Configure the tamper trigger */
1700  if (sTamper->Trigger != RTC_TAMPERTRIGGER_RISINGEDGE)
1701  {
1702  sTamper->Trigger = (uint32_t)(sTamper->Tamper << 1);
1703  }
1704 
1705  if (sTamper->NoErase != RTC_TAMPER_ERASE_BACKUP_ENABLE)
1706  {
1707  sTamper->NoErase = 0;
1708 #if defined(RTC_TAMPER1_SUPPORT)
1709  if ((sTamper->Tamper & RTC_TAMPER_1) != 0)
1710  {
1711  sTamper->NoErase |= RTC_TAMPCR_TAMP1NOERASE;
1712  }
1713 #endif /* RTC_TAMPER1_SUPPORT */
1714  if ((sTamper->Tamper & RTC_TAMPER_2) != 0)
1715  {
1716  sTamper->NoErase |= RTC_TAMPCR_TAMP2NOERASE;
1717  }
1718 #if defined(RTC_TAMPER3_SUPPORT)
1719  if ((sTamper->Tamper & RTC_TAMPER_3) != 0)
1720  {
1721  sTamper->NoErase |= RTC_TAMPCR_TAMP3NOERASE;
1722  }
1723 #endif /* RTC_TAMPER3_SUPPORT */
1724  }
1725 
1726  if (sTamper->MaskFlag != RTC_TAMPERMASK_FLAG_DISABLE)
1727  {
1728  sTamper->MaskFlag = 0;
1729 #if defined(RTC_TAMPER1_SUPPORT)
1730  if ((sTamper->Tamper & RTC_TAMPER_1) != 0)
1731  {
1732  sTamper->MaskFlag |= RTC_TAMPCR_TAMP1MF;
1733  }
1734 #endif /* RTC_TAMPER1_SUPPORT */
1735  if ((sTamper->Tamper & RTC_TAMPER_2) != 0)
1736  {
1737  sTamper->MaskFlag |= RTC_TAMPCR_TAMP2MF;
1738  }
1739 #if defined(RTC_TAMPER3_SUPPORT)
1740  if ((sTamper->Tamper & RTC_TAMPER_3) != 0)
1741  {
1742  sTamper->MaskFlag |= RTC_TAMPCR_TAMP3MF;
1743  }
1744 #endif /* RTC_TAMPER3_SUPPORT */
1745  }
1746 
1747  tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->Trigger | (uint32_t)sTamper->NoErase | \
1748  (uint32_t)sTamper->MaskFlag | (uint32_t)sTamper->Filter | (uint32_t)sTamper->SamplingFrequency | \
1749  (uint32_t)sTamper->PrechargeDuration | (uint32_t)sTamper->TamperPullUp | sTamper->TimeStampOnTamperDetection);
1750 
1751  hrtc->Instance->TAMPCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | RTC_TAMPCR_MASK);
1752 
1753  hrtc->Instance->TAMPCR |= tmpreg;
1754 
1755  hrtc->State = HAL_RTC_STATE_READY;
1756 
1757  /* Process Unlocked */
1758  __HAL_UNLOCK(hrtc);
1759 
1760  return HAL_OK;
1761 }
1762 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) */
1763 
1764 
1765 
1766 #if defined(STM32L412xx) || defined(STM32L422xx)
1767 
1773 HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper)
1774 {
1775  uint32_t tmpreg;
1776  /* Process TAMP instance pointer */
1777  TAMP_TypeDef *tamp = (TAMP_TypeDef *)((uint32_t)hrtc->Instance + hrtc->TampOffset);
1778 
1779  /* Check the parameters */
1780  assert_param(IS_RTC_TAMPER(sTamper->Tamper));
1781  assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger));
1782  assert_param(IS_RTC_TAMPER_ERASE_MODE(sTamper->NoErase));
1783  assert_param(IS_RTC_TAMPER_MASKFLAG_STATE(sTamper->MaskFlag));
1784  assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter));
1785  assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency));
1786  assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration));
1787  assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp));
1788  assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection));
1789 
1790  /* Copy configuration register into temporary variable */
1791  tmpreg = tamp->CR2;
1792 
1793  /* Clear the bits that are going to be configured and leave the others unchanged */
1794  tmpreg &= ~((sTamper->Tamper << TAMP_CR2_TAMP1TRG_Pos) | (sTamper->Tamper << TAMP_CR2_TAMP1MSK_Pos) | (sTamper->Tamper << TAMP_CR2_TAMP1NOERASE_Pos));
1795 
1796  if (sTamper->Trigger != RTC_TAMPERTRIGGER_RISINGEDGE)
1797  {
1798  tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1TRG_Pos);
1799  }
1800 
1801  /* Configure the tamper flags masking bit */
1802  if (sTamper->MaskFlag != RTC_TAMPERMASK_FLAG_DISABLE)
1803  {
1804  tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1MSK_Pos);
1805  }
1806 
1807  /* Configure the tamper backup registers erasure bit */
1808  if (sTamper->NoErase != RTC_TAMPER_ERASE_BACKUP_ENABLE)
1809  {
1810  tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1NOERASE_Pos);
1811  }
1812  tamp->CR2 = tmpreg;
1813 
1814  /* Configure filtering parameters */
1815  tamp->FLTCR = (sTamper->Filter) | (sTamper->SamplingFrequency) | \
1816  (sTamper->PrechargeDuration) | (sTamper->TamperPullUp);
1817 
1818  /* Configure Timestamp saving on tamper detection */
1819  if ((hrtc->Instance->CR & RTC_CR_TAMPTS) != (sTamper->TimeStampOnTamperDetection))
1820  {
1822  tmpreg = (hrtc->Instance->CR & ~RTC_CR_TAMPTS);
1823  hrtc->Instance->CR = (tmpreg | (sTamper->TimeStampOnTamperDetection));
1825  }
1826 
1827  /* Configure RTC Tamper Interrupt: EXTI configuration */
1828  __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT();
1829  __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_FALLING_EDGE();
1830 
1831  /* Enable interrupt on selected tamper */
1832  tamp->IER |= sTamper->Tamper;
1833 
1834  /* Enable selected tamper */
1835  tamp->CR1 |= sTamper->Tamper;
1836 
1837  return HAL_OK;
1838 }
1839 #else /* #if defined(STM32L412xx) || defined(STM32L422xx) */
1840 
1848 HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper)
1849 {
1850  uint32_t tmpreg = 0;
1851 
1852  /* Check the parameters */
1853  assert_param(IS_RTC_TAMPER(sTamper->Tamper));
1854  assert_param(IS_RTC_TAMPER_INTERRUPT(sTamper->Interrupt));
1855  assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger));
1856  assert_param(IS_RTC_TAMPER_ERASE_MODE(sTamper->NoErase));
1857  assert_param(IS_RTC_TAMPER_MASKFLAG_STATE(sTamper->MaskFlag));
1858  assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter));
1859  assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency));
1860  assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration));
1861  assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp));
1862  assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection));
1863 
1864  /* Process Locked */
1865  __HAL_LOCK(hrtc);
1866 
1867  hrtc->State = HAL_RTC_STATE_BUSY;
1868 
1869  /* Configure the tamper trigger */
1870  if (sTamper->Trigger != RTC_TAMPERTRIGGER_RISINGEDGE)
1871  {
1872  sTamper->Trigger = (uint32_t)(sTamper->Tamper << 1);
1873  }
1874 
1875  if (sTamper->NoErase != RTC_TAMPER_ERASE_BACKUP_ENABLE)
1876  {
1877  sTamper->NoErase = 0;
1878 #if defined(RTC_TAMPER1_SUPPORT)
1879  if ((sTamper->Tamper & RTC_TAMPER_1) != 0)
1880  {
1881  sTamper->NoErase |= RTC_TAMPCR_TAMP1NOERASE;
1882  }
1883 #endif /* RTC_TAMPER1_SUPPORT */
1884  if ((sTamper->Tamper & RTC_TAMPER_2) != 0)
1885  {
1886  sTamper->NoErase |= RTC_TAMPCR_TAMP2NOERASE;
1887  }
1888 #if defined(RTC_TAMPER3_SUPPORT)
1889  if ((sTamper->Tamper & RTC_TAMPER_3) != 0)
1890  {
1891  sTamper->NoErase |= RTC_TAMPCR_TAMP3NOERASE;
1892  }
1893 #endif /* RTC_TAMPER3_SUPPORT */
1894  }
1895 
1896  if (sTamper->MaskFlag != RTC_TAMPERMASK_FLAG_DISABLE)
1897  {
1898  sTamper->MaskFlag = 0;
1899 #if defined(RTC_TAMPER1_SUPPORT)
1900  if ((sTamper->Tamper & RTC_TAMPER_1) != 0)
1901  {
1902  sTamper->MaskFlag |= RTC_TAMPCR_TAMP1MF;
1903  }
1904 #endif /* RTC_TAMPER1_SUPPORT */
1905  if ((sTamper->Tamper & RTC_TAMPER_2) != 0)
1906  {
1907  sTamper->MaskFlag |= RTC_TAMPCR_TAMP2MF;
1908  }
1909 #if defined(RTC_TAMPER3_SUPPORT)
1910  if ((sTamper->Tamper & RTC_TAMPER_3) != 0)
1911  {
1912  sTamper->MaskFlag |= RTC_TAMPCR_TAMP3MF;
1913  }
1914 #endif /* RTC_TAMPER3_SUPPORT */
1915  }
1916 
1917  tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->Interrupt | (uint32_t)sTamper->Trigger | (uint32_t)sTamper->NoErase | \
1918  (uint32_t)sTamper->MaskFlag | (uint32_t)sTamper->Filter | (uint32_t)sTamper->SamplingFrequency | \
1919  (uint32_t)sTamper->PrechargeDuration | (uint32_t)sTamper->TamperPullUp | sTamper->TimeStampOnTamperDetection);
1920 
1921  hrtc->Instance->TAMPCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | RTC_TAMPCR_MASK);
1922 
1923  hrtc->Instance->TAMPCR |= tmpreg;
1924 
1925  /* RTC Tamper Interrupt Configuration: EXTI configuration */
1926  __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT();
1927  __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE();
1928 
1929  hrtc->State = HAL_RTC_STATE_READY;
1930 
1931  /* Process Unlocked */
1932  __HAL_UNLOCK(hrtc);
1933 
1934  return HAL_OK;
1935 }
1936 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) */
1937 
1938 
1939 #if defined(STM32L412xx) || defined(STM32L422xx)
1940 
1949 HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper)
1950 {
1951  /* Process TAMP instance pointer */
1952  TAMP_TypeDef *tamp = (TAMP_TypeDef *)((uint32_t)hrtc->Instance + hrtc->TampOffset);
1953 
1954  assert_param(IS_RTC_TAMPER(Tamper));
1955 
1956  /* Disable the selected Tamper pin */
1957  tamp->CR1 &= ~Tamper;
1958 
1959  /* Clear tamper mask/noerase/trigger configuration */
1960  tamp->CR2 &= ~((Tamper << 24) | (Tamper << 16) | Tamper);
1961 
1962  /* Clear tamper interrupt mode configuration */
1963  tamp->IER &= ~Tamper;
1964 
1965  /* Clear tamper interrupt and event flags (WO register) */
1966  tamp->SCR = Tamper;
1967 
1968  return HAL_OK;
1969 }
1970 #else /* #if defined(STM32L412xx) || defined(STM32L422xx) */
1971 
1981 HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper)
1982 {
1983  assert_param(IS_RTC_TAMPER(Tamper));
1984 
1985  /* Process Locked */
1986  __HAL_LOCK(hrtc);
1987 
1988  hrtc->State = HAL_RTC_STATE_BUSY;
1989 
1990  /* Disable the selected Tamper pin */
1991  hrtc->Instance->TAMPCR &= ~Tamper;
1992 
1993 #if defined(RTC_TAMPER1_SUPPORT)
1994  if ((Tamper & RTC_TAMPER_1) != 0U)
1995  {
1996  /* Disable the Tamper1 interrupt */
1997  hrtc->Instance->TAMPCR &= ((uint32_t)~(RTC_IT_TAMP | RTC_IT_TAMP1));
1998  }
1999 #endif /* RTC_TAMPER1_SUPPORT */
2000  if ((Tamper & RTC_TAMPER_2) != 0U)
2001  {
2002  /* Disable the Tamper2 interrupt */
2003  hrtc->Instance->TAMPCR &= ((uint32_t)~(RTC_IT_TAMP | RTC_IT_TAMP2));
2004  }
2005 #if defined(RTC_TAMPER3_SUPPORT)
2006  if ((Tamper & RTC_TAMPER_3) != 0U)
2007  {
2008  /* Disable the Tamper3 interrupt */
2009  hrtc->Instance->TAMPCR &= ((uint32_t)~(RTC_IT_TAMP | RTC_IT_TAMP3));
2010  }
2011 #endif /* RTC_TAMPER3_SUPPORT */
2012 
2013  hrtc->State = HAL_RTC_STATE_READY;
2014 
2015  /* Process Unlocked */
2016  __HAL_UNLOCK(hrtc);
2017 
2018  return HAL_OK;
2019 }
2020 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) */
2021 
2022 
2023 #if defined(RTC_TAMPER1_SUPPORT)
2024 
2030 HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
2031 {
2032  uint32_t tickstart = HAL_GetTick();
2033 
2034  /* Get the status of the Interrupt */
2035  while (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F) == 0U)
2036  {
2037  if (Timeout != HAL_MAX_DELAY)
2038  {
2039  if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
2040  {
2041  hrtc->State = HAL_RTC_STATE_TIMEOUT;
2042  return HAL_TIMEOUT;
2043  }
2044  }
2045  }
2046 
2047  /* Clear the Tamper Flag */
2048  __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP1F);
2049 
2050  /* Change RTC state */
2051  hrtc->State = HAL_RTC_STATE_READY;
2052 
2053  return HAL_OK;
2054 }
2055 #endif /* RTC_TAMPER1_SUPPORT */
2056 
2063 HAL_StatusTypeDef HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
2064 {
2065  uint32_t tickstart = HAL_GetTick();
2066 
2067  /* Get the status of the Interrupt */
2068  while (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP2F) == 0U)
2069  {
2070  if (Timeout != HAL_MAX_DELAY)
2071  {
2072  if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
2073  {
2074  hrtc->State = HAL_RTC_STATE_TIMEOUT;
2075  return HAL_TIMEOUT;
2076  }
2077  }
2078  }
2079 
2080  /* Clear the Tamper Flag */
2081  __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP2F);
2082 
2083  /* Change RTC state */
2084  hrtc->State = HAL_RTC_STATE_READY;
2085 
2086  return HAL_OK;
2087 }
2088 
2089 #if defined(RTC_TAMPER3_SUPPORT)
2090 
2096 HAL_StatusTypeDef HAL_RTCEx_PollForTamper3Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
2097 {
2098  uint32_t tickstart = HAL_GetTick();
2099 
2100  /* Get the status of the Interrupt */
2101  while (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP3F) == 0U)
2102  {
2103  if (Timeout != HAL_MAX_DELAY)
2104  {
2105  if ((Timeout == 0) || ((HAL_GetTick() - tickstart) > Timeout))
2106  {
2107  hrtc->State = HAL_RTC_STATE_TIMEOUT;
2108  return HAL_TIMEOUT;
2109  }
2110  }
2111  }
2112 
2113  /* Clear the Tamper Flag */
2114  __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP3F);
2115 
2116  /* Change RTC state */
2117  hrtc->State = HAL_RTC_STATE_READY;
2118 
2119  return HAL_OK;
2120 }
2121 #endif /* RTC_TAMPER3_SUPPORT */
2122 
2123 
2124 
2125 #if defined(RTC_TAMPER1_SUPPORT)
2126 
2132 {
2133  /* Prevent unused argument(s) compilation warning */
2134  UNUSED(hrtc);
2135 
2136  /* NOTE : This function should not be modified, when the callback is needed,
2137  the HAL_RTCEx_Tamper1EventCallback could be implemented in the user file
2138  */
2139 }
2140 #endif /* RTC_TAMPER1_SUPPORT */
2141 
2148 {
2149  /* Prevent unused argument(s) compilation warning */
2150  UNUSED(hrtc);
2151 
2152  /* NOTE : This function should not be modified, when the callback is needed,
2153  the HAL_RTCEx_Tamper2EventCallback could be implemented in the user file
2154  */
2155 }
2156 
2157 #if defined(RTC_TAMPER3_SUPPORT)
2158 
2164 {
2165  /* Prevent unused argument(s) compilation warning */
2166  UNUSED(hrtc);
2167 
2168  /* NOTE : This function should not be modified, when the callback is needed,
2169  the HAL_RTCEx_Tamper3EventCallback could be implemented in the user file
2170  */
2171 }
2172 #endif /* RTC_TAMPER3_SUPPORT */
2173 
2208 void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data)
2209 {
2210  uint32_t __IO tmp;
2211 #if defined(STM32L412xx) || defined(STM32L422xx)
2212  /* Process TAMP instance pointer */
2213  TAMP_TypeDef *tamp = (TAMP_TypeDef *)((uint32_t)hrtc->Instance + hrtc->TampOffset);
2214 
2215  /* Check the parameters */
2216  assert_param(IS_RTC_BKP(BackupRegister));
2217 
2218  tmp = (uint32_t) & (tamp->BKP0R);
2219 #else /* #if defined(STM32L412xx) || defined(STM32L422xx) */
2220  /* Check the parameters */
2221  assert_param(IS_RTC_BKP(BackupRegister));
2222 
2223  tmp = (uint32_t) & (hrtc->Instance->BKP0R);
2224 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) */
2225 
2226  tmp += (BackupRegister * 4U);
2227 
2228  /* Write the specified register */
2229  *(__IO uint32_t *)tmp = (uint32_t)Data;
2230 }
2231 
2232 
2241 uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister)
2242 {
2243  uint32_t tmp;
2244 #if defined(STM32L412xx) || defined(STM32L422xx)
2245  /* Process TAMP instance pointer */
2246  TAMP_TypeDef *tamp = (TAMP_TypeDef *)((uint32_t)hrtc->Instance + hrtc->TampOffset);
2247 
2248  /* Check the parameters */
2249  assert_param(IS_RTC_BKP(BackupRegister));
2250 
2251  tmp = (uint32_t) & (tamp->BKP0R);
2252 #else /* #if defined(STM32L412xx) || defined(STM32L422xx) */
2253  /* Check the parameters */
2254  assert_param(IS_RTC_BKP(BackupRegister));
2255 
2256  tmp = (uint32_t) & (hrtc->Instance->BKP0R);
2257 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) */
2258 
2259  tmp += (BackupRegister * 4U);
2260 
2261  /* Read the specified register */
2262  return (*(__IO uint32_t *)tmp);
2263 }
2264 
2265 
2274 #endif /* HAL_RTC_MODULE_ENABLED */
2275 
2284 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
2285 
HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
Set TimeStamp with Interrupt.
void(* Tamper3EventCallback)(struct __RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef HAL_RTCEx_SetInternalTimeStamp(RTC_HandleTypeDef *hrtc)
Set Internal TimeStamp.
void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data)
HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc)
Deactivate TimeStamp.
HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
Handle TimeStamp polling request.
HAL_StatusTypeDef HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc)
Deactivate wake up timer counter.
__HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc, RTC_IT_WUT)
__HAL_RTC_WAKEUPTIMER_ENABLE(hrtc)
HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc)
Wait until the RTC Time and Date registers (RTC_TR and RTC_DR) are synchronized with RTC APB clock...
HAL_StatusTypeDef uint32_t WakeUpCounter
HAL_StatusTypeDef uint32_t uint32_t WakeUpClock
This file contains all the functions prototypes for the HAL module driver.
HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
Set TimeStamp.
__HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT()
HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef *hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmoothCalibMinusPulsesValue)
__IO HAL_RTCStateTypeDef State
void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc)
Handle Wake Up Timer interrupt request.
__HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE()
HAL_StatusTypeDef HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister)
void(* Tamper2EventCallback)(struct __RTC_HandleTypeDef *hrtc)
void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc)
__HAL_RTC_WRITEPROTECTION_DISABLE(hrtc)
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef *hrtc)
__HAL_UNLOCK(hrtc)
void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc)
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
HAL_StatusTypeDef HAL_RTCEx_DeactivateInternalTimeStamp(RTC_HandleTypeDef *hrtc)
Deactivate Internal TimeStamp.
RTC Time structure definition.
__HAL_LOCK(hrtc)
HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef *hrtc, uint32_t CalibOutput)
return HAL_OK
HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper)
HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
Set wake up timer.
void HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc)
Handle TimeStamp interrupt request.
HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef *hrtc)
void HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef *hrtc)
void(* TimeStampEventCallback)(struct __RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef HAL_RTCEx_PollForTamper3Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc)
TimeStamp callback.
void(* Tamper1EventCallback)(struct __RTC_HandleTypeDef *hrtc)
void HAL_RTCEx_Tamper3EventCallback(RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef HAL_RTCEx_SetLowPowerCalib(RTC_HandleTypeDef *hrtc, uint32_t LowPowerCalib)
uint32_t HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc)
Get wake up timer counter.
uint8_t RTC_Bcd2ToByte(uint8_t Value)
Convert from 2 digit BCD to Binary.
HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
RTC Date structure definition.
__HAL_RTC_WRITEPROTECTION_ENABLE(hrtc)
HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper)
uint32_t TimeStampOnTamperDetection
HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTimeStamp, RTC_DateTypeDef *sTimeStampDate, uint32_t Format)
Get the RTC TimeStamp value.
HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef *hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS)
HAL_StatusTypeDef RTC_ExitInitMode(RTC_HandleTypeDef *hrtc)
Exit the RTC Initialization mode.
HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
void(* WakeUpTimerEventCallback)(struct __RTC_HandleTypeDef *hrtc)
RTC Handle Structure definition.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper)
HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock, uint32_t WakeUpAutoClr)
Set wake up timer with interrupt.
HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef *hrtc)
Enter the RTC Initialization mode.
HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)