py32f0xx_ll_rtc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. /**
  2. ******************************************************************************
  3. * @file py32f0xx_ll_rtc.c
  4. * @author MCU Application Team
  5. * @brief RTC LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2023 Puya Semiconductor Co.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by Puya under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. * @attention
  19. *
  20. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  21. * All rights reserved.</center></h2>
  22. *
  23. * This software component is licensed by ST under BSD 3-Clause license,
  24. * the "License"; You may not use this file except in compliance with the
  25. * License. You may obtain a copy of the License at:
  26. * opensource.org/licenses/BSD-3-Clause
  27. *
  28. ******************************************************************************
  29. */
  30. #if defined(USE_FULL_LL_DRIVER)
  31. /* Includes ------------------------------------------------------------------*/
  32. #include "py32f0xx_ll_rtc.h"
  33. #include "py32f0xx_ll_cortex.h"
  34. #ifdef USE_FULL_ASSERT
  35. #include "py32_assert.h"
  36. #else
  37. #define assert_param(expr) ((void)0U)
  38. #endif
  39. /** @addtogroup PY32F0xx_LL_Driver
  40. * @{
  41. */
  42. #if defined(RTC)
  43. /** @addtogroup RTC_LL
  44. * @{
  45. */
  46. /* Private types -------------------------------------------------------------*/
  47. /* Private variables ---------------------------------------------------------*/
  48. /* Private constants ---------------------------------------------------------*/
  49. /** @defgroup RTC_LL_Private_Constants RTC Private Constants
  50. * @{
  51. */
  52. /* Default values used for prescaler */
  53. #define RTC_ASYNCH_PRESC_DEFAULT 0x00007FFFU
  54. /* Values used for timeout */
  55. #define RTC_INITMODE_TIMEOUT 2000U /* 2s when tick set to 1ms */
  56. #define RTC_SYNCHRO_TIMEOUT 2000U /* 2s when tick set to 1ms */
  57. #define RTC_WAIT_RTOFF_ZERO 4U /* 1ms when tick set to 1ms */
  58. /**
  59. * @}
  60. */
  61. /* Private macros ------------------------------------------------------------*/
  62. /** @addtogroup RTC_LL_Private_Macros
  63. * @{
  64. */
  65. #define IS_LL_RTC_ASYNCH_PREDIV(__VALUE__) ((__VALUE__) <= 0xFFFFFU)
  66. #define IS_LL_RTC_FORMAT(__VALUE__) (((__VALUE__) == LL_RTC_FORMAT_BIN) \
  67. || ((__VALUE__) == LL_RTC_FORMAT_BCD))
  68. #define IS_LL_RTC_HOUR24(__HOUR__) ((__HOUR__) <= 23U)
  69. #define IS_LL_RTC_MINUTES(__MINUTES__) ((__MINUTES__) <= 59U)
  70. #define IS_LL_RTC_SECONDS(__SECONDS__) ((__SECONDS__) <= 59U)
  71. #define IS_LL_RTC_CALIB_OUTPUT(__OUTPUT__) (((__OUTPUT__) == LL_RTC_CALIB_OUTPUT_NONE) || \
  72. ((__OUTPUT__) == LL_RTC_CALIB_OUTPUT_RTCCLOCK) || \
  73. ((__OUTPUT__) == LL_RTC_CALIB_OUTPUT_ALARM) || \
  74. ((__OUTPUT__) == LL_RTC_CALIB_OUTPUT_SECOND))
  75. /**
  76. * @}
  77. */
  78. /* Private function prototypes -----------------------------------------------*/
  79. /* Exported functions --------------------------------------------------------*/
  80. /** @addtogroup RTC_LL_Exported_Functions
  81. * @{
  82. */
  83. /** @addtogroup RTC_LL_EF_Init
  84. * @{
  85. */
  86. /**
  87. * @brief De-Initializes the RTC registers to their default reset values.
  88. * @note This function doesn't reset the RTC Clock source and RTC Backup Data
  89. * registers.
  90. * @param RTCx RTC Instance
  91. * @retval An ErrorStatus enumeration value:
  92. * - SUCCESS: RTC registers are de-initialized
  93. * - ERROR: RTC registers are not de-initialized
  94. */
  95. ErrorStatus LL_RTC_DeInit(RTC_TypeDef *RTCx)
  96. {
  97. ErrorStatus status = ERROR;
  98. /* Check the parameter */
  99. assert_param(IS_RTC_ALL_INSTANCE(RTCx));
  100. /* Disable the write protection for RTC registers */
  101. LL_RTC_DisableWriteProtection(RTCx);
  102. /* Set Initialization mode */
  103. if (LL_RTC_EnterInitMode(RTCx) != ERROR)
  104. {
  105. LL_RTC_WriteReg(RTCx, CNTL, 0x0000);
  106. LL_RTC_WriteReg(RTCx, CNTH, 0x0000);
  107. LL_RTC_WriteReg(RTCx, PRLH, 0x0000);
  108. LL_RTC_WriteReg(RTCx, PRLL, 0x8000);
  109. LL_RTC_WriteReg(RTCx, CRH, 0x0000);
  110. LL_RTC_WriteReg(RTCx, CRL, 0x0020);
  111. /* Reset Tamper and alternate functions configuration register */
  112. LL_RTC_WriteReg(RTCx, BKP_RTCCR, 0x0000);
  113. /* Exit Initialization Mode */
  114. if (LL_RTC_ExitInitMode(RTCx) != ERROR)
  115. {
  116. /* Wait till the RTC RSF flag is set */
  117. status = LL_RTC_WaitForSynchro(RTCx);
  118. /* Clear RSF Flag */
  119. LL_RTC_ClearFlag_RS(RTCx);
  120. /* Enable the write protection for RTC registers */
  121. LL_RTC_EnableWriteProtection(RTCx);
  122. }
  123. }
  124. else
  125. {
  126. /* Enable the write protection for RTC registers */
  127. LL_RTC_EnableWriteProtection(RTCx);
  128. }
  129. return status;
  130. }
  131. /**
  132. * @brief Initializes the RTC registers according to the specified parameters
  133. * in RTC_InitStruct.
  134. * @param RTCx RTC Instance
  135. * @param RTC_InitStruct pointer to a @ref LL_RTC_InitTypeDef structure that contains
  136. * the configuration information for the RTC peripheral.
  137. * @note The RTC Prescaler register is write protected and can be written in
  138. * initialization mode only.
  139. * @note the user should call LL_RTC_StructInit() or the structure of Prescaler
  140. * need to be initialized before RTC init()
  141. * @retval An ErrorStatus enumeration value:
  142. * - SUCCESS: RTC registers are initialized
  143. * - ERROR: RTC registers are not initialized
  144. */
  145. ErrorStatus LL_RTC_Init(RTC_TypeDef *RTCx, LL_RTC_InitTypeDef *RTC_InitStruct)
  146. {
  147. ErrorStatus status = ERROR;
  148. /* Check the parameters */
  149. assert_param(IS_RTC_ALL_INSTANCE(RTCx));
  150. assert_param(IS_LL_RTC_ASYNCH_PREDIV(RTC_InitStruct->AsynchPrescaler));
  151. assert_param(IS_LL_RTC_CALIB_OUTPUT(RTC_InitStruct->OutPutSource));
  152. /* Waiting for synchro */
  153. if (LL_RTC_WaitForSynchro(RTCx) != ERROR)
  154. {
  155. /* Set Initialization mode */
  156. if (LL_RTC_EnterInitMode(RTCx) != ERROR)
  157. {
  158. /* Clear Flag Bits */
  159. LL_RTC_ClearFlag_ALR(RTCx);
  160. LL_RTC_ClearFlag_OW(RTCx);
  161. LL_RTC_ClearFlag_SEC(RTCx);
  162. /* Set the signal which will be routed to RTC Tamper Pin */
  163. LL_RTC_SetOutputSource(RTCx, RTC_InitStruct->OutPutSource);
  164. /* Configure Synchronous and Asynchronous prescaler factor */
  165. LL_RTC_SetAsynchPrescaler(RTCx, RTC_InitStruct->AsynchPrescaler);
  166. /* Exit Initialization Mode */
  167. LL_RTC_ExitInitMode(RTCx);
  168. status = SUCCESS;
  169. }
  170. }
  171. return status;
  172. }
  173. /**
  174. * @brief Set each @ref LL_RTC_InitTypeDef field to default value.
  175. * @param RTC_InitStruct pointer to a @ref LL_RTC_InitTypeDef structure which will be initialized.
  176. * @retval None
  177. */
  178. void LL_RTC_StructInit(LL_RTC_InitTypeDef *RTC_InitStruct)
  179. {
  180. /* Set RTC_InitStruct fields to default values */
  181. RTC_InitStruct->AsynchPrescaler = RTC_ASYNCH_PRESC_DEFAULT;
  182. RTC_InitStruct->OutPutSource = LL_RTC_CALIB_OUTPUT_NONE;
  183. }
  184. /**
  185. * @brief Set the RTC current time.
  186. * @param RTCx RTC Instance
  187. * @param RTC_Format This parameter can be one of the following values:
  188. * @arg @ref LL_RTC_FORMAT_BIN
  189. * @arg @ref LL_RTC_FORMAT_BCD
  190. * @param RTC_TimeStruct pointer to a RTC_TimeTypeDef structure that contains
  191. * the time configuration information for the RTC.
  192. * @note The user should call LL_RTC_TIME_StructInit() or the structure
  193. * of time need to be initialized before time init()
  194. * @retval An ErrorStatus enumeration value:
  195. * - SUCCESS: RTC Time register is configured
  196. * - ERROR: RTC Time register is not configured
  197. */
  198. ErrorStatus LL_RTC_TIME_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_TimeTypeDef *RTC_TimeStruct)
  199. {
  200. ErrorStatus status = ERROR;
  201. uint32_t counter_time = 0U;
  202. /* Check the parameters */
  203. assert_param(IS_RTC_ALL_INSTANCE(RTCx));
  204. assert_param(IS_LL_RTC_FORMAT(RTC_Format));
  205. if (RTC_Format == LL_RTC_FORMAT_BIN)
  206. {
  207. assert_param(IS_LL_RTC_HOUR24(RTC_TimeStruct->Hours));
  208. assert_param(IS_LL_RTC_MINUTES(RTC_TimeStruct->Minutes));
  209. assert_param(IS_LL_RTC_SECONDS(RTC_TimeStruct->Seconds));
  210. }
  211. else
  212. {
  213. assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Hours)));
  214. assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Minutes)));
  215. assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Seconds)));
  216. }
  217. /* Enter Initialization mode */
  218. if (LL_RTC_EnterInitMode(RTCx) != ERROR)
  219. {
  220. /* Check the input parameters format */
  221. if (RTC_Format == LL_RTC_FORMAT_BIN)
  222. {
  223. counter_time = (uint32_t)(((uint32_t)RTC_TimeStruct->Hours * 3600U) + \
  224. ((uint32_t)RTC_TimeStruct->Minutes * 60U) + \
  225. ((uint32_t)RTC_TimeStruct->Seconds));
  226. LL_RTC_TIME_Set(RTCx, counter_time);
  227. }
  228. else
  229. {
  230. counter_time = (((uint32_t)(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Hours)) * 3600U) + \
  231. ((uint32_t)(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Minutes)) * 60U) + \
  232. ((uint32_t)(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Seconds))));
  233. LL_RTC_TIME_Set(RTCx, counter_time);
  234. }
  235. status = SUCCESS;
  236. }
  237. /* Exit Initialization mode */
  238. LL_RTC_ExitInitMode(RTCx);
  239. return status;
  240. }
  241. /**
  242. * @brief Set each @ref LL_RTC_TimeTypeDef field to default value (Time = 00h:00min:00sec).
  243. * @param RTC_TimeStruct pointer to a @ref LL_RTC_TimeTypeDef structure which will be initialized.
  244. * @retval None
  245. */
  246. void LL_RTC_TIME_StructInit(LL_RTC_TimeTypeDef *RTC_TimeStruct)
  247. {
  248. /* Time = 00h:00min:00sec */
  249. RTC_TimeStruct->Hours = 0U;
  250. RTC_TimeStruct->Minutes = 0U;
  251. RTC_TimeStruct->Seconds = 0U;
  252. }
  253. /**
  254. * @brief Set the RTC Alarm.
  255. * @param RTCx RTC Instance
  256. * @param RTC_Format This parameter can be one of the following values:
  257. * @arg @ref LL_RTC_FORMAT_BIN
  258. * @arg @ref LL_RTC_FORMAT_BCD
  259. * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure that
  260. * contains the alarm configuration parameters.
  261. * @note the user should call LL_RTC_ALARM_StructInit() or the structure
  262. * of Alarm need to be initialized before Alarm init()
  263. * @retval An ErrorStatus enumeration value:
  264. * - SUCCESS: ALARM registers are configured
  265. * - ERROR: ALARM registers are not configured
  266. */
  267. ErrorStatus LL_RTC_ALARM_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_AlarmTypeDef *RTC_AlarmStruct)
  268. {
  269. ErrorStatus status = ERROR;
  270. uint32_t counter_alarm = 0U;
  271. /* Check the parameters */
  272. assert_param(IS_RTC_ALL_INSTANCE(RTCx));
  273. assert_param(IS_LL_RTC_FORMAT(RTC_Format));
  274. if (RTC_Format == LL_RTC_FORMAT_BIN)
  275. {
  276. assert_param(IS_LL_RTC_HOUR24(RTC_AlarmStruct->AlarmTime.Hours));
  277. assert_param(IS_LL_RTC_MINUTES(RTC_AlarmStruct->AlarmTime.Minutes));
  278. assert_param(IS_LL_RTC_SECONDS(RTC_AlarmStruct->AlarmTime.Seconds));
  279. }
  280. else
  281. {
  282. assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours)));
  283. assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Minutes)));
  284. assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Seconds)));
  285. }
  286. /* Enter Initialization mode */
  287. if (LL_RTC_EnterInitMode(RTCx) != ERROR)
  288. {
  289. /* Check the input parameters format */
  290. if (RTC_Format == LL_RTC_FORMAT_BIN)
  291. {
  292. counter_alarm = (uint32_t)(((uint32_t)RTC_AlarmStruct->AlarmTime.Hours * 3600U) + \
  293. ((uint32_t)RTC_AlarmStruct->AlarmTime.Minutes * 60U) + \
  294. ((uint32_t)RTC_AlarmStruct->AlarmTime.Seconds));
  295. LL_RTC_ALARM_Set(RTCx, counter_alarm);
  296. }
  297. else
  298. {
  299. counter_alarm = (((uint32_t)(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours)) * 3600U) + \
  300. ((uint32_t)(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Minutes)) * 60U) + \
  301. ((uint32_t)(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Seconds))));
  302. LL_RTC_ALARM_Set(RTCx, counter_alarm);
  303. }
  304. status = SUCCESS;
  305. }
  306. /* Exit Initialization mode */
  307. LL_RTC_ExitInitMode(RTCx);
  308. return status;
  309. }
  310. /**
  311. * @brief Set each @ref LL_RTC_AlarmTypeDef of ALARM field to default value (Time = 00h:00mn:00sec /
  312. * Day = 1st day of the month/Mask = all fields are masked).
  313. * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure which will be initialized.
  314. * @retval None
  315. */
  316. void LL_RTC_ALARM_StructInit(LL_RTC_AlarmTypeDef *RTC_AlarmStruct)
  317. {
  318. /* Alarm Time Settings : Time = 00h:00mn:00sec */
  319. RTC_AlarmStruct->AlarmTime.Hours = 0U;
  320. RTC_AlarmStruct->AlarmTime.Minutes = 0U;
  321. RTC_AlarmStruct->AlarmTime.Seconds = 0U;
  322. }
  323. /**
  324. * @brief Enters the RTC Initialization mode.
  325. * @param RTCx RTC Instance
  326. * @retval An ErrorStatus enumeration value:
  327. * - SUCCESS: RTC is in Init mode
  328. * - ERROR: RTC is not in Init mode
  329. */
  330. ErrorStatus LL_RTC_EnterInitMode(RTC_TypeDef *RTCx)
  331. {
  332. __IO uint32_t timeout = RTC_INITMODE_TIMEOUT;
  333. ErrorStatus status = SUCCESS;
  334. uint32_t tmp = 0U;
  335. /* Check the parameter */
  336. assert_param(IS_RTC_ALL_INSTANCE(RTCx));
  337. /* Wait till RTC is in INIT state and if Time out is reached exit */
  338. tmp = LL_RTC_IsActiveFlag_RTOF(RTCx);
  339. while ((timeout != 0U) && (tmp == 0U))
  340. {
  341. if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
  342. {
  343. timeout --;
  344. }
  345. tmp = LL_RTC_IsActiveFlag_RTOF(RTCx);
  346. if (timeout == 0U)
  347. {
  348. status = ERROR;
  349. }
  350. }
  351. /* Disable the write protection for RTC registers */
  352. LL_RTC_DisableWriteProtection(RTCx);
  353. return status;
  354. }
  355. /**
  356. * @brief Exit the RTC Initialization mode.
  357. * @note When the initialization sequence is complete, the calendar restarts
  358. * counting after 4 RTCCLK cycles.
  359. * @param RTCx RTC Instance
  360. * @retval An ErrorStatus enumeration value:
  361. * - SUCCESS: RTC exited from in Init mode
  362. * - ERROR: Not applicable
  363. */
  364. ErrorStatus LL_RTC_ExitInitMode(RTC_TypeDef *RTCx)
  365. {
  366. __IO uint32_t timeout = RTC_INITMODE_TIMEOUT;
  367. __IO uint32_t timeout_waitRtoffZer0 = RTC_WAIT_RTOFF_ZERO;
  368. ErrorStatus status = SUCCESS;
  369. uint32_t tmp = 0U;
  370. /* Check the parameter */
  371. assert_param(IS_RTC_ALL_INSTANCE(RTCx));
  372. /* Disable initialization mode */
  373. LL_RTC_EnableWriteProtection(RTCx);
  374. /* Wait till RTC is in INIT state and if Time out is reached exit */
  375. tmp = LL_RTC_IsActiveFlag_RTOF(RTCx);
  376. while ((timeout_waitRtoffZer0 != 0U) && (tmp !=0U))
  377. {
  378. if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
  379. {
  380. timeout_waitRtoffZer0 --;
  381. }
  382. tmp = LL_RTC_IsActiveFlag_RTOF(RTCx);
  383. }
  384. while ((timeout != 0U) && (tmp ==0U))
  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 Puya *****END OF FILE****/