stm32f7xx_hal_rtc.h 35 KB

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