You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

798 lines
33 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_hal_rtc.h
  4. * @author MCD Application Team
  5. * @brief Header file of RTC HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32F0xx_HAL_RTC_H
  37. #define __STM32F0xx_HAL_RTC_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32f0xx_hal_def.h"
  43. /** @addtogroup STM32F0xx_HAL_Driver
  44. * @{
  45. */
  46. /** @defgroup RTC RTC
  47. * @{
  48. */
  49. /* Exported types ------------------------------------------------------------*/
  50. /** @defgroup RTC_Exported_Types RTC Exported Types
  51. * @{
  52. */
  53. /**
  54. * @brief HAL State structures definition
  55. */
  56. typedef enum
  57. {
  58. HAL_RTC_STATE_RESET = 0x00U, /*!< RTC not yet initialized or disabled */
  59. HAL_RTC_STATE_READY = 0x01U, /*!< RTC initialized and ready for use */
  60. HAL_RTC_STATE_BUSY = 0x02U, /*!< RTC process is ongoing */
  61. HAL_RTC_STATE_TIMEOUT = 0x03U, /*!< RTC timeout state */
  62. HAL_RTC_STATE_ERROR = 0x04U /*!< RTC error state */
  63. }HAL_RTCStateTypeDef;
  64. /**
  65. * @brief RTC Configuration Structure definition
  66. */
  67. typedef struct
  68. {
  69. uint32_t HourFormat; /*!< Specifies the RTC Hour Format.
  70. This parameter can be a value of @ref RTC_Hour_Formats */
  71. uint32_t AsynchPrediv; /*!< Specifies the RTC Asynchronous Predivider value.
  72. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7F */
  73. uint32_t SynchPrediv; /*!< Specifies the RTC Synchronous Predivider value.
  74. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7FFF */
  75. uint32_t OutPut; /*!< Specifies which signal will be routed to the RTC output.
  76. This parameter can be a value of @ref RTCEx_Output_selection_Definitions */
  77. uint32_t OutPutPolarity; /*!< Specifies the polarity of the output signal.
  78. This parameter can be a value of @ref RTC_Output_Polarity_Definitions */
  79. uint32_t OutPutType; /*!< Specifies the RTC Output Pin mode.
  80. This parameter can be a value of @ref RTC_Output_Type_ALARM_OUT */
  81. }RTC_InitTypeDef;
  82. /**
  83. * @brief RTC Time structure definition
  84. */
  85. typedef struct
  86. {
  87. uint8_t Hours; /*!< Specifies the RTC Time Hour.
  88. This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected.
  89. This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected */
  90. uint8_t Minutes; /*!< Specifies the RTC Time Minutes.
  91. This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
  92. uint8_t Seconds; /*!< Specifies the RTC Time Seconds.
  93. This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
  94. uint8_t TimeFormat; /*!< Specifies the RTC AM/PM Time.
  95. This parameter can be a value of @ref RTC_AM_PM_Definitions */
  96. uint32_t SubSeconds; /*!< Specifies the RTC_SSR RTC Sub Second register content.
  97. This parameter corresponds to a time unit range between [0-1] Second
  98. with [1 Sec / SecondFraction +1] granularity */
  99. uint32_t SecondFraction; /*!< Specifies the range or granularity of Sub Second register content
  100. corresponding to Synchronous pre-scaler factor value (PREDIV_S)
  101. This parameter corresponds to a time unit range between [0-1] Second
  102. with [1 Sec / SecondFraction +1] granularity.
  103. This field will be used only by HAL_RTC_GetTime function */
  104. uint32_t DayLightSaving; /*!< Specifies RTC_DayLightSaveOperation: the value of hour adjustment.
  105. This parameter can be a value of @ref RTC_DayLightSaving_Definitions */
  106. uint32_t StoreOperation; /*!< Specifies RTC_StoreOperation value to be written in the BCK bit
  107. in CR register to store the operation.
  108. This parameter can be a value of @ref RTC_StoreOperation_Definitions */
  109. }RTC_TimeTypeDef;
  110. /**
  111. * @brief RTC Date structure definition
  112. */
  113. typedef struct
  114. {
  115. uint8_t WeekDay; /*!< Specifies the RTC Date WeekDay.
  116. This parameter can be a value of @ref RTC_WeekDay_Definitions */
  117. uint8_t Month; /*!< Specifies the RTC Date Month (in BCD format).
  118. This parameter can be a value of @ref RTC_Month_Date_Definitions */
  119. uint8_t Date; /*!< Specifies the RTC Date.
  120. This parameter must be a number between Min_Data = 1 and Max_Data = 31 */
  121. uint8_t Year; /*!< Specifies the RTC Date Year.
  122. This parameter must be a number between Min_Data = 0 and Max_Data = 99 */
  123. }RTC_DateTypeDef;
  124. /**
  125. * @brief RTC Alarm structure definition
  126. */
  127. typedef struct
  128. {
  129. RTC_TimeTypeDef AlarmTime; /*!< Specifies the RTC Alarm Time members */
  130. uint32_t AlarmMask; /*!< Specifies the RTC Alarm Masks.
  131. This parameter can be a value of @ref RTC_AlarmMask_Definitions */
  132. uint32_t AlarmSubSecondMask; /*!< Specifies the RTC Alarm SubSeconds Masks.
  133. This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */
  134. uint32_t AlarmDateWeekDaySel; /*!< Specifies the RTC Alarm is on Date or WeekDay.
  135. This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */
  136. uint8_t AlarmDateWeekDay; /*!< Specifies the RTC Alarm Date/WeekDay.
  137. If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range.
  138. If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */
  139. uint32_t Alarm; /*!< Specifies the alarm .
  140. This parameter can be a value of @ref RTC_Alarms_Definitions */
  141. }RTC_AlarmTypeDef;
  142. /**
  143. * @brief RTC Handle Structure definition
  144. */
  145. typedef struct
  146. {
  147. RTC_TypeDef *Instance; /*!< Register base address */
  148. RTC_InitTypeDef Init; /*!< RTC required parameters */
  149. HAL_LockTypeDef Lock; /*!< RTC locking object */
  150. __IO HAL_RTCStateTypeDef State; /*!< Time communication state */
  151. }RTC_HandleTypeDef;
  152. /**
  153. * @}
  154. */
  155. /* Exported constants --------------------------------------------------------*/
  156. /** @defgroup RTC_Exported_Constants RTC Exported Constants
  157. * @{
  158. */
  159. /** @defgroup RTC_Hour_Formats RTC Hour Formats
  160. * @{
  161. */
  162. #define RTC_HOURFORMAT_24 0x00000000U
  163. #define RTC_HOURFORMAT_12 0x00000040U
  164. /**
  165. * @}
  166. */
  167. /** @defgroup RTC_Output_Polarity_Definitions RTC Output Polarity Definitions
  168. * @{
  169. */
  170. #define RTC_OUTPUT_POLARITY_HIGH 0x00000000U
  171. #define RTC_OUTPUT_POLARITY_LOW 0x00100000U
  172. /**
  173. * @}
  174. */
  175. /** @defgroup RTC_Output_Type_ALARM_OUT RTC Output Type ALARM OUT
  176. * @{
  177. */
  178. #define RTC_OUTPUT_TYPE_OPENDRAIN 0x00000000U
  179. #define RTC_OUTPUT_TYPE_PUSHPULL 0x00040000U
  180. /**
  181. * @}
  182. */
  183. /** @defgroup RTC_AM_PM_Definitions RTC AM PM Definitions
  184. * @{
  185. */
  186. #define RTC_HOURFORMAT12_AM ((uint8_t)0x00)
  187. #define RTC_HOURFORMAT12_PM ((uint8_t)0x40)
  188. /**
  189. * @}
  190. */
  191. /** @defgroup RTC_DayLightSaving_Definitions RTC DayLight Saving Definitions
  192. * @{
  193. */
  194. #define RTC_DAYLIGHTSAVING_SUB1H 0x00020000U
  195. #define RTC_DAYLIGHTSAVING_ADD1H 0x00010000U
  196. #define RTC_DAYLIGHTSAVING_NONE 0x00000000U
  197. /**
  198. * @}
  199. */
  200. /** @defgroup RTC_StoreOperation_Definitions RTC Store Operation Definitions
  201. * @{
  202. */
  203. #define RTC_STOREOPERATION_RESET 0x00000000U
  204. #define RTC_STOREOPERATION_SET 0x00040000U
  205. /**
  206. * @}
  207. */
  208. /** @defgroup RTC_Input_parameter_format_definitions RTC Input parameter format definitions
  209. * @{
  210. */
  211. #define RTC_FORMAT_BIN 0x000000000U
  212. #define RTC_FORMAT_BCD 0x000000001U
  213. /**
  214. * @}
  215. */
  216. /** @defgroup RTC_Month_Date_Definitions RTC Month Date Definitions
  217. * @{
  218. */
  219. /* Coded in BCD format */
  220. #define RTC_MONTH_JANUARY ((uint8_t)0x01)
  221. #define RTC_MONTH_FEBRUARY ((uint8_t)0x02)
  222. #define RTC_MONTH_MARCH ((uint8_t)0x03)
  223. #define RTC_MONTH_APRIL ((uint8_t)0x04)
  224. #define RTC_MONTH_MAY ((uint8_t)0x05)
  225. #define RTC_MONTH_JUNE ((uint8_t)0x06)
  226. #define RTC_MONTH_JULY ((uint8_t)0x07)
  227. #define RTC_MONTH_AUGUST ((uint8_t)0x08)
  228. #define RTC_MONTH_SEPTEMBER ((uint8_t)0x09)
  229. #define RTC_MONTH_OCTOBER ((uint8_t)0x10)
  230. #define RTC_MONTH_NOVEMBER ((uint8_t)0x11)
  231. #define RTC_MONTH_DECEMBER ((uint8_t)0x12)
  232. /**
  233. * @}
  234. */
  235. /** @defgroup RTC_WeekDay_Definitions RTC WeekDay Definitions
  236. * @{
  237. */
  238. #define RTC_WEEKDAY_MONDAY ((uint8_t)0x01)
  239. #define RTC_WEEKDAY_TUESDAY ((uint8_t)0x02)
  240. #define RTC_WEEKDAY_WEDNESDAY ((uint8_t)0x03)
  241. #define RTC_WEEKDAY_THURSDAY ((uint8_t)0x04)
  242. #define RTC_WEEKDAY_FRIDAY ((uint8_t)0x05)
  243. #define RTC_WEEKDAY_SATURDAY ((uint8_t)0x06)
  244. #define RTC_WEEKDAY_SUNDAY ((uint8_t)0x07)
  245. /**
  246. * @}
  247. */
  248. /** @defgroup RTC_AlarmDateWeekDay_Definitions RTC Alarm Date WeekDay Definitions
  249. * @{
  250. */
  251. #define RTC_ALARMDATEWEEKDAYSEL_DATE 0x00000000U
  252. #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY 0x40000000U
  253. /**
  254. * @}
  255. */
  256. /** @defgroup RTC_AlarmMask_Definitions RTC Alarm Mask Definitions
  257. * @{
  258. */
  259. #define RTC_ALARMMASK_NONE 0x00000000U
  260. #define RTC_ALARMMASK_DATEWEEKDAY RTC_ALRMAR_MSK4
  261. #define RTC_ALARMMASK_HOURS RTC_ALRMAR_MSK3
  262. #define RTC_ALARMMASK_MINUTES RTC_ALRMAR_MSK2
  263. #define RTC_ALARMMASK_SECONDS RTC_ALRMAR_MSK1
  264. #define RTC_ALARMMASK_ALL 0x80808080U
  265. /**
  266. * @}
  267. */
  268. /** @defgroup RTC_Alarms_Definitions RTC Alarms Definitions
  269. * @{
  270. */
  271. #define RTC_ALARM_A RTC_CR_ALRAE
  272. /**
  273. * @}
  274. */
  275. /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions RTC Alarm Sub Seconds Masks Definitions
  276. * @{
  277. */
  278. #define RTC_ALARMSUBSECONDMASK_ALL 0x00000000U /*!< All Alarm SS fields are masked.
  279. There is no comparison on sub seconds
  280. for Alarm */
  281. #define RTC_ALARMSUBSECONDMASK_SS14_1 0x01000000U /*!< SS[14:1] are don't care in Alarm
  282. comparison. Only SS[0] is compared. */
  283. #define RTC_ALARMSUBSECONDMASK_SS14_2 0x02000000U /*!< SS[14:2] are don't care in Alarm
  284. comparison. Only SS[1:0] are compared */
  285. #define RTC_ALARMSUBSECONDMASK_SS14_3 0x03000000U /*!< SS[14:3] are don't care in Alarm
  286. comparison. Only SS[2:0] are compared */
  287. #define RTC_ALARMSUBSECONDMASK_SS14_4 0x04000000U /*!< SS[14:4] are don't care in Alarm
  288. comparison. Only SS[3:0] are compared */
  289. #define RTC_ALARMSUBSECONDMASK_SS14_5 0x05000000U /*!< SS[14:5] are don't care in Alarm
  290. comparison. Only SS[4:0] are compared */
  291. #define RTC_ALARMSUBSECONDMASK_SS14_6 0x06000000U /*!< SS[14:6] are don't care in Alarm
  292. comparison. Only SS[5:0] are compared */
  293. #define RTC_ALARMSUBSECONDMASK_SS14_7 0x07000000U /*!< SS[14:7] are don't care in Alarm
  294. comparison. Only SS[6:0] are compared */
  295. #define RTC_ALARMSUBSECONDMASK_SS14_8 0x08000000U /*!< SS[14:8] are don't care in Alarm
  296. comparison. Only SS[7:0] are compared */
  297. #define RTC_ALARMSUBSECONDMASK_SS14_9 0x09000000U /*!< SS[14:9] are don't care in Alarm
  298. comparison. Only SS[8:0] are compared */
  299. #define RTC_ALARMSUBSECONDMASK_SS14_10 0x0A000000U /*!< SS[14:10] are don't care in Alarm
  300. comparison. Only SS[9:0] are compared */
  301. #define RTC_ALARMSUBSECONDMASK_SS14_11 0x0B000000U /*!< SS[14:11] are don't care in Alarm
  302. comparison. Only SS[10:0] are compared */
  303. #define RTC_ALARMSUBSECONDMASK_SS14_12 0x0C000000U /*!< SS[14:12] are don't care in Alarm
  304. comparison.Only SS[11:0] are compared */
  305. #define RTC_ALARMSUBSECONDMASK_SS14_13 0x0D000000U /*!< SS[14:13] are don't care in Alarm
  306. comparison. Only SS[12:0] are compared */
  307. #define RTC_ALARMSUBSECONDMASK_SS14 0x0E000000U /*!< SS[14] is don't care in Alarm
  308. comparison.Only SS[13:0] are compared */
  309. #define RTC_ALARMSUBSECONDMASK_NONE 0x0F000000U /*!< SS[14:0] are compared and must match
  310. to activate alarm. */
  311. /**
  312. * @}
  313. */
  314. /** @defgroup RTC_Interrupts_Definitions RTC Interrupts Definitions
  315. * @{
  316. */
  317. #define RTC_IT_TS 0x00008000U
  318. #define RTC_IT_WUT 0x00004000U
  319. #define RTC_IT_ALRA 0x00001000U
  320. #define RTC_IT_TAMP 0x00000004U /* Used only to Enable the Tamper Interrupt */
  321. #define RTC_IT_TAMP1 0x00020000U /*only for RTC_ISR flag check*/
  322. #define RTC_IT_TAMP2 0x00040000U /*only for RTC_ISR flag check*/
  323. #define RTC_IT_TAMP3 0x00080000U /*only for RTC_ISR flag check*/
  324. /**
  325. * @}
  326. */
  327. /** @defgroup RTC_Flags_Definitions RTC Flags Definitions
  328. * @{
  329. */
  330. #define RTC_FLAG_RECALPF 0x00010000U
  331. #define RTC_FLAG_TAMP3F 0x00008000U
  332. #define RTC_FLAG_TAMP2F 0x00004000U
  333. #define RTC_FLAG_TAMP1F 0x00002000U
  334. #define RTC_FLAG_TSOVF 0x00001000U
  335. #define RTC_FLAG_TSF 0x00000800U
  336. #define RTC_FLAG_WUTF 0x00000400U
  337. #define RTC_FLAG_ALRAF 0x00000100U
  338. #define RTC_FLAG_INITF 0x00000040U
  339. #define RTC_FLAG_RSF 0x00000020U
  340. #define RTC_FLAG_INITS 0x00000010U
  341. #define RTC_FLAG_SHPF 0x00000008U
  342. #define RTC_FLAG_WUTWF 0x00000004U
  343. #define RTC_FLAG_ALRAWF 0x00000001U
  344. /**
  345. * @}
  346. */
  347. /**
  348. * @}
  349. */
  350. /* Exported macros ------------------------------------------------------------*/
  351. /** @defgroup RTC_Exported_Macros RTC Exported Macros
  352. * @{
  353. */
  354. /** @brief Reset RTC handle state
  355. * @param __HANDLE__ RTC handle.
  356. * @retval None
  357. */
  358. #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET)
  359. /**
  360. * @brief Disable the write protection for RTC registers.
  361. * @param __HANDLE__ specifies the RTC handle.
  362. * @retval None
  363. */
  364. #define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__) \
  365. do{ \
  366. (__HANDLE__)->Instance->WPR = 0xCAU; \
  367. (__HANDLE__)->Instance->WPR = 0x53U; \
  368. } while(0)
  369. /**
  370. * @brief Enable the write protection for RTC registers.
  371. * @param __HANDLE__ specifies the RTC handle.
  372. * @retval None
  373. */
  374. #define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__) \
  375. do{ \
  376. (__HANDLE__)->Instance->WPR = 0xFFU; \
  377. } while(0)
  378. /**
  379. * @brief Enable the RTC ALARMA peripheral.
  380. * @param __HANDLE__ specifies the RTC handle.
  381. * @retval None
  382. */
  383. #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE))
  384. /**
  385. * @brief Disable the RTC ALARMA peripheral.
  386. * @param __HANDLE__ specifies the RTC handle.
  387. * @retval None
  388. */
  389. #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE))
  390. /**
  391. * @brief Enable the RTC Alarm interrupt.
  392. * @param __HANDLE__ specifies the RTC handle.
  393. * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled.
  394. * This parameter can be any combination of the following values:
  395. * @arg RTC_IT_ALRA: Alarm A interrupt
  396. * @retval None
  397. */
  398. #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
  399. /**
  400. * @brief Disable the RTC Alarm interrupt.
  401. * @param __HANDLE__ specifies the RTC handle.
  402. * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled.
  403. * This parameter can be any combination of the following values:
  404. * @arg RTC_IT_ALRA: Alarm A interrupt
  405. * @retval None
  406. */
  407. #define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
  408. /**
  409. * @brief Check whether the specified RTC Alarm interrupt has occurred or not.
  410. * @param __HANDLE__ specifies the RTC handle.
  411. * @param __INTERRUPT__ specifies the RTC Alarm interrupt to check.
  412. * This parameter can be:
  413. * @arg RTC_IT_ALRA: Alarm A interrupt
  414. * @retval None
  415. */
  416. #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->ISR)& ((__INTERRUPT__)>> 4U)) != RESET)? SET : RESET)
  417. /**
  418. * @brief Check whether the specified RTC Alarm interrupt has been enabled or not.
  419. * @param __HANDLE__ specifies the RTC handle.
  420. * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check.
  421. * This parameter can be:
  422. * @arg RTC_IT_ALRA: Alarm A interrupt
  423. * @retval None
  424. */
  425. #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != RESET) ? SET : RESET)
  426. /**
  427. * @brief Get the selected RTC Alarm's flag status.
  428. * @param __HANDLE__ specifies the RTC handle.
  429. * @param __FLAG__ specifies the RTC Alarm Flag sources to check.
  430. * This parameter can be:
  431. * @arg RTC_FLAG_ALRAF
  432. * @arg RTC_FLAG_ALRAWF
  433. * @retval None
  434. */
  435. #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != RESET)? SET : RESET)
  436. /**
  437. * @brief Clear the RTC Alarm's pending flags.
  438. * @param __HANDLE__ specifies the RTC handle.
  439. * @param __FLAG__ specifies the RTC Alarm Flag sources to clear.
  440. * This parameter can be:
  441. * @arg RTC_FLAG_ALRAF
  442. * @retval None
  443. */
  444. #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT) | ((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
  445. /**
  446. * @brief Enable interrupt on the RTC Alarm associated Exti line.
  447. * @retval None
  448. */
  449. #define __HAL_RTC_ALARM_EXTI_ENABLE_IT() (EXTI->IMR |= RTC_EXTI_LINE_ALARM_EVENT)
  450. /**
  451. * @brief Disable interrupt on the RTC Alarm associated Exti line.
  452. * @retval None
  453. */
  454. #define __HAL_RTC_ALARM_EXTI_DISABLE_IT() (EXTI->IMR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  455. /**
  456. * @brief Enable event on the RTC Alarm associated Exti line.
  457. * @retval None.
  458. */
  459. #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT() (EXTI->EMR |= RTC_EXTI_LINE_ALARM_EVENT)
  460. /**
  461. * @brief Disable event on the RTC Alarm associated Exti line.
  462. * @retval None.
  463. */
  464. #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT() (EXTI->EMR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  465. /**
  466. * @brief Enable falling edge trigger on the RTC Alarm associated Exti line.
  467. * @retval None.
  468. */
  469. #define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE() (EXTI->FTSR |= RTC_EXTI_LINE_ALARM_EVENT)
  470. /**
  471. * @brief Disable falling edge trigger on the RTC Alarm associated Exti line.
  472. * @retval None.
  473. */
  474. #define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE() (EXTI->FTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  475. /**
  476. * @brief Enable rising edge trigger on the RTC Alarm associated Exti line.
  477. * @retval None.
  478. */
  479. #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE() (EXTI->RTSR |= RTC_EXTI_LINE_ALARM_EVENT)
  480. /**
  481. * @brief Disable rising edge trigger on the RTC Alarm associated Exti line.
  482. * @retval None.
  483. */
  484. #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE() (EXTI->RTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
  485. /**
  486. * @brief Enable rising & falling edge trigger on the RTC Alarm associated Exti line.
  487. * @retval None.
  488. */
  489. #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE() __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE();__HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE();
  490. /**
  491. * @brief Disable rising & falling edge trigger on the RTC Alarm associated Exti line.
  492. * @retval None.
  493. */
  494. #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE();__HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE();
  495. /**
  496. * @brief Check whether the RTC Alarm associated Exti line interrupt flag is set or not.
  497. * @retval Line Status.
  498. */
  499. #define __HAL_RTC_ALARM_EXTI_GET_FLAG() (EXTI->PR & RTC_EXTI_LINE_ALARM_EVENT)
  500. /**
  501. * @brief Clear the RTC Alarm associated Exti line flag.
  502. * @retval None.
  503. */
  504. #define __HAL_RTC_ALARM_EXTI_CLEAR_FLAG() (EXTI->PR = RTC_EXTI_LINE_ALARM_EVENT)
  505. /**
  506. * @brief Generate a Software interrupt on RTC Alarm associated Exti line.
  507. * @retval None.
  508. */
  509. #define __HAL_RTC_ALARM_EXTI_GENERATE_SWIT() (EXTI->SWIER |= RTC_EXTI_LINE_ALARM_EVENT)
  510. /**
  511. * @}
  512. */
  513. /* Include RTC HAL Extended module */
  514. #include "stm32f0xx_hal_rtc_ex.h"
  515. /* Exported functions --------------------------------------------------------*/
  516. /** @defgroup RTC_Exported_Functions RTC Exported Functions
  517. * @{
  518. */
  519. /** @defgroup RTC_Exported_Functions_Group1 Initialization and de-initialization functions
  520. * @{
  521. */
  522. /* Initialization and de-initialization functions ****************************/
  523. HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc);
  524. HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc);
  525. void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc);
  526. void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc);
  527. /**
  528. * @}
  529. */
  530. /** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions
  531. * @{
  532. */
  533. /* RTC Time and Date functions ************************************************/
  534. HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
  535. HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
  536. HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
  537. HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
  538. /**
  539. * @}
  540. */
  541. /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions
  542. * @{
  543. */
  544. /* RTC Alarm functions ********************************************************/
  545. HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
  546. HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
  547. HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm);
  548. HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format);
  549. void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc);
  550. HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
  551. void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc);
  552. /**
  553. * @}
  554. */
  555. /** @defgroup RTC_Exported_Functions_Group4 Peripheral Control functions
  556. * @{
  557. */
  558. /* Peripheral Control functions ***********************************************/
  559. HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef* hrtc);
  560. /**
  561. * @}
  562. */
  563. /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions
  564. * @{
  565. */
  566. /* Peripheral State functions *************************************************/
  567. HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc);
  568. /**
  569. * @}
  570. */
  571. /**
  572. * @}
  573. */
  574. /* Private types -------------------------------------------------------------*/
  575. /* Private variables ---------------------------------------------------------*/
  576. /* Private constants ---------------------------------------------------------*/
  577. /** @defgroup RTC_Private_Constants RTC Private Constants
  578. * @{
  579. */
  580. /* Masks Definition */
  581. #define RTC_TR_RESERVED_MASK 0x007F7F7FU
  582. #define RTC_DR_RESERVED_MASK 0x00FFFF3FU
  583. #define RTC_INIT_MASK 0xFFFFFFFFU
  584. #define RTC_RSF_MASK 0xFFFFFF5FU
  585. #define RTC_FLAGS_MASK ((uint32_t) (RTC_FLAG_RECALPF | RTC_FLAG_TAMP3F | RTC_FLAG_TAMP2F | \
  586. RTC_FLAG_TAMP1F| RTC_FLAG_TSOVF | RTC_FLAG_TSF | \
  587. RTC_FLAG_WUTF | RTC_FLAG_ALRAF | \
  588. RTC_FLAG_INITF | RTC_FLAG_RSF | RTC_FLAG_INITS | \
  589. RTC_FLAG_SHPF | RTC_FLAG_WUTWF | RTC_FLAG_ALRAWF))
  590. #define RTC_TIMEOUT_VALUE 1000U
  591. #define RTC_EXTI_LINE_ALARM_EVENT ((uint32_t)EXTI_IMR_MR17) /*!< External interrupt line 17 Connected to the RTC Alarm event */
  592. /**
  593. * @}
  594. */
  595. /* Private macros ------------------------------------------------------------*/
  596. /** @defgroup RTC_Private_Macros RTC Private Macros
  597. * @{
  598. */
  599. /** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters
  600. * @{
  601. */
  602. #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_HOURFORMAT_12) || \
  603. ((FORMAT) == RTC_HOURFORMAT_24))
  604. #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \
  605. ((POL) == RTC_OUTPUT_POLARITY_LOW))
  606. #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \
  607. ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL))
  608. #define IS_RTC_HOUR12(HOUR) (((HOUR) > 0U) && ((HOUR) <= 12U))
  609. #define IS_RTC_HOUR24(HOUR) ((HOUR) <= 23U)
  610. #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FU)
  611. #define IS_RTC_SYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FFFU)
  612. #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59U)
  613. #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59U)
  614. #define IS_RTC_HOURFORMAT12(PM) (((PM) == RTC_HOURFORMAT12_AM) || \
  615. ((PM) == RTC_HOURFORMAT12_PM))
  616. #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \
  617. ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \
  618. ((SAVE) == RTC_DAYLIGHTSAVING_NONE))
  619. #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \
  620. ((OPERATION) == RTC_STOREOPERATION_SET))
  621. #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || ((FORMAT) == RTC_FORMAT_BCD))
  622. #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99U)
  623. #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1U) && ((MONTH) <= 12U))
  624. #define IS_RTC_DATE(DATE) (((DATE) >= 1U) && ((DATE) <= 31U))
  625. #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \
  626. ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \
  627. ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
  628. ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \
  629. ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \
  630. ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \
  631. ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
  632. #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) > 0U) && ((DATE) <= 31U))
  633. #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \
  634. ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \
  635. ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
  636. ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \
  637. ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \
  638. ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \
  639. ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
  640. #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \
  641. ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY))
  642. #define IS_RTC_ALARM_MASK(MASK) (((MASK) & 0x7F7F7F7FU) == (uint32_t)RESET)
  643. #define IS_RTC_ALARM(ALARM) ((ALARM) == RTC_ALARM_A)
  644. #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= 0x00007FFFU)
  645. #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK) (((MASK) == RTC_ALARMSUBSECONDMASK_ALL) || \
  646. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_1) || \
  647. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_2) || \
  648. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_3) || \
  649. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_4) || \
  650. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_5) || \
  651. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_6) || \
  652. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_7) || \
  653. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_8) || \
  654. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_9) || \
  655. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_10) || \
  656. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_11) || \
  657. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_12) || \
  658. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_13) || \
  659. ((MASK) == RTC_ALARMSUBSECONDMASK_SS14) || \
  660. ((MASK) == RTC_ALARMSUBSECONDMASK_NONE))
  661. /**
  662. * @}
  663. */
  664. /**
  665. * @}
  666. */
  667. /* Private functions ---------------------------------------------------------*/
  668. /** @defgroup RTC_Private_Functions RTC Private Functions
  669. * @{
  670. */
  671. HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef* hrtc);
  672. uint8_t RTC_ByteToBcd2(uint8_t Value);
  673. uint8_t RTC_Bcd2ToByte(uint8_t Value);
  674. /**
  675. * @}
  676. */
  677. /**
  678. * @}
  679. */
  680. /**
  681. * @}
  682. */
  683. #ifdef __cplusplus
  684. }
  685. #endif
  686. #endif /* __STM32F0xx_HAL_RTC_H */
  687. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/