stm32f3xx_hal_rtc.h 36 KB

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