stm32f1xx_ll_rtc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_ll_rtc.c
  4. * @author MCD Application Team
  5. * @brief RTC LL module driver.
  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. #if defined(USE_FULL_LL_DRIVER)
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "stm32f1xx_ll_rtc.h"
  38. #include "stm32f1xx_ll_cortex.h"
  39. #ifdef USE_FULL_ASSERT
  40. #include "stm32_assert.h"
  41. #else
  42. #define assert_param(expr) ((void)0U)
  43. #endif
  44. /** @addtogroup STM32F1xx_LL_Driver
  45. * @{
  46. */
  47. #if defined(RTC)
  48. /** @addtogroup RTC_LL
  49. * @{
  50. */
  51. /* Private types -------------------------------------------------------------*/
  52. /* Private variables ---------------------------------------------------------*/
  53. /* Private constants ---------------------------------------------------------*/
  54. /** @addtogroup RTC_LL_Private_Constants
  55. * @{
  56. */
  57. /* Default values used for prescaler */
  58. #define RTC_ASYNCH_PRESC_DEFAULT 0x00007FFFU
  59. /* Values used for timeout */
  60. #define RTC_INITMODE_TIMEOUT 1000U /* 1s when tick set to 1ms */
  61. #define RTC_SYNCHRO_TIMEOUT 1000U /* 1s when tick set to 1ms */
  62. /**
  63. * @}
  64. */
  65. /* Private macros ------------------------------------------------------------*/
  66. /** @addtogroup RTC_LL_Private_Macros
  67. * @{
  68. */
  69. #define IS_LL_RTC_ASYNCH_PREDIV(__VALUE__) ((__VALUE__) <= 0xFFFFFU)
  70. #define IS_LL_RTC_FORMAT(__VALUE__) (((__VALUE__) == LL_RTC_FORMAT_BIN) \
  71. || ((__VALUE__) == LL_RTC_FORMAT_BCD))
  72. #define IS_LL_RTC_HOUR24(__HOUR__) ((__HOUR__) <= 23U)
  73. #define IS_LL_RTC_MINUTES(__MINUTES__) ((__MINUTES__) <= 59U)
  74. #define IS_LL_RTC_SECONDS(__SECONDS__) ((__SECONDS__) <= 59U)
  75. #define IS_LL_RTC_CALIB_OUTPUT(__OUTPUT__) (((__OUTPUT__) == LL_RTC_CALIB_OUTPUT_NONE) || \
  76. ((__OUTPUT__) == LL_RTC_CALIB_OUTPUT_RTCCLOCK) || \
  77. ((__OUTPUT__) == LL_RTC_CALIB_OUTPUT_ALARM) || \
  78. ((__OUTPUT__) == LL_RTC_CALIB_OUTPUT_SECOND))
  79. /**
  80. * @}
  81. */
  82. /* Private function prototypes -----------------------------------------------*/
  83. /* Exported functions --------------------------------------------------------*/
  84. /** @addtogroup RTC_LL_Exported_Functions
  85. * @{
  86. */
  87. /** @addtogroup RTC_LL_EF_Init
  88. * @{
  89. */
  90. /**
  91. * @brief De-Initializes the RTC registers to their default reset values.
  92. * @note This function doesn't reset the RTC Clock source and RTC Backup Data
  93. * registers.
  94. * @param RTCx RTC Instance
  95. * @retval An ErrorStatus enumeration value:
  96. * - SUCCESS: RTC registers are de-initialized
  97. * - ERROR: RTC registers are not de-initialized
  98. */
  99. ErrorStatus LL_RTC_DeInit(RTC_TypeDef *RTCx)
  100. {
  101. ErrorStatus status = ERROR;
  102. /* Check the parameter */
  103. assert_param(IS_RTC_ALL_INSTANCE(RTCx));
  104. /* Disable the write protection for RTC registers */
  105. LL_RTC_DisableWriteProtection(RTCx);
  106. /* Set Initialization mode */
  107. if (LL_RTC_EnterInitMode(RTCx) != ERROR)
  108. {
  109. LL_RTC_WriteReg(RTCx,CNTL, 0x0000);
  110. LL_RTC_WriteReg(RTCx,CNTH, 0x0000);
  111. LL_RTC_WriteReg(RTCx,PRLH, 0x0000);
  112. LL_RTC_WriteReg(RTCx,PRLL, 0x8000);
  113. LL_RTC_WriteReg(RTCx,CRH, 0x0000);
  114. LL_RTC_WriteReg(RTCx,CRL, 0x0020);
  115. /* Reset Tamper and alternate functions configuration register */
  116. LL_RTC_WriteReg(BKP,RTCCR, 0x00000000U);
  117. LL_RTC_WriteReg(BKP,CR, 0x00000000U);
  118. LL_RTC_WriteReg(BKP,CSR, 0x00000000U);
  119. /* Exit Initialization Mode */
  120. if(LL_RTC_ExitInitMode(RTCx) == ERROR)
  121. {
  122. return ERROR;
  123. }
  124. /* Wait till the RTC RSF flag is set */
  125. status = LL_RTC_WaitForSynchro(RTCx);
  126. /* Clear RSF Flag */
  127. LL_RTC_ClearFlag_RS(RTCx);
  128. }
  129. /* Enable the write protection for RTC registers */
  130. LL_RTC_EnableWriteProtection(RTCx);
  131. return status;
  132. }
  133. /**
  134. * @brief Initializes the RTC registers according to the specified parameters
  135. * in RTC_InitStruct.
  136. * @param RTCx RTC Instance
  137. * @param RTC_InitStruct pointer to a @ref LL_RTC_InitTypeDef structure that contains
  138. * the configuration information for the RTC peripheral.
  139. * @note The RTC Prescaler register is write protected and can be written in
  140. * initialization mode only.
  141. * @note the user should call LL_RTC_StructInit() or the structure of Prescaler
  142. * need to be initialized before RTC init()
  143. * @retval An ErrorStatus enumeration value:
  144. * - SUCCESS: RTC registers are initialized
  145. * - ERROR: RTC registers are not initialized
  146. */
  147. ErrorStatus LL_RTC_Init(RTC_TypeDef *RTCx, LL_RTC_InitTypeDef *RTC_InitStruct)
  148. {
  149. ErrorStatus status = ERROR;
  150. /* Check the parameters */
  151. assert_param(IS_RTC_ALL_INSTANCE(RTCx));
  152. assert_param(IS_LL_RTC_ASYNCH_PREDIV(RTC_InitStruct->AsynchPrescaler));
  153. assert_param(IS_LL_RTC_CALIB_OUTPUT(RTC_InitStruct->OutPutSource));
  154. /* Waiting for synchro */
  155. if(LL_RTC_WaitForSynchro(RTCx) != ERROR)
  156. {
  157. /* Set Initialization mode */
  158. if (LL_RTC_EnterInitMode(RTCx) != ERROR)
  159. {
  160. /* Clear Flag Bits */
  161. LL_RTC_ClearFlag_ALR(RTCx);
  162. LL_RTC_ClearFlag_OW(RTCx);
  163. LL_RTC_ClearFlag_SEC(RTCx);
  164. if(RTC_InitStruct->OutPutSource != LL_RTC_CALIB_OUTPUT_NONE)
  165. {
  166. /* Disable the selected Tamper Pin */
  167. LL_RTC_TAMPER_Disable(BKP);
  168. }
  169. /* Set the signal which will be routed to RTC Tamper Pin */
  170. LL_RTC_SetOutputSource(BKP, RTC_InitStruct->OutPutSource);
  171. /* Configure Synchronous and Asynchronous prescaler factor */
  172. LL_RTC_SetAsynchPrescaler(RTCx, RTC_InitStruct->AsynchPrescaler);
  173. /* Exit Initialization Mode */
  174. LL_RTC_ExitInitMode(RTCx);
  175. status = SUCCESS;
  176. }
  177. }
  178. return status;
  179. }
  180. /**
  181. * @brief Set each @ref LL_RTC_InitTypeDef field to default value.
  182. * @param RTC_InitStruct pointer to a @ref LL_RTC_InitTypeDef structure which will be initialized.
  183. * @retval None
  184. */
  185. void LL_RTC_StructInit(LL_RTC_InitTypeDef *RTC_InitStruct)
  186. {
  187. /* Set RTC_InitStruct fields to default values */
  188. RTC_InitStruct->AsynchPrescaler = RTC_ASYNCH_PRESC_DEFAULT;
  189. RTC_InitStruct->OutPutSource = LL_RTC_CALIB_OUTPUT_NONE;
  190. }
  191. /**
  192. * @brief Set the RTC current time.
  193. * @param RTCx RTC Instance
  194. * @param RTC_Format This parameter can be one of the following values:
  195. * @arg @ref LL_RTC_FORMAT_BIN
  196. * @arg @ref LL_RTC_FORMAT_BCD
  197. * @param RTC_TimeStruct pointer to a RTC_TimeTypeDef structure that contains
  198. * the time configuration information for the RTC.
  199. * @note The user should call LL_RTC_TIME_StructInit() or the structure
  200. * of time need to be initialized before time init()
  201. * @retval An ErrorStatus enumeration value:
  202. * - SUCCESS: RTC Time register is configured
  203. * - ERROR: RTC Time register is not configured
  204. */
  205. ErrorStatus LL_RTC_TIME_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_TimeTypeDef *RTC_TimeStruct)
  206. {
  207. ErrorStatus status = ERROR;
  208. uint32_t counter_time = 0U;
  209. /* Check the parameters */
  210. assert_param(IS_RTC_ALL_INSTANCE(RTCx));
  211. assert_param(IS_LL_RTC_FORMAT(RTC_Format));
  212. if (RTC_Format == LL_RTC_FORMAT_BIN)
  213. {
  214. assert_param(IS_LL_RTC_HOUR24(RTC_TimeStruct->Hours));
  215. assert_param(IS_LL_RTC_MINUTES(RTC_TimeStruct->Minutes));
  216. assert_param(IS_LL_RTC_SECONDS(RTC_TimeStruct->Seconds));
  217. }
  218. else
  219. {
  220. assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Hours)));
  221. assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Minutes)));
  222. assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Seconds)));
  223. }
  224. /* Enter Initialization mode */
  225. if (LL_RTC_EnterInitMode(RTCx) != ERROR)
  226. {
  227. /* Check the input parameters format */
  228. if (RTC_Format != LL_RTC_FORMAT_BIN)
  229. {
  230. counter_time = (uint32_t)(((uint32_t)RTC_TimeStruct->Hours * 3600U) + \
  231. ((uint32_t)RTC_TimeStruct->Minutes * 60U) + \
  232. ((uint32_t)RTC_TimeStruct->Seconds));
  233. LL_RTC_TIME_Set(RTCx, counter_time);
  234. }
  235. else
  236. {
  237. counter_time = (((uint32_t)(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Hours)) * 3600U) + \
  238. ((uint32_t)(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Minutes)) * 60U) + \
  239. ((uint32_t)(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Seconds))));
  240. LL_RTC_TIME_Set(RTCx, counter_time);
  241. }
  242. status = SUCCESS;
  243. }
  244. /* Exit Initialization mode */
  245. LL_RTC_ExitInitMode(RTCx);
  246. return status;
  247. }
  248. /**
  249. * @brief Set each @ref LL_RTC_TimeTypeDef field to default value (Time = 00h:00min:00sec).
  250. * @param RTC_TimeStruct pointer to a @ref LL_RTC_TimeTypeDef structure which will be initialized.
  251. * @retval None
  252. */
  253. void LL_RTC_TIME_StructInit(LL_RTC_TimeTypeDef *RTC_TimeStruct)
  254. {
  255. /* Time = 00h:00min:00sec */
  256. RTC_TimeStruct->Hours = 0U;
  257. RTC_TimeStruct->Minutes = 0U;
  258. RTC_TimeStruct->Seconds = 0U;
  259. }
  260. /**
  261. * @brief Set the RTC Alarm.
  262. * @param RTCx RTC Instance
  263. * @param RTC_Format This parameter can be one of the following values:
  264. * @arg @ref LL_RTC_FORMAT_BIN
  265. * @arg @ref LL_RTC_FORMAT_BCD
  266. * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure that
  267. * contains the alarm configuration parameters.
  268. * @note the user should call LL_RTC_ALARM_StructInit() or the structure
  269. * of Alarm need to be initialized before Alarm init()
  270. * @retval An ErrorStatus enumeration value:
  271. * - SUCCESS: ALARM registers are configured
  272. * - ERROR: ALARM registers are not configured
  273. */
  274. ErrorStatus LL_RTC_ALARM_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_AlarmTypeDef *RTC_AlarmStruct)
  275. {
  276. ErrorStatus status = ERROR;
  277. uint32_t counter_alarm = 0U;
  278. /* Check the parameters */
  279. assert_param(IS_RTC_ALL_INSTANCE(RTCx));
  280. assert_param(IS_LL_RTC_FORMAT(RTC_Format));
  281. if (RTC_Format == LL_RTC_FORMAT_BIN)
  282. {
  283. assert_param(IS_LL_RTC_HOUR24(RTC_AlarmStruct->AlarmTime.Hours));
  284. assert_param(IS_LL_RTC_MINUTES(RTC_AlarmStruct->AlarmTime.Minutes));
  285. assert_param(IS_LL_RTC_SECONDS(RTC_AlarmStruct->AlarmTime.Seconds));
  286. }
  287. else
  288. {
  289. assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours)));
  290. assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Minutes)));
  291. assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Seconds)));
  292. }
  293. /* Enter Initialization mode */
  294. if (LL_RTC_EnterInitMode(RTCx) != ERROR)
  295. {
  296. /* Check the input parameters format */
  297. if (RTC_Format != LL_RTC_FORMAT_BIN)
  298. {
  299. counter_alarm = (uint32_t)(((uint32_t)RTC_AlarmStruct->AlarmTime.Hours * 3600U) + \
  300. ((uint32_t)RTC_AlarmStruct->AlarmTime.Minutes * 60U) + \
  301. ((uint32_t)RTC_AlarmStruct->AlarmTime.Seconds));
  302. LL_RTC_ALARM_Set(RTCx, counter_alarm);
  303. }
  304. else
  305. {
  306. counter_alarm = (((uint32_t)(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours)) * 3600U) + \
  307. ((uint32_t)(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Minutes)) * 60U) + \
  308. ((uint32_t)(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Seconds))));
  309. LL_RTC_ALARM_Set(RTCx, counter_alarm);
  310. }
  311. status = SUCCESS;
  312. }
  313. /* Exit Initialization mode */
  314. LL_RTC_ExitInitMode(RTCx);
  315. return status;
  316. }
  317. /**
  318. * @brief Set each @ref LL_RTC_AlarmTypeDef of ALARM field to default value (Time = 00h:00mn:00sec /
  319. * Day = 1st day of the month/Mask = all fields are masked).
  320. * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure which will be initialized.
  321. * @retval None
  322. */
  323. void LL_RTC_ALARM_StructInit(LL_RTC_AlarmTypeDef *RTC_AlarmStruct)
  324. {
  325. /* Alarm Time Settings : Time = 00h:00mn:00sec */
  326. RTC_AlarmStruct->AlarmTime.Hours = 0U;
  327. RTC_AlarmStruct->AlarmTime.Minutes = 0U;
  328. RTC_AlarmStruct->AlarmTime.Seconds = 0U;
  329. }
  330. /**
  331. * @brief Enters the RTC Initialization mode.
  332. * @param RTCx RTC Instance
  333. * @retval An ErrorStatus enumeration value:
  334. * - SUCCESS: RTC is in Init mode
  335. * - ERROR: RTC is not in Init mode
  336. */
  337. ErrorStatus LL_RTC_EnterInitMode(RTC_TypeDef *RTCx)
  338. {
  339. __IO uint32_t timeout = RTC_INITMODE_TIMEOUT;
  340. ErrorStatus status = SUCCESS;
  341. uint32_t tmp = 0U;
  342. /* Check the parameter */
  343. assert_param(IS_RTC_ALL_INSTANCE(RTCx));
  344. /* Wait till RTC is in INIT state and if Time out is reached exit */
  345. tmp = LL_RTC_IsActiveFlag_RTOF(RTCx);
  346. while ((timeout != 0U) && (tmp != 1U))
  347. {
  348. if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
  349. {
  350. timeout --;
  351. }
  352. tmp = LL_RTC_IsActiveFlag_RTOF(RTCx);
  353. if (timeout == 0U)
  354. {
  355. status = ERROR;
  356. }
  357. }
  358. /* Disable the write protection for RTC registers */
  359. LL_RTC_DisableWriteProtection(RTCx);
  360. return status;
  361. }
  362. /**
  363. * @brief Exit the RTC Initialization mode.
  364. * @note When the initialization sequence is complete, the calendar restarts
  365. * counting after 4 RTCCLK cycles.
  366. * @param RTCx RTC Instance
  367. * @retval An ErrorStatus enumeration value:
  368. * - SUCCESS: RTC exited from in Init mode
  369. * - ERROR: Not applicable
  370. */
  371. ErrorStatus LL_RTC_ExitInitMode(RTC_TypeDef *RTCx)
  372. {
  373. __IO uint32_t timeout = RTC_INITMODE_TIMEOUT;
  374. ErrorStatus status = SUCCESS;
  375. uint32_t tmp = 0U;
  376. /* Check the parameter */
  377. assert_param(IS_RTC_ALL_INSTANCE(RTCx));
  378. /* Disable initialization mode */
  379. LL_RTC_EnableWriteProtection(RTCx);
  380. /* Wait till RTC is in INIT state and if Time out is reached exit */
  381. tmp = LL_RTC_IsActiveFlag_RTOF(RTCx);
  382. while ((timeout != 0U) && (tmp != 1U))
  383. {
  384. if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
  385. {
  386. timeout --;
  387. }
  388. tmp = LL_RTC_IsActiveFlag_RTOF(RTCx);
  389. if (timeout == 0U)
  390. {
  391. status = ERROR;
  392. }
  393. }
  394. return status;
  395. }
  396. /**
  397. * @brief Set the Time Counter
  398. * @param RTCx RTC Instance
  399. * @param TimeCounter this value can be from 0 to 0xFFFFFFFF
  400. * @retval An ErrorStatus enumeration value:
  401. * - SUCCESS: RTC Counter register configured
  402. * - ERROR: Not applicable
  403. */
  404. ErrorStatus LL_RTC_TIME_SetCounter(RTC_TypeDef *RTCx, uint32_t TimeCounter)
  405. {
  406. ErrorStatus status = ERROR;
  407. /* Check the parameter */
  408. assert_param(IS_RTC_ALL_INSTANCE(RTCx));
  409. /* Enter Initialization mode */
  410. if (LL_RTC_EnterInitMode(RTCx) != ERROR)
  411. {
  412. LL_RTC_TIME_Set(RTCx, TimeCounter);
  413. status = SUCCESS;
  414. }
  415. /* Exit Initialization mode */
  416. LL_RTC_ExitInitMode(RTCx);
  417. return status;
  418. }
  419. /**
  420. * @brief Set Alarm Counter.
  421. * @param RTCx RTC Instance
  422. * @param AlarmCounter this value can be from 0 to 0xFFFFFFFF
  423. * @retval An ErrorStatus enumeration value:
  424. * - SUCCESS: RTC exited from in Init mode
  425. * - ERROR: Not applicable
  426. */
  427. ErrorStatus LL_RTC_ALARM_SetCounter(RTC_TypeDef *RTCx, uint32_t AlarmCounter)
  428. {
  429. ErrorStatus status = ERROR;
  430. /* Check the parameter */
  431. assert_param(IS_RTC_ALL_INSTANCE(RTCx));
  432. /* Enter Initialization mode */
  433. if (LL_RTC_EnterInitMode(RTCx) != ERROR)
  434. {
  435. LL_RTC_ALARM_Set(RTCx, AlarmCounter);
  436. status = SUCCESS;
  437. }
  438. /* Exit Initialization mode */
  439. LL_RTC_ExitInitMode(RTCx);
  440. return status;
  441. }
  442. /**
  443. * @brief Waits until the RTC registers are synchronized with RTC APB clock.
  444. * @note The RTC Resynchronization mode is write protected, use the
  445. * @ref LL_RTC_DisableWriteProtection before calling this function.
  446. * @param RTCx RTC Instance
  447. * @retval An ErrorStatus enumeration value:
  448. * - SUCCESS: RTC registers are synchronised
  449. * - ERROR: RTC registers are not synchronised
  450. */
  451. ErrorStatus LL_RTC_WaitForSynchro(RTC_TypeDef *RTCx)
  452. {
  453. __IO uint32_t timeout = RTC_SYNCHRO_TIMEOUT;
  454. ErrorStatus status = SUCCESS;
  455. uint32_t tmp = 0U;
  456. /* Check the parameter */
  457. assert_param(IS_RTC_ALL_INSTANCE(RTCx));
  458. /* Clear RSF flag */
  459. LL_RTC_ClearFlag_RS(RTCx);
  460. /* Wait the registers to be synchronised */
  461. tmp = LL_RTC_IsActiveFlag_RS(RTCx);
  462. while ((timeout != 0U) && (tmp != 0U))
  463. {
  464. if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
  465. {
  466. timeout--;
  467. }
  468. tmp = LL_RTC_IsActiveFlag_RS(RTCx);
  469. if (timeout == 0U)
  470. {
  471. status = ERROR;
  472. }
  473. }
  474. return (status);
  475. }
  476. /**
  477. * @}
  478. */
  479. /**
  480. * @}
  481. */
  482. /**
  483. * @}
  484. */
  485. #endif /* defined(RTC) */
  486. /**
  487. * @}
  488. */
  489. #endif /* USE_FULL_LL_DRIVER */
  490. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/