stm32f4xx_hal_rtc.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_rtc.h
  4. * @author MCD Application Team
  5. * @brief Header file of RTC HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef __STM32F4xx_HAL_RTC_H
  21. #define __STM32F4xx_HAL_RTC_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32f4xx_hal_def.h"
  27. /** @addtogroup STM32F4xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup RTC
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup RTC_Exported_Types RTC Exported Types
  35. * @{
  36. */
  37. /**
  38. * @brief HAL State structures definition
  39. */
  40. typedef enum
  41. {
  42. HAL_RTC_STATE_RESET = 0x00U, /*!< RTC not yet initialized or disabled */
  43. HAL_RTC_STATE_READY = 0x01U, /*!< RTC initialized and ready for use */
  44. HAL_RTC_STATE_BUSY = 0x02U, /*!< RTC process is ongoing */
  45. HAL_RTC_STATE_TIMEOUT = 0x03U, /*!< RTC timeout state */
  46. HAL_RTC_STATE_ERROR = 0x04U /*!< RTC error state */
  47. }HAL_RTCStateTypeDef;
  48. /**
  49. * @brief RTC Configuration Structure definition
  50. */
  51. typedef struct
  52. {
  53. uint32_t HourFormat; /*!< Specifies the RTC Hour Format.
  54. This parameter can be a value of @ref RTC_Hour_Formats */
  55. uint32_t AsynchPrediv; /*!< Specifies the RTC Asynchronous Predivider value.
  56. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7F */
  57. uint32_t SynchPrediv; /*!< Specifies the RTC Synchronous Predivider value.
  58. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7FFFU */
  59. uint32_t OutPut; /*!< Specifies which signal will be routed to the RTC output.
  60. This parameter can be a value of @ref RTC_Output_selection_Definitions */
  61. uint32_t OutPutPolarity; /*!< Specifies the polarity of the output signal.
  62. This parameter can be a value of @ref RTC_Output_Polarity_Definitions */
  63. uint32_t OutPutType; /*!< Specifies the RTC Output Pin mode.
  64. This parameter can be a value of @ref RTC_Output_Type_ALARM_OUT */
  65. }RTC_InitTypeDef;
  66. /**
  67. * @brief RTC Time structure definition
  68. */
  69. typedef struct
  70. {
  71. uint8_t Hours; /*!< Specifies the RTC Time Hour.
  72. This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected.
  73. This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected */
  74. uint8_t Minutes; /*!< Specifies the RTC Time Minutes.
  75. This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
  76. uint8_t Seconds; /*!< Specifies the RTC Time Seconds.
  77. This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
  78. uint8_t TimeFormat; /*!< Specifies the RTC AM/PM Time.
  79. This parameter can be a value of @ref RTC_AM_PM_Definitions */
  80. uint32_t SubSeconds; /*!< Specifies the RTC_SSR RTC Sub Second register content.
  81. This parameter corresponds to a time unit range between [0-1] Second
  82. with [1 Sec / SecondFraction +1] granularity */
  83. uint32_t SecondFraction; /*!< Specifies the range or granularity of Sub Second register content
  84. corresponding to Synchronous pre-scaler factor value (PREDIV_S)
  85. This parameter corresponds to a time unit range between [0-1] Second
  86. with [1 Sec / SecondFraction +1] granularity.
  87. This field will be used only by HAL_RTC_GetTime function */
  88. uint32_t DayLightSaving; /*!< Specifies DayLight Save Operation.
  89. This parameter can be a value of @ref RTC_DayLightSaving_Definitions */
  90. uint32_t StoreOperation; /*!< Specifies RTC_StoreOperation value to be written in the BCK bit
  91. in CR register to store the operation.
  92. This parameter can be a value of @ref RTC_StoreOperation_Definitions */
  93. }RTC_TimeTypeDef;
  94. /**
  95. * @brief RTC Date structure definition
  96. */
  97. typedef struct
  98. {
  99. uint8_t WeekDay; /*!< Specifies the RTC Date WeekDay.
  100. This parameter can be a value of @ref RTC_WeekDay_Definitions */
  101. uint8_t Month; /*!< Specifies the RTC Date Month (in BCD format).
  102. This parameter can be a value of @ref RTC_Month_Date_Definitions */
  103. uint8_t Date; /*!< Specifies the RTC Date.
  104. This parameter must be a number between Min_Data = 1 and Max_Data = 31 */
  105. uint8_t Year; /*!< Specifies the RTC Date Year.
  106. This parameter must be a number between Min_Data = 0 and Max_Data = 99 */
  107. }RTC_DateTypeDef;
  108. /**
  109. * @brief RTC Alarm structure definition
  110. */
  111. typedef struct
  112. {
  113. RTC_TimeTypeDef AlarmTime; /*!< Specifies the RTC Alarm Time members */
  114. uint32_t AlarmMask; /*!< Specifies the RTC Alarm Masks.
  115. This parameter can be a value of @ref RTC_AlarmMask_Definitions */
  116. uint32_t AlarmSubSecondMask; /*!< Specifies the RTC Alarm SubSeconds Masks.
  117. This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */
  118. uint32_t AlarmDateWeekDaySel; /*!< Specifies the RTC Alarm is on Date or WeekDay.
  119. This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */
  120. uint8_t AlarmDateWeekDay; /*!< Specifies the RTC Alarm Date/WeekDay.
  121. If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range.
  122. If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */
  123. uint32_t Alarm; /*!< Specifies the alarm .
  124. This parameter can be a value of @ref RTC_Alarms_Definitions */
  125. }RTC_AlarmTypeDef;
  126. /**
  127. * @brief RTC Handle Structure definition
  128. */
  129. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  130. typedef struct __RTC_HandleTypeDef
  131. #else
  132. typedef struct
  133. #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */
  134. {
  135. RTC_TypeDef *Instance; /*!< Register base address */
  136. RTC_InitTypeDef Init; /*!< RTC required parameters */
  137. HAL_LockTypeDef Lock; /*!< RTC locking object */
  138. __IO HAL_RTCStateTypeDef State; /*!< Time communication state */
  139. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  140. void (* AlarmAEventCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC Alarm A Event callback */
  141. void (* AlarmBEventCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC Alarm B Event callback */
  142. void (* TimeStampEventCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC TimeStamp Event callback */
  143. void (* WakeUpTimerEventCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC WakeUpTimer Event callback */
  144. void (* Tamper1EventCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC Tamper 1 Event callback */
  145. void (* Tamper2EventCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC Tamper 2 Event callback */
  146. void (* MspInitCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC Msp Init callback */
  147. void (* MspDeInitCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC Msp DeInit callback */
  148. #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */
  149. }RTC_HandleTypeDef;
  150. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  151. /**
  152. * @brief HAL RTC Callback ID enumeration definition
  153. */
  154. typedef enum
  155. {
  156. HAL_RTC_ALARM_A_EVENT_CB_ID = 0x00u, /*!< RTC Alarm A Event Callback ID */
  157. HAL_RTC_ALARM_B_EVENT_CB_ID = 0x01u, /*!< RTC Alarm B Event Callback ID */
  158. HAL_RTC_TIMESTAMP_EVENT_CB_ID = 0x02u, /*!< RTC TimeStamp Event Callback ID */
  159. HAL_RTC_WAKEUPTIMER_EVENT_CB_ID = 0x03u, /*!< RTC Wake-Up Timer Event Callback ID */
  160. HAL_RTC_TAMPER1_EVENT_CB_ID = 0x04u, /*!< RTC Tamper 1 Callback ID */
  161. HAL_RTC_TAMPER2_EVENT_CB_ID = 0x05u, /*!< RTC Tamper 2 Callback ID */
  162. HAL_RTC_MSPINIT_CB_ID = 0x0Eu, /*!< RTC Msp Init callback ID */
  163. HAL_RTC_MSPDEINIT_CB_ID = 0x0Fu /*!< RTC Msp DeInit callback ID */
  164. }HAL_RTC_CallbackIDTypeDef;
  165. /**
  166. * @brief HAL RTC Callback pointer definition
  167. */
  168. typedef void (*pRTC_CallbackTypeDef)(RTC_HandleTypeDef * hrtc); /*!< pointer to an RTC callback function */
  169. #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
  170. /**
  171. * @}
  172. */
  173. /* Exported constants --------------------------------------------------------*/
  174. /** @defgroup RTC_Exported_Constants RTC Exported Constants
  175. * @{
  176. */
  177. /** @defgroup RTC_Hour_Formats RTC Hour Formats
  178. * @{
  179. */
  180. #define RTC_HOURFORMAT_24 0x00000000U
  181. #define RTC_HOURFORMAT_12 0x00000040U
  182. /**
  183. * @}
  184. */
  185. /** @defgroup RTC_Output_selection_Definitions RTC Output Selection Definitions
  186. * @{
  187. */
  188. #define RTC_OUTPUT_DISABLE 0x00000000U
  189. #define RTC_OUTPUT_ALARMA 0x00200000U
  190. #define RTC_OUTPUT_ALARMB 0x00400000U
  191. #define RTC_OUTPUT_WAKEUP 0x00600000U
  192. /**
  193. * @}
  194. */
  195. /** @defgroup RTC_Output_Polarity_Definitions RTC Output Polarity Definitions
  196. * @{
  197. */
  198. #define RTC_OUTPUT_POLARITY_HIGH 0x00000000U
  199. #define RTC_OUTPUT_POLARITY_LOW 0x00100000U
  200. /**
  201. * @}
  202. */
  203. /** @defgroup RTC_Output_Type_ALARM_OUT RTC Output Type ALARM OUT
  204. * @{
  205. */
  206. #define RTC_OUTPUT_TYPE_OPENDRAIN 0x00000000U
  207. #define RTC_OUTPUT_TYPE_PUSHPULL 0x00040000U
  208. /**
  209. * @}
  210. */
  211. /** @defgroup RTC_AM_PM_Definitions RTC AM PM Definitions
  212. * @{
  213. */
  214. #define RTC_HOURFORMAT12_AM ((uint8_t)0x00)
  215. #define RTC_HOURFORMAT12_PM ((uint8_t)0x40)
  216. /**
  217. * @}
  218. */
  219. /** @defgroup RTC_DayLightSaving_Definitions RTC DayLight Saving Definitions
  220. * @{
  221. */
  222. #define RTC_DAYLIGHTSAVING_SUB1H 0x00020000U
  223. #define RTC_DAYLIGHTSAVING_ADD1H 0x00010000U
  224. #define RTC_DAYLIGHTSAVING_NONE 0x00000000U
  225. /**
  226. * @}
  227. */
  228. /** @defgroup RTC_StoreOperation_Definitions RTC Store Operation Definitions
  229. * @{
  230. */
  231. #define RTC_STOREOPERATION_RESET 0x00000000U
  232. #define RTC_STOREOPERATION_SET 0x00040000U
  233. /**
  234. * @}
  235. */
  236. /** @defgroup RTC_Input_parameter_format_definitions RTC Input Parameter Format Definitions
  237. * @{
  238. */
  239. #define RTC_FORMAT_BIN 0x00000000U
  240. #define RTC_FORMAT_BCD 0x00000001U
  241. /**
  242. * @}
  243. */
  244. /** @defgroup RTC_Month_Date_Definitions RTC Month Date Definitions
  245. * @{
  246. */
  247. /* Coded in BCD format */
  248. #define RTC_MONTH_JANUARY ((uint8_t)0x01)
  249. #define RTC_MONTH_FEBRUARY ((uint8_t)0x02)
  250. #define RTC_MONTH_MARCH ((uint8_t)0x03)
  251. #define RTC_MONTH_APRIL ((uint8_t)0x04)
  252. #define RTC_MONTH_MAY ((uint8_t)0x05)
  253. #define RTC_MONTH_JUNE ((uint8_t)0x06)
  254. #define RTC_MONTH_JULY ((uint8_t)0x07)
  255. #define RTC_MONTH_AUGUST ((uint8_t)0x08)
  256. #define RTC_MONTH_SEPTEMBER ((uint8_t)0x09)
  257. #define RTC_MONTH_OCTOBER ((uint8_t)0x10)
  258. #define RTC_MONTH_NOVEMBER ((uint8_t)0x11)
  259. #define RTC_MONTH_DECEMBER ((uint8_t)0x12)
  260. /**
  261. * @}
  262. */
  263. /** @defgroup RTC_WeekDay_Definitions RTC WeekDay Definitions
  264. * @{
  265. */
  266. #define RTC_WEEKDAY_MONDAY ((uint8_t)0x01)
  267. #define RTC_WEEKDAY_TUESDAY ((uint8_t)0x02)
  268. #define RTC_WEEKDAY_WEDNESDAY ((uint8_t)0x03)
  269. #define RTC_WEEKDAY_THURSDAY ((uint8_t)0x04)
  270. #define RTC_WEEKDAY_FRIDAY ((uint8_t)0x05)
  271. #define RTC_WEEKDAY_SATURDAY ((uint8_t)0x06)
  272. #define RTC_WEEKDAY_SUNDAY ((uint8_t)0x07)
  273. /**
  274. * @}
  275. */
  276. /** @defgroup RTC_AlarmDateWeekDay_Definitions RTC Alarm Date WeekDay Definitions
  277. * @{
  278. */
  279. #define RTC_ALARMDATEWEEKDAYSEL_DATE 0x00000000U
  280. #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY 0x40000000U
  281. /**
  282. * @}
  283. */
  284. /** @defgroup RTC_AlarmMask_Definitions RTC Alarm Mask Definitions
  285. * @{
  286. */
  287. #define RTC_ALARMMASK_NONE 0x00000000U
  288. #define RTC_ALARMMASK_DATEWEEKDAY RTC_ALRMAR_MSK4
  289. #define RTC_ALARMMASK_HOURS RTC_ALRMAR_MSK3
  290. #define RTC_ALARMMASK_MINUTES RTC_ALRMAR_MSK2
  291. #define RTC_ALARMMASK_SECONDS RTC_ALRMAR_MSK1
  292. #define RTC_ALARMMASK_ALL 0x80808080U
  293. /**
  294. * @}
  295. */
  296. /** @defgroup RTC_Alarms_Definitions RTC Alarms Definitions
  297. * @{
  298. */
  299. #define RTC_ALARM_A RTC_CR_ALRAE
  300. #define RTC_ALARM_B RTC_CR_ALRBE
  301. /**
  302. * @}
  303. */
  304. /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions RTC Alarm Sub Seconds Masks Definitions
  305. * @{
  306. */
  307. #define RTC_ALARMSUBSECONDMASK_ALL 0x00000000U /*!< All Alarm SS fields are masked.
  308. There is no comparison on sub seconds
  309. for Alarm */
  310. #define RTC_ALARMSUBSECONDMASK_SS14_1 0x01000000U /*!< SS[14:1] are don't care in Alarm
  311. comparison. Only SS[0] is compared. */
  312. #define RTC_ALARMSUBSECONDMASK_SS14_2 0x02000000U /*!< SS[14:2] are don't care in Alarm
  313. comparison. Only SS[1:0] are compared */
  314. #define RTC_ALARMSUBSECONDMASK_SS14_3 0x03000000U /*!< SS[14:3] are don't care in Alarm
  315. comparison. Only SS[2:0] are compared */
  316. #define RTC_ALARMSUBSECONDMASK_SS14_4 0x04000000U /*!< SS[14:4] are don't care in Alarm
  317. comparison. Only SS[3:0] are compared */
  318. #define RTC_ALARMSUBSECONDMASK_SS14_5 0x05000000U /*!< SS[14:5] are don't care in Alarm
  319. comparison. Only SS[4:0] are compared */
  320. #define RTC_ALARMSUBSECONDMASK_SS14_6 0x06000000U /*!< SS[14:6] are don't care in Alarm
  321. comparison. Only SS[5:0] are compared */
  322. #define RTC_ALARMSUBSECONDMASK_SS14_7 0x07000000U /*!< SS[14:7] are don't care in Alarm
  323. comparison. Only SS[6:0] are compared */
  324. #define RTC_ALARMSUBSECONDMASK_SS14_8 0x08000000U /*!< SS[14:8] are don't care in Alarm
  325. comparison. Only SS[7:0] are compared */
  326. #define RTC_ALARMSUBSECONDMASK_SS14_9 0x09000000U /*!< SS[14:9] are don't care in Alarm
  327. comparison. Only SS[8:0] are compared */
  328. #define RTC_ALARMSUBSECONDMASK_SS14_10 0x0A000000U /*!< SS[14:10] are don't care in Alarm
  329. comparison. Only SS[9:0] are compared */
  330. #define RTC_ALARMSUBSECONDMASK_SS14_11 0x0B000000U /*!< SS[14:11] are don't care in Alarm
  331. comparison. Only SS[10:0] are compared */
  332. #define RTC_ALARMSUBSECONDMASK_SS14_12 0x0C000000U /*!< SS[14:12] are don't care in Alarm
  333. comparison.Only SS[11:0] are compared */
  334. #define RTC_ALARMSUBSECONDMASK_SS14_13 0x0D000000U /*!< SS[14:13] are don't care in Alarm
  335. comparison. Only SS[12:0] are compared */
  336. #define RTC_ALARMSUBSECONDMASK_SS14 0x0E000000U /*!< SS[14] is don't care in Alarm
  337. comparison.Only SS[13:0] are compared */
  338. #define RTC_ALARMSUBSECONDMASK_NONE 0x0F000000U /*!< SS[14:0] are compared and must match
  339. to activate alarm. */
  340. /**
  341. * @}
  342. */
  343. /** @defgroup RTC_Interrupts_Definitions RTC Interrupts Definitions
  344. * @{
  345. */
  346. #define RTC_IT_TS 0x00008000U
  347. #define RTC_IT_WUT 0x00004000U
  348. #define RTC_IT_ALRB 0x00002000U
  349. #define RTC_IT_ALRA 0x00001000U
  350. #define RTC_IT_TAMP 0x00000004U /* Used only to Enable the Tamper Interrupt */
  351. #define RTC_IT_TAMP1 0x00020000U
  352. #define RTC_IT_TAMP2 0x00040000U
  353. /**
  354. * @}
  355. */
  356. /** @defgroup RTC_Flags_Definitions RTC Flags Definitions
  357. * @{
  358. */
  359. #define RTC_FLAG_RECALPF 0x00010000U
  360. #define RTC_FLAG_TAMP2F 0x00004000U
  361. #define RTC_FLAG_TAMP1F 0x00002000U
  362. #define RTC_FLAG_TSOVF 0x00001000U
  363. #define RTC_FLAG_TSF 0x00000800U
  364. #define RTC_FLAG_WUTF 0x00000400U
  365. #define RTC_FLAG_ALRBF 0x00000200U
  366. #define RTC_FLAG_ALRAF 0x00000100U
  367. #define RTC_FLAG_INITF 0x00000040U
  368. #define RTC_FLAG_RSF 0x00000020U
  369. #define RTC_FLAG_INITS 0x00000010U
  370. #define RTC_FLAG_SHPF 0x00000008U
  371. #define RTC_FLAG_WUTWF 0x00000004U
  372. #define RTC_FLAG_ALRBWF 0x00000002U
  373. #define RTC_FLAG_ALRAWF 0x00000001U
  374. /**
  375. * @}
  376. */
  377. /**
  378. * @}
  379. */
  380. /* Exported macro ------------------------------------------------------------*/
  381. /** @defgroup RTC_Exported_Macros RTC Exported Macros
  382. * @{
  383. */
  384. /** @brief Reset RTC handle state
  385. * @param __HANDLE__ specifies the RTC handle.
  386. * @retval None
  387. */
  388. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  389. #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) do{\
  390. (__HANDLE__)->State = HAL_RTC_STATE_RESET;\
  391. (__HANDLE__)->MspInitCallback = NULL;\
  392. (__HANDLE__)->MspDeInitCallback = NULL;\
  393. }while(0u)
  394. #else
  395. #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET)
  396. #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
  397. /**
  398. * @brief Disable the write protection for RTC registers.
  399. * @param __HANDLE__ specifies the RTC handle.
  400. * @retval None
  401. */
  402. #define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__) \
  403. do{ \
  404. (__HANDLE__)->Instance->WPR = 0xCAU; \
  405. (__HANDLE__)->Instance->WPR = 0x53U; \
  406. } while(0U)
  407. /**
  408. * @brief Enable the write protection for RTC registers.
  409. * @param __HANDLE__ specifies the RTC handle.
  410. * @retval None
  411. */
  412. #define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__) \
  413. do{ \
  414. (__HANDLE__)->Instance->WPR = 0xFFU; \
  415. } while(0U)
  416. /**
  417. * @brief Enable the RTC ALARMA peripheral.
  418. * @param __HANDLE__ specifies the RTC handle.
  419. * @retval None
  420. */
  421. #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE))
  422. /**
  423. * @brief Disable the RTC ALARMA peripheral.
  424. * @param __HANDLE__ specifies the RTC handle.
  425. * @retval None
  426. */
  427. #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE))
  428. /**
  429. * @brief Enable the RTC ALARMB peripheral.
  430. * @param __HANDLE__ specifies the RTC handle.
  431. * @retval None
  432. */
  433. #define __HAL_RTC_ALARMB_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRBE))
  434. /**
  435. * @brief Disable the RTC ALARMB peripheral.
  436. * @param __HANDLE__ specifies the RTC handle.
  437. * @retval None
  438. */
  439. #define __HAL_RTC_ALARMB_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRBE))
  440. /**
  441. * @brief Enable the RTC Alarm interrupt.
  442. * @param __HANDLE__ specifies the RTC handle.
  443. * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled.
  444. * This parameter can be any combination of the following values:
  445. * @arg RTC_IT_ALRA: Alarm A interrupt
  446. * @arg RTC_IT_ALRB: Alarm B interrupt
  447. * @retval None
  448. */
  449. #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
  450. /**
  451. * @brief Disable the RTC Alarm interrupt.
  452. * @param __HANDLE__ specifies the RTC handle.
  453. * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled.
  454. * This parameter can be any combination of the following values:
  455. * @arg RTC_IT_ALRA: Alarm A interrupt
  456. * @arg RTC_IT_ALRB: Alarm B interrupt
  457. * @retval None
  458. */
  459. #define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
  460. /**
  461. * @brief Check whether the specified RTC Alarm interrupt has occurred or not.
  462. * @param __HANDLE__ specifies the RTC handle.
  463. * @param __INTERRUPT__ specifies the RTC Alarm interrupt to check.
  464. * This parameter can be:
  465. * @arg RTC_IT_ALRA: Alarm A interrupt
  466. * @arg RTC_IT_ALRB: Alarm B interrupt
  467. * @retval None
  468. */
  469. #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->ISR)& ((__INTERRUPT__)>> 4U)) != RESET)? SET : RESET)
  470. /**
  471. * @brief Get the selected RTC Alarm's flag status.
  472. * @param __HANDLE__ specifies the RTC handle.
  473. * @param __FLAG__ specifies the RTC Alarm Flag to check.
  474. * This parameter can be:
  475. * @arg RTC_FLAG_ALRAF
  476. * @arg RTC_FLAG_ALRBF
  477. * @arg RTC_FLAG_ALRAWF
  478. * @arg RTC_FLAG_ALRBWF
  479. * @retval None
  480. */
  481. #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != RESET)? SET : RESET)
  482. /**
  483. * @brief Clear the RTC Alarm's pending flags.
  484. * @param __HANDLE__ specifies the RTC handle.
  485. * @param __FLAG__ specifies the RTC Alarm Flag sources to be enabled or disabled.
  486. * This parameter can be:
  487. * @arg RTC_FLAG_ALRAF
  488. * @arg RTC_FLAG_ALRBF
  489. * @retval None
  490. */
  491. #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
  492. /**
  493. * @brief Check whether the specified RTC Alarm interrupt has been enabled or not.
  494. * @param __HANDLE__ specifies the RTC handle.
  495. * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check.
  496. * This parameter can be:
  497. * @arg RTC_IT_ALRA: Alarm A interrupt
  498. * @arg RTC_IT_ALRB: Alarm B interrupt
  499. * @retval None
  500. */
  501. #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != RESET) ? SET : RESET)
  502. /**
  503. * @brief Enable interrupt on the RTC Alarm associated Exti line.
  504. * @retval None
  505. */
  506. #define __HAL_RTC_ALARM_EXTI_ENABLE_IT() (EXTI->IMR |= RTC_EXTI_LINE_ALARM_EVENT)
  507. /**
  508. * @brief Disable interrupt on the RTC Alarm associated Exti line.
  509. * @retval None
  510. */
  511. #define __HAL_RTC_ALARM_EXTI_DISABLE_IT() (EXTI->IMR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  512. /**
  513. * @brief Enable event on the RTC Alarm associated Exti line.
  514. * @retval None.
  515. */
  516. #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT() (EXTI->EMR |= RTC_EXTI_LINE_ALARM_EVENT)
  517. /**
  518. * @brief Disable event on the RTC Alarm associated Exti line.
  519. * @retval None.
  520. */
  521. #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT() (EXTI->EMR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  522. /**
  523. * @brief Enable falling edge trigger on the RTC Alarm associated Exti line.
  524. * @retval None.
  525. */
  526. #define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE() (EXTI->FTSR |= RTC_EXTI_LINE_ALARM_EVENT)
  527. /**
  528. * @brief Disable falling edge trigger on the RTC Alarm associated Exti line.
  529. * @retval None.
  530. */
  531. #define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE() (EXTI->FTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  532. /**
  533. * @brief Enable rising edge trigger on the RTC Alarm associated Exti line.
  534. * @retval None.
  535. */
  536. #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE() (EXTI->RTSR |= RTC_EXTI_LINE_ALARM_EVENT)
  537. /**
  538. * @brief Disable rising edge trigger on the RTC Alarm associated Exti line.
  539. * @retval None.
  540. */
  541. #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE() (EXTI->RTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  542. /**
  543. * @brief Enable rising & falling edge trigger on the RTC Alarm associated Exti line.
  544. * @retval None.
  545. */
  546. #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE() do { __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE(); \
  547. __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE();\
  548. } while(0U)
  549. /**
  550. * @brief Disable rising & falling edge trigger on the RTC Alarm associated Exti line.
  551. * @retval None.
  552. */
  553. #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() do { __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE();\
  554. __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE();\
  555. } while(0U)
  556. /**
  557. * @brief Check whether the RTC Alarm associated Exti line interrupt flag is set or not.
  558. * @retval Line Status.
  559. */
  560. #define __HAL_RTC_ALARM_EXTI_GET_FLAG() (EXTI->PR & RTC_EXTI_LINE_ALARM_EVENT)
  561. /**
  562. * @brief Clear the RTC Alarm associated Exti line flag.
  563. * @retval None.
  564. */
  565. #define __HAL_RTC_ALARM_EXTI_CLEAR_FLAG() (EXTI->PR = RTC_EXTI_LINE_ALARM_EVENT)
  566. /**
  567. * @brief Generate a Software interrupt on RTC Alarm associated Exti line.
  568. * @retval None.
  569. */
  570. #define __HAL_RTC_ALARM_EXTI_GENERATE_SWIT() (EXTI->SWIER |= RTC_EXTI_LINE_ALARM_EVENT)
  571. /**
  572. * @}
  573. */
  574. /* Include RTC HAL Extension module */
  575. #include "stm32f4xx_hal_rtc_ex.h"
  576. /* Exported functions --------------------------------------------------------*/
  577. /** @addtogroup RTC_Exported_Functions
  578. * @{
  579. */
  580. /** @addtogroup RTC_Exported_Functions_Group1
  581. * @{
  582. */
  583. /* Initialization and de-initialization functions ****************************/
  584. HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc);
  585. HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc);
  586. void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc);
  587. void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc);
  588. /* Callbacks Register/UnRegister functions ***********************************/
  589. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  590. HAL_StatusTypeDef HAL_RTC_RegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID, pRTC_CallbackTypeDef pCallback);
  591. HAL_StatusTypeDef HAL_RTC_UnRegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID);
  592. #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
  593. /**
  594. * @}
  595. */
  596. /** @addtogroup RTC_Exported_Functions_Group2
  597. * @{
  598. */
  599. /* RTC Time and Date functions ************************************************/
  600. HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
  601. HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
  602. HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
  603. HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
  604. /**
  605. * @}
  606. */
  607. /** @addtogroup RTC_Exported_Functions_Group3
  608. * @{
  609. */
  610. /* RTC Alarm functions ********************************************************/
  611. HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
  612. HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
  613. HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm);
  614. HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format);
  615. void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc);
  616. HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
  617. void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc);
  618. /**
  619. * @}
  620. */
  621. /** @addtogroup RTC_Exported_Functions_Group4
  622. * @{
  623. */
  624. /* Peripheral Control functions ***********************************************/
  625. HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef* hrtc);
  626. /**
  627. * @}
  628. */
  629. /** @addtogroup RTC_Exported_Functions_Group5
  630. * @{
  631. */
  632. /* Peripheral State functions *************************************************/
  633. HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc);
  634. /**
  635. * @}
  636. */
  637. /**
  638. * @}
  639. */
  640. /* Private types -------------------------------------------------------------*/
  641. /* Private variables ---------------------------------------------------------*/
  642. /* Private constants ---------------------------------------------------------*/
  643. /** @defgroup RTC_Private_Constants RTC Private Constants
  644. * @{
  645. */
  646. /* Masks Definition */
  647. #define RTC_TR_RESERVED_MASK 0x007F7F7FU
  648. #define RTC_DR_RESERVED_MASK 0x00FFFF3FU
  649. #define RTC_INIT_MASK 0xFFFFFFFFU
  650. #define RTC_RSF_MASK 0xFFFFFF5FU
  651. #define RTC_FLAGS_MASK ((uint32_t)(RTC_FLAG_TSOVF | RTC_FLAG_TSF | RTC_FLAG_WUTF | \
  652. RTC_FLAG_ALRBF | RTC_FLAG_ALRAF | RTC_FLAG_INITF | \
  653. RTC_FLAG_RSF | RTC_FLAG_INITS | RTC_FLAG_WUTWF | \
  654. RTC_FLAG_ALRBWF | RTC_FLAG_ALRAWF | RTC_FLAG_TAMP1F | \
  655. RTC_FLAG_RECALPF | RTC_FLAG_SHPF))
  656. #define RTC_TIMEOUT_VALUE 1000
  657. #define RTC_EXTI_LINE_ALARM_EVENT ((uint32_t)EXTI_IMR_MR17) /*!< External interrupt line 17 Connected to the RTC Alarm event */
  658. /**
  659. * @}
  660. */
  661. /* Private macros ------------------------------------------------------------*/
  662. /** @defgroup RTC_Private_Macros RTC Private Macros
  663. * @{
  664. */
  665. /** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters
  666. * @{
  667. */
  668. #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_HOURFORMAT_12) || \
  669. ((FORMAT) == RTC_HOURFORMAT_24))
  670. #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \
  671. ((OUTPUT) == RTC_OUTPUT_ALARMA) || \
  672. ((OUTPUT) == RTC_OUTPUT_ALARMB) || \
  673. ((OUTPUT) == RTC_OUTPUT_WAKEUP))
  674. #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \
  675. ((POL) == RTC_OUTPUT_POLARITY_LOW))
  676. #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \
  677. ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL))
  678. #define IS_RTC_HOUR12(HOUR) (((HOUR) > 0U) && ((HOUR) <= 12U))
  679. #define IS_RTC_HOUR24(HOUR) ((HOUR) <= 23U)
  680. #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FU)
  681. #define IS_RTC_SYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FFFU)
  682. #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59U)
  683. #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59U)
  684. #define IS_RTC_HOURFORMAT12(PM) (((PM) == RTC_HOURFORMAT12_AM) || ((PM) == RTC_HOURFORMAT12_PM))
  685. #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \
  686. ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \
  687. ((SAVE) == RTC_DAYLIGHTSAVING_NONE))
  688. #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \
  689. ((OPERATION) == RTC_STOREOPERATION_SET))
  690. #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || ((FORMAT) == RTC_FORMAT_BCD))
  691. #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99U)
  692. #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1U) && ((MONTH) <= 12U))
  693. #define IS_RTC_DATE(DATE) (((DATE) >= 1U) && ((DATE) <= 31U))
  694. #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \
  695. ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \
  696. ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
  697. ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \
  698. ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \
  699. ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \
  700. ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
  701. #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) > 0U) && ((DATE) <= 31U))
  702. #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \
  703. ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \
  704. ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
  705. ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \
  706. ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \
  707. ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \
  708. ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
  709. #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \
  710. ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY))
  711. #define IS_RTC_ALARM_MASK(MASK) (((MASK) & 0x7F7F7F7FU) == (uint32_t)RESET)
  712. #define IS_RTC_ALARM(ALARM) (((ALARM) == RTC_ALARM_A) || ((ALARM) == RTC_ALARM_B))
  713. #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= 0x00007FFFU)
  714. #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK) (((MASK) == RTC_ALARMSUBSECONDMASK_ALL) || \
  715. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_1) || \
  716. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_2) || \
  717. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_3) || \
  718. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_4) || \
  719. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_5) || \
  720. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_6) || \
  721. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_7) || \
  722. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_8) || \
  723. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_9) || \
  724. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_10) || \
  725. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_11) || \
  726. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_12) || \
  727. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_13) || \
  728. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14) || \
  729. ((MASK) == RTC_ALARMSUBSECONDMASK_NONE))
  730. /**
  731. * @}
  732. */
  733. /**
  734. * @}
  735. */
  736. /* Private functions ---------------------------------------------------------*/
  737. /** @defgroup RTC_Private_Functions RTC Private Functions
  738. * @{
  739. */
  740. HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef* hrtc);
  741. uint8_t RTC_ByteToBcd2(uint8_t Value);
  742. uint8_t RTC_Bcd2ToByte(uint8_t Value);
  743. /**
  744. * @}
  745. */
  746. /**
  747. * @}
  748. */
  749. /**
  750. * @}
  751. */
  752. #ifdef __cplusplus
  753. }
  754. #endif
  755. #endif /* __STM32F4xx_HAL_RTC_H */
  756. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/