2 ******************************************************************************
3 * @file stm32f4xx_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 "stm32f4xx_ll_rtc.h"
41 #include "stm32f4xx_ll_cortex.h"
42 #ifdef USE_FULL_ASSERT
43 #include "stm32_assert.h"
45 #define assert_param(expr) ((void)0U)
48 /** @addtogroup STM32F4xx_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
, TAFCR
, 0x00000000U
);
206 /* Wait till the RTC RSF flag is set */
207 status
= LL_RTC_WaitForSynchro(RTCx
);
210 /* Enable the write protection for RTC registers */
211 LL_RTC_EnableWriteProtection(RTCx
);
217 * @brief Initializes the RTC registers according to the specified parameters
219 * @param RTCx RTC Instance
220 * @param RTC_InitStruct pointer to a @ref LL_RTC_InitTypeDef structure that contains
221 * the configuration information for the RTC peripheral.
222 * @note The RTC Prescaler register is write protected and can be written in
223 * initialization mode only.
224 * @retval An ErrorStatus enumeration value:
225 * - SUCCESS: RTC registers are initialized
226 * - ERROR: RTC registers are not initialized
228 ErrorStatus
LL_RTC_Init(RTC_TypeDef
*RTCx
, LL_RTC_InitTypeDef
*RTC_InitStruct
)
230 ErrorStatus status
= ERROR
;
232 /* Check the parameters */
233 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
234 assert_param(IS_LL_RTC_HOURFORMAT(RTC_InitStruct
->HourFormat
));
235 assert_param(IS_LL_RTC_ASYNCH_PREDIV(RTC_InitStruct
->AsynchPrescaler
));
236 assert_param(IS_LL_RTC_SYNCH_PREDIV(RTC_InitStruct
->SynchPrescaler
));
238 /* Disable the write protection for RTC registers */
239 LL_RTC_DisableWriteProtection(RTCx
);
241 /* Set Initialization mode */
242 if (LL_RTC_EnterInitMode(RTCx
) != ERROR
)
244 /* Set Hour Format */
245 LL_RTC_SetHourFormat(RTCx
, RTC_InitStruct
->HourFormat
);
247 /* Configure Synchronous and Asynchronous prescaler factor */
248 LL_RTC_SetSynchPrescaler(RTCx
, RTC_InitStruct
->SynchPrescaler
);
249 LL_RTC_SetAsynchPrescaler(RTCx
, RTC_InitStruct
->AsynchPrescaler
);
251 /* Exit Initialization mode */
252 LL_RTC_DisableInitMode(RTCx
);
256 /* Enable the write protection for RTC registers */
257 LL_RTC_EnableWriteProtection(RTCx
);
263 * @brief Set each @ref LL_RTC_InitTypeDef field to default value.
264 * @param RTC_InitStruct pointer to a @ref LL_RTC_InitTypeDef structure which will be initialized.
267 void LL_RTC_StructInit(LL_RTC_InitTypeDef
*RTC_InitStruct
)
269 /* Set RTC_InitStruct fields to default values */
270 RTC_InitStruct
->HourFormat
= LL_RTC_HOURFORMAT_24HOUR
;
271 RTC_InitStruct
->AsynchPrescaler
= RTC_ASYNCH_PRESC_DEFAULT
;
272 RTC_InitStruct
->SynchPrescaler
= RTC_SYNCH_PRESC_DEFAULT
;
276 * @brief Set the RTC current time.
277 * @param RTCx RTC Instance
278 * @param RTC_Format This parameter can be one of the following values:
279 * @arg @ref LL_RTC_FORMAT_BIN
280 * @arg @ref LL_RTC_FORMAT_BCD
281 * @param RTC_TimeStruct pointer to a RTC_TimeTypeDef structure that contains
282 * the time configuration information for the RTC.
283 * @retval An ErrorStatus enumeration value:
284 * - SUCCESS: RTC Time register is configured
285 * - ERROR: RTC Time register is not configured
287 ErrorStatus
LL_RTC_TIME_Init(RTC_TypeDef
*RTCx
, uint32_t RTC_Format
, LL_RTC_TimeTypeDef
*RTC_TimeStruct
)
289 ErrorStatus status
= ERROR
;
291 /* Check the parameters */
292 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
293 assert_param(IS_LL_RTC_FORMAT(RTC_Format
));
295 if (RTC_Format
== LL_RTC_FORMAT_BIN
)
297 if (LL_RTC_GetHourFormat(RTCx
) != LL_RTC_HOURFORMAT_24HOUR
)
299 assert_param(IS_LL_RTC_HOUR12(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(RTC_TimeStruct
->Hours
));
307 assert_param(IS_LL_RTC_MINUTES(RTC_TimeStruct
->Minutes
));
308 assert_param(IS_LL_RTC_SECONDS(RTC_TimeStruct
->Seconds
));
312 if (LL_RTC_GetHourFormat(RTCx
) != LL_RTC_HOURFORMAT_24HOUR
)
314 assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct
->Hours
)));
315 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_TimeStruct
->TimeFormat
));
319 RTC_TimeStruct
->TimeFormat
= 0x00U
;
320 assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct
->Hours
)));
322 assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct
->Minutes
)));
323 assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct
->Seconds
)));
326 /* Disable the write protection for RTC registers */
327 LL_RTC_DisableWriteProtection(RTCx
);
329 /* Set Initialization mode */
330 if (LL_RTC_EnterInitMode(RTCx
) != ERROR
)
332 /* Check the input parameters format */
333 if (RTC_Format
!= LL_RTC_FORMAT_BIN
)
335 LL_RTC_TIME_Config(RTCx
, RTC_TimeStruct
->TimeFormat
, RTC_TimeStruct
->Hours
,
336 RTC_TimeStruct
->Minutes
, RTC_TimeStruct
->Seconds
);
340 LL_RTC_TIME_Config(RTCx
, RTC_TimeStruct
->TimeFormat
, __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct
->Hours
),
341 __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct
->Minutes
),
342 __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct
->Seconds
));
345 /* Exit Initialization mode */
346 LL_RTC_DisableInitMode(RTC
);
348 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
349 if (LL_RTC_IsShadowRegBypassEnabled(RTCx
) == 0U)
351 status
= LL_RTC_WaitForSynchro(RTCx
);
358 /* Enable the write protection for RTC registers */
359 LL_RTC_EnableWriteProtection(RTCx
);
365 * @brief Set each @ref LL_RTC_TimeTypeDef field to default value (Time = 00h:00min:00sec).
366 * @param RTC_TimeStruct pointer to a @ref LL_RTC_TimeTypeDef structure which will be initialized.
369 void LL_RTC_TIME_StructInit(LL_RTC_TimeTypeDef
*RTC_TimeStruct
)
371 /* Time = 00h:00min:00sec */
372 RTC_TimeStruct
->TimeFormat
= LL_RTC_TIME_FORMAT_AM_OR_24
;
373 RTC_TimeStruct
->Hours
= 0U;
374 RTC_TimeStruct
->Minutes
= 0U;
375 RTC_TimeStruct
->Seconds
= 0U;
379 * @brief Set the RTC current date.
380 * @param RTCx RTC Instance
381 * @param RTC_Format This parameter can be one of the following values:
382 * @arg @ref LL_RTC_FORMAT_BIN
383 * @arg @ref LL_RTC_FORMAT_BCD
384 * @param RTC_DateStruct: pointer to a RTC_DateTypeDef structure that contains
385 * the date configuration information for the RTC.
386 * @retval An ErrorStatus enumeration value:
387 * - SUCCESS: RTC Day register is configured
388 * - ERROR: RTC Day register is not configured
390 ErrorStatus
LL_RTC_DATE_Init(RTC_TypeDef
*RTCx
, uint32_t RTC_Format
, LL_RTC_DateTypeDef
*RTC_DateStruct
)
392 ErrorStatus status
= ERROR
;
394 /* Check the parameters */
395 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
396 assert_param(IS_LL_RTC_FORMAT(RTC_Format
));
398 if ((RTC_Format
== LL_RTC_FORMAT_BIN
) && ((RTC_DateStruct
->Month
& 0x10U
) == 0x10U
))
400 RTC_DateStruct
->Month
= (RTC_DateStruct
->Month
& (uint32_t)~(0x10U
)) + 0x0AU
;
402 if (RTC_Format
== LL_RTC_FORMAT_BIN
)
404 assert_param(IS_LL_RTC_YEAR(RTC_DateStruct
->Year
));
405 assert_param(IS_LL_RTC_MONTH(RTC_DateStruct
->Month
));
406 assert_param(IS_LL_RTC_DAY(RTC_DateStruct
->Day
));
410 assert_param(IS_LL_RTC_YEAR(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct
->Year
)));
411 assert_param(IS_LL_RTC_MONTH(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct
->Month
)));
412 assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct
->Day
)));
414 assert_param(IS_LL_RTC_WEEKDAY(RTC_DateStruct
->WeekDay
));
416 /* Disable the write protection for RTC registers */
417 LL_RTC_DisableWriteProtection(RTCx
);
419 /* Set Initialization mode */
420 if (LL_RTC_EnterInitMode(RTCx
) != ERROR
)
422 /* Check the input parameters format */
423 if (RTC_Format
!= LL_RTC_FORMAT_BIN
)
425 LL_RTC_DATE_Config(RTCx
, RTC_DateStruct
->WeekDay
, RTC_DateStruct
->Day
, RTC_DateStruct
->Month
, RTC_DateStruct
->Year
);
429 LL_RTC_DATE_Config(RTCx
, RTC_DateStruct
->WeekDay
, __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct
->Day
),
430 __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct
->Month
), __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct
->Year
));
433 /* Exit Initialization mode */
434 LL_RTC_DisableInitMode(RTC
);
436 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
437 if (LL_RTC_IsShadowRegBypassEnabled(RTCx
) == 0U)
439 status
= LL_RTC_WaitForSynchro(RTCx
);
446 /* Enable the write protection for RTC registers */
447 LL_RTC_EnableWriteProtection(RTCx
);
453 * @brief Set each @ref LL_RTC_DateTypeDef field to default value (date = Monday, January 01 xx00)
454 * @param RTC_DateStruct pointer to a @ref LL_RTC_DateTypeDef structure which will be initialized.
457 void LL_RTC_DATE_StructInit(LL_RTC_DateTypeDef
*RTC_DateStruct
)
459 /* Monday, January 01 xx00 */
460 RTC_DateStruct
->WeekDay
= LL_RTC_WEEKDAY_MONDAY
;
461 RTC_DateStruct
->Day
= 1U;
462 RTC_DateStruct
->Month
= LL_RTC_MONTH_JANUARY
;
463 RTC_DateStruct
->Year
= 0U;
467 * @brief Set the RTC Alarm A.
468 * @note The Alarm register can only be written when the corresponding Alarm
469 * is disabled (Use @ref LL_RTC_ALMA_Disable function).
470 * @param RTCx RTC Instance
471 * @param RTC_Format This parameter can be one of the following values:
472 * @arg @ref LL_RTC_FORMAT_BIN
473 * @arg @ref LL_RTC_FORMAT_BCD
474 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure that
475 * contains the alarm configuration parameters.
476 * @retval An ErrorStatus enumeration value:
477 * - SUCCESS: ALARMA registers are configured
478 * - ERROR: ALARMA registers are not configured
480 ErrorStatus
LL_RTC_ALMA_Init(RTC_TypeDef
*RTCx
, uint32_t RTC_Format
, LL_RTC_AlarmTypeDef
*RTC_AlarmStruct
)
482 /* Check the parameters */
483 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
484 assert_param(IS_LL_RTC_FORMAT(RTC_Format
));
485 assert_param(IS_LL_RTC_ALMA_MASK(RTC_AlarmStruct
->AlarmMask
));
486 assert_param(IS_LL_RTC_ALMA_DATE_WEEKDAY_SEL(RTC_AlarmStruct
->AlarmDateWeekDaySel
));
488 if (RTC_Format
== LL_RTC_FORMAT_BIN
)
490 if (LL_RTC_GetHourFormat(RTCx
) != LL_RTC_HOURFORMAT_24HOUR
)
492 assert_param(IS_LL_RTC_HOUR12(RTC_AlarmStruct
->AlarmTime
.Hours
));
493 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct
->AlarmTime
.TimeFormat
));
497 RTC_AlarmStruct
->AlarmTime
.TimeFormat
= 0x00U
;
498 assert_param(IS_LL_RTC_HOUR24(RTC_AlarmStruct
->AlarmTime
.Hours
));
500 assert_param(IS_LL_RTC_MINUTES(RTC_AlarmStruct
->AlarmTime
.Minutes
));
501 assert_param(IS_LL_RTC_SECONDS(RTC_AlarmStruct
->AlarmTime
.Seconds
));
503 if (RTC_AlarmStruct
->AlarmDateWeekDaySel
== LL_RTC_ALMA_DATEWEEKDAYSEL_DATE
)
505 assert_param(IS_LL_RTC_DAY(RTC_AlarmStruct
->AlarmDateWeekDay
));
509 assert_param(IS_LL_RTC_WEEKDAY(RTC_AlarmStruct
->AlarmDateWeekDay
));
514 if (LL_RTC_GetHourFormat(RTCx
) != LL_RTC_HOURFORMAT_24HOUR
)
516 assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Hours
)));
517 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct
->AlarmTime
.TimeFormat
));
521 RTC_AlarmStruct
->AlarmTime
.TimeFormat
= 0x00U
;
522 assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Hours
)));
525 assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Minutes
)));
526 assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Seconds
)));
528 if (RTC_AlarmStruct
->AlarmDateWeekDaySel
== LL_RTC_ALMA_DATEWEEKDAYSEL_DATE
)
530 assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmDateWeekDay
)));
534 assert_param(IS_LL_RTC_WEEKDAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmDateWeekDay
)));
538 /* Disable the write protection for RTC registers */
539 LL_RTC_DisableWriteProtection(RTCx
);
541 /* Select weekday selection */
542 if (RTC_AlarmStruct
->AlarmDateWeekDaySel
== LL_RTC_ALMA_DATEWEEKDAYSEL_DATE
)
544 /* Set the date for ALARM */
545 LL_RTC_ALMA_DisableWeekday(RTCx
);
546 if (RTC_Format
!= LL_RTC_FORMAT_BIN
)
548 LL_RTC_ALMA_SetDay(RTCx
, RTC_AlarmStruct
->AlarmDateWeekDay
);
552 LL_RTC_ALMA_SetDay(RTCx
, __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmDateWeekDay
));
557 /* Set the week day for ALARM */
558 LL_RTC_ALMA_EnableWeekday(RTCx
);
559 LL_RTC_ALMA_SetWeekDay(RTCx
, RTC_AlarmStruct
->AlarmDateWeekDay
);
562 /* Configure the Alarm register */
563 if (RTC_Format
!= LL_RTC_FORMAT_BIN
)
565 LL_RTC_ALMA_ConfigTime(RTCx
, RTC_AlarmStruct
->AlarmTime
.TimeFormat
, RTC_AlarmStruct
->AlarmTime
.Hours
,
566 RTC_AlarmStruct
->AlarmTime
.Minutes
, RTC_AlarmStruct
->AlarmTime
.Seconds
);
570 LL_RTC_ALMA_ConfigTime(RTCx
, RTC_AlarmStruct
->AlarmTime
.TimeFormat
,
571 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmTime
.Hours
),
572 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmTime
.Minutes
),
573 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmTime
.Seconds
));
576 LL_RTC_ALMA_SetMask(RTCx
, RTC_AlarmStruct
->AlarmMask
);
578 /* Enable the write protection for RTC registers */
579 LL_RTC_EnableWriteProtection(RTCx
);
585 * @brief Set the RTC Alarm B.
586 * @note The Alarm register can only be written when the corresponding Alarm
587 * is disabled (@ref LL_RTC_ALMB_Disable function).
588 * @param RTCx RTC Instance
589 * @param RTC_Format This parameter can be one of the following values:
590 * @arg @ref LL_RTC_FORMAT_BIN
591 * @arg @ref LL_RTC_FORMAT_BCD
592 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure that
593 * contains the alarm configuration parameters.
594 * @retval An ErrorStatus enumeration value:
595 * - SUCCESS: ALARMB registers are configured
596 * - ERROR: ALARMB registers are not configured
598 ErrorStatus
LL_RTC_ALMB_Init(RTC_TypeDef
*RTCx
, uint32_t RTC_Format
, LL_RTC_AlarmTypeDef
*RTC_AlarmStruct
)
600 /* Check the parameters */
601 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
602 assert_param(IS_LL_RTC_FORMAT(RTC_Format
));
603 assert_param(IS_LL_RTC_ALMB_MASK(RTC_AlarmStruct
->AlarmMask
));
604 assert_param(IS_LL_RTC_ALMB_DATE_WEEKDAY_SEL(RTC_AlarmStruct
->AlarmDateWeekDaySel
));
606 if (RTC_Format
== LL_RTC_FORMAT_BIN
)
608 if (LL_RTC_GetHourFormat(RTCx
) != LL_RTC_HOURFORMAT_24HOUR
)
610 assert_param(IS_LL_RTC_HOUR12(RTC_AlarmStruct
->AlarmTime
.Hours
));
611 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct
->AlarmTime
.TimeFormat
));
615 RTC_AlarmStruct
->AlarmTime
.TimeFormat
= 0x00U
;
616 assert_param(IS_LL_RTC_HOUR24(RTC_AlarmStruct
->AlarmTime
.Hours
));
618 assert_param(IS_LL_RTC_MINUTES(RTC_AlarmStruct
->AlarmTime
.Minutes
));
619 assert_param(IS_LL_RTC_SECONDS(RTC_AlarmStruct
->AlarmTime
.Seconds
));
621 if (RTC_AlarmStruct
->AlarmDateWeekDaySel
== LL_RTC_ALMB_DATEWEEKDAYSEL_DATE
)
623 assert_param(IS_LL_RTC_DAY(RTC_AlarmStruct
->AlarmDateWeekDay
));
627 assert_param(IS_LL_RTC_WEEKDAY(RTC_AlarmStruct
->AlarmDateWeekDay
));
632 if (LL_RTC_GetHourFormat(RTCx
) != LL_RTC_HOURFORMAT_24HOUR
)
634 assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Hours
)));
635 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct
->AlarmTime
.TimeFormat
));
639 RTC_AlarmStruct
->AlarmTime
.TimeFormat
= 0x00U
;
640 assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Hours
)));
643 assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Minutes
)));
644 assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmTime
.Seconds
)));
646 if (RTC_AlarmStruct
->AlarmDateWeekDaySel
== LL_RTC_ALMB_DATEWEEKDAYSEL_DATE
)
648 assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmDateWeekDay
)));
652 assert_param(IS_LL_RTC_WEEKDAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct
->AlarmDateWeekDay
)));
656 /* Disable the write protection for RTC registers */
657 LL_RTC_DisableWriteProtection(RTCx
);
659 /* Select weekday selection */
660 if (RTC_AlarmStruct
->AlarmDateWeekDaySel
== LL_RTC_ALMB_DATEWEEKDAYSEL_DATE
)
662 /* Set the date for ALARM */
663 LL_RTC_ALMB_DisableWeekday(RTCx
);
664 if (RTC_Format
!= LL_RTC_FORMAT_BIN
)
666 LL_RTC_ALMB_SetDay(RTCx
, RTC_AlarmStruct
->AlarmDateWeekDay
);
670 LL_RTC_ALMB_SetDay(RTCx
, __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmDateWeekDay
));
675 /* Set the week day for ALARM */
676 LL_RTC_ALMB_EnableWeekday(RTCx
);
677 LL_RTC_ALMB_SetWeekDay(RTCx
, RTC_AlarmStruct
->AlarmDateWeekDay
);
680 /* Configure the Alarm register */
681 if (RTC_Format
!= LL_RTC_FORMAT_BIN
)
683 LL_RTC_ALMB_ConfigTime(RTCx
, RTC_AlarmStruct
->AlarmTime
.TimeFormat
, RTC_AlarmStruct
->AlarmTime
.Hours
,
684 RTC_AlarmStruct
->AlarmTime
.Minutes
, RTC_AlarmStruct
->AlarmTime
.Seconds
);
688 LL_RTC_ALMB_ConfigTime(RTCx
, RTC_AlarmStruct
->AlarmTime
.TimeFormat
,
689 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmTime
.Hours
),
690 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmTime
.Minutes
),
691 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct
->AlarmTime
.Seconds
));
694 LL_RTC_ALMB_SetMask(RTCx
, RTC_AlarmStruct
->AlarmMask
);
696 /* Enable the write protection for RTC registers */
697 LL_RTC_EnableWriteProtection(RTCx
);
703 * @brief Set each @ref LL_RTC_AlarmTypeDef of ALARMA field to default value (Time = 00h:00mn:00sec /
704 * Day = 1st day of the month/Mask = all fields are masked).
705 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure which will be initialized.
708 void LL_RTC_ALMA_StructInit(LL_RTC_AlarmTypeDef
*RTC_AlarmStruct
)
710 /* Alarm Time Settings : Time = 00h:00mn:00sec */
711 RTC_AlarmStruct
->AlarmTime
.TimeFormat
= LL_RTC_ALMA_TIME_FORMAT_AM
;
712 RTC_AlarmStruct
->AlarmTime
.Hours
= 0U;
713 RTC_AlarmStruct
->AlarmTime
.Minutes
= 0U;
714 RTC_AlarmStruct
->AlarmTime
.Seconds
= 0U;
716 /* Alarm Day Settings : Day = 1st day of the month */
717 RTC_AlarmStruct
->AlarmDateWeekDaySel
= LL_RTC_ALMA_DATEWEEKDAYSEL_DATE
;
718 RTC_AlarmStruct
->AlarmDateWeekDay
= 1U;
720 /* Alarm Masks Settings : Mask = all fields are not masked */
721 RTC_AlarmStruct
->AlarmMask
= LL_RTC_ALMA_MASK_NONE
;
725 * @brief Set each @ref LL_RTC_AlarmTypeDef of ALARMA field to default value (Time = 00h:00mn:00sec /
726 * Day = 1st day of the month/Mask = all fields are masked).
727 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure which will be initialized.
730 void LL_RTC_ALMB_StructInit(LL_RTC_AlarmTypeDef
*RTC_AlarmStruct
)
732 /* Alarm Time Settings : Time = 00h:00mn:00sec */
733 RTC_AlarmStruct
->AlarmTime
.TimeFormat
= LL_RTC_ALMB_TIME_FORMAT_AM
;
734 RTC_AlarmStruct
->AlarmTime
.Hours
= 0U;
735 RTC_AlarmStruct
->AlarmTime
.Minutes
= 0U;
736 RTC_AlarmStruct
->AlarmTime
.Seconds
= 0U;
738 /* Alarm Day Settings : Day = 1st day of the month */
739 RTC_AlarmStruct
->AlarmDateWeekDaySel
= LL_RTC_ALMB_DATEWEEKDAYSEL_DATE
;
740 RTC_AlarmStruct
->AlarmDateWeekDay
= 1U;
742 /* Alarm Masks Settings : Mask = all fields are not masked */
743 RTC_AlarmStruct
->AlarmMask
= LL_RTC_ALMB_MASK_NONE
;
747 * @brief Enters the RTC Initialization mode.
748 * @note The RTC Initialization mode is write protected, use the
749 * @ref LL_RTC_DisableWriteProtection before calling this function.
750 * @param RTCx RTC Instance
751 * @retval An ErrorStatus enumeration value:
752 * - SUCCESS: RTC is in Init mode
753 * - ERROR: RTC is not in Init mode
755 ErrorStatus
LL_RTC_EnterInitMode(RTC_TypeDef
*RTCx
)
757 __IO
uint32_t timeout
= RTC_INITMODE_TIMEOUT
;
758 ErrorStatus status
= SUCCESS
;
761 /* Check the parameter */
762 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
764 /* Check if the Initialization mode is set */
765 if (LL_RTC_IsActiveFlag_INIT(RTCx
) == 0U)
767 /* Set the Initialization mode */
768 LL_RTC_EnableInitMode(RTCx
);
770 /* Wait till RTC is in INIT state and if Time out is reached exit */
771 tmp
= LL_RTC_IsActiveFlag_INIT(RTCx
);
772 while ((timeout
!= 0U) && (tmp
!= 1U))
774 if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
778 tmp
= LL_RTC_IsActiveFlag_INIT(RTCx
);
789 * @brief Exit the RTC Initialization mode.
790 * @note When the initialization sequence is complete, the calendar restarts
791 * counting after 4 RTCCLK cycles.
792 * @note The RTC Initialization mode is write protected, use the
793 * @ref LL_RTC_DisableWriteProtection before calling this function.
794 * @param RTCx RTC Instance
795 * @retval An ErrorStatus enumeration value:
796 * - SUCCESS: RTC exited from in Init mode
797 * - ERROR: Not applicable
799 ErrorStatus
LL_RTC_ExitInitMode(RTC_TypeDef
*RTCx
)
801 /* Check the parameter */
802 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
804 /* Disable initialization mode */
805 LL_RTC_DisableInitMode(RTCx
);
811 * @brief Waits until the RTC Time and Day registers (RTC_TR and RTC_DR) are
812 * synchronized with RTC APB clock.
813 * @note The RTC Resynchronization mode is write protected, use the
814 * @ref LL_RTC_DisableWriteProtection before calling this function.
815 * @note To read the calendar through the shadow registers after Calendar
816 * initialization, calendar update or after wakeup from low power modes
817 * the software must first clear the RSF flag.
818 * The software must then wait until it is set again before reading
819 * the calendar, which means that the calendar registers have been
820 * correctly copied into the RTC_TR and RTC_DR shadow registers.
821 * @param RTCx RTC Instance
822 * @retval An ErrorStatus enumeration value:
823 * - SUCCESS: RTC registers are synchronised
824 * - ERROR: RTC registers are not synchronised
826 ErrorStatus
LL_RTC_WaitForSynchro(RTC_TypeDef
*RTCx
)
828 __IO
uint32_t timeout
= RTC_SYNCHRO_TIMEOUT
;
829 ErrorStatus status
= SUCCESS
;
832 /* Check the parameter */
833 assert_param(IS_RTC_ALL_INSTANCE(RTCx
));
836 LL_RTC_ClearFlag_RS(RTCx
);
838 /* Wait the registers to be synchronised */
839 tmp
= LL_RTC_IsActiveFlag_RS(RTCx
);
840 while ((timeout
!= 0U) && (tmp
!= 0U))
842 if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
846 tmp
= LL_RTC_IsActiveFlag_RS(RTCx
);
855 timeout
= RTC_SYNCHRO_TIMEOUT
;
856 tmp
= LL_RTC_IsActiveFlag_RS(RTCx
);
857 while ((timeout
!= 0U) && (tmp
!= 1U))
859 if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
863 tmp
= LL_RTC_IsActiveFlag_RS(RTCx
);
886 #endif /* defined(RTC) */
892 #endif /* USE_FULL_LL_DRIVER */
894 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/