stm32g0xx_hal_rtc.h 45 KB

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