2 ******************************************************************************
3 * @file stm32f7xx_ll_rtc.c
4 * @author MCD Application Team
5 * @brief RTC LL module driver.
6 ******************************************************************************
9 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.</center></h2>
12 * This software component is licensed by ST 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
17 ******************************************************************************
19 #if defined(USE_FULL_LL_DRIVER)
21 /* Includes ------------------------------------------------------------------*/
22 #include "stm32f7xx_ll_rtc.h"
23 #include "stm32f7xx_ll_cortex.h"
24 #ifdef USE_FULL_ASSERT
25 #include "stm32_assert.h"
27 #define assert_param(expr) ((void)0U)
30 /** @addtogroup STM32F7xx_LL_Driver
36 /** @addtogroup RTC_LL
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42 /* Private constants ---------------------------------------------------------*/
43 /** @addtogroup RTC_LL_Private_Constants
46 /* Default values used for prescaler */
47 #define RTC_ASYNCH_PRESC_DEFAULT 0x0000007FU
48 #define RTC_SYNCH_PRESC_DEFAULT 0x000000FFU
50 /* Values used for timeout */
51 #define RTC_INITMODE_TIMEOUT 1000U /* 1s when tick set to 1ms */
52 #define RTC_SYNCHRO_TIMEOUT 1000U /* 1s when tick set to 1ms */
57 /* Private macros ------------------------------------------------------------*/
58 /** @addtogroup RTC_LL_Private_Macros
62 #define IS_LL_RTC_HOURFORMAT(__VALUE__) (((__VALUE__) == LL_RTC_HOURFORMAT_24HOUR) \
63 || ((__VALUE__) == LL_RTC_HOURFORMAT_AMPM))
65 #define IS_LL_RTC_ASYNCH_PREDIV(__VALUE__) ((__VALUE__) <= 0x7FU)
67 #define IS_LL_RTC_SYNCH_PREDIV(__VALUE__) ((__VALUE__) <= 0x7FFFU)
69 #define IS_LL_RTC_FORMAT(__VALUE__) (((__VALUE__) == LL_RTC_FORMAT_BIN) \
70 || ((__VALUE__) == LL_RTC_FORMAT_BCD))
72 #define IS_LL_RTC_TIME_FORMAT(__VALUE__) (((__VALUE__) == LL_RTC_TIME_FORMAT_AM_OR_24) \
73 || ((__VALUE__) == LL_RTC_TIME_FORMAT_PM))
75 #define IS_LL_RTC_HOUR12(__HOUR__) (((__HOUR__) > 0U) && ((__HOUR__) <= 12U))
76 #define IS_LL_RTC_HOUR24(__HOUR__) ((__HOUR__) <= 23U)
77 #define IS_LL_RTC_MINUTES(__MINUTES__) ((__MINUTES__) <= 59U)
78 #define IS_LL_RTC_SECONDS(__SECONDS__) ((__SECONDS__) <= 59U)
80 #define IS_LL_RTC_WEEKDAY(__VALUE__) (((__VALUE__) == LL_RTC_WEEKDAY_MONDAY) \
81 || ((__VALUE__) == LL_RTC_WEEKDAY_TUESDAY) \
82 || ((__VALUE__) == LL_RTC_WEEKDAY_WEDNESDAY) \
83 || ((__VALUE__) == LL_RTC_WEEKDAY_THURSDAY) \
84 || ((__VALUE__) == LL_RTC_WEEKDAY_FRIDAY) \
85 || ((__VALUE__) == LL_RTC_WEEKDAY_SATURDAY) \
86 || ((__VALUE__) == LL_RTC_WEEKDAY_SUNDAY))
88 #define IS_LL_RTC_DAY(__DAY__) (((__DAY__) >= 1U) && ((__DAY__) <= 31U))
90 #define IS_LL_RTC_MONTH(__VALUE__) (((__VALUE__) == LL_RTC_MONTH_JANUARY) \
91 || ((__VALUE__) == LL_RTC_MONTH_FEBRUARY) \
92 || ((__VALUE__) == LL_RTC_MONTH_MARCH) \
93 || ((__VALUE__) == LL_RTC_MONTH_APRIL) \
94 || ((__VALUE__) == LL_RTC_MONTH_MAY) \
95 || ((__VALUE__) == LL_RTC_MONTH_JUNE) \
96 || ((__VALUE__) == LL_RTC_MONTH_JULY) \
97 || ((__VALUE__) == LL_RTC_MONTH_AUGUST) \
98 || ((__VALUE__) == LL_RTC_MONTH_SEPTEMBER) \
99 || ((__VALUE__) == LL_RTC_MONTH_OCTOBER) \
100 || ((__VALUE__) == LL_RTC_MONTH_NOVEMBER) \
101 || ((__VALUE__) == LL_RTC_MONTH_DECEMBER))
103 #define IS_LL_RTC_YEAR(__YEAR__) ((__YEAR__) <= 99U)
105 #define IS_LL_RTC_ALMA_MASK(__VALUE__) (((__VALUE__) == LL_RTC_ALMA_MASK_NONE) \
106 || ((__VALUE__) == LL_RTC_ALMA_MASK_DATEWEEKDAY) \
107 || ((__VALUE__) == LL_RTC_ALMA_MASK_HOURS) \
108 || ((__VALUE__) == LL_RTC_ALMA_MASK_MINUTES) \
109 || ((__VALUE__) == LL_RTC_ALMA_MASK_SECONDS) \
110 || ((__VALUE__) == LL_RTC_ALMA_MASK_ALL))
112 #define IS_LL_RTC_ALMB_MASK(__VALUE__) (((__VALUE__) == LL_RTC_ALMB_MASK_NONE) \
113 || ((__VALUE__) == LL_RTC_ALMB_MASK_DATEWEEKDAY) \
114 || ((__VALUE__) == LL_RTC_ALMB_MASK_HOURS) \
115 || ((__VALUE__) == LL_RTC_ALMB_MASK_MINUTES) \
116 || ((__VALUE__) == LL_RTC_ALMB_MASK_SECONDS) \
117 || ((__VALUE__) == LL_RTC_ALMB_MASK_ALL))
120 #define IS_LL_RTC_ALMA_DATE_WEEKDAY_SEL(__SEL__) (((__SEL__) == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE) || \
121 ((__SEL__) == LL_RTC_ALMA_DATEWEEKDAYSEL_WEEKDAY))
123 #define IS_LL_RTC_ALMB_DATE_WEEKDAY_SEL(__SEL__) (((__SEL__) == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE) || \
124 ((__SEL__) == LL_RTC_ALMB_DATEWEEKDAYSEL_WEEKDAY))
130 /* Private function prototypes -----------------------------------------------*/
131 /* Exported functions --------------------------------------------------------*/
132 /** @addtogroup RTC_LL_Exported_Functions
136 /** @addtogroup RTC_LL_EF_Init
141 * @brief De-Initializes the RTC registers to their default reset values.
142 * @note This function doesn't reset the RTC Clock source and RTC Backup Data
144 * @param RTCx RTC Instance
145 * @retval An ErrorStatus enumeration value:
146 * - SUCCESS: RTC registers are de-initialized
147 * - ERROR: RTC registers are not de-initialized
149 ErrorStatus
LL_RTC_DeInit(RTC_TypeDef
*RTCx
)
151 ErrorStatus status
= ERROR
;
153 /* Check the parameter */
154 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
156 /* Disable the write protection for RTC registers */
157 LL_RTC_DisableWriteProtection(RTCx
);
159 /* Set Initialization mode */
160 if (LL_RTC_EnterInitMode(RTCx
) != ERROR
)
162 /* Reset TR, DR and CR registers */
163 LL_RTC_WriteReg(RTCx
, TR
, 0x00000000U
);
164 #if defined(RTC_WAKEUP_SUPPORT)
165 LL_RTC_WriteReg(RTCx
, WUTR
, RTC_WUTR_WUT
);
166 #endif /* RTC_WAKEUP_SUPPORT */
167 LL_RTC_WriteReg(RTCx
, DR
, (RTC_DR_WDU_0
| RTC_DR_MU_0
| RTC_DR_DU_0
));
168 /* Reset All CR bits except CR[2:0] */
169 #if defined(RTC_WAKEUP_SUPPORT)
170 LL_RTC_WriteReg(RTCx
, CR
, (LL_RTC_ReadReg(RTCx
, CR
) & RTC_CR_WUCKSEL
));
172 LL_RTC_WriteReg(RTCx
, CR
, 0x00000000U
);
173 #endif /* RTC_WAKEUP_SUPPORT */
174 LL_RTC_WriteReg(RTCx
, PRER
, (RTC_PRER_PREDIV_A
| RTC_SYNCH_PRESC_DEFAULT
));
175 LL_RTC_WriteReg(RTCx
, ALRMAR
, 0x00000000U
);
176 LL_RTC_WriteReg(RTCx
, ALRMBR
, 0x00000000U
);
177 LL_RTC_WriteReg(RTCx
, SHIFTR
, 0x00000000U
);
178 LL_RTC_WriteReg(RTCx
, CALR
, 0x00000000U
);
179 LL_RTC_WriteReg(RTCx
, ALRMASSR
, 0x00000000U
);
180 LL_RTC_WriteReg(RTCx
, ALRMBSSR
, 0x00000000U
);
182 /* Reset ISR register and exit initialization mode */
183 LL_RTC_WriteReg(RTCx
, ISR
, 0x00000000U
);
185 /* Reset Tamper and alternate functions configuration register */
186 LL_RTC_WriteReg(RTCx
, TAMPCR
, 0x00000000U
);
188 /* Reset Option register */
189 LL_RTC_WriteReg(RTCx
, OR
, 0x00000000U
);
191 /* Wait till the RTC RSF flag is set */
192 status
= LL_RTC_WaitForSynchro(RTCx
);
195 /* Enable the write protection for RTC registers */
196 LL_RTC_EnableWriteProtection(RTCx
);
202 * @brief Initializes the RTC registers according to the specified parameters
204 * @param RTCx RTC Instance
205 * @param RTC_InitStruct pointer to a @ref LL_RTC_InitTypeDef structure that contains
206 * the configuration information for the RTC peripheral.
207 * @note The RTC Prescaler register is write protected and can be written in
208 * initialization mode only.
209 * @retval An ErrorStatus enumeration value:
210 * - SUCCESS: RTC registers are initialized
211 * - ERROR: RTC registers are not initialized
213 ErrorStatus
LL_RTC_Init(RTC_TypeDef
*RTCx
, LL_RTC_InitTypeDef
*RTC_InitStruct
)
215 ErrorStatus status
= ERROR
;
217 /* Check the parameters */
218 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
219 assert_param(IS_LL_RTC_HOURFORMAT(RTC_InitStruct
->HourFormat
));
220 assert_param(IS_LL_RTC_ASYNCH_PREDIV(RTC_InitStruct
->AsynchPrescaler
));
221 assert_param(IS_LL_RTC_SYNCH_PREDIV(RTC_InitStruct
->SynchPrescaler
));
223 /* Disable the write protection for RTC registers */
224 LL_RTC_DisableWriteProtection(RTCx
);
226 /* Set Initialization mode */
227 if (LL_RTC_EnterInitMode(RTCx
) != ERROR
)
229 /* Set Hour Format */
230 LL_RTC_SetHourFormat(RTCx
, RTC_InitStruct
->HourFormat
);
232 /* Configure Synchronous and Asynchronous prescaler factor */
233 LL_RTC_SetSynchPrescaler(RTCx
, RTC_InitStruct
->SynchPrescaler
);
234 LL_RTC_SetAsynchPrescaler(RTCx
, RTC_InitStruct
->AsynchPrescaler
);
236 /* Exit Initialization mode */
237 LL_RTC_DisableInitMode(RTCx
);
241 /* Enable the write protection for RTC registers */
242 LL_RTC_EnableWriteProtection(RTCx
);
248 * @brief Set each @ref LL_RTC_InitTypeDef field to default value.
249 * @param RTC_InitStruct pointer to a @ref LL_RTC_InitTypeDef structure which will be initialized.
252 void LL_RTC_StructInit(LL_RTC_InitTypeDef
*RTC_InitStruct
)
254 /* Set RTC_InitStruct fields to default values */
255 RTC_InitStruct
->HourFormat
= LL_RTC_HOURFORMAT_24HOUR
;
256 RTC_InitStruct
->AsynchPrescaler
= RTC_ASYNCH_PRESC_DEFAULT
;
257 RTC_InitStruct
->SynchPrescaler
= RTC_SYNCH_PRESC_DEFAULT
;
261 * @brief Set the RTC current time.
262 * @param RTCx RTC Instance
263 * @param RTC_Format This parameter can be one of the following values:
264 * @arg @ref LL_RTC_FORMAT_BIN
265 * @arg @ref LL_RTC_FORMAT_BCD
266 * @param RTC_TimeStruct pointer to a RTC_TimeTypeDef structure that contains
267 * the time configuration information for the RTC.
268 * @retval An ErrorStatus enumeration value:
269 * - SUCCESS: RTC Time register is configured
270 * - ERROR: RTC Time register is not configured
272 ErrorStatus
LL_RTC_TIME_Init(RTC_TypeDef
*RTCx
, uint32_t RTC_Format
, LL_RTC_TimeTypeDef
*RTC_TimeStruct
)
274 ErrorStatus status
= ERROR
;
276 /* Check the parameters */
277 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
278 assert_param(IS_LL_RTC_FORMAT(RTC_Format
));
280 if (RTC_Format
== LL_RTC_FORMAT_BIN
)
282 if (LL_RTC_GetHourFormat(RTCx
) != LL_RTC_HOURFORMAT_24HOUR
)
284 assert_param(IS_LL_RTC_HOUR12(RTC_TimeStruct
->Hours
));
285 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_TimeStruct
->TimeFormat
));
289 RTC_TimeStruct
->TimeFormat
= 0x00U
;
290 assert_param(IS_LL_RTC_HOUR24(RTC_TimeStruct
->Hours
));
292 assert_param(IS_LL_RTC_MINUTES(RTC_TimeStruct
->Minutes
));
293 assert_param(IS_LL_RTC_SECONDS(RTC_TimeStruct
->Seconds
));
297 if (LL_RTC_GetHourFormat(RTCx
) != LL_RTC_HOURFORMAT_24HOUR
)
299 assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct
->Hours
)));
300 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_TimeStruct
->TimeFormat
));
304 RTC_TimeStruct
->TimeFormat
= 0x00U
;
305 assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct
->Hours
)));
307 assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct
->Minutes
)));
308 assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct
->Seconds
)));
311 /* Disable the write protection for RTC registers */
312 LL_RTC_DisableWriteProtection(RTCx
);
314 /* Set Initialization mode */
315 if (LL_RTC_EnterInitMode(RTCx
) != ERROR
)
317 /* Check the input parameters format */
318 if (RTC_Format
!= LL_RTC_FORMAT_BIN
)
320 LL_RTC_TIME_Config(RTCx
, RTC_TimeStruct
->TimeFormat
, RTC_TimeStruct
->Hours
,
321 RTC_TimeStruct
->Minutes
, RTC_TimeStruct
->Seconds
);
325 LL_RTC_TIME_Config(RTCx
, RTC_TimeStruct
->TimeFormat
, __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct
->Hours
),
326 __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct
->Minutes
),
327 __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct
->Seconds
));
330 /* Exit Initialization mode */
331 LL_RTC_DisableInitMode(RTC
);
333 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
334 if (LL_RTC_IsShadowRegBypassEnabled(RTCx
) == 0U)
336 status
= LL_RTC_WaitForSynchro(RTCx
);
343 /* Enable the write protection for RTC registers */
344 LL_RTC_EnableWriteProtection(RTCx
);
350 * @brief Set each @ref LL_RTC_TimeTypeDef field to default value (Time = 00h:00min:00sec).
351 * @param RTC_TimeStruct pointer to a @ref LL_RTC_TimeTypeDef structure which will be initialized.
354 void LL_RTC_TIME_StructInit(LL_RTC_TimeTypeDef
*RTC_TimeStruct
)
356 /* Time = 00h:00min:00sec */
357 RTC_TimeStruct
->TimeFormat
= LL_RTC_TIME_FORMAT_AM_OR_24
;
358 RTC_TimeStruct
->Hours
= 0U;
359 RTC_TimeStruct
->Minutes
= 0U;
360 RTC_TimeStruct
->Seconds
= 0U;
364 * @brief Set the RTC current date.
365 * @param RTCx RTC Instance
366 * @param RTC_Format This parameter can be one of the following values:
367 * @arg @ref LL_RTC_FORMAT_BIN
368 * @arg @ref LL_RTC_FORMAT_BCD
369 * @param RTC_DateStruct pointer to a RTC_DateTypeDef structure that contains
370 * the date configuration information for the RTC.
371 * @retval An ErrorStatus enumeration value:
372 * - SUCCESS: RTC Day register is configured
373 * - ERROR: RTC Day register is not configured
375 ErrorStatus
LL_RTC_DATE_Init(RTC_TypeDef
*RTCx
, uint32_t RTC_Format
, LL_RTC_DateTypeDef
*RTC_DateStruct
)
377 ErrorStatus status
= ERROR
;
379 /* Check the parameters */
380 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
381 assert_param(IS_LL_RTC_FORMAT(RTC_Format
));
383 if ((RTC_Format
== LL_RTC_FORMAT_BIN
) && ((RTC_DateStruct
->Month
& 0x10U
) == 0x10U
))
385 RTC_DateStruct
->Month
= (RTC_DateStruct
->Month
& (uint32_t)~(0x10U
)) + 0x0AU
;
387 if (RTC_Format
== LL_RTC_FORMAT_BIN
)
389 assert_param(IS_LL_RTC_YEAR(RTC_DateStruct
->Year
));
390 assert_param(IS_LL_RTC_MONTH(RTC_DateStruct
->Month
));
391 assert_param(IS_LL_RTC_DAY(RTC_DateStruct
->Day
));
395 assert_param(IS_LL_RTC_YEAR(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct
->Year
)));
396 assert_param(IS_LL_RTC_MONTH(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct
->Month
)));
397 assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct
->Day
)));
399 assert_param(IS_LL_RTC_WEEKDAY(RTC_DateStruct
->WeekDay
));
401 /* Disable the write protection for RTC registers */
402 LL_RTC_DisableWriteProtection(RTCx
);
404 /* Set Initialization mode */
405 if (LL_RTC_EnterInitMode(RTCx
) != ERROR
)
407 /* Check the input parameters format */
408 if (RTC_Format
!= LL_RTC_FORMAT_BIN
)
410 LL_RTC_DATE_Config(RTCx
, RTC_DateStruct
->WeekDay
, RTC_DateStruct
->Day
, RTC_DateStruct
->Month
, RTC_DateStruct
->Year
);
414 LL_RTC_DATE_Config(RTCx
, RTC_DateStruct
->WeekDay
, __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct
->Day
),
415 __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct
->Month
), __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct
->Year
));
418 /* Exit Initialization mode */
419 LL_RTC_DisableInitMode(RTC
);
421 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
422 if (LL_RTC_IsShadowRegBypassEnabled(RTCx
) == 0U)
424 status
= LL_RTC_WaitForSynchro(RTCx
);
431 /* Enable the write protection for RTC registers */
432 LL_RTC_EnableWriteProtection(RTCx
);
438 * @brief Set each @ref LL_RTC_DateTypeDef field to default value (date = Monday, January 01 xx00)
439 * @param RTC_DateStruct pointer to a @ref LL_RTC_DateTypeDef structure which will be initialized.
442 void LL_RTC_DATE_StructInit(LL_RTC_DateTypeDef
*RTC_DateStruct
)
444 /* Monday, January 01 xx00 */
445 RTC_DateStruct
->WeekDay
= LL_RTC_WEEKDAY_MONDAY
;
446 RTC_DateStruct
->Day
= 1U;
447 RTC_DateStruct
->Month
= LL_RTC_MONTH_JANUARY
;
448 RTC_DateStruct
->Year
= 0U;
452 * @brief Set the RTC Alarm A.
453 * @note The Alarm register can only be written when the corresponding Alarm
454 * is disabled (Use @ref LL_RTC_ALMA_Disable function).
455 * @param RTCx RTC Instance
456 * @param RTC_Format This parameter can be one of the following values:
457 * @arg @ref LL_RTC_FORMAT_BIN
458 * @arg @ref LL_RTC_FORMAT_BCD
459 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure that
460 * contains the alarm configuration parameters.
461 * @retval An ErrorStatus enumeration value:
462 * - SUCCESS: ALARMA registers are configured
463 * - ERROR: ALARMA registers are not configured
465 ErrorStatus
LL_RTC_ALMA_Init(RTC_TypeDef
*RTCx
, uint32_t RTC_Format
, LL_RTC_AlarmTypeDef
*RTC_AlarmStruct
)
467 /* Check the parameters */
468 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
469 assert_param(IS_LL_RTC_FORMAT(RTC_Format
));
470 assert_param(IS_LL_RTC_ALMA_MASK(RTC_AlarmStruct
->AlarmMask
));
471 assert_param(IS_LL_RTC_ALMA_DATE_WEEKDAY_SEL(RTC_AlarmStruct
->AlarmDateWeekDaySel
));
473 if (RTC_Format
== LL_RTC_FORMAT_BIN
)
475 if (LL_RTC_GetHourFormat(RTCx
) != LL_RTC_HOURFORMAT_24HOUR
)
477 assert_param(IS_LL_RTC_HOUR12(RTC_AlarmStruct
->AlarmTime
.Hours
));
478 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct
->AlarmTime
.TimeFormat
));
482 RTC_AlarmStruct
->AlarmTime
.TimeFormat
= 0x00U
;
483 assert_param(IS_LL_RTC_HOUR24(RTC_AlarmStruct
->AlarmTime
.Hours
));
485 assert_param(IS_LL_RTC_MINUTES(RTC_AlarmStruct
->AlarmTime
.Minutes
));
486 assert_param(IS_LL_RTC_SECONDS(RTC_AlarmStruct
->AlarmTime
.Seconds
));
488 if (RTC_AlarmStruct
->AlarmDateWeekDaySel
== LL_RTC_ALMA_DATEWEEKDAYSEL_DATE
)
490 assert_param(IS_LL_RTC_DAY(RTC_AlarmStruct
->AlarmDateWeekDay
));
494 assert_param(IS_LL_RTC_WEEKDAY(RTC_AlarmStruct
->AlarmDateWeekDay
));
499 if (LL_RTC_GetHourFormat(RTCx
) != LL_RTC_HOURFORMAT_24HOUR
)
501 assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Hours
)));
502 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct
->AlarmTime
.TimeFormat
));
506 RTC_AlarmStruct
->AlarmTime
.TimeFormat
= 0x00U
;
507 assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Hours
)));
510 assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Minutes
)));
511 assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Seconds
)));
513 if (RTC_AlarmStruct
->AlarmDateWeekDaySel
== LL_RTC_ALMA_DATEWEEKDAYSEL_DATE
)
515 assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmDateWeekDay
)));
519 assert_param(IS_LL_RTC_WEEKDAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmDateWeekDay
)));
523 /* Disable the write protection for RTC registers */
524 LL_RTC_DisableWriteProtection(RTCx
);
526 /* Select weekday selection */
527 if (RTC_AlarmStruct
->AlarmDateWeekDaySel
== LL_RTC_ALMA_DATEWEEKDAYSEL_DATE
)
529 /* Set the date for ALARM */
530 LL_RTC_ALMA_DisableWeekday(RTCx
);
531 if (RTC_Format
!= LL_RTC_FORMAT_BIN
)
533 LL_RTC_ALMA_SetDay(RTCx
, RTC_AlarmStruct
->AlarmDateWeekDay
);
537 LL_RTC_ALMA_SetDay(RTCx
, __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmDateWeekDay
));
542 /* Set the week day for ALARM */
543 LL_RTC_ALMA_EnableWeekday(RTCx
);
544 LL_RTC_ALMA_SetWeekDay(RTCx
, RTC_AlarmStruct
->AlarmDateWeekDay
);
547 /* Configure the Alarm register */
548 if (RTC_Format
!= LL_RTC_FORMAT_BIN
)
550 LL_RTC_ALMA_ConfigTime(RTCx
, RTC_AlarmStruct
->AlarmTime
.TimeFormat
, RTC_AlarmStruct
->AlarmTime
.Hours
,
551 RTC_AlarmStruct
->AlarmTime
.Minutes
, RTC_AlarmStruct
->AlarmTime
.Seconds
);
555 LL_RTC_ALMA_ConfigTime(RTCx
, RTC_AlarmStruct
->AlarmTime
.TimeFormat
,
556 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmTime
.Hours
),
557 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmTime
.Minutes
),
558 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmTime
.Seconds
));
561 LL_RTC_ALMA_SetMask(RTCx
, RTC_AlarmStruct
->AlarmMask
);
563 /* Enable the write protection for RTC registers */
564 LL_RTC_EnableWriteProtection(RTCx
);
570 * @brief Set the RTC Alarm B.
571 * @note The Alarm register can only be written when the corresponding Alarm
572 * is disabled (@ref LL_RTC_ALMB_Disable function).
573 * @param RTCx RTC Instance
574 * @param RTC_Format This parameter can be one of the following values:
575 * @arg @ref LL_RTC_FORMAT_BIN
576 * @arg @ref LL_RTC_FORMAT_BCD
577 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure that
578 * contains the alarm configuration parameters.
579 * @retval An ErrorStatus enumeration value:
580 * - SUCCESS: ALARMB registers are configured
581 * - ERROR: ALARMB registers are not configured
583 ErrorStatus
LL_RTC_ALMB_Init(RTC_TypeDef
*RTCx
, uint32_t RTC_Format
, LL_RTC_AlarmTypeDef
*RTC_AlarmStruct
)
585 /* Check the parameters */
586 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
587 assert_param(IS_LL_RTC_FORMAT(RTC_Format
));
588 assert_param(IS_LL_RTC_ALMB_MASK(RTC_AlarmStruct
->AlarmMask
));
589 assert_param(IS_LL_RTC_ALMB_DATE_WEEKDAY_SEL(RTC_AlarmStruct
->AlarmDateWeekDaySel
));
591 if (RTC_Format
== LL_RTC_FORMAT_BIN
)
593 if (LL_RTC_GetHourFormat(RTCx
) != LL_RTC_HOURFORMAT_24HOUR
)
595 assert_param(IS_LL_RTC_HOUR12(RTC_AlarmStruct
->AlarmTime
.Hours
));
596 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct
->AlarmTime
.TimeFormat
));
600 RTC_AlarmStruct
->AlarmTime
.TimeFormat
= 0x00U
;
601 assert_param(IS_LL_RTC_HOUR24(RTC_AlarmStruct
->AlarmTime
.Hours
));
603 assert_param(IS_LL_RTC_MINUTES(RTC_AlarmStruct
->AlarmTime
.Minutes
));
604 assert_param(IS_LL_RTC_SECONDS(RTC_AlarmStruct
->AlarmTime
.Seconds
));
606 if (RTC_AlarmStruct
->AlarmDateWeekDaySel
== LL_RTC_ALMB_DATEWEEKDAYSEL_DATE
)
608 assert_param(IS_LL_RTC_DAY(RTC_AlarmStruct
->AlarmDateWeekDay
));
612 assert_param(IS_LL_RTC_WEEKDAY(RTC_AlarmStruct
->AlarmDateWeekDay
));
617 if (LL_RTC_GetHourFormat(RTCx
) != LL_RTC_HOURFORMAT_24HOUR
)
619 assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Hours
)));
620 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct
->AlarmTime
.TimeFormat
));
624 RTC_AlarmStruct
->AlarmTime
.TimeFormat
= 0x00U
;
625 assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Hours
)));
628 assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Minutes
)));
629 assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Seconds
)));
631 if (RTC_AlarmStruct
->AlarmDateWeekDaySel
== LL_RTC_ALMB_DATEWEEKDAYSEL_DATE
)
633 assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmDateWeekDay
)));
637 assert_param(IS_LL_RTC_WEEKDAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmDateWeekDay
)));
641 /* Disable the write protection for RTC registers */
642 LL_RTC_DisableWriteProtection(RTCx
);
644 /* Select weekday selection */
645 if (RTC_AlarmStruct
->AlarmDateWeekDaySel
== LL_RTC_ALMB_DATEWEEKDAYSEL_DATE
)
647 /* Set the date for ALARM */
648 LL_RTC_ALMB_DisableWeekday(RTCx
);
649 if (RTC_Format
!= LL_RTC_FORMAT_BIN
)
651 LL_RTC_ALMB_SetDay(RTCx
, RTC_AlarmStruct
->AlarmDateWeekDay
);
655 LL_RTC_ALMB_SetDay(RTCx
, __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmDateWeekDay
));
660 /* Set the week day for ALARM */
661 LL_RTC_ALMB_EnableWeekday(RTCx
);
662 LL_RTC_ALMB_SetWeekDay(RTCx
, RTC_AlarmStruct
->AlarmDateWeekDay
);
665 /* Configure the Alarm register */
666 if (RTC_Format
!= LL_RTC_FORMAT_BIN
)
668 LL_RTC_ALMB_ConfigTime(RTCx
, RTC_AlarmStruct
->AlarmTime
.TimeFormat
, RTC_AlarmStruct
->AlarmTime
.Hours
,
669 RTC_AlarmStruct
->AlarmTime
.Minutes
, RTC_AlarmStruct
->AlarmTime
.Seconds
);
673 LL_RTC_ALMB_ConfigTime(RTCx
, RTC_AlarmStruct
->AlarmTime
.TimeFormat
,
674 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmTime
.Hours
),
675 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmTime
.Minutes
),
676 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmTime
.Seconds
));
679 LL_RTC_ALMB_SetMask(RTCx
, RTC_AlarmStruct
->AlarmMask
);
681 /* Enable the write protection for RTC registers */
682 LL_RTC_EnableWriteProtection(RTCx
);
688 * @brief Set each @ref LL_RTC_AlarmTypeDef of ALARMA field to default value (Time = 00h:00mn:00sec /
689 * Day = 1st day of the month/Mask = all fields are masked).
690 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure which will be initialized.
693 void LL_RTC_ALMA_StructInit(LL_RTC_AlarmTypeDef
*RTC_AlarmStruct
)
695 /* Alarm Time Settings : Time = 00h:00mn:00sec */
696 RTC_AlarmStruct
->AlarmTime
.TimeFormat
= LL_RTC_ALMA_TIME_FORMAT_AM
;
697 RTC_AlarmStruct
->AlarmTime
.Hours
= 0U;
698 RTC_AlarmStruct
->AlarmTime
.Minutes
= 0U;
699 RTC_AlarmStruct
->AlarmTime
.Seconds
= 0U;
701 /* Alarm Day Settings : Day = 1st day of the month */
702 RTC_AlarmStruct
->AlarmDateWeekDaySel
= LL_RTC_ALMA_DATEWEEKDAYSEL_DATE
;
703 RTC_AlarmStruct
->AlarmDateWeekDay
= 1U;
705 /* Alarm Masks Settings : Mask = all fields are not masked */
706 RTC_AlarmStruct
->AlarmMask
= LL_RTC_ALMA_MASK_NONE
;
710 * @brief Set each @ref LL_RTC_AlarmTypeDef of ALARMA field to default value (Time = 00h:00mn:00sec /
711 * Day = 1st day of the month/Mask = all fields are masked).
712 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure which will be initialized.
715 void LL_RTC_ALMB_StructInit(LL_RTC_AlarmTypeDef
*RTC_AlarmStruct
)
717 /* Alarm Time Settings : Time = 00h:00mn:00sec */
718 RTC_AlarmStruct
->AlarmTime
.TimeFormat
= LL_RTC_ALMB_TIME_FORMAT_AM
;
719 RTC_AlarmStruct
->AlarmTime
.Hours
= 0U;
720 RTC_AlarmStruct
->AlarmTime
.Minutes
= 0U;
721 RTC_AlarmStruct
->AlarmTime
.Seconds
= 0U;
723 /* Alarm Day Settings : Day = 1st day of the month */
724 RTC_AlarmStruct
->AlarmDateWeekDaySel
= LL_RTC_ALMB_DATEWEEKDAYSEL_DATE
;
725 RTC_AlarmStruct
->AlarmDateWeekDay
= 1U;
727 /* Alarm Masks Settings : Mask = all fields are not masked */
728 RTC_AlarmStruct
->AlarmMask
= LL_RTC_ALMB_MASK_NONE
;
732 * @brief Enters the RTC Initialization mode.
733 * @note The RTC Initialization mode is write protected, use the
734 * @ref LL_RTC_DisableWriteProtection before calling this function.
735 * @param RTCx RTC Instance
736 * @retval An ErrorStatus enumeration value:
737 * - SUCCESS: RTC is in Init mode
738 * - ERROR: RTC is not in Init mode
740 ErrorStatus
LL_RTC_EnterInitMode(RTC_TypeDef
*RTCx
)
742 __IO
uint32_t timeout
= RTC_INITMODE_TIMEOUT
;
743 ErrorStatus status
= SUCCESS
;
746 /* Check the parameter */
747 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
749 /* Check if the Initialization mode is set */
750 if (LL_RTC_IsActiveFlag_INIT(RTCx
) == 0U)
752 /* Set the Initialization mode */
753 LL_RTC_EnableInitMode(RTCx
);
755 /* Wait till RTC is in INIT state and if Time out is reached exit */
756 tmp
= LL_RTC_IsActiveFlag_INIT(RTCx
);
757 while ((timeout
!= 0U) && (tmp
!= 1U))
759 if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
763 tmp
= LL_RTC_IsActiveFlag_INIT(RTCx
);
774 * @brief Exit the RTC Initialization mode.
775 * @note When the initialization sequence is complete, the calendar restarts
776 * counting after 4 RTCCLK cycles.
777 * @note The RTC Initialization mode is write protected, use the
778 * @ref LL_RTC_DisableWriteProtection before calling this function.
779 * @param RTCx RTC Instance
780 * @retval An ErrorStatus enumeration value:
781 * - SUCCESS: RTC exited from in Init mode
782 * - ERROR: Not applicable
784 ErrorStatus
LL_RTC_ExitInitMode(RTC_TypeDef
*RTCx
)
786 /* Check the parameter */
787 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
789 /* Disable initialization mode */
790 LL_RTC_DisableInitMode(RTCx
);
796 * @brief Waits until the RTC Time and Day registers (RTC_TR and RTC_DR) are
797 * synchronized with RTC APB clock.
798 * @note The RTC Resynchronization mode is write protected, use the
799 * @ref LL_RTC_DisableWriteProtection before calling this function.
800 * @note To read the calendar through the shadow registers after Calendar
801 * initialization, calendar update or after wakeup from low power modes
802 * the software must first clear the RSF flag.
803 * The software must then wait until it is set again before reading
804 * the calendar, which means that the calendar registers have been
805 * correctly copied into the RTC_TR and RTC_DR shadow registers.
806 * @param RTCx RTC Instance
807 * @retval An ErrorStatus enumeration value:
808 * - SUCCESS: RTC registers are synchronised
809 * - ERROR: RTC registers are not synchronised
811 ErrorStatus
LL_RTC_WaitForSynchro(RTC_TypeDef
*RTCx
)
813 __IO
uint32_t timeout
= RTC_SYNCHRO_TIMEOUT
;
814 ErrorStatus status
= SUCCESS
;
817 /* Check the parameter */
818 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
821 LL_RTC_ClearFlag_RS(RTCx
);
823 /* Wait the registers to be synchronised */
824 tmp
= LL_RTC_IsActiveFlag_RS(RTCx
);
825 while ((timeout
!= 0U) && (tmp
!= 0U))
827 if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
831 tmp
= LL_RTC_IsActiveFlag_RS(RTCx
);
840 timeout
= RTC_SYNCHRO_TIMEOUT
;
841 tmp
= LL_RTC_IsActiveFlag_RS(RTCx
);
842 while ((timeout
!= 0U) && (tmp
!= 1U))
844 if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
848 tmp
= LL_RTC_IsActiveFlag_RS(RTCx
);
871 #endif /* defined(RTC) */
877 #endif /* USE_FULL_LL_DRIVER */
879 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/