1 /**
2   ******************************************************************************
3   * @file    stm32l1xx_hal_rtc_ex.h
4   * @author  MCD Application Team
5   * @version V1.2.0
6   * @date    01-July-2016
7   * @brief   Header file of RTC HAL Extension module.
8   ******************************************************************************
9   * @attention
10   *
11   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
12   *
13   * Redistribution and use in source and binary forms, with or without modification,
14   * are permitted provided that the following conditions are met:
15   *   1. Redistributions of source code must retain the above copyright notice,
16   *      this list of conditions and the following disclaimer.
17   *   2. Redistributions in binary form must reproduce the above copyright notice,
18   *      this list of conditions and the following disclaimer in the documentation
19   *      and/or other materials provided with the distribution.
20   *   3. Neither the name of STMicroelectronics nor the names of its contributors
21   *      may be used to endorse or promote products derived from this software
22   *      without specific prior written permission.
23   *
24   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34   *
35   ******************************************************************************
36   */
37 
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32L1xx_HAL_RTC_EX_H
40 #define __STM32L1xx_HAL_RTC_EX_H
41 
42 #ifdef __cplusplus
43  extern "C" {
44 #endif
45 
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32l1xx_hal_def.h"
48 
49 /** @addtogroup STM32L1xx_HAL_Driver
50   * @{
51   */
52 
53 /** @addtogroup RTCEx
54   * @{
55   */
56 
57 /* Exported types ------------------------------------------------------------*/
58 /** @defgroup RTCEx_Exported_Types RTCEx Exported Types
59   * @{
60   */
61 
62 /**
63   * @brief  RTC Tamper structure definition
64   */
65 typedef struct
66 {
67   uint32_t Tamper;                      /*!< Specifies the Tamper Pin.
68                                              This parameter can be a value of @ref  RTCEx_Tamper_Pins_Definitions */
69 
70   uint32_t Trigger;                     /*!< Specifies the Tamper Trigger.
71                                              This parameter can be a value of @ref  RTCEx_Tamper_Trigger_Definitions */
72 
73 #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(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
74   uint32_t Filter;                      /*!< Specifies the RTC Filter Tamper.
75                                              This parameter can be a value of @ref RTCEx_Tamper_Filter_Definitions */
76 
77   uint32_t SamplingFrequency;           /*!< Specifies the sampling frequency.
78                                              This parameter can be a value of @ref RTCEx_Tamper_Sampling_Frequencies_Definitions */
79 
80   uint32_t PrechargeDuration;           /*!< Specifies the Precharge Duration .
81                                              This parameter can be a value of @ref RTCEx_Tamper_Pin_Precharge_Duration_Definitions */
82 
83   uint32_t TamperPullUp;                /*!< Specifies the Tamper PullUp .
84                                              This parameter can be a value of @ref RTCEx_Tamper_Pull_Up_Definitions */
85 
86   uint32_t TimeStampOnTamperDetection;  /*!< Specifies the TimeStampOnTamperDetection.
87                                              This parameter can be a value of @ref RTCEx_Tamper_TimeStampOnTamperDetection_Definitions */
88 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
89 }RTC_TamperTypeDef;
90 
91 /**
92   * @brief  RTC Time structure definition
93   */
94 typedef struct
95 {
96   uint8_t Hours;            /*!< Specifies the RTC Time Hour.
97                                  This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected
98                                  This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected  */
99 
100   uint8_t Minutes;          /*!< Specifies the RTC Time Minutes.
101                                  This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
102 
103   uint8_t Seconds;          /*!< Specifies the RTC Time Seconds.
104                                  This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
105 
106   uint8_t TimeFormat;       /*!< Specifies the RTC AM/PM Time.
107                                  This parameter can be a value of @ref RTC_AM_PM_Definitions */
108 
109 #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(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
110   uint32_t SubSeconds;     /*!< Specifies the RTC_SSR RTC Sub Second register content.
111                                  This parameter corresponds to a time unit range between [0-1] Second
112                                  with [1 Sec / SecondFraction +1] granularity */
113 
114   uint32_t SecondFraction;  /*!< Specifies the range or granularity of Sub Second register content
115                                  corresponding to Synchronous pre-scaler factor value (PREDIV_S)
116                                  This parameter corresponds to a time unit range between [0-1] Second
117                                  with [1 Sec / SecondFraction +1] granularity.
118                                  This field will be used only by HAL_RTC_GetTime function */
119 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
120 
121   uint32_t DayLightSaving;  /*!< Specifies RTC_DayLightSaveOperation: the value of hour adjustment.
122                                  This parameter can be a value of @ref RTC_DayLightSaving_Definitions */
123 
124   uint32_t StoreOperation;  /*!< Specifies RTC_StoreOperation value to be written in the BCK bit
125                                  in CR register to store the operation.
126                                  This parameter can be a value of @ref RTC_StoreOperation_Definitions */
127 }RTC_TimeTypeDef;
128 
129 /**
130   * @brief  RTC Alarm structure definition
131   */
132 typedef struct
133 {
134   RTC_TimeTypeDef AlarmTime;     /*!< Specifies the RTC Alarm Time members */
135 
136   uint32_t AlarmMask;            /*!< Specifies the RTC Alarm Masks.
137                                       This parameter can be a value of @ref RTC_AlarmMask_Definitions */
138 
139 #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(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
140   uint32_t AlarmSubSecondMask;   /*!< Specifies the RTC Alarm SubSeconds Masks.
141                                       This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */
142 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
143 
144   uint32_t AlarmDateWeekDaySel;  /*!< Specifies the RTC Alarm is on Date or WeekDay.
145                                       This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */
146 
147   uint8_t AlarmDateWeekDay;      /*!< Specifies the RTC Alarm Date/WeekDay.
148                                       If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range.
149                                       If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */
150 
151   uint32_t Alarm;                /*!< Specifies the alarm .
152                                       This parameter can be a value of @ref RTC_Alarms_Definitions */
153 }RTC_AlarmTypeDef;
154 /**
155   * @}
156   */
157 
158 /* Exported constants --------------------------------------------------------*/
159 /** @defgroup RTCEx_Exported_Constants RTCEx Exported Constants
160   * @{
161   */
162 
163 /** @defgroup RTC_Masks_Definitions Masks Definitions
164   * @{
165   */
166 #define RTC_TR_RESERVED_MASK    (0x007F7F7FU)
167 #define RTC_DR_RESERVED_MASK    (0x00FFFF3FU)
168 #define RTC_INIT_MASK           ((uint32_t)0xFFFFFFFFU)
169 #define RTC_RSF_MASK            ((uint32_t)0xFFFFFF5FU)
170 
171 #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(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
172 #define RTC_FLAGS_MASK          ((uint32_t)(RTC_FLAG_ALRAWF | RTC_FLAG_ALRBWF | RTC_FLAG_WUTWF | \
173                                             RTC_FLAG_SHPF | RTC_FLAG_INITS | RTC_FLAG_RSF | \
174                                             RTC_FLAG_INITF | RTC_FLAG_ALRAF | RTC_FLAG_ALRBF | \
175                                             RTC_FLAG_WUTF | RTC_FLAG_TSF | RTC_FLAG_TSOVF | \
176                                             RTC_FLAG_TAMP1F | RTC_FLAG_TAMP2F | RTC_FLAG_TAMP3F | \
177                                             RTC_FLAG_RECALPF))
178 #else
179 #define RTC_FLAGS_MASK          ((uint32_t)(RTC_FLAG_ALRAWF | RTC_FLAG_ALRBWF | RTC_FLAG_WUTWF | \
180                                             RTC_FLAG_SHPF | RTC_FLAG_INITS | RTC_FLAG_RSF | \
181                                             RTC_FLAG_INITF | RTC_FLAG_ALRAF | RTC_FLAG_ALRBF | \
182                                             RTC_FLAG_WUTF | RTC_FLAG_TSF | RTC_FLAG_TSOVF | \
183                                             RTC_FLAG_TAMP1F | \
184                                             RTC_FLAG_RECALPF))
185 
186 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
187 /**
188   * @}
189   */
190 
191 /** @defgroup RTC_Synchronous_Predivider Synchronous Predivider
192   * @{
193   */
194 #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(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
195 #define IS_RTC_SYNCH_PREDIV(PREDIV)    ((PREDIV) <= (uint32_t)0x7FFF)
196 #elif defined(STM32L100xB) || defined (STM32L151xB) || defined (STM32L152xB)
197 #define IS_RTC_SYNCH_PREDIV(PREDIV)    ((PREDIV) <= (uint32_t)0x1FFF)
198 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
199 /**
200   * @}
201   */
202 
203 /** @defgroup RTC_Interrupts_Definitions Interrupts Definitions
204   * @{
205   */
206 #define RTC_IT_TS                         ((uint32_t)RTC_CR_TSIE)
207 #define RTC_IT_WUT                        ((uint32_t)RTC_CR_WUTIE)
208 #define RTC_IT_ALRB                       ((uint32_t)RTC_CR_ALRBIE)
209 #define RTC_IT_ALRA                       ((uint32_t)RTC_CR_ALRAIE)
210 #define RTC_IT_TAMP1                      ((uint32_t)(RTC_TAFCR_TAMPIE | RTC_TAFCR_TAMP1E))
211 #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(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
212 #define RTC_IT_TAMP2                      ((uint32_t)(RTC_TAFCR_TAMPIE | RTC_TAFCR_TAMP2E))
213 #define RTC_IT_TAMP3                      ((uint32_t)(RTC_TAFCR_TAMPIE | RTC_TAFCR_TAMP3E))
214 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
215 /**
216   * @}
217   */
218 
219 /** @defgroup RTC_Flags_Definitions Flags Definitions
220   * @{
221   */
222 #define RTC_FLAG_RECALPF                  ((uint32_t)RTC_ISR_RECALPF)
223 #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(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
224 #define RTC_FLAG_TAMP3F                   ((uint32_t)RTC_ISR_TAMP3F)
225 #define RTC_FLAG_TAMP2F                   ((uint32_t)RTC_ISR_TAMP2F)
226 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
227 #define RTC_FLAG_TAMP1F                   ((uint32_t)RTC_ISR_TAMP1F)
228 #define RTC_FLAG_TSOVF                    ((uint32_t)RTC_ISR_TSOVF)
229 #define RTC_FLAG_TSF                      ((uint32_t)RTC_ISR_TSF)
230 #define RTC_FLAG_WUTF                     ((uint32_t)RTC_ISR_WUTF)
231 #define RTC_FLAG_ALRBF                    ((uint32_t)RTC_ISR_ALRBF)
232 #define RTC_FLAG_ALRAF                    ((uint32_t)RTC_ISR_ALRAF)
233 #define RTC_FLAG_INITF                    ((uint32_t)RTC_ISR_INITF)
234 #define RTC_FLAG_RSF                      ((uint32_t)RTC_ISR_RSF)
235 #define RTC_FLAG_INITS                    ((uint32_t)RTC_ISR_INITS)
236 #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(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
237 #define RTC_FLAG_SHPF                     ((uint32_t)RTC_ISR_SHPF)
238 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
239 #define RTC_FLAG_WUTWF                    ((uint32_t)RTC_ISR_WUTWF)
240 #define RTC_FLAG_ALRBWF                   ((uint32_t)RTC_ISR_ALRBWF)
241 #define RTC_FLAG_ALRAWF                   ((uint32_t)RTC_ISR_ALRAWF)
242 /**
243   * @}
244   */
245 
246 /** @defgroup RTCEx_Output_selection_Definitions Output selection Definitions
247   * @{
248   */
249 #define RTC_OUTPUT_DISABLE             (0x00000000U)
250 #define RTC_OUTPUT_ALARMA              (0x00200000U)
251 #define RTC_OUTPUT_ALARMB              (0x00400000U)
252 #define RTC_OUTPUT_WAKEUP              (0x00600000U)
253 
254 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \
255                                ((OUTPUT) == RTC_OUTPUT_ALARMA)  || \
256                                ((OUTPUT) == RTC_OUTPUT_ALARMB)  || \
257                                ((OUTPUT) == RTC_OUTPUT_WAKEUP))
258 /**
259   * @}
260   */
261 
262 /** @defgroup RTCEx_Backup_Registers_Definitions Backup Registers Definitions
263   * @{
264   */
265 #if RTC_BKP_NUMBER > 0
266 #define RTC_BKP_DR0                       (0x00000000U)
267 #define RTC_BKP_DR1                       (0x00000001U)
268 #define RTC_BKP_DR2                       (0x00000002U)
269 #define RTC_BKP_DR3                       (0x00000003U)
270 #define RTC_BKP_DR4                       (0x00000004U)
271 #endif /* RTC_BKP_NUMBER > 0 */
272 
273 #if RTC_BKP_NUMBER > 5
274 #define RTC_BKP_DR5                       (0x00000005U)
275 #define RTC_BKP_DR6                       (0x00000006U)
276 #define RTC_BKP_DR7                       (0x00000007U)
277 #define RTC_BKP_DR8                       (0x00000008U)
278 #define RTC_BKP_DR9                       (0x00000009U)
279 #define RTC_BKP_DR10                      (0x0000000AU)
280 #define RTC_BKP_DR11                      (0x0000000BU)
281 #define RTC_BKP_DR12                      (0x0000000CU)
282 #define RTC_BKP_DR13                      (0x0000000DU)
283 #define RTC_BKP_DR14                      (0x0000000EU)
284 #define RTC_BKP_DR15                      (0x0000000FU)
285 #define RTC_BKP_DR16                      (0x00000010U)
286 #define RTC_BKP_DR17                      (0x00000011U)
287 #define RTC_BKP_DR18                      (0x00000012U)
288 #define RTC_BKP_DR19                      (0x00000013U)
289 #endif /* RTC_BKP_NUMBER > 5 */
290 
291 #if RTC_BKP_NUMBER > 20
292 #define RTC_BKP_DR20                      (0x00000014U)
293 #define RTC_BKP_DR21                      (0x00000015U)
294 #define RTC_BKP_DR22                      (0x00000016U)
295 #define RTC_BKP_DR23                      (0x00000017U)
296 #define RTC_BKP_DR24                      (0x00000018U)
297 #define RTC_BKP_DR25                      (0x00000019U)
298 #define RTC_BKP_DR26                      (0x0000001AU)
299 #define RTC_BKP_DR27                      (0x0000001BU)
300 #define RTC_BKP_DR28                      (0x0000001CU)
301 #define RTC_BKP_DR29                      (0x0000001DU)
302 #define RTC_BKP_DR30                      (0x0000001EU)
303 #define RTC_BKP_DR31                      (0x0000001FU)
304 #endif /* RTC_BKP_NUMBER > 20 */
305 
306 #define IS_RTC_BKP(BKP)                   ((BKP) < (uint32_t) RTC_BKP_NUMBER)
307 /**
308   * @}
309   */
310 
311 /** @defgroup RTCEx_Time_Stamp_Edges_Definitions Time Stamp Edges Definitions
312   * @{
313   */
314 #define RTC_TIMESTAMPEDGE_RISING          (0x00000000U)
315 #define RTC_TIMESTAMPEDGE_FALLING         (0x00000008U)
316 
317 #define IS_TIMESTAMP_EDGE(EDGE) (((EDGE) == RTC_TIMESTAMPEDGE_RISING) || \
318                                  ((EDGE) == RTC_TIMESTAMPEDGE_FALLING))
319 /**
320   * @}
321   */
322 
323 /** @defgroup RTCEx_Tamper_Pins_Definitions Tamper Pins Definitions
324   * @{
325   */
326 #define RTC_TAMPER_1                    RTC_TAFCR_TAMP1E
327 #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(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
328 #define RTC_TAMPER_2                    RTC_TAFCR_TAMP2E
329 #define RTC_TAMPER_3                    RTC_TAFCR_TAMP3E
330 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
331 
332 #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(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
333 #define IS_RTC_TAMPER(TAMPER) (((~(RTC_TAMPER_1|RTC_TAMPER_2|RTC_TAMPER_3) & (TAMPER)) == (uint32_t)RESET) && ((TAMPER) != (uint32_t)RESET))
334 #else
335 #define IS_RTC_TAMPER(TAMPER) ((TAMPER) == RTC_TAMPER_1)
336 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
337 /**
338   * @}
339   */
340 
341 /** @defgroup RTCEx_Tamper_Trigger_Definitions Tamper Trigger Definitions
342   * @{
343   */
344 #define RTC_TAMPERTRIGGER_RISINGEDGE       (0x00000000U)
345 #define RTC_TAMPERTRIGGER_FALLINGEDGE      (0x00000002U)
346 #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(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
347 #define RTC_TAMPERTRIGGER_LOWLEVEL         RTC_TAMPERTRIGGER_RISINGEDGE
348 #define RTC_TAMPERTRIGGER_HIGHLEVEL        RTC_TAMPERTRIGGER_FALLINGEDGE
349 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
350 
351 #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(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
352 #define IS_RTC_TAMPER_TRIGGER(TRIGGER) (((TRIGGER) == RTC_TAMPERTRIGGER_RISINGEDGE) || \
353                                         ((TRIGGER) == RTC_TAMPERTRIGGER_FALLINGEDGE) || \
354                                         ((TRIGGER) == RTC_TAMPERTRIGGER_LOWLEVEL) || \
355                                         ((TRIGGER) == RTC_TAMPERTRIGGER_HIGHLEVEL))
356 #elif defined(STM32L100xB) || defined (STM32L151xB) || defined (STM32L152xB)
357 #define IS_RTC_TAMPER_TRIGGER(TRIGGER) (((TRIGGER) == RTC_TAMPERTRIGGER_RISINGEDGE) || \
358                                         ((TRIGGER) == RTC_TAMPERTRIGGER_FALLINGEDGE))
359 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
360 /**
361   * @}
362   */
363 
364 #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(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
365 /** @defgroup RTCEx_Tamper_Filter_Definitions Tamper Filter Definitions
366   * @{
367   */
368 #define RTC_TAMPERFILTER_DISABLE   (0x00000000U)  /*!< Tamper filter is disabled */
369 
370 #define RTC_TAMPERFILTER_2SAMPLE   (0x00000800U)  /*!< Tamper is activated after 2
371                                                                 consecutive samples at the active level */
372 #define RTC_TAMPERFILTER_4SAMPLE   (0x00001000U)  /*!< Tamper is activated after 4
373                                                                 consecutive samples at the active level */
374 #define RTC_TAMPERFILTER_8SAMPLE   (0x00001800U)  /*!< Tamper is activated after 8
375                                                                 consecutive samples at the active level. */
376 
377 #define IS_RTC_TAMPER_FILTER(FILTER)  (((FILTER) == RTC_TAMPERFILTER_DISABLE) || \
378                                    ((FILTER) == RTC_TAMPERFILTER_2SAMPLE) || \
379                                    ((FILTER) == RTC_TAMPERFILTER_4SAMPLE) || \
380                                    ((FILTER) == RTC_TAMPERFILTER_8SAMPLE))
381 /**
382   * @}
383   */
384 
385 /** @defgroup RTCEx_Tamper_Sampling_Frequencies_Definitions Tamper Sampling Frequencies
386   * @{
387   */
388 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV32768  (0x00000000U)  /*!< Each of the tamper inputs are sampled
389                                                                              with a frequency =  RTCCLK / 32768 */
390 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV16384  (0x00000100U)  /*!< Each of the tamper inputs are sampled
391                                                                              with a frequency =  RTCCLK / 16384 */
392 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV8192   (0x00000200U)  /*!< Each of the tamper inputs are sampled
393                                                                              with a frequency =  RTCCLK / 8192  */
394 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV4096   (0x00000300U)  /*!< Each of the tamper inputs are sampled
395                                                                              with a frequency =  RTCCLK / 4096  */
396 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV2048   (0x00000400U)  /*!< Each of the tamper inputs are sampled
397                                                                              with a frequency =  RTCCLK / 2048  */
398 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV1024   (0x00000500U)  /*!< Each of the tamper inputs are sampled
399                                                                              with a frequency =  RTCCLK / 1024  */
400 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV512    (0x00000600U)  /*!< Each of the tamper inputs are sampled
401                                                                              with a frequency =  RTCCLK / 512   */
402 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV256    (0x00000700U)  /*!< Each of the tamper inputs are sampled
403                                                                              with a frequency =  RTCCLK / 256   */
404 
405 #define IS_RTC_TAMPER_SAMPLING_FREQ(FREQ) (((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV32768)|| \
406                                        ((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV16384)|| \
407                                        ((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV8192) || \
408                                        ((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV4096) || \
409                                        ((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV2048) || \
410                                        ((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV1024) || \
411                                        ((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV512)  || \
412                                        ((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV256))
413 /**
414   * @}
415   */
416 
417 /** @defgroup RTCEx_Tamper_Pin_Precharge_Duration_Definitions Tamper Pin Precharge Duration
418   * @{
419   */
420 #define RTC_TAMPERPRECHARGEDURATION_1RTCCLK (0x00000000U)  /*!< Tamper pins are pre-charged before
421                                                                          sampling during 1 RTCCLK cycle */
422 #define RTC_TAMPERPRECHARGEDURATION_2RTCCLK (0x00002000U)  /*!< Tamper pins are pre-charged before
423                                                                          sampling during 2 RTCCLK cycles */
424 #define RTC_TAMPERPRECHARGEDURATION_4RTCCLK (0x00004000U)  /*!< Tamper pins are pre-charged before
425                                                                          sampling during 4 RTCCLK cycles */
426 #define RTC_TAMPERPRECHARGEDURATION_8RTCCLK (0x00006000U)  /*!< Tamper pins are pre-charged before
427                                                                          sampling during 8 RTCCLK cycles */
428 
429 #define IS_RTC_TAMPER_PRECHARGE_DURATION(DURATION) (((DURATION) == RTC_TAMPERPRECHARGEDURATION_1RTCCLK) || \
430                                                 ((DURATION) == RTC_TAMPERPRECHARGEDURATION_2RTCCLK) || \
431                                                 ((DURATION) == RTC_TAMPERPRECHARGEDURATION_4RTCCLK) || \
432                                                 ((DURATION) == RTC_TAMPERPRECHARGEDURATION_8RTCCLK))
433 /**
434   * @}
435   */
436 
437 /** @defgroup RTCEx_Tamper_TimeStampOnTamperDetection_Definitions TimeStampOnTamperDetection Definitions
438   * @{
439   */
440 #define RTC_TIMESTAMPONTAMPERDETECTION_ENABLE  ((uint32_t)RTC_TAFCR_TAMPTS)  /*!< TimeStamp on Tamper Detection event saved */
441 #define RTC_TIMESTAMPONTAMPERDETECTION_DISABLE (0x00000000U)        /*!< TimeStamp on Tamper Detection event is not saved */
442 
443 #define IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(DETECTION) (((DETECTION) == RTC_TIMESTAMPONTAMPERDETECTION_ENABLE) || \
444                                                           ((DETECTION) == RTC_TIMESTAMPONTAMPERDETECTION_DISABLE))
445 /**
446   * @}
447   */
448 
449 /** @defgroup RTCEx_Tamper_Pull_Up_Definitions Tamper Pull-Up Definitions
450   * @{
451   */
452 #define RTC_TAMPER_PULLUP_ENABLE  (0x00000000U)            /*!< TimeStamp on Tamper Detection event saved */
453 #define RTC_TAMPER_PULLUP_DISABLE (RTC_TAFCR_TAMPPUDIS)   /*!< TimeStamp on Tamper Detection event is not saved */
454 
455 #define IS_RTC_TAMPER_PULLUP_STATE(STATE) (((STATE) == RTC_TAMPER_PULLUP_ENABLE) || \
456                                        ((STATE) == RTC_TAMPER_PULLUP_DISABLE))
457 /**
458   * @}
459   */
460 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
461 
462 /** @defgroup RTCEx_Wakeup_Timer_Definitions Wakeup Timer Definitions
463   * @{
464   */
465 #define RTC_WAKEUPCLOCK_RTCCLK_DIV16        (0x00000000U)
466 #define RTC_WAKEUPCLOCK_RTCCLK_DIV8         (0x00000001U)
467 #define RTC_WAKEUPCLOCK_RTCCLK_DIV4         (0x00000002U)
468 #define RTC_WAKEUPCLOCK_RTCCLK_DIV2         (0x00000003U)
469 #define RTC_WAKEUPCLOCK_CK_SPRE_16BITS      (0x00000004U)
470 #define RTC_WAKEUPCLOCK_CK_SPRE_17BITS      (0x00000006U)
471 
472 #define IS_RTC_WAKEUP_CLOCK(CLOCK) (((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV16)   || \
473                                 ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV8)    || \
474                                 ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV4)    || \
475                                 ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV2)    || \
476                                 ((CLOCK) == RTC_WAKEUPCLOCK_CK_SPRE_16BITS) || \
477                                 ((CLOCK) == RTC_WAKEUPCLOCK_CK_SPRE_17BITS))
478 
479 #define IS_RTC_WAKEUP_COUNTER(COUNTER)  ((COUNTER) <= 0xFFFF)
480 /**
481   * @}
482   */
483 
484 /** @defgroup RTCEx_Digital_Calibration_Definitions Digital Calibration Definitions
485   * @{
486   */
487 #define RTC_CALIBSIGN_POSITIVE            (0x00000000U)
488 #define RTC_CALIBSIGN_NEGATIVE            (0x00000080U)
489 
490 #define IS_RTC_CALIB_SIGN(SIGN) (((SIGN) == RTC_CALIBSIGN_POSITIVE) || \
491                                  ((SIGN) == RTC_CALIBSIGN_NEGATIVE))
492 
493 #define IS_RTC_CALIB_VALUE(VALUE) ((VALUE) < 0x20)
494 /**
495   * @}
496   */
497 
498 /** @defgroup RTCEx_Smooth_Calib_Period_Definitions Smooth Calib Period Definitions
499   * @{
500   */
501 #define RTC_SMOOTHCALIB_PERIOD_32SEC   (0x00000000U) /*!<  If RTCCLK = 32768 Hz, Smooth calibation
502                                                                     period is 32s,  else 2exp20 RTCCLK seconds */
503 #define RTC_SMOOTHCALIB_PERIOD_16SEC   (0x00002000U) /*!<  If RTCCLK = 32768 Hz, Smooth calibation
504                                                                     period is 16s, else 2exp19 RTCCLK seconds */
505 #define RTC_SMOOTHCALIB_PERIOD_8SEC    (0x00004000U) /*!<  If RTCCLK = 32768 Hz, Smooth calibation
506                                                                     period is 8s, else 2exp18 RTCCLK seconds */
507 
508 #define IS_RTC_SMOOTH_CALIB_PERIOD(PERIOD) (((PERIOD) == RTC_SMOOTHCALIB_PERIOD_32SEC) || \
509                                             ((PERIOD) == RTC_SMOOTHCALIB_PERIOD_16SEC) || \
510                                             ((PERIOD) == RTC_SMOOTHCALIB_PERIOD_8SEC))
511 /**
512   * @}
513   */
514 
515 /** @defgroup RTCEx_Smooth_Calib_Plus_Pulses_Definitions Smooth Calib Plus Pulses Definitions
516   * @{
517   */
518 #define RTC_SMOOTHCALIB_PLUSPULSES_SET    (0x00008000U) /*!<  The number of RTCCLK pulses added
519                                                                        during a X -second window = Y - CALM[8:0]
520                                                                        with Y = 512, 256, 128 when X = 32, 16, 8 */
521 #define RTC_SMOOTHCALIB_PLUSPULSES_RESET  (0x00000000U) /*!<  The number of RTCCLK pulses subbstited
522                                                                        during a 32-second window =   CALM[8:0] */
523 
524 #define IS_RTC_SMOOTH_CALIB_PLUS(PLUS) (((PLUS) == RTC_SMOOTHCALIB_PLUSPULSES_SET) || \
525                                         ((PLUS) == RTC_SMOOTHCALIB_PLUSPULSES_RESET))
526 /**
527   * @}
528   */
529 
530 /** @defgroup RTCEx_Smooth_Calib_Minus_Pulses_Definitions Smooth Calib Minus Pulses Definitions
531   * @{
532   */
533 #define  IS_RTC_SMOOTH_CALIB_MINUS(VALUE) ((VALUE) <= 0x000001FFU)
534 /**
535   * @}
536   */
537 
538 /** @defgroup RTCEx_Add_1_Second_Parameter_Definitions Add 1 Second Parameter Definitions
539   * @{
540   */
541 #define RTC_SHIFTADD1S_RESET      (0x00000000U)
542 #define RTC_SHIFTADD1S_SET        (0x80000000U)
543 
544 #define IS_RTC_SHIFT_ADD1S(SEL) (((SEL) == RTC_SHIFTADD1S_RESET) || \
545                                  ((SEL) == RTC_SHIFTADD1S_SET))
546 /**
547   * @}
548   */
549 
550 /** @defgroup RTCEx_Substract_Fraction_Of_Second_Value Substract Fraction Of Second Value
551   * @{
552   */
553 #define IS_RTC_SHIFT_SUBFS(FS) ((FS) <= 0x00007FFFU)
554 /**
555   * @}
556   */
557 
558 /** @defgroup RTCEx_Calib_Output_Selection_Definitions Calib Output Selection Definitions
559   * @{
560   */
561 #define RTC_CALIBOUTPUT_512HZ            (0x00000000U)
562 #define RTC_CALIBOUTPUT_1HZ              (0x00080000U)
563 
564 #define IS_RTC_CALIB_OUTPUT(OUTPUT)  (((OUTPUT) == RTC_CALIBOUTPUT_512HZ) || \
565                                       ((OUTPUT) == RTC_CALIBOUTPUT_1HZ))
566 /**
567   * @}
568   */
569 
570 #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(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
571 /** @defgroup RTC_Alarm_Sub_Seconds_Value Alarm Sub Seconds Value
572   * @{
573   */
574 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= 0x00007FFFU)
575 /**
576   * @}
577   */
578 
579 /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions Alarm Sub Seconds Masks Definitions
580   * @{
581   */
582 #define RTC_ALARMSUBSECONDMASK_ALL         (0x00000000U)  /*!< All Alarm SS fields are masked.
583                                                                         There is no comparison on sub seconds
584                                                                         for Alarm */
585 #define RTC_ALARMSUBSECONDMASK_SS14_1      (0x01000000U)  /*!< SS[14:1] are don't care in Alarm
586                                                                         comparison. Only SS[0] is compared.    */
587 #define RTC_ALARMSUBSECONDMASK_SS14_2      (0x02000000U)  /*!< SS[14:2] are don't care in Alarm
588                                                                         comparison. Only SS[1:0] are compared  */
589 #define RTC_ALARMSUBSECONDMASK_SS14_3      (0x03000000U)  /*!< SS[14:3] are don't care in Alarm
590                                                                         comparison. Only SS[2:0] are compared  */
591 #define RTC_ALARMSUBSECONDMASK_SS14_4      (0x04000000U)  /*!< SS[14:4] are don't care in Alarm
592                                                                         comparison. Only SS[3:0] are compared  */
593 #define RTC_ALARMSUBSECONDMASK_SS14_5      (0x05000000U)  /*!< SS[14:5] are don't care in Alarm
594                                                                         comparison. Only SS[4:0] are compared  */
595 #define RTC_ALARMSUBSECONDMASK_SS14_6      (0x06000000U)  /*!< SS[14:6] are don't care in Alarm
596                                                                         comparison. Only SS[5:0] are compared  */
597 #define RTC_ALARMSUBSECONDMASK_SS14_7      (0x07000000U)  /*!< SS[14:7] are don't care in Alarm
598                                                                         comparison. Only SS[6:0] are compared  */
599 #define RTC_ALARMSUBSECONDMASK_SS14_8      (0x08000000U)  /*!< SS[14:8] are don't care in Alarm
600                                                                         comparison. Only SS[7:0] are compared  */
601 #define RTC_ALARMSUBSECONDMASK_SS14_9      (0x09000000U)  /*!< SS[14:9] are don't care in Alarm
602                                                                         comparison. Only SS[8:0] are compared  */
603 #define RTC_ALARMSUBSECONDMASK_SS14_10     (0x0A000000U)  /*!< SS[14:10] are don't care in Alarm
604                                                                         comparison. Only SS[9:0] are compared  */
605 #define RTC_ALARMSUBSECONDMASK_SS14_11     (0x0B000000U)  /*!< SS[14:11] are don't care in Alarm
606                                                                         comparison. Only SS[10:0] are compared */
607 #define RTC_ALARMSUBSECONDMASK_SS14_12     (0x0C000000U)  /*!< SS[14:12] are don't care in Alarm
608                                                                         comparison.Only SS[11:0] are compared  */
609 #define RTC_ALARMSUBSECONDMASK_SS14_13     (0x0D000000U)  /*!< SS[14:13] are don't care in Alarm
610                                                                         comparison. Only SS[12:0] are compared */
611 #define RTC_ALARMSUBSECONDMASK_SS14        (0x0E000000U)  /*!< SS[14] is don't care in Alarm
612                                                                         comparison.Only SS[13:0] are compared  */
613 #define RTC_ALARMSUBSECONDMASK_NONE        (0x0F000000U)  /*!< SS[14:0] are compared and must match
614                                                                         to activate alarm. */
615 
616 #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK)   (((MASK) == RTC_ALARMSUBSECONDMASK_ALL) || \
617                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_1) || \
618                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_2) || \
619                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_3) || \
620                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_4) || \
621                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_5) || \
622                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_6) || \
623                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_7) || \
624                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_8) || \
625                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_9) || \
626                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_10) || \
627                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_11) || \
628                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_12) || \
629                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_13) || \
630                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14) || \
631                                               ((MASK) == RTC_ALARMSUBSECONDMASK_NONE))
632 /**
633   * @}
634   */
635 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
636 
637 /**
638   * @}
639   */
640 
641 /* Exported macro ------------------------------------------------------------*/
642 /** @defgroup RTCEx_Exported_Macros RTCEx Exported Macros
643   * @{
644   */
645 
646 /**
647   * @brief Enable the RTC WakeUp Timer peripheral.
648   * @param  __HANDLE__: specifies the RTC handle.
649   * @retval None
650   */
651 #define __HAL_RTC_WAKEUPTIMER_ENABLE(__HANDLE__)                      ((__HANDLE__)->Instance->CR |= (RTC_CR_WUTE))
652 
653 /**
654   * @brief Enable the RTC TimeStamp peripheral.
655   * @param  __HANDLE__: specifies the RTC handle.
656   * @retval None
657   */
658 #define __HAL_RTC_TIMESTAMP_ENABLE(__HANDLE__)                        ((__HANDLE__)->Instance->CR |= (RTC_CR_TSE))
659 
660 /**
661   * @brief Disable the RTC WakeUp Timer peripheral.
662   * @param  __HANDLE__: specifies the RTC handle.
663   * @retval None
664   */
665 #define __HAL_RTC_WAKEUPTIMER_DISABLE(__HANDLE__)                     ((__HANDLE__)->Instance->CR &= ~(RTC_CR_WUTE))
666 
667 /**
668   * @brief Disable the RTC TimeStamp peripheral.
669   * @param  __HANDLE__: specifies the RTC handle.
670   * @retval None
671   */
672 #define __HAL_RTC_TIMESTAMP_DISABLE(__HANDLE__)                       ((__HANDLE__)->Instance->CR &= ~(RTC_CR_TSE))
673 
674 /**
675   * @brief  Enable the Coarse calibration process.
676   * @param  __HANDLE__: specifies the RTC handle.
677   * @retval None
678   */
679 #define __HAL_RTC_COARSE_CALIB_ENABLE(__HANDLE__)                       ((__HANDLE__)->Instance->CR |= (RTC_CR_DCE))
680 
681 /**
682   * @brief  Disable the Coarse calibration process.
683   * @param  __HANDLE__: specifies the RTC handle.
684   * @retval None
685   */
686 #define __HAL_RTC_COARSE_CALIB_DISABLE(__HANDLE__)                      ((__HANDLE__)->Instance->CR &= ~(RTC_CR_DCE))
687 
688 /**
689   * @brief  Enable the RTC calibration output.
690   * @param  __HANDLE__: specifies the RTC handle.
691   * @retval None
692   */
693 #define __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(__HANDLE__)                 ((__HANDLE__)->Instance->CR |= (RTC_CR_COE))
694 
695 /**
696   * @brief  Disable the calibration output.
697   * @param  __HANDLE__: specifies the RTC handle.
698   * @retval None
699   */
700 #define __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(__HANDLE__)                ((__HANDLE__)->Instance->CR &= ~(RTC_CR_COE))
701 
702 /**
703   * @brief  Enable the clock reference detection.
704   * @param  __HANDLE__: specifies the RTC handle.
705   * @retval None
706   */
707 #define __HAL_RTC_CLOCKREF_DETECTION_ENABLE(__HANDLE__)                 ((__HANDLE__)->Instance->CR |= (RTC_CR_REFCKON))
708 
709 /**
710   * @brief  Disable the clock reference detection.
711   * @param  __HANDLE__: specifies the RTC handle.
712   * @retval None
713   */
714 #define __HAL_RTC_CLOCKREF_DETECTION_DISABLE(__HANDLE__)                ((__HANDLE__)->Instance->CR &= ~(RTC_CR_REFCKON))
715 
716 /**
717   * @brief  Enable the RTC TimeStamp interrupt.
718   * @param  __HANDLE__: specifies the RTC handle.
719   * @param  __INTERRUPT__: specifies the RTC TimeStamp interrupt sources to be enabled or disabled.
720   *         This parameter can be:
721   *             @arg RTC_IT_TS: TimeStamp interrupt
722   * @retval None
723   */
724 #define __HAL_RTC_TIMESTAMP_ENABLE_IT(__HANDLE__, __INTERRUPT__)      ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
725 
726 /**
727   * @brief  Enable the RTC WakeUpTimer interrupt.
728   * @param  __HANDLE__: specifies the RTC handle.
729   * @param  __INTERRUPT__: specifies the RTC WakeUpTimer interrupt sources to be enabled or disabled.
730   *         This parameter can be:
731   *            @arg RTC_IT_WUT:  WakeUpTimer A interrupt
732   * @retval None
733   */
734 #define __HAL_RTC_WAKEUPTIMER_ENABLE_IT(__HANDLE__, __INTERRUPT__)    ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
735 
736 /**
737   * @brief  Disable the RTC TimeStamp interrupt.
738   * @param  __HANDLE__: specifies the RTC handle.
739   * @param  __INTERRUPT__: specifies the RTC TimeStamp interrupt sources to be enabled or disabled.
740   *          This parameter can be:
741   *             @arg RTC_IT_TS: TimeStamp interrupt
742   * @retval None
743   */
744 #define __HAL_RTC_TIMESTAMP_DISABLE_IT(__HANDLE__, __INTERRUPT__)     ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
745 
746 /**
747   * @brief  Disable the RTC WakeUpTimer interrupt.
748   * @param  __HANDLE__: specifies the RTC handle.
749   * @param  __INTERRUPT__: specifies the RTC WakeUpTimer interrupt sources to be enabled or disabled.
750   *         This parameter can be:
751   *            @arg RTC_IT_WUT:  WakeUpTimer A interrupt
752   * @retval None
753   */
754 #define __HAL_RTC_WAKEUPTIMER_DISABLE_IT(__HANDLE__, __INTERRUPT__)   ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
755 
756 /**
757   * @brief  Enable the RTC Tamper1 input detection.
758   * @param  __HANDLE__: specifies the RTC handle.
759   * @retval None
760   */
761 #define __HAL_RTC_TAMPER1_ENABLE(__HANDLE__)                         SET_BIT((__HANDLE__)->Instance->TAFCR, RTC_TAFCR_TAMP1E)
762 
763 /**
764   * @brief  Disable the RTC Tamper1 input detection.
765   * @param  __HANDLE__: specifies the RTC handle.
766   * @retval None
767   */
768 #define __HAL_RTC_TAMPER1_DISABLE(__HANDLE__)                        CLEAR_BIT((__HANDLE__)->Instance->TAFCR, RTC_TAFCR_TAMP1E)
769 
770 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC)\
771   || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA)\
772   || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA)\
773   || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
774 /**
775   * @brief  Enable the RTC Tamper2 input detection.
776   * @param  __HANDLE__: specifies the RTC handle.
777   * @retval None
778   */
779 #define __HAL_RTC_TAMPER2_ENABLE(__HANDLE__)                         SET_BIT((__HANDLE__)->Instance->TAFCR, RTC_TAFCR_TAMP2E)
780 
781 /**
782   * @brief  Disable the RTC Tamper2 input detection.
783   * @param  __HANDLE__: specifies the RTC handle.
784   * @retval None
785   */
786 #define __HAL_RTC_TAMPER2_DISABLE(__HANDLE__)                        CLEAR_BIT((__HANDLE__)->Instance->TAFCR, RTC_TAFCR_TAMP2E)
787 
788 /**
789   * @brief  Enable the RTC Tamper3 input detection.
790   * @param  __HANDLE__: specifies the RTC handle.
791   * @retval None
792   */
793 #define __HAL_RTC_TAMPER3_ENABLE(__HANDLE__)                         SET_BIT((__HANDLE__)->Instance->TAFCR, RTC_TAFCR_TAMP3E)
794 
795 /**
796   * @brief  Disable the RTC Tamper3 input detection.
797   * @param  __HANDLE__: specifies the RTC handle.
798   * @retval None
799   */
800 #define __HAL_RTC_TAMPER3_DISABLE(__HANDLE__)                        CLEAR_BIT((__HANDLE__)->Instance->TAFCR, RTC_TAFCR_TAMP3E)
801 
802 
803 /**
804   * @brief  Check whether the specified RTC Tamper interrupt has occurred or not.
805   * @param  __HANDLE__: specifies the RTC handle.
806   * @param  __INTERRUPT__: specifies the RTC Tamper interrupt to check.
807   *         This parameter can be:
808   *            @arg  RTC_IT_TAMP1: Tamper1 interrupt
809   *            @arg  RTC_IT_TAMP2: Tamper2 interrupt
810   *            @arg  RTC_IT_TAMP3: Tamper3 interrupt
811   * @retval None
812   */
813 #define __HAL_RTC_TAMPER_GET_IT(__HANDLE__, __INTERRUPT__) (((__INTERRUPT__) == RTC_IT_TAMP1) ? (((((__HANDLE__)->Instance->ISR) & RTC_ISR_TAMP1F) != RESET) ? SET : RESET) : \
814                                                            ((__INTERRUPT__) == RTC_IT_TAMP2) ? (((((__HANDLE__)->Instance->ISR) & RTC_ISR_TAMP2F) != RESET) ? SET : RESET) : \
815                                                            (((((__HANDLE__)->Instance->ISR) & RTC_ISR_TAMP3F) != RESET) ? SET : RESET))
816 #else
817 /**
818   * @brief  Check whether the specified RTC Tamper interrupt has occurred or not.
819   * @param  __HANDLE__: specifies the RTC handle.
820   * @param  __INTERRUPT__: specifies the RTC Tamper interrupt to check.
821   *         This parameter can be:
822   *            @arg  RTC_IT_TAMP1: Tamper1 interrupt
823   * @retval None
824   */
825 #define __HAL_RTC_TAMPER_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->ISR) & RTC_ISR_TAMP1F) != RESET) ? SET : RESET)
826 
827 #endif
828 
829 /**
830   * @brief  Enable the RTC Tamper interrupt.
831   * @param  __HANDLE__: specifies the RTC handle.
832   * @param  __INTERRUPT__: specifies the RTC Tamper interrupt sources to be enabled
833   *          This parameter can be any combination of the following values:
834   *            @arg  RTC_IT_TAMP1: Tamper1 interrupt
835   *            @arg  RTC_IT_TAMP2: Tamper2 interrupt (*)
836   *            @arg  RTC_IT_TAMP3: Tamper3 interrupt (*)
837   * @note   (*) Available only on devices STM32L100xBA, STM32L151xBA, STM32L152xBA, STM32L100xC,
838   *         STM32L151xC, STM32L152xC, STM32L162xC, STM32L151xCA, STM32L151xD, STM32L152xCA,
839   *         STM32L152xD, STM32L162xCA, STM32L162xD, STM32L151xE, STM32L152xE, STM32L162xE
840   *         STM32L151xDX, STM32L152xDX, STM32L162xDX
841   * @retval None
842   */
843 #define __HAL_RTC_TAMPER_ENABLE_IT(__HANDLE__, __INTERRUPT__)         SET_BIT(((__HANDLE__)->Instance->TAFCR), RTC_TAFCR_TAMPIE)
844 
845 /**
846   * @brief  Disable the RTC Tamper interrupt.
847   * @param  __HANDLE__: specifies the RTC handle.
848   * @param  __INTERRUPT__: specifies the RTC Tamper interrupt sources to be disabled.
849   *         This parameter can be any combination of the following values:
850   *            @arg  RTC_IT_TAMP1: Tamper1 interrupt
851   *            @arg  RTC_IT_TAMP2: Tamper2 interrupt (*)
852   *            @arg  RTC_IT_TAMP3: Tamper3 interrupt (*)
853   * @note   (*) Available only on devices STM32L100xBA, STM32L151xBA, STM32L152xBA, STM32L100xC,
854   *         STM32L151xC, STM32L152xC, STM32L162xC, STM32L151xCA, STM32L151xD, STM32L152xCA,
855   *         STM32L152xD, STM32L162xCA, STM32L162xD, STM32L151xE, STM32L152xE, STM32L162xE
856   *         STM32L151xDX, STM32L152xDX, STM32L162xDX
857   * @retval None
858   */
859 #define __HAL_RTC_TAMPER_DISABLE_IT(__HANDLE__, __INTERRUPT__)        CLEAR_BIT(((__HANDLE__)->Instance->TAFCR), RTC_TAFCR_TAMPIE)
860 
861 /**
862   * @brief  Check whether the specified RTC Tamper interrupt has been enabled or not.
863   * @param  __HANDLE__: specifies the RTC handle.
864   * @param  __INTERRUPT__: specifies the RTC Tamper interrupt source to check.
865   *         This parameter can be:
866   *            @arg  RTC_IT_TAMP1: Tamper1 interrupt
867   *            @arg  RTC_IT_TAMP2: Tamper2 interrupt (*)
868   *            @arg  RTC_IT_TAMP3: Tamper3 interrupt (*)
869   * @note   (*) Available only on devices STM32L100xBA, STM32L151xBA, STM32L152xBA, STM32L100xC,
870   *         STM32L151xC, STM32L152xC, STM32L162xC, STM32L151xCA, STM32L151xD, STM32L152xCA,
871   *         STM32L152xD, STM32L162xCA, STM32L162xD, STM32L151xE, STM32L152xE, STM32L162xE
872   *         STM32L151xDX, STM32L152xDX, STM32L162xDX
873   * @retval None
874   */
875 #define __HAL_RTC_TAMPER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)    (((((__HANDLE__)->Instance->TAFCR) & RTC_TAFCR_TAMPIE) != RESET) ? SET : RESET)
876 
877 /**
878   * @brief  Check whether the specified RTC WakeUpTimer interrupt has occurred or not.
879   * @param  __HANDLE__: specifies the RTC handle.
880   * @param  __FLAG__: specifies the RTC WakeUpTimer interrupt sources to be enabled or disabled.
881   *         This parameter can be:
882   *            @arg RTC_IT_WUT:  WakeUpTimer A interrupt
883   * @retval None
884   */
885 #define __HAL_RTC_WAKEUPTIMER_GET_IT(__HANDLE__, __FLAG__)            (((((__HANDLE__)->Instance->ISR) & ((__FLAG__)>> 4)) != RESET)? SET : RESET)
886 
887 /**
888   * @brief  Check whether the specified RTC Wake Up timer interrupt has been enabled or not.
889   * @param  __HANDLE__: specifies the RTC handle.
890   * @param  __INTERRUPT__: specifies the RTC Wake Up timer interrupt sources to check.
891   *         This parameter can be:
892   *            @arg RTC_IT_WUT:  WakeUpTimer interrupt
893   * @retval None
894   */
895 #define __HAL_RTC_WAKEUPTIMER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)   (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != RESET) ? SET : RESET)
896 
897 /**
898   * @brief  Check whether the specified RTC TimeStamp interrupt has occurred or not.
899   * @param  __HANDLE__: specifies the RTC handle.
900   * @param  __INTERRUPT__: specifies the RTC TimeStamp interrupt sources to be enabled or disabled.
901   *         This parameter can be:
902   *            @arg RTC_IT_TS: TimeStamp interrupt
903   * @retval None
904   */
905 #define __HAL_RTC_TIMESTAMP_GET_IT(__HANDLE__, __INTERRUPT__)              (((((__HANDLE__)->Instance->ISR) & ((__INTERRUPT__)>> 4)) != RESET)? SET : RESET)
906 
907 /**
908   * @brief  Check whether the specified RTC Time Stamp interrupt has been enabled or not.
909   * @param  __HANDLE__: specifies the RTC handle.
910   * @param  __INTERRUPT__: specifies the RTC Time Stamp interrupt source to check.
911   *         This parameter can be:
912   *            @arg RTC_IT_TS: TimeStamp interrupt
913   * @retval None
914   */
915 #define __HAL_RTC_TIMESTAMP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)     (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != RESET) ? SET : RESET)
916 
917 /**
918   * @brief  Get the selected RTC TimeStamp's flag status.
919   * @param  __HANDLE__: specifies the RTC handle.
920   * @param  __FLAG__: specifies the RTC TimeStamp Flag sources to be enabled or disabled.
921   *         This parameter can be:
922   *            @arg RTC_FLAG_TSF
923   *            @arg RTC_FLAG_TSOVF
924   * @retval None
925   */
926 #define __HAL_RTC_TIMESTAMP_GET_FLAG(__HANDLE__, __FLAG__)            (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != RESET)? SET : RESET)
927 
928 /**
929   * @brief  Get the selected RTC WakeUpTimer's flag status.
930   * @param  __HANDLE__: specifies the RTC handle.
931   * @param  __FLAG__: specifies the RTC WakeUpTimer Flag sources to be enabled or disabled.
932   *         This parameter can be:
933   *            @arg RTC_FLAG_WUTF
934   *            @arg RTC_FLAG_WUTWF
935   * @retval None
936   */
937 #define __HAL_RTC_WAKEUPTIMER_GET_FLAG(__HANDLE__, __FLAG__)          (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != RESET)? SET : RESET)
938 
939 /**
940   * @brief  Get the selected RTC Tamper's flag status.
941   * @param  __HANDLE__: specifies the RTC handle.
942   * @param  __FLAG__: specifies the RTC Tamper Flag sources to be enabled or disabled.
943   *         This parameter can be:
944   *            @arg RTC_FLAG_TAMP1F
945   *            @arg RTC_FLAG_TAMP2F  (*)
946   *            @arg RTC_FLAG_TAMP3F  (*)
947   * @note   (*) Available only on devices STM32L100xBA, STM32L151xBA, STM32L152xBA, STM32L100xC,
948   *         STM32L151xC, STM32L152xC, STM32L162xC, STM32L151xCA, STM32L151xD, STM32L152xCA,
949   *         STM32L152xD, STM32L162xCA, STM32L162xD, STM32L151xE, STM32L152xE, STM32L162xE
950   *         STM32L151xDX, STM32L152xDX, STM32L162xDX
951   * @retval None
952   */
953 #define __HAL_RTC_TAMPER_GET_FLAG(__HANDLE__, __FLAG__)               (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != RESET)? SET : RESET)
954 
955 #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC)\
956   || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA)\
957   || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA)\
958   || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
959 /**
960   * @brief  Get the selected RTC shift operation's flag status.
961   * @param  __HANDLE__: specifies the RTC handle.
962   * @param  __FLAG__: specifies the RTC shift operation Flag is pending or not.
963   *         This parameter can be:
964   *            @arg RTC_FLAG_SHPF
965   * @retval None
966   */
967 #define __HAL_RTC_SHIFT_GET_FLAG(__HANDLE__, __FLAG__)                (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != RESET)? SET : RESET)
968 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
969 
970 /**
971   * @brief  Clear the RTC Time Stamp's pending flags.
972   * @param  __HANDLE__: specifies the RTC handle.
973   * @param  __FLAG__: specifies the RTC Alarm Flag sources to be enabled or disabled.
974   *         This parameter can be:
975   *            @arg RTC_FLAG_TSF
976   * @retval None
977   */
978 #define __HAL_RTC_TIMESTAMP_CLEAR_FLAG(__HANDLE__, __FLAG__)          ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
979 
980 /**
981   * @brief  Clear the RTC Tamper's pending flags.
982   * @param  __HANDLE__: specifies the RTC handle.
983   * @param  __FLAG__: specifies the RTC Tamper Flag sources to be enabled or disabled.
984   *         This parameter can be:
985   *            @arg RTC_FLAG_TAMP1F
986   *            @arg RTC_FLAG_TAMP2F  (*)
987   *            @arg RTC_FLAG_TAMP3F  (*)
988   * @note   (*) Available only on devices STM32L100xBA, STM32L151xBA, STM32L152xBA, STM32L100xC,
989   *         STM32L151xC, STM32L152xC, STM32L162xC, STM32L151xCA, STM32L151xD, STM32L152xCA,
990   *         STM32L152xD, STM32L162xCA, STM32L162xD, STM32L151xE, STM32L152xE, STM32L162xE
991   *         STM32L151xDX, STM32L152xDX, STM32L162xDX
992   * @retval None
993   */
994 #define __HAL_RTC_TAMPER_CLEAR_FLAG(__HANDLE__, __FLAG__)      ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
995 
996 /**
997   * @brief  Clear the RTC Wake Up timer's pending flags.
998   * @param  __HANDLE__: specifies the RTC handle.
999   * @param  __FLAG__: specifies the RTC WakeUpTimer Flag to clear.
1000   *         This parameter can be:
1001   *            @arg RTC_FLAG_WUTF
1002   * @retval None
1003   */
1004 #define __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
1005 
1006 /**
1007   * @brief  Enable interrupt on the RTC WakeUp Timer associated Exti line.
1008   * @retval None
1009   */
1010 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT()       (EXTI->IMR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1011 
1012 /**
1013   * @brief  Disable interrupt on the RTC WakeUp Timer associated Exti line.
1014   * @retval None
1015   */
1016 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_IT()      (EXTI->IMR &= ~(RTC_EXTI_LINE_WAKEUPTIMER_EVENT))
1017 
1018 /**
1019   * @brief  Enable event on the RTC WakeUp Timer associated Exti line.
1020   * @retval None.
1021   */
1022 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_EVENT()    (EXTI->EMR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1023 
1024 /**
1025   * @brief  Disable event on the RTC WakeUp Timer associated Exti line.
1026   * @retval None.
1027   */
1028 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_EVENT()   (EXTI->EMR &= ~(RTC_EXTI_LINE_WAKEUPTIMER_EVENT))
1029 
1030 /**
1031   * @brief  Enable falling edge trigger on the RTC WakeUp Timer associated Exti line.
1032   * @retval None.
1033   */
1034 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_FALLING_EDGE()   (EXTI->FTSR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1035 
1036 /**
1037   * @brief  Disable falling edge trigger on the RTC WakeUp Timer associated Exti line.
1038   * @retval None.
1039   */
1040 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_FALLING_EDGE()  (EXTI->FTSR &= ~(RTC_EXTI_LINE_WAKEUPTIMER_EVENT))
1041 
1042 /**
1043   * @brief  Enable rising edge trigger on the RTC WakeUp Timer associated Exti line.
1044   * @retval None.
1045   */
1046 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE()    (EXTI->RTSR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1047 
1048 /**
1049   * @brief  Disable rising edge trigger on the RTC WakeUp Timer associated Exti line.
1050   * @retval None.
1051   */
1052 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_RISING_EDGE()   (EXTI->RTSR &= ~(RTC_EXTI_LINE_WAKEUPTIMER_EVENT))
1053 
1054 /**
1055   * @brief  Enable rising & falling edge trigger on the RTC WakeUp Timer associated Exti line.
1056   * @retval None.
1057   */
1058 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_FALLING_EDGE() do { __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE();__HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_FALLING_EDGE(); } while(0);
1059 
1060 /**
1061   * @brief  Disable rising & falling edge trigger on the RTC WakeUp Timer associated Exti line.
1062   * This parameter can be:
1063   * @retval None.
1064   */
1065 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_RISING_FALLING_EDGE() do { __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_RISING_EDGE();__HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_FALLING_EDGE(); } while(0);
1066 
1067 /**
1068   * @brief Check whether the RTC WakeUp Timer associated Exti line interrupt flag is set or not.
1069   * @retval Line Status.
1070   */
1071 #define __HAL_RTC_WAKEUPTIMER_EXTI_GET_FLAG()              (EXTI->PR & RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1072 
1073 /**
1074   * @brief Clear the RTC WakeUp Timer associated Exti line flag.
1075   * @retval None.
1076   */
1077 #define __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG()            (EXTI->PR = RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1078 
1079 /**
1080   * @brief Generate a Software interrupt on the RTC WakeUp Timer associated Exti line.
1081   * @retval None.
1082   */
1083 #define __HAL_RTC_WAKEUPTIMER_EXTI_GENERATE_SWIT()         (EXTI->SWIER |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1084 
1085 /**
1086   * @brief  Enable interrupt on the RTC Tamper and Timestamp associated Exti line.
1087   * @retval None
1088   */
1089 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT()        (EXTI->IMR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1090 
1091 /**
1092   * @brief  Disable interrupt on the RTC Tamper and Timestamp associated Exti line.
1093   * @retval None
1094   */
1095 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_IT()       (EXTI->IMR &= ~(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT))
1096 
1097 /**
1098   * @brief  Enable event on the RTC Tamper and Timestamp associated Exti line.
1099   * @retval None.
1100   */
1101 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_EVENT()    (EXTI->EMR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1102 
1103 /**
1104   * @brief  Disable event on the RTC Tamper and Timestamp associated Exti line.
1105   * @retval None.
1106   */
1107 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_EVENT()   (EXTI->EMR &= ~(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT))
1108 
1109 /**
1110   * @brief  Enable falling edge trigger on the RTC Tamper and Timestamp associated Exti line.
1111   * @retval None.
1112   */
1113 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_FALLING_EDGE()   (EXTI->FTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1114 
1115 /**
1116   * @brief  Disable falling edge trigger on the RTC Tamper and Timestamp associated Exti line.
1117   * @retval None.
1118   */
1119 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_FALLING_EDGE()  (EXTI->FTSR &= ~(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT))
1120 
1121 /**
1122   * @brief  Enable rising edge trigger on the RTC Tamper and Timestamp associated Exti line.
1123   * @retval None.
1124   */
1125 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE()    (EXTI->RTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1126 
1127 /**
1128   * @brief  Disable rising edge trigger on the RTC Tamper and Timestamp associated Exti line.
1129   * @retval None.
1130   */
1131 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_RISING_EDGE()   (EXTI->RTSR &= ~(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT))
1132 
1133 /**
1134   * @brief  Enable rising & falling edge trigger on the RTC Tamper and Timestamp associated Exti line.
1135   * @retval None.
1136   */
1137 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_FALLING_EDGE() do { __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE();__HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_FALLING_EDGE(); } while(0);
1138 
1139 /**
1140   * @brief  Disable rising & falling edge trigger on the RTC Tamper and Timestamp associated Exti line.
1141   * This parameter can be:
1142   * @retval None.
1143   */
1144 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_RISING_FALLING_EDGE() do { __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_RISING_EDGE();__HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_FALLING_EDGE(); } while(0);
1145 
1146 /**
1147   * @brief Check whether the RTC Tamper and Timestamp associated Exti line interrupt flag is set or not.
1148   * @retval Line Status.
1149   */
1150 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_GET_FLAG()         (EXTI->PR & RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1151 
1152 /**
1153   * @brief Clear the RTC Tamper and Timestamp associated Exti line flag.
1154   * @retval None.
1155   */
1156 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG()       (EXTI->PR = RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1157 
1158 /**
1159   * @brief Generate a Software interrupt on the RTC Tamper and Timestamp associated Exti line
1160   * @retval None.
1161   */
1162 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_GENERATE_SWIT()    (EXTI->SWIER |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1163 
1164 /**
1165   * @}
1166   */
1167 
1168 /* Exported functions --------------------------------------------------------*/
1169 /** @addtogroup RTCEx_Exported_Functions
1170   * @{
1171   */
1172 
1173 /* RTC TimeStamp and Tamper functions *****************************************/
1174 /** @addtogroup RTCEx_Exported_Functions_Group4
1175   * @{
1176   */
1177 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge);
1178 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge);
1179 HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc);
1180 HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTimeStamp, RTC_DateTypeDef *sTimeStampDate, uint32_t Format);
1181 
1182 HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper);
1183 HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper);
1184 HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper);
1185 void              HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc);
1186 
1187 void              HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc);
1188 #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(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
1189 void              HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef *hrtc);
1190 void              HAL_RTCEx_Tamper3EventCallback(RTC_HandleTypeDef *hrtc);
1191 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
1192 void              HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc);
1193 HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
1194 HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
1195 #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(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
1196 HAL_StatusTypeDef HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
1197 HAL_StatusTypeDef HAL_RTCEx_PollForTamper3Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
1198 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
1199 /**
1200   * @}
1201   */
1202 
1203 /* RTC Wake-up functions ******************************************************/
1204 /** @addtogroup RTCEx_Exported_Functions_Group5
1205   * @{
1206   */
1207 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock);
1208 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock);
1209 uint32_t          HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc);
1210 uint32_t          HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc);
1211 void              HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc);
1212 void              HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc);
1213 HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
1214 /**
1215   * @}
1216   */
1217 
1218 /* Extension Control functions ************************************************/
1219 /** @addtogroup RTCEx_Exported_Functions_Group7
1220   * @{
1221   */
1222 void              HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data);
1223 uint32_t          HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister);
1224 
1225 HAL_StatusTypeDef HAL_RTCEx_SetCoarseCalib(RTC_HandleTypeDef *hrtc, uint32_t CalibSign, uint32_t Value);
1226 HAL_StatusTypeDef HAL_RTCEx_DeactivateCoarseCalib(RTC_HandleTypeDef *hrtc);
1227 #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(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
1228 HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef *hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmoothCalibMinusPulsesValue);
1229 HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef *hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS);
1230 HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef *hrtc, uint32_t CalibOutput);
1231 #else
1232 HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef *hrtc);
1233 #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
1234 HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef *hrtc);
1235 HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef *hrtc);
1236 HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef *hrtc);
1237 HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef *hrtc);
1238 HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef *hrtc);
1239 /**
1240   * @}
1241   */
1242 
1243 /* Extension RTC features functions *******************************************/
1244 /** @addtogroup RTCEx_Exported_Functions_Group8
1245   * @{
1246   */
1247 void              HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc);
1248 HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
1249 /**
1250   * @}
1251   */
1252 
1253 /**
1254   * @}
1255   */
1256 
1257 /* Private types -------------------------------------------------------------*/
1258 /* Private variables ---------------------------------------------------------*/
1259 /* Private constants ---------------------------------------------------------*/
1260 /** @defgroup RTCEx_Private_Constants RTCEx Private Constants
1261   * @{
1262   */
1263 #define RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT  (0x00080000U)  /*!< External interrupt line 19 Connected to the RTC Tamper and Time Stamp events */
1264 #define RTC_EXTI_LINE_WAKEUPTIMER_EVENT       (0x00100000U)  /*!< External interrupt line 20 Connected to the RTC Wakeup event */
1265 
1266 /**
1267   * @}
1268   */
1269 
1270 /* Private macros ------------------------------------------------------------*/
1271 /** @defgroup RTCEx_Private_Macros RTCEx Private Macros
1272   * @{
1273   */
1274 
1275 /**
1276   * @}
1277   */
1278 
1279 /**
1280   * @}
1281   */
1282 
1283 /**
1284   * @}
1285   */
1286 
1287 #ifdef __cplusplus
1288 }
1289 #endif
1290 
1291 #endif /* __STM32L1xx_HAL_RTC_EX_H */
1292 
1293 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
1294