2 ******************************************************************************
3 * @file stm32l1xx_hal_rtc_ex.c
4 * @author MCD Application Team
6 * @date 5-September-2014
7 * @brief Extended RTC HAL module driver.
8 * This file provides firmware functions to manage the following
9 * functionalities of the Real Time Clock (RTC) Extension peripheral:
10 * + RTC Time Stamp functions
11 * + RTC Tamper functions
12 * + RTC Wake-up functions
13 * + Extension Control functions
14 * + Extension RTC features functions
17 ==============================================================================
18 ##### How to use this driver #####
19 ==============================================================================
21 (+) Enable the RTC domain access.
22 (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour
23 format using the HAL_RTC_Init() function.
25 *** RTC Wakeup configuration ***
26 ================================
28 (+) To configure the RTC Wakeup Clock source and Counter use the HAL_RTCEx_SetWakeUpTimer()
29 function. You can also configure the RTC Wakeup timer with interrupt mode
30 using the HAL_RTCEx_SetWakeUpTimer_IT() function.
31 (+) To read the RTC WakeUp Counter register, use the HAL_RTCEx_GetWakeUpTimer()
34 *** TimeStamp configuration ***
35 ===============================
37 (+) Configure the RTC_AFx trigger and enable the RTC TimeStamp using the
38 HAL_RTCEx_SetTimeStamp() function. You can also configure the RTC TimeStamp with
39 interrupt mode using the HAL_RTCEx_SetTimeStamp_IT() function.
40 (+) To read the RTC TimeStamp Time and Date register, use the HAL_RTCEx_GetTimeStamp()
42 (+) The TIMESTAMP alternate function can be mapped to RTC_AF1 (PC13).
44 *** Tamper configuration ***
45 ============================
47 (+) Enable the RTC Tamper and configure the Tamper filter count, trigger Edge
48 or Level according to the Tamper filter (if equal to 0 Edge else Level)
49 value, sampling frequency, precharge or discharge and Pull-UP using the
50 HAL_RTCEx_SetTamper() function. You can configure RTC Tamper with interrupt
51 mode using HAL_RTCEx_SetTamper_IT() function.
52 (+) The TAMPER1 alternate function can be mapped to RTC_AF1 (PC13).
54 *** Backup Data Registers configuration ***
55 ===========================================
57 (+) To write to the RTC Backup Data registers, use the HAL_RTCEx_BKUPWrite()
59 (+) To read the RTC Backup Data registers, use the HAL_RTCEx_BKUPRead()
63 ******************************************************************************
66 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
68 * Redistribution and use in source and binary forms, with or without modification,
69 * are permitted provided that the following conditions are met:
70 * 1. Redistributions of source code must retain the above copyright notice,
71 * this list of conditions and the following disclaimer.
72 * 2. Redistributions in binary form must reproduce the above copyright notice,
73 * this list of conditions and the following disclaimer in the documentation
74 * and/or other materials provided with the distribution.
75 * 3. Neither the name of STMicroelectronics nor the names of its contributors
76 * may be used to endorse or promote products derived from this software
77 * without specific prior written permission.
79 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
80 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
81 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
82 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
83 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
84 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
85 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
86 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
87 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
88 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90 ******************************************************************************
93 /* Includes ------------------------------------------------------------------*/
94 #include "stm32l1xx_hal.h"
96 /** @addtogroup STM32L1xx_HAL_Driver
104 #ifdef HAL_RTC_MODULE_ENABLED
106 /* Private typedef -----------------------------------------------------------*/
107 /* Private define ------------------------------------------------------------*/
108 /* Private macro -------------------------------------------------------------*/
109 /* Private variables ---------------------------------------------------------*/
110 /* Private function prototypes -----------------------------------------------*/
111 /* Private functions ---------------------------------------------------------*/
113 /** @addtogroup RTC_Exported_Functions
118 /** @addtogroup RTC_Exported_Functions_Group1
123 * @brief DeInitializes the RTC peripheral
124 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
125 * the configuration information for RTC.
126 * @note This function does not reset the RTC Backup Data registers.
129 HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc)
131 uint32_t tickstart = 0;
133 /* Check the parameters */
134 assert_param(IS_RTC_ALL_INSTANCE(hrtc->Instance));
137 hrtc->State = HAL_RTC_STATE_BUSY;
139 /* Disable the write protection for RTC registers */
140 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
142 /* Set Initialization mode */
143 if(RTC_EnterInitMode(hrtc) != HAL_OK)
145 /* Enable the write protection for RTC registers */
146 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
149 hrtc->State = HAL_RTC_STATE_ERROR;
155 /* Reset TR, DR and CR registers */
156 hrtc->Instance->TR = (uint32_t)0x00000000;
157 hrtc->Instance->DR = (uint32_t)0x00002101;
158 /* Reset All CR bits except CR[2:0] */
159 hrtc->Instance->CR &= (uint32_t)0x00000007;
161 tickstart = HAL_GetTick();
163 /* Wait till WUTWF flag is set and if Time out is reached exit */
164 while(((hrtc->Instance->ISR) & RTC_ISR_WUTWF) == (uint32_t)RESET)
166 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
168 /* Enable the write protection for RTC registers */
169 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
172 hrtc->State = HAL_RTC_STATE_TIMEOUT;
178 /* Reset all RTC CR register bits */
179 hrtc->Instance->CR &= (uint32_t)0x00000000;
180 hrtc->Instance->WUTR = (uint32_t)0x0000FFFF;
181 hrtc->Instance->PRER = (uint32_t)0x007F00FF;
182 hrtc->Instance->CALIBR = (uint32_t)0x00000000;
183 hrtc->Instance->ALRMAR = (uint32_t)0x00000000;
184 hrtc->Instance->ALRMBR = (uint32_t)0x00000000;
185 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
186 hrtc->Instance->SHIFTR = (uint32_t)0x00000000;
187 hrtc->Instance->CALR = (uint32_t)0x00000000;
188 hrtc->Instance->ALRMASSR = (uint32_t)0x00000000;
189 hrtc->Instance->ALRMBSSR = (uint32_t)0x00000000;
190 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
191 /* Reset ISR register and exit initialization mode */
192 hrtc->Instance->ISR = (uint32_t)0x00000000;
194 /* Reset Tamper and alternate functions configuration register */
195 hrtc->Instance->TAFCR = 0x00000000;
197 /* Wait for synchro */
198 if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
200 /* Enable the write protection for RTC registers */
201 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
203 hrtc->State = HAL_RTC_STATE_ERROR;
209 /* Enable the write protection for RTC registers */
210 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
212 /* De-Initialize RTC MSP */
213 HAL_RTC_MspDeInit(hrtc);
215 hrtc->State = HAL_RTC_STATE_RESET;
227 /** @addtogroup RTC_Exported_Functions_Group2
232 * @brief Gets RTC current time.
233 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
234 * the configuration information for RTC.
235 * @param sTime: Pointer to Time structure
236 * @param Format: Specifies the format of the entered parameters.
237 * This parameter can be one of the following values:
238 * @arg FORMAT_BIN: Binary data format
239 * @arg FORMAT_BCD: BCD data format
240 * @note Call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values
241 * in the higher-order calendar shadow registers.
244 HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format)
248 /* Check the parameters */
249 assert_param(IS_RTC_FORMAT(Format));
251 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
252 /* Get subseconds values from the correspondent registers*/
253 sTime->SubSeconds = (uint32_t)((hrtc->Instance->SSR) & RTC_SSR_SS);
254 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
256 /* Get the TR register */
257 tmpreg = (uint32_t)(hrtc->Instance->TR & RTC_TR_RESERVED_MASK);
259 /* Fill the structure fields with the read parameters */
260 sTime->Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16);
261 sTime->Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >>8);
262 sTime->Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU));
263 sTime->TimeFormat = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16);
265 /* Check the input parameters format */
266 if(Format == FORMAT_BIN)
268 /* Convert the time structure parameters to Binary format */
269 sTime->Hours = (uint8_t)RTC_Bcd2ToByte(sTime->Hours);
270 sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes);
271 sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds);
281 /** @addtogroup RTC_Exported_Functions_Group3
286 * @brief Sets the specified RTC Alarm.
287 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
288 * the configuration information for RTC.
289 * @param sAlarm: Pointer to Alarm structure
290 * @param Format: Specifies the format of the entered parameters.
291 * This parameter can be one of the following values:
292 * @arg FORMAT_BIN: Binary data format
293 * @arg FORMAT_BCD: BCD data format
296 HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format)
298 uint32_t tickstart = 0;
301 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
302 uint32_t subsecondtmpreg = 0;
303 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
305 /* Check the parameters */
306 assert_param(IS_RTC_FORMAT(Format));
307 assert_param(IS_ALARM(sAlarm->Alarm));
308 assert_param(IS_ALARM_MASK(sAlarm->AlarmMask));
309 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel));
310 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
311 assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds));
312 assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask));
313 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
318 hrtc->State = HAL_RTC_STATE_BUSY;
320 if(Format == FORMAT_BIN)
322 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
324 assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours));
325 assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
329 sAlarm->AlarmTime.TimeFormat = 0x00;
330 assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours));
332 assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes));
333 assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds));
335 if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
337 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay));
341 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay));
344 tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << 16) | \
345 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << 8) | \
346 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \
347 ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \
348 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << 24) | \
349 ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
350 ((uint32_t)sAlarm->AlarmMask));
354 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
356 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours);
357 assert_param(IS_RTC_HOUR12(tmpreg));
358 assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
362 sAlarm->AlarmTime.TimeFormat = 0x00;
363 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours)));
366 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes)));
367 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds)));
369 if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
371 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
372 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg));
376 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
377 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg));
380 tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << 16) | \
381 ((uint32_t)(sAlarm->AlarmTime.Minutes) << 8) | \
382 ((uint32_t) sAlarm->AlarmTime.Seconds) | \
383 ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \
384 ((uint32_t)(sAlarm->AlarmDateWeekDay) << 24) | \
385 ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
386 ((uint32_t)sAlarm->AlarmMask));
389 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
390 /* Configure the Alarm A or Alarm B Sub Second registers */
391 subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask));
392 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
394 /* Disable the write protection for RTC registers */
395 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
397 /* Configure the Alarm register */
398 if(sAlarm->Alarm == RTC_ALARM_A)
400 /* Disable the Alarm A interrupt */
401 __HAL_RTC_ALARMA_DISABLE(hrtc);
403 /* In case of interrupt mode is used, the interrupt source must disabled */
404 __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA);
406 tickstart = HAL_GetTick();
407 /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */
408 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET)
410 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
412 /* Enable the write protection for RTC registers */
413 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
415 hrtc->State = HAL_RTC_STATE_TIMEOUT;
417 /* Process Unlocked */
424 hrtc->Instance->ALRMAR = (uint32_t)tmpreg;
425 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
426 /* Configure the Alarm A Sub Second register */
427 hrtc->Instance->ALRMASSR = subsecondtmpreg;
428 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
429 /* Configure the Alarm state: Enable Alarm */
430 __HAL_RTC_ALARMA_ENABLE(hrtc);
434 /* Disable the Alarm B interrupt */
435 __HAL_RTC_ALARMB_DISABLE(hrtc);
437 /* In case of interrupt mode is used, the interrupt source must disabled */
438 __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRB);
440 tickstart = HAL_GetTick();
441 /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */
442 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET)
444 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
446 /* Enable the write protection for RTC registers */
447 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
449 hrtc->State = HAL_RTC_STATE_TIMEOUT;
451 /* Process Unlocked */
458 hrtc->Instance->ALRMBR = (uint32_t)tmpreg;
459 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
460 /* Configure the Alarm B Sub Second register */
461 hrtc->Instance->ALRMBSSR = subsecondtmpreg;
462 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
463 /* Configure the Alarm state: Enable Alarm */
464 __HAL_RTC_ALARMB_ENABLE(hrtc);
467 /* Enable the write protection for RTC registers */
468 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
470 /* Change RTC state */
471 hrtc->State = HAL_RTC_STATE_READY;
473 /* Process Unlocked */
480 * @brief Sets the specified RTC Alarm with Interrupt
481 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
482 * the configuration information for RTC.
483 * @param sAlarm: Pointer to Alarm structure
484 * @param Format: Specifies the format of the entered parameters.
485 * This parameter can be one of the following values:
486 * @arg FORMAT_BIN: Binary data format
487 * @arg FORMAT_BCD: BCD data format
488 * @note The Alarm register can only be written when the corresponding Alarm
489 * is disabled (Use the HAL_RTC_DeactivateAlarm()).
490 * @note The HAL_RTC_SetTime() must be called before enabling the Alarm feature.
493 HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format)
495 uint32_t tickstart = 0;
497 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
498 uint32_t subsecondtmpreg = 0;
499 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
501 /* Check the parameters */
502 assert_param(IS_RTC_FORMAT(Format));
503 assert_param(IS_ALARM(sAlarm->Alarm));
504 assert_param(IS_ALARM_MASK(sAlarm->AlarmMask));
505 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel));
506 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
507 assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds));
508 assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask));
509 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
514 hrtc->State = HAL_RTC_STATE_BUSY;
516 if(Format == FORMAT_BIN)
518 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
520 assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours));
521 assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
525 sAlarm->AlarmTime.TimeFormat = 0x00;
526 assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours));
528 assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes));
529 assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds));
531 if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
533 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay));
537 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay));
539 tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << 16) | \
540 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << 8) | \
541 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \
542 ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \
543 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << 24) | \
544 ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
545 ((uint32_t)sAlarm->AlarmMask));
549 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
551 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours);
552 assert_param(IS_RTC_HOUR12(tmpreg));
553 assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
557 sAlarm->AlarmTime.TimeFormat = 0x00;
558 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours)));
561 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes)));
562 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds)));
564 if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
566 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
567 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg));
571 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
572 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg));
574 tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << 16) | \
575 ((uint32_t)(sAlarm->AlarmTime.Minutes) << 8) | \
576 ((uint32_t) sAlarm->AlarmTime.Seconds) | \
577 ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \
578 ((uint32_t)(sAlarm->AlarmDateWeekDay) << 24) | \
579 ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
580 ((uint32_t)sAlarm->AlarmMask));
582 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
583 /* Configure the Alarm A or Alarm B Sub Second registers */
584 subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask));
585 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
587 /* Disable the write protection for RTC registers */
588 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
590 /* Configure the Alarm register */
591 if(sAlarm->Alarm == RTC_ALARM_A)
593 /* Disable the Alarm A interrupt */
594 __HAL_RTC_ALARMA_DISABLE(hrtc);
596 /* Clear flag alarm A */
597 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);
599 tickstart = HAL_GetTick();
600 /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */
601 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET)
603 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
605 /* Enable the write protection for RTC registers */
606 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
608 hrtc->State = HAL_RTC_STATE_TIMEOUT;
610 /* Process Unlocked */
617 hrtc->Instance->ALRMAR = (uint32_t)tmpreg;
618 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
619 /* Configure the Alarm A Sub Second register */
620 hrtc->Instance->ALRMASSR = subsecondtmpreg;
621 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
622 /* Configure the Alarm state: Enable Alarm */
623 __HAL_RTC_ALARMA_ENABLE(hrtc);
624 /* Configure the Alarm interrupt */
625 __HAL_RTC_ALARM_ENABLE_IT(hrtc,RTC_IT_ALRA);
629 /* Disable the Alarm B interrupt */
630 __HAL_RTC_ALARMB_DISABLE(hrtc);
632 /* Clear flag alarm B */
633 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF);
635 tickstart = HAL_GetTick();
636 /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */
637 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET)
639 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
641 /* Enable the write protection for RTC registers */
642 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
644 hrtc->State = HAL_RTC_STATE_TIMEOUT;
646 /* Process Unlocked */
653 hrtc->Instance->ALRMBR = (uint32_t)tmpreg;
654 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
655 /* Configure the Alarm B Sub Second register */
656 hrtc->Instance->ALRMBSSR = subsecondtmpreg;
657 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
658 /* Configure the Alarm state: Enable Alarm */
659 __HAL_RTC_ALARMB_ENABLE(hrtc);
660 /* Configure the Alarm interrupt */
661 __HAL_RTC_ALARM_ENABLE_IT(hrtc, RTC_IT_ALRB);
664 /* RTC Alarm Interrupt Configuration: EXTI configuration */
665 __HAL_RTC_ENABLE_IT(RTC_EXTI_LINE_ALARM_EVENT);
667 EXTI->RTSR |= RTC_EXTI_LINE_ALARM_EVENT;
669 /* Enable the write protection for RTC registers */
670 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
672 hrtc->State = HAL_RTC_STATE_READY;
674 /* Process Unlocked */
681 * @brief Gets the RTC Alarm value and masks.
682 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
683 * the configuration information for RTC.
684 * @param sAlarm: Pointer to Date structure
685 * @param Alarm: Specifies the Alarm.
686 * This parameter can be one of the following values:
687 * @arg RTC_ALARM_A: AlarmA
688 * @arg RTC_ALARM_B: AlarmB
689 * @param Format: Specifies the format of the entered parameters.
690 * This parameter can be one of the following values:
691 * @arg FORMAT_BIN: Binary data format
692 * @arg FORMAT_BCD: BCD data format
695 HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format)
698 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
699 uint32_t subsecondtmpreg = 0;
700 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
702 /* Check the parameters */
703 assert_param(IS_RTC_FORMAT(Format));
704 assert_param(IS_ALARM(Alarm));
706 if(Alarm == RTC_ALARM_A)
709 sAlarm->Alarm = RTC_ALARM_A;
711 tmpreg = (uint32_t)(hrtc->Instance->ALRMAR);
712 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
713 subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMASSR) & RTC_ALRMASSR_SS);
714 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
718 sAlarm->Alarm = RTC_ALARM_B;
720 tmpreg = (uint32_t)(hrtc->Instance->ALRMBR);
721 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
722 subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMBSSR) & RTC_ALRMBSSR_SS);
723 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
726 /* Fill the structure with the read parameters */
727 sAlarm->AlarmTime.Hours = (uint32_t)((tmpreg & (RTC_ALRMAR_HT | RTC_ALRMAR_HU)) >> 16);
728 sAlarm->AlarmTime.Minutes = (uint32_t)((tmpreg & (RTC_ALRMAR_MNT | RTC_ALRMAR_MNU)) >> 8);
729 sAlarm->AlarmTime.Seconds = (uint32_t)(tmpreg & (RTC_ALRMAR_ST | RTC_ALRMAR_SU));
730 sAlarm->AlarmTime.TimeFormat = (uint32_t)((tmpreg & RTC_ALRMAR_PM) >> 16);
731 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
732 sAlarm->AlarmTime.SubSeconds = (uint32_t) subsecondtmpreg;
733 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
734 sAlarm->AlarmDateWeekDay = (uint32_t)((tmpreg & (RTC_ALRMAR_DT | RTC_ALRMAR_DU)) >> 24);
735 sAlarm->AlarmDateWeekDaySel = (uint32_t)(tmpreg & RTC_ALRMAR_WDSEL);
736 sAlarm->AlarmMask = (uint32_t)(tmpreg & RTC_ALARMMASK_ALL);
738 if(Format == FORMAT_BIN)
740 sAlarm->AlarmTime.Hours = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours);
741 sAlarm->AlarmTime.Minutes = RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes);
742 sAlarm->AlarmTime.Seconds = RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds);
743 sAlarm->AlarmDateWeekDay = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
754 /** @defgroup RTC_Exported_Functions_Group6 Peripheral Control functions
755 * @brief Peripheral Control functions
758 ===============================================================================
759 ##### Peripheral Control functions #####
760 ===============================================================================
762 This subsection provides functions allowing to
763 (+) Wait for RTC Time and Date Synchronization
770 * @brief Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are
771 * synchronized with RTC APB clock.
772 * @note The RTC Resynchronization mode is write protected, use the
773 * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function.
774 * @note To read the calendar through the shadow registers after Calendar
775 * initialization, calendar update or after wakeup from low power modes
776 * the software must first clear the RSF flag.
777 * The software must then wait until it is set again before reading
778 * the calendar, which means that the calendar registers have been
779 * correctly copied into the RTC_TR and RTC_DR shadow registers.
780 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
781 * the configuration information for RTC.
784 HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef* hrtc)
786 uint32_t tickstart = 0;
788 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
789 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
790 if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET)
791 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
794 hrtc->Instance->ISR &= (uint32_t)RTC_RSF_MASK;
796 tickstart = HAL_GetTick();
798 /* Wait the registers to be synchronised */
799 while((hrtc->Instance->ISR & RTC_ISR_RSF) == (uint32_t)RESET)
801 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
823 /** @defgroup RTCEx RTCEx
824 * @brief RTC Extended HAL module driver
828 /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions
832 /** @defgroup RTCEx_Exported_Functions_Group4 RTC TimeStamp and Tamper functions
833 * @brief RTC TimeStamp and Tamper functions
836 ===============================================================================
837 ##### RTC TimeStamp and Tamper functions #####
838 ===============================================================================
840 [..] This section provides functions allowing to configure TimeStamp feature
847 * @brief Sets TimeStamp.
848 * @note This API must be called before enabling the TimeStamp feature.
849 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
850 * the configuration information for RTC.
851 * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is
853 * This parameter can be one of the following values:
854 * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the
855 * rising edge of the related pin.
856 * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the
857 * falling edge of the related pin.
860 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge)
864 /* Check the parameters */
865 assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge));
870 hrtc->State = HAL_RTC_STATE_BUSY;
872 /* Get the RTC_CR register and clear the bits to be configured */
873 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
875 tmpreg|= TimeStampEdge;
877 /* Disable the write protection for RTC registers */
878 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
880 /* Configure the Time Stamp TSEDGE and Enable bits */
881 hrtc->Instance->CR = (uint32_t)tmpreg;
883 __HAL_RTC_TIMESTAMP_ENABLE(hrtc);
885 /* Enable the write protection for RTC registers */
886 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
888 /* Change RTC state */
889 hrtc->State = HAL_RTC_STATE_READY;
891 /* Process Unlocked */
898 * @brief Sets TimeStamp with Interrupt.
899 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
900 * the configuration information for RTC.
901 * @note This API must be called before enabling the TimeStamp feature.
902 * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is
904 * This parameter can be one of the following values:
905 * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the
906 * rising edge of the related pin.
907 * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the
908 * falling edge of the related pin.
911 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge)
915 /* Check the parameters */
916 assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge));
921 hrtc->State = HAL_RTC_STATE_BUSY;
923 /* Get the RTC_CR register and clear the bits to be configured */
924 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
926 tmpreg |= TimeStampEdge;
928 /* Disable the write protection for RTC registers */
929 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
931 /* Configure the Time Stamp TSEDGE and Enable bits */
932 hrtc->Instance->CR = (uint32_t)tmpreg;
934 __HAL_RTC_TIMESTAMP_ENABLE(hrtc);
936 /* Enable IT timestamp */
937 __HAL_RTC_TIMESTAMP_ENABLE_IT(hrtc,RTC_IT_TS);
939 /* RTC timestamp Interrupt Configuration: EXTI configuration */
940 __HAL_RTC_ENABLE_IT(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT);
942 EXTI->RTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT;
944 /* Enable the write protection for RTC registers */
945 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
947 hrtc->State = HAL_RTC_STATE_READY;
949 /* Process Unlocked */
956 * @brief Deactivates TimeStamp.
957 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
958 * the configuration information for RTC.
961 HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc)
968 hrtc->State = HAL_RTC_STATE_BUSY;
970 /* Disable the write protection for RTC registers */
971 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
973 /* In case of interrupt mode is used, the interrupt source must disabled */
974 __HAL_RTC_TIMESTAMP_DISABLE_IT(hrtc, RTC_IT_TS);
976 /* Get the RTC_CR register and clear the bits to be configured */
977 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
979 /* Configure the Time Stamp TSEDGE and Enable bits */
980 hrtc->Instance->CR = (uint32_t)tmpreg;
982 /* Enable the write protection for RTC registers */
983 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
985 hrtc->State = HAL_RTC_STATE_READY;
987 /* Process Unlocked */
994 * @brief Gets the RTC TimeStamp value.
995 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
996 * the configuration information for RTC.
997 * @param sTimeStamp: Pointer to Time structure
998 * @param sTimeStampDate: Pointer to Date structure
999 * @param Format: specifies the format of the entered parameters.
1000 * This parameter can be one of the following values:
1001 * FORMAT_BIN: Binary data format
1002 * FORMAT_BCD: BCD data format
1003 * @retval HAL status
1005 HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef* sTimeStamp, RTC_DateTypeDef* sTimeStampDate, uint32_t Format)
1007 uint32_t tmptime = 0, tmpdate = 0;
1009 /* Check the parameters */
1010 assert_param(IS_RTC_FORMAT(Format));
1012 /* Get the TimeStamp time and date registers values */
1013 tmptime = (uint32_t)(hrtc->Instance->TSTR & RTC_TR_RESERVED_MASK);
1014 tmpdate = (uint32_t)(hrtc->Instance->TSDR & RTC_DR_RESERVED_MASK);
1016 /* Fill the Time structure fields with the read parameters */
1017 sTimeStamp->Hours = (uint8_t)((tmptime & (RTC_TR_HT | RTC_TR_HU)) >> 16);
1018 sTimeStamp->Minutes = (uint8_t)((tmptime & (RTC_TR_MNT | RTC_TR_MNU)) >> 8);
1019 sTimeStamp->Seconds = (uint8_t)(tmptime & (RTC_TR_ST | RTC_TR_SU));
1020 sTimeStamp->TimeFormat = (uint8_t)((tmptime & (RTC_TR_PM)) >> 16);
1021 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
1022 sTimeStamp->SubSeconds = (uint32_t)((hrtc->Instance->TSSSR) & RTC_TSSSR_SS);
1023 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
1025 /* Fill the Date structure fields with the read parameters */
1026 sTimeStampDate->Year = 0;
1027 sTimeStampDate->Month = (uint8_t)((tmpdate & (RTC_DR_MT | RTC_DR_MU)) >> 8);
1028 sTimeStampDate->Date = (uint8_t)(tmpdate & (RTC_DR_DT | RTC_DR_DU));
1029 sTimeStampDate->WeekDay = (uint8_t)((tmpdate & (RTC_DR_WDU)) >> 13);
1031 /* Check the input parameters format */
1032 if(Format == FORMAT_BIN)
1034 /* Convert the TimeStamp structure parameters to Binary format */
1035 sTimeStamp->Hours = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Hours);
1036 sTimeStamp->Minutes = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Minutes);
1037 sTimeStamp->Seconds = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Seconds);
1039 /* Convert the DateTimeStamp structure parameters to Binary format */
1040 sTimeStampDate->Month = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Month);
1041 sTimeStampDate->Date = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Date);
1042 sTimeStampDate->WeekDay = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->WeekDay);
1045 /* Clear the TIMESTAMP Flag */
1046 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF);
1052 * @brief Sets Tamper
1053 * @note By calling this API we disable the tamper interrupt for all tampers.
1054 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1055 * the configuration information for RTC.
1056 * @param sTamper: Pointer to Tamper Structure.
1057 * @retval HAL status
1059 HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper)
1061 uint32_t tmpreg = 0;
1063 /* Check the parameters */
1064 assert_param(IS_TAMPER(sTamper->Tamper));
1065 assert_param(IS_TAMPER_TRIGGER(sTamper->Trigger));
1066 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
1067 assert_param(IS_TAMPER_FILTER(sTamper->Filter));
1068 assert_param(IS_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency));
1069 assert_param(IS_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration));
1070 assert_param(IS_TAMPER_PULLUP_STATE(sTamper->TamperPullUp));
1071 assert_param(IS_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection));
1072 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
1074 /* Process Locked */
1077 hrtc->State = HAL_RTC_STATE_BUSY;
1079 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
1080 if((sTamper->Trigger == RTC_TAMPERTRIGGER_RISINGEDGE))
1082 /* Configure the RTC_TAFCR register */
1083 sTamper->Trigger = RTC_TAMPERTRIGGER_RISINGEDGE;
1087 sTamper->Trigger = (uint32_t)(sTamper->Tamper << 1);
1090 tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->Trigger | (uint32_t)sTamper->Filter |\
1091 (uint32_t)sTamper->SamplingFrequency | (uint32_t)sTamper->PrechargeDuration |\
1092 (uint32_t)sTamper->TamperPullUp | sTamper->TimeStampOnTamperDetection);
1094 hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | (uint32_t)RTC_TAFCR_TAMPTS |\
1095 (uint32_t)RTC_TAFCR_TAMPFREQ | (uint32_t)RTC_TAFCR_TAMPFLT | (uint32_t)RTC_TAFCR_TAMPPRCH |\
1096 (uint32_t)RTC_TAFCR_TAMPPUDIS | (uint32_t)RTC_TAFCR_TAMPIE);
1098 tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Trigger));
1100 hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)RTC_TAFCR_TAMP1E | (uint32_t)RTC_TAFCR_TAMP1TRG);
1102 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
1103 hrtc->Instance->TAFCR |= tmpreg;
1105 hrtc->State = HAL_RTC_STATE_READY;
1107 /* Process Unlocked */
1114 * @brief Sets Tamper with interrupt.
1115 * @note By calling this API we force the tamper interrupt for all tampers.
1116 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1117 * the configuration information for RTC.
1118 * @param sTamper: Pointer to RTC Tamper.
1119 * @retval HAL status
1121 HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper)
1123 uint32_t tmpreg = 0;
1125 /* Check the parameters */
1126 assert_param(IS_TAMPER(sTamper->Tamper));
1127 assert_param(IS_TAMPER_TRIGGER(sTamper->Trigger));
1128 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
1129 assert_param(IS_TAMPER_FILTER(sTamper->Filter));
1130 assert_param(IS_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency));
1131 assert_param(IS_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration));
1132 assert_param(IS_TAMPER_PULLUP_STATE(sTamper->TamperPullUp));
1133 assert_param(IS_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection));
1134 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
1136 /* Process Locked */
1139 hrtc->State = HAL_RTC_STATE_BUSY;
1141 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
1142 /* Configure the tamper trigger */
1143 if((sTamper->Trigger == RTC_TAMPERTRIGGER_RISINGEDGE))
1145 sTamper->Trigger = RTC_TAMPERTRIGGER_RISINGEDGE;
1149 sTamper->Trigger = (uint32_t) (sTamper->Tamper<<1);
1152 tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->Trigger | (uint32_t)sTamper->Filter |\
1153 (uint32_t)sTamper->SamplingFrequency | (uint32_t)sTamper->PrechargeDuration |\
1154 (uint32_t)sTamper->TamperPullUp | sTamper->TimeStampOnTamperDetection);
1156 hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | (uint32_t)RTC_TAFCR_TAMPTS |\
1157 (uint32_t)RTC_TAFCR_TAMPFREQ | (uint32_t)RTC_TAFCR_TAMPFLT | (uint32_t)RTC_TAFCR_TAMPPRCH |\
1158 (uint32_t)RTC_TAFCR_TAMPPUDIS);
1160 tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->Trigger);
1162 hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)RTC_TAFCR_TAMP1E | (uint32_t)RTC_TAFCR_TAMP1TRG | (uint32_t)RTC_TAFCR_TAMPIE);
1163 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
1164 hrtc->Instance->TAFCR |= tmpreg;
1166 /* Configure the Tamper Interrupt in the RTC_TAFCR */
1167 hrtc->Instance->TAFCR |= (uint32_t)RTC_TAFCR_TAMPIE;
1169 /* RTC Tamper Interrupt Configuration: EXTI configuration */
1170 __HAL_RTC_ENABLE_IT(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT);
1172 EXTI->RTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT;
1174 hrtc->State = HAL_RTC_STATE_READY;
1176 /* Process Unlocked */
1183 * @brief Deactivates Tamper.
1184 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1185 * the configuration information for RTC.
1186 * @param Tamper: Selected tamper pin.
1187 * This parameter can be a value of @ref RTCEx_Tamper_Pins_Definitions
1188 * @retval HAL status
1190 HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper)
1192 assert_param(IS_TAMPER(Tamper));
1194 /* Process Locked */
1197 hrtc->State = HAL_RTC_STATE_BUSY;
1199 /* Disable the selected Tamper pin */
1200 hrtc->Instance->TAFCR &= (uint32_t)~Tamper;
1202 hrtc->State = HAL_RTC_STATE_READY;
1204 /* Process Unlocked */
1211 * @brief This function handles TimeStamp interrupt request.
1212 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1213 * the configuration information for RTC.
1216 void HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc)
1218 if(__HAL_RTC_TIMESTAMP_GET_IT(hrtc, RTC_IT_TS))
1220 /* Get the status of the Interrupt */
1221 if((uint32_t)(hrtc->Instance->CR & RTC_IT_TS) != (uint32_t)RESET)
1223 /* TIMESTAMP callback */
1224 HAL_RTCEx_TimeStampEventCallback(hrtc);
1226 /* Clear the TIMESTAMP interrupt pending bit */
1227 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc,RTC_FLAG_TSF);
1231 /* Get the status of the Interrupt */
1232 if(__HAL_RTC_TAMPER_GET_IT(hrtc,RTC_IT_TAMP1))
1234 /* Get the TAMPER Interrupt enable bit and pending bit */
1235 if(((hrtc->Instance->TAFCR & (RTC_TAFCR_TAMPIE))) != (uint32_t)RESET)
1237 /* Tamper callback */
1238 HAL_RTCEx_Tamper1EventCallback(hrtc);
1240 /* Clear the Tamper interrupt pending bit */
1241 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP1F);
1245 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
1246 /* Get the status of the Interrupt */
1247 if(__HAL_RTC_TAMPER_GET_IT(hrtc, RTC_IT_TAMP2))
1249 /* Get the TAMPER Interrupt enable bit and pending bit */
1250 if(((hrtc->Instance->TAFCR & RTC_TAFCR_TAMPIE)) != (uint32_t)RESET)
1252 /* Tamper callback */
1253 HAL_RTCEx_Tamper2EventCallback(hrtc);
1255 /* Clear the Tamper interrupt pending bit */
1256 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP2F);
1260 /* Get the status of the Interrupt */
1261 if(__HAL_RTC_TAMPER_GET_IT(hrtc, RTC_IT_TAMP3))
1263 /* Get the TAMPER Interrupt enable bit and pending bit */
1264 if(((hrtc->Instance->TAFCR & RTC_TAFCR_TAMPIE)) != (uint32_t)RESET)
1266 /* Tamper callback */
1267 HAL_RTCEx_Tamper3EventCallback(hrtc);
1269 /* Clear the Tamper interrupt pending bit */
1270 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP3F);
1273 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
1275 /* Clear the EXTI s Flag for RTC TimeStamp and Tamper */
1276 __HAL_RTC_CLEAR_FLAG(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT);
1278 /* Change RTC state */
1279 hrtc->State = HAL_RTC_STATE_READY;
1283 * @brief TimeStamp callback.
1284 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1285 * the configuration information for RTC.
1288 __weak void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc)
1290 /* NOTE : This function Should not be modified, when the callback is needed,
1291 the HAL_RTCEx_TimeStampEventCallback could be implemented in the user file
1296 * @brief Tamper 1 callback.
1297 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1298 * the configuration information for RTC.
1301 __weak void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc)
1303 /* NOTE : This function Should not be modified, when the callback is needed,
1304 the HAL_RTCEx_Tamper1EventCallback could be implemented in the user file
1308 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
1310 * @brief Tamper 2 callback.
1311 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1312 * the configuration information for RTC.
1315 __weak void HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef *hrtc)
1317 /* NOTE : This function Should not be modified, when the callback is needed,
1318 the HAL_RTCEx_Tamper2EventCallback could be implemented in the user file
1323 * @brief Tamper 3 callback.
1324 * @param hrtc: RTC handle
1327 __weak void HAL_RTCEx_Tamper3EventCallback(RTC_HandleTypeDef *hrtc)
1329 /* NOTE : This function Should not be modified, when the callback is needed,
1330 the HAL_RTCEx_Tamper3EventCallback could be implemented in the user file
1333 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
1336 * @brief This function handles TimeStamp polling request.
1337 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1338 * the configuration information for RTC.
1339 * @param Timeout: Timeout duration
1340 * @retval HAL status
1342 HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
1344 uint32_t tickstart = HAL_GetTick();
1346 while(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) == RESET)
1348 if(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSOVF) != RESET)
1350 /* Clear the TIMESTAMP OverRun Flag */
1351 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSOVF);
1353 /* Change TIMESTAMP state */
1354 hrtc->State = HAL_RTC_STATE_ERROR;
1359 if(Timeout != HAL_MAX_DELAY)
1361 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
1363 hrtc->State = HAL_RTC_STATE_TIMEOUT;
1369 /* Change RTC state */
1370 hrtc->State = HAL_RTC_STATE_READY;
1376 * @brief This function handles Tamper1 Polling.
1377 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1378 * the configuration information for RTC.
1379 * @param Timeout: Timeout duration
1380 * @retval HAL status
1382 HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
1384 uint32_t tickstart = HAL_GetTick();
1386 /* Get the status of the Interrupt */
1387 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc,RTC_FLAG_TAMP1F)== RESET)
1389 if(Timeout != HAL_MAX_DELAY)
1391 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
1393 hrtc->State = HAL_RTC_STATE_TIMEOUT;
1399 /* Clear the Tamper Flag */
1400 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP1F);
1402 /* Change RTC state */
1403 hrtc->State = HAL_RTC_STATE_READY;
1408 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
1410 * @brief This function handles Tamper2 Polling.
1411 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1412 * the configuration information for RTC.
1413 * @param Timeout: Timeout duration
1414 * @retval HAL status
1416 HAL_StatusTypeDef HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
1418 uint32_t tickstart = HAL_GetTick();
1420 /* Get the status of the Interrupt */
1421 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc,RTC_FLAG_TAMP2F) == RESET)
1423 if(Timeout != HAL_MAX_DELAY)
1425 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
1427 hrtc->State = HAL_RTC_STATE_TIMEOUT;
1433 /* Clear the Tamper Flag */
1434 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP2F);
1436 /* Change RTC state */
1437 hrtc->State = HAL_RTC_STATE_READY;
1443 * @brief This function handles Tamper3 Polling.
1444 * @param hrtc: RTC handle
1445 * @param Timeout: Timeout duration
1446 * @retval HAL status
1448 HAL_StatusTypeDef HAL_RTCEx_PollForTamper3Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
1450 uint32_t tickstart = HAL_GetTick();
1452 /* Get the status of the Interrupt */
1453 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc,RTC_FLAG_TAMP3F) == RESET)
1455 if(Timeout != HAL_MAX_DELAY)
1457 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
1459 hrtc->State = HAL_RTC_STATE_TIMEOUT;
1465 /* Clear the Tamper Flag */
1466 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP3F);
1468 /* Change RTC state */
1469 hrtc->State = HAL_RTC_STATE_READY;
1473 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
1479 /** @defgroup RTCEx_Exported_Functions_Group5 RTC Wake-up functions
1480 * @brief RTC Wake-up functions
1483 ===============================================================================
1484 ##### RTC Wake-up functions #####
1485 ===============================================================================
1487 [..] This section provides functions allowing to configure Wake-up feature
1494 * @brief Sets wake up timer.
1495 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1496 * the configuration information for RTC.
1497 * @param WakeUpCounter: Wake up counter
1498 * @param WakeUpClock: Wake up clock
1499 * @retval HAL status
1501 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
1503 uint32_t tickstart = 0;
1505 /* Check the parameters */
1506 assert_param(IS_WAKEUP_CLOCK(WakeUpClock));
1507 assert_param(IS_WAKEUP_COUNTER(WakeUpCounter));
1509 /* Process Locked */
1512 hrtc->State = HAL_RTC_STATE_BUSY;
1514 /* Disable the write protection for RTC registers */
1515 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
1517 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
1519 tickstart = HAL_GetTick();
1521 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
1522 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
1524 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
1526 /* Enable the write protection for RTC registers */
1527 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1529 hrtc->State = HAL_RTC_STATE_TIMEOUT;
1531 /* Process Unlocked */
1538 /* Clear the Wakeup Timer clock source bits in CR register */
1539 hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL;
1541 /* Configure the clock source */
1542 hrtc->Instance->CR |= (uint32_t)WakeUpClock;
1544 /* Configure the Wakeup Timer counter */
1545 hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
1547 /* Enable the Wakeup Timer */
1548 __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc);
1550 /* Enable the write protection for RTC registers */
1551 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1553 hrtc->State = HAL_RTC_STATE_READY;
1555 /* Process Unlocked */
1562 * @brief Sets wake up timer with interrupt
1563 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1564 * the configuration information for RTC.
1565 * @param WakeUpCounter: Wake up counter
1566 * @param WakeUpClock: Wake up clock
1567 * @retval HAL status
1569 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
1571 uint32_t tickstart = 0;
1573 /* Check the parameters */
1574 assert_param(IS_WAKEUP_CLOCK(WakeUpClock));
1575 assert_param(IS_WAKEUP_COUNTER(WakeUpCounter));
1577 /* Process Locked */
1580 hrtc->State = HAL_RTC_STATE_BUSY;
1582 /* Disable the write protection for RTC registers */
1583 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
1585 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
1587 tickstart = HAL_GetTick();
1589 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
1590 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
1592 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
1594 /* Enable the write protection for RTC registers */
1595 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1597 hrtc->State = HAL_RTC_STATE_TIMEOUT;
1599 /* Process Unlocked */
1606 /* Configure the Wakeup Timer counter */
1607 hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
1609 /* Clear the Wakeup Timer clock source bits in CR register */
1610 hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL;
1612 /* Configure the clock source */
1613 hrtc->Instance->CR |= (uint32_t)WakeUpClock;
1615 /* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */
1616 __HAL_RTC_ENABLE_IT(RTC_EXTI_LINE_WAKEUPTIMER_EVENT);
1618 EXTI->RTSR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT;
1620 /* Configure the Interrupt in the RTC_CR register */
1621 __HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc,RTC_IT_WUT);
1623 /* Enable the Wakeup Timer */
1624 __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc);
1626 /* Enable the write protection for RTC registers */
1627 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1629 hrtc->State = HAL_RTC_STATE_READY;
1631 /* Process Unlocked */
1638 * @brief Deactivates wake up timer counter.
1639 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1640 * the configuration information for RTC.
1641 * @retval HAL status
1643 uint32_t HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc)
1645 uint32_t tickstart = 0;
1647 /* Process Locked */
1650 hrtc->State = HAL_RTC_STATE_BUSY;
1652 /* Disable the write protection for RTC registers */
1653 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
1655 /* Disable the Wakeup Timer */
1656 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
1658 /* In case of interrupt mode is used, the interrupt source must disabled */
1659 __HAL_RTC_WAKEUPTIMER_DISABLE_IT(hrtc,RTC_IT_WUT);
1661 tickstart = HAL_GetTick();
1662 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
1663 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
1665 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
1667 /* Enable the write protection for RTC registers */
1668 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1670 hrtc->State = HAL_RTC_STATE_TIMEOUT;
1672 /* Process Unlocked */
1679 /* Enable the write protection for RTC registers */
1680 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1682 hrtc->State = HAL_RTC_STATE_READY;
1684 /* Process Unlocked */
1691 * @brief Gets wake up timer counter.
1692 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1693 * the configuration information for RTC.
1694 * @retval Counter value
1696 uint32_t HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc)
1698 /* Get the counter value */
1699 return ((uint32_t)(hrtc->Instance->WUTR & RTC_WUTR_WUT));
1703 * @brief This function handles Wake Up Timer interrupt request.
1704 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1705 * the configuration information for RTC.
1708 void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc)
1710 if(__HAL_RTC_WAKEUPTIMER_GET_IT(hrtc, RTC_IT_WUT))
1712 /* Get the status of the Interrupt */
1713 if((uint32_t)(hrtc->Instance->CR & RTC_IT_WUT) != (uint32_t)RESET)
1715 /* WAKEUPTIMER callback */
1716 HAL_RTCEx_WakeUpTimerEventCallback(hrtc);
1718 /* Clear the WAKEUPTIMER interrupt pending bit */
1719 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
1723 /* Clear the EXTI s line Flag for RTC WakeUpTimer */
1724 __HAL_RTC_CLEAR_FLAG(RTC_EXTI_LINE_WAKEUPTIMER_EVENT);
1726 /* Change RTC state */
1727 hrtc->State = HAL_RTC_STATE_READY;
1731 * @brief Wake Up Timer callback.
1732 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1733 * the configuration information for RTC.
1736 __weak void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
1738 /* NOTE : This function Should not be modified, when the callback is needed,
1739 the HAL_RTCEx_WakeUpTimerEventCallback could be implemented in the user file
1744 * @brief This function handles Wake Up Timer Polling.
1745 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1746 * the configuration information for RTC.
1747 * @param Timeout: Timeout duration
1748 * @retval HAL status
1750 HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
1752 uint32_t tickstart = HAL_GetTick();
1754 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) == RESET)
1756 if(Timeout != HAL_MAX_DELAY)
1758 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
1760 hrtc->State = HAL_RTC_STATE_TIMEOUT;
1767 /* Clear the WAKEUPTIMER Flag */
1768 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
1770 /* Change RTC state */
1771 hrtc->State = HAL_RTC_STATE_READY;
1780 /** @defgroup RTCEx_Exported_Functions_Group7 Extended Peripheral Control functions
1781 * @brief Extended Peripheral Control functions
1784 ===============================================================================
1785 ##### Extension Peripheral Control functions #####
1786 ===============================================================================
1788 This subsection provides functions allowing to
1789 (+) Writes a data in a specified RTC Backup data register
1790 (+) Read a data in a specified RTC Backup data register
1791 (+) Sets the Coarse calibration parameters.
1792 (+) Deactivates the Coarse calibration parameters
1793 (+) Sets the Smooth calibration parameters.
1794 (+) Configures the Synchronization Shift Control Settings.
1795 (+) Configures the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
1796 (+) Deactivates the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
1797 (+) Enables the RTC reference clock detection.
1798 (+) Disable the RTC reference clock detection.
1799 (+) Enables the Bypass Shadow feature.
1800 (+) Disables the Bypass Shadow feature.
1807 * @brief Writes a data in a specified RTC Backup data register.
1808 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1809 * the configuration information for RTC.
1810 * @param BackupRegister: RTC Backup data Register number.
1811 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to
1812 * specify the register.
1813 * @param Data: Data to be written in the specified RTC Backup data register.
1816 void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data)
1820 /* Check the parameters */
1821 assert_param(IS_RTC_BKP(BackupRegister));
1823 tmp = (uint32_t)&(hrtc->Instance->BKP0R);
1824 tmp += (BackupRegister * 4);
1826 /* Write the specified register */
1827 *(__IO uint32_t *)tmp = (uint32_t)Data;
1831 * @brief Reads data from the specified RTC Backup data Register.
1832 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1833 * the configuration information for RTC.
1834 * @param BackupRegister: RTC Backup data Register number.
1835 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to
1836 * specify the register.
1837 * @retval Read value
1839 uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister)
1843 /* Check the parameters */
1844 assert_param(IS_RTC_BKP(BackupRegister));
1846 tmp = (uint32_t)&(hrtc->Instance->BKP0R);
1847 tmp += (BackupRegister * 4);
1849 /* Read the specified register */
1850 return (*(__IO uint32_t *)tmp);
1854 * @brief Sets the Coarse calibration parameters.
1855 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1856 * the configuration information for RTC.
1857 * @param CalibSign: Specifies the sign of the coarse calibration value.
1858 * This parameter can be one of the following values :
1859 * @arg RTC_CALIBSIGN_POSITIVE: The value sign is positive
1860 * @arg RTC_CALIBSIGN_NEGATIVE: The value sign is negative
1861 * @param Value: value of coarse calibration expressed in ppm (coded on 5 bits).
1863 * @note This Calibration value should be between 0 and 63 when using negative
1864 * sign with a 2-ppm step.
1866 * @note This Calibration value should be between 0 and 126 when using positive
1867 * sign with a 4-ppm step.
1868 * @retval HAL status
1870 HAL_StatusTypeDef HAL_RTCEx_SetCoarseCalib(RTC_HandleTypeDef* hrtc, uint32_t CalibSign, uint32_t Value)
1872 /* Check the parameters */
1873 assert_param(IS_RTC_CALIB_SIGN(CalibSign));
1874 assert_param(IS_RTC_CALIB_VALUE(Value));
1876 /* Process Locked */
1879 hrtc->State = HAL_RTC_STATE_BUSY;
1881 /* Disable the write protection for RTC registers */
1882 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
1884 /* Set Initialization mode */
1885 if(RTC_EnterInitMode(hrtc) != HAL_OK)
1887 /* Enable the write protection for RTC registers */
1888 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1891 hrtc->State = HAL_RTC_STATE_ERROR;
1893 /* Process Unlocked */
1900 /* Enable the Coarse Calibration */
1901 __HAL_RTC_COARSE_CALIB_ENABLE(hrtc);
1903 /* Set the coarse calibration value */
1904 hrtc->Instance->CALIBR = (uint32_t)(CalibSign|Value);
1906 /* Exit Initialization mode */
1907 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
1910 /* Enable the write protection for RTC registers */
1911 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1914 hrtc->State = HAL_RTC_STATE_READY;
1916 /* Process Unlocked */
1923 * @brief Deactivates the Coarse calibration parameters.
1924 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1925 * the configuration information for RTC.
1926 * @retval HAL status
1928 HAL_StatusTypeDef HAL_RTCEx_DeactivateCoarseCalib(RTC_HandleTypeDef* hrtc)
1930 /* Process Locked */
1933 hrtc->State = HAL_RTC_STATE_BUSY;
1935 /* Disable the write protection for RTC registers */
1936 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
1938 /* Set Initialization mode */
1939 if(RTC_EnterInitMode(hrtc) != HAL_OK)
1941 /* Enable the write protection for RTC registers */
1942 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1945 hrtc->State = HAL_RTC_STATE_ERROR;
1947 /* Process Unlocked */
1954 /* Enable the Coarse Calibration */
1955 __HAL_RTC_COARSE_CALIB_DISABLE(hrtc);
1957 /* Exit Initialization mode */
1958 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
1961 /* Enable the write protection for RTC registers */
1962 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1965 hrtc->State = HAL_RTC_STATE_READY;
1967 /* Process Unlocked */
1973 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
1975 * @brief Sets the Smooth calibration parameters.
1976 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1977 * the configuration information for RTC.
1978 * @param SmoothCalibPeriod: Select the Smooth Calibration Period.
1979 * This parameter can be can be one of the following values :
1980 * @arg RTC_SMOOTHCALIB_PERIOD_32SEC: The smooth calibration periode is 32s.
1981 * @arg RTC_SMOOTHCALIB_PERIOD_16SEC: The smooth calibration periode is 16s.
1982 * @arg RTC_SMOOTHCALIB_PERIOD_8SEC: The smooth calibartion periode is 8s.
1983 * @param SmoothCalibPlusPulses: Select to Set or reset the CALP bit.
1984 * This parameter can be one of the following values:
1985 * @arg RTC_SMOOTHCALIB_PLUSPULSES_SET: Add one RTCCLK puls every 2*11 pulses.
1986 * @arg RTC_SMOOTHCALIB_PLUSPULSES_RESET: No RTCCLK pulses are added.
1987 * @param SmouthCalibMinusPulsesValue: Select the value of CALM[8:0] bits.
1988 * This parameter can be one any value from 0 to 0x000001FF.
1989 * @note To deactivate the smooth calibration, the field SmoothCalibPlusPulses
1990 * must be equal to SMOOTHCALIB_PLUSPULSES_RESET and the field
1991 * SmouthCalibMinusPulsesValue must be equal to 0.
1992 * @retval HAL status
1994 HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef* hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmouthCalibMinusPulsesValue)
1996 uint32_t tickstart = 0;
1998 /* Check the parameters */
1999 assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(SmoothCalibPeriod));
2000 assert_param(IS_RTC_SMOOTH_CALIB_PLUS(SmoothCalibPlusPulses));
2001 assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmouthCalibMinusPulsesValue));
2003 /* Process Locked */
2006 hrtc->State = HAL_RTC_STATE_BUSY;
2008 /* Disable the write protection for RTC registers */
2009 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
2011 /* check if a calibration is pending*/
2012 if((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET)
2014 tickstart = HAL_GetTick();
2016 /* check if a calibration is pending*/
2017 while((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET)
2019 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
2021 /* Enable the write protection for RTC registers */
2022 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
2024 /* Change RTC state */
2025 hrtc->State = HAL_RTC_STATE_TIMEOUT;
2027 /* Process Unlocked */
2035 /* Configure the Smooth calibration settings */
2036 hrtc->Instance->CALR = (uint32_t)((uint32_t)SmoothCalibPeriod | (uint32_t)SmoothCalibPlusPulses | (uint32_t)SmouthCalibMinusPulsesValue);
2038 /* Enable the write protection for RTC registers */
2039 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
2041 /* Change RTC state */
2042 hrtc->State = HAL_RTC_STATE_READY;
2044 /* Process Unlocked */
2051 * @brief Configures the Synchronization Shift Control Settings.
2052 * @note When REFCKON is set, firmware must not write to Shift control register.
2053 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
2054 * the configuration information for RTC.
2055 * @param ShiftAdd1S: Select to add or not 1 second to the time calendar.
2056 * This parameter can be one of the following values :
2057 * @arg RTC_SHIFTADD1S_SET: Add one second to the clock calendar.
2058 * @arg RTC_SHIFTADD1S_RESET: No effect.
2059 * @param ShiftSubFS: Select the number of Second Fractions to substitute.
2060 * This parameter can be one any value from 0 to 0x7FFF.
2061 * @retval HAL status
2063 HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef* hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS)
2065 uint32_t tickstart = 0;
2067 /* Check the parameters */
2068 assert_param(IS_RTC_SHIFT_ADD1S(ShiftAdd1S));
2069 assert_param(IS_RTC_SHIFT_SUBFS(ShiftSubFS));
2071 /* Process Locked */
2074 hrtc->State = HAL_RTC_STATE_BUSY;
2076 /* Disable the write protection for RTC registers */
2077 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
2079 tickstart = HAL_GetTick();
2081 /* Wait until the shift is completed*/
2082 while((hrtc->Instance->ISR & RTC_ISR_SHPF) != RESET)
2084 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
2086 /* Enable the write protection for RTC registers */
2087 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
2089 hrtc->State = HAL_RTC_STATE_TIMEOUT;
2091 /* Process Unlocked */
2098 /* Check if the reference clock detection is disabled */
2099 if((hrtc->Instance->CR & RTC_CR_REFCKON) == RESET)
2101 /* Configure the Shift settings */
2102 hrtc->Instance->SHIFTR = (uint32_t)(uint32_t)(ShiftSubFS) | (uint32_t)(ShiftAdd1S);
2104 /* Wait for synchro */
2105 if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
2107 /* Enable the write protection for RTC registers */
2108 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
2110 hrtc->State = HAL_RTC_STATE_ERROR;
2112 /* Process Unlocked */
2120 /* Enable the write protection for RTC registers */
2121 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
2123 /* Change RTC state */
2124 hrtc->State = HAL_RTC_STATE_ERROR;
2126 /* Process Unlocked */
2132 /* Enable the write protection for RTC registers */
2133 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
2135 /* Change RTC state */
2136 hrtc->State = HAL_RTC_STATE_READY;
2138 /* Process Unlocked */
2143 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
2146 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
2148 * @brief Configures the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
2149 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
2150 * the configuration information for RTC.
2151 * @param CalibOutput : Select the Calibration output Selection .
2152 * This parameter can be one of the following values:
2153 * @arg RTC_CALIBOUTPUT_512HZ: A signal has a regular waveform at 512Hz.
2154 * @arg RTC_CALIBOUTPUT_1HZ: A signal has a regular waveform at 1Hz.
2155 * @retval HAL status
2157 HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef* hrtc, uint32_t CalibOutput)
2160 * @brief Configure the Calibration Pinout (RTC_CALIB).
2161 * @param hrtc : RTC handle
2162 * @retval HAL status
2164 HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef* hrtc)
2165 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
2167 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
2168 /* Check the parameters */
2169 assert_param(IS_RTC_CALIB_OUTPUT(CalibOutput));
2170 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
2172 /* Process Locked */
2175 hrtc->State = HAL_RTC_STATE_BUSY;
2177 /* Disable the write protection for RTC registers */
2178 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
2180 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
2181 /* Clear flags before config */
2182 hrtc->Instance->CR &= (uint32_t)~RTC_CR_COSEL;
2184 /* Configure the RTC_CR register */
2185 hrtc->Instance->CR |= (uint32_t)CalibOutput;
2186 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
2188 __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(hrtc);
2190 /* Enable the write protection for RTC registers */
2191 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
2193 /* Change RTC state */
2194 hrtc->State = HAL_RTC_STATE_READY;
2196 /* Process Unlocked */
2203 * @brief Deactivates the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
2204 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
2205 * the configuration information for RTC.
2206 * @retval HAL status
2208 HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef* hrtc)
2210 /* Process Locked */
2213 hrtc->State = HAL_RTC_STATE_BUSY;
2215 /* Disable the write protection for RTC registers */
2216 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
2218 __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(hrtc);
2220 /* Enable the write protection for RTC registers */
2221 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
2223 /* Change RTC state */
2224 hrtc->State = HAL_RTC_STATE_READY;
2226 /* Process Unlocked */
2233 * @brief Enables the RTC reference clock detection.
2234 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
2235 * the configuration information for RTC.
2236 * @retval HAL status
2238 HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef* hrtc)
2240 /* Process Locked */
2243 hrtc->State = HAL_RTC_STATE_BUSY;
2245 /* Disable the write protection for RTC registers */
2246 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
2248 /* Set Initialization mode */
2249 if(RTC_EnterInitMode(hrtc) != HAL_OK)
2251 /* Enable the write protection for RTC registers */
2252 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
2255 hrtc->State = HAL_RTC_STATE_ERROR;
2257 /* Process Unlocked */
2264 __HAL_RTC_CLOCKREF_DETECTION_ENABLE(hrtc);
2266 /* Exit Initialization mode */
2267 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
2270 /* Enable the write protection for RTC registers */
2271 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
2273 /* Change RTC state */
2274 hrtc->State = HAL_RTC_STATE_READY;
2276 /* Process Unlocked */
2283 * @brief Disable the RTC reference clock detection.
2284 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
2285 * the configuration information for RTC.
2286 * @retval HAL status
2288 HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef* hrtc)
2290 /* Process Locked */
2293 hrtc->State = HAL_RTC_STATE_BUSY;
2295 /* Disable the write protection for RTC registers */
2296 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
2298 /* Set Initialization mode */
2299 if(RTC_EnterInitMode(hrtc) != HAL_OK)
2301 /* Enable the write protection for RTC registers */
2302 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
2305 hrtc->State = HAL_RTC_STATE_ERROR;
2307 /* Process Unlocked */
2314 __HAL_RTC_CLOCKREF_DETECTION_DISABLE(hrtc);
2316 /* Exit Initialization mode */
2317 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
2320 /* Enable the write protection for RTC registers */
2321 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
2323 /* Change RTC state */
2324 hrtc->State = HAL_RTC_STATE_READY;
2326 /* Process Unlocked */
2332 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined (STM32L152xE) || defined (STM32L162xE)
2334 * @brief Enables the Bypass Shadow feature.
2335 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
2336 * the configuration information for RTC.
2337 * @note When the Bypass Shadow is enabled the calendar value are taken
2338 * directly from the Calendar counter.
2339 * @retval HAL status
2341 HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef* hrtc)
2343 /* Process Locked */
2346 hrtc->State = HAL_RTC_STATE_BUSY;
2348 /* Disable the write protection for RTC registers */
2349 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
2351 /* Set the BYPSHAD bit */
2352 hrtc->Instance->CR |= (uint8_t)RTC_CR_BYPSHAD;
2354 /* Enable the write protection for RTC registers */
2355 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
2357 /* Change RTC state */
2358 hrtc->State = HAL_RTC_STATE_READY;
2360 /* Process Unlocked */
2367 * @brief Disables the Bypass Shadow feature.
2368 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
2369 * the configuration information for RTC.
2370 * @note When the Bypass Shadow is enabled the calendar value are taken
2371 * directly from the Calendar counter.
2372 * @retval HAL status
2374 HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef* hrtc)
2376 /* Process Locked */
2379 hrtc->State = HAL_RTC_STATE_BUSY;
2381 /* Disable the write protection for RTC registers */
2382 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
2384 /* Reset the BYPSHAD bit */
2385 hrtc->Instance->CR &= (uint8_t)~RTC_CR_BYPSHAD;
2387 /* Enable the write protection for RTC registers */
2388 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
2390 /* Change RTC state */
2391 hrtc->State = HAL_RTC_STATE_READY;
2393 /* Process Unlocked */
2398 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */
2404 /** @defgroup RTCEx_Exported_Functions_Group8 Extended features functions
2405 * @brief Extended features functions
2408 ===============================================================================
2409 ##### Extended features functions #####
2410 ===============================================================================
2411 [..] This section provides functions allowing to:
2412 (+) RTC Alram B callback
2413 (+) RTC Poll for Alarm B request
2420 * @brief Alarm B callback.
2421 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
2422 * the configuration information for RTC.
2425 __weak void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc)
2427 /* NOTE : This function Should not be modified, when the callback is needed,
2428 the HAL_RTCEx_AlarmBEventCallback could be implemented in the user file
2433 * @brief This function handles AlarmB Polling request.
2434 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
2435 * the configuration information for RTC.
2436 * @param Timeout: Timeout duration
2437 * @retval HAL status
2439 HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
2441 uint32_t tickstart = HAL_GetTick();
2443 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBF) == RESET)
2445 if(Timeout != HAL_MAX_DELAY)
2447 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
2449 hrtc->State = HAL_RTC_STATE_TIMEOUT;
2455 /* Clear the Alarm Flag */
2456 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF);
2458 /* Change RTC state */
2459 hrtc->State = HAL_RTC_STATE_READY;
2476 #endif /* HAL_RTC_MODULE_ENABLED */
2482 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/