stm32f1xx_ll_rtc.h 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_ll_rtc.h
  4. * @author MCD Application Team
  5. * @brief Header file of RTC LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2016 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 __STM32F1xx_LL_RTC_H
  20. #define __STM32F1xx_LL_RTC_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32f1xx.h"
  26. /** @addtogroup STM32F1xx_LL_Driver
  27. * @{
  28. */
  29. #if defined(RTC)
  30. /** @defgroup RTC_LL RTC
  31. * @{
  32. */
  33. /* Private types -------------------------------------------------------------*/
  34. /* Private variables ---------------------------------------------------------*/
  35. /* Private constants ---------------------------------------------------------*/
  36. /* Private macros ------------------------------------------------------------*/
  37. #if defined(USE_FULL_LL_DRIVER)
  38. /** @defgroup RTC_LL_Private_Macros RTC Private Macros
  39. * @{
  40. */
  41. /**
  42. * @}
  43. */
  44. #endif /*USE_FULL_LL_DRIVER*/
  45. /* Exported types ------------------------------------------------------------*/
  46. #if defined(USE_FULL_LL_DRIVER)
  47. /** @defgroup RTC_LL_ES_INIT RTC Exported Init structure
  48. * @{
  49. */
  50. /**
  51. * @brief RTC Init structures definition
  52. */
  53. typedef struct
  54. {
  55. uint32_t AsynchPrescaler; /*!< Specifies the RTC Asynchronous Predivider value.
  56. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFFFFF
  57. This feature can be modified afterwards using unitary function
  58. @ref LL_RTC_SetAsynchPrescaler(). */
  59. uint32_t OutPutSource; /*!< Specifies which signal will be routed to the RTC Tamper pin.
  60. This parameter can be a value of @ref LL_RTC_Output_Source
  61. This feature can be modified afterwards using unitary function
  62. @ref LL_RTC_SetOutputSource(). */
  63. } LL_RTC_InitTypeDef;
  64. /**
  65. * @brief RTC Time structure definition
  66. */
  67. typedef struct
  68. {
  69. uint8_t Hours; /*!< Specifies the RTC Time Hours.
  70. This parameter must be a number between Min_Data = 0 and Max_Data = 23 */
  71. uint8_t Minutes; /*!< Specifies the RTC Time Minutes.
  72. This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
  73. uint8_t Seconds; /*!< Specifies the RTC Time Seconds.
  74. This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
  75. } LL_RTC_TimeTypeDef;
  76. /**
  77. * @brief RTC Alarm structure definition
  78. */
  79. typedef struct
  80. {
  81. LL_RTC_TimeTypeDef AlarmTime; /*!< Specifies the RTC Alarm Time members. */
  82. } LL_RTC_AlarmTypeDef;
  83. /**
  84. * @}
  85. */
  86. #endif /* USE_FULL_LL_DRIVER */
  87. /* Exported constants --------------------------------------------------------*/
  88. /** @defgroup RTC_LL_Exported_Constants RTC Exported Constants
  89. * @{
  90. */
  91. #if defined(USE_FULL_LL_DRIVER)
  92. /** @defgroup RTC_LL_EC_FORMAT FORMAT
  93. * @{
  94. */
  95. #define LL_RTC_FORMAT_BIN (0x000000000U) /*!< Binary data format */
  96. #define LL_RTC_FORMAT_BCD (0x000000001U) /*!< BCD data format */
  97. /**
  98. * @}
  99. */
  100. #endif /* USE_FULL_LL_DRIVER */
  101. /** @defgroup RTC_LL_EC_BKP BACKUP
  102. * @{
  103. */
  104. #if RTC_BKP_NUMBER > 0
  105. #define LL_RTC_BKP_DR1 (0x00000001U)
  106. #define LL_RTC_BKP_DR2 (0x00000002U)
  107. #define LL_RTC_BKP_DR3 (0x00000003U)
  108. #define LL_RTC_BKP_DR4 (0x00000004U)
  109. #define LL_RTC_BKP_DR5 (0x00000005U)
  110. #define LL_RTC_BKP_DR6 (0x00000006U)
  111. #define LL_RTC_BKP_DR7 (0x00000007U)
  112. #define LL_RTC_BKP_DR8 (0x00000008U)
  113. #define LL_RTC_BKP_DR9 (0x00000009U)
  114. #define LL_RTC_BKP_DR10 (0x0000000AU)
  115. #endif /* RTC_BKP_NUMBER > 0 */
  116. #if RTC_BKP_NUMBER > 10
  117. #define LL_RTC_BKP_DR11 (0x00000010U)
  118. #define LL_RTC_BKP_DR12 (0x00000011U)
  119. #define LL_RTC_BKP_DR13 (0x00000012U)
  120. #define LL_RTC_BKP_DR14 (0x00000013U)
  121. #define LL_RTC_BKP_DR15 (0x00000014U)
  122. #define LL_RTC_BKP_DR16 (0x00000015U)
  123. #define LL_RTC_BKP_DR17 (0x00000016U)
  124. #define LL_RTC_BKP_DR18 (0x00000017U)
  125. #define LL_RTC_BKP_DR19 (0x00000018U)
  126. #define LL_RTC_BKP_DR20 (0x00000019U)
  127. #define LL_RTC_BKP_DR21 (0x0000001AU)
  128. #define LL_RTC_BKP_DR22 (0x0000001BU)
  129. #define LL_RTC_BKP_DR23 (0x0000001CU)
  130. #define LL_RTC_BKP_DR24 (0x0000001DU)
  131. #define LL_RTC_BKP_DR25 (0x0000001EU)
  132. #define LL_RTC_BKP_DR26 (0x0000001FU)
  133. #define LL_RTC_BKP_DR27 (0x00000020U)
  134. #define LL_RTC_BKP_DR28 (0x00000021U)
  135. #define LL_RTC_BKP_DR29 (0x00000022U)
  136. #define LL_RTC_BKP_DR30 (0x00000023U)
  137. #define LL_RTC_BKP_DR31 (0x00000024U)
  138. #define LL_RTC_BKP_DR32 (0x00000025U)
  139. #define LL_RTC_BKP_DR33 (0x00000026U)
  140. #define LL_RTC_BKP_DR34 (0x00000027U)
  141. #define LL_RTC_BKP_DR35 (0x00000028U)
  142. #define LL_RTC_BKP_DR36 (0x00000029U)
  143. #define LL_RTC_BKP_DR37 (0x0000002AU)
  144. #define LL_RTC_BKP_DR38 (0x0000002BU)
  145. #define LL_RTC_BKP_DR39 (0x0000002CU)
  146. #define LL_RTC_BKP_DR40 (0x0000002DU)
  147. #define LL_RTC_BKP_DR41 (0x0000002EU)
  148. #define LL_RTC_BKP_DR42 (0x0000002FU)
  149. #endif /* RTC_BKP_NUMBER > 10 */
  150. /**
  151. * @}
  152. */
  153. /** @defgroup RTC_LL_EC_TAMPLEVEL Tamper Active Level
  154. * @{
  155. */
  156. #define LL_RTC_TAMPER_ACTIVELEVEL_LOW BKP_CR_TPAL /*!< A high level on the TAMPER pin resets all data backup registers (if TPE bit is set) */
  157. #define LL_RTC_TAMPER_ACTIVELEVEL_HIGH (0x00000000U) /*!< A low level on the TAMPER pin resets all data backup registers (if TPE bit is set) */
  158. /**
  159. * @}
  160. */
  161. /** @defgroup LL_RTC_Output_Source Clock Source to output on the Tamper Pin
  162. * @{
  163. */
  164. #define LL_RTC_CALIB_OUTPUT_NONE (0x00000000U) /*!< Calibration output disabled */
  165. #define LL_RTC_CALIB_OUTPUT_RTCCLOCK BKP_RTCCR_CCO /*!< Calibration output is RTC Clock with a frequency divided by 64 on the TAMPER Pin */
  166. #define LL_RTC_CALIB_OUTPUT_ALARM BKP_RTCCR_ASOE /*!< Calibration output is Alarm pulse signal on the TAMPER pin */
  167. #define LL_RTC_CALIB_OUTPUT_SECOND (BKP_RTCCR_ASOS | BKP_RTCCR_ASOE) /*!< Calibration output is Second pulse signal on the TAMPER pin*/
  168. /**
  169. * @}
  170. */
  171. /**
  172. * @}
  173. */
  174. /* Exported macro ------------------------------------------------------------*/
  175. /** @defgroup RTC_LL_Exported_Macros RTC Exported Macros
  176. * @{
  177. */
  178. /** @defgroup RTC_LL_EM_WRITE_READ Common Write and read registers Macros
  179. * @{
  180. */
  181. /**
  182. * @brief Write a value in RTC register
  183. * @param __INSTANCE__ RTC Instance
  184. * @param __REG__ Register to be written
  185. * @param __VALUE__ Value to be written in the register
  186. * @retval None
  187. */
  188. #define LL_RTC_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  189. /**
  190. * @brief Read a value in RTC register
  191. * @param __INSTANCE__ RTC Instance
  192. * @param __REG__ Register to be read
  193. * @retval Register value
  194. */
  195. #define LL_RTC_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  196. /**
  197. * @}
  198. */
  199. /** @defgroup RTC_LL_EM_Convert Convert helper Macros
  200. * @{
  201. */
  202. /**
  203. * @brief Helper macro to convert a value from 2 digit decimal format to BCD format
  204. * @param __VALUE__ Byte to be converted
  205. * @retval Converted byte
  206. */
  207. #define __LL_RTC_CONVERT_BIN2BCD(__VALUE__) (uint8_t)((((__VALUE__) / 10U) << 4U) | ((__VALUE__) % 10U))
  208. /**
  209. * @brief Helper macro to convert a value from BCD format to 2 digit decimal format
  210. * @param __VALUE__ BCD value to be converted
  211. * @retval Converted byte
  212. */
  213. #define __LL_RTC_CONVERT_BCD2BIN(__VALUE__) (uint8_t)(((uint8_t)((__VALUE__) & (uint8_t)0xF0U) >> (uint8_t)0x4U) * 10U + ((__VALUE__) & (uint8_t)0x0FU))
  214. /**
  215. * @}
  216. */
  217. /**
  218. * @}
  219. */
  220. /* Exported functions --------------------------------------------------------*/
  221. /** @defgroup RTC_LL_Exported_Functions RTC Exported Functions
  222. * @{
  223. */
  224. /** @defgroup RTC_LL_EF_Configuration Configuration
  225. * @{
  226. */
  227. /**
  228. * @brief Set Asynchronous prescaler factor
  229. * @rmtoll PRLH PRL LL_RTC_SetAsynchPrescaler\n
  230. * @rmtoll PRLL PRL LL_RTC_SetAsynchPrescaler\n
  231. * @param RTCx RTC Instance
  232. * @param AsynchPrescaler Value between Min_Data = 0 and Max_Data = 0xFFFFF
  233. * @retval None
  234. */
  235. __STATIC_INLINE void LL_RTC_SetAsynchPrescaler(RTC_TypeDef *RTCx, uint32_t AsynchPrescaler)
  236. {
  237. MODIFY_REG(RTCx->PRLH, RTC_PRLH_PRL, (AsynchPrescaler >> 16));
  238. MODIFY_REG(RTCx->PRLL, RTC_PRLL_PRL, (AsynchPrescaler & RTC_PRLL_PRL));
  239. }
  240. /**
  241. * @brief Get Asynchronous prescaler factor
  242. * @rmtoll DIVH DIV LL_RTC_GetDivider\n
  243. * @rmtoll DIVL DIV LL_RTC_GetDivider\n
  244. * @param RTCx RTC Instance
  245. * @retval Value between Min_Data = 0 and Max_Data = 0xFFFFF
  246. */
  247. __STATIC_INLINE uint32_t LL_RTC_GetDivider(RTC_TypeDef *RTCx)
  248. {
  249. register uint16_t Highprescaler = 0, Lowprescaler = 0;
  250. Highprescaler = READ_REG(RTCx->DIVH & RTC_DIVH_RTC_DIV);
  251. Lowprescaler = READ_REG(RTCx->DIVL & RTC_DIVL_RTC_DIV);
  252. return (((uint32_t) Highprescaler << 16U) | Lowprescaler);
  253. }
  254. /**
  255. * @brief Set Output Source
  256. * @rmtoll RTCCR CCO LL_RTC_SetOutputSource
  257. * @rmtoll RTCCR ASOE LL_RTC_SetOutputSource
  258. * @rmtoll RTCCR ASOS LL_RTC_SetOutputSource
  259. * @param BKPx BKP Instance
  260. * @param OutputSource This parameter can be one of the following values:
  261. * @arg @ref LL_RTC_CALIB_OUTPUT_NONE
  262. * @arg @ref LL_RTC_CALIB_OUTPUT_RTCCLOCK
  263. * @arg @ref LL_RTC_CALIB_OUTPUT_ALARM
  264. * @arg @ref LL_RTC_CALIB_OUTPUT_SECOND
  265. * @retval None
  266. */
  267. __STATIC_INLINE void LL_RTC_SetOutputSource(BKP_TypeDef *BKPx, uint32_t OutputSource)
  268. {
  269. MODIFY_REG(BKPx->RTCCR, (BKP_RTCCR_CCO | BKP_RTCCR_ASOE | BKP_RTCCR_ASOS), OutputSource);
  270. }
  271. /**
  272. * @brief Get Output Source
  273. * @rmtoll RTCCR CCO LL_RTC_GetOutPutSource
  274. * @rmtoll RTCCR ASOE LL_RTC_GetOutPutSource
  275. * @rmtoll RTCCR ASOS LL_RTC_GetOutPutSource
  276. * @param BKPx BKP Instance
  277. * @retval Returned value can be one of the following values:
  278. * @arg @ref LL_RTC_CALIB_OUTPUT_NONE
  279. * @arg @ref LL_RTC_CALIB_OUTPUT_RTCCLOCK
  280. * @arg @ref LL_RTC_CALIB_OUTPUT_ALARM
  281. * @arg @ref LL_RTC_CALIB_OUTPUT_SECOND
  282. */
  283. __STATIC_INLINE uint32_t LL_RTC_GetOutPutSource(BKP_TypeDef *BKPx)
  284. {
  285. return (uint32_t)(READ_BIT(BKPx->RTCCR, (BKP_RTCCR_CCO | BKP_RTCCR_ASOE | BKP_RTCCR_ASOS)));
  286. }
  287. /**
  288. * @brief Enable the write protection for RTC registers.
  289. * @rmtoll CRL CNF LL_RTC_EnableWriteProtection
  290. * @param RTCx RTC Instance
  291. * @retval None
  292. */
  293. __STATIC_INLINE void LL_RTC_EnableWriteProtection(RTC_TypeDef *RTCx)
  294. {
  295. CLEAR_BIT(RTCx->CRL, RTC_CRL_CNF);
  296. }
  297. /**
  298. * @brief Disable the write protection for RTC registers.
  299. * @rmtoll CRL RTC_CRL_CNF LL_RTC_DisableWriteProtection
  300. * @param RTCx RTC Instance
  301. * @retval None
  302. */
  303. __STATIC_INLINE void LL_RTC_DisableWriteProtection(RTC_TypeDef *RTCx)
  304. {
  305. SET_BIT(RTCx->CRL, RTC_CRL_CNF);
  306. }
  307. /**
  308. * @}
  309. */
  310. /** @defgroup RTC_LL_EF_Time Time
  311. * @{
  312. */
  313. /**
  314. * @brief Set time counter in BCD format
  315. * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
  316. * @note It can be written in initialization mode only (@ref LL_RTC_EnterInitMode function)
  317. * @rmtoll CNTH CNT LL_RTC_TIME_Set\n
  318. * CNTL CNT LL_RTC_TIME_Set\n
  319. * @param RTCx RTC Instance
  320. * @param TimeCounter Value between Min_Data=0x00 and Max_Data=0xFFFFF
  321. * @retval None
  322. */
  323. __STATIC_INLINE void LL_RTC_TIME_Set(RTC_TypeDef *RTCx, uint32_t TimeCounter)
  324. {
  325. /* Set RTC COUNTER MSB word */
  326. WRITE_REG(RTCx->CNTH, (TimeCounter >> 16U));
  327. /* Set RTC COUNTER LSB word */
  328. WRITE_REG(RTCx->CNTL, (TimeCounter & RTC_CNTL_RTC_CNT));
  329. }
  330. /**
  331. * @brief Get time counter in BCD format
  332. * @rmtoll CNTH CNT LL_RTC_TIME_Get\n
  333. * CNTL CNT LL_RTC_TIME_Get\n
  334. * @param RTCx RTC Instance
  335. * @retval Value between Min_Data = 0 and Max_Data = 0xFFFFF
  336. */
  337. __STATIC_INLINE uint32_t LL_RTC_TIME_Get(RTC_TypeDef *RTCx)
  338. {
  339. register uint16_t high = 0, low = 0;
  340. high = READ_REG(RTCx->CNTH & RTC_CNTH_RTC_CNT);
  341. low = READ_REG(RTCx->CNTL & RTC_CNTL_RTC_CNT);
  342. return ((uint32_t)(((uint32_t) high << 16U) | low));
  343. }
  344. /**
  345. * @}
  346. */
  347. /** @defgroup RTC_LL_EF_ALARM ALARM
  348. * @{
  349. */
  350. /**
  351. * @brief Set Alarm Counter
  352. * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
  353. * @rmtoll ALRH ALR LL_RTC_ALARM_Set\n
  354. * @rmtoll ALRL ALR LL_RTC_ALARM_Set\n
  355. * @param RTCx RTC Instance
  356. * @param AlarmCounter Value between Min_Data=0x00 and Max_Data=0xFFFFF
  357. * @retval None
  358. */
  359. __STATIC_INLINE void LL_RTC_ALARM_Set(RTC_TypeDef *RTCx, uint32_t AlarmCounter)
  360. {
  361. /* Set RTC COUNTER MSB word */
  362. WRITE_REG(RTCx->ALRH, (AlarmCounter >> 16));
  363. /* Set RTC COUNTER LSB word */
  364. WRITE_REG(RTCx->ALRL, (AlarmCounter & RTC_ALRL_RTC_ALR));
  365. }
  366. /**
  367. * @brief Get Alarm Counter
  368. * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
  369. * @rmtoll ALRH ALR LL_RTC_ALARM_Get\n
  370. * @rmtoll ALRL ALR LL_RTC_ALARM_Get\n
  371. * @param RTCx RTC Instance
  372. * @retval None
  373. */
  374. __STATIC_INLINE uint32_t LL_RTC_ALARM_Get(RTC_TypeDef *RTCx)
  375. {
  376. register uint16_t high = 0, low = 0;
  377. high = READ_REG(RTCx->ALRH & RTC_ALRH_RTC_ALR);
  378. low = READ_REG(RTCx->ALRL & RTC_ALRL_RTC_ALR);
  379. return (((uint32_t) high << 16U) | low);
  380. }
  381. /**
  382. * @}
  383. */
  384. /** @defgroup RTC_LL_EF_Tamper Tamper
  385. * @{
  386. */
  387. /**
  388. * @brief Enable RTC_TAMPx input detection
  389. * @rmtoll CR TPE LL_RTC_TAMPER_Enable\n
  390. * @retval None
  391. */
  392. __STATIC_INLINE void LL_RTC_TAMPER_Enable(BKP_TypeDef *BKPx)
  393. {
  394. SET_BIT(BKPx->CR, BKP_CR_TPE);
  395. }
  396. /**
  397. * @brief Disable RTC_TAMPx Tamper
  398. * @rmtoll CR TPE LL_RTC_TAMPER_Disable\n
  399. * @retval None
  400. */
  401. __STATIC_INLINE void LL_RTC_TAMPER_Disable(BKP_TypeDef *BKPx)
  402. {
  403. CLEAR_BIT(BKP->CR, BKP_CR_TPE);
  404. }
  405. /**
  406. * @brief Enable Active level for Tamper input
  407. * @rmtoll CR TPAL LL_RTC_TAMPER_SetActiveLevel\n
  408. * @param BKPx BKP Instance
  409. * @param Tamper This parameter can be a combination of the following values:
  410. * @arg @ref LL_RTC_TAMPER_ACTIVELEVEL_LOW
  411. * @arg @ref LL_RTC_TAMPER_ACTIVELEVEL_HIGH
  412. * @retval None
  413. */
  414. __STATIC_INLINE void LL_RTC_TAMPER_SetActiveLevel(BKP_TypeDef *BKPx, uint32_t Tamper)
  415. {
  416. MODIFY_REG(BKPx->CR, BKP_CR_TPAL, Tamper);
  417. }
  418. /**
  419. * @brief Disable Active level for Tamper input
  420. * @rmtoll CR TPAL LL_RTC_TAMPER_SetActiveLevel\n
  421. * @retval None
  422. */
  423. __STATIC_INLINE uint32_t LL_RTC_TAMPER_GetActiveLevel(BKP_TypeDef *BKPx)
  424. {
  425. return (uint32_t)(READ_BIT(BKPx->CR, BKP_CR_TPAL));
  426. }
  427. /**
  428. * @}
  429. */
  430. /** @defgroup RTC_LL_EF_Backup_Registers Backup_Registers
  431. * @{
  432. */
  433. /**
  434. * @brief Writes a data in a specified RTC Backup data register.
  435. * @rmtoll BKPDR DR LL_RTC_BKP_SetRegister
  436. * @param BKPx BKP Instance
  437. * @param BackupRegister This parameter can be one of the following values:
  438. * @arg @ref LL_RTC_BKP_DR1
  439. * @arg @ref LL_RTC_BKP_DR2
  440. * @arg @ref LL_RTC_BKP_DR3
  441. * @arg @ref LL_RTC_BKP_DR4
  442. * @arg @ref LL_RTC_BKP_DR5
  443. * @arg @ref LL_RTC_BKP_DR6
  444. * @arg @ref LL_RTC_BKP_DR7
  445. * @arg @ref LL_RTC_BKP_DR8
  446. * @arg @ref LL_RTC_BKP_DR9
  447. * @arg @ref LL_RTC_BKP_DR10
  448. * @arg @ref LL_RTC_BKP_DR11 (*)
  449. * @arg @ref LL_RTC_BKP_DR12 (*)
  450. * @arg @ref LL_RTC_BKP_DR13 (*)
  451. * @arg @ref LL_RTC_BKP_DR14 (*)
  452. * @arg @ref LL_RTC_BKP_DR15 (*)
  453. * @arg @ref LL_RTC_BKP_DR16 (*)
  454. * @arg @ref LL_RTC_BKP_DR17 (*)
  455. * @arg @ref LL_RTC_BKP_DR18 (*)
  456. * @arg @ref LL_RTC_BKP_DR19 (*)
  457. * @arg @ref LL_RTC_BKP_DR20 (*)
  458. * @arg @ref LL_RTC_BKP_DR21 (*)
  459. * @arg @ref LL_RTC_BKP_DR22 (*)
  460. * @arg @ref LL_RTC_BKP_DR23 (*)
  461. * @arg @ref LL_RTC_BKP_DR24 (*)
  462. * @arg @ref LL_RTC_BKP_DR25 (*)
  463. * @arg @ref LL_RTC_BKP_DR26 (*)
  464. * @arg @ref LL_RTC_BKP_DR27 (*)
  465. * @arg @ref LL_RTC_BKP_DR28 (*)
  466. * @arg @ref LL_RTC_BKP_DR29 (*)
  467. * @arg @ref LL_RTC_BKP_DR30 (*)
  468. * @arg @ref LL_RTC_BKP_DR31 (*)
  469. * @arg @ref LL_RTC_BKP_DR32 (*)
  470. * @arg @ref LL_RTC_BKP_DR33 (*)
  471. * @arg @ref LL_RTC_BKP_DR34 (*)
  472. * @arg @ref LL_RTC_BKP_DR35 (*)
  473. * @arg @ref LL_RTC_BKP_DR36 (*)
  474. * @arg @ref LL_RTC_BKP_DR37 (*)
  475. * @arg @ref LL_RTC_BKP_DR38 (*)
  476. * @arg @ref LL_RTC_BKP_DR39 (*)
  477. * @arg @ref LL_RTC_BKP_DR40 (*)
  478. * @arg @ref LL_RTC_BKP_DR41 (*)
  479. * @arg @ref LL_RTC_BKP_DR42 (*)
  480. * (*) value not defined in all devices.
  481. * @param Data Value between Min_Data=0x00 and Max_Data=0xFFFFFFFF
  482. * @retval None
  483. */
  484. __STATIC_INLINE void LL_RTC_BKP_SetRegister(BKP_TypeDef *BKPx, uint32_t BackupRegister, uint32_t Data)
  485. {
  486. register uint32_t tmp = 0U;
  487. tmp = (uint32_t)BKP_BASE;
  488. tmp += (BackupRegister * 4U);
  489. /* Write the specified register */
  490. *(__IO uint32_t *)tmp = (uint32_t)Data;
  491. }
  492. /**
  493. * @brief Reads data from the specified RTC Backup data Register.
  494. * @rmtoll BKPDR DR LL_RTC_BKP_GetRegister
  495. * @param BKPx BKP Instance
  496. * @param BackupRegister This parameter can be one of the following values:
  497. * @arg @ref LL_RTC_BKP_DR1
  498. * @arg @ref LL_RTC_BKP_DR2
  499. * @arg @ref LL_RTC_BKP_DR3
  500. * @arg @ref LL_RTC_BKP_DR4
  501. * @arg @ref LL_RTC_BKP_DR5
  502. * @arg @ref LL_RTC_BKP_DR6
  503. * @arg @ref LL_RTC_BKP_DR7
  504. * @arg @ref LL_RTC_BKP_DR8
  505. * @arg @ref LL_RTC_BKP_DR9
  506. * @arg @ref LL_RTC_BKP_DR10
  507. * @arg @ref LL_RTC_BKP_DR11 (*)
  508. * @arg @ref LL_RTC_BKP_DR12 (*)
  509. * @arg @ref LL_RTC_BKP_DR13 (*)
  510. * @arg @ref LL_RTC_BKP_DR14 (*)
  511. * @arg @ref LL_RTC_BKP_DR15 (*)
  512. * @arg @ref LL_RTC_BKP_DR16 (*)
  513. * @arg @ref LL_RTC_BKP_DR17 (*)
  514. * @arg @ref LL_RTC_BKP_DR18 (*)
  515. * @arg @ref LL_RTC_BKP_DR19 (*)
  516. * @arg @ref LL_RTC_BKP_DR20 (*)
  517. * @arg @ref LL_RTC_BKP_DR21 (*)
  518. * @arg @ref LL_RTC_BKP_DR22 (*)
  519. * @arg @ref LL_RTC_BKP_DR23 (*)
  520. * @arg @ref LL_RTC_BKP_DR24 (*)
  521. * @arg @ref LL_RTC_BKP_DR25 (*)
  522. * @arg @ref LL_RTC_BKP_DR26 (*)
  523. * @arg @ref LL_RTC_BKP_DR27 (*)
  524. * @arg @ref LL_RTC_BKP_DR28 (*)
  525. * @arg @ref LL_RTC_BKP_DR29 (*)
  526. * @arg @ref LL_RTC_BKP_DR30 (*)
  527. * @arg @ref LL_RTC_BKP_DR31 (*)
  528. * @arg @ref LL_RTC_BKP_DR32 (*)
  529. * @arg @ref LL_RTC_BKP_DR33 (*)
  530. * @arg @ref LL_RTC_BKP_DR34 (*)
  531. * @arg @ref LL_RTC_BKP_DR35 (*)
  532. * @arg @ref LL_RTC_BKP_DR36 (*)
  533. * @arg @ref LL_RTC_BKP_DR37 (*)
  534. * @arg @ref LL_RTC_BKP_DR38 (*)
  535. * @arg @ref LL_RTC_BKP_DR39 (*)
  536. * @arg @ref LL_RTC_BKP_DR40 (*)
  537. * @arg @ref LL_RTC_BKP_DR41 (*)
  538. * @arg @ref LL_RTC_BKP_DR42 (*)
  539. * @retval Value between Min_Data=0x00 and Max_Data=0xFFFFFFFF
  540. */
  541. __STATIC_INLINE uint32_t LL_RTC_BKP_GetRegister(BKP_TypeDef *BKPx, uint32_t BackupRegister)
  542. {
  543. register uint32_t tmp = 0U;
  544. tmp = (uint32_t)BKP_BASE;
  545. tmp += (BackupRegister * 4U);
  546. /* Read the specified register */
  547. return ((*(__IO uint32_t *)tmp) & BKP_DR1_D);
  548. }
  549. /**
  550. * @}
  551. */
  552. /** @defgroup RTC_LL_EF_Calibration Calibration
  553. * @{
  554. */
  555. /**
  556. * @brief Set the coarse digital calibration
  557. * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
  558. * @note It can be written in initialization mode only (@ref LL_RTC_EnterInitMode function)
  559. * @rmtoll RTCCR CAL LL_RTC_CAL_SetCoarseDigital\n
  560. * @param BKPx RTC Instance
  561. * @param Value value of coarse calibration expressed in ppm (coded on 5 bits)
  562. * @note This Calibration value should be between 0 and 121 when using positive sign with a 4-ppm step.
  563. * @retval None
  564. */
  565. __STATIC_INLINE void LL_RTC_CAL_SetCoarseDigital(BKP_TypeDef *BKPx, uint32_t Value)
  566. {
  567. MODIFY_REG(BKPx->RTCCR, BKP_RTCCR_CAL, Value);
  568. }
  569. /**
  570. * @brief Get the coarse digital calibration value
  571. * @rmtoll RTCCR CAL LL_RTC_CAL_SetCoarseDigital\n
  572. * @param BKPx BKP Instance
  573. * @retval value of coarse calibration expressed in ppm (coded on 5 bits)
  574. */
  575. __STATIC_INLINE uint32_t LL_RTC_CAL_GetCoarseDigital(BKP_TypeDef *BKPx)
  576. {
  577. return (uint32_t)(READ_BIT(BKPx->RTCCR, BKP_RTCCR_CAL));
  578. }
  579. /**
  580. * @}
  581. */
  582. /** @defgroup RTC_LL_EF_FLAG_Management FLAG_Management
  583. * @{
  584. */
  585. /**
  586. * @brief Get RTC_TAMPI Interruption detection flag
  587. * @rmtoll CSR TIF LL_RTC_IsActiveFlag_TAMPI
  588. * @param BKPx BKP Instance
  589. * @retval State of bit (1 or 0).
  590. */
  591. __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_TAMPI(BKP_TypeDef *BKPx)
  592. {
  593. return (READ_BIT(BKPx->CSR, BKP_CSR_TIF) == (BKP_CSR_TIF));
  594. }
  595. /**
  596. * @brief Clear RTC_TAMP Interruption detection flag
  597. * @rmtoll CSR CTI LL_RTC_ClearFlag_TAMPI
  598. * @param BKPx BKP Instance
  599. * @retval None
  600. */
  601. __STATIC_INLINE void LL_RTC_ClearFlag_TAMPI(BKP_TypeDef *BKPx)
  602. {
  603. SET_BIT(BKPx->CSR, BKP_CSR_CTI);
  604. }
  605. /**
  606. * @brief Get RTC_TAMPE Event detection flag
  607. * @rmtoll CSR TEF LL_RTC_IsActiveFlag_TAMPE
  608. * @param BKPx BKP Instance
  609. * @retval State of bit (1 or 0).
  610. */
  611. __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_TAMPE(BKP_TypeDef *BKPx)
  612. {
  613. return (READ_BIT(BKPx->CSR, BKP_CSR_TEF) == (BKP_CSR_TEF));
  614. }
  615. /**
  616. * @brief Clear RTC_TAMPE Even detection flag
  617. * @rmtoll CSR CTE LL_RTC_ClearFlag_TAMPE
  618. * @param BKPx BKP Instance
  619. * @retval None
  620. */
  621. __STATIC_INLINE void LL_RTC_ClearFlag_TAMPE(BKP_TypeDef *BKPx)
  622. {
  623. SET_BIT(BKPx->CSR, BKP_CSR_CTE);
  624. }
  625. /**
  626. * @brief Get Alarm flag
  627. * @rmtoll CRL ALRF LL_RTC_IsActiveFlag_ALR
  628. * @param RTCx RTC Instance
  629. * @retval State of bit (1 or 0).
  630. */
  631. __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_ALR(RTC_TypeDef *RTCx)
  632. {
  633. return (READ_BIT(RTCx->CRL, RTC_CRL_ALRF) == (RTC_CRL_ALRF));
  634. }
  635. /**
  636. * @brief Clear Alarm flag
  637. * @rmtoll CRL ALRF LL_RTC_ClearFlag_ALR
  638. * @param RTCx RTC Instance
  639. * @retval None
  640. */
  641. __STATIC_INLINE void LL_RTC_ClearFlag_ALR(RTC_TypeDef *RTCx)
  642. {
  643. CLEAR_BIT(RTCx->CRL, RTC_CRL_ALRF);
  644. }
  645. /**
  646. * @brief Get Registers synchronization flag
  647. * @rmtoll CRL RSF LL_RTC_IsActiveFlag_RS
  648. * @param RTCx RTC Instance
  649. * @retval State of bit (1 or 0).
  650. */
  651. __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_RS(RTC_TypeDef *RTCx)
  652. {
  653. return (READ_BIT(RTCx->CRL, RTC_CRL_RSF) == (RTC_CRL_RSF));
  654. }
  655. /**
  656. * @brief Clear Registers synchronization flag
  657. * @rmtoll CRL RSF LL_RTC_ClearFlag_RS
  658. * @param RTCx RTC Instance
  659. * @retval None
  660. */
  661. __STATIC_INLINE void LL_RTC_ClearFlag_RS(RTC_TypeDef *RTCx)
  662. {
  663. CLEAR_BIT(RTCx->CRL, RTC_CRL_RSF);
  664. }
  665. /**
  666. * @brief Get Registers OverFlow flag
  667. * @rmtoll CRL OWF LL_RTC_IsActiveFlag_OW
  668. * @param RTCx RTC Instance
  669. * @retval State of bit (1 or 0).
  670. */
  671. __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_OW(RTC_TypeDef *RTCx)
  672. {
  673. return (READ_BIT(RTCx->CRL, RTC_CRL_OWF) == (RTC_CRL_OWF));
  674. }
  675. /**
  676. * @brief Clear Registers OverFlow flag
  677. * @rmtoll CRL OWF LL_RTC_ClearFlag_OW
  678. * @param RTCx RTC Instance
  679. * @retval None
  680. */
  681. __STATIC_INLINE void LL_RTC_ClearFlag_OW(RTC_TypeDef *RTCx)
  682. {
  683. CLEAR_BIT(RTCx->CRL, RTC_CRL_OWF);
  684. }
  685. /**
  686. * @brief Get Registers synchronization flag
  687. * @rmtoll CRL SECF LL_RTC_IsActiveFlag_SEC
  688. * @param RTCx RTC Instance
  689. * @retval State of bit (1 or 0).
  690. */
  691. __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_SEC(RTC_TypeDef *RTCx)
  692. {
  693. return (READ_BIT(RTCx->CRL, RTC_CRL_SECF) == (RTC_CRL_SECF));
  694. }
  695. /**
  696. * @brief Clear Registers synchronization flag
  697. * @rmtoll CRL SECF LL_RTC_ClearFlag_SEC
  698. * @param RTCx RTC Instance
  699. * @retval None
  700. */
  701. __STATIC_INLINE void LL_RTC_ClearFlag_SEC(RTC_TypeDef *RTCx)
  702. {
  703. CLEAR_BIT(RTCx->CRL, RTC_CRL_SECF);
  704. }
  705. /**
  706. * @brief Get RTC Operation OFF status flag
  707. * @rmtoll CRL RTOFF LL_RTC_IsActiveFlag_RTOF
  708. * @param RTCx RTC Instance
  709. * @retval State of bit (1 or 0).
  710. */
  711. __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_RTOF(RTC_TypeDef *RTCx)
  712. {
  713. return (READ_BIT(RTCx->CRL, RTC_CRL_RTOFF) == (RTC_CRL_RTOFF));
  714. }
  715. /**
  716. * @}
  717. */
  718. /** @defgroup RTC_LL_EF_IT_Management IT_Management
  719. * @{
  720. */
  721. /**
  722. * @brief Enable Alarm interrupt
  723. * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
  724. * @rmtoll CRH ALRIE LL_RTC_EnableIT_ALR
  725. * @param RTCx RTC Instance
  726. * @retval None
  727. */
  728. __STATIC_INLINE void LL_RTC_EnableIT_ALR(RTC_TypeDef *RTCx)
  729. {
  730. SET_BIT(RTCx->CRH, RTC_CRH_ALRIE);
  731. }
  732. /**
  733. * @brief Disable Alarm interrupt
  734. * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
  735. * @rmtoll CRH ALRIE LL_RTC_DisableIT_ALR
  736. * @param RTCx RTC Instance
  737. * @retval None
  738. */
  739. __STATIC_INLINE void LL_RTC_DisableIT_ALR(RTC_TypeDef *RTCx)
  740. {
  741. CLEAR_BIT(RTCx->CRH, RTC_CRH_ALRIE);
  742. }
  743. /**
  744. * @brief Check if Alarm interrupt is enabled or not
  745. * @rmtoll CRH ALRIE LL_RTC_IsEnabledIT_ALR
  746. * @param RTCx RTC Instance
  747. * @retval State of bit (1 or 0).
  748. */
  749. __STATIC_INLINE uint32_t LL_RTC_IsEnabledIT_ALR(RTC_TypeDef *RTCx)
  750. {
  751. return (READ_BIT(RTCx->CRH, RTC_CRH_ALRIE) == (RTC_CRH_ALRIE));
  752. }
  753. /**
  754. * @brief Enable Second Interrupt interrupt
  755. * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
  756. * @rmtoll CRH SECIE LL_RTC_EnableIT_SEC
  757. * @param RTCx RTC Instance
  758. * @retval None
  759. */
  760. __STATIC_INLINE void LL_RTC_EnableIT_SEC(RTC_TypeDef *RTCx)
  761. {
  762. SET_BIT(RTCx->CRH, RTC_CRH_SECIE);
  763. }
  764. /**
  765. * @brief Disable Second interrupt
  766. * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
  767. * @rmtoll CRH SECIE LL_RTC_DisableIT_SEC
  768. * @param RTCx RTC Instance
  769. * @retval None
  770. */
  771. __STATIC_INLINE void LL_RTC_DisableIT_SEC(RTC_TypeDef *RTCx)
  772. {
  773. CLEAR_BIT(RTCx->CRH, RTC_CRH_SECIE);
  774. }
  775. /**
  776. * @brief Check if Second interrupt is enabled or not
  777. * @rmtoll CRH SECIE LL_RTC_IsEnabledIT_SEC
  778. * @param RTCx RTC Instance
  779. * @retval State of bit (1 or 0).
  780. */
  781. __STATIC_INLINE uint32_t LL_RTC_IsEnabledIT_SEC(RTC_TypeDef *RTCx)
  782. {
  783. return (READ_BIT(RTCx->CRH, RTC_CRH_SECIE) == (RTC_CRH_SECIE));
  784. }
  785. /**
  786. * @brief Enable OverFlow interrupt
  787. * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
  788. * @rmtoll CRH OWIE LL_RTC_EnableIT_OW
  789. * @param RTCx RTC Instance
  790. * @retval None
  791. */
  792. __STATIC_INLINE void LL_RTC_EnableIT_OW(RTC_TypeDef *RTCx)
  793. {
  794. SET_BIT(RTCx->CRH, RTC_CRH_OWIE);
  795. }
  796. /**
  797. * @brief Disable OverFlow interrupt
  798. * @note Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
  799. * @rmtoll CRH OWIE LL_RTC_DisableIT_OW
  800. * @param RTCx RTC Instance
  801. * @retval None
  802. */
  803. __STATIC_INLINE void LL_RTC_DisableIT_OW(RTC_TypeDef *RTCx)
  804. {
  805. CLEAR_BIT(RTCx->CRH, RTC_CRH_OWIE);
  806. }
  807. /**
  808. * @brief Check if OverFlow interrupt is enabled or not
  809. * @rmtoll CRH OWIE LL_RTC_IsEnabledIT_OW
  810. * @param RTCx RTC Instance
  811. * @retval State of bit (1 or 0).
  812. */
  813. __STATIC_INLINE uint32_t LL_RTC_IsEnabledIT_OW(RTC_TypeDef *RTCx)
  814. {
  815. return (READ_BIT(RTCx->CRH, RTC_CRH_OWIE) == (RTC_CRH_OWIE));
  816. }
  817. /**
  818. * @brief Enable Tamper interrupt
  819. * @rmtoll CSR TPIE LL_RTC_EnableIT_TAMP
  820. * @param BKPx BKP Instance
  821. * @retval None
  822. */
  823. __STATIC_INLINE void LL_RTC_EnableIT_TAMP(BKP_TypeDef *BKPx)
  824. {
  825. SET_BIT(BKPx->CSR, BKP_CSR_TPIE);
  826. }
  827. /**
  828. * @brief Disable Tamper interrupt
  829. * @rmtoll CSR TPIE LL_RTC_EnableIT_TAMP
  830. * @param BKPx BKP Instance
  831. * @retval None
  832. */
  833. __STATIC_INLINE void LL_RTC_DisableIT_TAMP(BKP_TypeDef *BKPx)
  834. {
  835. CLEAR_BIT(BKPx->CSR, BKP_CSR_TPIE);
  836. }
  837. /**
  838. * @brief Check if all the TAMPER interrupts are enabled or not
  839. * @rmtoll CSR TPIE LL_RTC_IsEnabledIT_TAMP
  840. * @param BKPx BKP Instance
  841. * @retval State of bit (1 or 0).
  842. */
  843. __STATIC_INLINE uint32_t LL_RTC_IsEnabledIT_TAMP(BKP_TypeDef *BKPx)
  844. {
  845. return (READ_BIT(BKPx->CSR, BKP_CSR_TPIE) == BKP_CSR_TPIE);
  846. }
  847. /**
  848. * @}
  849. */
  850. #if defined(USE_FULL_LL_DRIVER)
  851. /** @defgroup RTC_LL_EF_Init Initialization and de-initialization functions
  852. * @{
  853. */
  854. ErrorStatus LL_RTC_DeInit(RTC_TypeDef *RTCx);
  855. ErrorStatus LL_RTC_Init(RTC_TypeDef *RTCx, LL_RTC_InitTypeDef *RTC_InitStruct);
  856. void LL_RTC_StructInit(LL_RTC_InitTypeDef *RTC_InitStruct);
  857. ErrorStatus LL_RTC_TIME_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_TimeTypeDef *RTC_TimeStruct);
  858. void LL_RTC_TIME_StructInit(LL_RTC_TimeTypeDef *RTC_TimeStruct);
  859. ErrorStatus LL_RTC_ALARM_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_AlarmTypeDef *RTC_AlarmStruct);
  860. void LL_RTC_ALARM_StructInit(LL_RTC_AlarmTypeDef *RTC_AlarmStruct);
  861. ErrorStatus LL_RTC_EnterInitMode(RTC_TypeDef *RTCx);
  862. ErrorStatus LL_RTC_ExitInitMode(RTC_TypeDef *RTCx);
  863. ErrorStatus LL_RTC_WaitForSynchro(RTC_TypeDef *RTCx);
  864. ErrorStatus LL_RTC_TIME_SetCounter(RTC_TypeDef *RTCx, uint32_t TimeCounter);
  865. ErrorStatus LL_RTC_ALARM_SetCounter(RTC_TypeDef *RTCx, uint32_t AlarmCounter);
  866. /**
  867. * @}
  868. */
  869. #endif /* USE_FULL_LL_DRIVER */
  870. /**
  871. * @}
  872. */
  873. /**
  874. * @}
  875. */
  876. /**
  877. * @}
  878. */
  879. #endif /* defined(RTC) */
  880. /**
  881. * @}
  882. */
  883. #ifdef __cplusplus
  884. }
  885. #endif
  886. #endif /* __STM32F1xx_LL_RTC_H */