stm32g4xx_hal_rtc.h 46 KB

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