stm32l0xx_hal_rtc_ex.h 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143
  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_hal_rtc_ex.h
  4. * @author MCD Application Team
  5. * @brief Header file of RTC HAL Extended module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef STM32L0xx_HAL_RTC_EX_H
  20. #define STM32L0xx_HAL_RTC_EX_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32l0xx_hal_def.h"
  26. /** @addtogroup STM32L0xx_HAL_Driver
  27. * @{
  28. */
  29. /** @addtogroup RTCEx
  30. * @{
  31. */
  32. /* Exported types ------------------------------------------------------------*/
  33. /** @defgroup RTCEx_Exported_Types RTCEx Exported Types
  34. * @{
  35. */
  36. /**
  37. * @brief RTC Tamper structure definition
  38. */
  39. typedef struct
  40. {
  41. uint32_t Tamper; /*!< Specifies the Tamper Pin.
  42. This parameter can be a value of @ref RTCEx_Tamper_Pin_Definitions */
  43. uint32_t Interrupt; /*!< Specifies the Tamper Interrupt.
  44. This parameter can be a value of @ref RTCEx_Tamper_Interrupt_Definitions */
  45. uint32_t Trigger; /*!< Specifies the Tamper Trigger.
  46. This parameter can be a value of @ref RTCEx_Tamper_Trigger_Definitions */
  47. uint32_t NoErase; /*!< Specifies the Tamper no erase mode.
  48. This parameter can be a value of @ref RTCEx_Tamper_EraseBackUp_Definitions */
  49. uint32_t MaskFlag; /*!< Specifies the Tamper Flag masking.
  50. This parameter can be a value of @ref RTCEx_Tamper_MaskFlag_Definitions */
  51. uint32_t Filter; /*!< Specifies the RTC Filter Tamper.
  52. This parameter can be a value of @ref RTCEx_Tamper_Filter_Definitions */
  53. uint32_t SamplingFrequency; /*!< Specifies the sampling frequency.
  54. This parameter can be a value of @ref RTCEx_Tamper_Sampling_Frequencies_Definitions */
  55. uint32_t PrechargeDuration; /*!< Specifies the Precharge Duration .
  56. This parameter can be a value of @ref RTCEx_Tamper_Pin_Precharge_Duration_Definitions */
  57. uint32_t TamperPullUp; /*!< Specifies the Tamper PullUp .
  58. This parameter can be a value of @ref RTCEx_Tamper_Pull_Up_Definitions */
  59. uint32_t TimeStampOnTamperDetection; /*!< Specifies the TimeStampOnTamperDetection.
  60. This parameter can be a value of @ref RTCEx_Tamper_TimeStampOnTamperDetection_Definitions */
  61. } RTC_TamperTypeDef;
  62. /**
  63. * @}
  64. */
  65. /* Exported constants --------------------------------------------------------*/
  66. /** @defgroup RTCEx_Exported_Constants RTCEx Exported Constants
  67. * @{
  68. */
  69. /** @defgroup RTCEx_Backup_Registers_Definitions RTCEx Backup Registers Definitions
  70. * @{
  71. */
  72. #define RTC_BKP_DR0 0x00000000U
  73. #define RTC_BKP_DR1 0x00000001U
  74. #define RTC_BKP_DR2 0x00000002U
  75. #define RTC_BKP_DR3 0x00000003U
  76. #define RTC_BKP_DR4 0x00000004U
  77. /**
  78. * @}
  79. */
  80. /** @defgroup RTCEx_Timestamp_Edges_Definitions RTCEx Timestamp Edges Definitions
  81. * @{
  82. */
  83. #define RTC_TIMESTAMPEDGE_RISING 0x00000000U
  84. #define RTC_TIMESTAMPEDGE_FALLING RTC_CR_TSEDGE
  85. /**
  86. * @}
  87. */
  88. /** @defgroup RTCEx_Timestamp_Pin_Selection RTC Timestamp Pin Selection
  89. * @{
  90. */
  91. #define RTC_TIMESTAMPPIN_DEFAULT 0x00000000U
  92. /**
  93. * @}
  94. */
  95. /** @defgroup RTCEx_Tamper_Pin_Definitions RTCEx Tamper Pins Definitions
  96. * @{
  97. */
  98. #if defined(RTC_TAMPER1_SUPPORT)
  99. #define RTC_TAMPER_1 RTC_TAMPCR_TAMP1E
  100. #endif /* RTC_TAMPER1_SUPPORT */
  101. #define RTC_TAMPER_2 RTC_TAMPCR_TAMP2E
  102. #if defined(RTC_TAMPER3_SUPPORT)
  103. #define RTC_TAMPER_3 RTC_TAMPCR_TAMP3E
  104. #endif /* RTC_TAMPER3_SUPPORT */
  105. /**
  106. * @}
  107. */
  108. /** @defgroup RTCEx_Tamper_Pin_Selection RTC tamper Pins Selection
  109. * @{
  110. */
  111. #define RTC_TAMPERPIN_DEFAULT 0x00000000U
  112. /**
  113. * @}
  114. */
  115. /** @defgroup RTCEx_Tamper_Interrupt_Definitions RTCEx Tamper Interrupt Definitions
  116. * @{
  117. */
  118. #define RTC_IT_TAMP RTC_TAMPCR_TAMPIE /*!< Enable global Tamper Interrupt */
  119. #if defined(RTC_TAMPER1_SUPPORT)
  120. #define RTC_IT_TAMP1 RTC_TAMPCR_TAMP1IE /*!< Enable Tamper 1 Interrupt */
  121. #endif /* RTC_TAMPER1_SUPPORT */
  122. #define RTC_IT_TAMP2 RTC_TAMPCR_TAMP2IE /*!< Enable Tamper 2 Interrupt */
  123. #if defined(RTC_TAMPER3_SUPPORT)
  124. #define RTC_IT_TAMP3 RTC_TAMPCR_TAMP3IE /*!< Enable Tamper 3 Interrupt */
  125. #endif /* RTC_TAMPER3_SUPPORT */
  126. /**
  127. * @}
  128. */
  129. /** @defgroup RTCEx_Tamper_Trigger_Definitions RTCEx Tamper Triggers Definitions
  130. * @{
  131. */
  132. #define RTC_TAMPERTRIGGER_RISINGEDGE 0x00000000U
  133. #define RTC_TAMPERTRIGGER_FALLINGEDGE 0x00000002U
  134. #define RTC_TAMPERTRIGGER_LOWLEVEL RTC_TAMPERTRIGGER_RISINGEDGE
  135. #define RTC_TAMPERTRIGGER_HIGHLEVEL RTC_TAMPERTRIGGER_FALLINGEDGE
  136. /**
  137. * @}
  138. */
  139. /** @defgroup RTCEx_Tamper_EraseBackUp_Definitions RTCEx Tamper EraseBackUp Definitions
  140. * @{
  141. */
  142. #define RTC_TAMPER_ERASE_BACKUP_ENABLE 0x00000000U
  143. #define RTC_TAMPER_ERASE_BACKUP_DISABLE 0x00020000U
  144. /**
  145. * @}
  146. */
  147. /** @defgroup RTCEx_Tamper_MaskFlag_Definitions RTCEx Tamper MaskFlag Definitions
  148. * @{
  149. */
  150. #define RTC_TAMPERMASK_FLAG_DISABLE 0x00000000U
  151. #define RTC_TAMPERMASK_FLAG_ENABLE 0x00040000U
  152. /**
  153. * @}
  154. */
  155. /** @defgroup RTCEx_Tamper_Filter_Definitions RTCEx Tamper Filter Definitions
  156. * @{
  157. */
  158. #define RTC_TAMPERFILTER_DISABLE 0x00000000U /*!< Tamper filter is disabled */
  159. #define RTC_TAMPERFILTER_2SAMPLE RTC_TAMPCR_TAMPFLT_0 /*!< Tamper is activated after 2
  160. consecutive samples at the active level */
  161. #define RTC_TAMPERFILTER_4SAMPLE RTC_TAMPCR_TAMPFLT_1 /*!< Tamper is activated after 4
  162. consecutive samples at the active level */
  163. #define RTC_TAMPERFILTER_8SAMPLE RTC_TAMPCR_TAMPFLT /*!< Tamper is activated after 8
  164. consecutive samples at the active level */
  165. #define RTC_TAMPERFILTER_MASK RTC_TAMPCR_TAMPFLT /*!< Masking all bits except those of
  166. field TAMPFLT */
  167. /**
  168. * @}
  169. */
  170. /** @defgroup RTCEx_Tamper_Sampling_Frequencies_Definitions RTCEx Tamper Sampling Frequencies Definitions
  171. * @{
  172. */
  173. #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV32768 0x00000000U /*!< Each of the tamper inputs are sampled
  174. with a frequency = RTCCLK / 32768 */
  175. #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV16384 RTC_TAMPCR_TAMPFREQ_0 /*!< Each of the tamper inputs are sampled
  176. with a frequency = RTCCLK / 16384 */
  177. #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV8192 RTC_TAMPCR_TAMPFREQ_1 /*!< Each of the tamper inputs are sampled
  178. with a frequency = RTCCLK / 8192 */
  179. #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV4096 (RTC_TAMPCR_TAMPFREQ_0 | RTC_TAMPCR_TAMPFREQ_1) /*!< Each of the tamper inputs are sampled
  180. with a frequency = RTCCLK / 4096 */
  181. #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV2048 RTC_TAMPCR_TAMPFREQ_2 /*!< Each of the tamper inputs are sampled
  182. with a frequency = RTCCLK / 2048 */
  183. #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV1024 (RTC_TAMPCR_TAMPFREQ_0 | RTC_TAMPCR_TAMPFREQ_2) /*!< Each of the tamper inputs are sampled
  184. with a frequency = RTCCLK / 1024 */
  185. #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV512 (RTC_TAMPCR_TAMPFREQ_1 | RTC_TAMPCR_TAMPFREQ_2) /*!< Each of the tamper inputs are sampled
  186. with a frequency = RTCCLK / 512 */
  187. #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV256 RTC_TAMPCR_TAMPFREQ /*!< Each of the tamper inputs are sampled
  188. with a frequency = RTCCLK / 256 */
  189. #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_MASK RTC_TAMPCR_TAMPFREQ /*!< Masking all bits except those of
  190. field TAMPFREQ */
  191. /**
  192. * @}
  193. */
  194. /** @defgroup RTCEx_Tamper_Pin_Precharge_Duration_Definitions RTCEx Tamper Pin Precharge Duration Definitions
  195. * @{
  196. */
  197. #define RTC_TAMPERPRECHARGEDURATION_1RTCCLK 0x00000000U /*!< Tamper pins are pre-charged before
  198. sampling during 1 RTCCLK cycle */
  199. #define RTC_TAMPERPRECHARGEDURATION_2RTCCLK RTC_TAMPCR_TAMPPRCH_0 /*!< Tamper pins are pre-charged before
  200. sampling during 2 RTCCLK cycles */
  201. #define RTC_TAMPERPRECHARGEDURATION_4RTCCLK RTC_TAMPCR_TAMPPRCH_1 /*!< Tamper pins are pre-charged before
  202. sampling during 4 RTCCLK cycles */
  203. #define RTC_TAMPERPRECHARGEDURATION_8RTCCLK RTC_TAMPCR_TAMPPRCH /*!< Tamper pins are pre-charged before
  204. sampling during 8 RTCCLK cycles */
  205. #define RTC_TAMPERPRECHARGEDURATION_MASK RTC_TAMPCR_TAMPPRCH /*!< Masking all bits except those of
  206. field TAMPPRCH */
  207. /**
  208. * @}
  209. */
  210. /** @defgroup RTCEx_Tamper_Pull_Up_Definitions RTCEx Tamper Pull Up Definitions
  211. * @{
  212. */
  213. #define RTC_TAMPER_PULLUP_ENABLE 0x00000000U /*!< Tamper pins are pre-charged before sampling */
  214. #define RTC_TAMPER_PULLUP_DISABLE RTC_TAMPCR_TAMPPUDIS /*!< Tamper pins are not pre-charged before sampling */
  215. #define RTC_TAMPER_PULLUP_MASK RTC_TAMPCR_TAMPPUDIS /*!< Masking all bits except bit TAMPPUDIS */
  216. /**
  217. * @}
  218. */
  219. /** @defgroup RTCEx_Tamper_TimeStampOnTamperDetection_Definitions RTCEx Tamper TimeStamp On Tamper Detection Definitions
  220. * @{
  221. */
  222. #define RTC_TIMESTAMPONTAMPERDETECTION_ENABLE RTC_TAMPCR_TAMPTS /*!< TimeStamp on Tamper Detection event saved */
  223. #define RTC_TIMESTAMPONTAMPERDETECTION_DISABLE 0x00000000U /*!< TimeStamp on Tamper Detection event is not saved */
  224. #define RTC_TIMESTAMPONTAMPERDETECTION_MASK RTC_TAMPCR_TAMPTS /*!< Masking all bits except bit TAMPTS */
  225. /**
  226. * @}
  227. */
  228. /** @defgroup RTCEx_Wakeup_Timer_Definitions RTCEx Wakeup Timer Definitions
  229. * @{
  230. */
  231. #define RTC_WAKEUPCLOCK_RTCCLK_DIV16 0x00000000U
  232. #define RTC_WAKEUPCLOCK_RTCCLK_DIV8 RTC_CR_WUCKSEL_0
  233. #define RTC_WAKEUPCLOCK_RTCCLK_DIV4 RTC_CR_WUCKSEL_1
  234. #define RTC_WAKEUPCLOCK_RTCCLK_DIV2 (RTC_CR_WUCKSEL_0 | RTC_CR_WUCKSEL_1)
  235. #define RTC_WAKEUPCLOCK_CK_SPRE_16BITS RTC_CR_WUCKSEL_2
  236. #define RTC_WAKEUPCLOCK_CK_SPRE_17BITS (RTC_CR_WUCKSEL_1 | RTC_CR_WUCKSEL_2)
  237. /**
  238. * @}
  239. */
  240. /** @defgroup RTCEx_Smooth_calib_period_Definitions RTCEx Smooth Calib Period Definitions
  241. * @{
  242. */
  243. #define RTC_SMOOTHCALIB_PERIOD_32SEC 0x00000000U /*!< If RTCCLK = 32768 Hz, smooth calibration
  244. period is 32s, otherwise 2^20 RTCCLK pulses */
  245. #define RTC_SMOOTHCALIB_PERIOD_16SEC RTC_CALR_CALW16 /*!< If RTCCLK = 32768 Hz, smooth calibration
  246. period is 16s, otherwise 2^19 RTCCLK pulses */
  247. #define RTC_SMOOTHCALIB_PERIOD_8SEC RTC_CALR_CALW8 /*!< If RTCCLK = 32768 Hz, smooth calibration
  248. period is 8s, otherwise 2^18 RTCCLK pulses */
  249. /**
  250. * @}
  251. */
  252. /** @defgroup RTCEx_Smooth_calib_Plus_pulses_Definitions RTCEx Smooth Calib Plus Pulses Definitions
  253. * @{
  254. */
  255. #define RTC_SMOOTHCALIB_PLUSPULSES_SET RTC_CALR_CALP /*!< The number of RTCCLK pulses added
  256. during a X -second window = Y - CALM[8:0]
  257. with Y = 512, 256, 128 when X = 32, 16, 8 */
  258. #define RTC_SMOOTHCALIB_PLUSPULSES_RESET 0x00000000U /*!< The number of RTCCLK pulses subbstited
  259. during a 32-second window = CALM[8:0] */
  260. /**
  261. * @}
  262. */
  263. /** @defgroup RTCEx_Add_1_Second_Parameter_Definitions RTCEx Add 1 Second Parameter Definitions
  264. * @{
  265. */
  266. #define RTC_SHIFTADD1S_RESET 0x00000000U
  267. #define RTC_SHIFTADD1S_SET RTC_SHIFTR_ADD1S
  268. /**
  269. * @}
  270. */
  271. /** @defgroup RTCEx_Calib_Output_selection_Definitions RTCEx Calib Output Selection Definitions
  272. * @{
  273. */
  274. #define RTC_CALIBOUTPUT_512HZ 0x00000000U
  275. #define RTC_CALIBOUTPUT_1HZ RTC_CR_COSEL
  276. /**
  277. * @}
  278. */
  279. /**
  280. * @}
  281. */
  282. /* Exported macros -----------------------------------------------------------*/
  283. /** @defgroup RTCEx_Exported_Macros RTCEx Exported Macros
  284. * @{
  285. */
  286. /* ---------------------------------WAKEUPTIMER-------------------------------*/
  287. /** @defgroup RTCEx_WakeUp_Timer RTCEx WakeUp Timer
  288. * @{
  289. */
  290. /**
  291. * @brief Enable the RTC WakeUp Timer peripheral.
  292. * @param __HANDLE__ specifies the RTC handle.
  293. * @retval None
  294. */
  295. #define __HAL_RTC_WAKEUPTIMER_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_WUTE))
  296. /**
  297. * @brief Disable the RTC Wakeup Timer peripheral.
  298. * @param __HANDLE__ specifies the RTC handle.
  299. * @retval None
  300. */
  301. #define __HAL_RTC_WAKEUPTIMER_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_WUTE))
  302. /**
  303. * @brief Enable the RTC Wakeup Timer interrupt.
  304. * @param __HANDLE__ specifies the RTC handle.
  305. * @param __INTERRUPT__ specifies the RTC Wakeup Timer interrupt sources to be enabled or disabled.
  306. * This parameter can be:
  307. * @arg RTC_IT_WUT: Wakeup Timer interrupt
  308. * @retval None
  309. */
  310. #define __HAL_RTC_WAKEUPTIMER_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
  311. /**
  312. * @brief Disable the RTC Wakeup Timer interrupt.
  313. * @param __HANDLE__ specifies the RTC handle.
  314. * @param __INTERRUPT__ specifies the RTC Wakeup Timer interrupt sources to be enabled or disabled.
  315. * This parameter can be:
  316. * @arg RTC_IT_WUT: Wakeup Timer interrupt
  317. * @retval None
  318. */
  319. #define __HAL_RTC_WAKEUPTIMER_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
  320. /**
  321. * @brief Check whether the specified RTC Wakeup Timer interrupt has occurred or not.
  322. * @param __HANDLE__ specifies the RTC handle.
  323. * @param __INTERRUPT__ specifies the RTC Wakeup Timer interrupt to check.
  324. * This parameter can be:
  325. * @arg RTC_IT_WUT: Wakeup Timer interrupt
  326. * @retval None
  327. */
  328. #define __HAL_RTC_WAKEUPTIMER_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->ISR) & ((__INTERRUPT__) >> 4U)) != 0U) ? 1U : 0U)
  329. /**
  330. * @brief Check whether the specified RTC Wakeup timer interrupt has been enabled or not.
  331. * @param __HANDLE__ specifies the RTC handle.
  332. * @param __INTERRUPT__ specifies the RTC Wakeup timer interrupt sources to check.
  333. * This parameter can be:
  334. * @arg RTC_IT_WUT: WakeUpTimer interrupt
  335. * @retval None
  336. */
  337. #define __HAL_RTC_WAKEUPTIMER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
  338. /**
  339. * @brief Get the selected RTC Wakeup Timer's flag status.
  340. * @param __HANDLE__ specifies the RTC handle.
  341. * @param __FLAG__ specifies the RTC Wakeup Timer flag to check.
  342. * This parameter can be:
  343. * @arg RTC_FLAG_WUTF: Wakeup Timer interrupt flag
  344. * @arg RTC_FLAG_WUTWF: Wakeup Timer 'write allowed' flag
  345. * @retval None
  346. */
  347. #define __HAL_RTC_WAKEUPTIMER_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U)? 1U : 0U)
  348. /**
  349. * @brief Clear the RTC Wakeup timer's pending flags.
  350. * @param __HANDLE__ specifies the RTC handle.
  351. * @param __FLAG__ specifies the RTC Wakeup Timer Flag to clear.
  352. * This parameter can be:
  353. * @arg RTC_FLAG_WUTF: Wakeup Timer interrupt Flag
  354. * @retval None
  355. */
  356. #define __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
  357. /**
  358. * @brief Enable interrupt on the RTC Wakeup Timer associated EXTI line.
  359. * @retval None
  360. */
  361. #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT() (EXTI->IMR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
  362. /**
  363. * @brief Disable interrupt on the RTC Wakeup Timer associated EXTI line.
  364. * @retval None
  365. */
  366. #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_IT() (EXTI->IMR &= ~RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
  367. /**
  368. * @brief Enable event on the RTC Wakeup Timer associated EXTI line.
  369. * @retval None.
  370. */
  371. #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_EVENT() (EXTI->EMR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
  372. /**
  373. * @brief Disable event on the RTC Wakeup Timer associated EXTI line.
  374. * @retval None.
  375. */
  376. #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_EVENT() (EXTI->EMR &= ~RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
  377. /**
  378. * @brief Enable falling edge trigger on the RTC Wakeup Timer associated EXTI line.
  379. * @retval None.
  380. */
  381. #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_FALLING_EDGE() (EXTI->FTSR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
  382. /**
  383. * @brief Disable falling edge trigger on the RTC Wakeup Timer associated EXTI line.
  384. * @retval None.
  385. */
  386. #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_FALLING_EDGE() (EXTI->FTSR &= ~RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
  387. /**
  388. * @brief Enable rising edge trigger on the RTC Wakeup Timer associated EXTI line.
  389. * @retval None.
  390. */
  391. #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE() (EXTI->RTSR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
  392. /**
  393. * @brief Disable rising edge trigger on the RTC Wakeup Timer associated EXTI line.
  394. * @retval None.
  395. */
  396. #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_RISING_EDGE() (EXTI->RTSR &= ~RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
  397. /**
  398. * @brief Enable rising & falling edge trigger on the RTC Wakeup Timer associated EXTI line.
  399. * @retval None.
  400. */
  401. #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
  402. __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE(); \
  403. __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_FALLING_EDGE(); \
  404. } while(0U)
  405. /**
  406. * @brief Disable rising & falling edge trigger on the RTC Wakeup Timer associated EXTI line.
  407. * This parameter can be:
  408. * @retval None.
  409. */
  410. #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
  411. __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_RISING_EDGE(); \
  412. __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_FALLING_EDGE(); \
  413. } while(0U)
  414. /**
  415. * @brief Check whether the RTC Wakeup Timer associated EXTI line interrupt flag is set or not.
  416. * @retval Line Status.
  417. */
  418. #define __HAL_RTC_WAKEUPTIMER_EXTI_GET_FLAG() (EXTI->PR & RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
  419. /**
  420. * @brief Clear the RTC Wakeup Timer associated EXTI line flag.
  421. * @retval None.
  422. */
  423. #define __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG() (EXTI->PR = RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
  424. /**
  425. * @brief Generate a Software interrupt on the RTC Wakeup Timer associated EXTI line.
  426. * @retval None.
  427. */
  428. #define __HAL_RTC_WAKEUPTIMER_EXTI_GENERATE_SWIT() (EXTI->SWIER |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
  429. /**
  430. * @}
  431. */
  432. /* ---------------------------------TIMESTAMP---------------------------------*/
  433. /** @defgroup RTCEx_Timestamp RTCEx Timestamp
  434. * @{
  435. */
  436. /**
  437. * @brief Enable the RTC Timestamp peripheral.
  438. * @param __HANDLE__ specifies the RTC handle.
  439. * @retval None
  440. */
  441. #define __HAL_RTC_TIMESTAMP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_TSE))
  442. /**
  443. * @brief Disable the RTC Timestamp peripheral.
  444. * @param __HANDLE__ specifies the RTC handle.
  445. * @retval None
  446. */
  447. #define __HAL_RTC_TIMESTAMP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_TSE))
  448. /**
  449. * @brief Enable the RTC Timestamp interrupt.
  450. * @param __HANDLE__ specifies the RTC handle.
  451. * @param __INTERRUPT__ specifies the RTC Timestamp interrupt sources to be enabled or disabled.
  452. * This parameter can be:
  453. * @arg RTC_IT_TS: TimeStamp interrupt
  454. * @retval None
  455. */
  456. #define __HAL_RTC_TIMESTAMP_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
  457. /**
  458. * @brief Disable the RTC Timestamp interrupt.
  459. * @param __HANDLE__ specifies the RTC handle.
  460. * @param __INTERRUPT__ specifies the RTC Timestamp interrupt sources to be enabled or disabled.
  461. * This parameter can be:
  462. * @arg RTC_IT_TS: TimeStamp interrupt
  463. * @retval None
  464. */
  465. #define __HAL_RTC_TIMESTAMP_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
  466. /**
  467. * @brief Check whether the specified RTC Timestamp interrupt has occurred or not.
  468. * @param __HANDLE__ specifies the RTC handle.
  469. * @param __INTERRUPT__ specifies the RTC Timestamp interrupt to check.
  470. * This parameter can be:
  471. * @arg RTC_IT_TS: TimeStamp interrupt
  472. * @retval None
  473. */
  474. #define __HAL_RTC_TIMESTAMP_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->ISR) & ((__INTERRUPT__) >> 4U)) != 0U) ? 1U : 0U)
  475. /**
  476. * @brief Check whether the specified RTC Timestamp interrupt has been enabled or not.
  477. * @param __HANDLE__ specifies the RTC handle.
  478. * @param __INTERRUPT__ specifies the RTC Timestamp interrupt source to check.
  479. * This parameter can be:
  480. * @arg RTC_IT_TS: TimeStamp interrupt
  481. * @retval None
  482. */
  483. #define __HAL_RTC_TIMESTAMP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
  484. /**
  485. * @brief Get the selected RTC Timestamp's flag status.
  486. * @param __HANDLE__ specifies the RTC handle.
  487. * @param __FLAG__ specifies the RTC Timestamp flag to check.
  488. * This parameter can be:
  489. * @arg RTC_FLAG_TSF: Timestamp interrupt flag
  490. * @arg RTC_FLAG_TSOVF: Timestamp overflow flag
  491. * @retval None
  492. */
  493. #define __HAL_RTC_TIMESTAMP_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U)? 1U : 0U)
  494. /**
  495. * @brief Clear the RTC Timestamp's pending flags.
  496. * @param __HANDLE__ specifies the RTC handle.
  497. * @param __FLAG__ specifies the RTC Timestamp flag to clear.
  498. * This parameter can be:
  499. * @arg RTC_FLAG_TSF: Timestamp interrupt flag
  500. * @arg RTC_FLAG_TSOVF: Timestamp overflow flag
  501. * @retval None
  502. */
  503. #define __HAL_RTC_TIMESTAMP_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
  504. /**
  505. * @}
  506. */
  507. /* ---------------------------------TAMPER------------------------------------*/
  508. /** @defgroup RTCEx_Tamper RTCEx Tamper
  509. * @{
  510. */
  511. #if defined(RTC_TAMPER1_SUPPORT)
  512. /**
  513. * @brief Enable the RTC Tamper1 input detection.
  514. * @param __HANDLE__ specifies the RTC handle.
  515. * @retval None
  516. */
  517. #define __HAL_RTC_TAMPER1_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->TAMPCR |= (RTC_TAMPCR_TAMP1E))
  518. /**
  519. * @brief Disable the RTC Tamper1 input detection.
  520. * @param __HANDLE__ specifies the RTC handle.
  521. * @retval None
  522. */
  523. #define __HAL_RTC_TAMPER1_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->TAMPCR &= ~(RTC_TAMPCR_TAMP1E))
  524. #endif /* RTC_TAMPER1_SUPPORT */
  525. /**
  526. * @brief Enable the RTC Tamper2 input detection.
  527. * @param __HANDLE__ specifies the RTC handle.
  528. * @retval None
  529. */
  530. #define __HAL_RTC_TAMPER2_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->TAMPCR |= (RTC_TAMPCR_TAMP2E))
  531. /**
  532. * @brief Disable the RTC Tamper2 input detection.
  533. * @param __HANDLE__ specifies the RTC handle.
  534. * @retval None
  535. */
  536. #define __HAL_RTC_TAMPER2_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->TAMPCR &= ~(RTC_TAMPCR_TAMP2E))
  537. #if defined(RTC_TAMPER3_SUPPORT)
  538. /**
  539. * @brief Enable the RTC Tamper3 input detection.
  540. * @param __HANDLE__ specifies the RTC handle.
  541. * @retval None
  542. */
  543. #define __HAL_RTC_TAMPER3_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->TAMPCR |= (RTC_TAMPCR_TAMP3E))
  544. /**
  545. * @brief Disable the RTC Tamper3 input detection.
  546. * @param __HANDLE__ specifies the RTC handle.
  547. * @retval None
  548. */
  549. #define __HAL_RTC_TAMPER3_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->TAMPCR &= ~(RTC_TAMPCR_TAMP3E))
  550. #endif /* RTC_TAMPER3_SUPPORT */
  551. /**
  552. * @brief Enable the RTC Tamper interrupt.
  553. * @param __HANDLE__ specifies the RTC handle.
  554. * @param __INTERRUPT__ specifies the RTC Tamper interrupt sources to be enabled.
  555. * This parameter can be any combination of the following values:
  556. * @arg RTC_IT_TAMP: Tamper global interrupt
  557. * @arg RTC_IT_TAMP1: Tamper 1 interrupt
  558. * @arg RTC_IT_TAMP2: Tamper 2 interrupt
  559. * @arg RTC_IT_TAMP3: Tamper 3 interrupt
  560. * @note RTC_IT_TAMP1 is not applicable to all devices.
  561. * @note RTC_IT_TAMP3 is not applicable to all devices.
  562. * @retval None
  563. */
  564. #define __HAL_RTC_TAMPER_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->TAMPCR |= (__INTERRUPT__))
  565. /**
  566. * @brief Disable the RTC Tamper interrupt.
  567. * @param __HANDLE__ specifies the RTC handle.
  568. * @param __INTERRUPT__ specifies the RTC Tamper interrupt sources to be disabled.
  569. * This parameter can be any combination of the following values:
  570. * @arg RTC_IT_TAMP: Tamper global interrupt
  571. * @arg RTC_IT_TAMP1: Tamper 1 interrupt
  572. * @arg RTC_IT_TAMP2: Tamper 2 interrupt
  573. * @arg RTC_IT_TAMP3: Tamper 3 interrupt
  574. * @note RTC_IT_TAMP1 is not applicable to all devices.
  575. * @note RTC_IT_TAMP3 is not applicable to all devices.
  576. * @retval None
  577. */
  578. #define __HAL_RTC_TAMPER_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->TAMPCR &= ~(__INTERRUPT__))
  579. /**
  580. * @brief Check whether the specified RTC Tamper interrupt has occurred or not.
  581. * @param __HANDLE__ specifies the RTC handle.
  582. * @param __INTERRUPT__ specifies the RTC Tamper interrupt to check.
  583. * This parameter can be:
  584. * @arg RTC_IT_TAMP1: Tamper 1 interrupt
  585. * @arg RTC_IT_TAMP2: Tamper 2 interrupt
  586. * @arg RTC_IT_TAMP3: Tamper 3 interrupt
  587. * @note RTC_IT_TAMP1 is not applicable to all devices.
  588. * @note RTC_IT_TAMP3 is not applicable to all devices.
  589. * @retval None
  590. */
  591. #define __HAL_RTC_TAMPER_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->ISR) & ((__INTERRUPT__) >> 4U)) != 0U) ? 1U : 0U)
  592. /**
  593. * @brief Check whether the specified RTC Tamper interrupt has been enabled or not.
  594. * @param __HANDLE__ specifies the RTC handle.
  595. * @param __INTERRUPT__ specifies the RTC Tamper interrupt source to check.
  596. * This parameter can be:
  597. * @arg RTC_IT_TAMP: Tamper global interrupt
  598. * @arg RTC_IT_TAMP1: Tamper 1 interrupt
  599. * @arg RTC_IT_TAMP2: Tamper 2 interrupt
  600. * @arg RTC_IT_TAMP3: Tamper 3 interrupt
  601. * @note RTC_IT_TAMP1 is not applicable to all devices.
  602. * @note RTC_IT_TAMP3 is not applicable to all devices.
  603. * @retval None
  604. */
  605. #define __HAL_RTC_TAMPER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->TAMPCR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
  606. /**
  607. * @brief Get the selected RTC Tamper's flag status.
  608. * @param __HANDLE__ specifies the RTC handle.
  609. * @param __FLAG__ specifies the RTC Tamper flag to be checked.
  610. * This parameter can be:
  611. * @arg RTC_FLAG_TAMP1F: Tamper 1 interrupt flag
  612. * @arg RTC_FLAG_TAMP2F: Tamper 2 interrupt flag
  613. * @arg RTC_FLAG_TAMP3F: Tamper 3 interrupt flag
  614. * @note RTC_FLAG_TAMP1F is not applicable to all devices.
  615. * @note RTC_FLAG_TAMP3F is not applicable to all devices.
  616. * @retval None
  617. */
  618. #define __HAL_RTC_TAMPER_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U)? 1U : 0U)
  619. /**
  620. * @brief Clear the RTC Tamper's pending flags.
  621. * @param __HANDLE__ specifies the RTC handle.
  622. * @param __FLAG__ specifies the RTC Tamper Flag to clear.
  623. * This parameter can be:
  624. * @arg RTC_FLAG_TAMP1F: Tamper 1 interrupt flag
  625. * @arg RTC_FLAG_TAMP2F: Tamper 2 interrupt flag
  626. * @arg RTC_FLAG_TAMP3F: Tamper 3 interrupt flag
  627. * @note RTC_FLAG_TAMP1F is not applicable to all devices.
  628. * @note RTC_FLAG_TAMP3F is not applicable to all devices.
  629. * @retval None
  630. */
  631. #define __HAL_RTC_TAMPER_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
  632. /**
  633. * @}
  634. */
  635. /* --------------------------TAMPER/TIMESTAMP---------------------------------*/
  636. /** @defgroup RTCEx_Tamper_Timestamp EXTI RTC Tamper Timestamp EXTI
  637. * @{
  638. */
  639. /**
  640. * @brief Enable interrupt on the RTC Tamper and Timestamp associated EXTI line.
  641. * @retval None
  642. */
  643. #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT() (EXTI->IMR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
  644. /**
  645. * @brief Disable interrupt on the RTC Tamper and Timestamp associated EXTI line.
  646. * @retval None
  647. */
  648. #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_IT() (EXTI->IMR &= ~RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
  649. /**
  650. * @brief Enable event on the RTC Tamper and Timestamp associated EXTI line.
  651. * @retval None.
  652. */
  653. #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_EVENT() (EXTI->EMR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
  654. /**
  655. * @brief Disable event on the RTC Tamper and Timestamp associated EXTI line.
  656. * @retval None.
  657. */
  658. #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_EVENT() (EXTI->EMR &= ~RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
  659. /**
  660. * @brief Enable falling edge trigger on the RTC Tamper and Timestamp associated EXTI line.
  661. * @retval None.
  662. */
  663. #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_FALLING_EDGE() (EXTI->FTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
  664. /**
  665. * @brief Disable falling edge trigger on the RTC Tamper and Timestamp associated EXTI line.
  666. * @retval None.
  667. */
  668. #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_FALLING_EDGE() (EXTI->FTSR &= ~RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
  669. /**
  670. * @brief Enable rising edge trigger on the RTC Tamper and Timestamp associated EXTI line.
  671. * @retval None.
  672. */
  673. #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE() (EXTI->RTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
  674. /**
  675. * @brief Disable rising edge trigger on the RTC Tamper and Timestamp associated EXTI line.
  676. * @retval None.
  677. */
  678. #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_RISING_EDGE() (EXTI->RTSR &= ~RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
  679. /**
  680. * @brief Enable rising & falling edge trigger on the RTC Tamper and Timestamp associated EXTI line.
  681. * @retval None.
  682. */
  683. #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
  684. __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE(); \
  685. __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_FALLING_EDGE(); \
  686. } while(0U)
  687. /**
  688. * @brief Disable rising & falling edge trigger on the RTC Tamper and Timestamp associated EXTI line.
  689. * This parameter can be:
  690. * @retval None.
  691. */
  692. #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
  693. __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_RISING_EDGE(); \
  694. __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_FALLING_EDGE(); \
  695. } while(0U)
  696. /**
  697. * @brief Check whether the RTC Tamper and Timestamp associated EXTI line interrupt flag is set or not.
  698. * @retval Line Status.
  699. */
  700. #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_GET_FLAG() (EXTI->PR & RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
  701. /**
  702. * @brief Clear the RTC Tamper and Timestamp associated EXTI line flag.
  703. * @retval None.
  704. */
  705. #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG() (EXTI->PR = RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
  706. /**
  707. * @brief Generate a Software interrupt on the RTC Tamper and Timestamp associated EXTI line
  708. * @retval None.
  709. */
  710. #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_GENERATE_SWIT() (EXTI->SWIER |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
  711. /**
  712. * @}
  713. */
  714. /* ------------------------------CALIBRATION----------------------------------*/
  715. /** @defgroup RTCEx_Calibration RTCEx Calibration
  716. * @{
  717. */
  718. /**
  719. * @brief Enable the RTC calibration output.
  720. * @param __HANDLE__ specifies the RTC handle.
  721. * @retval None
  722. */
  723. #define __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_COE))
  724. /**
  725. * @brief Disable the calibration output.
  726. * @param __HANDLE__ specifies the RTC handle.
  727. * @retval None
  728. */
  729. #define __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_COE))
  730. /**
  731. * @brief Enable the clock reference detection.
  732. * @param __HANDLE__ specifies the RTC handle.
  733. * @retval None
  734. */
  735. #define __HAL_RTC_CLOCKREF_DETECTION_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_REFCKON))
  736. /**
  737. * @brief Disable the clock reference detection.
  738. * @param __HANDLE__ specifies the RTC handle.
  739. * @retval None
  740. */
  741. #define __HAL_RTC_CLOCKREF_DETECTION_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_REFCKON))
  742. /**
  743. * @brief Get the selected RTC shift operation's flag status.
  744. * @param __HANDLE__ specifies the RTC handle.
  745. * @param __FLAG__ specifies the RTC shift operation Flag is pending or not.
  746. * This parameter can be:
  747. * @arg RTC_FLAG_SHPF: Shift pending flag
  748. * @retval None
  749. */
  750. #define __HAL_RTC_SHIFT_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U)? 1U : 0U)
  751. /**
  752. * @}
  753. */
  754. /**
  755. * @}
  756. */
  757. /* Exported functions --------------------------------------------------------*/
  758. /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions
  759. * @{
  760. */
  761. /** @addtogroup RTCEx_Exported_Functions_Group1
  762. * @{
  763. */
  764. /* RTC Timestamp and Tamper functions *****************************************/
  765. HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t RTC_TimeStampEdge, uint32_t RTC_TimeStampPin);
  766. HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t RTC_TimeStampEdge, uint32_t RTC_TimeStampPin);
  767. HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc);
  768. HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTimeStamp, RTC_DateTypeDef *sTimeStampDate, uint32_t Format);
  769. HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper);
  770. HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper);
  771. HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper);
  772. void HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc);
  773. #if defined(RTC_TAMPER1_SUPPORT)
  774. void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc);
  775. #endif /* RTC_TAMPER1_SUPPORT */
  776. void HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef *hrtc);
  777. #if defined(RTC_TAMPER3_SUPPORT)
  778. void HAL_RTCEx_Tamper3EventCallback(RTC_HandleTypeDef *hrtc);
  779. #endif /* RTC_TAMPER3_SUPPORT */
  780. void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc);
  781. HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
  782. #if defined(RTC_TAMPER1_SUPPORT)
  783. HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
  784. #endif /* RTC_TAMPER1_SUPPORT */
  785. HAL_StatusTypeDef HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
  786. #if defined(RTC_TAMPER3_SUPPORT)
  787. HAL_StatusTypeDef HAL_RTCEx_PollForTamper3Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
  788. #endif /* RTC_TAMPER3_SUPPORT */
  789. /**
  790. * @}
  791. */
  792. /** @addtogroup RTCEx_Exported_Functions_Group2
  793. * @{
  794. */
  795. /* RTC Wakeup functions ******************************************************/
  796. HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock);
  797. HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock);
  798. HAL_StatusTypeDef HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc);
  799. uint32_t HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc);
  800. void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc);
  801. void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc);
  802. HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
  803. /**
  804. * @}
  805. */
  806. /** @addtogroup RTCEx_Exported_Functions_Group3
  807. * @{
  808. */
  809. /* Extended Control functions ************************************************/
  810. void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data);
  811. uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister);
  812. HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef *hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmoothCalibMinusPulsesValue);
  813. HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef *hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS);
  814. HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef *hrtc, uint32_t CalibOutput);
  815. HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef *hrtc);
  816. HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef *hrtc);
  817. HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef *hrtc);
  818. HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef *hrtc);
  819. HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef *hrtc);
  820. /**
  821. * @}
  822. */
  823. /** @addtogroup RTCEx_Exported_Functions_Group4
  824. * @{
  825. */
  826. /* Extended RTC features functions *******************************************/
  827. void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc);
  828. HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
  829. /**
  830. * @}
  831. */
  832. /**
  833. * @}
  834. */
  835. /* Private types -------------------------------------------------------------*/
  836. /* Private variables ---------------------------------------------------------*/
  837. /* Private constants ---------------------------------------------------------*/
  838. /** @defgroup RTCEx_Private_Constants RTCEx Private Constants
  839. * @{
  840. */
  841. #define RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT EXTI_IMR_IM19 /*!< External interrupt line 19 Connected to the RTC Tamper and Timestamp event */
  842. #define RTC_EXTI_LINE_WAKEUPTIMER_EVENT EXTI_IMR_IM20 /*!< External interrupt line 20 Connected to the RTC Wakeup event */
  843. /**
  844. * @}
  845. */
  846. /** @defgroup RTCEx_Private_Constants RTCEx Private Constants
  847. * @{
  848. */
  849. /* Masks Definition */
  850. #if defined(RTC_TAMPER3_SUPPORT)
  851. #if defined(RTC_TAMPER1_SUPPORT)
  852. #define RTC_TAMPER_ENABLE_BITS_MASK ((uint32_t) (RTC_TAMPER_1 | \
  853. RTC_TAMPER_2 | \
  854. RTC_TAMPER_3))
  855. #define RTC_TAMPER_FLAGS_MASK ((uint32_t) (RTC_FLAG_TAMP1F | \
  856. RTC_FLAG_TAMP2F | \
  857. RTC_FLAG_TAMP3F))
  858. #else /* RTC_TAMPER1_SUPPORT */
  859. #define RTC_TAMPER_ENABLE_BITS_MASK ((uint32_t) (RTC_TAMPER_2 | \
  860. RTC_TAMPER_3))
  861. #define RTC_TAMPER_FLAGS_MASK ((uint32_t) (RTC_FLAG_TAMP2F | \
  862. RTC_FLAG_TAMP3F))
  863. #endif /* RTC_TAMPER1_SUPPORT */
  864. #else /* RTC_TAMPER3_SUPPORT */
  865. #if defined(RTC_TAMPER1_SUPPORT)
  866. #define RTC_TAMPER_ENABLE_BITS_MASK ((uint32_t) (RTC_TAMPER_1 | \
  867. RTC_TAMPER_2))
  868. #define RTC_TAMPER_FLAGS_MASK ((uint32_t) (RTC_FLAG_TAMP1F | \
  869. RTC_FLAG_TAMP2F))
  870. #else /* RTC_TAMPER1_SUPPORT */
  871. #define RTC_TAMPER_ENABLE_BITS_MASK RTC_TAMPER_2
  872. #define RTC_TAMPER_FLAGS_MASK RTC_FLAG_TAMP2F
  873. #endif /* RTC_TAMPER1_SUPPORT */
  874. #endif /* RTC_TAMPER3_SUPPORT */
  875. #if defined(RTC_TAMPER3_SUPPORT)
  876. #if defined(RTC_TAMPER1_SUPPORT)
  877. #define RTC_TAMPER_IT_ENABLE_BITS_MASK ((uint32_t) (RTC_IT_TAMP1 | \
  878. RTC_IT_TAMP2 | \
  879. RTC_IT_TAMP3 | \
  880. RTC_IT_TAMP))
  881. #else /* RTC_TAMPER1_SUPPORT */
  882. #define RTC_TAMPER_IT_ENABLE_BITS_MASK ((uint32_t) (RTC_IT_TAMP2 | \
  883. RTC_IT_TAMP3 | \
  884. RTC_IT_TAMP))
  885. #endif /* RTC_TAMPER1_SUPPORT */
  886. #else /* RTC_TAMPER3_SUPPORT */
  887. #if defined(RTC_TAMPER1_SUPPORT)
  888. #define RTC_TAMPER_IT_ENABLE_BITS_MASK ((uint32_t) (RTC_IT_TAMP1 | \
  889. RTC_IT_TAMP2 | \
  890. RTC_IT_TAMP))
  891. #else /* RTC_TAMPER1_SUPPORT */
  892. #define RTC_TAMPER_IT_ENABLE_BITS_MASK ((uint32_t) (RTC_IT_TAMP2 | \
  893. RTC_IT_TAMP))
  894. #endif /* RTC_TAMPER1_SUPPORT */
  895. #endif /* RTC_TAMPER3_SUPPORT */
  896. /**
  897. * @}
  898. */
  899. /* Private macros ------------------------------------------------------------*/
  900. /** @defgroup RTCEx_Private_Macros RTCEx Private Macros
  901. * @{
  902. */
  903. /** @defgroup RTCEx_IS_RTC_Definitions Private macros to check input parameters
  904. * @{
  905. */
  906. #define IS_RTC_BKP(BKP) ((BKP) < (uint32_t) RTC_BKP_NUMBER)
  907. #define IS_TIMESTAMP_EDGE(EDGE) (((EDGE) == RTC_TIMESTAMPEDGE_RISING) || \
  908. ((EDGE) == RTC_TIMESTAMPEDGE_FALLING))
  909. #define IS_RTC_TAMPER(TAMPER) ((((TAMPER) & ((uint32_t)~RTC_TAMPER_ENABLE_BITS_MASK)) == 0x00U) && ((TAMPER) != 0U))
  910. #define IS_RTC_TAMPER_PIN(PIN) ((PIN) == RTC_TAMPERPIN_DEFAULT)
  911. #define IS_RTC_TIMESTAMP_PIN(PIN) ((PIN) == RTC_TIMESTAMPPIN_DEFAULT)
  912. #define IS_RTC_TAMPER_INTERRUPT(INTERRUPT) ((((INTERRUPT) & ((uint32_t)~RTC_TAMPER_IT_ENABLE_BITS_MASK )) == 0x00U) && ((INTERRUPT) != 0U))
  913. #define IS_RTC_TAMPER_TRIGGER(TRIGGER) (((TRIGGER) == RTC_TAMPERTRIGGER_RISINGEDGE) || \
  914. ((TRIGGER) == RTC_TAMPERTRIGGER_FALLINGEDGE) || \
  915. ((TRIGGER) == RTC_TAMPERTRIGGER_LOWLEVEL) || \
  916. ((TRIGGER) == RTC_TAMPERTRIGGER_HIGHLEVEL))
  917. #define IS_RTC_TAMPER_ERASE_MODE(MODE) (((MODE) == RTC_TAMPER_ERASE_BACKUP_ENABLE) || \
  918. ((MODE) == RTC_TAMPER_ERASE_BACKUP_DISABLE))
  919. #define IS_RTC_TAMPER_MASKFLAG_STATE(STATE) (((STATE) == RTC_TAMPERMASK_FLAG_ENABLE) || \
  920. ((STATE) == RTC_TAMPERMASK_FLAG_DISABLE))
  921. #define IS_RTC_TAMPER_FILTER(FILTER) (((FILTER) == RTC_TAMPERFILTER_DISABLE) || \
  922. ((FILTER) == RTC_TAMPERFILTER_2SAMPLE) || \
  923. ((FILTER) == RTC_TAMPERFILTER_4SAMPLE) || \
  924. ((FILTER) == RTC_TAMPERFILTER_8SAMPLE))
  925. #define IS_RTC_TAMPER_FILTER_CONFIG_CORRECT(FILTER, TRIGGER) \
  926. ( ( ((FILTER) != RTC_TAMPERFILTER_DISABLE) \
  927. && ( ((TRIGGER) == RTC_TAMPERTRIGGER_LOWLEVEL) \
  928. || ((TRIGGER) == RTC_TAMPERTRIGGER_HIGHLEVEL))) \
  929. || ( ((FILTER) == RTC_TAMPERFILTER_DISABLE) \
  930. && ( ((TRIGGER) == RTC_TAMPERTRIGGER_RISINGEDGE) \
  931. || ((TRIGGER) == RTC_TAMPERTRIGGER_FALLINGEDGE))))
  932. #define IS_RTC_TAMPER_SAMPLING_FREQ(FREQ) (((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV32768)|| \
  933. ((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV16384)|| \
  934. ((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV8192) || \
  935. ((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV4096) || \
  936. ((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV2048) || \
  937. ((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV1024) || \
  938. ((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV512) || \
  939. ((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV256))
  940. #define IS_RTC_TAMPER_PRECHARGE_DURATION(DURATION) (((DURATION) == RTC_TAMPERPRECHARGEDURATION_1RTCCLK) || \
  941. ((DURATION) == RTC_TAMPERPRECHARGEDURATION_2RTCCLK) || \
  942. ((DURATION) == RTC_TAMPERPRECHARGEDURATION_4RTCCLK) || \
  943. ((DURATION) == RTC_TAMPERPRECHARGEDURATION_8RTCCLK))
  944. #define IS_RTC_TAMPER_PULLUP_STATE(STATE) (((STATE) == RTC_TAMPER_PULLUP_ENABLE) || \
  945. ((STATE) == RTC_TAMPER_PULLUP_DISABLE))
  946. #define IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(DETECTION) (((DETECTION) == RTC_TIMESTAMPONTAMPERDETECTION_ENABLE) || \
  947. ((DETECTION) == RTC_TIMESTAMPONTAMPERDETECTION_DISABLE))
  948. #define IS_RTC_WAKEUP_CLOCK(CLOCK) (((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV16) || \
  949. ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV8) || \
  950. ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV4) || \
  951. ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV2) || \
  952. ((CLOCK) == RTC_WAKEUPCLOCK_CK_SPRE_16BITS) || \
  953. ((CLOCK) == RTC_WAKEUPCLOCK_CK_SPRE_17BITS))
  954. #define IS_RTC_WAKEUP_COUNTER(COUNTER) ((COUNTER) <= RTC_WUTR_WUT)
  955. #define IS_RTC_SMOOTH_CALIB_PERIOD(PERIOD) (((PERIOD) == RTC_SMOOTHCALIB_PERIOD_32SEC) || \
  956. ((PERIOD) == RTC_SMOOTHCALIB_PERIOD_16SEC) || \
  957. ((PERIOD) == RTC_SMOOTHCALIB_PERIOD_8SEC))
  958. #define IS_RTC_SMOOTH_CALIB_PLUS(PLUS) (((PLUS) == RTC_SMOOTHCALIB_PLUSPULSES_SET) || \
  959. ((PLUS) == RTC_SMOOTHCALIB_PLUSPULSES_RESET))
  960. #define IS_RTC_SMOOTH_CALIB_MINUS(VALUE) ((VALUE) <= RTC_CALR_CALM)
  961. #define IS_RTC_SHIFT_ADD1S(SEL) (((SEL) == RTC_SHIFTADD1S_RESET) || \
  962. ((SEL) == RTC_SHIFTADD1S_SET))
  963. #define IS_RTC_SHIFT_SUBFS(FS) ((FS) <= RTC_SHIFTR_SUBFS)
  964. #define IS_RTC_CALIB_OUTPUT(OUTPUT) (((OUTPUT) == RTC_CALIBOUTPUT_512HZ) || \
  965. ((OUTPUT) == RTC_CALIBOUTPUT_1HZ))
  966. /**
  967. * @}
  968. */
  969. /**
  970. * @}
  971. */
  972. /**
  973. * @}
  974. */
  975. /**
  976. * @}
  977. */
  978. #ifdef __cplusplus
  979. }
  980. #endif
  981. #endif /* STM32L0xx_HAL_RTC_EX_H */