stm32l4xx_hal_rtc.h 52 KB

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