You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1242 lines
49 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_rtc.h
  4. * @author MCD Application Team
  5. * @brief Header file of RTC HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef STM32H7xx_HAL_RTC_H
  21. #define STM32H7xx_HAL_RTC_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32h7xx_hal_def.h"
  27. /** @addtogroup STM32H7xx_HAL_Driver
  28. * @{
  29. */
  30. /** @defgroup RTC RTC
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup RTC_Exported_Types RTC Exported Types
  35. * @{
  36. */
  37. /**
  38. * @brief HAL State structures definition
  39. */
  40. typedef enum
  41. {
  42. HAL_RTC_STATE_RESET = 0x00U, /*!< RTC not yet initialized or disabled */
  43. HAL_RTC_STATE_READY = 0x01U, /*!< RTC initialized and ready for use */
  44. HAL_RTC_STATE_BUSY = 0x02U, /*!< RTC process is ongoing */
  45. HAL_RTC_STATE_TIMEOUT = 0x03U, /*!< RTC timeout state */
  46. HAL_RTC_STATE_ERROR = 0x04U /*!< RTC error state */
  47. } HAL_RTCStateTypeDef;
  48. /**
  49. * @brief RTC Configuration Structure definition
  50. */
  51. typedef struct
  52. {
  53. uint32_t HourFormat; /*!< Specifies the RTC Hour Format.
  54. This parameter can be a value of @ref RTC_Hour_Formats */
  55. uint32_t AsynchPrediv; /*!< Specifies the RTC Asynchronous Predivider value.
  56. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7F */
  57. uint32_t SynchPrediv; /*!< Specifies the RTC Synchronous Predivider value.
  58. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7FFF */
  59. uint32_t OutPut; /*!< Specifies which signal will be routed to the RTC output.
  60. This parameter can be a value of @ref RTCEx_Output_selection_Definitions */
  61. uint32_t OutPutRemap; /*!< Specifies the remap for RTC output.
  62. This parameter can be a value of @ref RTC_Output_ALARM_OUT_Remap */
  63. uint32_t OutPutPolarity; /*!< Specifies the polarity of the output signal.
  64. This parameter can be a value of @ref RTC_Output_Polarity_Definitions */
  65. uint32_t OutPutType; /*!< Specifies the RTC Output Pin mode.
  66. This parameter can be a value of @ref RTC_Output_Type_ALARM_OUT */
  67. #if defined(RTC_CR_TAMPALRM_PU)
  68. uint32_t OutPutPullUp; /*!< Specifies the RTC Output Pull-Up mode.
  69. This parameter can be a value of @ref RTC_Output_PullUp_ALARM_OUT */
  70. #endif /* RTC_CR_TAMPALRM_PU */
  71. } RTC_InitTypeDef;
  72. /**
  73. * @brief RTC Time structure definition
  74. */
  75. typedef struct
  76. {
  77. uint8_t Hours; /*!< Specifies the RTC Time Hour.
  78. This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected.
  79. This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected */
  80. uint8_t Minutes; /*!< Specifies the RTC Time Minutes.
  81. This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
  82. uint8_t Seconds; /*!< Specifies the RTC Time Seconds.
  83. This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
  84. uint8_t TimeFormat; /*!< Specifies the RTC AM/PM Time.
  85. This parameter can be a value of @ref RTC_AM_PM_Definitions */
  86. uint32_t SubSeconds; /*!< Specifies the RTC_SSR RTC Sub Second register content.
  87. This parameter corresponds to a time unit range between [0-1] Second
  88. with [1 Sec / SecondFraction +1] granularity */
  89. uint32_t SecondFraction; /*!< Specifies the range or granularity of Sub Second register content
  90. corresponding to Synchronous pre-scaler factor value (PREDIV_S)
  91. This parameter corresponds to a time unit range between [0-1] Second
  92. with [1 Sec / SecondFraction +1] granularity.
  93. This field will be used only by HAL_RTC_GetTime function */
  94. uint32_t DayLightSaving; /*!< Specifies RTC_DayLightSaveOperation: the value of hour adjustment.
  95. This parameter can be a value of @ref RTC_DayLightSaving_Definitions */
  96. uint32_t StoreOperation; /*!< Specifies RTC_StoreOperation value to be written in the BKP bit
  97. in CR register to store the operation.
  98. This parameter can be a value of @ref RTC_StoreOperation_Definitions */
  99. } RTC_TimeTypeDef;
  100. /**
  101. * @brief RTC Date structure definition
  102. */
  103. typedef struct
  104. {
  105. uint8_t WeekDay; /*!< Specifies the RTC Date WeekDay.
  106. This parameter can be a value of @ref RTC_WeekDay_Definitions */
  107. uint8_t Month; /*!< Specifies the RTC Date Month (in BCD format).
  108. This parameter can be a value of @ref RTC_Month_Date_Definitions */
  109. uint8_t Date; /*!< Specifies the RTC Date.
  110. This parameter must be a number between Min_Data = 1 and Max_Data = 31 */
  111. uint8_t Year; /*!< Specifies the RTC Date Year.
  112. This parameter must be a number between Min_Data = 0 and Max_Data = 99 */
  113. } RTC_DateTypeDef;
  114. /**
  115. * @brief RTC Alarm structure definition
  116. */
  117. typedef struct
  118. {
  119. RTC_TimeTypeDef AlarmTime; /*!< Specifies the RTC Alarm Time members */
  120. uint32_t AlarmMask; /*!< Specifies the RTC Alarm Masks.
  121. This parameter can be a value of @ref RTC_AlarmMask_Definitions */
  122. uint32_t AlarmSubSecondMask; /*!< Specifies the RTC Alarm SubSeconds Masks.
  123. This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */
  124. uint32_t AlarmDateWeekDaySel; /*!< Specifies the RTC Alarm is on Date or WeekDay.
  125. This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */
  126. uint8_t AlarmDateWeekDay; /*!< Specifies the RTC Alarm Date/WeekDay.
  127. If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range.
  128. If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */
  129. uint32_t Alarm; /*!< Specifies the alarm .
  130. This parameter can be a value of @ref RTC_Alarms_Definitions */
  131. } RTC_AlarmTypeDef;
  132. /**
  133. * @brief RTC Handle Structure definition
  134. */
  135. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  136. typedef struct __RTC_HandleTypeDef
  137. #else
  138. typedef struct
  139. #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */
  140. {
  141. RTC_TypeDef *Instance; /*!< Register base address */
  142. RTC_InitTypeDef Init; /*!< RTC required parameters */
  143. HAL_LockTypeDef Lock; /*!< RTC locking object */
  144. __IO HAL_RTCStateTypeDef State; /*!< Time communication state */
  145. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  146. void (* AlarmAEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Alarm A Event callback */
  147. void (* AlarmBEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Alarm B Event callback */
  148. void (* TimeStampEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC TimeStamp Event callback */
  149. void (* WakeUpTimerEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC WakeUpTimer Event callback */
  150. void (* Tamper1EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Tamper 1 Event callback */
  151. void (* Tamper2EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Tamper 2 Event callback */
  152. void (* Tamper3EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Tamper 3 Event callback */
  153. #if defined(TAMP_CR1_ITAMP1E)
  154. void (* InternalTamper1EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Internal Tamper 1 Event callback */
  155. #endif /* TAMP_CR1_ITAMP1E */
  156. #if defined(TAMP_CR1_ITAMP2E)
  157. void (* InternalTamper2EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Internal Tamper 2 Event callback */
  158. #endif /* TAMP_CR1_ITAMP2E */
  159. #if defined(TAMP_CR1_ITAMP3E)
  160. void (* InternalTamper3EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Internal Tamper 3 Event callback */
  161. #endif /* TAMP_CR1_ITAMP3E */
  162. #if defined(TAMP_CR1_ITAMP4E)
  163. void (* InternalTamper4EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Internal Tamper 4 Event callback */
  164. #endif /* TAMP_CR1_ITAMP4E */
  165. #if defined(TAMP_CR1_ITAMP5E)
  166. void (* InternalTamper5EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Internal Tamper 5 Event callback */
  167. #endif /* TAMP_CR1_ITAMP5E */
  168. #if defined(TAMP_CR1_ITAMP6E)
  169. void (* InternalTamper6EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Internal Tamper 6 Event callback */
  170. #endif /* TAMP_CR1_ITAMP6E */
  171. #if defined(TAMP_CR1_ITAMP8E)
  172. void (* InternalTamper8EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Internal Tamper 8 Event callback */
  173. #endif /* TAMP_CR1_ITAMP8E */
  174. void (* MspInitCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Msp Init callback */
  175. void (* MspDeInitCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Msp DeInit callback */
  176. #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
  177. } RTC_HandleTypeDef;
  178. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  179. /**
  180. * @brief HAL RTC Callback ID enumeration definition
  181. */
  182. typedef enum
  183. {
  184. HAL_RTC_ALARM_A_EVENT_CB_ID = 0u, /*!< RTC Alarm A Event Callback ID */
  185. HAL_RTC_ALARM_B_EVENT_CB_ID = 1u, /*!< RTC Alarm B Event Callback ID */
  186. HAL_RTC_TIMESTAMP_EVENT_CB_ID = 2u, /*!< RTC TimeStamp Event Callback ID */
  187. HAL_RTC_WAKEUPTIMER_EVENT_CB_ID = 3u, /*!< RTC WakeUp Timer Event Callback ID */
  188. HAL_RTC_TAMPER1_EVENT_CB_ID = 4u, /*!< RTC Tamper 1 Callback ID */
  189. HAL_RTC_TAMPER2_EVENT_CB_ID = 5u, /*!< RTC Tamper 2 Callback ID */
  190. HAL_RTC_TAMPER3_EVENT_CB_ID = 6u, /*!< RTC Tamper 3 Callback ID */
  191. #if defined(TAMP_CR1_ITAMP1E)
  192. HAL_RTC_INTERNAL_TAMPER1_EVENT_CB_ID = 12u, /*!< RTC Internal Tamper 1 Callback ID */
  193. #endif /* TAMP_CR1_ITAMP1E */
  194. #if defined(TAMP_CR1_ITAMP2E)
  195. HAL_RTC_INTERNAL_TAMPER2_EVENT_CB_ID = 13u, /*!< RTC Internal Tamper 2 Callback ID */
  196. #endif /* TAMP_CR1_ITAMP2E */
  197. #if defined(TAMP_CR1_ITAMP3E)
  198. HAL_RTC_INTERNAL_TAMPER3_EVENT_CB_ID = 14u, /*!< RTC Internal Tamper 3 Callback ID */
  199. #endif /* TAMP_CR1_ITAMP3E */
  200. #if defined(TAMP_CR1_ITAMP4E)
  201. HAL_RTC_INTERNAL_TAMPER4_EVENT_CB_ID = 15u, /*!< RTC Internal Tamper 4 Callback ID */
  202. #endif /* TAMP_CR1_ITAMP4E */
  203. #if defined(TAMP_CR1_ITAMP5E)
  204. HAL_RTC_INTERNAL_TAMPER5_EVENT_CB_ID = 16u, /*!< RTC Internal Tamper 5 Callback ID */
  205. #endif /* TAMP_CR1_ITAMP5E */
  206. #if defined(TAMP_CR1_ITAMP6E)
  207. HAL_RTC_INTERNAL_TAMPER6_EVENT_CB_ID = 17u, /*!< RTC Internal Tamper 6 Callback ID */
  208. #endif /* TAMP_CR1_ITAMP6E */
  209. #if defined(TAMP_CR1_ITAMP8E)
  210. HAL_RTC_INTERNAL_TAMPER8_EVENT_CB_ID = 19u, /*!< RTC Internal Tamper 8 Callback ID */
  211. #endif /* TAMP_CR1_ITAMP8E */
  212. HAL_RTC_MSPINIT_CB_ID = 20u, /*!< RTC Msp Init callback ID */
  213. HAL_RTC_MSPDEINIT_CB_ID = 21u /*!< RTC Msp DeInit callback ID */
  214. } HAL_RTC_CallbackIDTypeDef;
  215. /**
  216. * @brief HAL RTC Callback pointer definition
  217. */
  218. typedef void (*pRTC_CallbackTypeDef)(RTC_HandleTypeDef *hrtc); /*!< pointer to an RTC callback function */
  219. #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
  220. /**
  221. * @}
  222. */
  223. /* Exported constants --------------------------------------------------------*/
  224. /** @defgroup RTC_Exported_Constants RTC Exported Constants
  225. * @{
  226. */
  227. /** @defgroup RTC_Hour_Formats_Definitions RTC Hour Formats Definitions
  228. * @{
  229. */
  230. #define RTC_HOURFORMAT_24 0x00000000u
  231. #define RTC_HOURFORMAT_12 RTC_CR_FMT
  232. /**
  233. * @}
  234. */
  235. /** @defgroup RTC_Output_selection_Definitions RTC Output Selection Definitions
  236. * @{
  237. */
  238. #define RTC_OUTPUT_DISABLE 0x00000000u
  239. #define RTC_OUTPUT_ALARMA RTC_CR_OSEL_0
  240. #define RTC_OUTPUT_ALARMB RTC_CR_OSEL_1
  241. #define RTC_OUTPUT_WAKEUP RTC_CR_OSEL
  242. #if defined(RTC_CR_TAMPOE)
  243. #define RTC_OUTPUT_TAMPER RTC_CR_TAMPOE
  244. #endif /* RTC_CR_TAMPOE */
  245. /**
  246. * @}
  247. */
  248. /** @defgroup RTC_Output_Polarity_Definitions RTC Output Polarity Definitions
  249. * @{
  250. */
  251. #define RTC_OUTPUT_POLARITY_HIGH 0x00000000u
  252. #define RTC_OUTPUT_POLARITY_LOW RTC_CR_POL
  253. /**
  254. * @}
  255. */
  256. /** @defgroup RTC_Output_Type_ALARM_OUT RTC Output Type ALARM OUT
  257. * @{
  258. */
  259. #if defined(RTC_CR_TAMPALRM_TYPE)
  260. #define RTC_OUTPUT_TYPE_PUSHPULL 0x00000000u
  261. #define RTC_OUTPUT_TYPE_OPENDRAIN RTC_CR_TAMPALRM_TYPE
  262. #define RTC_ALARM_OUTPUT_TYPE RTC_CR_TAMPALRM_TYPE
  263. #endif /* RTC_CR_TAMPALRM_TYPE */
  264. #if defined(RTC_OR_ALARMOUTTYPE)
  265. #define RTC_OUTPUT_TYPE_PUSHPULL RTC_OR_ALARMOUTTYPE
  266. #define RTC_OUTPUT_TYPE_OPENDRAIN 0x00000000u
  267. #define RTC_ALARM_OUTPUT_TYPE RTC_OR_ALARMOUTTYPE
  268. #endif /* RTC_OR_ALARMOUTTYPE */
  269. /**
  270. * @}
  271. */
  272. /** @defgroup RTC_Output_PullUp_ALARM_OUT RTC Output Pull-Up ALARM OUT
  273. * @{
  274. */
  275. #if defined(RTC_CR_TAMPALRM_PU)
  276. #define RTC_OUTPUT_PULLUP_NONE 0x00000000u
  277. #define RTC_OUTPUT_PULLUP_ON RTC_CR_TAMPALRM_PU
  278. #endif /* RTC_CR_TAMPALRM_PU */
  279. /**
  280. * @}
  281. */
  282. /** @defgroup RTC_Output_ALARM_OUT_Remap RTC Output ALARM OUT Remap
  283. * @{
  284. */
  285. #if defined(RTC_CR_OUT2EN)
  286. #define RTC_OUTPUT_REMAP_NONE 0x00000000u
  287. #define RTC_OUTPUT_REMAP_POS1 RTC_CR_OUT2EN
  288. #endif /* RTC_CR_OUT2EN */
  289. #if defined(RTC_OR_OUT_RMP)
  290. #define RTC_OUTPUT_REMAP_NONE 0x00000000u
  291. #define RTC_OUTPUT_REMAP_POS1 RTC_OR_OUT_RMP
  292. #endif /* RTC_OR_OUT_RMP */
  293. /**
  294. * @}
  295. */
  296. /** @defgroup RTC_AM_PM_Definitions RTC AM PM Definitions
  297. * @{
  298. */
  299. #define RTC_HOURFORMAT12_AM ((uint8_t)0x00)
  300. #define RTC_HOURFORMAT12_PM ((uint8_t)0x01)
  301. /**
  302. * @}
  303. */
  304. /** @defgroup RTC_DayLightSaving_Definitions RTC DayLight Saving Definitions
  305. * @{
  306. */
  307. #define RTC_DAYLIGHTSAVING_SUB1H RTC_CR_SUB1H
  308. #define RTC_DAYLIGHTSAVING_ADD1H RTC_CR_ADD1H
  309. #define RTC_DAYLIGHTSAVING_NONE 0x00000000u
  310. /**
  311. * @}
  312. */
  313. /** @defgroup RTC_StoreOperation_Definitions RTC Store Operation Definitions
  314. * @{
  315. */
  316. #define RTC_STOREOPERATION_RESET 0x00000000u
  317. #define RTC_STOREOPERATION_SET RTC_CR_BKP
  318. /**
  319. * @}
  320. */
  321. /** @defgroup RTC_Input_parameter_format_definitions RTC Input Parameter Format Definitions
  322. * @{
  323. */
  324. #define RTC_FORMAT_BIN 0x00000000u
  325. #define RTC_FORMAT_BCD 0x00000001u
  326. /**
  327. * @}
  328. */
  329. /** @defgroup RTC_Month_Date_Definitions RTC Month Date Definitions (in BCD format)
  330. * @{
  331. */
  332. #define RTC_MONTH_JANUARY ((uint8_t)0x01)
  333. #define RTC_MONTH_FEBRUARY ((uint8_t)0x02)
  334. #define RTC_MONTH_MARCH ((uint8_t)0x03)
  335. #define RTC_MONTH_APRIL ((uint8_t)0x04)
  336. #define RTC_MONTH_MAY ((uint8_t)0x05)
  337. #define RTC_MONTH_JUNE ((uint8_t)0x06)
  338. #define RTC_MONTH_JULY ((uint8_t)0x07)
  339. #define RTC_MONTH_AUGUST ((uint8_t)0x08)
  340. #define RTC_MONTH_SEPTEMBER ((uint8_t)0x09)
  341. #define RTC_MONTH_OCTOBER ((uint8_t)0x10)
  342. #define RTC_MONTH_NOVEMBER ((uint8_t)0x11)
  343. #define RTC_MONTH_DECEMBER ((uint8_t)0x12)
  344. /**
  345. * @}
  346. */
  347. /** @defgroup RTC_WeekDay_Definitions RTC WeekDay Definitions
  348. * @{
  349. */
  350. #define RTC_WEEKDAY_MONDAY ((uint8_t)0x01)
  351. #define RTC_WEEKDAY_TUESDAY ((uint8_t)0x02)
  352. #define RTC_WEEKDAY_WEDNESDAY ((uint8_t)0x03)
  353. #define RTC_WEEKDAY_THURSDAY ((uint8_t)0x04)
  354. #define RTC_WEEKDAY_FRIDAY ((uint8_t)0x05)
  355. #define RTC_WEEKDAY_SATURDAY ((uint8_t)0x06)
  356. #define RTC_WEEKDAY_SUNDAY ((uint8_t)0x07)
  357. /**
  358. * @}
  359. */
  360. /** @defgroup RTC_AlarmDateWeekDay_Definitions RTC Alarm Date WeekDay Definitions
  361. * @{
  362. */
  363. #define RTC_ALARMDATEWEEKDAYSEL_DATE 0x00000000u
  364. #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY RTC_ALRMAR_WDSEL
  365. /**
  366. * @}
  367. */
  368. /** @defgroup RTC_AlarmMask_Definitions RTC Alarm Mask Definitions
  369. * @{
  370. */
  371. #define RTC_ALARMMASK_NONE 0x00000000u
  372. #define RTC_ALARMMASK_DATEWEEKDAY RTC_ALRMAR_MSK4
  373. #define RTC_ALARMMASK_HOURS RTC_ALRMAR_MSK3
  374. #define RTC_ALARMMASK_MINUTES RTC_ALRMAR_MSK2
  375. #define RTC_ALARMMASK_SECONDS RTC_ALRMAR_MSK1
  376. #define RTC_ALARMMASK_ALL (RTC_ALARMMASK_DATEWEEKDAY | \
  377. RTC_ALARMMASK_HOURS | \
  378. RTC_ALARMMASK_MINUTES | \
  379. RTC_ALARMMASK_SECONDS)
  380. /**
  381. * @}
  382. */
  383. /** @defgroup RTC_Alarms_Definitions RTC Alarms Definitions
  384. * @{
  385. */
  386. #define RTC_ALARM_A RTC_CR_ALRAE
  387. #define RTC_ALARM_B RTC_CR_ALRBE
  388. /**
  389. * @}
  390. */
  391. /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions RTC Alarm Sub Seconds Masks Definitions
  392. * @{
  393. */
  394. /*!< All Alarm SS fields are masked. There is no comparison on sub seconds for Alarm */
  395. #define RTC_ALARMSUBSECONDMASK_ALL 0x00000000u
  396. /*!< SS[14:1] are don't care in Alarm comparison. Only SS[0] is compared. */
  397. #define RTC_ALARMSUBSECONDMASK_SS14_1 RTC_ALRMASSR_MASKSS_0
  398. /*!< SS[14:2] are don't care in Alarm comparison. Only SS[1:0] are compared. */
  399. #define RTC_ALARMSUBSECONDMASK_SS14_2 RTC_ALRMASSR_MASKSS_1
  400. /*!< SS[14:3] are don't care in Alarm comparison. Only SS[2:0] are compared. */
  401. #define RTC_ALARMSUBSECONDMASK_SS14_3 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1)
  402. /*!< SS[14:4] are don't care in Alarm comparison. Only SS[3:0] are compared. */
  403. #define RTC_ALARMSUBSECONDMASK_SS14_4 RTC_ALRMASSR_MASKSS_2
  404. /*!< SS[14:5] are don't care in Alarm comparison. Only SS[4:0] are compared. */
  405. #define RTC_ALARMSUBSECONDMASK_SS14_5 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2)
  406. /*!< SS[14:6] are don't care in Alarm comparison. Only SS[5:0] are compared. */
  407. #define RTC_ALARMSUBSECONDMASK_SS14_6 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2)
  408. /*!< SS[14:7] are don't care in Alarm comparison. Only SS[6:0] are compared. */
  409. #define RTC_ALARMSUBSECONDMASK_SS14_7 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2)
  410. /*!< SS[14:8] are don't care in Alarm comparison. Only SS[7:0] are compared. */
  411. #define RTC_ALARMSUBSECONDMASK_SS14_8 RTC_ALRMASSR_MASKSS_3
  412. /*!< SS[14:9] are don't care in Alarm comparison. Only SS[8:0] are compared. */
  413. #define RTC_ALARMSUBSECONDMASK_SS14_9 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_3)
  414. /*!< SS[14:10] are don't care in Alarm comparison. Only SS[9:0] are compared. */
  415. #define RTC_ALARMSUBSECONDMASK_SS14_10 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3)
  416. /*!< SS[14:11] are don't care in Alarm comparison. Only SS[10:0] are compared. */
  417. #define RTC_ALARMSUBSECONDMASK_SS14_11 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3)
  418. /*!< SS[14:12] are don't care in Alarm comparison. Only SS[11:0] are compared. */
  419. #define RTC_ALARMSUBSECONDMASK_SS14_12 (RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3)
  420. /*!< SS[14:13] are don't care in Alarm comparison. Only SS[12:0] are compared. */
  421. #define RTC_ALARMSUBSECONDMASK_SS14_13 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3)
  422. /*!< SS[14] is don't care in Alarm comparison. Only SS[13:0] are compared. */
  423. #define RTC_ALARMSUBSECONDMASK_SS14 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3)
  424. /*!< SS[14:0] are compared and must match to activate alarm. */
  425. #define RTC_ALARMSUBSECONDMASK_NONE RTC_ALRMASSR_MASKSS
  426. /**
  427. * @}
  428. */
  429. /** @defgroup RTC_Interrupts_Definitions RTC Interrupts Definitions
  430. * @{
  431. */
  432. #define RTC_IT_TS RTC_CR_TSIE /*!< Enable Timestamp Interrupt */
  433. #define RTC_IT_WUT RTC_CR_WUTIE /*!< Enable Wakeup timer Interrupt */
  434. #define RTC_IT_ALRA RTC_CR_ALRAIE /*!< Enable Alarm A Interrupt */
  435. #define RTC_IT_ALRB RTC_CR_ALRBIE /*!< Enable Alarm B Interrupt */
  436. /**
  437. * @}
  438. */
  439. /** @defgroup RTC_Flags_Definitions RTC Flags Definitions
  440. * @{
  441. */
  442. #if defined(RTC_ICSR_RECALPF)
  443. #define RTC_FLAG_RECALPF RTC_ICSR_RECALPF /*!< Recalibration pending Flag */
  444. #endif /* RTC_ICSR_RECALPF */
  445. #if defined(RTC_ICSR_INITF)
  446. #define RTC_FLAG_INITF RTC_ICSR_INITF /*!< Initialization pending flag */
  447. #endif /* RTC_ICSR_INITF */
  448. #if defined(RTC_ICSR_RSF)
  449. #define RTC_FLAG_RSF RTC_ICSR_RSF /*!< Registers synchronization flag */
  450. #endif /* RTC_ICSR_RSF */
  451. #if defined(RTC_ICSR_INITS)
  452. #define RTC_FLAG_INITS RTC_ICSR_INITS /*!< Initialization status flag */
  453. #endif /* RTC_ICSR_INITS */
  454. #if defined(RTC_ICSR_SHPF)
  455. #define RTC_FLAG_SHPF RTC_ICSR_SHPF /*!< Shift operation pending flag */
  456. #endif /* RTC_ICSR_SHPF */
  457. #if defined(RTC_ICSR_WUTWF)
  458. #define RTC_FLAG_WUTWF RTC_ICSR_WUTWF /*!< Wakeup timer write operation pending flag */
  459. #endif /* RTC_ICSR_WUTWF */
  460. #if defined(RTC_ICSR_ALRBWF)
  461. #define RTC_FLAG_ALRBWF RTC_ICSR_ALRBWF /*!< Alarm B write operation pending flag */
  462. #endif /* RTC_ICSR_ALRBWF */
  463. #if defined(RTC_ICSR_ALRAWF)
  464. #define RTC_FLAG_ALRAWF RTC_ICSR_ALRAWF /*!< Alarm A write operation pending flag */
  465. #endif /* RTC_ICSR_ALRAWF */
  466. #if defined(RTC_SR_ITSF)
  467. #define RTC_FLAG_ITSF RTC_SR_ITSF /*!< Internal Time-stamp flag */
  468. #endif /* RTC_SR_ITSF */
  469. #if defined(RTC_SR_TSOVF)
  470. #define RTC_FLAG_TSOVF RTC_SR_TSOVF /*!< Time-stamp overflow flag */
  471. #endif /* RTC_SR_TSOVF */
  472. #if defined(RTC_SR_TSF)
  473. #define RTC_FLAG_TSF RTC_SR_TSF /*!< Time-stamp flag */
  474. #endif /* RTC_SR_TSF */
  475. #if defined(RTC_SR_WUTF)
  476. #define RTC_FLAG_WUTF RTC_SR_WUTF /*!< Wakeup timer flag */
  477. #endif /* RTC_SR_WUTF */
  478. #if defined(RTC_SR_ALRBF)
  479. #define RTC_FLAG_ALRBF RTC_SR_ALRBF /*!< Alarm B flag */
  480. #endif /* RTC_SR_ALRBF */
  481. #if defined(RTC_SR_ALRAF)
  482. #define RTC_FLAG_ALRAF RTC_SR_ALRAF /*!< Alarm A flag */
  483. #endif /* RTC_SR_ALRAF */
  484. /**
  485. * @}
  486. */
  487. /** @defgroup RTC_Clear_Flags_Definitions RTC Clear Flags Definitions
  488. * @{
  489. */
  490. #if defined(RTC_SCR_CITSF)
  491. #define RTC_CLEAR_ITSF RTC_SCR_CITSF /*!< Clear Internal Time-stamp flag */
  492. #endif /* RTC_SCR_CITSF */
  493. #if defined(RTC_SCR_CTSOVF)
  494. #define RTC_CLEAR_TSOVF RTC_SCR_CTSOVF /*!< Clear Time-stamp overflow flag */
  495. #endif /* RTC_SCR_CTSOVF */
  496. #if defined(RTC_SCR_CTSF)
  497. #define RTC_CLEAR_TSF RTC_SCR_CTSF /*!< Clear Time-stamp flag */
  498. #endif /* RTC_SCR_CTSF */
  499. #if defined(RTC_SCR_CWUTF)
  500. #define RTC_CLEAR_WUTF RTC_SCR_CWUTF /*!< Clear Wakeup timer flag */
  501. #endif /* RTC_SCR_CWUTF */
  502. #if defined(RTC_SCR_CALRBF)
  503. #define RTC_CLEAR_ALRBF RTC_SCR_CALRBF /*!< Clear Alarm B flag */
  504. #endif /* RTC_SCR_CALRBF */
  505. #if defined(RTC_SCR_CALRAF)
  506. #define RTC_CLEAR_ALRAF RTC_SCR_CALRAF /*!< Clear Alarm A flag */
  507. #endif /* RTC_SCR_CALRAF */
  508. /**
  509. * @}
  510. */
  511. /** @defgroup RTC_Flags_Definitions RTC Flags Definitions
  512. * @{
  513. */
  514. #if defined(RTC_ISR_RECALPF)
  515. #define RTC_FLAG_RECALPF RTC_ISR_RECALPF
  516. #endif /* RTC_ISR_RECALPF */
  517. #if defined(RTC_ISR_TSOVF)
  518. #define RTC_FLAG_TSOVF RTC_ISR_TSOVF
  519. #endif /* RTC_ISR_TSOVF */
  520. #if defined(RTC_ISR_TSF)
  521. #define RTC_FLAG_TSF RTC_ISR_TSF
  522. #endif /* RTC_ISR_TSF */
  523. #if defined(RTC_ISR_ITSF)
  524. #define RTC_FLAG_ITSF RTC_ISR_ITSF
  525. #endif /* RTC_ISR_ITSF */
  526. #if defined(RTC_ISR_WUTF)
  527. #define RTC_FLAG_WUTF RTC_ISR_WUTF
  528. #endif /* RTC_ISR_WUTF */
  529. #if defined(RTC_ISR_ALRBF)
  530. #define RTC_FLAG_ALRBF RTC_ISR_ALRBF
  531. #endif /* RTC_ISR_ALRBF */
  532. #if defined(RTC_ISR_ALRAF)
  533. #define RTC_FLAG_ALRAF RTC_ISR_ALRAF
  534. #endif /* RTC_ISR_ALRAF */
  535. #if defined(RTC_ISR_INITF)
  536. #define RTC_FLAG_INITF RTC_ISR_INITF
  537. #endif /* RTC_ISR_INITF */
  538. #if defined(RTC_ISR_RSF)
  539. #define RTC_FLAG_RSF RTC_ISR_RSF
  540. #endif /* RTC_ISR_RSF */
  541. #if defined(RTC_ISR_INITS)
  542. #define RTC_FLAG_INITS RTC_ISR_INITS
  543. #endif /* RTC_ISR_INITS */
  544. #if defined(RTC_ISR_SHPF)
  545. #define RTC_FLAG_SHPF RTC_ISR_SHPF
  546. #endif /* RTC_ISR_SHPF */
  547. #if defined(RTC_ISR_WUTWF)
  548. #define RTC_FLAG_WUTWF RTC_ISR_WUTWF
  549. #endif /* RTC_ISR_WUTWF */
  550. #if defined(RTC_ISR_ALRBWF)
  551. #define RTC_FLAG_ALRBWF RTC_ISR_ALRBWF
  552. #endif /* RTC_ISR_ALRBWF */
  553. #if defined(RTC_ISR_ALRAWF)
  554. #define RTC_FLAG_ALRAWF RTC_ISR_ALRAWF
  555. #endif /* RTC_ISR_ALRAWF */
  556. /**
  557. * @}
  558. */
  559. /**
  560. * @}
  561. */
  562. /* Exported macros -----------------------------------------------------------*/
  563. /** @defgroup RTC_Exported_Macros RTC Exported Macros
  564. * @{
  565. */
  566. /** @brief Reset RTC handle state
  567. * @param __HANDLE__ RTC handle.
  568. * @retval None
  569. */
  570. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  571. #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) do{ \
  572. (__HANDLE__)->State = HAL_RTC_STATE_RESET; \
  573. (__HANDLE__)->MspInitCallback = NULL; \
  574. (__HANDLE__)->MspDeInitCallback = NULL; \
  575. }while(0u)
  576. #else
  577. #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET)
  578. #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
  579. /**
  580. * @brief Disable the write protection for RTC registers.
  581. * @param __HANDLE__ specifies the RTC handle.
  582. * @retval None
  583. */
  584. #define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__) \
  585. do{ \
  586. (__HANDLE__)->Instance->WPR = 0xCAU; \
  587. (__HANDLE__)->Instance->WPR = 0x53U; \
  588. } while(0u)
  589. /**
  590. * @brief Enable the write protection for RTC registers.
  591. * @param __HANDLE__ specifies the RTC handle.
  592. * @retval None
  593. */
  594. #define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__) \
  595. do{ \
  596. (__HANDLE__)->Instance->WPR = 0xFFU; \
  597. } while(0u)
  598. /**
  599. * @brief Add 1 hour (summer time change).
  600. * @param __HANDLE__ specifies the RTC handle.
  601. * @param __BKP__ Backup
  602. * This parameter can be:
  603. * @arg @ref RTC_STOREOPERATION_RESET
  604. * @arg @ref RTC_STOREOPERATION_SET
  605. * @retval None
  606. */
  607. #define __HAL_RTC_DAYLIGHT_SAVING_TIME_ADD1H(__HANDLE__, __BKP__) \
  608. do { \
  609. __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__); \
  610. SET_BIT((__HANDLE__)->Instance->CR, RTC_CR_ADD1H); \
  611. MODIFY_REG((__HANDLE__)->Instance->CR, RTC_CR_BKP , (__BKP__)); \
  612. __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__); \
  613. } while(0u);
  614. /**
  615. * @brief Subtract 1 hour (winter time change).
  616. * @param __HANDLE__ specifies the RTC handle.
  617. * @param __BKP__ Backup
  618. * This parameter can be:
  619. * @arg @ref RTC_STOREOPERATION_RESET
  620. * @arg @ref RTC_STOREOPERATION_SET
  621. * @retval None
  622. */
  623. #define __HAL_RTC_DAYLIGHT_SAVING_TIME_SUB1H(__HANDLE__, __BKP__) \
  624. do { \
  625. __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__); \
  626. SET_BIT((__HANDLE__)->Instance->CR, RTC_CR_SUB1H); \
  627. MODIFY_REG((__HANDLE__)->Instance->CR, RTC_CR_BKP , (__BKP__)); \
  628. __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__); \
  629. } while(0u);
  630. /**
  631. * @brief Enable the RTC ALARMA peripheral.
  632. * @param __HANDLE__ specifies the RTC handle.
  633. * @retval None
  634. */
  635. #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE))
  636. /**
  637. * @brief Disable the RTC ALARMA peripheral.
  638. * @param __HANDLE__ specifies the RTC handle.
  639. * @retval None
  640. */
  641. #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE))
  642. /**
  643. * @brief Enable the RTC ALARMB peripheral.
  644. * @param __HANDLE__ specifies the RTC handle.
  645. * @retval None
  646. */
  647. #define __HAL_RTC_ALARMB_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRBE))
  648. /**
  649. * @brief Disable the RTC ALARMB peripheral.
  650. * @param __HANDLE__ specifies the RTC handle.
  651. * @retval None
  652. */
  653. #define __HAL_RTC_ALARMB_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRBE))
  654. /**
  655. * @brief Enable the RTC Alarm interrupt.
  656. * @param __HANDLE__ specifies the RTC handle.
  657. * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled.
  658. * This parameter can be any combination of the following values:
  659. * @arg @ref RTC_IT_ALRA Alarm A interrupt
  660. * @arg @ref RTC_IT_ALRB Alarm B interrupt
  661. * @retval None
  662. */
  663. #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
  664. /**
  665. * @brief Disable the RTC Alarm interrupt.
  666. * @param __HANDLE__ specifies the RTC handle.
  667. * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled.
  668. * This parameter can be any combination of the following values:
  669. * @arg @ref RTC_IT_ALRA Alarm A interrupt
  670. * @arg @ref RTC_IT_ALRB Alarm B interrupt
  671. * @retval None
  672. */
  673. #define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
  674. /**
  675. * @brief Check whether the specified RTC Alarm interrupt has occurred or not.
  676. * @param __HANDLE__ specifies the RTC handle.
  677. * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check.
  678. * This parameter can be:
  679. * @arg @ref RTC_IT_ALRA Alarm A interrupt
  680. * @arg @ref RTC_IT_ALRB Alarm B interrupt
  681. * @retval None
  682. */
  683. #if defined(RTC_MISR_ALRAMF)
  684. #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->MISR)& (__INTERRUPT__ >> 12)) != 0U)? 1U : 0U)
  685. #endif /* RTC_MISR_ALRAMF */
  686. #if defined(RTC_ISR_ALRAF)
  687. #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->ISR)& (__INTERRUPT__ >> 4)) != 0U)? 1U : 0U)
  688. #endif /* RTC_ISR_ALRAF */
  689. /**
  690. * @brief Check whether the specified RTC Alarm interrupt has been enabled or not.
  691. * @param __HANDLE__ specifies the RTC handle.
  692. * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check.
  693. * This parameter can be:
  694. * @arg @ref RTC_IT_ALRA Alarm A interrupt
  695. * @arg @ref RTC_IT_ALRB Alarm B interrupt
  696. * @retval None
  697. */
  698. #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
  699. #if defined(RTC_SR_ALRAF)
  700. /**
  701. * @brief Get the selected RTC Alarm's flag status.
  702. * @param __HANDLE__ specifies the RTC handle.
  703. * @param __FLAG__ specifies the RTC Alarm Flag sources to check.
  704. * This parameter can be:
  705. * @arg @ref RTC_FLAG_ALRAF
  706. * @arg @ref RTC_FLAG_ALRBF
  707. * @retval None
  708. */
  709. #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->SR) & (__FLAG__)) != 0U) ? 1U : 0U)
  710. #endif /* RTC_SR_ALRAF */
  711. #if defined(RTC_ISR_ALRAF)
  712. /**
  713. * @brief Get the selected RTC Alarm's flag status.
  714. * @param __HANDLE__ specifies the RTC handle.
  715. * @param __FLAG__ specifies the RTC Alarm Flag sources to check.
  716. * This parameter can be:
  717. * @arg @ref RTC_FLAG_ALRAF
  718. * @arg @ref RTC_FLAG_ALRBF
  719. * @arg @ref RTC_FLAG_ALRAWF
  720. * @arg @ref RTC_FLAG_ALRBWF
  721. * @retval None
  722. */
  723. #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U) ? 1U : 0U)
  724. #endif /* RTC_ISR_ALRAF */
  725. /**
  726. * @brief Clear the RTC Alarm's pending flags.
  727. * @param __HANDLE__ specifies the RTC handle.
  728. * @param __FLAG__ specifies the RTC Alarm Flag sources to clear.
  729. * This parameter can be:
  730. * @arg @ref RTC_FLAG_ALRAF
  731. * @arg @ref RTC_FLAG_ALRBF
  732. * @retval None
  733. */
  734. #if defined(RTC_SCR_CALRAF)
  735. #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SCR |= __FLAG__)
  736. #endif /* RTC_SCR_CALRAF */
  737. #if defined(RTC_ISR_ALRAF)
  738. #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT)))
  739. #endif /* RTC_ISR_ALRAF */
  740. /**
  741. * @brief Enable interrupt on the RTC Alarm associated Exti line.
  742. * @retval None
  743. */
  744. #if defined(EXTI_D1)
  745. #define __HAL_RTC_ALARM_EXTI_ENABLE_IT() (EXTI_D1->IMR1 |= RTC_EXTI_LINE_ALARM_EVENT)
  746. #else /* EXTI */
  747. #define __HAL_RTC_ALARM_EXTI_ENABLE_IT() (EXTI->IMR1 |= RTC_EXTI_LINE_ALARM_EVENT)
  748. #endif /* EXTI_D1 */
  749. /**
  750. * @brief Disable interrupt on the RTC Alarm associated Exti line.
  751. * @retval None
  752. */
  753. #if defined(EXTI_D1)
  754. #define __HAL_RTC_ALARM_EXTI_DISABLE_IT() (EXTI_D1->IMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  755. #else /* EXTI */
  756. #define __HAL_RTC_ALARM_EXTI_DISABLE_IT() (EXTI->IMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  757. #endif /* EXTI_D1 */
  758. /**
  759. * @brief Enable event on the RTC Alarm associated Exti line.
  760. * @retval None.
  761. */
  762. #if defined(EXTI_D1)
  763. #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT() (EXTI_D1->EMR1 |= RTC_EXTI_LINE_ALARM_EVENT)
  764. #else /* EXTI */
  765. #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT() (EXTI->EMR1 |= RTC_EXTI_LINE_ALARM_EVENT)
  766. #endif /* EXTI_D1 */
  767. /**
  768. * @brief Disable event on the RTC Alarm associated Exti line.
  769. * @retval None.
  770. */
  771. #if defined(EXTI_D1)
  772. #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT() (EXTI_D1->EMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  773. #else /* EXTI */
  774. #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT() (EXTI->EMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  775. #endif /* EXTI_D1 */
  776. #if defined(DUAL_CORE)
  777. /**
  778. * @brief Enable interrupt on the RTC Alarm associated D2 Exti line.
  779. * @retval None
  780. */
  781. #define __HAL_RTC_ALARM_EXTID2_ENABLE_IT() (EXTI_D2->IMR1 |= RTC_EXTI_LINE_ALARM_EVENT)
  782. /**
  783. * @brief Disable interrupt on the RTC Alarm associated D2 Exti line.
  784. * @retval None
  785. */
  786. #define __HAL_RTC_ALARM_EXTID2_DISABLE_IT() (EXTI_D2->IMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  787. /**
  788. * @brief Enable event on the RTC Alarm associated D2 Exti line.
  789. * @retval None
  790. */
  791. #define __HAL_RTC_ALARM_EXTID2_ENABLE_EVENT() (EXTI_D2->EMR1 |= RTC_EXTI_LINE_ALARM_EVENT)
  792. /**
  793. * @brief Disable event on the RTC Alarm associated D2 Exti line.
  794. * @retval None
  795. */
  796. #define __HAL_RTC_ALARM_EXTID2_DISABLE_EVENT() (EXTI_D2->EMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  797. #endif
  798. /**
  799. * @brief Enable falling edge trigger on the RTC Alarm associated Exti line.
  800. * @retval None
  801. */
  802. #define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE() (EXTI->FTSR1 |= RTC_EXTI_LINE_ALARM_EVENT)
  803. /**
  804. * @brief Disable falling edge trigger on the RTC Alarm associated Exti line.
  805. * @retval None
  806. */
  807. #define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE() (EXTI->FTSR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  808. /**
  809. * @brief Enable rising edge trigger on the RTC Alarm associated Exti line.
  810. * @retval None
  811. */
  812. #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE() (EXTI->RTSR1 |= RTC_EXTI_LINE_ALARM_EVENT)
  813. /**
  814. * @brief Disable rising edge trigger on the RTC Alarm associated Exti line.
  815. * @retval None
  816. */
  817. #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE() (EXTI->RTSR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  818. /**
  819. * @brief Enable rising & falling edge trigger on the RTC Alarm associated Exti line.
  820. * @retval None
  821. */
  822. #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
  823. __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE(); \
  824. __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE(); \
  825. } while(0u)
  826. /**
  827. * @brief Disable rising & falling edge trigger on the RTC Alarm associated Exti line.
  828. * @retval None
  829. */
  830. #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
  831. __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE(); \
  832. __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE(); \
  833. } while(0u)
  834. /**
  835. * @brief Check whether the RTC Alarm associated Exti line interrupt flag is set or not.
  836. * @retval Line Status.
  837. */
  838. #if defined(EXTI_D1)
  839. #define __HAL_RTC_ALARM_EXTI_GET_FLAG() (EXTI_D1->PR1 & RTC_EXTI_LINE_ALARM_EVENT)
  840. #else /* EXTI */
  841. #define __HAL_RTC_ALARM_EXTI_GET_FLAG() (EXTI->PR1 & RTC_EXTI_LINE_ALARM_EVENT)
  842. #endif /* EXTI_D1 */
  843. /**
  844. * @brief Clear the RTC Alarm associated Exti line flag.
  845. * @retval None.
  846. */
  847. #if defined(EXTI_D1)
  848. #define __HAL_RTC_ALARM_EXTI_CLEAR_FLAG() (EXTI_D1->PR1 = (RTC_EXTI_LINE_ALARM_EVENT))
  849. #else /* EXTI */
  850. #define __HAL_RTC_ALARM_EXTI_CLEAR_FLAG() (EXTI->PR1 = (RTC_EXTI_LINE_ALARM_EVENT))
  851. #endif /* EXTI_D1 */
  852. #if defined(DUAL_CORE)
  853. /**
  854. * @brief Check whether the RTC Alarm associated D2 Exti line interrupt flag is set or not.
  855. * @retval Line Status
  856. */
  857. #define __HAL_RTC_ALARM_EXTID2_GET_FLAG() (EXTI_D2->PR1 & RTC_EXTI_LINE_ALARM_EVENT)
  858. /**
  859. * @brief Clear the RTC Alarm associated D2 Exti line flag.
  860. * @retval None
  861. */
  862. #define __HAL_RTC_ALARM_EXTID2_CLEAR_FLAG() (EXTI_D2->PR1 = (RTC_EXTI_LINE_ALARM_EVENT))
  863. #endif
  864. /**
  865. * @brief Generate a Software interrupt on RTC Alarm associated Exti line.
  866. * @retval None
  867. */
  868. #define __HAL_RTC_ALARM_EXTI_GENERATE_SWIT() (EXTI->SWIER1 |= RTC_EXTI_LINE_ALARM_EVENT)
  869. /**
  870. * @}
  871. */
  872. /* Include RTC HAL Extended module */
  873. #include "stm32h7xx_hal_rtc_ex.h"
  874. /* Exported functions --------------------------------------------------------*/
  875. /** @defgroup RTC_Exported_Functions RTC Exported Functions
  876. * @{
  877. */
  878. /** @defgroup RTC_Exported_Functions_Group1 Initialization and de-initialization functions
  879. * @{
  880. */
  881. /* Initialization and de-initialization functions ****************************/
  882. HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc);
  883. HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc);
  884. void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc);
  885. void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc);
  886. /* Callbacks Register/UnRegister functions ***********************************/
  887. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  888. HAL_StatusTypeDef HAL_RTC_RegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID, pRTC_CallbackTypeDef pCallback);
  889. HAL_StatusTypeDef HAL_RTC_UnRegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID);
  890. #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
  891. /**
  892. * @}
  893. */
  894. /** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions
  895. * @{
  896. */
  897. /* RTC Time and Date functions ************************************************/
  898. HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
  899. HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
  900. HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
  901. HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
  902. /**
  903. * @}
  904. */
  905. /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions
  906. * @{
  907. */
  908. /* RTC Alarm functions ********************************************************/
  909. HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
  910. HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
  911. HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm);
  912. HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format);
  913. void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc);
  914. void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc);
  915. HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
  916. /**
  917. * @}
  918. */
  919. /** @defgroup RTC_Exported_Functions_Group4 Peripheral Control functions
  920. * @{
  921. */
  922. /* Peripheral Control functions ***********************************************/
  923. HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc);
  924. /**
  925. * @}
  926. */
  927. /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions
  928. * @{
  929. */
  930. /* Peripheral State functions *************************************************/
  931. HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc);
  932. /**
  933. * @}
  934. */
  935. /**
  936. * @}
  937. */
  938. /* Private types -------------------------------------------------------------*/
  939. /* Private variables ---------------------------------------------------------*/
  940. /* Private constants ---------------------------------------------------------*/
  941. /** @defgroup RTC_Private_Constants RTC Private Constants
  942. * @{
  943. */
  944. /* Masks Definition */
  945. #define RTC_TR_RESERVED_MASK (RTC_TR_PM | RTC_TR_HT | RTC_TR_HU | \
  946. RTC_TR_MNT | RTC_TR_MNU| RTC_TR_ST | \
  947. RTC_TR_SU)
  948. #define RTC_DR_RESERVED_MASK (RTC_DR_YT | RTC_DR_YU | RTC_DR_WDU | \
  949. RTC_DR_MT | RTC_DR_MU | RTC_DR_DT | \
  950. RTC_DR_DU)
  951. #define RTC_INIT_MASK 0xFFFFFFFFu
  952. #if defined(RTC_ICSR_INIT) && defined(RTC_ICSR_RSF)
  953. #define RTC_RSF_MASK (~(RTC_ICSR_INIT | RTC_ICSR_RSF))
  954. #endif /* RTC_ICSR_INIT && RTC_ICSR_RSF */
  955. #if defined(RTC_ISR_INIT) && defined(RTC_ISR_RSF)
  956. #define RTC_RSF_MASK (~(RTC_ISR_INIT | RTC_ISR_RSF))
  957. #endif /* RTC_ISR_INIT && RTC_ISR_RSF */
  958. #define RTC_TIMEOUT_VALUE 1000u
  959. #define RTC_EXTI_LINE_ALARM_EVENT EXTI_IMR1_IM17 /*!< External interrupt line 17 Connected to the RTC Alarm event */
  960. /**
  961. * @}
  962. */
  963. /* Private macros ------------------------------------------------------------*/
  964. /** @defgroup RTC_Private_Macros RTC Private Macros
  965. * @{
  966. */
  967. /** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters
  968. * @{
  969. */
  970. #if defined(RTC_CR_TAMPOE)
  971. #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \
  972. ((OUTPUT) == RTC_OUTPUT_ALARMA) || \
  973. ((OUTPUT) == RTC_OUTPUT_ALARMB) || \
  974. ((OUTPUT) == RTC_OUTPUT_WAKEUP) || \
  975. ((OUTPUT) == RTC_OUTPUT_TAMPER))
  976. #else /* RTC_CR_TAMPOE not defined */
  977. #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \
  978. ((OUTPUT) == RTC_OUTPUT_ALARMA) || \
  979. ((OUTPUT) == RTC_OUTPUT_ALARMB) || \
  980. ((OUTPUT) == RTC_OUTPUT_WAKEUP))
  981. #endif /* RTC_CR_TAMPOE */
  982. #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_HOURFORMAT_12) || \
  983. ((FORMAT) == RTC_HOURFORMAT_24))
  984. #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \
  985. ((POL) == RTC_OUTPUT_POLARITY_LOW))
  986. #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \
  987. ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL))
  988. #if defined(RTC_CR_TAMPALRM_PU)
  989. #define IS_RTC_OUTPUT_PULLUP(TYPE) (((TYPE) == RTC_OUTPUT_PULLUP_NONE) || \
  990. ((TYPE) == RTC_OUTPUT_PULLUP_ON))
  991. #endif /* RTC_CR_TAMPALRM_PU */
  992. #define IS_RTC_OUTPUT_REMAP(REMAP) (((REMAP) == RTC_OUTPUT_REMAP_NONE) || \
  993. ((REMAP) == RTC_OUTPUT_REMAP_POS1))
  994. #define IS_RTC_HOURFORMAT12(PM) (((PM) == RTC_HOURFORMAT12_AM) || \
  995. ((PM) == RTC_HOURFORMAT12_PM))
  996. #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \
  997. ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \
  998. ((SAVE) == RTC_DAYLIGHTSAVING_NONE))
  999. #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \
  1000. ((OPERATION) == RTC_STOREOPERATION_SET))
  1001. #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || \
  1002. ((FORMAT) == RTC_FORMAT_BCD))
  1003. #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99u)
  1004. #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1u) && ((MONTH) <= 12u))
  1005. #define IS_RTC_DATE(DATE) (((DATE) >= 1u) && ((DATE) <= 31u))
  1006. #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \
  1007. ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \
  1008. ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
  1009. ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \
  1010. ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \
  1011. ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \
  1012. ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
  1013. #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) > 0u) && ((DATE) <= 31u))
  1014. #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \
  1015. ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \
  1016. ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
  1017. ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \
  1018. ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \
  1019. ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \
  1020. ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
  1021. #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \
  1022. ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY))
  1023. #define IS_RTC_ALARM_MASK(MASK) (((MASK) & ~(RTC_ALARMMASK_ALL)) == 0u)
  1024. #define IS_RTC_ALARM(ALARM) (((ALARM) == RTC_ALARM_A) || \
  1025. ((ALARM) == RTC_ALARM_B))
  1026. #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= RTC_ALRMASSR_SS)
  1027. #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK) (((MASK) == 0u) || \
  1028. (((MASK) >= RTC_ALARMSUBSECONDMASK_SS14_1) && ((MASK) <= RTC_ALARMSUBSECONDMASK_NONE)))
  1029. #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= (RTC_PRER_PREDIV_A >> RTC_PRER_PREDIV_A_Pos))
  1030. #define IS_RTC_SYNCH_PREDIV(PREDIV) ((PREDIV) <= (RTC_PRER_PREDIV_S >> RTC_PRER_PREDIV_S_Pos))
  1031. #define IS_RTC_HOUR12(HOUR) (((HOUR) > 0u) && ((HOUR) <= 12u))
  1032. #define IS_RTC_HOUR24(HOUR) ((HOUR) <= 23u)
  1033. #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59u)
  1034. #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59u)
  1035. /**
  1036. * @}
  1037. */
  1038. /**
  1039. * @}
  1040. */
  1041. /* Private functions -------------------------------------------------------------*/
  1042. /** @defgroup RTC_Private_Functions RTC Private Functions
  1043. * @{
  1044. */
  1045. HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef *hrtc);
  1046. uint8_t RTC_ByteToBcd2(uint8_t Value);
  1047. uint8_t RTC_Bcd2ToByte(uint8_t Value);
  1048. /**
  1049. * @}
  1050. */
  1051. /**
  1052. * @}
  1053. */
  1054. /**
  1055. * @}
  1056. */
  1057. #ifdef __cplusplus
  1058. }
  1059. #endif
  1060. #endif /* STM32H7xx_HAL_RTC_H */
  1061. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/