1 /**
2   ******************************************************************************
3   * @file    stm32f7xx_hal_rtc.h
4   * @author  MCD Application Team
5   * @version V1.0.1
6   * @date    25-June-2015
7   * @brief   Header file of RTC HAL module.
8   ******************************************************************************
9   * @attention
10   *
11   * <h2><center>&copy; COPYRIGHT(c) 2015 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 __STM32F7xx_HAL_RTC_H
40 #define __STM32F7xx_HAL_RTC_H
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f7xx_hal_def.h"
48 
49 /** @addtogroup STM32F7xx_HAL_Driver
50   * @{
51   */
52 
53 /** @addtogroup RTC
54   * @{
55   */
56 
57 /* Exported types ------------------------------------------------------------*/
58 /** @defgroup RTC_Exported_Types RTC Exported Types
59   * @{
60   */
61 
62 /**
63   * @brief  HAL State structures definition
64   */
65 typedef enum {
66     HAL_RTC_STATE_RESET             = 0x00,  /*!< RTC not yet initialized or disabled */
67     HAL_RTC_STATE_READY             = 0x01,  /*!< RTC initialized and ready for use   */
68     HAL_RTC_STATE_BUSY              = 0x02,  /*!< RTC process is ongoing              */
69     HAL_RTC_STATE_TIMEOUT           = 0x03,  /*!< RTC timeout state                   */
70     HAL_RTC_STATE_ERROR             = 0x04   /*!< RTC error state                     */
71 
72 } HAL_RTCStateTypeDef;
73 
74 /**
75   * @brief  RTC Configuration Structure definition
76   */
77 typedef struct {
78     uint32_t HourFormat;      /*!< Specifies the RTC Hour Format.
79                                  This parameter can be a value of @ref RTC_Hour_Formats */
80 
81     uint32_t AsynchPrediv;    /*!< Specifies the RTC Asynchronous Predivider value.
82                                  This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7F */
83 
84     uint32_t SynchPrediv;     /*!< Specifies the RTC Synchronous Predivider value.
85                                  This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7FFF */
86 
87     uint32_t OutPut;          /*!< Specifies which signal will be routed to the RTC output.
88                                  This parameter can be a value of @ref RTCEx_Output_selection_Definitions */
89 
90     uint32_t OutPutPolarity;  /*!< Specifies the polarity of the output signal.
91                                  This parameter can be a value of @ref RTC_Output_Polarity_Definitions */
92 
93     uint32_t OutPutType;      /*!< Specifies the RTC Output Pin mode.
94                                  This parameter can be a value of @ref RTC_Output_Type_ALARM_OUT */
95 } RTC_InitTypeDef;
96 
97 /**
98   * @brief  RTC Time structure definition
99   */
100 typedef struct {
101     uint8_t Hours;            /*!< Specifies the RTC Time Hour.
102                                  This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected.
103                                  This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected  */
104 
105     uint8_t Minutes;          /*!< Specifies the RTC Time Minutes.
106                                  This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
107 
108     uint8_t Seconds;          /*!< Specifies the RTC Time Seconds.
109                                  This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
110 
111     uint32_t SubSeconds;      /*!< Specifies the RTC Time SubSeconds.
112                                  This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
113 
114     uint8_t TimeFormat;       /*!< Specifies the RTC AM/PM Time.
115                                  This parameter can be a value of @ref RTC_AM_PM_Definitions */
116 
117     uint32_t DayLightSaving;  /*!< Specifies RTC_DayLightSaveOperation: the value of hour adjustment.
118                                  This parameter can be a value of @ref RTC_DayLightSaving_Definitions */
119 
120     uint32_t StoreOperation;  /*!< Specifies RTC_StoreOperation value to be written in the BCK bit
121                                  in CR register to store the operation.
122                                  This parameter can be a value of @ref RTC_StoreOperation_Definitions */
123 } RTC_TimeTypeDef;
124 
125 /**
126   * @brief  RTC Date structure definition
127   */
128 typedef struct {
129     uint8_t WeekDay;  /*!< Specifies the RTC Date WeekDay.
130                          This parameter can be a value of @ref RTC_WeekDay_Definitions */
131 
132     uint8_t Month;    /*!< Specifies the RTC Date Month (in BCD format).
133                          This parameter can be a value of @ref RTC_Month_Date_Definitions */
134 
135     uint8_t Date;     /*!< Specifies the RTC Date.
136                          This parameter must be a number between Min_Data = 1 and Max_Data = 31 */
137 
138     uint8_t Year;     /*!< Specifies the RTC Date Year.
139                          This parameter must be a number between Min_Data = 0 and Max_Data = 99 */
140 
141 } RTC_DateTypeDef;
142 
143 /**
144   * @brief  RTC Alarm structure definition
145   */
146 typedef struct {
147     RTC_TimeTypeDef AlarmTime;     /*!< Specifies the RTC Alarm Time members */
148 
149     uint32_t AlarmMask;            /*!< Specifies the RTC Alarm Masks.
150                                       This parameter can be a value of @ref RTC_AlarmMask_Definitions */
151 
152     uint32_t AlarmSubSecondMask;   /*!< Specifies the RTC Alarm SubSeconds Masks.
153                                       This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */
154 
155     uint32_t AlarmDateWeekDaySel;  /*!< Specifies the RTC Alarm is on Date or WeekDay.
156                                      This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */
157 
158     uint8_t AlarmDateWeekDay;      /*!< Specifies the RTC Alarm Date/WeekDay.
159                                       If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range.
160                                       If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */
161 
162     uint32_t Alarm;                /*!< Specifies the alarm .
163                                       This parameter can be a value of @ref RTC_Alarms_Definitions */
164 } RTC_AlarmTypeDef;
165 
166 /**
167   * @brief  RTC Handle Structure definition
168   */
169 typedef struct {
170     RTC_TypeDef                 *Instance;  /*!< Register base address    */
171 
172     RTC_InitTypeDef             Init;       /*!< RTC required parameters  */
173 
174     HAL_LockTypeDef             Lock;       /*!< RTC locking object       */
175 
176     __IO HAL_RTCStateTypeDef    State;      /*!< Time communication state */
177 
178 } RTC_HandleTypeDef;
179 
180 /**
181   * @}
182   */
183 
184 /* Exported constants --------------------------------------------------------*/
185 /** @defgroup RTC_Exported_Constants RTC Exported Constants
186   * @{
187   */
188 
189 /** @defgroup RTC_Hour_Formats RTC Hour Formats
190   * @{
191   */
192 #define RTC_HOURFORMAT_24              ((uint32_t)0x00000000)
193 #define RTC_HOURFORMAT_12              ((uint32_t)0x00000040)
194 /**
195   * @}
196   */
197 
198 
199 /** @defgroup RTC_Output_Polarity_Definitions RTC Output Polarity Definitions
200   * @{
201   */
202 #define RTC_OUTPUT_POLARITY_HIGH       ((uint32_t)0x00000000)
203 #define RTC_OUTPUT_POLARITY_LOW        ((uint32_t)0x00100000)
204 /**
205   * @}
206   */
207 
208 /** @defgroup RTC_Output_Type_ALARM_OUT RTC Output Type ALARM OUT
209   * @{
210   */
211 #define RTC_OUTPUT_TYPE_OPENDRAIN      ((uint32_t)0x00000000)
212 #define RTC_OUTPUT_TYPE_PUSHPULL       ((uint32_t)RTC_OR_ALARMTYPE)  /* 0x00000008 */
213 /**
214   * @}
215   */
216 
217 /** @defgroup RTC_AM_PM_Definitions RTC AM PM Definitions
218   * @{
219   */
220 #define RTC_HOURFORMAT12_AM            ((uint8_t)0x00)
221 #define RTC_HOURFORMAT12_PM            ((uint8_t)0x40)
222 /**
223   * @}
224   */
225 
226 /** @defgroup RTC_DayLightSaving_Definitions RTC DayLight Saving Definitions
227   * @{
228   */
229 #define RTC_DAYLIGHTSAVING_SUB1H       ((uint32_t)0x00020000)
230 #define RTC_DAYLIGHTSAVING_ADD1H       ((uint32_t)0x00010000)
231 #define RTC_DAYLIGHTSAVING_NONE        ((uint32_t)0x00000000)
232 /**
233   * @}
234   */
235 
236 /** @defgroup RTC_StoreOperation_Definitions RTC Store Operation Definitions
237   * @{
238   */
239 #define RTC_STOREOPERATION_RESET        ((uint32_t)0x00000000)
240 #define RTC_STOREOPERATION_SET          ((uint32_t)0x00040000)
241 /**
242   * @}
243   */
244 
245 /** @defgroup RTC_Input_parameter_format_definitions RTC Input Parameter Format Definitions
246   * @{
247   */
248 #define RTC_FORMAT_BIN                      ((uint32_t)0x000000000)
249 #define RTC_FORMAT_BCD                      ((uint32_t)0x000000001)
250 /**
251   * @}
252   */
253 
254 /** @defgroup RTC_Month_Date_Definitions RTC Month Date Definitions
255   * @{
256   */
257 /* Coded in BCD format */
258 #define RTC_MONTH_JANUARY              ((uint8_t)0x01)
259 #define RTC_MONTH_FEBRUARY             ((uint8_t)0x02)
260 #define RTC_MONTH_MARCH                ((uint8_t)0x03)
261 #define RTC_MONTH_APRIL                ((uint8_t)0x04)
262 #define RTC_MONTH_MAY                  ((uint8_t)0x05)
263 #define RTC_MONTH_JUNE                 ((uint8_t)0x06)
264 #define RTC_MONTH_JULY                 ((uint8_t)0x07)
265 #define RTC_MONTH_AUGUST               ((uint8_t)0x08)
266 #define RTC_MONTH_SEPTEMBER            ((uint8_t)0x09)
267 #define RTC_MONTH_OCTOBER              ((uint8_t)0x10)
268 #define RTC_MONTH_NOVEMBER             ((uint8_t)0x11)
269 #define RTC_MONTH_DECEMBER             ((uint8_t)0x12)
270 /**
271   * @}
272   */
273 
274 /** @defgroup RTC_WeekDay_Definitions RTC WeekDay Definitions
275   * @{
276   */
277 #define RTC_WEEKDAY_MONDAY             ((uint8_t)0x01)
278 #define RTC_WEEKDAY_TUESDAY            ((uint8_t)0x02)
279 #define RTC_WEEKDAY_WEDNESDAY          ((uint8_t)0x03)
280 #define RTC_WEEKDAY_THURSDAY           ((uint8_t)0x04)
281 #define RTC_WEEKDAY_FRIDAY             ((uint8_t)0x05)
282 #define RTC_WEEKDAY_SATURDAY           ((uint8_t)0x06)
283 #define RTC_WEEKDAY_SUNDAY             ((uint8_t)0x07)
284 /**
285   * @}
286   */
287 
288 /** @defgroup RTC_AlarmDateWeekDay_Definitions RTC Alarm Date WeekDay Definitions
289   * @{
290   */
291 #define RTC_ALARMDATEWEEKDAYSEL_DATE      ((uint32_t)0x00000000)
292 #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY   ((uint32_t)0x40000000)
293 /**
294   * @}
295   */
296 
297 /** @defgroup RTC_AlarmMask_Definitions RTC Alarm Mask Definitions
298   * @{
299   */
300 #define RTC_ALARMMASK_NONE                ((uint32_t)0x00000000)
301 #define RTC_ALARMMASK_DATEWEEKDAY         RTC_ALRMAR_MSK4
302 #define RTC_ALARMMASK_HOURS               RTC_ALRMAR_MSK3
303 #define RTC_ALARMMASK_MINUTES             RTC_ALRMAR_MSK2
304 #define RTC_ALARMMASK_SECONDS             RTC_ALRMAR_MSK1
305 #define RTC_ALARMMASK_ALL                 ((uint32_t)0x80808080)
306 /**
307   * @}
308   */
309 
310 /** @defgroup RTC_Alarms_Definitions RTC Alarms Definitions
311   * @{
312   */
313 #define RTC_ALARM_A                       RTC_CR_ALRAE
314 #define RTC_ALARM_B                       RTC_CR_ALRBE
315 /**
316   * @}
317   */
318 
319 /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions RTC Alarm Sub Seconds Masks Definitions
320   * @{
321   */
322 #define RTC_ALARMSUBSECONDMASK_ALL         ((uint32_t)0x00000000)  /*!< All Alarm SS fields are masked.
323                                                                         There is no comparison on sub seconds
324                                                                         for Alarm */
325 #define RTC_ALARMSUBSECONDMASK_SS14_1      ((uint32_t)0x01000000)  /*!< SS[14:1] are don't care in Alarm
326                                                                         comparison. Only SS[0] is compared.    */
327 #define RTC_ALARMSUBSECONDMASK_SS14_2      ((uint32_t)0x02000000)  /*!< SS[14:2] are don't care in Alarm
328                                                                         comparison. Only SS[1:0] are compared  */
329 #define RTC_ALARMSUBSECONDMASK_SS14_3      ((uint32_t)0x03000000)  /*!< SS[14:3] are don't care in Alarm
330                                                                         comparison. Only SS[2:0] are compared  */
331 #define RTC_ALARMSUBSECONDMASK_SS14_4      ((uint32_t)0x04000000)  /*!< SS[14:4] are don't care in Alarm
332                                                                         comparison. Only SS[3:0] are compared  */
333 #define RTC_ALARMSUBSECONDMASK_SS14_5      ((uint32_t)0x05000000)  /*!< SS[14:5] are don't care in Alarm
334                                                                         comparison. Only SS[4:0] are compared  */
335 #define RTC_ALARMSUBSECONDMASK_SS14_6      ((uint32_t)0x06000000)  /*!< SS[14:6] are don't care in Alarm
336                                                                         comparison. Only SS[5:0] are compared  */
337 #define RTC_ALARMSUBSECONDMASK_SS14_7      ((uint32_t)0x07000000)  /*!< SS[14:7] are don't care in Alarm
338                                                                         comparison. Only SS[6:0] are compared  */
339 #define RTC_ALARMSUBSECONDMASK_SS14_8      ((uint32_t)0x08000000)  /*!< SS[14:8] are don't care in Alarm
340                                                                         comparison. Only SS[7:0] are compared  */
341 #define RTC_ALARMSUBSECONDMASK_SS14_9      ((uint32_t)0x09000000)  /*!< SS[14:9] are don't care in Alarm
342                                                                         comparison. Only SS[8:0] are compared  */
343 #define RTC_ALARMSUBSECONDMASK_SS14_10     ((uint32_t)0x0A000000)  /*!< SS[14:10] are don't care in Alarm
344                                                                         comparison. Only SS[9:0] are compared  */
345 #define RTC_ALARMSUBSECONDMASK_SS14_11     ((uint32_t)0x0B000000)  /*!< SS[14:11] are don't care in Alarm
346                                                                         comparison. Only SS[10:0] are compared */
347 #define RTC_ALARMSUBSECONDMASK_SS14_12     ((uint32_t)0x0C000000)  /*!< SS[14:12] are don't care in Alarm
348                                                                         comparison.Only SS[11:0] are compared  */
349 #define RTC_ALARMSUBSECONDMASK_SS14_13     ((uint32_t)0x0D000000)  /*!< SS[14:13] are don't care in Alarm
350                                                                         comparison. Only SS[12:0] are compared */
351 #define RTC_ALARMSUBSECONDMASK_SS14        ((uint32_t)0x0E000000)  /*!< SS[14] is don't care in Alarm
352                                                                         comparison.Only SS[13:0] are compared  */
353 #define RTC_ALARMSUBSECONDMASK_NONE        ((uint32_t)0x0F000000)  /*!< SS[14:0] are compared and must match
354                                                                         to activate alarm. */
355 /**
356   * @}
357   */
358 
359 /** @defgroup RTC_Interrupts_Definitions RTC Interrupts Definitions
360   * @{
361   */
362 #define RTC_IT_TS                         ((uint32_t)RTC_CR_TSIE)
363 #define RTC_IT_WUT                        ((uint32_t)RTC_CR_WUTIE)
364 #define RTC_IT_ALRA                       ((uint32_t)RTC_CR_ALRAIE)
365 #define RTC_IT_ALRB                       ((uint32_t)RTC_CR_ALRBIE)
366 #define RTC_IT_TAMP                       ((uint32_t)RTC_TAMPCR_TAMPIE) /* Used only to Enable the Tamper Interrupt */
367 #define RTC_IT_TAMP1                      ((uint32_t)RTC_TAMPCR_TAMP1IE)
368 #define RTC_IT_TAMP2                      ((uint32_t)RTC_TAMPCR_TAMP2IE)
369 #define RTC_IT_TAMP3                      ((uint32_t)RTC_TAMPCR_TAMP3IE)
370 /**
371   * @}
372   */
373 
374 /** @defgroup RTC_Flags_Definitions RTC Flags Definitions
375   * @{
376   */
377 #define RTC_FLAG_RECALPF                  ((uint32_t)RTC_ISR_RECALPF)
378 #define RTC_FLAG_TAMP3F                   ((uint32_t)RTC_ISR_TAMP3F)
379 #define RTC_FLAG_TAMP2F                   ((uint32_t)RTC_ISR_TAMP2F)
380 #define RTC_FLAG_TAMP1F                   ((uint32_t)RTC_ISR_TAMP1F)
381 #define RTC_FLAG_TSOVF                    ((uint32_t)RTC_ISR_TSOVF)
382 #define RTC_FLAG_TSF                      ((uint32_t)RTC_ISR_TSF)
383 #define RTC_FLAG_ITSF                     ((uint32_t)RTC_ISR_ITSF)
384 #define RTC_FLAG_WUTF                     ((uint32_t)RTC_ISR_WUTF)
385 #define RTC_FLAG_ALRBF                    ((uint32_t)RTC_ISR_ALRBF)
386 #define RTC_FLAG_ALRAF                    ((uint32_t)RTC_ISR_ALRAF)
387 #define RTC_FLAG_INITF                    ((uint32_t)RTC_ISR_INITF)
388 #define RTC_FLAG_RSF                      ((uint32_t)RTC_ISR_RSF)
389 #define RTC_FLAG_INITS                    ((uint32_t)RTC_ISR_INITS)
390 #define RTC_FLAG_SHPF                     ((uint32_t)RTC_ISR_SHPF)
391 #define RTC_FLAG_WUTWF                    ((uint32_t)RTC_ISR_WUTWF)
392 #define RTC_FLAG_ALRBWF                   ((uint32_t)RTC_ISR_ALRBWF)
393 #define RTC_FLAG_ALRAWF                   ((uint32_t)RTC_ISR_ALRAWF)
394 /**
395   * @}
396   */
397 
398 /**
399   * @}
400   */
401 
402 /* Exported macro ------------------------------------------------------------*/
403 /** @defgroup RTC_Exported_Macros RTC Exported Macros
404   * @{
405   */
406 
407 /** @brief Reset RTC handle state
408   * @param  __HANDLE__: specifies the RTC handle.
409   * @retval None
410   */
411 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET)
412 
413 /**
414   * @brief  Disable the write protection for RTC registers.
415   * @param  __HANDLE__: specifies the RTC handle.
416   * @retval None
417   */
418 #define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__)             \
419                         do{                                       \
420                             (__HANDLE__)->Instance->WPR = 0xCA;   \
421                             (__HANDLE__)->Instance->WPR = 0x53;   \
422                           } while(0)
423 
424 /**
425   * @brief  Enable the write protection for RTC registers.
426   * @param  __HANDLE__: specifies the RTC handle.
427   * @retval None
428   */
429 #define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__)              \
430                         do{                                       \
431                             (__HANDLE__)->Instance->WPR = 0xFF;   \
432                           } while(0)
433 
434 /**
435   * @brief  Enable the RTC ALARMA peripheral.
436   * @param  __HANDLE__: specifies the RTC handle.
437   * @retval None
438   */
439 #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__)                           ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE))
440 
441 /**
442   * @brief  Disable the RTC ALARMA peripheral.
443   * @param  __HANDLE__: specifies the RTC handle.
444   * @retval None
445   */
446 #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__)                          ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE))
447 
448 /**
449   * @brief  Enable the RTC ALARMB peripheral.
450   * @param  __HANDLE__: specifies the RTC handle.
451   * @retval None
452   */
453 #define __HAL_RTC_ALARMB_ENABLE(__HANDLE__)                           ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRBE))
454 
455 /**
456   * @brief  Disable the RTC ALARMB peripheral.
457   * @param  __HANDLE__: specifies the RTC handle.
458   * @retval None
459   */
460 #define __HAL_RTC_ALARMB_DISABLE(__HANDLE__)                          ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRBE))
461 
462 /**
463   * @brief  Enable the RTC Alarm interrupt.
464   * @param  __HANDLE__: specifies the RTC handle.
465   * @param  __INTERRUPT__: specifies the RTC Alarm interrupt sources to be enabled or disabled.
466   *          This parameter can be any combination of the following values:
467   *             @arg RTC_IT_ALRA: Alarm A interrupt
468   *             @arg RTC_IT_ALRB: Alarm B interrupt
469   * @retval None
470   */
471 #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__)          ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
472 
473 /**
474   * @brief  Disable the RTC Alarm interrupt.
475   * @param  __HANDLE__: specifies the RTC handle.
476   * @param  __INTERRUPT__: specifies the RTC Alarm interrupt sources to be enabled or disabled.
477   *         This parameter can be any combination of the following values:
478   *            @arg RTC_IT_ALRA: Alarm A interrupt
479   *            @arg RTC_IT_ALRB: Alarm B interrupt
480   * @retval None
481   */
482 #define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__)         ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
483 
484 /**
485   * @brief  Check whether the specified RTC Alarm interrupt has occurred or not.
486   * @param  __HANDLE__: specifies the RTC handle.
487   * @param  __INTERRUPT__: specifies the RTC Alarm interrupt to check.
488   *         This parameter can be:
489   *            @arg RTC_IT_ALRA: Alarm A interrupt
490   *            @arg RTC_IT_ALRB: Alarm B interrupt
491   * @retval None
492   */
493 #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__)                  ((((((__HANDLE__)->Instance->ISR)& ((__INTERRUPT__)>> 4)) & 0x0000FFFF) != RESET)? SET : RESET)
494 
495 /**
496   * @brief  Get the selected RTC Alarm's flag status.
497   * @param  __HANDLE__: specifies the RTC handle.
498   * @param  __FLAG__: specifies the RTC Alarm Flag to check.
499   *         This parameter can be:
500   *            @arg RTC_FLAG_ALRAF
501   *            @arg RTC_FLAG_ALRBF
502   *            @arg RTC_FLAG_ALRAWF
503   *            @arg RTC_FLAG_ALRBWF
504   * @retval None
505   */
506 #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__)                (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != RESET)? SET : RESET)
507 
508 /**
509   * @brief  Clear the RTC Alarm's pending flags.
510   * @param  __HANDLE__: specifies the RTC handle.
511   * @param  __FLAG__: specifies the RTC Alarm Flag sources to be enabled or disabled.
512   *          This parameter can be:
513   *             @arg RTC_FLAG_ALRAF
514   *             @arg RTC_FLAG_ALRBF
515   * @retval None
516   */
517 #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__)                  ((__HANDLE__)->Instance->ISR) = (~(((__FLAG__) | RTC_ISR_INIT)& 0x0000FFFF)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
518 
519 /**
520   * @brief  Check whether the specified RTC Alarm interrupt has been enabled or not.
521   * @param  __HANDLE__: specifies the RTC handle.
522   * @param  __INTERRUPT__: specifies the RTC Alarm interrupt sources to check.
523   *         This parameter can be:
524   *            @arg RTC_IT_ALRA: Alarm A interrupt
525   *            @arg RTC_IT_ALRB: Alarm B interrupt
526   * @retval None
527   */
528 #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)     (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != RESET) ? SET : RESET)
529 
530 /**
531   * @brief  Enable interrupt on the RTC Alarm associated Exti line.
532   * @retval None
533   */
534 #define __HAL_RTC_ALARM_EXTI_ENABLE_IT()            (EXTI->IMR |= RTC_EXTI_LINE_ALARM_EVENT)
535 
536 /**
537   * @brief  Disable interrupt on the RTC Alarm associated Exti line.
538   * @retval None
539   */
540 #define __HAL_RTC_ALARM_EXTI_DISABLE_IT()           (EXTI->IMR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
541 
542 /**
543   * @brief  Enable event on the RTC Alarm associated Exti line.
544   * @retval None.
545   */
546 #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT()         (EXTI->EMR |= RTC_EXTI_LINE_ALARM_EVENT)
547 
548 /**
549   * @brief  Disable event on the RTC Alarm associated Exti line.
550   * @retval None.
551   */
552 #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT()         (EXTI->EMR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
553 
554 /**
555   * @brief  Enable falling edge trigger on the RTC Alarm associated Exti line.
556   * @retval None.
557   */
558 #define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE()   (EXTI->FTSR |= RTC_EXTI_LINE_ALARM_EVENT)
559 
560 /**
561   * @brief  Disable falling edge trigger on the RTC Alarm associated Exti line.
562   * @retval None.
563   */
564 #define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE()  (EXTI->FTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
565 
566 /**
567   * @brief  Enable rising edge trigger on the RTC Alarm associated Exti line.
568   * @retval None.
569   */
570 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE()    (EXTI->RTSR |= RTC_EXTI_LINE_ALARM_EVENT)
571 
572 /**
573   * @brief  Disable rising edge trigger on the RTC Alarm associated Exti line.
574   * @retval None.
575   */
576 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE()   (EXTI->RTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
577 
578 /**
579   * @brief  Enable rising & falling edge trigger on the RTC Alarm associated Exti line.
580   * @retval None.
581   */
582 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE() __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE();__HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE();
583 
584 /**
585   * @brief  Disable rising & falling edge trigger on the RTC Alarm associated Exti line.
586   * @retval None.
587   */
588 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE();__HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE();
589 
590 /**
591   * @brief Check whether the RTC Alarm associated Exti line interrupt flag is set or not.
592   * @retval Line Status.
593   */
594 #define __HAL_RTC_ALARM_EXTI_GET_FLAG()              (EXTI->PR & RTC_EXTI_LINE_ALARM_EVENT)
595 
596 /**
597   * @brief Clear the RTC Alarm associated Exti line flag.
598   * @retval None.
599   */
600 #define __HAL_RTC_ALARM_EXTI_CLEAR_FLAG()            (EXTI->PR = RTC_EXTI_LINE_ALARM_EVENT)
601 
602 /**
603   * @brief Generate a Software interrupt on RTC Alarm associated Exti line.
604   * @retval None.
605   */
606 #define __HAL_RTC_ALARM_EXTI_GENERATE_SWIT()         (EXTI->SWIER |= RTC_EXTI_LINE_ALARM_EVENT)
607 /**
608   * @}
609   */
610 
611 /* Include RTC HAL Extension module */
612 #include "stm32f7xx_hal_rtc_ex.h"
613 
614 /* Exported functions --------------------------------------------------------*/
615 /** @addtogroup RTC_Exported_Functions
616   * @{
617   */
618 
619 /** @addtogroup RTC_Exported_Functions_Group1
620   * @{
621   */
622 /* Initialization and de-initialization functions  ****************************/
623 HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc);
624 HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc);
625 void       HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc);
626 void       HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc);
627 /**
628   * @}
629   */
630 
631 /** @addtogroup RTC_Exported_Functions_Group2
632   * @{
633   */
634 /* RTC Time and Date functions ************************************************/
635 HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
636 HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
637 HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
638 HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
639 /**
640   * @}
641   */
642 
643 /** @addtogroup RTC_Exported_Functions_Group3
644   * @{
645   */
646 /* RTC Alarm functions ********************************************************/
647 HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
648 HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
649 HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm);
650 HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format);
651 void                HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc);
652 HAL_StatusTypeDef   HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
653 void         HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc);
654 /**
655   * @}
656   */
657 
658 /** @addtogroup RTC_Exported_Functions_Group4
659   * @{
660   */
661 /* Peripheral Control functions ***********************************************/
662 HAL_StatusTypeDef   HAL_RTC_WaitForSynchro(RTC_HandleTypeDef* hrtc);
663 /**
664   * @}
665   */
666 
667 /** @addtogroup RTC_Exported_Functions_Group5
668   * @{
669   */
670 /* Peripheral State functions *************************************************/
671 HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc);
672 /**
673   * @}
674   */
675 
676 /**
677   * @}
678   */
679 
680 /* Private types -------------------------------------------------------------*/
681 /* Private variables ---------------------------------------------------------*/
682 /* Private constants ---------------------------------------------------------*/
683 /** @defgroup RTC_Private_Constants RTC Private Constants
684   * @{
685   */
686 /* Masks Definition */
687 #define RTC_TR_RESERVED_MASK    ((uint32_t)0x007F7F7F)
688 #define RTC_DR_RESERVED_MASK    ((uint32_t)0x00FFFF3F)
689 #define RTC_INIT_MASK           ((uint32_t)0xFFFFFFFF)
690 #define RTC_RSF_MASK            ((uint32_t)0xFFFFFF5F)
691 
692 #define RTC_TIMEOUT_VALUE       1000
693 
694 #define RTC_EXTI_LINE_ALARM_EVENT             ((uint32_t)EXTI_IMR_MR17)  /*!< External interrupt line 17 Connected to the RTC Alarm event */
695 /**
696   * @}
697   */
698 
699 /* Private macros ------------------------------------------------------------*/
700 /** @defgroup RTC_Private_Macros RTC Private Macros
701   * @{
702   */
703 
704 /** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters
705   * @{
706   */
707 #define IS_RTC_HOUR_FORMAT(__FORMAT__) (((__FORMAT__) == RTC_HOURFORMAT_12) || \
708                                         ((__FORMAT__) == RTC_HOURFORMAT_24))
709 #define IS_RTC_OUTPUT_POL(__POL__)     (((__POL__) == RTC_OUTPUT_POLARITY_HIGH) || \
710                                         ((__POL__) == RTC_OUTPUT_POLARITY_LOW))
711 #define IS_RTC_OUTPUT_TYPE(__TYPE__)   (((__TYPE__) == RTC_OUTPUT_TYPE_OPENDRAIN) || \
712                                         ((__TYPE__) == RTC_OUTPUT_TYPE_PUSHPULL))
713 #define IS_RTC_ASYNCH_PREDIV(__PREDIV__)   ((__PREDIV__) <= (uint32_t)0x7F)
714 #define IS_RTC_SYNCH_PREDIV(__PREDIV__)    ((__PREDIV__) <= (uint32_t)0x7FFF)
715 #define IS_RTC_HOUR12(__HOUR__)            (((__HOUR__) > (uint32_t)0) && ((__HOUR__) <= (uint32_t)12))
716 #define IS_RTC_HOUR24(__HOUR__)            ((__HOUR__) <= (uint32_t)23)
717 #define IS_RTC_MINUTES(__MINUTES__)        ((__MINUTES__) <= (uint32_t)59)
718 #define IS_RTC_SECONDS(__SECONDS__)        ((__SECONDS__) <= (uint32_t)59)
719 #define IS_RTC_HOURFORMAT12(__PM__)  (((__PM__) == RTC_HOURFORMAT12_AM) || ((__PM__) == RTC_HOURFORMAT12_PM))
720 #define IS_RTC_DAYLIGHT_SAVING(__SAVE__) (((__SAVE__) == RTC_DAYLIGHTSAVING_SUB1H) || \
721                                           ((__SAVE__) == RTC_DAYLIGHTSAVING_ADD1H) || \
722                                           ((__SAVE__) == RTC_DAYLIGHTSAVING_NONE))
723 #define IS_RTC_STORE_OPERATION(__OPERATION__) (((__OPERATION__) == RTC_STOREOPERATION_RESET) || \
724                                                ((__OPERATION__) == RTC_STOREOPERATION_SET))
725 #define IS_RTC_FORMAT(__FORMAT__) (((__FORMAT__) == RTC_FORMAT_BIN) || ((__FORMAT__) == RTC_FORMAT_BCD))
726 #define IS_RTC_YEAR(__YEAR__)              ((__YEAR__) <= (uint32_t)99)
727 #define IS_RTC_MONTH(__MONTH__)            (((__MONTH__) >= (uint32_t)1) && ((__MONTH__) <= (uint32_t)12))
728 #define IS_RTC_DATE(__DATE__)              (((__DATE__) >= (uint32_t)1) && ((__DATE__) <= (uint32_t)31))
729 #define IS_RTC_WEEKDAY(__WEEKDAY__) (((__WEEKDAY__) == RTC_WEEKDAY_MONDAY)    || \
730                                      ((__WEEKDAY__) == RTC_WEEKDAY_TUESDAY)   || \
731                                      ((__WEEKDAY__) == RTC_WEEKDAY_WEDNESDAY) || \
732                                      ((__WEEKDAY__) == RTC_WEEKDAY_THURSDAY)  || \
733                                      ((__WEEKDAY__) == RTC_WEEKDAY_FRIDAY)    || \
734                                      ((__WEEKDAY__) == RTC_WEEKDAY_SATURDAY)  || \
735                                      ((__WEEKDAY__) == RTC_WEEKDAY_SUNDAY))
736 
737 #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(__DATE__) (((__DATE__) >(uint32_t) 0) && ((__DATE__) <= (uint32_t)31))
738 #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(__WEEKDAY__) (((__WEEKDAY__) == RTC_WEEKDAY_MONDAY)    || \
739                                                         ((__WEEKDAY__) == RTC_WEEKDAY_TUESDAY)   || \
740                                                         ((__WEEKDAY__) == RTC_WEEKDAY_WEDNESDAY) || \
741                                                         ((__WEEKDAY__) == RTC_WEEKDAY_THURSDAY)  || \
742                                                         ((__WEEKDAY__) == RTC_WEEKDAY_FRIDAY)    || \
743                                                         ((__WEEKDAY__) == RTC_WEEKDAY_SATURDAY)  || \
744                                                         ((__WEEKDAY__) == RTC_WEEKDAY_SUNDAY))
745 #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(__SEL__) (((__SEL__) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \
746                                                 ((__SEL__) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY))
747 #define IS_RTC_ALARM_MASK(__MASK__)  (((__MASK__) & 0x7F7F7F7F) == (uint32_t)RESET)
748 #define IS_RTC_ALARM(__ALARM__)      (((__ALARM__) == RTC_ALARM_A) || ((__ALARM__) == RTC_ALARM_B))
749 #define IS_RTC_ALARM_SUB_SECOND_VALUE(__VALUE__) ((__VALUE__) <= (uint32_t)0x00007FFF)
750 #define IS_RTC_ALARM_SUB_SECOND_MASK(__MASK__)   (((__MASK__) == RTC_ALARMSUBSECONDMASK_ALL) || \
751                                                   ((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_1) || \
752                                                   ((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_2) || \
753                                                   ((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_3) || \
754                                                   ((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_4) || \
755                                                   ((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_5) || \
756                                                   ((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_6) || \
757                                                   ((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_7) || \
758                                                   ((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_8) || \
759                                                   ((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_9) || \
760                                                   ((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_10) || \
761                                                   ((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_11) || \
762                                                   ((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_12) || \
763                                                   ((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14_13) || \
764                                                   ((__MASK__) == RTC_ALARMSUBSECONDMASK_SS14) || \
765                                                   ((__MASK__) == RTC_ALARMSUBSECONDMASK_NONE))
766 
767 /**
768   * @}
769   */
770 
771 /**
772   * @}
773   */
774 
775 /* Private functions ---------------------------------------------------------*/
776 /** @defgroup RTC_Private_Functions RTC Private Functions
777   * @{
778   */
779 HAL_StatusTypeDef  RTC_EnterInitMode(RTC_HandleTypeDef* hrtc);
780 uint8_t            RTC_ByteToBcd2(uint8_t Value);
781 uint8_t            RTC_Bcd2ToByte(uint8_t Value);
782 /**
783   * @}
784   */
785 
786 /**
787   * @}
788   */
789 
790 /**
791   * @}
792   */
793 
794 #ifdef __cplusplus
795 }
796 #endif
797 
798 #endif /* __STM32F7xx_HAL_RTC_H */
799 
800 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
801