Merge pull request #11189 from klutvott123/move-telemetry-displayport-init
[betaflight.git] / lib / main / STM32F3 / Drivers / STM32F3xx_HAL_Driver / Src / stm32f3xx_ll_rtc.c
blobc26cc8d7a5a5425ab874e17176b5db07b060259f
1 /**
2 ******************************************************************************
3 * @file stm32f3xx_ll_rtc.c
4 * @author MCD Application Team
5 * @brief RTC LL module driver.
6 ******************************************************************************
7 * @attention
9 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
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.
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.
33 ******************************************************************************
35 #if defined(USE_FULL_LL_DRIVER)
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f3xx_ll_rtc.h"
39 #include "stm32f3xx_ll_cortex.h"
40 #ifdef USE_FULL_ASSERT
41 #include "stm32_assert.h"
42 #else
43 #define assert_param(expr) ((void)0U)
44 #endif
46 /** @addtogroup STM32F3xx_LL_Driver
47 * @{
50 #if defined(RTC)
52 /** @addtogroup RTC_LL
53 * @{
56 /* Private types -------------------------------------------------------------*/
57 /* Private variables ---------------------------------------------------------*/
58 /* Private constants ---------------------------------------------------------*/
59 /** @addtogroup RTC_LL_Private_Constants
60 * @{
62 /* Default values used for prescaler */
63 #define RTC_ASYNCH_PRESC_DEFAULT 0x0000007FU
64 #define RTC_SYNCH_PRESC_DEFAULT 0x000000FFU
66 /* Values used for timeout */
67 #define RTC_INITMODE_TIMEOUT 1000U /* 1s when tick set to 1ms */
68 #define RTC_SYNCHRO_TIMEOUT 1000U /* 1s when tick set to 1ms */
69 /**
70 * @}
73 /* Private macros ------------------------------------------------------------*/
74 /** @addtogroup RTC_LL_Private_Macros
75 * @{
78 #define IS_LL_RTC_HOURFORMAT(__VALUE__) (((__VALUE__) == LL_RTC_HOURFORMAT_24HOUR) \
79 || ((__VALUE__) == LL_RTC_HOURFORMAT_AMPM))
81 #define IS_LL_RTC_ASYNCH_PREDIV(__VALUE__) ((__VALUE__) <= 0x7FU)
83 #define IS_LL_RTC_SYNCH_PREDIV(__VALUE__) ((__VALUE__) <= 0x7FFFU)
85 #define IS_LL_RTC_FORMAT(__VALUE__) (((__VALUE__) == LL_RTC_FORMAT_BIN) \
86 || ((__VALUE__) == LL_RTC_FORMAT_BCD))
88 #define IS_LL_RTC_TIME_FORMAT(__VALUE__) (((__VALUE__) == LL_RTC_TIME_FORMAT_AM_OR_24) \
89 || ((__VALUE__) == LL_RTC_TIME_FORMAT_PM))
91 #define IS_LL_RTC_HOUR12(__HOUR__) (((__HOUR__) > 0U) && ((__HOUR__) <= 12U))
92 #define IS_LL_RTC_HOUR24(__HOUR__) ((__HOUR__) <= 23U)
93 #define IS_LL_RTC_MINUTES(__MINUTES__) ((__MINUTES__) <= 59U)
94 #define IS_LL_RTC_SECONDS(__SECONDS__) ((__SECONDS__) <= 59U)
96 #define IS_LL_RTC_WEEKDAY(__VALUE__) (((__VALUE__) == LL_RTC_WEEKDAY_MONDAY) \
97 || ((__VALUE__) == LL_RTC_WEEKDAY_TUESDAY) \
98 || ((__VALUE__) == LL_RTC_WEEKDAY_WEDNESDAY) \
99 || ((__VALUE__) == LL_RTC_WEEKDAY_THURSDAY) \
100 || ((__VALUE__) == LL_RTC_WEEKDAY_FRIDAY) \
101 || ((__VALUE__) == LL_RTC_WEEKDAY_SATURDAY) \
102 || ((__VALUE__) == LL_RTC_WEEKDAY_SUNDAY))
104 #define IS_LL_RTC_DAY(__DAY__) (((__DAY__) >= 1U) && ((__DAY__) <= 31U))
106 #define IS_LL_RTC_MONTH(__VALUE__) (((__VALUE__) == LL_RTC_MONTH_JANUARY) \
107 || ((__VALUE__) == LL_RTC_MONTH_FEBRUARY) \
108 || ((__VALUE__) == LL_RTC_MONTH_MARCH) \
109 || ((__VALUE__) == LL_RTC_MONTH_APRIL) \
110 || ((__VALUE__) == LL_RTC_MONTH_MAY) \
111 || ((__VALUE__) == LL_RTC_MONTH_JUNE) \
112 || ((__VALUE__) == LL_RTC_MONTH_JULY) \
113 || ((__VALUE__) == LL_RTC_MONTH_AUGUST) \
114 || ((__VALUE__) == LL_RTC_MONTH_SEPTEMBER) \
115 || ((__VALUE__) == LL_RTC_MONTH_OCTOBER) \
116 || ((__VALUE__) == LL_RTC_MONTH_NOVEMBER) \
117 || ((__VALUE__) == LL_RTC_MONTH_DECEMBER))
119 #define IS_LL_RTC_YEAR(__YEAR__) ((__YEAR__) <= 99U)
121 #define IS_LL_RTC_ALMA_MASK(__VALUE__) (((__VALUE__) == LL_RTC_ALMA_MASK_NONE) \
122 || ((__VALUE__) == LL_RTC_ALMA_MASK_DATEWEEKDAY) \
123 || ((__VALUE__) == LL_RTC_ALMA_MASK_HOURS) \
124 || ((__VALUE__) == LL_RTC_ALMA_MASK_MINUTES) \
125 || ((__VALUE__) == LL_RTC_ALMA_MASK_SECONDS) \
126 || ((__VALUE__) == LL_RTC_ALMA_MASK_ALL))
128 #define IS_LL_RTC_ALMB_MASK(__VALUE__) (((__VALUE__) == LL_RTC_ALMB_MASK_NONE) \
129 || ((__VALUE__) == LL_RTC_ALMB_MASK_DATEWEEKDAY) \
130 || ((__VALUE__) == LL_RTC_ALMB_MASK_HOURS) \
131 || ((__VALUE__) == LL_RTC_ALMB_MASK_MINUTES) \
132 || ((__VALUE__) == LL_RTC_ALMB_MASK_SECONDS) \
133 || ((__VALUE__) == LL_RTC_ALMB_MASK_ALL))
136 #define IS_LL_RTC_ALMA_DATE_WEEKDAY_SEL(__SEL__) (((__SEL__) == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE) || \
137 ((__SEL__) == LL_RTC_ALMA_DATEWEEKDAYSEL_WEEKDAY))
139 #define IS_LL_RTC_ALMB_DATE_WEEKDAY_SEL(__SEL__) (((__SEL__) == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE) || \
140 ((__SEL__) == LL_RTC_ALMB_DATEWEEKDAYSEL_WEEKDAY))
144 * @}
146 /* Private function prototypes -----------------------------------------------*/
147 /* Exported functions --------------------------------------------------------*/
148 /** @addtogroup RTC_LL_Exported_Functions
149 * @{
152 /** @addtogroup RTC_LL_EF_Init
153 * @{
157 * @brief De-Initializes the RTC registers to their default reset values.
158 * @note This function doesn't reset the RTC Clock source and RTC Backup Data
159 * registers.
160 * @param RTCx RTC Instance
161 * @retval An ErrorStatus enumeration value:
162 * - SUCCESS: RTC registers are de-initialized
163 * - ERROR: RTC registers are not de-initialized
165 ErrorStatus LL_RTC_DeInit(RTC_TypeDef *RTCx)
167 ErrorStatus status = ERROR;
169 /* Check the parameter */
170 assert_param(IS_RTC_ALL_INSTANCE(RTCx));
172 /* Disable the write protection for RTC registers */
173 LL_RTC_DisableWriteProtection(RTCx);
175 /* Set Initialization mode */
176 if (LL_RTC_EnterInitMode(RTCx) != ERROR)
178 /* Reset TR, DR and CR registers */
179 LL_RTC_WriteReg(RTCx, TR, 0x00000000U);
180 #if defined(RTC_WAKEUP_SUPPORT)
181 LL_RTC_WriteReg(RTCx, WUTR, RTC_WUTR_WUT);
182 #endif /* RTC_WAKEUP_SUPPORT */
183 LL_RTC_WriteReg(RTCx, DR , (RTC_DR_WDU_0 | RTC_DR_MU_0 | RTC_DR_DU_0));
184 /* Reset All CR bits except CR[2:0] */
185 #if defined(RTC_WAKEUP_SUPPORT)
186 LL_RTC_WriteReg(RTCx, CR, (LL_RTC_ReadReg(RTCx, CR) & RTC_CR_WUCKSEL));
187 #else
188 LL_RTC_WriteReg(RTCx, CR, 0x00000000U);
189 #endif /* RTC_WAKEUP_SUPPORT */
190 LL_RTC_WriteReg(RTCx, PRER, (RTC_PRER_PREDIV_A | RTC_SYNCH_PRESC_DEFAULT));
191 LL_RTC_WriteReg(RTCx, ALRMAR, 0x00000000U);
192 LL_RTC_WriteReg(RTCx, ALRMBR, 0x00000000U);
193 LL_RTC_WriteReg(RTCx, SHIFTR, 0x00000000U);
194 LL_RTC_WriteReg(RTCx, CALR, 0x00000000U);
195 LL_RTC_WriteReg(RTCx, ALRMASSR, 0x00000000U);
196 LL_RTC_WriteReg(RTCx, ALRMBSSR, 0x00000000U);
198 /* Reset ISR register and exit initialization mode */
199 LL_RTC_WriteReg(RTCx, ISR, 0x00000000U);
201 /* Reset Tamper and alternate functions configuration register */
202 LL_RTC_WriteReg(RTCx, TAFCR, 0x00000000U);
204 /* Wait till the RTC RSF flag is set */
205 status = LL_RTC_WaitForSynchro(RTCx);
208 /* Enable the write protection for RTC registers */
209 LL_RTC_EnableWriteProtection(RTCx);
211 return status;
215 * @brief Initializes the RTC registers according to the specified parameters
216 * in RTC_InitStruct.
217 * @param RTCx RTC Instance
218 * @param RTC_InitStruct pointer to a @ref LL_RTC_InitTypeDef structure that contains
219 * the configuration information for the RTC peripheral.
220 * @note The RTC Prescaler register is write protected and can be written in
221 * initialization mode only.
222 * @retval An ErrorStatus enumeration value:
223 * - SUCCESS: RTC registers are initialized
224 * - ERROR: RTC registers are not initialized
226 ErrorStatus LL_RTC_Init(RTC_TypeDef *RTCx, LL_RTC_InitTypeDef *RTC_InitStruct)
228 ErrorStatus status = ERROR;
230 /* Check the parameters */
231 assert_param(IS_RTC_ALL_INSTANCE(RTCx));
232 assert_param(IS_LL_RTC_HOURFORMAT(RTC_InitStruct->HourFormat));
233 assert_param(IS_LL_RTC_ASYNCH_PREDIV(RTC_InitStruct->AsynchPrescaler));
234 assert_param(IS_LL_RTC_SYNCH_PREDIV(RTC_InitStruct->SynchPrescaler));
236 /* Disable the write protection for RTC registers */
237 LL_RTC_DisableWriteProtection(RTCx);
239 /* Set Initialization mode */
240 if (LL_RTC_EnterInitMode(RTCx) != ERROR)
242 /* Set Hour Format */
243 LL_RTC_SetHourFormat(RTCx, RTC_InitStruct->HourFormat);
245 /* Configure Synchronous and Asynchronous prescaler factor */
246 LL_RTC_SetSynchPrescaler(RTCx, RTC_InitStruct->SynchPrescaler);
247 LL_RTC_SetAsynchPrescaler(RTCx, RTC_InitStruct->AsynchPrescaler);
249 /* Exit Initialization mode */
250 LL_RTC_DisableInitMode(RTCx);
252 status = SUCCESS;
254 /* Enable the write protection for RTC registers */
255 LL_RTC_EnableWriteProtection(RTCx);
257 return status;
261 * @brief Set each @ref LL_RTC_InitTypeDef field to default value.
262 * @param RTC_InitStruct pointer to a @ref LL_RTC_InitTypeDef structure which will be initialized.
263 * @retval None
265 void LL_RTC_StructInit(LL_RTC_InitTypeDef *RTC_InitStruct)
267 /* Set RTC_InitStruct fields to default values */
268 RTC_InitStruct->HourFormat = LL_RTC_HOURFORMAT_24HOUR;
269 RTC_InitStruct->AsynchPrescaler = RTC_ASYNCH_PRESC_DEFAULT;
270 RTC_InitStruct->SynchPrescaler = RTC_SYNCH_PRESC_DEFAULT;
274 * @brief Set the RTC current time.
275 * @param RTCx RTC Instance
276 * @param RTC_Format This parameter can be one of the following values:
277 * @arg @ref LL_RTC_FORMAT_BIN
278 * @arg @ref LL_RTC_FORMAT_BCD
279 * @param RTC_TimeStruct pointer to a RTC_TimeTypeDef structure that contains
280 * the time configuration information for the RTC.
281 * @retval An ErrorStatus enumeration value:
282 * - SUCCESS: RTC Time register is configured
283 * - ERROR: RTC Time register is not configured
285 ErrorStatus LL_RTC_TIME_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_TimeTypeDef *RTC_TimeStruct)
287 ErrorStatus status = ERROR;
289 /* Check the parameters */
290 assert_param(IS_RTC_ALL_INSTANCE(RTCx));
291 assert_param(IS_LL_RTC_FORMAT(RTC_Format));
293 if (RTC_Format == LL_RTC_FORMAT_BIN)
295 if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR)
297 assert_param(IS_LL_RTC_HOUR12(RTC_TimeStruct->Hours));
298 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_TimeStruct->TimeFormat));
300 else
302 RTC_TimeStruct->TimeFormat = 0x00U;
303 assert_param(IS_LL_RTC_HOUR24(RTC_TimeStruct->Hours));
305 assert_param(IS_LL_RTC_MINUTES(RTC_TimeStruct->Minutes));
306 assert_param(IS_LL_RTC_SECONDS(RTC_TimeStruct->Seconds));
308 else
310 if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR)
312 assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Hours)));
313 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_TimeStruct->TimeFormat));
315 else
317 RTC_TimeStruct->TimeFormat = 0x00U;
318 assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Hours)));
320 assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Minutes)));
321 assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Seconds)));
324 /* Disable the write protection for RTC registers */
325 LL_RTC_DisableWriteProtection(RTCx);
327 /* Set Initialization mode */
328 if (LL_RTC_EnterInitMode(RTCx) != ERROR)
330 /* Check the input parameters format */
331 if (RTC_Format != LL_RTC_FORMAT_BIN)
333 LL_RTC_TIME_Config(RTCx, RTC_TimeStruct->TimeFormat, RTC_TimeStruct->Hours,
334 RTC_TimeStruct->Minutes, RTC_TimeStruct->Seconds);
336 else
338 LL_RTC_TIME_Config(RTCx, RTC_TimeStruct->TimeFormat, __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct->Hours),
339 __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct->Minutes),
340 __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct->Seconds));
343 /* Exit Initialization mode */
344 LL_RTC_DisableInitMode(RTC);
346 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
347 if (LL_RTC_IsShadowRegBypassEnabled(RTCx) == 0U)
349 status = LL_RTC_WaitForSynchro(RTCx);
351 else
353 status = SUCCESS;
356 /* Enable the write protection for RTC registers */
357 LL_RTC_EnableWriteProtection(RTCx);
359 return status;
363 * @brief Set each @ref LL_RTC_TimeTypeDef field to default value (Time = 00h:00min:00sec).
364 * @param RTC_TimeStruct pointer to a @ref LL_RTC_TimeTypeDef structure which will be initialized.
365 * @retval None
367 void LL_RTC_TIME_StructInit(LL_RTC_TimeTypeDef *RTC_TimeStruct)
369 /* Time = 00h:00min:00sec */
370 RTC_TimeStruct->TimeFormat = LL_RTC_TIME_FORMAT_AM_OR_24;
371 RTC_TimeStruct->Hours = 0U;
372 RTC_TimeStruct->Minutes = 0U;
373 RTC_TimeStruct->Seconds = 0U;
377 * @brief Set the RTC current date.
378 * @param RTCx RTC Instance
379 * @param RTC_Format This parameter can be one of the following values:
380 * @arg @ref LL_RTC_FORMAT_BIN
381 * @arg @ref LL_RTC_FORMAT_BCD
382 * @param RTC_DateStruct pointer to a RTC_DateTypeDef structure that contains
383 * the date configuration information for the RTC.
384 * @retval An ErrorStatus enumeration value:
385 * - SUCCESS: RTC Day register is configured
386 * - ERROR: RTC Day register is not configured
388 ErrorStatus LL_RTC_DATE_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_DateTypeDef *RTC_DateStruct)
390 ErrorStatus status = ERROR;
392 /* Check the parameters */
393 assert_param(IS_RTC_ALL_INSTANCE(RTCx));
394 assert_param(IS_LL_RTC_FORMAT(RTC_Format));
396 if ((RTC_Format == LL_RTC_FORMAT_BIN) && ((RTC_DateStruct->Month & 0x10U) == 0x10U))
398 RTC_DateStruct->Month = (RTC_DateStruct->Month & (uint32_t)~(0x10U)) + 0x0AU;
400 if (RTC_Format == LL_RTC_FORMAT_BIN)
402 assert_param(IS_LL_RTC_YEAR(RTC_DateStruct->Year));
403 assert_param(IS_LL_RTC_MONTH(RTC_DateStruct->Month));
404 assert_param(IS_LL_RTC_DAY(RTC_DateStruct->Day));
406 else
408 assert_param(IS_LL_RTC_YEAR(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct->Year)));
409 assert_param(IS_LL_RTC_MONTH(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct->Month)));
410 assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct->Day)));
412 assert_param(IS_LL_RTC_WEEKDAY(RTC_DateStruct->WeekDay));
414 /* Disable the write protection for RTC registers */
415 LL_RTC_DisableWriteProtection(RTCx);
417 /* Set Initialization mode */
418 if (LL_RTC_EnterInitMode(RTCx) != ERROR)
420 /* Check the input parameters format */
421 if (RTC_Format != LL_RTC_FORMAT_BIN)
423 LL_RTC_DATE_Config(RTCx, RTC_DateStruct->WeekDay, RTC_DateStruct->Day, RTC_DateStruct->Month, RTC_DateStruct->Year);
425 else
427 LL_RTC_DATE_Config(RTCx, RTC_DateStruct->WeekDay, __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct->Day),
428 __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct->Month), __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct->Year));
431 /* Exit Initialization mode */
432 LL_RTC_DisableInitMode(RTC);
434 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
435 if (LL_RTC_IsShadowRegBypassEnabled(RTCx) == 0U)
437 status = LL_RTC_WaitForSynchro(RTCx);
439 else
441 status = SUCCESS;
444 /* Enable the write protection for RTC registers */
445 LL_RTC_EnableWriteProtection(RTCx);
447 return status;
451 * @brief Set each @ref LL_RTC_DateTypeDef field to default value (date = Monday, January 01 xx00)
452 * @param RTC_DateStruct pointer to a @ref LL_RTC_DateTypeDef structure which will be initialized.
453 * @retval None
455 void LL_RTC_DATE_StructInit(LL_RTC_DateTypeDef *RTC_DateStruct)
457 /* Monday, January 01 xx00 */
458 RTC_DateStruct->WeekDay = LL_RTC_WEEKDAY_MONDAY;
459 RTC_DateStruct->Day = 1U;
460 RTC_DateStruct->Month = LL_RTC_MONTH_JANUARY;
461 RTC_DateStruct->Year = 0U;
465 * @brief Set the RTC Alarm A.
466 * @note The Alarm register can only be written when the corresponding Alarm
467 * is disabled (Use @ref LL_RTC_ALMA_Disable function).
468 * @param RTCx RTC Instance
469 * @param RTC_Format This parameter can be one of the following values:
470 * @arg @ref LL_RTC_FORMAT_BIN
471 * @arg @ref LL_RTC_FORMAT_BCD
472 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure that
473 * contains the alarm configuration parameters.
474 * @retval An ErrorStatus enumeration value:
475 * - SUCCESS: ALARMA registers are configured
476 * - ERROR: ALARMA registers are not configured
478 ErrorStatus LL_RTC_ALMA_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_AlarmTypeDef *RTC_AlarmStruct)
480 /* Check the parameters */
481 assert_param(IS_RTC_ALL_INSTANCE(RTCx));
482 assert_param(IS_LL_RTC_FORMAT(RTC_Format));
483 assert_param(IS_LL_RTC_ALMA_MASK(RTC_AlarmStruct->AlarmMask));
484 assert_param(IS_LL_RTC_ALMA_DATE_WEEKDAY_SEL(RTC_AlarmStruct->AlarmDateWeekDaySel));
486 if (RTC_Format == LL_RTC_FORMAT_BIN)
488 if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR)
490 assert_param(IS_LL_RTC_HOUR12(RTC_AlarmStruct->AlarmTime.Hours));
491 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct->AlarmTime.TimeFormat));
493 else
495 RTC_AlarmStruct->AlarmTime.TimeFormat = 0x00U;
496 assert_param(IS_LL_RTC_HOUR24(RTC_AlarmStruct->AlarmTime.Hours));
498 assert_param(IS_LL_RTC_MINUTES(RTC_AlarmStruct->AlarmTime.Minutes));
499 assert_param(IS_LL_RTC_SECONDS(RTC_AlarmStruct->AlarmTime.Seconds));
501 if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE)
503 assert_param(IS_LL_RTC_DAY(RTC_AlarmStruct->AlarmDateWeekDay));
505 else
507 assert_param(IS_LL_RTC_WEEKDAY(RTC_AlarmStruct->AlarmDateWeekDay));
510 else
512 if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR)
514 assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours)));
515 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct->AlarmTime.TimeFormat));
517 else
519 RTC_AlarmStruct->AlarmTime.TimeFormat = 0x00U;
520 assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours)));
523 assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Minutes)));
524 assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Seconds)));
526 if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE)
528 assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmDateWeekDay)));
530 else
532 assert_param(IS_LL_RTC_WEEKDAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmDateWeekDay)));
536 /* Disable the write protection for RTC registers */
537 LL_RTC_DisableWriteProtection(RTCx);
539 /* Select weekday selection */
540 if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE)
542 /* Set the date for ALARM */
543 LL_RTC_ALMA_DisableWeekday(RTCx);
544 if (RTC_Format != LL_RTC_FORMAT_BIN)
546 LL_RTC_ALMA_SetDay(RTCx, RTC_AlarmStruct->AlarmDateWeekDay);
548 else
550 LL_RTC_ALMA_SetDay(RTCx, __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmDateWeekDay));
553 else
555 /* Set the week day for ALARM */
556 LL_RTC_ALMA_EnableWeekday(RTCx);
557 LL_RTC_ALMA_SetWeekDay(RTCx, RTC_AlarmStruct->AlarmDateWeekDay);
560 /* Configure the Alarm register */
561 if (RTC_Format != LL_RTC_FORMAT_BIN)
563 LL_RTC_ALMA_ConfigTime(RTCx, RTC_AlarmStruct->AlarmTime.TimeFormat, RTC_AlarmStruct->AlarmTime.Hours,
564 RTC_AlarmStruct->AlarmTime.Minutes, RTC_AlarmStruct->AlarmTime.Seconds);
566 else
568 LL_RTC_ALMA_ConfigTime(RTCx, RTC_AlarmStruct->AlarmTime.TimeFormat,
569 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Hours),
570 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Minutes),
571 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Seconds));
573 /* Set ALARM mask */
574 LL_RTC_ALMA_SetMask(RTCx, RTC_AlarmStruct->AlarmMask);
576 /* Enable the write protection for RTC registers */
577 LL_RTC_EnableWriteProtection(RTCx);
579 return SUCCESS;
583 * @brief Set the RTC Alarm B.
584 * @note The Alarm register can only be written when the corresponding Alarm
585 * is disabled (@ref LL_RTC_ALMB_Disable function).
586 * @param RTCx RTC Instance
587 * @param RTC_Format This parameter can be one of the following values:
588 * @arg @ref LL_RTC_FORMAT_BIN
589 * @arg @ref LL_RTC_FORMAT_BCD
590 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure that
591 * contains the alarm configuration parameters.
592 * @retval An ErrorStatus enumeration value:
593 * - SUCCESS: ALARMB registers are configured
594 * - ERROR: ALARMB registers are not configured
596 ErrorStatus LL_RTC_ALMB_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_AlarmTypeDef *RTC_AlarmStruct)
598 /* Check the parameters */
599 assert_param(IS_RTC_ALL_INSTANCE(RTCx));
600 assert_param(IS_LL_RTC_FORMAT(RTC_Format));
601 assert_param(IS_LL_RTC_ALMB_MASK(RTC_AlarmStruct->AlarmMask));
602 assert_param(IS_LL_RTC_ALMB_DATE_WEEKDAY_SEL(RTC_AlarmStruct->AlarmDateWeekDaySel));
604 if (RTC_Format == LL_RTC_FORMAT_BIN)
606 if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR)
608 assert_param(IS_LL_RTC_HOUR12(RTC_AlarmStruct->AlarmTime.Hours));
609 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct->AlarmTime.TimeFormat));
611 else
613 RTC_AlarmStruct->AlarmTime.TimeFormat = 0x00U;
614 assert_param(IS_LL_RTC_HOUR24(RTC_AlarmStruct->AlarmTime.Hours));
616 assert_param(IS_LL_RTC_MINUTES(RTC_AlarmStruct->AlarmTime.Minutes));
617 assert_param(IS_LL_RTC_SECONDS(RTC_AlarmStruct->AlarmTime.Seconds));
619 if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE)
621 assert_param(IS_LL_RTC_DAY(RTC_AlarmStruct->AlarmDateWeekDay));
623 else
625 assert_param(IS_LL_RTC_WEEKDAY(RTC_AlarmStruct->AlarmDateWeekDay));
628 else
630 if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR)
632 assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours)));
633 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct->AlarmTime.TimeFormat));
635 else
637 RTC_AlarmStruct->AlarmTime.TimeFormat = 0x00U;
638 assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours)));
641 assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Minutes)));
642 assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Seconds)));
644 if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE)
646 assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmDateWeekDay)));
648 else
650 assert_param(IS_LL_RTC_WEEKDAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmDateWeekDay)));
654 /* Disable the write protection for RTC registers */
655 LL_RTC_DisableWriteProtection(RTCx);
657 /* Select weekday selection */
658 if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE)
660 /* Set the date for ALARM */
661 LL_RTC_ALMB_DisableWeekday(RTCx);
662 if (RTC_Format != LL_RTC_FORMAT_BIN)
664 LL_RTC_ALMB_SetDay(RTCx, RTC_AlarmStruct->AlarmDateWeekDay);
666 else
668 LL_RTC_ALMB_SetDay(RTCx, __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmDateWeekDay));
671 else
673 /* Set the week day for ALARM */
674 LL_RTC_ALMB_EnableWeekday(RTCx);
675 LL_RTC_ALMB_SetWeekDay(RTCx, RTC_AlarmStruct->AlarmDateWeekDay);
678 /* Configure the Alarm register */
679 if (RTC_Format != LL_RTC_FORMAT_BIN)
681 LL_RTC_ALMB_ConfigTime(RTCx, RTC_AlarmStruct->AlarmTime.TimeFormat, RTC_AlarmStruct->AlarmTime.Hours,
682 RTC_AlarmStruct->AlarmTime.Minutes, RTC_AlarmStruct->AlarmTime.Seconds);
684 else
686 LL_RTC_ALMB_ConfigTime(RTCx, RTC_AlarmStruct->AlarmTime.TimeFormat,
687 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Hours),
688 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Minutes),
689 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Seconds));
691 /* Set ALARM mask */
692 LL_RTC_ALMB_SetMask(RTCx, RTC_AlarmStruct->AlarmMask);
694 /* Enable the write protection for RTC registers */
695 LL_RTC_EnableWriteProtection(RTCx);
697 return SUCCESS;
701 * @brief Set each @ref LL_RTC_AlarmTypeDef of ALARMA field to default value (Time = 00h:00mn:00sec /
702 * Day = 1st day of the month/Mask = all fields are masked).
703 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure which will be initialized.
704 * @retval None
706 void LL_RTC_ALMA_StructInit(LL_RTC_AlarmTypeDef *RTC_AlarmStruct)
708 /* Alarm Time Settings : Time = 00h:00mn:00sec */
709 RTC_AlarmStruct->AlarmTime.TimeFormat = LL_RTC_ALMA_TIME_FORMAT_AM;
710 RTC_AlarmStruct->AlarmTime.Hours = 0U;
711 RTC_AlarmStruct->AlarmTime.Minutes = 0U;
712 RTC_AlarmStruct->AlarmTime.Seconds = 0U;
714 /* Alarm Day Settings : Day = 1st day of the month */
715 RTC_AlarmStruct->AlarmDateWeekDaySel = LL_RTC_ALMA_DATEWEEKDAYSEL_DATE;
716 RTC_AlarmStruct->AlarmDateWeekDay = 1U;
718 /* Alarm Masks Settings : Mask = all fields are not masked */
719 RTC_AlarmStruct->AlarmMask = LL_RTC_ALMA_MASK_NONE;
723 * @brief Set each @ref LL_RTC_AlarmTypeDef of ALARMA field to default value (Time = 00h:00mn:00sec /
724 * Day = 1st day of the month/Mask = all fields are masked).
725 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure which will be initialized.
726 * @retval None
728 void LL_RTC_ALMB_StructInit(LL_RTC_AlarmTypeDef *RTC_AlarmStruct)
730 /* Alarm Time Settings : Time = 00h:00mn:00sec */
731 RTC_AlarmStruct->AlarmTime.TimeFormat = LL_RTC_ALMB_TIME_FORMAT_AM;
732 RTC_AlarmStruct->AlarmTime.Hours = 0U;
733 RTC_AlarmStruct->AlarmTime.Minutes = 0U;
734 RTC_AlarmStruct->AlarmTime.Seconds = 0U;
736 /* Alarm Day Settings : Day = 1st day of the month */
737 RTC_AlarmStruct->AlarmDateWeekDaySel = LL_RTC_ALMB_DATEWEEKDAYSEL_DATE;
738 RTC_AlarmStruct->AlarmDateWeekDay = 1U;
740 /* Alarm Masks Settings : Mask = all fields are not masked */
741 RTC_AlarmStruct->AlarmMask = LL_RTC_ALMB_MASK_NONE;
745 * @brief Enters the RTC Initialization mode.
746 * @note The RTC Initialization mode is write protected, use the
747 * @ref LL_RTC_DisableWriteProtection before calling this function.
748 * @param RTCx RTC Instance
749 * @retval An ErrorStatus enumeration value:
750 * - SUCCESS: RTC is in Init mode
751 * - ERROR: RTC is not in Init mode
753 ErrorStatus LL_RTC_EnterInitMode(RTC_TypeDef *RTCx)
755 __IO uint32_t timeout = RTC_INITMODE_TIMEOUT;
756 ErrorStatus status = SUCCESS;
757 uint32_t tmp = 0U;
759 /* Check the parameter */
760 assert_param(IS_RTC_ALL_INSTANCE(RTCx));
762 /* Check if the Initialization mode is set */
763 if (LL_RTC_IsActiveFlag_INIT(RTCx) == 0U)
765 /* Set the Initialization mode */
766 LL_RTC_EnableInitMode(RTCx);
768 /* Wait till RTC is in INIT state and if Time out is reached exit */
769 tmp = LL_RTC_IsActiveFlag_INIT(RTCx);
770 while ((timeout != 0U) && (tmp != 1U))
772 if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
774 timeout --;
776 tmp = LL_RTC_IsActiveFlag_INIT(RTCx);
777 if (timeout == 0U)
779 status = ERROR;
783 return status;
787 * @brief Exit the RTC Initialization mode.
788 * @note When the initialization sequence is complete, the calendar restarts
789 * counting after 4 RTCCLK cycles.
790 * @note The RTC Initialization mode is write protected, use the
791 * @ref LL_RTC_DisableWriteProtection before calling this function.
792 * @param RTCx RTC Instance
793 * @retval An ErrorStatus enumeration value:
794 * - SUCCESS: RTC exited from in Init mode
795 * - ERROR: Not applicable
797 ErrorStatus LL_RTC_ExitInitMode(RTC_TypeDef *RTCx)
799 /* Check the parameter */
800 assert_param(IS_RTC_ALL_INSTANCE(RTCx));
802 /* Disable initialization mode */
803 LL_RTC_DisableInitMode(RTCx);
805 return SUCCESS;
809 * @brief Waits until the RTC Time and Day registers (RTC_TR and RTC_DR) are
810 * synchronized with RTC APB clock.
811 * @note The RTC Resynchronization mode is write protected, use the
812 * @ref LL_RTC_DisableWriteProtection before calling this function.
813 * @note To read the calendar through the shadow registers after Calendar
814 * initialization, calendar update or after wakeup from low power modes
815 * the software must first clear the RSF flag.
816 * The software must then wait until it is set again before reading
817 * the calendar, which means that the calendar registers have been
818 * correctly copied into the RTC_TR and RTC_DR shadow registers.
819 * @param RTCx RTC Instance
820 * @retval An ErrorStatus enumeration value:
821 * - SUCCESS: RTC registers are synchronised
822 * - ERROR: RTC registers are not synchronised
824 ErrorStatus LL_RTC_WaitForSynchro(RTC_TypeDef *RTCx)
826 __IO uint32_t timeout = RTC_SYNCHRO_TIMEOUT;
827 ErrorStatus status = SUCCESS;
828 uint32_t tmp = 0U;
830 /* Check the parameter */
831 assert_param(IS_RTC_ALL_INSTANCE(RTCx));
833 /* Clear RSF flag */
834 LL_RTC_ClearFlag_RS(RTCx);
836 /* Wait the registers to be synchronised */
837 tmp = LL_RTC_IsActiveFlag_RS(RTCx);
838 while ((timeout != 0U) && (tmp != 0U))
840 if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
842 timeout--;
844 tmp = LL_RTC_IsActiveFlag_RS(RTCx);
845 if (timeout == 0U)
847 status = ERROR;
851 if (status != ERROR)
853 timeout = RTC_SYNCHRO_TIMEOUT;
854 tmp = LL_RTC_IsActiveFlag_RS(RTCx);
855 while ((timeout != 0U) && (tmp != 1U))
857 if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
859 timeout--;
861 tmp = LL_RTC_IsActiveFlag_RS(RTCx);
862 if (timeout == 0U)
864 status = ERROR;
869 return (status);
873 * @}
877 * @}
881 * @}
884 #endif /* defined(RTC) */
887 * @}
890 #endif /* USE_FULL_LL_DRIVER */
892 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/