stm32f1xx_ll_rtc.c 18 KB

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