stm32l4xx_hal_rtc.h 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137
  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 Add 1 hour (summer time change).
  560. * @note This interface is deprecated.
  561. * To manage Daylight Saving Time, please use HAL_RTC_DST_xxx functions
  562. * @param __HANDLE__ specifies the RTC handle.
  563. * @param __BKP__ Backup
  564. * This parameter can be:
  565. * @arg @ref RTC_STOREOPERATION_RESET
  566. * @arg @ref RTC_STOREOPERATION_SET
  567. * @retval None
  568. */
  569. #define __HAL_RTC_DAYLIGHT_SAVING_TIME_ADD1H(__HANDLE__, __BKP__) \
  570. do { \
  571. __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__); \
  572. SET_BIT((__HANDLE__)->Instance->CR, RTC_CR_ADD1H); \
  573. MODIFY_REG((__HANDLE__)->Instance->CR, RTC_CR_BKP , (__BKP__)); \
  574. __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__); \
  575. } while(0u);
  576. /**
  577. * @brief Subtract 1 hour (winter time change).
  578. * @note This interface is deprecated.
  579. * To manage Daylight Saving Time, please use HAL_RTC_DST_xxx functions
  580. * @param __HANDLE__ specifies the RTC handle.
  581. * @param __BKP__ Backup
  582. * This parameter can be:
  583. * @arg @ref RTC_STOREOPERATION_RESET
  584. * @arg @ref RTC_STOREOPERATION_SET
  585. * @retval None
  586. */
  587. #define __HAL_RTC_DAYLIGHT_SAVING_TIME_SUB1H(__HANDLE__, __BKP__) \
  588. do { \
  589. __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__); \
  590. SET_BIT((__HANDLE__)->Instance->CR, RTC_CR_SUB1H); \
  591. MODIFY_REG((__HANDLE__)->Instance->CR, RTC_CR_BKP , (__BKP__)); \
  592. __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__); \
  593. } while(0u);
  594. /**
  595. * @brief Enable the RTC ALARMA peripheral.
  596. * @param __HANDLE__ specifies the RTC handle.
  597. * @retval None
  598. */
  599. #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE))
  600. /**
  601. * @brief Disable the RTC ALARMA peripheral.
  602. * @param __HANDLE__ specifies the RTC handle.
  603. * @retval None
  604. */
  605. #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE))
  606. /**
  607. * @brief Enable the RTC ALARMB peripheral.
  608. * @param __HANDLE__ specifies the RTC handle.
  609. * @retval None
  610. */
  611. #define __HAL_RTC_ALARMB_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRBE))
  612. /**
  613. * @brief Disable the RTC ALARMB peripheral.
  614. * @param __HANDLE__ specifies the RTC handle.
  615. * @retval None
  616. */
  617. #define __HAL_RTC_ALARMB_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRBE))
  618. /**
  619. * @brief Enable the RTC Alarm interrupt.
  620. * @param __HANDLE__ specifies the RTC handle.
  621. * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled.
  622. * This parameter can be any combination of the following values:
  623. * @arg @ref RTC_IT_ALRA Alarm A interrupt
  624. * @arg @ref RTC_IT_ALRB Alarm B interrupt
  625. * @retval None
  626. */
  627. #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
  628. /**
  629. * @brief Disable 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_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
  638. /**
  639. * @brief Check whether the specified RTC Alarm interrupt has occurred or not.
  640. * @param __HANDLE__ specifies the RTC handle.
  641. * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check.
  642. * This parameter can be:
  643. * @arg @ref RTC_IT_ALRA Alarm A interrupt
  644. * @arg @ref RTC_IT_ALRB Alarm B interrupt
  645. * @retval None
  646. */
  647. #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
  648. #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->MISR)& (__INTERRUPT__ >> 12)) != 0U)? 1U : 0U)
  649. #else
  650. #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->ISR)& (__INTERRUPT__ >> 4)) != 0U)? 1U : 0U)
  651. #endif
  652. /**
  653. * @brief Check whether the specified RTC Alarm interrupt has been enabled or not.
  654. * @param __HANDLE__ specifies the RTC handle.
  655. * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check.
  656. * This parameter can be:
  657. * @arg @ref RTC_IT_ALRA Alarm A interrupt
  658. * @arg @ref RTC_IT_ALRB Alarm B interrupt
  659. * @retval None
  660. */
  661. #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
  662. #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
  663. /**
  664. * @brief Get the selected RTC Alarm's flag status.
  665. * @param __HANDLE__ specifies the RTC handle.
  666. * @param __FLAG__ specifies the RTC Alarm Flag sources to check.
  667. * This parameter can be:
  668. * @arg @ref RTC_FLAG_ALRAF
  669. * @arg @ref RTC_FLAG_ALRBF
  670. * @retval None
  671. */
  672. #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (__HAL_RTC_GET_FLAG((__HANDLE__), (__FLAG__)))
  673. #else /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
  674. /**
  675. * @brief Get the selected RTC Alarm's flag status.
  676. * @param __HANDLE__ specifies the RTC handle.
  677. * @param __FLAG__ specifies the RTC Alarm Flag sources to check.
  678. * This parameter can be:
  679. * @arg @ref RTC_FLAG_ALRAF
  680. * @arg @ref RTC_FLAG_ALRBF
  681. * @arg @ref RTC_FLAG_ALRAWF
  682. * @arg @ref RTC_FLAG_ALRBWF
  683. * @retval None
  684. */
  685. #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U) ? 1U : 0U)
  686. #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
  687. /**
  688. * @brief Clear the RTC Alarm's pending flags.
  689. * @param __HANDLE__ specifies the RTC handle.
  690. * @param __FLAG__ specifies the RTC Alarm Flag sources to clear.
  691. * This parameter can be:
  692. * @arg @ref RTC_FLAG_ALRAF
  693. * @arg @ref RTC_FLAG_ALRBF
  694. * @retval None
  695. */
  696. #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
  697. #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__FLAG__) == RTC_FLAG_ALRAF) ? (((__HANDLE__)->Instance->SCR = (RTC_CLEAR_ALRAF))) : \
  698. ((__HANDLE__)->Instance->SCR = (RTC_CLEAR_ALRBF)))
  699. #else
  700. #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT)))
  701. #endif
  702. /**
  703. * @brief Enable interrupt on the RTC Alarm associated Exti line.
  704. * @retval None
  705. */
  706. #define __HAL_RTC_ALARM_EXTI_ENABLE_IT() (EXTI->IMR1 |= RTC_EXTI_LINE_ALARM_EVENT)
  707. /**
  708. * @brief Disable interrupt on the RTC Alarm associated Exti line.
  709. * @retval None
  710. */
  711. #define __HAL_RTC_ALARM_EXTI_DISABLE_IT() (EXTI->IMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  712. /**
  713. * @brief Enable event on the RTC Alarm associated Exti line.
  714. * @retval None.
  715. */
  716. #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT() (EXTI->EMR1 |= RTC_EXTI_LINE_ALARM_EVENT)
  717. /**
  718. * @brief Disable event on the RTC Alarm associated Exti line.
  719. * @retval None.
  720. */
  721. #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT() (EXTI->EMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  722. /**
  723. * @brief Enable falling edge trigger on the RTC Alarm associated Exti line.
  724. * @retval None
  725. */
  726. #define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE() (EXTI->FTSR1 |= RTC_EXTI_LINE_ALARM_EVENT)
  727. /**
  728. * @brief Disable falling edge trigger on the RTC Alarm associated Exti line.
  729. * @retval None
  730. */
  731. #define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE() (EXTI->FTSR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  732. /**
  733. * @brief Enable rising edge trigger on the RTC Alarm associated Exti line.
  734. * @retval None
  735. */
  736. #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE() (EXTI->RTSR1 |= RTC_EXTI_LINE_ALARM_EVENT)
  737. /**
  738. * @brief Disable rising edge trigger on the RTC Alarm associated Exti line.
  739. * @retval None
  740. */
  741. #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE() (EXTI->RTSR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  742. /**
  743. * @brief Enable rising & falling edge trigger on the RTC Alarm associated Exti line.
  744. * @retval None
  745. */
  746. #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
  747. __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE(); \
  748. __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE(); \
  749. } while(0u)
  750. /**
  751. * @brief Disable rising & falling edge trigger on the RTC Alarm associated Exti line.
  752. * @retval None
  753. */
  754. #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
  755. __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE(); \
  756. __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE(); \
  757. } while(0u)
  758. /**
  759. * @brief Check whether the RTC Alarm associated Exti line interrupt flag is set or not.
  760. * @retval Line Status.
  761. */
  762. #define __HAL_RTC_ALARM_EXTI_GET_FLAG() (EXTI->PR1 & RTC_EXTI_LINE_ALARM_EVENT)
  763. /**
  764. * @brief Clear the RTC Alarm associated Exti line flag.
  765. * @retval None
  766. */
  767. #define __HAL_RTC_ALARM_EXTI_CLEAR_FLAG() (EXTI->PR1 = RTC_EXTI_LINE_ALARM_EVENT)
  768. /**
  769. * @brief Generate a Software interrupt on RTC Alarm associated Exti line.
  770. * @retval None
  771. */
  772. #define __HAL_RTC_ALARM_EXTI_GENERATE_SWIT() (EXTI->SWIER1 |= RTC_EXTI_LINE_ALARM_EVENT)
  773. /**
  774. * @}
  775. */
  776. /* Include RTC HAL Extended module */
  777. #include "stm32l4xx_hal_rtc_ex.h"
  778. /* Exported functions --------------------------------------------------------*/
  779. /** @defgroup RTC_Exported_Functions RTC Exported Functions
  780. * @{
  781. */
  782. /** @defgroup RTC_Exported_Functions_Group1 Initialization and de-initialization functions
  783. * @{
  784. */
  785. /* Initialization and de-initialization functions ****************************/
  786. HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc);
  787. HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc);
  788. void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc);
  789. void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc);
  790. /* Callbacks Register/UnRegister functions ***********************************/
  791. #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
  792. HAL_StatusTypeDef HAL_RTC_RegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID, pRTC_CallbackTypeDef pCallback);
  793. HAL_StatusTypeDef HAL_RTC_UnRegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID);
  794. #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
  795. /**
  796. * @}
  797. */
  798. /** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions
  799. * @{
  800. */
  801. /* RTC Time and Date functions ************************************************/
  802. HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
  803. HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
  804. HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
  805. HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
  806. void HAL_RTC_DST_Add1Hour(RTC_HandleTypeDef *hrtc);
  807. void HAL_RTC_DST_Sub1Hour(RTC_HandleTypeDef *hrtc);
  808. void HAL_RTC_DST_SetStoreOperation(RTC_HandleTypeDef *hrtc);
  809. void HAL_RTC_DST_ClearStoreOperation(RTC_HandleTypeDef *hrtc);
  810. uint32_t HAL_RTC_DST_ReadStoreOperation(RTC_HandleTypeDef *hrtc);
  811. /**
  812. * @}
  813. */
  814. /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions
  815. * @{
  816. */
  817. /* RTC Alarm functions ********************************************************/
  818. HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
  819. HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
  820. HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm);
  821. HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format);
  822. void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc);
  823. void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc);
  824. HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
  825. /**
  826. * @}
  827. */
  828. /** @defgroup RTC_Exported_Functions_Group4 Peripheral Control functions
  829. * @{
  830. */
  831. /* Peripheral Control functions ***********************************************/
  832. HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc);
  833. /**
  834. * @}
  835. */
  836. /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions
  837. * @{
  838. */
  839. /* Peripheral State functions *************************************************/
  840. HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc);
  841. /**
  842. * @}
  843. */
  844. /**
  845. * @}
  846. */
  847. /* Private types -------------------------------------------------------------*/
  848. /* Private variables ---------------------------------------------------------*/
  849. /* Private constants ---------------------------------------------------------*/
  850. /** @defgroup RTC_Private_Constants RTC Private Constants
  851. * @{
  852. */
  853. /* Masks Definition */
  854. #define RTC_TR_RESERVED_MASK (RTC_TR_PM | RTC_TR_HT | RTC_TR_HU | \
  855. RTC_TR_MNT | RTC_TR_MNU| RTC_TR_ST | \
  856. RTC_TR_SU)
  857. #define RTC_DR_RESERVED_MASK (RTC_DR_YT | RTC_DR_YU | RTC_DR_WDU | \
  858. RTC_DR_MT | RTC_DR_MU | RTC_DR_DT | \
  859. RTC_DR_DU)
  860. #define RTC_INIT_MASK 0xFFFFFFFFu
  861. #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
  862. #define RTC_RSF_MASK (~(RTC_ICSR_INIT | RTC_ICSR_RSF))
  863. #else
  864. #define RTC_RSF_MASK (~(RTC_ISR_INIT | RTC_ISR_RSF))
  865. #endif
  866. #define RTC_TIMEOUT_VALUE 1000u
  867. #define RTC_EXTI_LINE_ALARM_EVENT EXTI_IMR1_IM18 /*!< External interrupt line 18 Connected to the RTC Alarm event */
  868. /**
  869. * @}
  870. */
  871. /* Private macros ------------------------------------------------------------*/
  872. /** @defgroup RTC_Private_Macros RTC Private Macros
  873. * @{
  874. */
  875. /** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters
  876. * @{
  877. */
  878. #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
  879. #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \
  880. ((OUTPUT) == RTC_OUTPUT_ALARMA) || \
  881. ((OUTPUT) == RTC_OUTPUT_ALARMB) || \
  882. ((OUTPUT) == RTC_OUTPUT_WAKEUP) || \
  883. ((OUTPUT) == RTC_OUTPUT_TAMPER))
  884. #else
  885. #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \
  886. ((OUTPUT) == RTC_OUTPUT_ALARMA) || \
  887. ((OUTPUT) == RTC_OUTPUT_ALARMB) || \
  888. ((OUTPUT) == RTC_OUTPUT_WAKEUP))
  889. #endif
  890. #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_HOURFORMAT_12) || \
  891. ((FORMAT) == RTC_HOURFORMAT_24))
  892. #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \
  893. ((POL) == RTC_OUTPUT_POLARITY_LOW))
  894. #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \
  895. ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL))
  896. #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
  897. #define IS_RTC_OUTPUT_PULLUP(TYPE) (((TYPE) == RTC_OUTPUT_PULLUP_NONE) || \
  898. ((TYPE) == RTC_OUTPUT_PULLUP_ON))
  899. #endif
  900. #define IS_RTC_OUTPUT_REMAP(REMAP) (((REMAP) == RTC_OUTPUT_REMAP_NONE) || \
  901. ((REMAP) == RTC_OUTPUT_REMAP_POS1))
  902. #define IS_RTC_HOURFORMAT12(PM) (((PM) == RTC_HOURFORMAT12_AM) || \
  903. ((PM) == RTC_HOURFORMAT12_PM))
  904. #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \
  905. ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \
  906. ((SAVE) == RTC_DAYLIGHTSAVING_NONE))
  907. #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \
  908. ((OPERATION) == RTC_STOREOPERATION_SET))
  909. #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || \
  910. ((FORMAT) == RTC_FORMAT_BCD))
  911. #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99u)
  912. #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1u) && ((MONTH) <= 12u))
  913. #define IS_RTC_DATE(DATE) (((DATE) >= 1u) && ((DATE) <= 31u))
  914. #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \
  915. ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \
  916. ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
  917. ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \
  918. ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \
  919. ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \
  920. ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
  921. #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) >0u) && ((DATE) <= 31u))
  922. #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \
  923. ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \
  924. ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
  925. ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \
  926. ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \
  927. ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \
  928. ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
  929. #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \
  930. ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY))
  931. #define IS_RTC_ALARM_MASK(MASK) (((MASK) & ~(RTC_ALARMMASK_ALL)) == 0U)
  932. #define IS_RTC_ALARM(ALARM) (((ALARM) == RTC_ALARM_A) || \
  933. ((ALARM) == RTC_ALARM_B))
  934. #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= RTC_ALRMASSR_SS)
  935. #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK) (((MASK) == 0u) || \
  936. (((MASK) >= RTC_ALARMSUBSECONDMASK_SS14_1) && ((MASK) <= RTC_ALARMSUBSECONDMASK_NONE)))
  937. #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= (RTC_PRER_PREDIV_A >> RTC_PRER_PREDIV_A_Pos))
  938. #define IS_RTC_SYNCH_PREDIV(PREDIV) ((PREDIV) <= (RTC_PRER_PREDIV_S >> RTC_PRER_PREDIV_S_Pos))
  939. #define IS_RTC_HOUR12(HOUR) (((HOUR) > 0u) && ((HOUR) <= 12u))
  940. #define IS_RTC_HOUR24(HOUR) ((HOUR) <= 23u)
  941. #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59u)
  942. #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59u)
  943. /**
  944. * @}
  945. */
  946. /**
  947. * @}
  948. */
  949. /* Private functions -------------------------------------------------------------*/
  950. /** @defgroup RTC_Private_Functions RTC Private Functions
  951. * @{
  952. */
  953. HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef *hrtc);
  954. HAL_StatusTypeDef RTC_ExitInitMode(RTC_HandleTypeDef *hrtc);
  955. uint8_t RTC_ByteToBcd2(uint8_t Value);
  956. uint8_t RTC_Bcd2ToByte(uint8_t Value);
  957. /**
  958. * @}
  959. */
  960. /**
  961. * @}
  962. */
  963. /**
  964. * @}
  965. */
  966. /**
  967. * @}
  968. */
  969. #ifdef __cplusplus
  970. }
  971. #endif
  972. #endif /* STM32L4xx_HAL_RTC_H */