2 ******************************************************************************
3 * @file stm32f7xx_ll_rtc.c
4 * @author MCD Application Team
7 * @brief RTC LL module driver.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
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.
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.
35 ******************************************************************************
37 #if defined(USE_FULL_LL_DRIVER)
39 /* Includes ------------------------------------------------------------------*/
40 #include "stm32f7xx_ll_rtc.h"
41 #include "stm32f7xx_ll_cortex.h"
42 #ifdef USE_FULL_ASSERT
43 #include "stm32_assert.h"
45 #define assert_param(expr) ((void)0U)
48 /** @addtogroup STM32F7xx_LL_Driver
54 /** @addtogroup RTC_LL
58 /* Private types -------------------------------------------------------------*/
59 /* Private variables ---------------------------------------------------------*/
60 /* Private constants ---------------------------------------------------------*/
61 /** @addtogroup RTC_LL_Private_Constants
64 /* Default values used for prescaler */
65 #define RTC_ASYNCH_PRESC_DEFAULT 0x0000007FU
66 #define RTC_SYNCH_PRESC_DEFAULT 0x000000FFU
68 /* Values used for timeout */
69 #define RTC_INITMODE_TIMEOUT 1000U /* 1s when tick set to 1ms */
70 #define RTC_SYNCHRO_TIMEOUT 1000U /* 1s when tick set to 1ms */
75 /* Private macros ------------------------------------------------------------*/
76 /** @addtogroup RTC_LL_Private_Macros
80 #define IS_LL_RTC_HOURFORMAT(__VALUE__) (((__VALUE__) == LL_RTC_HOURFORMAT_24HOUR) \
81 || ((__VALUE__) == LL_RTC_HOURFORMAT_AMPM))
83 #define IS_LL_RTC_ASYNCH_PREDIV(__VALUE__) ((__VALUE__) <= 0x7FU)
85 #define IS_LL_RTC_SYNCH_PREDIV(__VALUE__) ((__VALUE__) <= 0x7FFFU)
87 #define IS_LL_RTC_FORMAT(__VALUE__) (((__VALUE__) == LL_RTC_FORMAT_BIN) \
88 || ((__VALUE__) == LL_RTC_FORMAT_BCD))
90 #define IS_LL_RTC_TIME_FORMAT(__VALUE__) (((__VALUE__) == LL_RTC_TIME_FORMAT_AM_OR_24) \
91 || ((__VALUE__) == LL_RTC_TIME_FORMAT_PM))
93 #define IS_LL_RTC_HOUR12(__HOUR__) (((__HOUR__) > 0U) && ((__HOUR__) <= 12U))
94 #define IS_LL_RTC_HOUR24(__HOUR__) ((__HOUR__) <= 23U)
95 #define IS_LL_RTC_MINUTES(__MINUTES__) ((__MINUTES__) <= 59U)
96 #define IS_LL_RTC_SECONDS(__SECONDS__) ((__SECONDS__) <= 59U)
98 #define IS_LL_RTC_WEEKDAY(__VALUE__) (((__VALUE__) == LL_RTC_WEEKDAY_MONDAY) \
99 || ((__VALUE__) == LL_RTC_WEEKDAY_TUESDAY) \
100 || ((__VALUE__) == LL_RTC_WEEKDAY_WEDNESDAY) \
101 || ((__VALUE__) == LL_RTC_WEEKDAY_THURSDAY) \
102 || ((__VALUE__) == LL_RTC_WEEKDAY_FRIDAY) \
103 || ((__VALUE__) == LL_RTC_WEEKDAY_SATURDAY) \
104 || ((__VALUE__) == LL_RTC_WEEKDAY_SUNDAY))
106 #define IS_LL_RTC_DAY(__DAY__) (((__DAY__) >= 1U) && ((__DAY__) <= 31U))
108 #define IS_LL_RTC_MONTH(__VALUE__) (((__VALUE__) == LL_RTC_MONTH_JANUARY) \
109 || ((__VALUE__) == LL_RTC_MONTH_FEBRUARY) \
110 || ((__VALUE__) == LL_RTC_MONTH_MARCH) \
111 || ((__VALUE__) == LL_RTC_MONTH_APRIL) \
112 || ((__VALUE__) == LL_RTC_MONTH_MAY) \
113 || ((__VALUE__) == LL_RTC_MONTH_JUNE) \
114 || ((__VALUE__) == LL_RTC_MONTH_JULY) \
115 || ((__VALUE__) == LL_RTC_MONTH_AUGUST) \
116 || ((__VALUE__) == LL_RTC_MONTH_SEPTEMBER) \
117 || ((__VALUE__) == LL_RTC_MONTH_OCTOBER) \
118 || ((__VALUE__) == LL_RTC_MONTH_NOVEMBER) \
119 || ((__VALUE__) == LL_RTC_MONTH_DECEMBER))
121 #define IS_LL_RTC_YEAR(__YEAR__) ((__YEAR__) <= 99U)
123 #define IS_LL_RTC_ALMA_MASK(__VALUE__) (((__VALUE__) == LL_RTC_ALMA_MASK_NONE) \
124 || ((__VALUE__) == LL_RTC_ALMA_MASK_DATEWEEKDAY) \
125 || ((__VALUE__) == LL_RTC_ALMA_MASK_HOURS) \
126 || ((__VALUE__) == LL_RTC_ALMA_MASK_MINUTES) \
127 || ((__VALUE__) == LL_RTC_ALMA_MASK_SECONDS) \
128 || ((__VALUE__) == LL_RTC_ALMA_MASK_ALL))
130 #define IS_LL_RTC_ALMB_MASK(__VALUE__) (((__VALUE__) == LL_RTC_ALMB_MASK_NONE) \
131 || ((__VALUE__) == LL_RTC_ALMB_MASK_DATEWEEKDAY) \
132 || ((__VALUE__) == LL_RTC_ALMB_MASK_HOURS) \
133 || ((__VALUE__) == LL_RTC_ALMB_MASK_MINUTES) \
134 || ((__VALUE__) == LL_RTC_ALMB_MASK_SECONDS) \
135 || ((__VALUE__) == LL_RTC_ALMB_MASK_ALL))
138 #define IS_LL_RTC_ALMA_DATE_WEEKDAY_SEL(__SEL__) (((__SEL__) == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE) || \
139 ((__SEL__) == LL_RTC_ALMA_DATEWEEKDAYSEL_WEEKDAY))
141 #define IS_LL_RTC_ALMB_DATE_WEEKDAY_SEL(__SEL__) (((__SEL__) == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE) || \
142 ((__SEL__) == LL_RTC_ALMB_DATEWEEKDAYSEL_WEEKDAY))
148 /* Private function prototypes -----------------------------------------------*/
149 /* Exported functions --------------------------------------------------------*/
150 /** @addtogroup RTC_LL_Exported_Functions
154 /** @addtogroup RTC_LL_EF_Init
159 * @brief De-Initializes the RTC registers to their default reset values.
160 * @note This function doesn't reset the RTC Clock source and RTC Backup Data
162 * @param RTCx RTC Instance
163 * @retval An ErrorStatus enumeration value:
164 * - SUCCESS: RTC registers are de-initialized
165 * - ERROR: RTC registers are not de-initialized
167 ErrorStatus
LL_RTC_DeInit(RTC_TypeDef
*RTCx
)
169 ErrorStatus status
= ERROR
;
171 /* Check the parameter */
172 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
174 /* Disable the write protection for RTC registers */
175 LL_RTC_DisableWriteProtection(RTCx
);
177 /* Set Initialization mode */
178 if (LL_RTC_EnterInitMode(RTCx
) != ERROR
)
180 /* Reset TR, DR and CR registers */
181 LL_RTC_WriteReg(RTCx
, TR
, 0x00000000U
);
182 #if defined(RTC_WAKEUP_SUPPORT)
183 LL_RTC_WriteReg(RTCx
, WUTR
, RTC_WUTR_WUT
);
184 #endif /* RTC_WAKEUP_SUPPORT */
185 LL_RTC_WriteReg(RTCx
, DR
, (RTC_DR_WDU_0
| RTC_DR_MU_0
| RTC_DR_DU_0
));
186 /* Reset All CR bits except CR[2:0] */
187 #if defined(RTC_WAKEUP_SUPPORT)
188 LL_RTC_WriteReg(RTCx
, CR
, (LL_RTC_ReadReg(RTCx
, CR
) & RTC_CR_WUCKSEL
));
190 LL_RTC_WriteReg(RTCx
, CR
, 0x00000000U
);
191 #endif /* RTC_WAKEUP_SUPPORT */
192 LL_RTC_WriteReg(RTCx
, PRER
, (RTC_PRER_PREDIV_A
| RTC_SYNCH_PRESC_DEFAULT
));
193 LL_RTC_WriteReg(RTCx
, ALRMAR
, 0x00000000U
);
194 LL_RTC_WriteReg(RTCx
, ALRMBR
, 0x00000000U
);
195 LL_RTC_WriteReg(RTCx
, SHIFTR
, 0x00000000U
);
196 LL_RTC_WriteReg(RTCx
, CALR
, 0x00000000U
);
197 LL_RTC_WriteReg(RTCx
, ALRMASSR
, 0x00000000U
);
198 LL_RTC_WriteReg(RTCx
, ALRMBSSR
, 0x00000000U
);
200 /* Reset ISR register and exit initialization mode */
201 LL_RTC_WriteReg(RTCx
, ISR
, 0x00000000U
);
203 /* Reset Tamper and alternate functions configuration register */
204 LL_RTC_WriteReg(RTCx
, TAMPCR
, 0x00000000U
);
206 /* Reset Option register */
207 LL_RTC_WriteReg(RTCx
, OR
, 0x00000000U
);
209 /* Wait till the RTC RSF flag is set */
210 status
= LL_RTC_WaitForSynchro(RTCx
);
213 /* Enable the write protection for RTC registers */
214 LL_RTC_EnableWriteProtection(RTCx
);
220 * @brief Initializes the RTC registers according to the specified parameters
222 * @param RTCx RTC Instance
223 * @param RTC_InitStruct pointer to a @ref LL_RTC_InitTypeDef structure that contains
224 * the configuration information for the RTC peripheral.
225 * @note The RTC Prescaler register is write protected and can be written in
226 * initialization mode only.
227 * @retval An ErrorStatus enumeration value:
228 * - SUCCESS: RTC registers are initialized
229 * - ERROR: RTC registers are not initialized
231 ErrorStatus
LL_RTC_Init(RTC_TypeDef
*RTCx
, LL_RTC_InitTypeDef
*RTC_InitStruct
)
233 ErrorStatus status
= ERROR
;
235 /* Check the parameters */
236 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
237 assert_param(IS_LL_RTC_HOURFORMAT(RTC_InitStruct
->HourFormat
));
238 assert_param(IS_LL_RTC_ASYNCH_PREDIV(RTC_InitStruct
->AsynchPrescaler
));
239 assert_param(IS_LL_RTC_SYNCH_PREDIV(RTC_InitStruct
->SynchPrescaler
));
241 /* Disable the write protection for RTC registers */
242 LL_RTC_DisableWriteProtection(RTCx
);
244 /* Set Initialization mode */
245 if (LL_RTC_EnterInitMode(RTCx
) != ERROR
)
247 /* Set Hour Format */
248 LL_RTC_SetHourFormat(RTCx
, RTC_InitStruct
->HourFormat
);
250 /* Configure Synchronous and Asynchronous prescaler factor */
251 LL_RTC_SetSynchPrescaler(RTCx
, RTC_InitStruct
->SynchPrescaler
);
252 LL_RTC_SetAsynchPrescaler(RTCx
, RTC_InitStruct
->AsynchPrescaler
);
254 /* Exit Initialization mode */
255 LL_RTC_DisableInitMode(RTCx
);
259 /* Enable the write protection for RTC registers */
260 LL_RTC_EnableWriteProtection(RTCx
);
266 * @brief Set each @ref LL_RTC_InitTypeDef field to default value.
267 * @param RTC_InitStruct pointer to a @ref LL_RTC_InitTypeDef structure which will be initialized.
270 void LL_RTC_StructInit(LL_RTC_InitTypeDef
*RTC_InitStruct
)
272 /* Set RTC_InitStruct fields to default values */
273 RTC_InitStruct
->HourFormat
= LL_RTC_HOURFORMAT_24HOUR
;
274 RTC_InitStruct
->AsynchPrescaler
= RTC_ASYNCH_PRESC_DEFAULT
;
275 RTC_InitStruct
->SynchPrescaler
= RTC_SYNCH_PRESC_DEFAULT
;
279 * @brief Set the RTC current time.
280 * @param RTCx RTC Instance
281 * @param RTC_Format This parameter can be one of the following values:
282 * @arg @ref LL_RTC_FORMAT_BIN
283 * @arg @ref LL_RTC_FORMAT_BCD
284 * @param RTC_TimeStruct pointer to a RTC_TimeTypeDef structure that contains
285 * the time configuration information for the RTC.
286 * @retval An ErrorStatus enumeration value:
287 * - SUCCESS: RTC Time register is configured
288 * - ERROR: RTC Time register is not configured
290 ErrorStatus
LL_RTC_TIME_Init(RTC_TypeDef
*RTCx
, uint32_t RTC_Format
, LL_RTC_TimeTypeDef
*RTC_TimeStruct
)
292 ErrorStatus status
= ERROR
;
294 /* Check the parameters */
295 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
296 assert_param(IS_LL_RTC_FORMAT(RTC_Format
));
298 if (RTC_Format
== LL_RTC_FORMAT_BIN
)
300 if (LL_RTC_GetHourFormat(RTCx
) != LL_RTC_HOURFORMAT_24HOUR
)
302 assert_param(IS_LL_RTC_HOUR12(RTC_TimeStruct
->Hours
));
303 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_TimeStruct
->TimeFormat
));
307 RTC_TimeStruct
->TimeFormat
= 0x00U
;
308 assert_param(IS_LL_RTC_HOUR24(RTC_TimeStruct
->Hours
));
310 assert_param(IS_LL_RTC_MINUTES(RTC_TimeStruct
->Minutes
));
311 assert_param(IS_LL_RTC_SECONDS(RTC_TimeStruct
->Seconds
));
315 if (LL_RTC_GetHourFormat(RTCx
) != LL_RTC_HOURFORMAT_24HOUR
)
317 assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct
->Hours
)));
318 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_TimeStruct
->TimeFormat
));
322 RTC_TimeStruct
->TimeFormat
= 0x00U
;
323 assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct
->Hours
)));
325 assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct
->Minutes
)));
326 assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct
->Seconds
)));
329 /* Disable the write protection for RTC registers */
330 LL_RTC_DisableWriteProtection(RTCx
);
332 /* Set Initialization mode */
333 if (LL_RTC_EnterInitMode(RTCx
) != ERROR
)
335 /* Check the input parameters format */
336 if (RTC_Format
!= LL_RTC_FORMAT_BIN
)
338 LL_RTC_TIME_Config(RTCx
, RTC_TimeStruct
->TimeFormat
, RTC_TimeStruct
->Hours
,
339 RTC_TimeStruct
->Minutes
, RTC_TimeStruct
->Seconds
);
343 LL_RTC_TIME_Config(RTCx
, RTC_TimeStruct
->TimeFormat
, __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct
->Hours
),
344 __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct
->Minutes
),
345 __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct
->Seconds
));
348 /* Exit Initialization mode */
349 LL_RTC_DisableInitMode(RTC
);
351 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
352 if (LL_RTC_IsShadowRegBypassEnabled(RTCx
) == 0U)
354 status
= LL_RTC_WaitForSynchro(RTCx
);
361 /* Enable the write protection for RTC registers */
362 LL_RTC_EnableWriteProtection(RTCx
);
368 * @brief Set each @ref LL_RTC_TimeTypeDef field to default value (Time = 00h:00min:00sec).
369 * @param RTC_TimeStruct pointer to a @ref LL_RTC_TimeTypeDef structure which will be initialized.
372 void LL_RTC_TIME_StructInit(LL_RTC_TimeTypeDef
*RTC_TimeStruct
)
374 /* Time = 00h:00min:00sec */
375 RTC_TimeStruct
->TimeFormat
= LL_RTC_TIME_FORMAT_AM_OR_24
;
376 RTC_TimeStruct
->Hours
= 0U;
377 RTC_TimeStruct
->Minutes
= 0U;
378 RTC_TimeStruct
->Seconds
= 0U;
382 * @brief Set the RTC current date.
383 * @param RTCx RTC Instance
384 * @param RTC_Format This parameter can be one of the following values:
385 * @arg @ref LL_RTC_FORMAT_BIN
386 * @arg @ref LL_RTC_FORMAT_BCD
387 * @param RTC_DateStruct: pointer to a RTC_DateTypeDef structure that contains
388 * the date configuration information for the RTC.
389 * @retval An ErrorStatus enumeration value:
390 * - SUCCESS: RTC Day register is configured
391 * - ERROR: RTC Day register is not configured
393 ErrorStatus
LL_RTC_DATE_Init(RTC_TypeDef
*RTCx
, uint32_t RTC_Format
, LL_RTC_DateTypeDef
*RTC_DateStruct
)
395 ErrorStatus status
= ERROR
;
397 /* Check the parameters */
398 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
399 assert_param(IS_LL_RTC_FORMAT(RTC_Format
));
401 if ((RTC_Format
== LL_RTC_FORMAT_BIN
) && ((RTC_DateStruct
->Month
& 0x10U
) == 0x10U
))
403 RTC_DateStruct
->Month
= (RTC_DateStruct
->Month
& (uint32_t)~(0x10U
)) + 0x0AU
;
405 if (RTC_Format
== LL_RTC_FORMAT_BIN
)
407 assert_param(IS_LL_RTC_YEAR(RTC_DateStruct
->Year
));
408 assert_param(IS_LL_RTC_MONTH(RTC_DateStruct
->Month
));
409 assert_param(IS_LL_RTC_DAY(RTC_DateStruct
->Day
));
413 assert_param(IS_LL_RTC_YEAR(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct
->Year
)));
414 assert_param(IS_LL_RTC_MONTH(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct
->Month
)));
415 assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct
->Day
)));
417 assert_param(IS_LL_RTC_WEEKDAY(RTC_DateStruct
->WeekDay
));
419 /* Disable the write protection for RTC registers */
420 LL_RTC_DisableWriteProtection(RTCx
);
422 /* Set Initialization mode */
423 if (LL_RTC_EnterInitMode(RTCx
) != ERROR
)
425 /* Check the input parameters format */
426 if (RTC_Format
!= LL_RTC_FORMAT_BIN
)
428 LL_RTC_DATE_Config(RTCx
, RTC_DateStruct
->WeekDay
, RTC_DateStruct
->Day
, RTC_DateStruct
->Month
, RTC_DateStruct
->Year
);
432 LL_RTC_DATE_Config(RTCx
, RTC_DateStruct
->WeekDay
, __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct
->Day
),
433 __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct
->Month
), __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct
->Year
));
436 /* Exit Initialization mode */
437 LL_RTC_DisableInitMode(RTC
);
439 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
440 if (LL_RTC_IsShadowRegBypassEnabled(RTCx
) == 0U)
442 status
= LL_RTC_WaitForSynchro(RTCx
);
449 /* Enable the write protection for RTC registers */
450 LL_RTC_EnableWriteProtection(RTCx
);
456 * @brief Set each @ref LL_RTC_DateTypeDef field to default value (date = Monday, January 01 xx00)
457 * @param RTC_DateStruct pointer to a @ref LL_RTC_DateTypeDef structure which will be initialized.
460 void LL_RTC_DATE_StructInit(LL_RTC_DateTypeDef
*RTC_DateStruct
)
462 /* Monday, January 01 xx00 */
463 RTC_DateStruct
->WeekDay
= LL_RTC_WEEKDAY_MONDAY
;
464 RTC_DateStruct
->Day
= 1U;
465 RTC_DateStruct
->Month
= LL_RTC_MONTH_JANUARY
;
466 RTC_DateStruct
->Year
= 0U;
470 * @brief Set the RTC Alarm A.
471 * @note The Alarm register can only be written when the corresponding Alarm
472 * is disabled (Use @ref LL_RTC_ALMA_Disable function).
473 * @param RTCx RTC Instance
474 * @param RTC_Format This parameter can be one of the following values:
475 * @arg @ref LL_RTC_FORMAT_BIN
476 * @arg @ref LL_RTC_FORMAT_BCD
477 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure that
478 * contains the alarm configuration parameters.
479 * @retval An ErrorStatus enumeration value:
480 * - SUCCESS: ALARMA registers are configured
481 * - ERROR: ALARMA registers are not configured
483 ErrorStatus
LL_RTC_ALMA_Init(RTC_TypeDef
*RTCx
, uint32_t RTC_Format
, LL_RTC_AlarmTypeDef
*RTC_AlarmStruct
)
485 /* Check the parameters */
486 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
487 assert_param(IS_LL_RTC_FORMAT(RTC_Format
));
488 assert_param(IS_LL_RTC_ALMA_MASK(RTC_AlarmStruct
->AlarmMask
));
489 assert_param(IS_LL_RTC_ALMA_DATE_WEEKDAY_SEL(RTC_AlarmStruct
->AlarmDateWeekDaySel
));
491 if (RTC_Format
== LL_RTC_FORMAT_BIN
)
493 if (LL_RTC_GetHourFormat(RTCx
) != LL_RTC_HOURFORMAT_24HOUR
)
495 assert_param(IS_LL_RTC_HOUR12(RTC_AlarmStruct
->AlarmTime
.Hours
));
496 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct
->AlarmTime
.TimeFormat
));
500 RTC_AlarmStruct
->AlarmTime
.TimeFormat
= 0x00U
;
501 assert_param(IS_LL_RTC_HOUR24(RTC_AlarmStruct
->AlarmTime
.Hours
));
503 assert_param(IS_LL_RTC_MINUTES(RTC_AlarmStruct
->AlarmTime
.Minutes
));
504 assert_param(IS_LL_RTC_SECONDS(RTC_AlarmStruct
->AlarmTime
.Seconds
));
506 if (RTC_AlarmStruct
->AlarmDateWeekDaySel
== LL_RTC_ALMA_DATEWEEKDAYSEL_DATE
)
508 assert_param(IS_LL_RTC_DAY(RTC_AlarmStruct
->AlarmDateWeekDay
));
512 assert_param(IS_LL_RTC_WEEKDAY(RTC_AlarmStruct
->AlarmDateWeekDay
));
517 if (LL_RTC_GetHourFormat(RTCx
) != LL_RTC_HOURFORMAT_24HOUR
)
519 assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Hours
)));
520 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct
->AlarmTime
.TimeFormat
));
524 RTC_AlarmStruct
->AlarmTime
.TimeFormat
= 0x00U
;
525 assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Hours
)));
528 assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Minutes
)));
529 assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Seconds
)));
531 if (RTC_AlarmStruct
->AlarmDateWeekDaySel
== LL_RTC_ALMA_DATEWEEKDAYSEL_DATE
)
533 assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmDateWeekDay
)));
537 assert_param(IS_LL_RTC_WEEKDAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmDateWeekDay
)));
541 /* Disable the write protection for RTC registers */
542 LL_RTC_DisableWriteProtection(RTCx
);
544 /* Select weekday selection */
545 if (RTC_AlarmStruct
->AlarmDateWeekDaySel
== LL_RTC_ALMA_DATEWEEKDAYSEL_DATE
)
547 /* Set the date for ALARM */
548 LL_RTC_ALMA_DisableWeekday(RTCx
);
549 if (RTC_Format
!= LL_RTC_FORMAT_BIN
)
551 LL_RTC_ALMA_SetDay(RTCx
, RTC_AlarmStruct
->AlarmDateWeekDay
);
555 LL_RTC_ALMA_SetDay(RTCx
, __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmDateWeekDay
));
560 /* Set the week day for ALARM */
561 LL_RTC_ALMA_EnableWeekday(RTCx
);
562 LL_RTC_ALMA_SetWeekDay(RTCx
, RTC_AlarmStruct
->AlarmDateWeekDay
);
565 /* Configure the Alarm register */
566 if (RTC_Format
!= LL_RTC_FORMAT_BIN
)
568 LL_RTC_ALMA_ConfigTime(RTCx
, RTC_AlarmStruct
->AlarmTime
.TimeFormat
, RTC_AlarmStruct
->AlarmTime
.Hours
,
569 RTC_AlarmStruct
->AlarmTime
.Minutes
, RTC_AlarmStruct
->AlarmTime
.Seconds
);
573 LL_RTC_ALMA_ConfigTime(RTCx
, RTC_AlarmStruct
->AlarmTime
.TimeFormat
,
574 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmTime
.Hours
),
575 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmTime
.Minutes
),
576 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmTime
.Seconds
));
579 LL_RTC_ALMA_SetMask(RTCx
, RTC_AlarmStruct
->AlarmMask
);
581 /* Enable the write protection for RTC registers */
582 LL_RTC_EnableWriteProtection(RTCx
);
588 * @brief Set the RTC Alarm B.
589 * @note The Alarm register can only be written when the corresponding Alarm
590 * is disabled (@ref LL_RTC_ALMB_Disable function).
591 * @param RTCx RTC Instance
592 * @param RTC_Format This parameter can be one of the following values:
593 * @arg @ref LL_RTC_FORMAT_BIN
594 * @arg @ref LL_RTC_FORMAT_BCD
595 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure that
596 * contains the alarm configuration parameters.
597 * @retval An ErrorStatus enumeration value:
598 * - SUCCESS: ALARMB registers are configured
599 * - ERROR: ALARMB registers are not configured
601 ErrorStatus
LL_RTC_ALMB_Init(RTC_TypeDef
*RTCx
, uint32_t RTC_Format
, LL_RTC_AlarmTypeDef
*RTC_AlarmStruct
)
603 /* Check the parameters */
604 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
605 assert_param(IS_LL_RTC_FORMAT(RTC_Format
));
606 assert_param(IS_LL_RTC_ALMB_MASK(RTC_AlarmStruct
->AlarmMask
));
607 assert_param(IS_LL_RTC_ALMB_DATE_WEEKDAY_SEL(RTC_AlarmStruct
->AlarmDateWeekDaySel
));
609 if (RTC_Format
== LL_RTC_FORMAT_BIN
)
611 if (LL_RTC_GetHourFormat(RTCx
) != LL_RTC_HOURFORMAT_24HOUR
)
613 assert_param(IS_LL_RTC_HOUR12(RTC_AlarmStruct
->AlarmTime
.Hours
));
614 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct
->AlarmTime
.TimeFormat
));
618 RTC_AlarmStruct
->AlarmTime
.TimeFormat
= 0x00U
;
619 assert_param(IS_LL_RTC_HOUR24(RTC_AlarmStruct
->AlarmTime
.Hours
));
621 assert_param(IS_LL_RTC_MINUTES(RTC_AlarmStruct
->AlarmTime
.Minutes
));
622 assert_param(IS_LL_RTC_SECONDS(RTC_AlarmStruct
->AlarmTime
.Seconds
));
624 if (RTC_AlarmStruct
->AlarmDateWeekDaySel
== LL_RTC_ALMB_DATEWEEKDAYSEL_DATE
)
626 assert_param(IS_LL_RTC_DAY(RTC_AlarmStruct
->AlarmDateWeekDay
));
630 assert_param(IS_LL_RTC_WEEKDAY(RTC_AlarmStruct
->AlarmDateWeekDay
));
635 if (LL_RTC_GetHourFormat(RTCx
) != LL_RTC_HOURFORMAT_24HOUR
)
637 assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Hours
)));
638 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct
->AlarmTime
.TimeFormat
));
642 RTC_AlarmStruct
->AlarmTime
.TimeFormat
= 0x00U
;
643 assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Hours
)));
646 assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Minutes
)));
647 assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Seconds
)));
649 if (RTC_AlarmStruct
->AlarmDateWeekDaySel
== LL_RTC_ALMB_DATEWEEKDAYSEL_DATE
)
651 assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmDateWeekDay
)));
655 assert_param(IS_LL_RTC_WEEKDAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmDateWeekDay
)));
659 /* Disable the write protection for RTC registers */
660 LL_RTC_DisableWriteProtection(RTCx
);
662 /* Select weekday selection */
663 if (RTC_AlarmStruct
->AlarmDateWeekDaySel
== LL_RTC_ALMB_DATEWEEKDAYSEL_DATE
)
665 /* Set the date for ALARM */
666 LL_RTC_ALMB_DisableWeekday(RTCx
);
667 if (RTC_Format
!= LL_RTC_FORMAT_BIN
)
669 LL_RTC_ALMB_SetDay(RTCx
, RTC_AlarmStruct
->AlarmDateWeekDay
);
673 LL_RTC_ALMB_SetDay(RTCx
, __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmDateWeekDay
));
678 /* Set the week day for ALARM */
679 LL_RTC_ALMB_EnableWeekday(RTCx
);
680 LL_RTC_ALMB_SetWeekDay(RTCx
, RTC_AlarmStruct
->AlarmDateWeekDay
);
683 /* Configure the Alarm register */
684 if (RTC_Format
!= LL_RTC_FORMAT_BIN
)
686 LL_RTC_ALMB_ConfigTime(RTCx
, RTC_AlarmStruct
->AlarmTime
.TimeFormat
, RTC_AlarmStruct
->AlarmTime
.Hours
,
687 RTC_AlarmStruct
->AlarmTime
.Minutes
, RTC_AlarmStruct
->AlarmTime
.Seconds
);
691 LL_RTC_ALMB_ConfigTime(RTCx
, RTC_AlarmStruct
->AlarmTime
.TimeFormat
,
692 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmTime
.Hours
),
693 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmTime
.Minutes
),
694 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmTime
.Seconds
));
697 LL_RTC_ALMB_SetMask(RTCx
, RTC_AlarmStruct
->AlarmMask
);
699 /* Enable the write protection for RTC registers */
700 LL_RTC_EnableWriteProtection(RTCx
);
706 * @brief Set each @ref LL_RTC_AlarmTypeDef of ALARMA field to default value (Time = 00h:00mn:00sec /
707 * Day = 1st day of the month/Mask = all fields are masked).
708 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure which will be initialized.
711 void LL_RTC_ALMA_StructInit(LL_RTC_AlarmTypeDef
*RTC_AlarmStruct
)
713 /* Alarm Time Settings : Time = 00h:00mn:00sec */
714 RTC_AlarmStruct
->AlarmTime
.TimeFormat
= LL_RTC_ALMA_TIME_FORMAT_AM
;
715 RTC_AlarmStruct
->AlarmTime
.Hours
= 0U;
716 RTC_AlarmStruct
->AlarmTime
.Minutes
= 0U;
717 RTC_AlarmStruct
->AlarmTime
.Seconds
= 0U;
719 /* Alarm Day Settings : Day = 1st day of the month */
720 RTC_AlarmStruct
->AlarmDateWeekDaySel
= LL_RTC_ALMA_DATEWEEKDAYSEL_DATE
;
721 RTC_AlarmStruct
->AlarmDateWeekDay
= 1U;
723 /* Alarm Masks Settings : Mask = all fields are not masked */
724 RTC_AlarmStruct
->AlarmMask
= LL_RTC_ALMA_MASK_NONE
;
728 * @brief Set each @ref LL_RTC_AlarmTypeDef of ALARMA field to default value (Time = 00h:00mn:00sec /
729 * Day = 1st day of the month/Mask = all fields are masked).
730 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure which will be initialized.
733 void LL_RTC_ALMB_StructInit(LL_RTC_AlarmTypeDef
*RTC_AlarmStruct
)
735 /* Alarm Time Settings : Time = 00h:00mn:00sec */
736 RTC_AlarmStruct
->AlarmTime
.TimeFormat
= LL_RTC_ALMB_TIME_FORMAT_AM
;
737 RTC_AlarmStruct
->AlarmTime
.Hours
= 0U;
738 RTC_AlarmStruct
->AlarmTime
.Minutes
= 0U;
739 RTC_AlarmStruct
->AlarmTime
.Seconds
= 0U;
741 /* Alarm Day Settings : Day = 1st day of the month */
742 RTC_AlarmStruct
->AlarmDateWeekDaySel
= LL_RTC_ALMB_DATEWEEKDAYSEL_DATE
;
743 RTC_AlarmStruct
->AlarmDateWeekDay
= 1U;
745 /* Alarm Masks Settings : Mask = all fields are not masked */
746 RTC_AlarmStruct
->AlarmMask
= LL_RTC_ALMB_MASK_NONE
;
750 * @brief Enters the RTC Initialization mode.
751 * @note The RTC Initialization mode is write protected, use the
752 * @ref LL_RTC_DisableWriteProtection before calling this function.
753 * @param RTCx RTC Instance
754 * @retval An ErrorStatus enumeration value:
755 * - SUCCESS: RTC is in Init mode
756 * - ERROR: RTC is not in Init mode
758 ErrorStatus
LL_RTC_EnterInitMode(RTC_TypeDef
*RTCx
)
760 __IO
uint32_t timeout
= RTC_INITMODE_TIMEOUT
;
761 ErrorStatus status
= SUCCESS
;
764 /* Check the parameter */
765 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
767 /* Check if the Initialization mode is set */
768 if (LL_RTC_IsActiveFlag_INIT(RTCx
) == 0U)
770 /* Set the Initialization mode */
771 LL_RTC_EnableInitMode(RTCx
);
773 /* Wait till RTC is in INIT state and if Time out is reached exit */
774 tmp
= LL_RTC_IsActiveFlag_INIT(RTCx
);
775 while ((timeout
!= 0U) && (tmp
!= 1U))
777 if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
781 tmp
= LL_RTC_IsActiveFlag_INIT(RTCx
);
792 * @brief Exit the RTC Initialization mode.
793 * @note When the initialization sequence is complete, the calendar restarts
794 * counting after 4 RTCCLK cycles.
795 * @note The RTC Initialization mode is write protected, use the
796 * @ref LL_RTC_DisableWriteProtection before calling this function.
797 * @param RTCx RTC Instance
798 * @retval An ErrorStatus enumeration value:
799 * - SUCCESS: RTC exited from in Init mode
800 * - ERROR: Not applicable
802 ErrorStatus
LL_RTC_ExitInitMode(RTC_TypeDef
*RTCx
)
804 /* Check the parameter */
805 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
807 /* Disable initialization mode */
808 LL_RTC_DisableInitMode(RTCx
);
814 * @brief Waits until the RTC Time and Day registers (RTC_TR and RTC_DR) are
815 * synchronized with RTC APB clock.
816 * @note The RTC Resynchronization mode is write protected, use the
817 * @ref LL_RTC_DisableWriteProtection before calling this function.
818 * @note To read the calendar through the shadow registers after Calendar
819 * initialization, calendar update or after wakeup from low power modes
820 * the software must first clear the RSF flag.
821 * The software must then wait until it is set again before reading
822 * the calendar, which means that the calendar registers have been
823 * correctly copied into the RTC_TR and RTC_DR shadow registers.
824 * @param RTCx RTC Instance
825 * @retval An ErrorStatus enumeration value:
826 * - SUCCESS: RTC registers are synchronised
827 * - ERROR: RTC registers are not synchronised
829 ErrorStatus
LL_RTC_WaitForSynchro(RTC_TypeDef
*RTCx
)
831 __IO
uint32_t timeout
= RTC_SYNCHRO_TIMEOUT
;
832 ErrorStatus status
= SUCCESS
;
835 /* Check the parameter */
836 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
839 LL_RTC_ClearFlag_RS(RTCx
);
841 /* Wait the registers to be synchronised */
842 tmp
= LL_RTC_IsActiveFlag_RS(RTCx
);
843 while ((timeout
!= 0U) && (tmp
!= 0U))
845 if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
849 tmp
= LL_RTC_IsActiveFlag_RS(RTCx
);
858 timeout
= RTC_SYNCHRO_TIMEOUT
;
859 tmp
= LL_RTC_IsActiveFlag_RS(RTCx
);
860 while ((timeout
!= 0U) && (tmp
!= 1U))
862 if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
866 tmp
= LL_RTC_IsActiveFlag_RS(RTCx
);
889 #endif /* defined(RTC) */
895 #endif /* USE_FULL_LL_DRIVER */
897 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/