STM32F439xx HAL User Manual
stm32f4xx_hal_rtc.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4xx_hal_rtc.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of RTC HAL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
00010   *
00011   * Redistribution and use in source and binary forms, with or without modification,
00012   * are permitted provided that the following conditions are met:
00013   *   1. Redistributions of source code must retain the above copyright notice,
00014   *      this list of conditions and the following disclaimer.
00015   *   2. Redistributions in binary form must reproduce the above copyright notice,
00016   *      this list of conditions and the following disclaimer in the documentation
00017   *      and/or other materials provided with the distribution.
00018   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00019   *      may be used to endorse or promote products derived from this software
00020   *      without specific prior written permission.
00021   *
00022   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00023   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00025   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00026   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00028   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00030   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00031   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032   *
00033   ******************************************************************************
00034   */ 
00035 
00036 /* Define to prevent recursive inclusion -------------------------------------*/
00037 #ifndef __STM32F4xx_HAL_RTC_H
00038 #define __STM32F4xx_HAL_RTC_H
00039 
00040 #ifdef __cplusplus
00041  extern "C" {
00042 #endif
00043 
00044 /* Includes ------------------------------------------------------------------*/
00045 #include "stm32f4xx_hal_def.h"
00046 
00047 /** @addtogroup STM32F4xx_HAL_Driver
00048   * @{
00049   */
00050 
00051 /** @addtogroup RTC
00052   * @{
00053   */ 
00054 
00055 /* Exported types ------------------------------------------------------------*/
00056 /** @defgroup RTC_Exported_Types RTC Exported Types
00057   * @{
00058   */
00059 
00060 /** 
00061   * @brief  HAL State structures definition  
00062   */
00063 typedef enum
00064 {
00065   HAL_RTC_STATE_RESET             = 0x00U,  /*!< RTC not yet initialized or disabled */
00066   HAL_RTC_STATE_READY             = 0x01U,  /*!< RTC initialized and ready for use   */
00067   HAL_RTC_STATE_BUSY              = 0x02U,  /*!< RTC process is ongoing              */
00068   HAL_RTC_STATE_TIMEOUT           = 0x03U,  /*!< RTC timeout state                   */
00069   HAL_RTC_STATE_ERROR             = 0x04U   /*!< RTC error state                     */
00070 }HAL_RTCStateTypeDef;
00071 
00072 /** 
00073   * @brief  RTC Configuration Structure definition  
00074   */
00075 typedef struct
00076 {
00077   uint32_t HourFormat;      /*!< Specifies the RTC Hour Format.
00078                                  This parameter can be a value of @ref RTC_Hour_Formats */
00079 
00080   uint32_t AsynchPrediv;    /*!< Specifies the RTC Asynchronous Predivider value.
00081                                  This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7F */
00082 
00083   uint32_t SynchPrediv;     /*!< Specifies the RTC Synchronous Predivider value.
00084                                  This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7FFFU */
00085 
00086   uint32_t OutPut;          /*!< Specifies which signal will be routed to the RTC output.   
00087                                  This parameter can be a value of @ref RTC_Output_selection_Definitions */
00088 
00089   uint32_t OutPutPolarity;  /*!< Specifies the polarity of the output signal.  
00090                                  This parameter can be a value of @ref RTC_Output_Polarity_Definitions */
00091 
00092   uint32_t OutPutType;      /*!< Specifies the RTC Output Pin mode.   
00093                                  This parameter can be a value of @ref RTC_Output_Type_ALARM_OUT */
00094 }RTC_InitTypeDef;
00095 
00096 /** 
00097   * @brief  RTC Time structure definition  
00098   */
00099 typedef struct
00100 {
00101   uint8_t Hours;            /*!< Specifies the RTC Time Hour.
00102                                  This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected.
00103                                  This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected  */
00104 
00105   uint8_t Minutes;          /*!< Specifies the RTC Time Minutes.
00106                                  This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
00107 
00108   uint8_t Seconds;          /*!< Specifies the RTC Time Seconds.
00109                                  This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
00110 
00111   uint8_t TimeFormat;       /*!< Specifies the RTC AM/PM Time.
00112                                  This parameter can be a value of @ref RTC_AM_PM_Definitions */
00113 
00114   uint32_t SubSeconds;     /*!< Specifies the RTC_SSR RTC Sub Second register content.
00115                                  This parameter corresponds to a time unit range between [0-1] Second
00116                                  with [1 Sec / SecondFraction +1] granularity */
00117 
00118   uint32_t SecondFraction;  /*!< Specifies the range or granularity of Sub Second register content
00119                                  corresponding to Synchronous pre-scaler factor value (PREDIV_S)
00120                                  This parameter corresponds to a time unit range between [0-1] Second
00121                                  with [1 Sec / SecondFraction +1] granularity.
00122                                  This field will be used only by HAL_RTC_GetTime function */
00123 
00124   uint32_t DayLightSaving;  /*!< Specifies DayLight Save Operation.
00125                                  This parameter can be a value of @ref RTC_DayLightSaving_Definitions */
00126 
00127   uint32_t StoreOperation;  /*!< Specifies RTC_StoreOperation value to be written in the BCK bit 
00128                                  in CR register to store the operation.
00129                                  This parameter can be a value of @ref RTC_StoreOperation_Definitions */
00130 }RTC_TimeTypeDef; 
00131 
00132 /** 
00133   * @brief  RTC Date structure definition  
00134   */
00135 typedef struct
00136 {
00137   uint8_t WeekDay;  /*!< Specifies the RTC Date WeekDay.
00138                          This parameter can be a value of @ref RTC_WeekDay_Definitions */
00139 
00140   uint8_t Month;    /*!< Specifies the RTC Date Month (in BCD format).
00141                          This parameter can be a value of @ref RTC_Month_Date_Definitions */
00142 
00143   uint8_t Date;     /*!< Specifies the RTC Date.
00144                          This parameter must be a number between Min_Data = 1 and Max_Data = 31 */
00145 
00146   uint8_t Year;     /*!< Specifies the RTC Date Year.
00147                          This parameter must be a number between Min_Data = 0 and Max_Data = 99 */
00148 
00149 }RTC_DateTypeDef;
00150 
00151 /** 
00152   * @brief  RTC Alarm structure definition  
00153   */
00154 typedef struct
00155 {
00156   RTC_TimeTypeDef AlarmTime;     /*!< Specifies the RTC Alarm Time members */
00157 
00158   uint32_t AlarmMask;            /*!< Specifies the RTC Alarm Masks.
00159                                       This parameter can be a value of @ref RTC_AlarmMask_Definitions */
00160 
00161   uint32_t AlarmSubSecondMask;   /*!< Specifies the RTC Alarm SubSeconds Masks.
00162                                       This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */
00163 
00164   uint32_t AlarmDateWeekDaySel;  /*!< Specifies the RTC Alarm is on Date or WeekDay.
00165                                      This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */
00166 
00167   uint8_t AlarmDateWeekDay;      /*!< Specifies the RTC Alarm Date/WeekDay.
00168                                       If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range.
00169                                       If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */
00170 
00171   uint32_t Alarm;                /*!< Specifies the alarm .
00172                                       This parameter can be a value of @ref RTC_Alarms_Definitions */
00173 }RTC_AlarmTypeDef;
00174 
00175 /** 
00176   * @brief  RTC Handle Structure definition  
00177   */ 
00178 typedef struct
00179 {
00180   RTC_TypeDef                 *Instance;  /*!< Register base address    */
00181 
00182   RTC_InitTypeDef             Init;       /*!< RTC required parameters  */
00183 
00184   HAL_LockTypeDef             Lock;       /*!< RTC locking object       */
00185 
00186   __IO HAL_RTCStateTypeDef    State;      /*!< Time communication state */
00187 
00188 }RTC_HandleTypeDef;
00189 
00190 /**
00191   * @}
00192   */
00193 
00194 /* Exported constants --------------------------------------------------------*/
00195 /** @defgroup RTC_Exported_Constants RTC Exported Constants
00196   * @{
00197   */
00198 
00199 /** @defgroup RTC_Hour_Formats RTC Hour Formats
00200   * @{
00201   */ 
00202 #define RTC_HOURFORMAT_24              0x00000000U
00203 #define RTC_HOURFORMAT_12              0x00000040U
00204 /**
00205   * @}
00206   */ 
00207   
00208 /** @defgroup RTC_Output_selection_Definitions RTC Output Selection Definitions
00209   * @{
00210   */ 
00211 #define RTC_OUTPUT_DISABLE             0x00000000U
00212 #define RTC_OUTPUT_ALARMA              0x00200000U
00213 #define RTC_OUTPUT_ALARMB              0x00400000U
00214 #define RTC_OUTPUT_WAKEUP              0x00600000U
00215 /**
00216   * @}
00217   */ 
00218 
00219 /** @defgroup RTC_Output_Polarity_Definitions RTC Output Polarity Definitions
00220   * @{
00221   */ 
00222 #define RTC_OUTPUT_POLARITY_HIGH       0x00000000U
00223 #define RTC_OUTPUT_POLARITY_LOW        0x00100000U
00224 /**
00225   * @}
00226   */ 
00227 
00228 /** @defgroup RTC_Output_Type_ALARM_OUT RTC Output Type ALARM OUT
00229   * @{
00230   */ 
00231 #define RTC_OUTPUT_TYPE_OPENDRAIN      0x00000000U
00232 #define RTC_OUTPUT_TYPE_PUSHPULL       0x00040000U
00233 /**
00234   * @}
00235   */ 
00236 
00237 /** @defgroup RTC_AM_PM_Definitions RTC AM PM Definitions
00238   * @{
00239   */ 
00240 #define RTC_HOURFORMAT12_AM            ((uint8_t)0x00)
00241 #define RTC_HOURFORMAT12_PM            ((uint8_t)0x40)
00242 /**
00243   * @}
00244   */ 
00245 
00246 /** @defgroup RTC_DayLightSaving_Definitions RTC DayLight Saving Definitions
00247   * @{
00248   */ 
00249 #define RTC_DAYLIGHTSAVING_SUB1H       0x00020000U
00250 #define RTC_DAYLIGHTSAVING_ADD1H       0x00010000U
00251 #define RTC_DAYLIGHTSAVING_NONE        0x00000000U
00252 /**
00253   * @}
00254   */
00255 
00256 /** @defgroup RTC_StoreOperation_Definitions RTC Store Operation Definitions
00257   * @{
00258   */ 
00259 #define RTC_STOREOPERATION_RESET        0x00000000U
00260 #define RTC_STOREOPERATION_SET          0x00040000U
00261 /**
00262   * @}
00263   */
00264 
00265 /** @defgroup RTC_Input_parameter_format_definitions RTC Input Parameter Format Definitions
00266   * @{
00267   */ 
00268 #define RTC_FORMAT_BIN                      0x00000000U
00269 #define RTC_FORMAT_BCD                      0x00000001U
00270 /**
00271   * @}
00272   */
00273 
00274 /** @defgroup RTC_Month_Date_Definitions RTC Month Date Definitions
00275   * @{
00276   */ 
00277 /* Coded in BCD format */
00278 #define RTC_MONTH_JANUARY              ((uint8_t)0x01)
00279 #define RTC_MONTH_FEBRUARY             ((uint8_t)0x02)
00280 #define RTC_MONTH_MARCH                ((uint8_t)0x03)
00281 #define RTC_MONTH_APRIL                ((uint8_t)0x04)
00282 #define RTC_MONTH_MAY                  ((uint8_t)0x05)
00283 #define RTC_MONTH_JUNE                 ((uint8_t)0x06)
00284 #define RTC_MONTH_JULY                 ((uint8_t)0x07)
00285 #define RTC_MONTH_AUGUST               ((uint8_t)0x08)
00286 #define RTC_MONTH_SEPTEMBER            ((uint8_t)0x09)
00287 #define RTC_MONTH_OCTOBER              ((uint8_t)0x10)
00288 #define RTC_MONTH_NOVEMBER             ((uint8_t)0x11)
00289 #define RTC_MONTH_DECEMBER             ((uint8_t)0x12)
00290 /**
00291   * @}
00292   */ 
00293 
00294 /** @defgroup RTC_WeekDay_Definitions RTC WeekDay Definitions
00295   * @{
00296   */   
00297 #define RTC_WEEKDAY_MONDAY             ((uint8_t)0x01)
00298 #define RTC_WEEKDAY_TUESDAY            ((uint8_t)0x02)
00299 #define RTC_WEEKDAY_WEDNESDAY          ((uint8_t)0x03)
00300 #define RTC_WEEKDAY_THURSDAY           ((uint8_t)0x04)
00301 #define RTC_WEEKDAY_FRIDAY             ((uint8_t)0x05)
00302 #define RTC_WEEKDAY_SATURDAY           ((uint8_t)0x06)
00303 #define RTC_WEEKDAY_SUNDAY             ((uint8_t)0x07)
00304 /**
00305   * @}
00306   */ 
00307 
00308 /** @defgroup RTC_AlarmDateWeekDay_Definitions RTC Alarm Date WeekDay Definitions
00309   * @{
00310   */ 
00311 #define RTC_ALARMDATEWEEKDAYSEL_DATE      0x00000000U
00312 #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY   0x40000000U
00313 /**
00314   * @}
00315   */ 
00316 
00317 /** @defgroup RTC_AlarmMask_Definitions RTC Alarm Mask Definitions
00318   * @{
00319   */ 
00320 #define RTC_ALARMMASK_NONE                0x00000000U
00321 #define RTC_ALARMMASK_DATEWEEKDAY         RTC_ALRMAR_MSK4
00322 #define RTC_ALARMMASK_HOURS               RTC_ALRMAR_MSK3
00323 #define RTC_ALARMMASK_MINUTES             RTC_ALRMAR_MSK2
00324 #define RTC_ALARMMASK_SECONDS             RTC_ALRMAR_MSK1
00325 #define RTC_ALARMMASK_ALL                 0x80808080U
00326 /**
00327   * @}
00328   */ 
00329 
00330 /** @defgroup RTC_Alarms_Definitions RTC Alarms Definitions
00331   * @{
00332   */ 
00333 #define RTC_ALARM_A                       RTC_CR_ALRAE
00334 #define RTC_ALARM_B                       RTC_CR_ALRBE
00335 /**
00336   * @}
00337   */ 
00338 
00339 /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions RTC Alarm Sub Seconds Masks Definitions
00340   * @{
00341   */ 
00342 #define RTC_ALARMSUBSECONDMASK_ALL         0x00000000U  /*!< All Alarm SS fields are masked. 
00343                                                                         There is no comparison on sub seconds 
00344                                                                         for Alarm */
00345 #define RTC_ALARMSUBSECONDMASK_SS14_1      0x01000000U  /*!< SS[14:1] are don't care in Alarm 
00346                                                                         comparison. Only SS[0] is compared.    */
00347 #define RTC_ALARMSUBSECONDMASK_SS14_2      0x02000000U  /*!< SS[14:2] are don't care in Alarm 
00348                                                                         comparison. Only SS[1:0] are compared  */
00349 #define RTC_ALARMSUBSECONDMASK_SS14_3      0x03000000U  /*!< SS[14:3] are don't care in Alarm 
00350                                                                         comparison. Only SS[2:0] are compared  */
00351 #define RTC_ALARMSUBSECONDMASK_SS14_4      0x04000000U  /*!< SS[14:4] are don't care in Alarm 
00352                                                                         comparison. Only SS[3:0] are compared  */
00353 #define RTC_ALARMSUBSECONDMASK_SS14_5      0x05000000U  /*!< SS[14:5] are don't care in Alarm 
00354                                                                         comparison. Only SS[4:0] are compared  */
00355 #define RTC_ALARMSUBSECONDMASK_SS14_6      0x06000000U  /*!< SS[14:6] are don't care in Alarm 
00356                                                                         comparison. Only SS[5:0] are compared  */
00357 #define RTC_ALARMSUBSECONDMASK_SS14_7      0x07000000U  /*!< SS[14:7] are don't care in Alarm 
00358                                                                         comparison. Only SS[6:0] are compared  */
00359 #define RTC_ALARMSUBSECONDMASK_SS14_8      0x08000000U  /*!< SS[14:8] are don't care in Alarm 
00360                                                                         comparison. Only SS[7:0] are compared  */
00361 #define RTC_ALARMSUBSECONDMASK_SS14_9      0x09000000U  /*!< SS[14:9] are don't care in Alarm 
00362                                                                         comparison. Only SS[8:0] are compared  */
00363 #define RTC_ALARMSUBSECONDMASK_SS14_10     0x0A000000U  /*!< SS[14:10] are don't care in Alarm 
00364                                                                         comparison. Only SS[9:0] are compared  */
00365 #define RTC_ALARMSUBSECONDMASK_SS14_11     0x0B000000U  /*!< SS[14:11] are don't care in Alarm 
00366                                                                         comparison. Only SS[10:0] are compared */
00367 #define RTC_ALARMSUBSECONDMASK_SS14_12     0x0C000000U  /*!< SS[14:12] are don't care in Alarm 
00368                                                                         comparison.Only SS[11:0] are compared  */
00369 #define RTC_ALARMSUBSECONDMASK_SS14_13     0x0D000000U  /*!< SS[14:13] are don't care in Alarm 
00370                                                                         comparison. Only SS[12:0] are compared */
00371 #define RTC_ALARMSUBSECONDMASK_SS14        0x0E000000U  /*!< SS[14] is don't care in Alarm 
00372                                                                         comparison.Only SS[13:0] are compared  */
00373 #define RTC_ALARMSUBSECONDMASK_NONE        0x0F000000U  /*!< SS[14:0] are compared and must match 
00374                                                                         to activate alarm. */
00375 /**
00376   * @}
00377   */   
00378 
00379 /** @defgroup RTC_Interrupts_Definitions RTC Interrupts Definitions
00380   * @{
00381   */ 
00382 #define RTC_IT_TS                         0x00008000U
00383 #define RTC_IT_WUT                        0x00004000U
00384 #define RTC_IT_ALRB                       0x00002000U
00385 #define RTC_IT_ALRA                       0x00001000U
00386 #define RTC_IT_TAMP                       0x00000004U /* Used only to Enable the Tamper Interrupt */
00387 #define RTC_IT_TAMP1                      0x00020000U
00388 #define RTC_IT_TAMP2                      0x00040000U
00389 /**
00390   * @}
00391   */
00392 
00393 /** @defgroup RTC_Flags_Definitions RTC Flags Definitions
00394   * @{
00395   */ 
00396 #define RTC_FLAG_RECALPF                  0x00010000U
00397 #define RTC_FLAG_TAMP2F                   0x00004000U
00398 #define RTC_FLAG_TAMP1F                   0x00002000U
00399 #define RTC_FLAG_TSOVF                    0x00001000U
00400 #define RTC_FLAG_TSF                      0x00000800U
00401 #define RTC_FLAG_WUTF                     0x00000400U
00402 #define RTC_FLAG_ALRBF                    0x00000200U
00403 #define RTC_FLAG_ALRAF                    0x00000100U
00404 #define RTC_FLAG_INITF                    0x00000040U
00405 #define RTC_FLAG_RSF                      0x00000020U
00406 #define RTC_FLAG_INITS                    0x00000010U
00407 #define RTC_FLAG_SHPF                     0x00000008U
00408 #define RTC_FLAG_WUTWF                    0x00000004U
00409 #define RTC_FLAG_ALRBWF                   0x00000002U
00410 #define RTC_FLAG_ALRAWF                   0x00000001U
00411 /**
00412   * @}
00413   */
00414 
00415 /**
00416   * @}
00417   */ 
00418   
00419 /* Exported macro ------------------------------------------------------------*/
00420 /** @defgroup RTC_Exported_Macros RTC Exported Macros
00421   * @{
00422   */
00423 
00424 /** @brief Reset RTC handle state
00425   * @param  __HANDLE__ specifies the RTC handle.
00426   * @retval None
00427   */
00428 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET)
00429 
00430 /**
00431   * @brief  Disable the write protection for RTC registers.
00432   * @param  __HANDLE__ specifies the RTC handle.
00433   * @retval None
00434   */
00435 #define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__)             \
00436                         do{                                       \
00437                             (__HANDLE__)->Instance->WPR = 0xCAU;  \
00438                             (__HANDLE__)->Instance->WPR = 0x53U;  \
00439                           } while(0U)
00440 
00441 /**
00442   * @brief  Enable the write protection for RTC registers.
00443   * @param  __HANDLE__ specifies the RTC handle.
00444   * @retval None
00445   */
00446 #define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__)              \
00447                         do{                                       \
00448                             (__HANDLE__)->Instance->WPR = 0xFFU;  \
00449                           } while(0U)                            
00450  
00451 /**
00452   * @brief  Enable the RTC ALARMA peripheral.
00453   * @param  __HANDLE__ specifies the RTC handle.
00454   * @retval None
00455   */
00456 #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__)                           ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE))
00457 
00458 /**
00459   * @brief  Disable the RTC ALARMA peripheral.
00460   * @param  __HANDLE__ specifies the RTC handle.
00461   * @retval None
00462   */
00463 #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__)                          ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE))
00464 
00465 /**
00466   * @brief  Enable the RTC ALARMB peripheral.
00467   * @param  __HANDLE__ specifies the RTC handle.
00468   * @retval None
00469   */
00470 #define __HAL_RTC_ALARMB_ENABLE(__HANDLE__)                           ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRBE))
00471 
00472 /**
00473   * @brief  Disable the RTC ALARMB peripheral.
00474   * @param  __HANDLE__ specifies the RTC handle.
00475   * @retval None
00476   */
00477 #define __HAL_RTC_ALARMB_DISABLE(__HANDLE__)                          ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRBE))
00478 
00479 /**
00480   * @brief  Enable the RTC Alarm interrupt.
00481   * @param  __HANDLE__ specifies the RTC handle.
00482   * @param  __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled. 
00483   *          This parameter can be any combination of the following values:
00484   *             @arg RTC_IT_ALRA: Alarm A interrupt
00485   *             @arg RTC_IT_ALRB: Alarm B interrupt  
00486   * @retval None
00487   */   
00488 #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__)          ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
00489 
00490 /**
00491   * @brief  Disable the RTC Alarm interrupt.
00492   * @param  __HANDLE__ specifies the RTC handle.
00493   * @param  __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled. 
00494   *         This parameter can be any combination of the following values:
00495   *            @arg RTC_IT_ALRA: Alarm A interrupt
00496   *            @arg RTC_IT_ALRB: Alarm B interrupt  
00497   * @retval None
00498   */
00499 #define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__)         ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
00500 
00501 /**
00502   * @brief  Check whether the specified RTC Alarm interrupt has occurred or not.
00503   * @param  __HANDLE__ specifies the RTC handle.
00504   * @param  __INTERRUPT__ specifies the RTC Alarm interrupt to check.
00505   *         This parameter can be:
00506   *            @arg RTC_IT_ALRA: Alarm A interrupt
00507   *            @arg RTC_IT_ALRB: Alarm B interrupt  
00508   * @retval None
00509   */
00510 #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__)           (((((__HANDLE__)->Instance->ISR)& ((__INTERRUPT__)>> 4U)) != RESET)? SET : RESET)
00511 
00512 /**
00513   * @brief  Get the selected RTC Alarm's flag status.
00514   * @param  __HANDLE__ specifies the RTC handle.
00515   * @param  __FLAG__ specifies the RTC Alarm Flag to check.
00516   *         This parameter can be:
00517   *            @arg RTC_FLAG_ALRAF
00518   *            @arg RTC_FLAG_ALRBF
00519   *            @arg RTC_FLAG_ALRAWF     
00520   *            @arg RTC_FLAG_ALRBWF    
00521   * @retval None
00522   */
00523 #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__)                (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != RESET)? SET : RESET)
00524 
00525 /**
00526   * @brief  Clear the RTC Alarm's pending flags.
00527   * @param  __HANDLE__ specifies the RTC handle.
00528   * @param  __FLAG__ specifies the RTC Alarm Flag sources to be enabled or disabled.
00529   *          This parameter can be:
00530   *             @arg RTC_FLAG_ALRAF
00531   *             @arg RTC_FLAG_ALRBF 
00532   * @retval None
00533   */
00534 #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__)                  ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
00535   
00536   
00537 /**
00538   * @brief  Check whether the specified RTC Alarm interrupt has been enabled or not.
00539   * @param  __HANDLE__ specifies the RTC handle.
00540   * @param  __INTERRUPT__ specifies the RTC Alarm interrupt sources to check.
00541   *         This parameter can be:
00542   *            @arg RTC_IT_ALRA: Alarm A interrupt
00543   *            @arg RTC_IT_ALRB: Alarm B interrupt
00544   * @retval None
00545   */
00546 #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)     (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != RESET) ? SET : RESET)
00547 
00548 /**
00549   * @brief  Enable interrupt on the RTC Alarm associated Exti line.
00550   * @retval None
00551   */
00552 #define __HAL_RTC_ALARM_EXTI_ENABLE_IT()            (EXTI->IMR |= RTC_EXTI_LINE_ALARM_EVENT)
00553 
00554 /**
00555   * @brief  Disable interrupt on the RTC Alarm associated Exti line.
00556   * @retval None
00557   */
00558 #define __HAL_RTC_ALARM_EXTI_DISABLE_IT()           (EXTI->IMR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
00559 
00560 /**
00561   * @brief  Enable event on the RTC Alarm associated Exti line.
00562   * @retval None.
00563   */
00564 #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT()         (EXTI->EMR |= RTC_EXTI_LINE_ALARM_EVENT)
00565 
00566 /**
00567   * @brief  Disable event on the RTC Alarm associated Exti line.
00568   * @retval None.
00569   */
00570 #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT()         (EXTI->EMR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
00571 
00572 /**
00573   * @brief  Enable falling edge trigger on the RTC Alarm associated Exti line.  
00574   * @retval None.
00575   */
00576 #define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE()   (EXTI->FTSR |= RTC_EXTI_LINE_ALARM_EVENT)
00577 
00578 /**
00579   * @brief  Disable falling edge trigger on the RTC Alarm associated Exti line.  
00580   * @retval None.
00581   */
00582 #define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE()  (EXTI->FTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
00583 
00584 /**
00585   * @brief  Enable rising edge trigger on the RTC Alarm associated Exti line.  
00586   * @retval None.
00587   */
00588 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE()    (EXTI->RTSR |= RTC_EXTI_LINE_ALARM_EVENT)
00589 
00590 /**
00591   * @brief  Disable rising edge trigger on the RTC Alarm associated Exti line.  
00592   * @retval None.
00593   */
00594 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE()   (EXTI->RTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
00595 
00596 /**
00597   * @brief  Enable rising & falling edge trigger on the RTC Alarm associated Exti line.  
00598   * @retval None.
00599   */
00600 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE() do { __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE(); \
00601                                                                __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE();\
00602                                                              } while(0U)  
00603 
00604 /**
00605   * @brief  Disable rising & falling edge trigger on the RTC Alarm associated Exti line.  
00606   * @retval None.
00607   */
00608 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() do { __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE();\
00609                                                                 __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE();\
00610                                                               } while(0U)   
00611 
00612 /**
00613   * @brief Check whether the RTC Alarm associated Exti line interrupt flag is set or not.
00614   * @retval Line Status.
00615   */
00616 #define __HAL_RTC_ALARM_EXTI_GET_FLAG()              (EXTI->PR & RTC_EXTI_LINE_ALARM_EVENT)
00617 
00618 /**
00619   * @brief Clear the RTC Alarm associated Exti line flag.
00620   * @retval None.
00621   */
00622 #define __HAL_RTC_ALARM_EXTI_CLEAR_FLAG()            (EXTI->PR = RTC_EXTI_LINE_ALARM_EVENT)
00623 
00624 /**
00625   * @brief Generate a Software interrupt on RTC Alarm associated Exti line.
00626   * @retval None.
00627   */
00628 #define __HAL_RTC_ALARM_EXTI_GENERATE_SWIT()         (EXTI->SWIER |= RTC_EXTI_LINE_ALARM_EVENT)
00629 /**
00630   * @}
00631   */
00632 
00633 /* Include RTC HAL Extension module */
00634 #include "stm32f4xx_hal_rtc_ex.h"
00635 
00636 /* Exported functions --------------------------------------------------------*/
00637 /** @addtogroup RTC_Exported_Functions
00638   * @{
00639   */
00640 
00641 /** @addtogroup RTC_Exported_Functions_Group1
00642   * @{
00643   */
00644 /* Initialization and de-initialization functions  ****************************/
00645 HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc);
00646 HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc);
00647 void       HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc);
00648 void       HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc);
00649 /**
00650   * @}
00651   */
00652 
00653 /** @addtogroup RTC_Exported_Functions_Group2
00654   * @{
00655   */
00656 /* RTC Time and Date functions ************************************************/
00657 HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
00658 HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
00659 HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
00660 HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
00661 /**
00662   * @}
00663   */
00664 
00665 /** @addtogroup RTC_Exported_Functions_Group3
00666   * @{
00667   */
00668 /* RTC Alarm functions ********************************************************/
00669 HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
00670 HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
00671 HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm);
00672 HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format);
00673 void                HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc);
00674 HAL_StatusTypeDef   HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
00675 void         HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc);
00676 /**
00677   * @}
00678   */
00679 
00680 /** @addtogroup RTC_Exported_Functions_Group4
00681   * @{
00682   */
00683 /* Peripheral Control functions ***********************************************/
00684 HAL_StatusTypeDef   HAL_RTC_WaitForSynchro(RTC_HandleTypeDef* hrtc);
00685 /**
00686   * @}
00687   */
00688 
00689 /** @addtogroup RTC_Exported_Functions_Group5
00690   * @{
00691   */
00692 /* Peripheral State functions *************************************************/
00693 HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc);
00694 /**
00695   * @}
00696   */
00697 
00698 /**
00699   * @}
00700   */
00701 
00702 /* Private types -------------------------------------------------------------*/
00703 /* Private variables ---------------------------------------------------------*/
00704 /* Private constants ---------------------------------------------------------*/
00705 /** @defgroup RTC_Private_Constants RTC Private Constants
00706   * @{
00707   */
00708 /* Masks Definition */
00709 #define RTC_TR_RESERVED_MASK    0x007F7F7FU
00710 #define RTC_DR_RESERVED_MASK    0x00FFFF3FU
00711 #define RTC_INIT_MASK           0xFFFFFFFFU
00712 #define RTC_RSF_MASK            0xFFFFFF5FU
00713 #define RTC_FLAGS_MASK          ((uint32_t)(RTC_FLAG_TSOVF | RTC_FLAG_TSF | RTC_FLAG_WUTF | \
00714                                             RTC_FLAG_ALRBF | RTC_FLAG_ALRAF | RTC_FLAG_INITF | \
00715                                             RTC_FLAG_RSF | RTC_FLAG_INITS | RTC_FLAG_WUTWF | \
00716                                             RTC_FLAG_ALRBWF | RTC_FLAG_ALRAWF | RTC_FLAG_TAMP1F | \
00717                                             RTC_FLAG_RECALPF | RTC_FLAG_SHPF))
00718 
00719 #define RTC_TIMEOUT_VALUE       1000
00720 
00721 #define RTC_EXTI_LINE_ALARM_EVENT             ((uint32_t)EXTI_IMR_MR17)  /*!< External interrupt line 17 Connected to the RTC Alarm event */
00722 /**
00723   * @}
00724   */
00725 
00726 /* Private macros ------------------------------------------------------------*/
00727 /** @defgroup RTC_Private_Macros RTC Private Macros
00728   * @{
00729   */
00730 
00731 /** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters
00732   * @{
00733   */
00734 #define IS_RTC_HOUR_FORMAT(FORMAT)     (((FORMAT) == RTC_HOURFORMAT_12) || \
00735                                         ((FORMAT) == RTC_HOURFORMAT_24))
00736 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \
00737                                ((OUTPUT) == RTC_OUTPUT_ALARMA)  || \
00738                                ((OUTPUT) == RTC_OUTPUT_ALARMB)  || \
00739                                ((OUTPUT) == RTC_OUTPUT_WAKEUP))
00740 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \
00741                                 ((POL) == RTC_OUTPUT_POLARITY_LOW))
00742 #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \
00743                                   ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL))
00744 #define IS_RTC_HOUR12(HOUR)            (((HOUR) > 0U) && ((HOUR) <= 12U))
00745 #define IS_RTC_HOUR24(HOUR)            ((HOUR) <= 23U)
00746 #define IS_RTC_ASYNCH_PREDIV(PREDIV)   ((PREDIV) <= 0x7FU)
00747 #define IS_RTC_SYNCH_PREDIV(PREDIV)    ((PREDIV) <= 0x7FFFU)
00748 #define IS_RTC_MINUTES(MINUTES)        ((MINUTES) <= 59U)
00749 #define IS_RTC_SECONDS(SECONDS)        ((SECONDS) <= 59U)
00750 
00751 #define IS_RTC_HOURFORMAT12(PM)  (((PM) == RTC_HOURFORMAT12_AM) || ((PM) == RTC_HOURFORMAT12_PM))
00752 #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \
00753                                       ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \
00754                                       ((SAVE) == RTC_DAYLIGHTSAVING_NONE))
00755 #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \
00756                                            ((OPERATION) == RTC_STOREOPERATION_SET))
00757 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || ((FORMAT) == RTC_FORMAT_BCD))
00758 #define IS_RTC_YEAR(YEAR)              ((YEAR) <= 99U)
00759 #define IS_RTC_MONTH(MONTH)            (((MONTH) >= 1U) && ((MONTH) <= 12U))
00760 #define IS_RTC_DATE(DATE)              (((DATE) >= 1U) && ((DATE) <= 31U))
00761 #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY)    || \
00762                                  ((WEEKDAY) == RTC_WEEKDAY_TUESDAY)   || \
00763                                  ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
00764                                  ((WEEKDAY) == RTC_WEEKDAY_THURSDAY)  || \
00765                                  ((WEEKDAY) == RTC_WEEKDAY_FRIDAY)    || \
00766                                  ((WEEKDAY) == RTC_WEEKDAY_SATURDAY)  || \
00767                                  ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
00768 #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) > 0U) && ((DATE) <= 31U))
00769 #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY)    || \
00770                                                     ((WEEKDAY) == RTC_WEEKDAY_TUESDAY)   || \
00771                                                     ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
00772                                                     ((WEEKDAY) == RTC_WEEKDAY_THURSDAY)  || \
00773                                                     ((WEEKDAY) == RTC_WEEKDAY_FRIDAY)    || \
00774                                                     ((WEEKDAY) == RTC_WEEKDAY_SATURDAY)  || \
00775                                                     ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
00776 #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \
00777                                             ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY))
00778 #define IS_RTC_ALARM_MASK(MASK)  (((MASK) & 0x7F7F7F7FU) == (uint32_t)RESET)
00779 #define IS_RTC_ALARM(ALARM)      (((ALARM) == RTC_ALARM_A) || ((ALARM) == RTC_ALARM_B))
00780 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= 0x00007FFFU)
00781 
00782 #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK)   (((MASK) == RTC_ALARMSUBSECONDMASK_ALL) || \
00783                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_1) || \
00784                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_2) || \
00785                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_3) || \
00786                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_4) || \
00787                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_5) || \
00788                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_6) || \
00789                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_7) || \
00790                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_8) || \
00791                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_9) || \
00792                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_10) || \
00793                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_11) || \
00794                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_12) || \
00795                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_13) || \
00796                                               ((MASK) == RTC_ALARMSUBSECONDMASK_SS14) || \
00797                                               ((MASK) == RTC_ALARMSUBSECONDMASK_NONE))
00798 /**
00799   * @}
00800   */
00801 
00802 /**
00803   * @}
00804   */
00805 
00806 /* Private functions ---------------------------------------------------------*/
00807 /** @defgroup RTC_Private_Functions RTC Private Functions
00808   * @{
00809   */
00810 HAL_StatusTypeDef  RTC_EnterInitMode(RTC_HandleTypeDef* hrtc);
00811 uint8_t            RTC_ByteToBcd2(uint8_t Value);
00812 uint8_t            RTC_Bcd2ToByte(uint8_t Value);
00813 /**
00814   * @}
00815   */
00816 
00817 /**
00818   * @}
00819   */ 
00820 
00821 /**
00822   * @}
00823   */ 
00824   
00825 #ifdef __cplusplus
00826 }
00827 #endif
00828 
00829 #endif /* __STM32F4xx_HAL_RTC_H */
00830 
00831 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/