stm32g0xx_hal_rtc_ex.h 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  1. /**
  2. ******************************************************************************
  3. * @file stm32g0xx_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) 2018 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 STM32G0xx_HAL_RTC_EX_H
  20. #define STM32G0xx_HAL_RTC_EX_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32g0xx_hal_def.h"
  26. /** @addtogroup STM32G0xx_HAL_Driver
  27. * @{
  28. */
  29. /** @defgroup RTCEx RTCEx
  30. * @{
  31. */
  32. /* Exported types ------------------------------------------------------------*/
  33. /** @defgroup RTCEx_Exported_Types RTCEx Exported Types
  34. * @{
  35. */
  36. /** @defgroup RTCEx_Tamper_structure_definition RTCEx Tamper structure definition
  37. * @{
  38. */
  39. typedef struct
  40. {
  41. uint32_t Tamper; /*!< Specifies the Tamper Pin.
  42. This parameter can be a value of @ref RTCEx_Tamper_Pins */
  43. uint32_t Trigger; /*!< Specifies the Tamper Trigger.
  44. This parameter can be a value of @ref RTCEx_Tamper_Trigger */
  45. uint32_t NoErase; /*!< Specifies the Tamper no erase mode.
  46. This parameter can be a value of @ref RTCEx_Tamper_EraseBackUp */
  47. uint32_t MaskFlag; /*!< Specifies the Tamper Flag masking.
  48. This parameter can be a value of @ref RTCEx_Tamper_MaskFlag */
  49. uint32_t Filter; /*!< Specifies the TAMP Filter Tamper.
  50. This parameter can be a value of @ref RTCEx_Tamper_Filter */
  51. uint32_t SamplingFrequency; /*!< Specifies the sampling frequency.
  52. This parameter can be a value of @ref RTCEx_Tamper_Sampling_Frequencies */
  53. uint32_t PrechargeDuration; /*!< Specifies the Precharge Duration .
  54. This parameter can be a value of @ref RTCEx_Tamper_Pin_Precharge_Duration */
  55. uint32_t TamperPullUp; /*!< Specifies the Tamper PullUp .
  56. This parameter can be a value of @ref RTCEx_Tamper_Pull_UP */
  57. uint32_t TimeStampOnTamperDetection; /*!< Specifies the TimeStampOnTamperDetection.
  58. This parameter can be a value of @ref RTCEx_Tamper_TimeStampOnTamperDetection_Definitions */
  59. }RTC_TamperTypeDef;
  60. /**
  61. * @}
  62. */
  63. /** @defgroup RTCEx_Internal_Tamper_structure_definition RTCEx Internal Tamper structure definition
  64. * @{
  65. */
  66. typedef struct
  67. {
  68. uint32_t IntTamper; /*!< Specifies the Internal Tamper Pin.
  69. This parameter can be a value of @ref RTCEx_Internal_Tamper_Pins */
  70. uint32_t TimeStampOnTamperDetection; /*!< Specifies the TimeStampOnTamperDetection.
  71. This parameter can be a value of @ref RTCEx_Tamper_TimeStampOnTamperDetection_Definitions */
  72. } RTC_InternalTamperTypeDef;
  73. /**
  74. * @}
  75. */
  76. /**
  77. * @}
  78. */
  79. /* Exported constants --------------------------------------------------------*/
  80. /** @defgroup RTCEx_Exported_Constants RTCEx Exported Constants
  81. * @{
  82. */
  83. /** @defgroup RTCEx_Time_Stamp_Edges_definitions RTCEx Time Stamp Edges definition
  84. * @{
  85. */
  86. #define RTC_TIMESTAMPEDGE_RISING 0x00000000u
  87. #define RTC_TIMESTAMPEDGE_FALLING RTC_CR_TSEDGE
  88. /**
  89. * @}
  90. */
  91. /** @defgroup RTCEx_TimeStamp_Pin_Selections RTCEx TimeStamp Pin Selection
  92. * @{
  93. */
  94. #define RTC_TIMESTAMPPIN_DEFAULT 0x00000000u
  95. /**
  96. * @}
  97. */
  98. /** @defgroup RTCEx_Wakeup_Timer_Definitions RTCEx Wakeup Timer Definitions
  99. * @{
  100. */
  101. #define RTC_WAKEUPCLOCK_RTCCLK_DIV16 0x00000000u
  102. #define RTC_WAKEUPCLOCK_RTCCLK_DIV8 RTC_CR_WUCKSEL_0
  103. #define RTC_WAKEUPCLOCK_RTCCLK_DIV4 RTC_CR_WUCKSEL_1
  104. #define RTC_WAKEUPCLOCK_RTCCLK_DIV2 (RTC_CR_WUCKSEL_0 | RTC_CR_WUCKSEL_1)
  105. #define RTC_WAKEUPCLOCK_CK_SPRE_16BITS RTC_CR_WUCKSEL_2
  106. #define RTC_WAKEUPCLOCK_CK_SPRE_17BITS (RTC_CR_WUCKSEL_1 | RTC_CR_WUCKSEL_2)
  107. /**
  108. * @}
  109. */
  110. /** @defgroup RTCEx_Smooth_calib_period_Definitions RTCEx Smooth calib period Definitions
  111. * @{
  112. */
  113. #define RTC_SMOOTHCALIB_PERIOD_32SEC 0x00000000u /*!< If RTCCLK = 32768 Hz, Smooth calibation
  114. period is 32s, else 2exp20 RTCCLK pulses */
  115. #define RTC_SMOOTHCALIB_PERIOD_16SEC RTC_CALR_CALW16 /*!< If RTCCLK = 32768 Hz, Smooth calibation
  116. period is 16s, else 2exp19 RTCCLK pulses */
  117. #define RTC_SMOOTHCALIB_PERIOD_8SEC RTC_CALR_CALW8 /*!< If RTCCLK = 32768 Hz, Smooth calibation
  118. period is 8s, else 2exp18 RTCCLK pulses */
  119. /**
  120. * @}
  121. */
  122. /** @defgroup RTCEx_Smooth_calib_Plus_pulses_Definitions RTCEx Smooth calib Plus pulses Definitions
  123. * @{
  124. */
  125. #define RTC_SMOOTHCALIB_PLUSPULSES_SET RTC_CALR_CALP /*!< The number of RTCCLK pulses added
  126. during a X -second window = Y - CALM[8:0]
  127. with Y = 512, 256, 128 when X = 32, 16, 8 */
  128. #define RTC_SMOOTHCALIB_PLUSPULSES_RESET 0x00000000u /*!< The number of RTCCLK pulses subbstited
  129. during a 32-second window = CALM[8:0] */
  130. /**
  131. * @}
  132. */
  133. /** @defgroup RTCEx_Calib_Output_selection_Definitions RTCEx Calib Output selection Definitions
  134. * @{
  135. */
  136. #define RTC_CALIBOUTPUT_512HZ 0x00000000u
  137. #define RTC_CALIBOUTPUT_1HZ RTC_CR_COSEL
  138. /**
  139. * @}
  140. */
  141. /** @defgroup RTCEx_Add_1_Second_Parameter_Definition RTCEx Add 1 Second Parameter Definitions
  142. * @{
  143. */
  144. #define RTC_SHIFTADD1S_RESET 0x00000000u
  145. #define RTC_SHIFTADD1S_SET RTC_SHIFTR_ADD1S
  146. /**
  147. * @}
  148. */
  149. /** @defgroup RTCEx_Tamper_Pins RTCEx Tamper Pins Definition
  150. * @{
  151. */
  152. #define RTC_TAMPER_1 TAMP_CR1_TAMP1E
  153. #define RTC_TAMPER_2 TAMP_CR1_TAMP2E
  154. #if defined(TAMP_CR1_TAMP3E)
  155. #define RTC_TAMPER_3 TAMP_CR1_TAMP3E
  156. #define RTC_TAMPER_ALL (TAMP_CR1_TAMP1E | TAMP_CR1_TAMP2E | TAMP_CR1_TAMP3E)
  157. #else
  158. #define RTC_TAMPER_ALL (TAMP_CR1_TAMP1E | TAMP_CR1_TAMP2E)
  159. #endif /* TAMP_CR1_TAMP3E */
  160. /**
  161. * @}
  162. */
  163. /** @defgroup RTCEx_Internal_Tamper_Pins RTCEx Internal Tamper Pins Definition
  164. * @{
  165. */
  166. #define RTC_INT_TAMPER_3 TAMP_CR1_ITAMP3E
  167. #define RTC_INT_TAMPER_4 TAMP_CR1_ITAMP4E
  168. #define RTC_INT_TAMPER_5 TAMP_CR1_ITAMP5E
  169. #define RTC_INT_TAMPER_6 TAMP_CR1_ITAMP6E
  170. #define RTC_INT_TAMPER_ALL (TAMP_CR1_ITAMP3E | TAMP_CR1_ITAMP4E | \
  171. TAMP_CR1_ITAMP5E | TAMP_CR1_ITAMP6E)
  172. /**
  173. * @}
  174. */
  175. /** @defgroup RTCEx_Tamper_Trigger RTCEx Tamper Trigger
  176. * @{
  177. */
  178. #define RTC_TAMPERTRIGGER_RISINGEDGE 0x00u
  179. #define RTC_TAMPERTRIGGER_FALLINGEDGE 0x01u
  180. #define RTC_TAMPERTRIGGER_LOWLEVEL RTC_TAMPERTRIGGER_RISINGEDGE
  181. #define RTC_TAMPERTRIGGER_HIGHLEVEL RTC_TAMPERTRIGGER_FALLINGEDGE
  182. /**
  183. * @}
  184. */
  185. /** @defgroup RTCEx_Tamper_MaskFlag RTCEx Tamper MaskFlag
  186. * @{
  187. */
  188. #define RTC_TAMPERMASK_FLAG_DISABLE 0x00u
  189. #define RTC_TAMPERMASK_FLAG_ENABLE 0x01u
  190. /**
  191. * @}
  192. */
  193. /** @defgroup RTCEx_Tamper_EraseBackUp RTCEx Tamper EraseBackUp
  194. * @{
  195. */
  196. #define RTC_TAMPER_ERASE_BACKUP_ENABLE 0x00u
  197. #define RTC_TAMPER_ERASE_BACKUP_DISABLE 0x01u
  198. /**
  199. * @}
  200. */
  201. /** @defgroup RTCEx_Tamper_Filter RTCEx Tamper Filter
  202. * @{
  203. */
  204. #define RTC_TAMPERFILTER_DISABLE 0x00000000U /*!< Tamper filter is disabled */
  205. #define RTC_TAMPERFILTER_2SAMPLE TAMP_FLTCR_TAMPFLT_0 /*!< Tamper is activated after 2
  206. consecutive samples at the active level */
  207. #define RTC_TAMPERFILTER_4SAMPLE TAMP_FLTCR_TAMPFLT_1 /*!< Tamper is activated after 4
  208. consecutive samples at the active level */
  209. #define RTC_TAMPERFILTER_8SAMPLE TAMP_FLTCR_TAMPFLT /*!< Tamper is activated after 8
  210. consecutive samples at the active level */
  211. /**
  212. * @}
  213. */
  214. /** @defgroup RTCEx_Tamper_Sampling_Frequencies RTCEx Tamper Sampling Frequencies
  215. * @{
  216. */
  217. #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV32768 0x00000000U /*!< Each of the tamper inputs are sampled
  218. with a frequency = RTCCLK / 32768 */
  219. #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV16384 TAMP_FLTCR_TAMPFREQ_0 /*!< Each of the tamper inputs are sampled
  220. with a frequency = RTCCLK / 16384 */
  221. #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV8192 TAMP_FLTCR_TAMPFREQ_1 /*!< Each of the tamper inputs are sampled
  222. with a frequency = RTCCLK / 8192 */
  223. #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV4096 (TAMP_FLTCR_TAMPFREQ_0 | TAMP_FLTCR_TAMPFREQ_1) /*!< Each of the tamper inputs are sampled
  224. with a frequency = RTCCLK / 4096 */
  225. #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV2048 TAMP_FLTCR_TAMPFREQ_2 /*!< Each of the tamper inputs are sampled
  226. with a frequency = RTCCLK / 2048 */
  227. #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV1024 (TAMP_FLTCR_TAMPFREQ_0 | TAMP_FLTCR_TAMPFREQ_2) /*!< Each of the tamper inputs are sampled
  228. with a frequency = RTCCLK / 1024 */
  229. #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV512 (TAMP_FLTCR_TAMPFREQ_1 | TAMP_FLTCR_TAMPFREQ_2) /*!< Each of the tamper inputs are sampled
  230. with a frequency = RTCCLK / 512 */
  231. #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV256 (TAMP_FLTCR_TAMPFREQ_0 | TAMP_FLTCR_TAMPFREQ_1 | \
  232. TAMP_FLTCR_TAMPFREQ_2) /*!< Each of the tamper inputs are sampled
  233. with a frequency = RTCCLK / 256 */
  234. /**
  235. * @}
  236. */
  237. /** @defgroup RTCEx_Tamper_Pin_Precharge_Duration RTCEx Tamper Pin Precharge Duration
  238. * @{
  239. */
  240. #define RTC_TAMPERPRECHARGEDURATION_1RTCCLK 0x00000000U /*!< Tamper pins are pre-charged before
  241. sampling during 1 RTCCLK cycle */
  242. #define RTC_TAMPERPRECHARGEDURATION_2RTCCLK TAMP_FLTCR_TAMPPRCH_0 /*!< Tamper pins are pre-charged before
  243. sampling during 2 RTCCLK cycles */
  244. #define RTC_TAMPERPRECHARGEDURATION_4RTCCLK TAMP_FLTCR_TAMPPRCH_1 /*!< Tamper pins are pre-charged before
  245. sampling during 4 RTCCLK cycles */
  246. #define RTC_TAMPERPRECHARGEDURATION_8RTCCLK (TAMP_FLTCR_TAMPPRCH_0 | TAMP_FLTCR_TAMPPRCH_1) /*!< Tamper pins are pre-charged before
  247. sampling during 8 RTCCLK cycles */
  248. /**
  249. * @}
  250. */
  251. /** @defgroup RTCEx_Tamper_Pull_UP RTCEx Tamper Pull UP
  252. * @{
  253. */
  254. #define RTC_TAMPER_PULLUP_ENABLE 0x00000000u /*!< Tamper pins are pre-charged before sampling */
  255. #define RTC_TAMPER_PULLUP_DISABLE TAMP_FLTCR_TAMPPUDIS /*!< Tamper pins pre-charge is disabled */
  256. /**
  257. * @}
  258. */
  259. /** @defgroup RTCEx_Tamper_TimeStampOnTamperDetection_Definitions RTCEx Tamper TimeStamp On Tamper Detection Definitions
  260. * @{
  261. */
  262. #define RTC_TIMESTAMPONTAMPERDETECTION_DISABLE 0x00000000u /*!< TimeStamp on Tamper Detection event is not saved */
  263. #define RTC_TIMESTAMPONTAMPERDETECTION_ENABLE RTC_CR_TAMPTS /*!< TimeStamp on Tamper Detection event saved */
  264. /**
  265. * @}
  266. */
  267. /** @defgroup RTCEx_Internal_Tamper_Interrupt RTCEx Internal Tamper Interrupt
  268. * @{
  269. */
  270. #define RTC_IT_TAMP1 TAMP_IER_TAMP1IE /*!< Tamper 1 Interrupt */
  271. #define RTC_IT_TAMP2 TAMP_IER_TAMP2IE /*!< Tamper 2 Interrupt */
  272. #if defined(TAMP_CR1_TAMP3E)
  273. #define RTC_IT_TAMP3 TAMP_IER_TAMP3IE /*!< Tamper 3 Interrupt */
  274. #define RTC_IT_TAMPALL (TAMP_IER_TAMP1IE | TAMP_IER_TAMP2IE | TAMP_IER_TAMP3IE)
  275. #else
  276. #define RTC_IT_TAMPALL (TAMP_IER_TAMP1IE | TAMP_IER_TAMP2IE)
  277. #endif /* TAMP_CR1_TAMP3E */
  278. #define RTC_IT_INT_TAMP3 TAMP_IER_ITAMP3IE
  279. #define RTC_IT_INT_TAMP4 TAMP_IER_ITAMP4IE
  280. #define RTC_IT_INT_TAMP5 TAMP_IER_ITAMP5IE
  281. #define RTC_IT_INT_TAMP6 TAMP_IER_ITAMP6IE
  282. #define RTC_IT_INT_TAMPALL (RTC_IT_INT_TAMP3 | RTC_IT_INT_TAMP4 | \
  283. RTC_IT_INT_TAMP5 | RTC_IT_INT_TAMP6)
  284. /**
  285. * @}
  286. */
  287. /** @defgroup RTCEx_Flags RTCEx Flags
  288. * @{
  289. */
  290. #define RTC_FLAG_TAMP1 TAMP_SR_TAMP1F
  291. #define RTC_FLAG_TAMP2 TAMP_SR_TAMP2F
  292. #if defined(TAMP_CR1_TAMP3E)
  293. #define RTC_FLAG_TAMP3 TAMP_SR_TAMP3F
  294. #define RTC_FLAG_TAMPALL (RTC_FLAG_TAMP1 | RTC_FLAG_TAMP2 | RTC_FLAG_TAMP3)
  295. #else
  296. #define RTC_FLAG_TAMPALL (RTC_FLAG_TAMP1 | RTC_FLAG_TAMP2)
  297. #endif /* TAMP_CR1_TAMP3E */
  298. #define RTC_FLAG_INT_TAMP3 TAMP_SR_ITAMP3F
  299. #define RTC_FLAG_INT_TAMP4 TAMP_SR_ITAMP4F
  300. #define RTC_FLAG_INT_TAMP5 TAMP_SR_ITAMP5F
  301. #define RTC_FLAG_INT_TAMP6 TAMP_SR_ITAMP6F
  302. #define RTC_FLAG_INT_TAMPALL (RTC_FLAG_INT_TAMP3 | RTC_FLAG_INT_TAMP4 | \
  303. RTC_FLAG_INT_TAMP5 | RTC_FLAG_INT_TAMP6)
  304. /**
  305. * @}
  306. */
  307. /** @defgroup RTCEx_Backup_Registers RTCEx Backup Registers Definition
  308. * @{
  309. */
  310. #define RTC_BKP_NUMBER 0x00000005u
  311. #define RTC_BKP_DR0 0x00000000u
  312. #define RTC_BKP_DR1 0x00000001u
  313. #define RTC_BKP_DR2 0x00000002u
  314. #define RTC_BKP_DR3 0x00000003u
  315. #define RTC_BKP_DR4 0x00000004u
  316. /**
  317. * @}
  318. */
  319. /**
  320. * @}
  321. */
  322. /* Exported macros -----------------------------------------------------------*/
  323. /** @defgroup RTCEx_Exported_Macros RTCEx Exported Macros
  324. * @{
  325. */
  326. /** @brief Clear the specified RTC pending flag.
  327. * @param __HANDLE__ specifies the RTC Handle.
  328. * @param __FLAG__ specifies the flag to check.
  329. * This parameter can be any combination of the following values:
  330. * @arg @ref RTC_CLEAR_ITSF Clear Internal Time-stamp flag
  331. * @arg @ref RTC_CLEAR_TSOVF Clear Time-stamp overflow flag
  332. * @arg @ref RTC_CLEAR_TSF Clear Time-stamp flag
  333. * @arg @ref RTC_CLEAR_WUTF Clear Wakeup timer flag
  334. * @arg @ref RTC_CLEAR_ALRBF Clear Alarm B flag
  335. * @arg @ref RTC_CLEAR_ALRAF Clear Alarm A flag
  336. * @retval None
  337. */
  338. #define __HAL_RTC_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SCR |= (__FLAG__))
  339. /** @brief Check whether the specified RTC flag is set or not.
  340. * @param __HANDLE__ specifies the RTC Handle.
  341. * @param __FLAG__ specifies the flag to check.
  342. * This parameter can be:
  343. * @arg @ref RTC_FLAG_RECALPF Recalibration pending Flag
  344. * @arg @ref RTC_FLAG_INITF Initialization flag
  345. * @arg @ref RTC_FLAG_RSF Registers synchronization flag
  346. * @arg @ref RTC_FLAG_INITS Initialization status flag
  347. * @arg @ref RTC_FLAG_SHPF Shift operation pending flag
  348. * @arg @ref RTC_FLAG_WUTWF Wakeup timer write flag
  349. * @arg @ref RTC_FLAG_ALRBWF Alarm B write flag
  350. * @arg @ref RTC_FLAG_ALRAWF Alarm A write flag
  351. * @arg @ref RTC_FLAG_ITSF Internal Time-stamp flag
  352. * @arg @ref RTC_FLAG_TSOVF Time-stamp overflow flag
  353. * @arg @ref RTC_FLAG_TSF Time-stamp flag
  354. * @arg @ref RTC_FLAG_WUTF Wakeup timer flag
  355. * @arg @ref RTC_FLAG_ALRBF Alarm B flag
  356. * @arg @ref RTC_FLAG_ALRAF Alarm A flag
  357. * @retval The state of __FLAG__ (TRUE or FALSE).
  358. */
  359. #define __HAL_RTC_GET_FLAG(__HANDLE__, __FLAG__) (((((__FLAG__)) >> 8U) == 1U) ? ((((__HANDLE__)->Instance->ICSR & (1U << (((uint16_t)(__FLAG__)) & RTC_FLAG_MASK))) != 0U) ? 1U : 0U) :\
  360. ((((__HANDLE__)->Instance->SR & (1U << (((uint16_t)(__FLAG__)) & RTC_FLAG_MASK))) != 0U) ? 1U : 0U))
  361. /* ---------------------------------WAKEUPTIMER---------------------------------*/
  362. /** @defgroup RTCEx_WakeUp_Timer RTC WakeUp Timer
  363. * @{
  364. */
  365. /**
  366. * @brief Enable the RTC WakeUp Timer peripheral.
  367. * @param __HANDLE__ specifies the RTC handle.
  368. * @retval None
  369. */
  370. #define __HAL_RTC_WAKEUPTIMER_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_WUTE))
  371. /**
  372. * @brief Disable the RTC WakeUp Timer peripheral.
  373. * @param __HANDLE__ specifies the RTC handle.
  374. * @retval None
  375. */
  376. #define __HAL_RTC_WAKEUPTIMER_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_WUTE))
  377. /**
  378. * @brief Enable the RTC WakeUpTimer interrupt.
  379. * @param __HANDLE__ specifies the RTC handle.
  380. * @param __INTERRUPT__ specifies the RTC WakeUpTimer interrupt sources to be enabled.
  381. * This parameter can be:
  382. * @arg @ref RTC_IT_WUT WakeUpTimer interrupt
  383. * @retval None
  384. */
  385. #define __HAL_RTC_WAKEUPTIMER_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
  386. /**
  387. * @brief Disable the RTC WakeUpTimer interrupt.
  388. * @param __HANDLE__ specifies the RTC handle.
  389. * @param __INTERRUPT__ specifies the RTC WakeUpTimer interrupt sources to be disabled.
  390. * This parameter can be:
  391. * @arg @ref RTC_IT_WUT WakeUpTimer interrupt
  392. * @retval None
  393. */
  394. #define __HAL_RTC_WAKEUPTIMER_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
  395. /**
  396. * @brief Check whether the specified RTC WakeUpTimer interrupt has occurred or not.
  397. * @param __HANDLE__ specifies the RTC handle.
  398. * @param __INTERRUPT__ specifies the RTC WakeUpTimer interrupt to check.
  399. * This parameter can be:
  400. * @arg @ref RTC_IT_WUT WakeUpTimer interrupt
  401. * @retval The state of __INTERRUPT__ (TRUE or FALSE).
  402. */
  403. #define __HAL_RTC_WAKEUPTIMER_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->MISR) & ((__INTERRUPT__) >> 12U)) != 0U) ? 1U : 0U)
  404. /**
  405. * @brief Check whether the specified RTC Wake Up timer interrupt has been enabled or not.
  406. * @param __HANDLE__ specifies the RTC handle.
  407. * @param __INTERRUPT__ specifies the RTC Wake Up timer interrupt sources to check.
  408. * This parameter can be:
  409. * @arg @ref RTC_IT_WUT WakeUpTimer interrupt
  410. * @retval The state of __INTERRUPT__ (TRUE or FALSE).
  411. */
  412. #define __HAL_RTC_WAKEUPTIMER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
  413. /**
  414. * @brief Get the selected RTC WakeUpTimers flag status.
  415. * @param __HANDLE__ specifies the RTC handle.
  416. * @param __FLAG__ specifies the RTC WakeUpTimer Flag is pending or not.
  417. * This parameter can be:
  418. * @arg @ref RTC_FLAG_WUTF
  419. * @arg @ref RTC_FLAG_WUTWF
  420. * @retval The state of __FLAG__ (TRUE or FALSE).
  421. */
  422. #define __HAL_RTC_WAKEUPTIMER_GET_FLAG(__HANDLE__, __FLAG__)( \
  423. ((__FLAG__) == RTC_FLAG_WUTF) ? (((((__HANDLE__)->Instance->SR) & (RTC_SR_WUTF)) != 0) ? 1U : 0U):\
  424. (((((__HANDLE__)->Instance->ICSR) & (RTC_ICSR_WUTWF)) != 0) ? 1U : 0U))
  425. /**
  426. * @brief Clear the RTC Wake Up timers pending flags.
  427. * @param __HANDLE__ specifies the RTC handle.
  428. * @param __FLAG__ specifies the RTC WakeUpTimer Flag to clear.
  429. * This parameter can be:
  430. * @arg @ref RTC_FLAG_WUTF
  431. * @retval None
  432. */
  433. #define __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SCR |= (RTC_SCR_CWUTF))
  434. /* WAKE-UP TIMER EXTI */
  435. /* ------------------ */
  436. /**
  437. * @brief Enable interrupt on the RTC WakeUp Timer associated Exti line.
  438. * @retval None
  439. */
  440. #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT() (EXTI->IMR1 |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
  441. /**
  442. * @brief Disable interrupt on the RTC WakeUp Timer associated Exti line.
  443. * @retval None
  444. */
  445. #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_IT() (EXTI->IMR1 &= ~(RTC_EXTI_LINE_WAKEUPTIMER_EVENT))
  446. /**
  447. * @brief Enable event on the RTC WakeUp Timer associated Exti line.
  448. * @retval None.
  449. */
  450. #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_EVENT() (EXTI->EMR1 |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
  451. /**
  452. * @brief Disable event on the RTC WakeUp Timer associated Exti line.
  453. * @retval None.
  454. */
  455. #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_EVENT() (EXTI->EMR1 &= ~(RTC_EXTI_LINE_WAKEUPTIMER_EVENT))
  456. /**
  457. * @}
  458. */
  459. /* ---------------------------------TIMESTAMP---------------------------------*/
  460. /** @defgroup RTCEx_Timestamp RTC Timestamp
  461. * @{
  462. */
  463. /**
  464. * @brief Enable the RTC TimeStamp peripheral.
  465. * @param __HANDLE__ specifies the RTC handle.
  466. * @retval None
  467. */
  468. #define __HAL_RTC_TIMESTAMP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_TSE))
  469. /**
  470. * @brief Disable the RTC TimeStamp peripheral.
  471. * @param __HANDLE__ specifies the RTC handle.
  472. * @retval None
  473. */
  474. #define __HAL_RTC_TIMESTAMP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_TSE))
  475. /**
  476. * @brief Enable the RTC TimeStamp interrupt.
  477. * @param __HANDLE__ specifies the RTC handle.
  478. * @param __INTERRUPT__ specifies the RTC TimeStamp interrupt source to be enabled.
  479. * This parameter can be:
  480. * @arg @ref RTC_IT_TS TimeStamp interrupt
  481. * @retval None
  482. */
  483. #define __HAL_RTC_TIMESTAMP_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
  484. /**
  485. * @brief Disable the RTC TimeStamp interrupt.
  486. * @param __HANDLE__ specifies the RTC handle.
  487. * @param __INTERRUPT__ specifies the RTC TimeStamp interrupt source to be disabled.
  488. * This parameter can be:
  489. * @arg @ref RTC_IT_TS TimeStamp interrupt
  490. * @retval None
  491. */
  492. #define __HAL_RTC_TIMESTAMP_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
  493. /**
  494. * @brief Check whether the specified RTC TimeStamp interrupt has occurred or not.
  495. * @param __HANDLE__ specifies the RTC handle.
  496. * @param __INTERRUPT__ specifies the RTC TimeStamp interrupt to check.
  497. * This parameter can be:
  498. * @arg @ref RTC_IT_TS TimeStamp interrupt
  499. * @retval The state of __INTERRUPT__ (TRUE or FALSE).
  500. */
  501. #define __HAL_RTC_TIMESTAMP_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->MISR) & ((__INTERRUPT__) >> 12U)) != 0U) ? 1U : 0U)
  502. /**
  503. * @brief Check whether the specified RTC Time Stamp interrupt has been enabled or not.
  504. * @param __HANDLE__ specifies the RTC handle.
  505. * @param __INTERRUPT__ specifies the RTC Time Stamp interrupt source to check.
  506. * This parameter can be:
  507. * @arg @ref RTC_IT_TS TimeStamp interrupt
  508. * @retval The state of __INTERRUPT__ (TRUE or FALSE).
  509. */
  510. #define __HAL_RTC_TIMESTAMP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
  511. /**
  512. * @brief Get the selected RTC TimeStamps flag status.
  513. * @param __HANDLE__ specifies the RTC handle.
  514. * @param __FLAG__ specifies the RTC TimeStamp Flag is pending or not.
  515. * This parameter can be:
  516. * @arg @ref RTC_FLAG_TSF
  517. * @arg @ref RTC_FLAG_TSOVF
  518. * @retval The state of __FLAG__ (TRUE or FALSE).
  519. */
  520. #define __HAL_RTC_TIMESTAMP_GET_FLAG(__HANDLE__, __FLAG__)( \
  521. ((__FLAG__) == RTC_FLAG_TSF) ? (((((__HANDLE__)->Instance->SR) & (RTC_SR_TSF)) != 0) ? 1U : 0U):\
  522. (((((__HANDLE__)->Instance->SR) & (RTC_SR_TSOVF)) != 0) ? 1U : 0U))
  523. /**
  524. * @brief Clear the RTC Time Stamps pending flags.
  525. * @param __HANDLE__ specifies the RTC handle.
  526. * @param __FLAG__ specifies the RTC TimeStamp Flag to clear.
  527. * This parameter can be:
  528. * @arg @ref RTC_FLAG_TSF
  529. * @arg @ref RTC_FLAG_TSOVF
  530. * @retval None
  531. */
  532. #define __HAL_RTC_TIMESTAMP_CLEAR_FLAG(__HANDLE__, __FLAG__)( \
  533. ((__FLAG__) == RTC_FLAG_TSF) ? ((__HANDLE__)->Instance->SCR |= (RTC_SCR_CTSF)):\
  534. ((__HANDLE__)->Instance->SCR |= (RTC_SCR_CTSOVF)))
  535. /**
  536. * @brief Enable interrupt on the RTC Timestamp associated Exti line.
  537. * @retval None
  538. */
  539. #define __HAL_RTC_TIMESTAMP_EXTI_ENABLE_IT() (EXTI->IMR1 |= RTC_EXTI_LINE_TIMESTAMP_EVENT)
  540. /**
  541. * @brief Disable interrupt on the RTC Timestamp associated Exti line.
  542. * @retval None
  543. */
  544. #define __HAL_RTC_TIMESTAMP_EXTI_DISABLE_IT() (EXTI->IMR1 &= ~(RTC_EXTI_LINE_TIMESTAMP_EVENT))
  545. /**
  546. * @brief Enable event on the RTC Timestamp associated Exti line.
  547. * @retval None
  548. */
  549. #define __HAL_RTC_TIMESTAMP_EXTI_ENABLE_EVENT() (EXTI->EMR1 |= RTC_EXTI_LINE_TIMESTAMP_EVENT)
  550. /**
  551. * @brief Disable event on the RTC Timestamp associated Exti line.
  552. * @retval None
  553. */
  554. #define __HAL_RTC_TIMESTAMP_EXTI_DISABLE_EVENT() (EXTI->EMR1 &= ~(RTC_EXTI_LINE_TIMESTAMP_EVENT))
  555. /**
  556. * @brief Enable the RTC internal TimeStamp peripheral.
  557. * @param __HANDLE__ specifies the RTC handle.
  558. * @retval None
  559. */
  560. #define __HAL_RTC_INTERNAL_TIMESTAMP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ITSE))
  561. /**
  562. * @brief Disable the RTC internal TimeStamp peripheral.
  563. * @param __HANDLE__ specifies the RTC handle.
  564. * @retval None
  565. */
  566. #define __HAL_RTC_INTERNAL_TIMESTAMP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ITSE))
  567. /**
  568. * @brief Get the selected RTC Internal Time Stamps flag status.
  569. * @param __HANDLE__ specifies the RTC handle.
  570. * @param __FLAG__ specifies the RTC Internal Time Stamp Flag is pending or not.
  571. * This parameter can be:
  572. * @arg @ref RTC_FLAG_ITSF
  573. * @retval The state of __FLAG__ (TRUE or FALSE).
  574. */
  575. #define __HAL_RTC_INTERNAL_TIMESTAMP_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->SR) & (RTC_SR_ITSF)) != 0) ? 1U : 0U)
  576. /**
  577. * @brief Clear the RTC Internal Time Stamps pending flags.
  578. * @param __HANDLE__ specifies the RTC handle.
  579. * @param __FLAG__ specifies the RTC Internal Time Stamp Flag source to clear.
  580. * This parameter can be:
  581. * @arg @ref RTC_FLAG_ITSF
  582. * @retval None
  583. */
  584. #define __HAL_RTC_INTERNAL_TIMESTAMP_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SCR |= (RTC_SCR_CITSF))
  585. /**
  586. * @brief Enable the RTC TimeStamp on Tamper detection.
  587. * @param __HANDLE__ specifies the RTC handle.
  588. * @retval None
  589. */
  590. #define __HAL_RTC_TAMPTS_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_TAMPTS))
  591. /**
  592. * @brief Disable the RTC TimeStamp on Tamper detection.
  593. * @param __HANDLE__ specifies the RTC handle.
  594. * @retval None
  595. */
  596. #define __HAL_RTC_TAMPTS_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_TAMPTS))
  597. /**
  598. * @brief Enable the RTC Tamper detection output.
  599. * @param __HANDLE__ specifies the RTC handle.
  600. * @retval None
  601. */
  602. #define __HAL_RTC_TAMPOE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_TAMPOE))
  603. /**
  604. * @brief Disable the RTC Tamper detection output.
  605. * @param __HANDLE__ specifies the RTC handle.
  606. * @retval None
  607. */
  608. #define __HAL_RTC_TAMPOE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_TAMPOE))
  609. /**
  610. * @}
  611. */
  612. /* ------------------------------Calibration----------------------------------*/
  613. /** @defgroup RTCEx_Calibration RTC Calibration
  614. * @{
  615. */
  616. /**
  617. * @brief Enable the RTC calibration output.
  618. * @param __HANDLE__ specifies the RTC handle.
  619. * @retval None
  620. */
  621. #define __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_COE))
  622. /**
  623. * @brief Disable the calibration output.
  624. * @param __HANDLE__ specifies the RTC handle.
  625. * @retval None
  626. */
  627. #define __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_COE))
  628. /**
  629. * @brief Enable the clock reference detection.
  630. * @param __HANDLE__ specifies the RTC handle.
  631. * @retval None
  632. */
  633. #define __HAL_RTC_CLOCKREF_DETECTION_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_REFCKON))
  634. /**
  635. * @brief Disable the clock reference detection.
  636. * @param __HANDLE__ specifies the RTC handle.
  637. * @retval None
  638. */
  639. #define __HAL_RTC_CLOCKREF_DETECTION_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_REFCKON))
  640. /**
  641. * @brief Get the selected RTC shift operations flag status.
  642. * @param __HANDLE__ specifies the RTC handle.
  643. * @param __FLAG__ specifies the RTC shift operation Flag is pending or not.
  644. * This parameter can be:
  645. * @arg @ref RTC_FLAG_SHPF
  646. * @retval The state of __FLAG__ (TRUE or FALSE).
  647. */
  648. #define __HAL_RTC_SHIFT_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ICSR) & (RTC_ICSR_SHPF)) != 0U) ? 1U : 0U)
  649. /**
  650. * @}
  651. */
  652. /* ------------------------------Tamper----------------------------------*/
  653. /** @defgroup RTCEx_Tamper RTCEx tamper
  654. * @{
  655. */
  656. /**
  657. * @brief Enable the TAMP Tamper input detection.
  658. * @param __HANDLE__ specifies the RTC handle.
  659. * @param __TAMPER__ specifies the RTC Tamper source to be enabled.
  660. * This parameter can be any combination of the following values:
  661. * @arg RTC_ALL_TAMPER: All tampers
  662. * @arg RTC_TAMPER_1: Tamper1
  663. * @arg RTC_TAMPER_2: Tamper2
  664. * @arg RTC_TAMPER_3: Tamper3 (*)
  665. * @retval None
  666. */
  667. #define __HAL_RTC_TAMPER_ENABLE(__HANDLE__, __TAMPER__) (((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + (__HANDLE__)->TampOffset))->CR1 |= (__TAMPER__))
  668. /**
  669. * @brief Disable the TAMP Tamper input detection.
  670. * @param __HANDLE__ specifies the TAMP handle.
  671. * @param __TAMPER__ specifies the TAMP Tamper sources to be enabled.
  672. * This parameter can be any combination of the following values:
  673. * @arg RTC_ALL_TAMPER: All tampers
  674. * @arg RTC_TAMPER_1: Tamper1
  675. * @arg RTC_TAMPER_2: Tamper2
  676. * @arg RTC_TAMPER_3: Tamper3 (*)
  677. */
  678. #define __HAL_RTC_TAMPER_DISABLE(__HANDLE__, __TAMPER__) (((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + (__HANDLE__)->TampOffset))->CR1 &= ~(__TAMPER__))
  679. /**************************************************************************************************/
  680. /**
  681. * @brief Enable the TAMP Tamper interrupt.
  682. * @param __HANDLE__ specifies the TAMP handle.
  683. * @param __INTERRUPT__ specifies the TAMP Tamper interrupt sources to be enabled.
  684. * This parameter can be any combination of the following values:
  685. * @arg RTC_IT_TAMPALL: All tampers interrupts
  686. * @arg RTC_IT_TAMP1: Tamper1 interrupt
  687. * @arg RTC_IT_TAMP2: Tamper2 interrupt
  688. * @arg RTC_IT_TAMP3: Tamper3 interrupt (*)
  689. * @retval None
  690. */
  691. #define __HAL_RTC_TAMPER_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + (__HANDLE__)->TampOffset))->IER |= (__INTERRUPT__))
  692. /**
  693. * @brief Disable the TAMP Tamper interrupt.
  694. * @param __HANDLE__ specifies the TAMP handle.
  695. * @param __INTERRUPT__ specifies the TAMP Tamper interrupt sources to be disabled.
  696. * This parameter can be any combination of the following values:
  697. * @arg RTC_IT_TAMPALL: All tampers interrupts
  698. * @arg RTC_IT_TAMP1: Tamper1 interrupt
  699. * @arg RTC_IT_TAMP2: Tamper2 interrupt
  700. * @arg RTC_IT_TAMP3: Tamper3 interrupt (*)
  701. * @retval None
  702. */
  703. #define __HAL_RTC_TAMPER_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + (__HANDLE__)->TampOffset))->IER &= ~(__INTERRUPT__))
  704. /**************************************************************************************************/
  705. /**
  706. * @brief Check whether the specified TAMP Tamper interrupt has occurred or not.
  707. * @param __HANDLE__ specifies the TAMP handle.
  708. * @param __INTERRUPT__ specifies the TAMP Tamper interrupt to check.
  709. * This parameter can be:
  710. * @arg RTC_IT_TAMPALL: All tampers interrupts
  711. * @arg RTC_IT_TAMP1: Tamper1 interrupt
  712. * @arg RTC_IT_TAMP2: Tamper2 interrupt
  713. * @arg RTC_IT_TAMP3: Tamper3 interrupt (*)
  714. * @arg RTC_IT_INT_TAMP3: Internal Tamper3 interrupt
  715. * @arg RTC_IT_INT_TAMP4: Internal Tamper4 interrupt
  716. * @arg RTC_IT_INT_TAMP5: Internal Tamper5 interrupt
  717. * @arg RTC_IT_INT_TAMP6: Internal Tamper6 interrupt
  718. * @retval The state of __INTERRUPT__ (TRUE or FALSE).
  719. */
  720. #define __HAL_RTC_TAMPER_GET_IT(__HANDLE__, __INTERRUPT__) ((((((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + (__HANDLE__)->TampOffset))->MISR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
  721. /**
  722. * @brief Check whether the specified TAMP Tamper interrupt has been enabled or not.
  723. * @param __HANDLE__ specifies the TAMP handle.
  724. * @param __INTERRUPT__ specifies the TAMP Tamper interrupt source to check.
  725. * This parameter can be:
  726. * @arg RTC_IT_TAMPALL: All tampers interrupts
  727. * @arg RTC_IT_TAMP1: Tamper1 interrupt
  728. * @arg RTC_IT_TAMP2: Tamper2 interrupt
  729. * @arg RTC_IT_TAMP3: Tamper3 interrupt (*)
  730. * @arg RTC_IT_INT_TAMPALL: All internal tampers interrupts
  731. * @arg RTC_IT_INT_TAMP3: Internal Tamper3 interrupt
  732. * @arg RTC_IT_INT_TAMP4: Internal Tamper4 interrupt
  733. * @arg RTC_IT_INT_TAMP5: Internal Tamper5 interrupt
  734. * @arg RTC_IT_INT_TAMP6: Internal Tamper6 interrupt
  735. * @retval The state of __INTERRUPT__ (TRUE or FALSE).
  736. */
  737. #define __HAL_RTC_TAMPER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + (__HANDLE__)->TampOffset))->IER) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
  738. /**
  739. * @brief Get the selected TAMP Tampers flag status.
  740. * @param __HANDLE__ specifies the TAMP handle.
  741. * @param __FLAG__ specifies the TAMP Tamper Flag is pending or not.
  742. * This parameter can be:
  743. * @arg RTC_FLAG_TAMP1: Tamper1 flag
  744. * @arg RTC_FLAG_TAMP2: Tamper2 flag
  745. * @arg RTC_FLAG_TAMP3: Tamper3 flag (*)
  746. * @arg RTC_FLAG_INT_TAMP3: Internal Tamper3 flag
  747. * @arg RTC_FLAG_INT_TAMP4: Internal Tamper4 flag
  748. * @arg RTC_FLAG_INT_TAMP5: Internal Tamper5 flag
  749. * @arg RTC_FLAG_INT_TAMP6: Internal Tamper6 flag
  750. * @retval The state of __FLAG__ (TRUE or FALSE).
  751. */
  752. #define __HAL_RTC_TAMPER_GET_FLAG(__HANDLE__, __FLAG__) (((((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + (__HANDLE__)->TampOffset))->SR) & (__FLAG__)) != 0U)
  753. /**
  754. * @brief Clear the TAMP Tampers pending flags.
  755. * @param __HANDLE__ specifies the TAMP handle.
  756. * @param __FLAG__ specifies the TAMP Tamper Flag to clear.
  757. * This parameter can be:
  758. * @arg RTC_FLAG_TAMPALL: All Tamper flags
  759. * @arg RTC_FLAG_TAMP1: Tamper1 flag
  760. * @arg RTC_FLAG_TAMP2: Tamper2 flag
  761. * @arg RTC_FLAG_TAMP3: Tamper3 flag (*)
  762. * @arg RTC_FLAG_INT_TAMP3: Internal Tamper3 flag
  763. * @arg RTC_FLAG_INT_TAMP4: Internal Tamper4 flag
  764. * @arg RTC_FLAG_INT_TAMP5: Internal Tamper5 flag
  765. * @arg RTC_FLAG_INT_TAMP6: Internal Tamper6 flag
  766. * @retval None
  767. */
  768. #define __HAL_RTC_TAMPER_CLEAR_FLAG(__HANDLE__, __FLAG__) ((((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + (__HANDLE__)->TampOffset))->SCR) |= (__FLAG__))
  769. /**
  770. * @brief Enable interrupt on the TAMP associated Exti line.
  771. * @retval None
  772. */
  773. #define __HAL_RTC_TAMPER_EXTI_ENABLE_IT() (EXTI->IMR1 |= RTC_EXTI_LINE_TAMPER_EVENT)
  774. /**
  775. * @brief Disable interrupt on the TAMP associated Exti line.
  776. * @retval None
  777. */
  778. #define __HAL_RTC_TAMPER_EXTI_DISABLE_IT() (EXTI->IMR1 &= ~(RTC_EXTI_LINE_TAMPER_EVENT))
  779. /**
  780. * @brief Enable event on the TAMP associated Exti line.
  781. * @retval None
  782. */
  783. #define __HAL_RTC_TAMPER_EXTI_ENABLE_EVENT() (EXTI->EMR1 |= RTC_EXTI_LINE_TAMPER_EVENT)
  784. /**
  785. * @brief Disable event on the TAMP associated Exti line.
  786. * @retval None
  787. */
  788. #define __HAL_RTC_TAMPER_EXTI_DISABLE_EVENT() (EXTI->EMR1 &= ~(RTC_EXTI_LINE_TAMPER_EVENT))
  789. /**
  790. * @}
  791. */
  792. /**
  793. * @}
  794. */
  795. /* Exported functions --------------------------------------------------------*/
  796. /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions
  797. * @{
  798. */
  799. /* RTC TimeStamp functions *****************************************/
  800. /** @defgroup RTCEx_Exported_Functions_Group1 Extended RTC TimeStamp functions
  801. * @{
  802. */
  803. HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin);
  804. HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin);
  805. HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc);
  806. HAL_StatusTypeDef HAL_RTCEx_SetInternalTimeStamp(RTC_HandleTypeDef *hrtc);
  807. HAL_StatusTypeDef HAL_RTCEx_DeactivateInternalTimeStamp(RTC_HandleTypeDef *hrtc);
  808. HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTimeStamp, RTC_DateTypeDef *sTimeStampDate, uint32_t Format);
  809. void HAL_RTCEx_TimeStampIRQHandler(RTC_HandleTypeDef *hrtc);
  810. HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
  811. void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc);
  812. /**
  813. * @}
  814. */
  815. /* RTC Wake-up functions ******************************************************/
  816. /** @defgroup RTCEx_Exported_Functions_Group2 Extended RTC Wake-up functions
  817. * @{
  818. */
  819. HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock);
  820. HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock);
  821. HAL_StatusTypeDef HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc);
  822. uint32_t HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc);
  823. void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc);
  824. void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc);
  825. HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
  826. /**
  827. * @}
  828. */
  829. /* Extended Control functions ************************************************/
  830. /** @defgroup RTCEx_Exported_Functions_Group3 Extended Peripheral Control functions
  831. * @{
  832. */
  833. HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef *hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmoothCalibMinusPulsesValue);
  834. HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef *hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS);
  835. HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef *hrtc, uint32_t CalibOutput);
  836. HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef *hrtc);
  837. HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef *hrtc);
  838. HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef *hrtc);
  839. HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef *hrtc);
  840. HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef *hrtc);
  841. /**
  842. * @}
  843. */
  844. /* Extended RTC features functions *******************************************/
  845. /** @defgroup RTCEx_Exported_Functions_Group4 Extended features functions
  846. * @{
  847. */
  848. void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc);
  849. HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
  850. /**
  851. * @}
  852. */
  853. /** @defgroup RTCEx_Exported_Functions_Group5 Extended RTC Tamper functions
  854. * @{
  855. */
  856. HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper);
  857. HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper);
  858. HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper);
  859. HAL_StatusTypeDef HAL_RTCEx_PollForTamperEvent(RTC_HandleTypeDef *hrtc, uint32_t Tamper, uint32_t Timeout);
  860. HAL_StatusTypeDef HAL_RTCEx_SetInternalTamper(RTC_HandleTypeDef *hrtc, RTC_InternalTamperTypeDef* sIntTamper);
  861. HAL_StatusTypeDef HAL_RTCEx_SetInternalTamper_IT(RTC_HandleTypeDef *hrtc, RTC_InternalTamperTypeDef* sIntTamper);
  862. HAL_StatusTypeDef HAL_RTCEx_DeactivateInternalTamper(RTC_HandleTypeDef *hrtc, uint32_t IntTamper);
  863. HAL_StatusTypeDef HAL_RTCEx_PollForInternalTamperEvent(RTC_HandleTypeDef *hrtc, uint32_t IntTamper, uint32_t Timeout);
  864. void HAL_RTCEx_TamperIRQHandler(RTC_HandleTypeDef *hrtc);
  865. void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc);
  866. void HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef *hrtc);
  867. #if defined(TAMP_CR1_TAMP3E)
  868. void HAL_RTCEx_Tamper3EventCallback(RTC_HandleTypeDef *hrtc);
  869. #endif /* TAMP_CR1_TAMP3E */
  870. void HAL_RTCEx_InternalTamper3EventCallback(RTC_HandleTypeDef *hrtc);
  871. void HAL_RTCEx_InternalTamper4EventCallback(RTC_HandleTypeDef *hrtc);
  872. void HAL_RTCEx_InternalTamper5EventCallback(RTC_HandleTypeDef *hrtc);
  873. void HAL_RTCEx_InternalTamper6EventCallback(RTC_HandleTypeDef *hrtc);
  874. /**
  875. * @}
  876. */
  877. /** @defgroup RTCEx_Exported_Functions_Group6 Extended RTC Backup register functions
  878. * @{
  879. */
  880. void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data);
  881. uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister);
  882. /**
  883. * @}
  884. */
  885. /**
  886. * @}
  887. */
  888. /* Private types -------------------------------------------------------------*/
  889. /* Private variables ---------------------------------------------------------*/
  890. /* Private constants ---------------------------------------------------------*/
  891. /** @defgroup RTCEx_Private_Constants RTCEx Private Constants
  892. * @{
  893. */
  894. #define RTC_EXTI_LINE_TIMESTAMP_EVENT EXTI_IMR1_IM19 /*!< External interrupt line 19 Connected to the RTC Time Stamp events */
  895. #define RTC_EXTI_LINE_WAKEUPTIMER_EVENT EXTI_IMR1_IM19 /*!< External interrupt line 19 Connected to the RTC Wakeup event */
  896. #define RTC_EXTI_LINE_TAMPER_EVENT EXTI_IMR1_IM21 /*!< External interrupt line 19 Connected to the RTC tamper events*/
  897. /**
  898. * @}
  899. */
  900. /* Private macros ------------------------------------------------------------*/
  901. /** @defgroup RTCEx_Private_Macros RTCEx Private Macros
  902. * @{
  903. */
  904. /** @defgroup RTCEx_IS_RTC_Definitions Private macros to check input parameters
  905. * @{
  906. */
  907. #define IS_TIMESTAMP_EDGE(EDGE) (((EDGE) == RTC_TIMESTAMPEDGE_RISING) || \
  908. ((EDGE) == RTC_TIMESTAMPEDGE_FALLING))
  909. #define IS_RTC_TIMESTAMP_PIN(PIN) (((PIN) == RTC_TIMESTAMPPIN_DEFAULT))
  910. #define IS_RTC_TIMESTAMPONTAMPER_DETECTION(DETECTION) (((DETECTION) == RTC_TIMESTAMPONTAMPERDETECTION_ENABLE) || \
  911. ((DETECTION) == RTC_TIMESTAMPONTAMPERDETECTION_DISABLE))
  912. #define IS_RTC_TAMPER_TAMPERDETECTIONOUTPUT(MODE) (((MODE) == RTC_TAMPERDETECTIONOUTPUT_ENABLE) || \
  913. ((MODE) == RTC_TAMPERDETECTIONOUTPUT_DISABLE))
  914. #define IS_RTC_WAKEUP_CLOCK(CLOCK) (((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV16) || \
  915. ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV8) || \
  916. ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV4) || \
  917. ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV2) || \
  918. ((CLOCK) == RTC_WAKEUPCLOCK_CK_SPRE_16BITS) || \
  919. ((CLOCK) == RTC_WAKEUPCLOCK_CK_SPRE_17BITS))
  920. #define IS_RTC_WAKEUP_COUNTER(COUNTER) ((COUNTER) <= RTC_WUTR_WUT)
  921. #define IS_RTC_SMOOTH_CALIB_PERIOD(PERIOD) (((PERIOD) == RTC_SMOOTHCALIB_PERIOD_32SEC) || \
  922. ((PERIOD) == RTC_SMOOTHCALIB_PERIOD_16SEC) || \
  923. ((PERIOD) == RTC_SMOOTHCALIB_PERIOD_8SEC))
  924. #define IS_RTC_SMOOTH_CALIB_PLUS(PLUS) (((PLUS) == RTC_SMOOTHCALIB_PLUSPULSES_SET) || \
  925. ((PLUS) == RTC_SMOOTHCALIB_PLUSPULSES_RESET))
  926. #define IS_RTC_TAMPER(__TAMPER__) ((((__TAMPER__) & RTC_TAMPER_ALL) != 0x00U) && \
  927. (((__TAMPER__) & ~RTC_TAMPER_ALL) == 0x00U))
  928. #define IS_RTC_INTERNAL_TAMPER(__INT_TAMPER__) ((((__INT_TAMPER__) & RTC_INT_TAMPER_ALL) != 0x00U) && \
  929. (((__INT_TAMPER__) & ~RTC_INT_TAMPER_ALL) == 0x00U))
  930. #define IS_RTC_TAMPER_TRIGGER(__TRIGGER__) (((__TRIGGER__) == RTC_TAMPERTRIGGER_RISINGEDGE) || \
  931. ((__TRIGGER__) == RTC_TAMPERTRIGGER_FALLINGEDGE) || \
  932. ((__TRIGGER__) == RTC_TAMPERTRIGGER_LOWLEVEL) || \
  933. ((__TRIGGER__) == RTC_TAMPERTRIGGER_HIGHLEVEL))
  934. #define IS_RTC_TAMPER_ERASE_MODE(__MODE__) (((__MODE__) == RTC_TAMPER_ERASE_BACKUP_ENABLE) || \
  935. ((__MODE__) == RTC_TAMPER_ERASE_BACKUP_DISABLE))
  936. #define IS_RTC_TAMPER_MASKFLAG_STATE(__STATE__) (((__STATE__) == RTC_TAMPERMASK_FLAG_ENABLE) || \
  937. ((__STATE__) == RTC_TAMPERMASK_FLAG_DISABLE))
  938. #define IS_RTC_TAMPER_FILTER(__FILTER__) (((__FILTER__) == RTC_TAMPERFILTER_DISABLE) || \
  939. ((__FILTER__) == RTC_TAMPERFILTER_2SAMPLE) || \
  940. ((__FILTER__) == RTC_TAMPERFILTER_4SAMPLE) || \
  941. ((__FILTER__) == RTC_TAMPERFILTER_8SAMPLE))
  942. #define IS_RTC_TAMPER_SAMPLING_FREQ(__FREQ__) (((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV32768)|| \
  943. ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV16384)|| \
  944. ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV8192) || \
  945. ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV4096) || \
  946. ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV2048) || \
  947. ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV1024) || \
  948. ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV512) || \
  949. ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV256))
  950. #define IS_RTC_TAMPER_PRECHARGE_DURATION(__DURATION__) (((__DURATION__) == RTC_TAMPERPRECHARGEDURATION_1RTCCLK) || \
  951. ((__DURATION__) == RTC_TAMPERPRECHARGEDURATION_2RTCCLK) || \
  952. ((__DURATION__) == RTC_TAMPERPRECHARGEDURATION_4RTCCLK) || \
  953. ((__DURATION__) == RTC_TAMPERPRECHARGEDURATION_8RTCCLK))
  954. #define IS_RTC_TAMPER_PULLUP_STATE(__STATE__) (((__STATE__) == RTC_TAMPER_PULLUP_ENABLE) || \
  955. ((__STATE__) == RTC_TAMPER_PULLUP_DISABLE))
  956. #define IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(DETECTION) (((DETECTION) == RTC_TIMESTAMPONTAMPERDETECTION_ENABLE) || \
  957. ((DETECTION) == RTC_TIMESTAMPONTAMPERDETECTION_DISABLE))
  958. #define IS_RTC_BKP(__BKP__) ((__BKP__) < RTC_BKP_NUMBER)
  959. /** @defgroup RTCEx_Smooth_calib_Minus_pulses_Definitions RTCEx Smooth calib Minus pulses Definitions
  960. * @{
  961. */
  962. #define IS_RTC_SMOOTH_CALIB_MINUS(VALUE) ((VALUE) <= RTC_CALR_CALM)
  963. /**
  964. * @}
  965. */
  966. #define IS_RTC_SHIFT_ADD1S(SEL) (((SEL) == RTC_SHIFTADD1S_RESET) || \
  967. ((SEL) == RTC_SHIFTADD1S_SET))
  968. /** @defgroup RTCEx_Subtract_Fraction_Of_Second_Value RTCEx Subtract Fraction Of Second Value
  969. * @{
  970. */
  971. #define IS_RTC_SHIFT_SUBFS(FS) ((FS) <= RTC_SHIFTR_SUBFS)
  972. /**
  973. * @}
  974. */
  975. #define IS_RTC_CALIB_OUTPUT(OUTPUT) (((OUTPUT) == RTC_CALIBOUTPUT_512HZ) || \
  976. ((OUTPUT) == RTC_CALIBOUTPUT_1HZ))
  977. /**
  978. * @}
  979. */
  980. /**
  981. * @}
  982. */
  983. /**
  984. * @}
  985. */
  986. /**
  987. * @}
  988. */
  989. #ifdef __cplusplus
  990. }
  991. #endif
  992. #endif /* STM32G0xx_HAL_RTC_EX_H */