stm32f4xx_hal_rtc.h 36 KB

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