Subversion Repositories LedShow

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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