1 /**
2   ******************************************************************************
3   * @file    stm32c0xx_ll_rtc.h
4   * @author  MCD Application Team
5   * @brief   Header file of RTC LL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2022 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32C0xx_LL_RTC_H
21 #define STM32C0xx_LL_RTC_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32c0xx.h"
29 
30 /** @addtogroup STM32C0xx_LL_Driver
31   * @{
32   */
33 
34 #if defined(RTC)
35 
36 /** @defgroup RTC_LL RTC
37   * @{
38   */
39 
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42 /* Private constants ---------------------------------------------------------*/
43 /** @defgroup RTC_LL_Private_Constants RTC Private Constants
44   * @{
45   */
46 /* Masks Definition */
47 #define RTC_LL_INIT_MASK              0xFFFFFFFFU
48 #define RTC_LL_RSF_MASK               0xFFFFFF5FU
49 
50 /* Write protection defines */
51 #define RTC_WRITE_PROTECTION_DISABLE  ((uint8_t)0xFFU)
52 #define RTC_WRITE_PROTECTION_ENABLE_1 ((uint8_t)0xCAU)
53 #define RTC_WRITE_PROTECTION_ENABLE_2 ((uint8_t)0x53U)
54 
55 /* Defines used to combine date & time */
56 #define RTC_OFFSET_WEEKDAY            (uint32_t)24U
57 #define RTC_OFFSET_DAY                (uint32_t)16U
58 #define RTC_OFFSET_MONTH              (uint32_t)8U
59 #define RTC_OFFSET_HOUR               (uint32_t)16U
60 #define RTC_OFFSET_MINUTE             (uint32_t)8U
61 
62 /**
63   * @}
64   */
65 
66 /* Private macros ------------------------------------------------------------*/
67 #if defined(USE_FULL_LL_DRIVER)
68 /** @defgroup RTC_LL_Private_Macros RTC Private Macros
69   * @{
70   */
71 /**
72   * @}
73   */
74 #endif /*USE_FULL_LL_DRIVER*/
75 
76 /* Exported types ------------------------------------------------------------*/
77 #if defined(USE_FULL_LL_DRIVER)
78 /** @defgroup RTC_LL_ES_INIT RTC Exported Init structure
79   * @{
80   */
81 
82 /**
83   * @brief  RTC Init structures definition
84   */
85 typedef struct
86 {
87   uint32_t HourFormat;   /*!< Specifies the RTC Hours Format.
88                               This parameter can be a value of @ref RTC_LL_EC_HOURFORMAT
89 
90                               This feature can be modified afterwards using unitary function
91                               @ref LL_RTC_SetHourFormat(). */
92 
93   uint32_t AsynchPrescaler; /*!< Specifies the RTC Asynchronous Predivider value.
94                               This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7F
95 
96                               This feature can be modified afterwards using unitary function
97                               @ref LL_RTC_SetAsynchPrescaler(). */
98 
99   uint32_t SynchPrescaler;  /*!< Specifies the RTC Synchronous Predivider value.
100                               This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7FFF
101 
102                               This feature can be modified afterwards using unitary function
103                               @ref LL_RTC_SetSynchPrescaler(). */
104 } LL_RTC_InitTypeDef;
105 
106 /**
107   * @brief  RTC Time structure definition
108   */
109 typedef struct
110 {
111   uint32_t TimeFormat; /*!< Specifies the RTC AM/PM Time.
112                             This parameter can be a value of @ref RTC_LL_EC_TIME_FORMAT
113 
114                             This feature can be modified afterwards using unitary function @ref LL_RTC_TIME_SetFormat(). */
115 
116   uint8_t Hours;       /*!< Specifies the RTC Time Hours.
117                             This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the @ref LL_RTC_TIME_FORMAT_PM is selected.
118                             This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the @ref LL_RTC_TIME_FORMAT_AM_OR_24 is selected.
119 
120                             This feature can be modified afterwards using unitary function @ref LL_RTC_TIME_SetHour(). */
121 
122   uint8_t Minutes;     /*!< Specifies the RTC Time Minutes.
123                             This parameter must be a number between Min_Data = 0 and Max_Data = 59
124 
125                             This feature can be modified afterwards using unitary function @ref LL_RTC_TIME_SetMinute(). */
126 
127   uint8_t Seconds;     /*!< Specifies the RTC Time Seconds.
128                             This parameter must be a number between Min_Data = 0 and Max_Data = 59
129 
130                             This feature can be modified afterwards using unitary function @ref LL_RTC_TIME_SetSecond(). */
131 } LL_RTC_TimeTypeDef;
132 
133 /**
134   * @brief  RTC Date structure definition
135   */
136 typedef struct
137 {
138   uint8_t WeekDay;  /*!< Specifies the RTC Date WeekDay.
139                          This parameter can be a value of @ref RTC_LL_EC_WEEKDAY
140 
141                          This feature can be modified afterwards using unitary function @ref LL_RTC_DATE_SetWeekDay(). */
142 
143   uint8_t Month;    /*!< Specifies the RTC Date Month.
144                          This parameter can be a value of @ref RTC_LL_EC_MONTH
145 
146                          This feature can be modified afterwards using unitary function @ref LL_RTC_DATE_SetMonth(). */
147 
148   uint8_t Day;      /*!< Specifies the RTC Date Day.
149                          This parameter must be a number between Min_Data = 1 and Max_Data = 31
150 
151                          This feature can be modified afterwards using unitary function @ref LL_RTC_DATE_SetDay(). */
152 
153   uint8_t Year;     /*!< Specifies the RTC Date Year.
154                          This parameter must be a number between Min_Data = 0 and Max_Data = 99
155 
156                          This feature can be modified afterwards using unitary function @ref LL_RTC_DATE_SetYear(). */
157 } LL_RTC_DateTypeDef;
158 
159 /**
160   * @brief  RTC Alarm structure definition
161   */
162 typedef struct
163 {
164   LL_RTC_TimeTypeDef AlarmTime;  /*!< Specifies the RTC Alarm Time members. */
165 
166   uint32_t AlarmMask;            /*!< Specifies the RTC Alarm Masks.
167                                       This parameter can be a value of @ref RTC_LL_EC_ALMA_MASK for ALARM A.
168 
169                                       This feature can be modified afterwards using unitary function @ref LL_RTC_ALMA_SetMask() for ALARM A.
170                                  */
171 
172   uint32_t AlarmDateWeekDaySel;  /*!< Specifies the RTC Alarm is on day or WeekDay.
173                                       This parameter can be a value of @ref RTC_LL_EC_ALMA_WEEKDAY_SELECTION for ALARM A
174 
175                                       This feature can be modified afterwards using unitary function @ref LL_RTC_ALMA_EnableWeekday() or @ref LL_RTC_ALMA_DisableWeekday()
176                                       for ALARM A
177                                  */
178 
179   uint8_t AlarmDateWeekDay;      /*!< Specifies the RTC Alarm Day/WeekDay.
180                                       If AlarmDateWeekDaySel set to day, this parameter  must be a number between Min_Data = 1 and Max_Data = 31.
181 
182                                       This feature can be modified afterwards using unitary function @ref LL_RTC_ALMA_SetDay()
183                                       for ALARM A.
184 
185                                       If AlarmDateWeekDaySel set to Weekday, this parameter can be a value of @ref RTC_LL_EC_WEEKDAY.
186 
187                                       This feature can be modified afterwards using unitary function @ref LL_RTC_ALMA_SetWeekDay()
188                                       for ALARM A.
189                                  */
190 } LL_RTC_AlarmTypeDef;
191 
192 /**
193   * @}
194   */
195 #endif /* USE_FULL_LL_DRIVER */
196 
197 /* Exported constants --------------------------------------------------------*/
198 /** @defgroup RTC_LL_Exported_Constants RTC Exported Constants
199   * @{
200   */
201 
202 #if defined(USE_FULL_LL_DRIVER)
203 /** @defgroup RTC_LL_EC_FORMAT FORMAT
204   * @{
205   */
206 #define LL_RTC_FORMAT_BIN                  0U           /*!< Binary data format */
207 #define LL_RTC_FORMAT_BCD                  1U           /*!< BCD data format */
208 /**
209   * @}
210   */
211 
212 /** @defgroup RTC_LL_EC_ALMA_WEEKDAY_SELECTION RTC Alarm A Date WeekDay
213   * @{
214   */
215 #define LL_RTC_ALMA_DATEWEEKDAYSEL_DATE    0U                      /*!< Alarm A Date is selected */
216 #define LL_RTC_ALMA_DATEWEEKDAYSEL_WEEKDAY RTC_ALRMAR_WDSEL        /*!< Alarm A WeekDay is selected */
217 /**
218   * @}
219   */
220 
221 #endif /* USE_FULL_LL_DRIVER */
222 
223 /** @defgroup RTC_LL_EC_GET_FLAG Get Flags Defines
224   * @brief    Flags defines which can be used with LL_RTC_ReadReg function
225   * @{
226   */
227 #define LL_RTC_SCR_ITSF                    RTC_SCR_CITSF
228 #define LL_RTC_SCR_TSOVF                   RTC_SCR_CTSOVF
229 #define LL_RTC_SCR_TSF                     RTC_SCR_CTSF
230 #define LL_RTC_SCR_ALRAF                   RTC_SCR_CALRAF
231 
232 #define LL_RTC_ICSR_RECALPF                RTC_ICSR_RECALPF
233 #define LL_RTC_ICSR_INITF                  RTC_ICSR_INITF
234 #define LL_RTC_ICSR_RSF                    RTC_ICSR_RSF
235 #define LL_RTC_ICSR_INITS                  RTC_ICSR_INITS
236 #define LL_RTC_ICSR_SHPF                   RTC_ICSR_SHPF
237 #define LL_RTC_ICSR_ALRAWF                 RTC_ICSR_ALRAWF
238 /**
239   * @}
240   */
241 
242 /** @defgroup RTC_LL_EC_IT IT Defines
243   * @brief    IT defines which can be used with LL_RTC_ReadReg and  LL_RTC_WriteReg functions
244   * @{
245   */
246 #define LL_RTC_CR_TSIE                     RTC_CR_TSIE
247 #define LL_RTC_CR_ALRAIE                   RTC_CR_ALRAIE
248 /**
249   * @}
250   */
251 
252 /** @defgroup RTC_LL_EC_WEEKDAY  WEEK DAY
253   * @{
254   */
255 #define LL_RTC_WEEKDAY_MONDAY              ((uint8_t)0x01U) /*!< Monday    */
256 #define LL_RTC_WEEKDAY_TUESDAY             ((uint8_t)0x02U) /*!< Tuesday   */
257 #define LL_RTC_WEEKDAY_WEDNESDAY           ((uint8_t)0x03U) /*!< Wednesday */
258 #define LL_RTC_WEEKDAY_THURSDAY            ((uint8_t)0x04U) /*!< Thrusday  */
259 #define LL_RTC_WEEKDAY_FRIDAY              ((uint8_t)0x05U) /*!< Friday    */
260 #define LL_RTC_WEEKDAY_SATURDAY            ((uint8_t)0x06U) /*!< Saturday  */
261 #define LL_RTC_WEEKDAY_SUNDAY              ((uint8_t)0x07U) /*!< Sunday    */
262 /**
263   * @}
264   */
265 
266 /** @defgroup RTC_LL_EC_MONTH  MONTH
267   * @{
268   */
269 #define LL_RTC_MONTH_JANUARY               ((uint8_t)0x01U)  /*!< January   */
270 #define LL_RTC_MONTH_FEBRUARY              ((uint8_t)0x02U)  /*!< February  */
271 #define LL_RTC_MONTH_MARCH                 ((uint8_t)0x03U)  /*!< March     */
272 #define LL_RTC_MONTH_APRIL                 ((uint8_t)0x04U)  /*!< April     */
273 #define LL_RTC_MONTH_MAY                   ((uint8_t)0x05U)  /*!< May       */
274 #define LL_RTC_MONTH_JUNE                  ((uint8_t)0x06U)  /*!< June      */
275 #define LL_RTC_MONTH_JULY                  ((uint8_t)0x07U)  /*!< July      */
276 #define LL_RTC_MONTH_AUGUST                ((uint8_t)0x08U)  /*!< August    */
277 #define LL_RTC_MONTH_SEPTEMBER             ((uint8_t)0x09U)  /*!< September */
278 #define LL_RTC_MONTH_OCTOBER               ((uint8_t)0x10U)  /*!< October   */
279 #define LL_RTC_MONTH_NOVEMBER              ((uint8_t)0x11U)  /*!< November  */
280 #define LL_RTC_MONTH_DECEMBER              ((uint8_t)0x12U)  /*!< December  */
281 /**
282   * @}
283   */
284 
285 /** @defgroup RTC_LL_EC_HOURFORMAT  HOUR FORMAT
286   * @{
287   */
288 #define LL_RTC_HOURFORMAT_24HOUR           0U                    /*!< 24 hour/day format */
289 #define LL_RTC_HOURFORMAT_AMPM             RTC_CR_FMT            /*!< AM/PM hour format */
290 /**
291   * @}
292   */
293 
294 /** @defgroup RTC_LL_EC_ALARMOUT  ALARM OUTPUT
295   * @{
296   */
297 #define LL_RTC_ALARMOUT_DISABLE            0U                    /*!< Output disabled */
298 #define LL_RTC_ALARMOUT_ALMA               RTC_CR_OSEL_0         /*!< Alarm A output enabled */
299 /**
300   * @}
301   */
302 
303 /** @defgroup RTC_LL_EC_ALARM_OUTPUTTYPE  ALARM OUTPUT TYPE
304   * @{
305   */
306 #define LL_RTC_ALARM_OUTPUTTYPE_OPENDRAIN  RTC_CR_TAMPALRM_TYPE  /*!< RTC_ALARM is open-drain output */
307 #define LL_RTC_ALARM_OUTPUTTYPE_PUSHPULL   0U                    /*!< RTC_ALARM is push-pull output */
308 /**
309   * @}
310   */
311 
312 /** @defgroup RTC_LL_EC_OUTPUTPOLARITY_PIN  OUTPUT POLARITY PIN
313   * @{
314   */
315 #define LL_RTC_OUTPUTPOLARITY_PIN_HIGH     0U                    /*!< Pin is high when ALRAF is asserted (depending on OSEL)*/
316 #define LL_RTC_OUTPUTPOLARITY_PIN_LOW      RTC_CR_POL            /*!< Pin is low when ALRAF is asserted (depending on OSEL) */
317 /**
318   * @}
319   */
320 
321 /** @defgroup RTC_LL_EC_TIME_FORMAT TIME FORMAT
322   * @{
323   */
324 #define LL_RTC_TIME_FORMAT_AM_OR_24        0U                    /*!< AM or 24-hour format */
325 #define LL_RTC_TIME_FORMAT_PM              RTC_TR_PM             /*!< PM */
326 /**
327   * @}
328   */
329 
330 /** @defgroup RTC_LL_EC_SHIFT_SECOND  SHIFT SECOND
331   * @{
332   */
333 #define LL_RTC_SHIFT_SECOND_DELAY          0U                   /*!< Delay (seconds) = SUBFS / (PREDIV_S + 1) */
334 #define LL_RTC_SHIFT_SECOND_ADVANCE        RTC_SHIFTR_ADD1S     /*!< Advance (seconds) = (1 - (SUBFS / (PREDIV_S + 1))) */
335 /**
336   * @}
337   */
338 
339 /** @defgroup RTC_LL_EC_ALMA_MASK  ALARMA MASK
340   * @{
341   */
342 #define LL_RTC_ALMA_MASK_NONE              0U                      /*!< No masks applied on Alarm A*/
343 #define LL_RTC_ALMA_MASK_DATEWEEKDAY       RTC_ALRMAR_MSK4         /*!< Date/day do not care in Alarm A comparison */
344 #define LL_RTC_ALMA_MASK_HOURS             RTC_ALRMAR_MSK3         /*!< Hours do not care in Alarm A comparison */
345 #define LL_RTC_ALMA_MASK_MINUTES           RTC_ALRMAR_MSK2         /*!< Minutes do not care in Alarm A comparison */
346 #define LL_RTC_ALMA_MASK_SECONDS           RTC_ALRMAR_MSK1         /*!< Seconds do not care in Alarm A comparison */
347 #define LL_RTC_ALMA_MASK_ALL               (RTC_ALRMAR_MSK4 | RTC_ALRMAR_MSK3 | RTC_ALRMAR_MSK2 | RTC_ALRMAR_MSK1) /*!< Masks all */
348 /**
349   * @}
350   */
351 
352 /** @defgroup RTC_LL_EC_ALMA_TIME_FORMAT  ALARMA TIME FORMAT
353   * @{
354   */
355 #define LL_RTC_ALMA_TIME_FORMAT_AM         0U                      /*!< AM or 24-hour format */
356 #define LL_RTC_ALMA_TIME_FORMAT_PM         RTC_ALRMAR_PM           /*!< PM */
357 /**
358   * @}
359   */
360 
361 /** @defgroup RTC_LL_EC_TIMESTAMP_EDGE  TIMESTAMP EDGE
362   * @{
363   */
364 #define LL_RTC_TIMESTAMP_EDGE_RISING       0U                      /*!< RTC_TS input rising edge generates a time-stamp event */
365 #define LL_RTC_TIMESTAMP_EDGE_FALLING      RTC_CR_TSEDGE           /*!< RTC_TS input falling edge generates a time-stamp even */
366 /**
367   * @}
368   */
369 
370 /** @defgroup RTC_LL_EC_TS_TIME_FORMAT  TIMESTAMP TIME FORMAT
371   * @{
372   */
373 #define LL_RTC_TS_TIME_FORMAT_AM           0U                      /*!< AM or 24-hour format */
374 #define LL_RTC_TS_TIME_FORMAT_PM           RTC_TSTR_PM             /*!< PM */
375 /**
376   * @}
377   */
378 
379 /** @defgroup RTC_LL_EC_CALIB_OUTPUT  Calibration output
380   * @{
381   */
382 #define LL_RTC_CALIB_OUTPUT_NONE           0U                          /*!< Calibration output disabled */
383 #define LL_RTC_CALIB_OUTPUT_1HZ            (RTC_CR_COE | RTC_CR_COSEL) /*!< Calibration output is 1 Hz */
384 #define LL_RTC_CALIB_OUTPUT_512HZ          RTC_CR_COE                 /*!< Calibration output is 512 Hz */
385 /**
386   * @}
387   */
388 
389 /** @defgroup RTC_LL_EC_CALIB_INSERTPULSE  Calibration pulse insertion
390   * @{
391   */
392 #define LL_RTC_CALIB_INSERTPULSE_NONE      0U                    /*!< No RTCCLK pulses are added */
393 #define LL_RTC_CALIB_INSERTPULSE_SET       RTC_CALR_CALP         /*!< One RTCCLK pulse is effectively inserted every 2exp11 pulses (frequency increased by 488.5 ppm) */
394 /**
395   * @}
396   */
397 
398 /** @defgroup RTC_LL_EC_CALIB_PERIOD  Calibration period
399   * @{
400   */
401 #define LL_RTC_CALIB_PERIOD_32SEC          0U                    /*!< Use a 32-second calibration cycle period */
402 #define LL_RTC_CALIB_PERIOD_16SEC          RTC_CALR_CALW16       /*!< Use a 16-second calibration cycle period */
403 #define LL_RTC_CALIB_PERIOD_8SEC           RTC_CALR_CALW8        /*!< Use a 8-second calibration cycle period */
404 /**
405   * @}
406   */
407 
408 /**
409   * @}
410   */
411 
412 /* Exported macro ------------------------------------------------------------*/
413 /** @defgroup RTC_LL_Exported_Macros RTC Exported Macros
414   * @{
415   */
416 
417 /** @defgroup RTC_LL_EM_WRITE_READ Common Write and read registers Macros
418   * @{
419   */
420 
421 /**
422   * @brief  Write a value in RTC register
423   * @param  __INSTANCE__ RTC Instance
424   * @param  __REG__ Register to be written
425   * @param  __VALUE__ Value to be written in the register
426   * @retval None
427   */
428 #define LL_RTC_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
429 
430 /**
431   * @brief  Read a value in RTC register
432   * @param  __INSTANCE__ RTC Instance
433   * @param  __REG__ Register to be read
434   * @retval Register value
435   */
436 #define LL_RTC_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
437 /**
438   * @}
439   */
440 
441 /** @defgroup RTC_LL_EM_Convert Convert helper Macros
442   * @{
443   */
444 
445 /**
446   * @brief  Helper macro to convert a value from 2 digit decimal format to BCD format
447   * @param  __VALUE__ Byte to be converted
448   * @retval Converted byte
449   */
450 #define __LL_RTC_CONVERT_BIN2BCD(__VALUE__) (uint8_t)((((__VALUE__) / 10U) << 4U) | ((__VALUE__) % 10U))
451 
452 /**
453   * @brief  Helper macro to convert a value from BCD format to 2 digit decimal format
454   * @param  __VALUE__ BCD value to be converted
455   * @retval Converted byte
456   */
457 #define __LL_RTC_CONVERT_BCD2BIN(__VALUE__) (uint8_t)((((uint8_t)((__VALUE__)\
458                                                                   & (uint8_t)0xF0U) >> (uint8_t)0x4U) * 10U ) + ((__VALUE__) & (uint8_t)0x0FU))
459 
460 /**
461   * @}
462   */
463 
464 /** @defgroup RTC_LL_EM_Date Date helper Macros
465   * @{
466   */
467 
468 /**
469   * @brief  Helper macro to retrieve weekday.
470   * @param  __RTC_DATE__ Date returned by @ref  LL_RTC_DATE_Get function.
471   * @retval Returned value can be one of the following values:
472   *         @arg @ref LL_RTC_WEEKDAY_MONDAY
473   *         @arg @ref LL_RTC_WEEKDAY_TUESDAY
474   *         @arg @ref LL_RTC_WEEKDAY_WEDNESDAY
475   *         @arg @ref LL_RTC_WEEKDAY_THURSDAY
476   *         @arg @ref LL_RTC_WEEKDAY_FRIDAY
477   *         @arg @ref LL_RTC_WEEKDAY_SATURDAY
478   *         @arg @ref LL_RTC_WEEKDAY_SUNDAY
479   */
480 #define __LL_RTC_GET_WEEKDAY(__RTC_DATE__) (((__RTC_DATE__) >> RTC_OFFSET_WEEKDAY) & 0x000000FFU)
481 
482 /**
483   * @brief  Helper macro to retrieve Year in BCD format
484   * @param  __RTC_DATE__ Value returned by @ref  LL_RTC_DATE_Get
485   * @retval Year in BCD format (0x00 . . . 0x99)
486   */
487 #define __LL_RTC_GET_YEAR(__RTC_DATE__) ((__RTC_DATE__) & 0x000000FFU)
488 
489 /**
490   * @brief  Helper macro to retrieve Month in BCD format
491   * @param  __RTC_DATE__ Value returned by @ref  LL_RTC_DATE_Get
492   * @retval Returned value can be one of the following values:
493   *         @arg @ref LL_RTC_MONTH_JANUARY
494   *         @arg @ref LL_RTC_MONTH_FEBRUARY
495   *         @arg @ref LL_RTC_MONTH_MARCH
496   *         @arg @ref LL_RTC_MONTH_APRIL
497   *         @arg @ref LL_RTC_MONTH_MAY
498   *         @arg @ref LL_RTC_MONTH_JUNE
499   *         @arg @ref LL_RTC_MONTH_JULY
500   *         @arg @ref LL_RTC_MONTH_AUGUST
501   *         @arg @ref LL_RTC_MONTH_SEPTEMBER
502   *         @arg @ref LL_RTC_MONTH_OCTOBER
503   *         @arg @ref LL_RTC_MONTH_NOVEMBER
504   *         @arg @ref LL_RTC_MONTH_DECEMBER
505   */
506 #define __LL_RTC_GET_MONTH(__RTC_DATE__) (((__RTC_DATE__) >>RTC_OFFSET_MONTH) & 0x000000FFU)
507 
508 /**
509   * @brief  Helper macro to retrieve Day in BCD format
510   * @param  __RTC_DATE__ Value returned by @ref  LL_RTC_DATE_Get
511   * @retval Day in BCD format (0x01 . . . 0x31)
512   */
513 #define __LL_RTC_GET_DAY(__RTC_DATE__) (((__RTC_DATE__) >>RTC_OFFSET_DAY) & 0x000000FFU)
514 
515 /**
516   * @}
517   */
518 
519 /** @defgroup RTC_LL_EM_Time Time helper Macros
520   * @{
521   */
522 
523 /**
524   * @brief  Helper macro to retrieve hour in BCD format
525   * @param  __RTC_TIME__ RTC time returned by @ref LL_RTC_TIME_Get function
526   * @retval Hours in BCD format (0x01. . .0x12 or between Min_Data=0x00 and Max_Data=0x23)
527   */
528 #define __LL_RTC_GET_HOUR(__RTC_TIME__) (((__RTC_TIME__) >> RTC_OFFSET_HOUR) & 0x000000FFU)
529 
530 /**
531   * @brief  Helper macro to retrieve minute in BCD format
532   * @param  __RTC_TIME__ RTC time returned by @ref LL_RTC_TIME_Get function
533   * @retval Minutes in BCD format (0x00. . .0x59)
534   */
535 #define __LL_RTC_GET_MINUTE(__RTC_TIME__) (((__RTC_TIME__) >> RTC_OFFSET_MINUTE) & 0x000000FFU)
536 
537 /**
538   * @brief  Helper macro to retrieve second in BCD format
539   * @param  __RTC_TIME__ RTC time returned by @ref LL_RTC_TIME_Get function
540   * @retval Seconds in  format (0x00. . .0x59)
541   */
542 #define __LL_RTC_GET_SECOND(__RTC_TIME__) ((__RTC_TIME__) & 0x000000FFU)
543 
544 /**
545   * @}
546   */
547 
548 /**
549   * @}
550   */
551 
552 /* Exported functions --------------------------------------------------------*/
553 /** @defgroup RTC_LL_Exported_Functions RTC Exported Functions
554   * @{
555   */
556 
557 /** @defgroup RTC_LL_EF_Configuration Configuration
558   * @{
559   */
560 
561 /**
562   * @brief  Set Hours format (24 hour/day or AM/PM hour format)
563   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
564   * @note   It can be written in initialization mode only (@ref LL_RTC_EnableInitMode function)
565   * @rmtoll RTC_CR           FMT           LL_RTC_SetHourFormat
566   * @param  RTCx RTC Instance
567   * @param  HourFormat This parameter can be one of the following values:
568   *         @arg @ref LL_RTC_HOURFORMAT_24HOUR
569   *         @arg @ref LL_RTC_HOURFORMAT_AMPM
570   * @retval None
571   */
LL_RTC_SetHourFormat(RTC_TypeDef * RTCx,uint32_t HourFormat)572 __STATIC_INLINE void LL_RTC_SetHourFormat(RTC_TypeDef *RTCx, uint32_t HourFormat)
573 {
574   MODIFY_REG(RTCx->CR, RTC_CR_FMT, HourFormat);
575 }
576 
577 /**
578   * @brief  Get Hours format (24 hour/day or AM/PM hour format)
579   * @rmtoll RTC_CR           FMT           LL_RTC_GetHourFormat
580   * @param  RTCx RTC Instance
581   * @retval Returned value can be one of the following values:
582   *         @arg @ref LL_RTC_HOURFORMAT_24HOUR
583   *         @arg @ref LL_RTC_HOURFORMAT_AMPM
584   */
LL_RTC_GetHourFormat(RTC_TypeDef * RTCx)585 __STATIC_INLINE uint32_t LL_RTC_GetHourFormat(RTC_TypeDef *RTCx)
586 {
587   return (uint32_t)(READ_BIT(RTCx->CR, RTC_CR_FMT));
588 }
589 
590 /**
591   * @brief  Select the flag to be routed to RTC_ALARM output
592   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
593   * @rmtoll RTC_CR           OSEL          LL_RTC_SetAlarmOutEvent
594   * @param  RTCx RTC Instance
595   * @param  AlarmOutput This parameter can be one of the following values:
596   *         @arg @ref LL_RTC_ALARMOUT_DISABLE
597   *         @arg @ref LL_RTC_ALARMOUT_ALMA
598   * @retval None
599   */
LL_RTC_SetAlarmOutEvent(RTC_TypeDef * RTCx,uint32_t AlarmOutput)600 __STATIC_INLINE void LL_RTC_SetAlarmOutEvent(RTC_TypeDef *RTCx, uint32_t AlarmOutput)
601 {
602   MODIFY_REG(RTCx->CR, RTC_CR_OSEL, AlarmOutput);
603 }
604 
605 /**
606   * @brief  Get the flag to be routed to RTC_ALARM output
607   * @rmtoll RTC_CR           OSEL          LL_RTC_GetAlarmOutEvent
608   * @param  RTCx RTC Instance
609   * @retval Returned value can be one of the following values:
610   *         @arg @ref LL_RTC_ALARMOUT_DISABLE
611   *         @arg @ref LL_RTC_ALARMOUT_ALMA
612   */
LL_RTC_GetAlarmOutEvent(RTC_TypeDef * RTCx)613 __STATIC_INLINE uint32_t LL_RTC_GetAlarmOutEvent(RTC_TypeDef *RTCx)
614 {
615   return (uint32_t)(READ_BIT(RTCx->CR, RTC_CR_OSEL));
616 }
617 
618 /**
619   * @brief  Set RTC_ALARM output type (ALARM in push-pull or open-drain output)
620   * @rmtoll RTC_CR           TAMPALRM_TYPE          LL_RTC_SetAlarmOutputType
621   * @param  RTCx RTC Instance
622   * @param  Output This parameter can be one of the following values:
623   *         @arg @ref LL_RTC_ALARM_OUTPUTTYPE_OPENDRAIN
624   *         @arg @ref LL_RTC_ALARM_OUTPUTTYPE_PUSHPULL
625   * @retval None
626   */
LL_RTC_SetAlarmOutputType(RTC_TypeDef * RTCx,uint32_t Output)627 __STATIC_INLINE void LL_RTC_SetAlarmOutputType(RTC_TypeDef *RTCx, uint32_t Output)
628 {
629   MODIFY_REG(RTCx->CR, RTC_CR_TAMPALRM_TYPE, Output);
630 }
631 
632 /**
633   * @brief  Get RTC_ALARM output type (ALARM in push-pull or open-drain output)
634   * @rmtoll RTC_CR           TAMPALRM_TYPE          LL_RTC_SetAlarmOutputType
635   * @param  RTCx RTC Instance
636   * @retval Returned value can be one of the following values:
637   *         @arg @ref LL_RTC_ALARM_OUTPUTTYPE_OPENDRAIN
638   *         @arg @ref LL_RTC_ALARM_OUTPUTTYPE_PUSHPULL
639   */
LL_RTC_GetAlarmOutputType(RTC_TypeDef * RTCx)640 __STATIC_INLINE uint32_t LL_RTC_GetAlarmOutputType(RTC_TypeDef *RTCx)
641 {
642   return (uint32_t)(READ_BIT(RTCx->CR, RTC_CR_TAMPALRM_TYPE));
643 }
644 
645 /**
646   * @brief  Enable initialization mode
647   * @note   Initialization mode is used to program time and date register (RTC_TR and RTC_DR)
648   *         and prescaler register (RTC_PRER).
649   *         Counters are stopped and start counting from the new value when INIT is reset.
650   * @rmtoll RTC_ICSR          INIT          LL_RTC_EnableInitMode
651   * @param  RTCx RTC Instance
652   * @retval None
653   */
LL_RTC_EnableInitMode(RTC_TypeDef * RTCx)654 __STATIC_INLINE void LL_RTC_EnableInitMode(RTC_TypeDef *RTCx)
655 {
656   /* Set the Initialization mode */
657   WRITE_REG(RTCx->ICSR, RTC_LL_INIT_MASK);
658 }
659 
660 /**
661   * @brief  Disable initialization mode (Free running mode)
662   * @rmtoll RTC_ICSR          INIT          LL_RTC_DisableInitMode
663   * @param  RTCx RTC Instance
664   * @retval None
665   */
LL_RTC_DisableInitMode(RTC_TypeDef * RTCx)666 __STATIC_INLINE void LL_RTC_DisableInitMode(RTC_TypeDef *RTCx)
667 {
668   /* Exit Initialization mode */
669   WRITE_REG(RTCx->ICSR, (uint32_t)~RTC_ICSR_INIT);
670 }
671 
672 /**
673   * @brief  Set Output polarity (pin is low when ALRAF is asserted)
674   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
675   * @rmtoll RTC_CR           POL           LL_RTC_SetOutputPolarity
676   * @param  RTCx RTC Instance
677   * @param  Polarity This parameter can be one of the following values:
678   *         @arg @ref LL_RTC_OUTPUTPOLARITY_PIN_HIGH
679   *         @arg @ref LL_RTC_OUTPUTPOLARITY_PIN_LOW
680   * @retval None
681   */
LL_RTC_SetOutputPolarity(RTC_TypeDef * RTCx,uint32_t Polarity)682 __STATIC_INLINE void LL_RTC_SetOutputPolarity(RTC_TypeDef *RTCx, uint32_t Polarity)
683 {
684   MODIFY_REG(RTCx->CR, RTC_CR_POL, Polarity);
685 }
686 
687 /**
688   * @brief  Get Output polarity
689   * @rmtoll RTC_CR           POL           LL_RTC_GetOutputPolarity
690   * @param  RTCx RTC Instance
691   * @retval Returned value can be one of the following values:
692   *         @arg @ref LL_RTC_OUTPUTPOLARITY_PIN_HIGH
693   *         @arg @ref LL_RTC_OUTPUTPOLARITY_PIN_LOW
694   */
LL_RTC_GetOutputPolarity(RTC_TypeDef * RTCx)695 __STATIC_INLINE uint32_t LL_RTC_GetOutputPolarity(RTC_TypeDef *RTCx)
696 {
697   return (uint32_t)(READ_BIT(RTCx->CR, RTC_CR_POL));
698 }
699 
700 /**
701   * @brief  Enable Bypass the shadow registers
702   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
703   * @rmtoll RTC_CR           BYPSHAD       LL_RTC_EnableShadowRegBypass
704   * @param  RTCx RTC Instance
705   * @retval None
706   */
LL_RTC_EnableShadowRegBypass(RTC_TypeDef * RTCx)707 __STATIC_INLINE void LL_RTC_EnableShadowRegBypass(RTC_TypeDef *RTCx)
708 {
709   SET_BIT(RTCx->CR, RTC_CR_BYPSHAD);
710 }
711 
712 /**
713   * @brief  Disable Bypass the shadow registers
714   * @rmtoll RTC_CR           BYPSHAD       LL_RTC_DisableShadowRegBypass
715   * @param  RTCx RTC Instance
716   * @retval None
717   */
LL_RTC_DisableShadowRegBypass(RTC_TypeDef * RTCx)718 __STATIC_INLINE void LL_RTC_DisableShadowRegBypass(RTC_TypeDef *RTCx)
719 {
720   CLEAR_BIT(RTCx->CR, RTC_CR_BYPSHAD);
721 }
722 
723 /**
724   * @brief  Check if Shadow registers bypass is enabled or not.
725   * @rmtoll RTC_CR           BYPSHAD       LL_RTC_IsShadowRegBypassEnabled
726   * @param  RTCx RTC Instance
727   * @retval State of bit (1 or 0).
728   */
LL_RTC_IsShadowRegBypassEnabled(RTC_TypeDef * RTCx)729 __STATIC_INLINE uint32_t LL_RTC_IsShadowRegBypassEnabled(RTC_TypeDef *RTCx)
730 {
731   return ((READ_BIT(RTCx->CR, RTC_CR_BYPSHAD) == (RTC_CR_BYPSHAD)) ? 1UL : 0UL);
732 }
733 
734 /**
735   * @brief  Enable RTC_REFIN reference clock detection (50 or 60 Hz)
736   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
737   * @note   It can be written in initialization mode only (@ref LL_RTC_EnableInitMode function)
738   * @rmtoll RTC_CR           REFCKON       LL_RTC_EnableRefClock
739   * @param  RTCx RTC Instance
740   * @retval None
741   */
LL_RTC_EnableRefClock(RTC_TypeDef * RTCx)742 __STATIC_INLINE void LL_RTC_EnableRefClock(RTC_TypeDef *RTCx)
743 {
744   SET_BIT(RTCx->CR, RTC_CR_REFCKON);
745 }
746 
747 /**
748   * @brief  Disable RTC_REFIN reference clock detection (50 or 60 Hz)
749   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
750   * @note   It can be written in initialization mode only (@ref LL_RTC_EnableInitMode function)
751   * @rmtoll RTC_CR           REFCKON       LL_RTC_DisableRefClock
752   * @param  RTCx RTC Instance
753   * @retval None
754   */
LL_RTC_DisableRefClock(RTC_TypeDef * RTCx)755 __STATIC_INLINE void LL_RTC_DisableRefClock(RTC_TypeDef *RTCx)
756 {
757   CLEAR_BIT(RTCx->CR, RTC_CR_REFCKON);
758 }
759 
760 /**
761   * @brief  Set Asynchronous prescaler factor
762   * @rmtoll RTC_PRER         PREDIV_A      LL_RTC_SetAsynchPrescaler
763   * @param  RTCx RTC Instance
764   * @param  AsynchPrescaler Value between Min_Data = 0 and Max_Data = 0x7F
765   * @retval None
766   */
LL_RTC_SetAsynchPrescaler(RTC_TypeDef * RTCx,uint32_t AsynchPrescaler)767 __STATIC_INLINE void LL_RTC_SetAsynchPrescaler(RTC_TypeDef *RTCx, uint32_t AsynchPrescaler)
768 {
769   MODIFY_REG(RTCx->PRER, RTC_PRER_PREDIV_A, AsynchPrescaler << RTC_PRER_PREDIV_A_Pos);
770 }
771 
772 /**
773   * @brief  Set Synchronous prescaler factor
774   * @rmtoll RTC_PRER         PREDIV_S      LL_RTC_SetSynchPrescaler
775   * @param  RTCx RTC Instance
776   * @param  SynchPrescaler Value between Min_Data = 0 and Max_Data = 0x7FFF
777   * @retval None
778   */
LL_RTC_SetSynchPrescaler(RTC_TypeDef * RTCx,uint32_t SynchPrescaler)779 __STATIC_INLINE void LL_RTC_SetSynchPrescaler(RTC_TypeDef *RTCx, uint32_t SynchPrescaler)
780 {
781   MODIFY_REG(RTCx->PRER, RTC_PRER_PREDIV_S, SynchPrescaler);
782 }
783 
784 /**
785   * @brief  Get Asynchronous prescaler factor
786   * @rmtoll RTC_PRER         PREDIV_A      LL_RTC_GetAsynchPrescaler
787   * @param  RTCx RTC Instance
788   * @retval Value between Min_Data = 0 and Max_Data = 0x7F
789   */
LL_RTC_GetAsynchPrescaler(RTC_TypeDef * RTCx)790 __STATIC_INLINE uint32_t LL_RTC_GetAsynchPrescaler(RTC_TypeDef *RTCx)
791 {
792   return (uint32_t)(READ_BIT(RTCx->PRER, RTC_PRER_PREDIV_A) >> RTC_PRER_PREDIV_A_Pos);
793 }
794 
795 /**
796   * @brief  Get Synchronous prescaler factor
797   * @rmtoll RTC_PRER         PREDIV_S      LL_RTC_GetSynchPrescaler
798   * @param  RTCx RTC Instance
799   * @retval Value between Min_Data = 0 and Max_Data = 0x7FFF
800   */
LL_RTC_GetSynchPrescaler(RTC_TypeDef * RTCx)801 __STATIC_INLINE uint32_t LL_RTC_GetSynchPrescaler(RTC_TypeDef *RTCx)
802 {
803   return (uint32_t)(READ_BIT(RTCx->PRER, RTC_PRER_PREDIV_S));
804 }
805 
806 /**
807   * @brief  Enable the write protection for RTC registers.
808   * @rmtoll RTC_WPR          KEY           LL_RTC_EnableWriteProtection
809   * @param  RTCx RTC Instance
810   * @retval None
811   */
LL_RTC_EnableWriteProtection(RTC_TypeDef * RTCx)812 __STATIC_INLINE void LL_RTC_EnableWriteProtection(RTC_TypeDef *RTCx)
813 {
814   WRITE_REG(RTCx->WPR, RTC_WRITE_PROTECTION_DISABLE);
815 }
816 
817 /**
818   * @brief  Disable the write protection for RTC registers.
819   * @rmtoll RTC_WPR          KEY           LL_RTC_DisableWriteProtection
820   * @param  RTCx RTC Instance
821   * @retval None
822   */
LL_RTC_DisableWriteProtection(RTC_TypeDef * RTCx)823 __STATIC_INLINE void LL_RTC_DisableWriteProtection(RTC_TypeDef *RTCx)
824 {
825   WRITE_REG(RTCx->WPR, RTC_WRITE_PROTECTION_ENABLE_1);
826   WRITE_REG(RTCx->WPR, RTC_WRITE_PROTECTION_ENABLE_2);
827 }
828 
829 
830 /**
831   * @brief  Enable internal pull-up in output mode.
832   * @rmtoll RTC_CR           TAMPALRM_PU       LL_RTC_EnableAlarmPullUp
833   * @param  RTCx RTC Instance
834   * @retval None
835   */
LL_RTC_EnableAlarmPullUp(RTC_TypeDef * RTCx)836 __STATIC_INLINE void LL_RTC_EnableAlarmPullUp(RTC_TypeDef *RTCx)
837 {
838   SET_BIT(RTCx->CR, RTC_CR_TAMPALRM_PU);
839 }
840 
841 /**
842   * @brief  Disable internal pull-up in output mode.
843   * @rmtoll RTC_CR           TAMPALRM_PU       LL_RTC_EnableAlarmPullUp
844   * @param  RTCx RTC Instance
845   * @retval None
846   */
LL_RTC_DisableAlarmPullUp(RTC_TypeDef * RTCx)847 __STATIC_INLINE void LL_RTC_DisableAlarmPullUp(RTC_TypeDef *RTCx)
848 {
849   CLEAR_BIT(RTCx->CR, RTC_CR_TAMPALRM_PU);
850 }
851 
852 /**
853   * @brief  Check if internal pull-up in output mode is enabled or not.
854   * @rmtoll RTC_CR           TAMPALRM_PU       LL_RTC_IsAlarmPullUpEnabled
855   * @param  RTCx RTC Instance
856   * @retval State of bit (1 or 0).
857   */
LL_RTC_IsAlarmPullUpEnabled(RTC_TypeDef * RTCx)858 __STATIC_INLINE uint32_t LL_RTC_IsAlarmPullUpEnabled(RTC_TypeDef *RTCx)
859 {
860   return ((READ_BIT(RTCx->CR, RTC_CR_TAMPALRM_PU) == (RTC_CR_TAMPALRM_PU)) ? 1UL : 0UL);
861 }
862 
863 /**
864   * @brief  Enable RTC_OUT2 output
865   * @note RTC_OUT2 mapping depends on both OSEL (@ref LL_RTC_SetAlarmOutEvent)
866   *       and COE (@ref LL_RTC_CAL_SetOutputFreq) settings.
867   * @note RTC_OUT2 is not available ins VBAT mode.
868   * @rmtoll RTC_CR           OUT2EN       LL_RTC_EnableOutput2
869   * @param  RTCx RTC Instance
870   * @retval None
871   */
LL_RTC_EnableOutput2(RTC_TypeDef * RTCx)872 __STATIC_INLINE void LL_RTC_EnableOutput2(RTC_TypeDef *RTCx)
873 {
874   SET_BIT(RTCx->CR, RTC_CR_OUT2EN);
875 }
876 
877 /**
878   * @brief  Disable RTC_OUT2 output
879   * @rmtoll RTC_CR           OUT2EN       LL_RTC_DisableOutput2
880   * @param  RTCx RTC Instance
881   * @retval None
882   */
LL_RTC_DisableOutput2(RTC_TypeDef * RTCx)883 __STATIC_INLINE void LL_RTC_DisableOutput2(RTC_TypeDef *RTCx)
884 {
885   CLEAR_BIT(RTCx->CR, RTC_CR_OUT2EN);
886 }
887 
888 /**
889   * @brief  Check if RTC_OUT2 output is enabled or not.
890   * @rmtoll RTC_CR           OUT2EN       LL_RTC_IsOutput2Enabled
891   * @param  RTCx RTC Instance
892   * @retval State of bit (1 or 0).
893   */
LL_RTC_IsOutput2Enabled(RTC_TypeDef * RTCx)894 __STATIC_INLINE uint32_t LL_RTC_IsOutput2Enabled(RTC_TypeDef *RTCx)
895 {
896   return ((READ_BIT(RTCx->CR, RTC_CR_OUT2EN) == (RTC_CR_OUT2EN)) ? 1UL : 0UL);
897 }
898 
899 /**
900   * @}
901   */
902 
903 /** @defgroup RTC_LL_EF_Time Time
904   * @{
905   */
906 
907 /**
908   * @brief  Set time format (AM/24-hour or PM notation)
909   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
910   * @note   It can be written in initialization mode only (@ref LL_RTC_EnableInitMode function)
911   * @rmtoll RTC_TR           PM            LL_RTC_TIME_SetFormat
912   * @param  RTCx RTC Instance
913   * @param  TimeFormat This parameter can be one of the following values:
914   *         @arg @ref LL_RTC_TIME_FORMAT_AM_OR_24
915   *         @arg @ref LL_RTC_TIME_FORMAT_PM
916   * @retval None
917   */
LL_RTC_TIME_SetFormat(RTC_TypeDef * RTCx,uint32_t TimeFormat)918 __STATIC_INLINE void LL_RTC_TIME_SetFormat(RTC_TypeDef *RTCx, uint32_t TimeFormat)
919 {
920   MODIFY_REG(RTCx->TR, RTC_TR_PM, TimeFormat);
921 }
922 
923 /**
924   * @brief  Get time format (AM or PM notation)
925   * @note if shadow mode is disabled (BYPSHAD=0), need to check if RSF flag is set
926   *       before reading this bit
927   * @note Read either RTC_SSR or RTC_TR locks the values in the higher-order calendar
928   *       shadow registers until RTC_DR is read (LL_RTC_ReadReg(RTC, DR)).
929   * @rmtoll RTC_TR           PM            LL_RTC_TIME_GetFormat
930   * @param  RTCx RTC Instance
931   * @retval Returned value can be one of the following values:
932   *         @arg @ref LL_RTC_TIME_FORMAT_AM_OR_24
933   *         @arg @ref LL_RTC_TIME_FORMAT_PM
934   */
LL_RTC_TIME_GetFormat(RTC_TypeDef * RTCx)935 __STATIC_INLINE uint32_t LL_RTC_TIME_GetFormat(RTC_TypeDef *RTCx)
936 {
937   return (uint32_t)(READ_BIT(RTCx->TR, RTC_TR_PM));
938 }
939 
940 /**
941   * @brief  Set Hours in BCD format
942   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
943   * @note   It can be written in initialization mode only (@ref LL_RTC_EnableInitMode function)
944   * @note helper macro __LL_RTC_CONVERT_BIN2BCD is available to convert hour from binary to BCD format
945   * @rmtoll RTC_TR           HT            LL_RTC_TIME_SetHour\n
946   *         RTC_TR           HU            LL_RTC_TIME_SetHour
947   * @param  RTCx RTC Instance
948   * @param  Hours Value between Min_Data=0x01 and Max_Data=0x12 or between Min_Data=0x00 and Max_Data=0x23
949   * @retval None
950   */
LL_RTC_TIME_SetHour(RTC_TypeDef * RTCx,uint32_t Hours)951 __STATIC_INLINE void LL_RTC_TIME_SetHour(RTC_TypeDef *RTCx, uint32_t Hours)
952 {
953   MODIFY_REG(RTCx->TR, (RTC_TR_HT | RTC_TR_HU),
954              (((Hours & 0xF0U) << (RTC_TR_HT_Pos - 4U)) | ((Hours & 0x0FU) << RTC_TR_HU_Pos)));
955 }
956 
957 /**
958   * @brief  Get Hours in BCD format
959   * @note if shadow mode is disabled (BYPSHAD=0), need to check if RSF flag is set
960   *       before reading this bit
961   * @note Read either RTC_SSR or RTC_TR locks the values in the higher-order calendar
962   *       shadow registers until RTC_DR is read (LL_RTC_ReadReg(RTC, DR)).
963   * @note helper macro __LL_RTC_CONVERT_BCD2BIN is available to convert hour from BCD to
964   *       Binary format
965   * @rmtoll RTC_TR           HT            LL_RTC_TIME_GetHour\n
966   *         RTC_TR           HU            LL_RTC_TIME_GetHour
967   * @param  RTCx RTC Instance
968   * @retval Value between Min_Data=0x01 and Max_Data=0x12 or between Min_Data=0x00 and Max_Data=0x23
969   */
LL_RTC_TIME_GetHour(RTC_TypeDef * RTCx)970 __STATIC_INLINE uint32_t LL_RTC_TIME_GetHour(RTC_TypeDef *RTCx)
971 {
972   return ((READ_BIT(RTCx->TR, (RTC_TR_HT | RTC_TR_HU))) >> RTC_TR_HU_Pos);
973 }
974 
975 /**
976   * @brief  Set Minutes in BCD format
977   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
978   * @note   It can be written in initialization mode only (@ref LL_RTC_EnableInitMode function)
979   * @note helper macro __LL_RTC_CONVERT_BIN2BCD is available to convert Minutes from binary to BCD format
980   * @rmtoll RTC_TR           MNT           LL_RTC_TIME_SetMinute\n
981   *         RTC_TR           MNU           LL_RTC_TIME_SetMinute
982   * @param  RTCx RTC Instance
983   * @param  Minutes Value between Min_Data=0x00 and Max_Data=0x59
984   * @retval None
985   */
LL_RTC_TIME_SetMinute(RTC_TypeDef * RTCx,uint32_t Minutes)986 __STATIC_INLINE void LL_RTC_TIME_SetMinute(RTC_TypeDef *RTCx, uint32_t Minutes)
987 {
988   MODIFY_REG(RTCx->TR, (RTC_TR_MNT | RTC_TR_MNU),
989              (((Minutes & 0xF0U) << (RTC_TR_MNT_Pos - 4U)) | ((Minutes & 0x0FU) << RTC_TR_MNU_Pos)));
990 }
991 
992 /**
993   * @brief  Get Minutes in BCD format
994   * @note if shadow mode is disabled (BYPSHAD=0), need to check if RSF flag is set
995   *       before reading this bit
996   * @note Read either RTC_SSR or RTC_TR locks the values in the higher-order calendar
997   *       shadow registers until RTC_DR is read (LL_RTC_ReadReg(RTC, DR)).
998   * @note helper macro __LL_RTC_CONVERT_BCD2BIN is available to convert minute from BCD
999   *       to Binary format
1000   * @rmtoll RTC_TR           MNT           LL_RTC_TIME_GetMinute\n
1001   *         RTC_TR           MNU           LL_RTC_TIME_GetMinute
1002   * @param  RTCx RTC Instance
1003   * @retval Value between Min_Data=0x00 and Max_Data=0x59
1004   */
LL_RTC_TIME_GetMinute(RTC_TypeDef * RTCx)1005 __STATIC_INLINE uint32_t LL_RTC_TIME_GetMinute(RTC_TypeDef *RTCx)
1006 {
1007   return ((READ_BIT(RTCx->TR, (RTC_TR_MNT | RTC_TR_MNU))) >> RTC_TR_MNU_Pos);
1008 }
1009 
1010 /**
1011   * @brief  Set Seconds in BCD format
1012   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
1013   * @note   It can be written in initialization mode only (@ref LL_RTC_EnableInitMode function)
1014   * @note helper macro __LL_RTC_CONVERT_BIN2BCD is available to convert Seconds from binary to BCD format
1015   * @rmtoll RTC_TR           ST            LL_RTC_TIME_SetSecond\n
1016   *         RTC_TR           SU            LL_RTC_TIME_SetSecond
1017   * @param  RTCx RTC Instance
1018   * @param  Seconds Value between Min_Data=0x00 and Max_Data=0x59
1019   * @retval None
1020   */
LL_RTC_TIME_SetSecond(RTC_TypeDef * RTCx,uint32_t Seconds)1021 __STATIC_INLINE void LL_RTC_TIME_SetSecond(RTC_TypeDef *RTCx, uint32_t Seconds)
1022 {
1023   MODIFY_REG(RTCx->TR, (RTC_TR_ST | RTC_TR_SU),
1024              (((Seconds & 0xF0U) << (RTC_TR_ST_Pos - 4U)) | ((Seconds & 0x0FU) << RTC_TR_SU_Pos)));
1025 }
1026 
1027 /**
1028   * @brief  Get Seconds in BCD format
1029   * @note if shadow mode is disabled (BYPSHAD=0), need to check if RSF flag is set
1030   *       before reading this bit
1031   * @note Read either RTC_SSR or RTC_TR locks the values in the higher-order calendar
1032   *       shadow registers until RTC_DR is read (LL_RTC_ReadReg(RTC, DR)).
1033   * @note helper macro __LL_RTC_CONVERT_BCD2BIN is available to convert Seconds from BCD
1034   *       to Binary format
1035   * @rmtoll RTC_TR           ST            LL_RTC_TIME_GetSecond\n
1036   *         RTC_TR           SU            LL_RTC_TIME_GetSecond
1037   * @param  RTCx RTC Instance
1038   * @retval Value between Min_Data=0x00 and Max_Data=0x59
1039   */
LL_RTC_TIME_GetSecond(RTC_TypeDef * RTCx)1040 __STATIC_INLINE uint32_t LL_RTC_TIME_GetSecond(RTC_TypeDef *RTCx)
1041 {
1042   return ((READ_BIT(RTCx->TR, (RTC_TR_ST | RTC_TR_SU))) >> RTC_TR_SU_Pos);
1043 }
1044 
1045 /**
1046   * @brief  Set time (hour, minute and second) in BCD format
1047   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
1048   * @note   It can be written in initialization mode only (@ref LL_RTC_EnableInitMode function)
1049   * @note TimeFormat and Hours should follow the same format
1050   * @rmtoll RTC_TR           PM            LL_RTC_TIME_Config\n
1051   *         RTC_TR           HT            LL_RTC_TIME_Config\n
1052   *         RTC_TR           HU            LL_RTC_TIME_Config\n
1053   *         RTC_TR           MNT           LL_RTC_TIME_Config\n
1054   *         RTC_TR           MNU           LL_RTC_TIME_Config\n
1055   *         RTC_TR           ST            LL_RTC_TIME_Config\n
1056   *         RTC_TR           SU            LL_RTC_TIME_Config
1057   * @param  RTCx RTC Instance
1058   * @param  Format12_24 This parameter can be one of the following values:
1059   *         @arg @ref LL_RTC_TIME_FORMAT_AM_OR_24
1060   *         @arg @ref LL_RTC_TIME_FORMAT_PM
1061   * @param  Hours Value between Min_Data=0x01 and Max_Data=0x12 or between Min_Data=0x00 and Max_Data=0x23
1062   * @param  Minutes Value between Min_Data=0x00 and Max_Data=0x59
1063   * @param  Seconds Value between Min_Data=0x00 and Max_Data=0x59
1064   * @retval None
1065   */
LL_RTC_TIME_Config(RTC_TypeDef * RTCx,uint32_t Format12_24,uint32_t Hours,uint32_t Minutes,uint32_t Seconds)1066 __STATIC_INLINE void LL_RTC_TIME_Config(RTC_TypeDef *RTCx, uint32_t Format12_24, uint32_t Hours, uint32_t Minutes,
1067                                         uint32_t Seconds)
1068 {
1069   register uint32_t temp;
1070 
1071   temp = Format12_24                                                                            | \
1072          (((Hours & 0xF0U) << (RTC_TR_HT_Pos - 4U)) | ((Hours & 0x0FU) << RTC_TR_HU_Pos))       | \
1073          (((Minutes & 0xF0U) << (RTC_TR_MNT_Pos - 4U)) | ((Minutes & 0x0FU) << RTC_TR_MNU_Pos)) | \
1074          (((Seconds & 0xF0U) << (RTC_TR_ST_Pos - 4U)) | ((Seconds & 0x0FU) << RTC_TR_SU_Pos));
1075   MODIFY_REG(RTCx->TR, (RTC_TR_PM | RTC_TR_HT | RTC_TR_HU | RTC_TR_MNT | RTC_TR_MNU | RTC_TR_ST | RTC_TR_SU), temp);
1076 }
1077 
1078 /**
1079   * @brief  Get time (hour, minute and second) in BCD format
1080   * @note if shadow mode is disabled (BYPSHAD=0), need to check if RSF flag is set
1081   *       before reading this bit
1082   * @note Read either RTC_SSR or RTC_TR locks the values in the higher-order calendar
1083   *       shadow registers until RTC_DR is read (LL_RTC_ReadReg(RTC, DR)).
1084   * @note helper macros __LL_RTC_GET_HOUR, __LL_RTC_GET_MINUTE and __LL_RTC_GET_SECOND
1085   *       are available to get independently each parameter.
1086   * @rmtoll RTC_TR           HT            LL_RTC_TIME_Get\n
1087   *         RTC_TR           HU            LL_RTC_TIME_Get\n
1088   *         RTC_TR           MNT           LL_RTC_TIME_Get\n
1089   *         RTC_TR           MNU           LL_RTC_TIME_Get\n
1090   *         RTC_TR           ST            LL_RTC_TIME_Get\n
1091   *         RTC_TR           SU            LL_RTC_TIME_Get
1092   * @param  RTCx RTC Instance
1093   * @retval Combination of hours, minutes and seconds (Format: 0x00HHMMSS).
1094   */
LL_RTC_TIME_Get(RTC_TypeDef * RTCx)1095 __STATIC_INLINE uint32_t LL_RTC_TIME_Get(RTC_TypeDef *RTCx)
1096 {
1097   register uint32_t temp;
1098 
1099   temp = READ_BIT(RTCx->TR, (RTC_TR_HT | RTC_TR_HU | RTC_TR_MNT | RTC_TR_MNU | RTC_TR_ST | RTC_TR_SU));
1100   return (uint32_t)((((((temp & RTC_TR_HT) >> RTC_TR_HT_Pos) << 4U) | ((temp & RTC_TR_HU) >> RTC_TR_HU_Pos)) << RTC_OFFSET_HOUR) |  \
1101                     (((((temp & RTC_TR_MNT) >> RTC_TR_MNT_Pos) << 4U) | ((temp & RTC_TR_MNU) >> RTC_TR_MNU_Pos)) << RTC_OFFSET_MINUTE) | \
1102                     ((((temp & RTC_TR_ST) >> RTC_TR_ST_Pos) << 4U) | ((temp & RTC_TR_SU) >> RTC_TR_SU_Pos)));
1103 }
1104 
1105 /**
1106   * @brief  Memorize whether the daylight saving time change has been performed
1107   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
1108   * @rmtoll RTC_CR           BKP           LL_RTC_TIME_EnableDayLightStore
1109   * @param  RTCx RTC Instance
1110   * @retval None
1111   */
LL_RTC_TIME_EnableDayLightStore(RTC_TypeDef * RTCx)1112 __STATIC_INLINE void LL_RTC_TIME_EnableDayLightStore(RTC_TypeDef *RTCx)
1113 {
1114   SET_BIT(RTCx->CR, RTC_CR_BKP);
1115 }
1116 
1117 /**
1118   * @brief  Disable memorization whether the daylight saving time change has been performed.
1119   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
1120   * @rmtoll RTC_CR           BKP           LL_RTC_TIME_DisableDayLightStore
1121   * @param  RTCx RTC Instance
1122   * @retval None
1123   */
LL_RTC_TIME_DisableDayLightStore(RTC_TypeDef * RTCx)1124 __STATIC_INLINE void LL_RTC_TIME_DisableDayLightStore(RTC_TypeDef *RTCx)
1125 {
1126   CLEAR_BIT(RTCx->CR, RTC_CR_BKP);
1127 }
1128 
1129 /**
1130   * @brief  Check if RTC Day Light Saving stored operation has been enabled or not
1131   * @rmtoll RTC_CR           BKP           LL_RTC_TIME_IsDayLightStoreEnabled
1132   * @param  RTCx RTC Instance
1133   * @retval State of bit (1 or 0).
1134   */
LL_RTC_TIME_IsDayLightStoreEnabled(RTC_TypeDef * RTCx)1135 __STATIC_INLINE uint32_t LL_RTC_TIME_IsDayLightStoreEnabled(RTC_TypeDef *RTCx)
1136 {
1137   return ((READ_BIT(RTCx->CR, RTC_CR_BKP) == (RTC_CR_BKP)) ? 1UL : 0UL);
1138 }
1139 
1140 /**
1141   * @brief  Subtract 1 hour (winter time change)
1142   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
1143   * @rmtoll RTC_CR           SUB1H         LL_RTC_TIME_DecHour
1144   * @param  RTCx RTC Instance
1145   * @retval None
1146   */
LL_RTC_TIME_DecHour(RTC_TypeDef * RTCx)1147 __STATIC_INLINE void LL_RTC_TIME_DecHour(RTC_TypeDef *RTCx)
1148 {
1149   SET_BIT(RTCx->CR, RTC_CR_SUB1H);
1150 }
1151 
1152 /**
1153   * @brief  Add 1 hour (summer time change)
1154   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
1155   * @rmtoll RTC_CR           ADD1H         LL_RTC_TIME_IncHour
1156   * @param  RTCx RTC Instance
1157   * @retval None
1158   */
LL_RTC_TIME_IncHour(RTC_TypeDef * RTCx)1159 __STATIC_INLINE void LL_RTC_TIME_IncHour(RTC_TypeDef *RTCx)
1160 {
1161   SET_BIT(RTCx->CR, RTC_CR_ADD1H);
1162 }
1163 
1164 /**
1165   * @brief  Get Sub second value in the synchronous prescaler counter.
1166   * @note  You can use both SubSeconds value and SecondFraction (PREDIV_S through
1167   *        LL_RTC_GetSynchPrescaler function) terms returned to convert Calendar
1168   *        SubSeconds value in second fraction ratio with time unit following
1169   *        generic formula:
1170   *          ==> Seconds fraction ratio * time_unit= [(SecondFraction-SubSeconds)/(SecondFraction+1)] * time_unit
1171   *        This conversion can be performed only if no shift operation is pending
1172   *        (ie. SHFP=0) when PREDIV_S >= SS.
1173   * @rmtoll RTC_SSR          SS            LL_RTC_TIME_GetSubSecond
1174   * @param  RTCx RTC Instance
1175   * @retval Sub second value (number between 0 and 65535)
1176   */
LL_RTC_TIME_GetSubSecond(RTC_TypeDef * RTCx)1177 __STATIC_INLINE uint32_t LL_RTC_TIME_GetSubSecond(RTC_TypeDef *RTCx)
1178 {
1179   return (uint32_t)(READ_BIT(RTCx->SSR, RTC_SSR_SS));
1180 }
1181 
1182 /**
1183   * @brief  Synchronize to a remote clock with a high degree of precision.
1184   * @note   This operation effectively subtracts from (delays) or advance the clock of a fraction of a second.
1185   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
1186   * @note   When REFCKON is set, firmware must not write to Shift control register.
1187   * @rmtoll RTC_SHIFTR       ADD1S         LL_RTC_TIME_Synchronize\n
1188   *         RTC_SHIFTR       SUBFS         LL_RTC_TIME_Synchronize
1189   * @param  RTCx RTC Instance
1190   * @param  ShiftSecond This parameter can be one of the following values:
1191   *         @arg @ref LL_RTC_SHIFT_SECOND_DELAY
1192   *         @arg @ref LL_RTC_SHIFT_SECOND_ADVANCE
1193   * @param  Fraction Number of Seconds Fractions (any value from 0 to 0x7FFF)
1194   * @retval None
1195   */
LL_RTC_TIME_Synchronize(RTC_TypeDef * RTCx,uint32_t ShiftSecond,uint32_t Fraction)1196 __STATIC_INLINE void LL_RTC_TIME_Synchronize(RTC_TypeDef *RTCx, uint32_t ShiftSecond, uint32_t Fraction)
1197 {
1198   WRITE_REG(RTCx->SHIFTR, ShiftSecond | Fraction);
1199 }
1200 
1201 /**
1202   * @}
1203   */
1204 
1205 /** @defgroup RTC_LL_EF_Date Date
1206   * @{
1207   */
1208 
1209 /**
1210   * @brief  Set Year in BCD format
1211   * @note helper macro __LL_RTC_CONVERT_BIN2BCD is available to convert Year from binary to BCD format
1212   * @rmtoll RTC_DR           YT            LL_RTC_DATE_SetYear\n
1213   *         RTC_DR           YU            LL_RTC_DATE_SetYear
1214   * @param  RTCx RTC Instance
1215   * @param  Year Value between Min_Data=0x00 and Max_Data=0x99
1216   * @retval None
1217   */
LL_RTC_DATE_SetYear(RTC_TypeDef * RTCx,uint32_t Year)1218 __STATIC_INLINE void LL_RTC_DATE_SetYear(RTC_TypeDef *RTCx, uint32_t Year)
1219 {
1220   MODIFY_REG(RTCx->DR, (RTC_DR_YT | RTC_DR_YU),
1221              (((Year & 0xF0U) << (RTC_DR_YT_Pos - 4U)) | ((Year & 0x0FU) << RTC_DR_YU_Pos)));
1222 }
1223 
1224 /**
1225   * @brief  Get Year in BCD format
1226   * @note if shadow mode is disabled (BYPSHAD=0), need to check if RSF flag is set
1227   *       before reading this bit
1228   * @note helper macro __LL_RTC_CONVERT_BCD2BIN is available to convert Year from BCD to Binary format
1229   * @rmtoll RTC_DR           YT            LL_RTC_DATE_GetYear\n
1230   *         RTC_DR           YU            LL_RTC_DATE_GetYear
1231   * @param  RTCx RTC Instance
1232   * @retval Value between Min_Data=0x00 and Max_Data=0x99
1233   */
LL_RTC_DATE_GetYear(RTC_TypeDef * RTCx)1234 __STATIC_INLINE uint32_t LL_RTC_DATE_GetYear(RTC_TypeDef *RTCx)
1235 {
1236   return ((READ_BIT(RTCx->DR, (RTC_DR_YT | RTC_DR_YU))) >> RTC_DR_YU_Pos);
1237 }
1238 
1239 /**
1240   * @brief  Set Week day
1241   * @rmtoll RTC_DR           WDU           LL_RTC_DATE_SetWeekDay
1242   * @param  RTCx RTC Instance
1243   * @param  WeekDay This parameter can be one of the following values:
1244   *         @arg @ref LL_RTC_WEEKDAY_MONDAY
1245   *         @arg @ref LL_RTC_WEEKDAY_TUESDAY
1246   *         @arg @ref LL_RTC_WEEKDAY_WEDNESDAY
1247   *         @arg @ref LL_RTC_WEEKDAY_THURSDAY
1248   *         @arg @ref LL_RTC_WEEKDAY_FRIDAY
1249   *         @arg @ref LL_RTC_WEEKDAY_SATURDAY
1250   *         @arg @ref LL_RTC_WEEKDAY_SUNDAY
1251   * @retval None
1252   */
LL_RTC_DATE_SetWeekDay(RTC_TypeDef * RTCx,uint32_t WeekDay)1253 __STATIC_INLINE void LL_RTC_DATE_SetWeekDay(RTC_TypeDef *RTCx, uint32_t WeekDay)
1254 {
1255   MODIFY_REG(RTCx->DR, RTC_DR_WDU, WeekDay << RTC_DR_WDU_Pos);
1256 }
1257 
1258 /**
1259   * @brief  Get Week day
1260   * @note if shadow mode is disabled (BYPSHAD=0), need to check if RSF flag is set
1261   *       before reading this bit
1262   * @rmtoll RTC_DR           WDU           LL_RTC_DATE_GetWeekDay
1263   * @param  RTCx RTC Instance
1264   * @retval Returned value can be one of the following values:
1265   *         @arg @ref LL_RTC_WEEKDAY_MONDAY
1266   *         @arg @ref LL_RTC_WEEKDAY_TUESDAY
1267   *         @arg @ref LL_RTC_WEEKDAY_WEDNESDAY
1268   *         @arg @ref LL_RTC_WEEKDAY_THURSDAY
1269   *         @arg @ref LL_RTC_WEEKDAY_FRIDAY
1270   *         @arg @ref LL_RTC_WEEKDAY_SATURDAY
1271   *         @arg @ref LL_RTC_WEEKDAY_SUNDAY
1272   */
LL_RTC_DATE_GetWeekDay(RTC_TypeDef * RTCx)1273 __STATIC_INLINE uint32_t LL_RTC_DATE_GetWeekDay(RTC_TypeDef *RTCx)
1274 {
1275   return (uint32_t)(READ_BIT(RTCx->DR, RTC_DR_WDU) >> RTC_DR_WDU_Pos);
1276 }
1277 
1278 /**
1279   * @brief  Set Month in BCD format
1280   * @note helper macro __LL_RTC_CONVERT_BIN2BCD is available to convert Month from binary to BCD format
1281   * @rmtoll RTC_DR           MT            LL_RTC_DATE_SetMonth\n
1282   *         RTC_DR           MU            LL_RTC_DATE_SetMonth
1283   * @param  RTCx RTC Instance
1284   * @param  Month This parameter can be one of the following values:
1285   *         @arg @ref LL_RTC_MONTH_JANUARY
1286   *         @arg @ref LL_RTC_MONTH_FEBRUARY
1287   *         @arg @ref LL_RTC_MONTH_MARCH
1288   *         @arg @ref LL_RTC_MONTH_APRIL
1289   *         @arg @ref LL_RTC_MONTH_MAY
1290   *         @arg @ref LL_RTC_MONTH_JUNE
1291   *         @arg @ref LL_RTC_MONTH_JULY
1292   *         @arg @ref LL_RTC_MONTH_AUGUST
1293   *         @arg @ref LL_RTC_MONTH_SEPTEMBER
1294   *         @arg @ref LL_RTC_MONTH_OCTOBER
1295   *         @arg @ref LL_RTC_MONTH_NOVEMBER
1296   *         @arg @ref LL_RTC_MONTH_DECEMBER
1297   * @retval None
1298   */
LL_RTC_DATE_SetMonth(RTC_TypeDef * RTCx,uint32_t Month)1299 __STATIC_INLINE void LL_RTC_DATE_SetMonth(RTC_TypeDef *RTCx, uint32_t Month)
1300 {
1301   MODIFY_REG(RTCx->DR, (RTC_DR_MT | RTC_DR_MU),
1302              (((Month & 0xF0U) << (RTC_DR_MT_Pos - 4U)) | ((Month & 0x0FU) << RTC_DR_MU_Pos)));
1303 }
1304 
1305 /**
1306   * @brief  Get Month in BCD format
1307   * @note if shadow mode is disabled (BYPSHAD=0), need to check if RSF flag is set
1308   *       before reading this bit
1309   * @note helper macro __LL_RTC_CONVERT_BCD2BIN is available to convert Month from BCD to Binary format
1310   * @rmtoll RTC_DR           MT            LL_RTC_DATE_GetMonth\n
1311   *         RTC_DR           MU            LL_RTC_DATE_GetMonth
1312   * @param  RTCx RTC Instance
1313   * @retval Returned value can be one of the following values:
1314   *         @arg @ref LL_RTC_MONTH_JANUARY
1315   *         @arg @ref LL_RTC_MONTH_FEBRUARY
1316   *         @arg @ref LL_RTC_MONTH_MARCH
1317   *         @arg @ref LL_RTC_MONTH_APRIL
1318   *         @arg @ref LL_RTC_MONTH_MAY
1319   *         @arg @ref LL_RTC_MONTH_JUNE
1320   *         @arg @ref LL_RTC_MONTH_JULY
1321   *         @arg @ref LL_RTC_MONTH_AUGUST
1322   *         @arg @ref LL_RTC_MONTH_SEPTEMBER
1323   *         @arg @ref LL_RTC_MONTH_OCTOBER
1324   *         @arg @ref LL_RTC_MONTH_NOVEMBER
1325   *         @arg @ref LL_RTC_MONTH_DECEMBER
1326   */
LL_RTC_DATE_GetMonth(RTC_TypeDef * RTCx)1327 __STATIC_INLINE uint32_t LL_RTC_DATE_GetMonth(RTC_TypeDef *RTCx)
1328 {
1329   return ((READ_BIT(RTCx->DR, (RTC_DR_MT | RTC_DR_MU))) >> RTC_DR_MU_Pos);
1330 }
1331 
1332 /**
1333   * @brief  Set Day in BCD format
1334   * @note helper macro __LL_RTC_CONVERT_BIN2BCD is available to convert Day from binary to BCD format
1335   * @rmtoll RTC_DR           DT            LL_RTC_DATE_SetDay\n
1336   *         RTC_DR           DU            LL_RTC_DATE_SetDay
1337   * @param  RTCx RTC Instance
1338   * @param  Day Value between Min_Data=0x01 and Max_Data=0x31
1339   * @retval None
1340   */
LL_RTC_DATE_SetDay(RTC_TypeDef * RTCx,uint32_t Day)1341 __STATIC_INLINE void LL_RTC_DATE_SetDay(RTC_TypeDef *RTCx, uint32_t Day)
1342 {
1343   MODIFY_REG(RTCx->DR, (RTC_DR_DT | RTC_DR_DU),
1344              (((Day & 0xF0U) << (RTC_DR_DT_Pos - 4U)) | ((Day & 0x0FU) << RTC_DR_DU_Pos)));
1345 }
1346 
1347 /**
1348   * @brief  Get Day in BCD format
1349   * @note if shadow mode is disabled (BYPSHAD=0), need to check if RSF flag is set
1350   *       before reading this bit
1351   * @note helper macro __LL_RTC_CONVERT_BCD2BIN is available to convert Day from BCD to Binary format
1352   * @rmtoll RTC_DR           DT            LL_RTC_DATE_GetDay\n
1353   *         RTC_DR           DU            LL_RTC_DATE_GetDay
1354   * @param  RTCx RTC Instance
1355   * @retval Value between Min_Data=0x01 and Max_Data=0x31
1356   */
LL_RTC_DATE_GetDay(RTC_TypeDef * RTCx)1357 __STATIC_INLINE uint32_t LL_RTC_DATE_GetDay(RTC_TypeDef *RTCx)
1358 {
1359   return ((READ_BIT(RTCx->DR, (RTC_DR_DT | RTC_DR_DU))) >> RTC_DR_DU_Pos);
1360 }
1361 
1362 /**
1363   * @brief  Set date (WeekDay, Day, Month and Year) in BCD format
1364   * @rmtoll RTC_DR           WDU           LL_RTC_DATE_Config\n
1365   *         RTC_DR           MT            LL_RTC_DATE_Config\n
1366   *         RTC_DR           MU            LL_RTC_DATE_Config\n
1367   *         RTC_DR           DT            LL_RTC_DATE_Config\n
1368   *         RTC_DR           DU            LL_RTC_DATE_Config\n
1369   *         RTC_DR           YT            LL_RTC_DATE_Config\n
1370   *         RTC_DR           YU            LL_RTC_DATE_Config
1371   * @param  RTCx RTC Instance
1372   * @param  WeekDay This parameter can be one of the following values:
1373   *         @arg @ref LL_RTC_WEEKDAY_MONDAY
1374   *         @arg @ref LL_RTC_WEEKDAY_TUESDAY
1375   *         @arg @ref LL_RTC_WEEKDAY_WEDNESDAY
1376   *         @arg @ref LL_RTC_WEEKDAY_THURSDAY
1377   *         @arg @ref LL_RTC_WEEKDAY_FRIDAY
1378   *         @arg @ref LL_RTC_WEEKDAY_SATURDAY
1379   *         @arg @ref LL_RTC_WEEKDAY_SUNDAY
1380   * @param  Day Value between Min_Data=0x01 and Max_Data=0x31
1381   * @param  Month This parameter can be one of the following values:
1382   *         @arg @ref LL_RTC_MONTH_JANUARY
1383   *         @arg @ref LL_RTC_MONTH_FEBRUARY
1384   *         @arg @ref LL_RTC_MONTH_MARCH
1385   *         @arg @ref LL_RTC_MONTH_APRIL
1386   *         @arg @ref LL_RTC_MONTH_MAY
1387   *         @arg @ref LL_RTC_MONTH_JUNE
1388   *         @arg @ref LL_RTC_MONTH_JULY
1389   *         @arg @ref LL_RTC_MONTH_AUGUST
1390   *         @arg @ref LL_RTC_MONTH_SEPTEMBER
1391   *         @arg @ref LL_RTC_MONTH_OCTOBER
1392   *         @arg @ref LL_RTC_MONTH_NOVEMBER
1393   *         @arg @ref LL_RTC_MONTH_DECEMBER
1394   * @param  Year Value between Min_Data=0x00 and Max_Data=0x99
1395   * @retval None
1396   */
LL_RTC_DATE_Config(RTC_TypeDef * RTCx,uint32_t WeekDay,uint32_t Day,uint32_t Month,uint32_t Year)1397 __STATIC_INLINE void LL_RTC_DATE_Config(RTC_TypeDef *RTCx, uint32_t WeekDay, uint32_t Day, uint32_t Month,
1398                                         uint32_t Year)
1399 {
1400   register uint32_t temp;
1401 
1402   temp = (WeekDay << RTC_DR_WDU_Pos)                                                        | \
1403          (((Year & 0xF0U) << (RTC_DR_YT_Pos - 4U)) | ((Year & 0x0FU) << RTC_DR_YU_Pos))   | \
1404          (((Month & 0xF0U) << (RTC_DR_MT_Pos - 4U)) | ((Month & 0x0FU) << RTC_DR_MU_Pos)) | \
1405          (((Day & 0xF0U) << (RTC_DR_DT_Pos - 4U)) | ((Day & 0x0FU) << RTC_DR_DU_Pos));
1406 
1407   MODIFY_REG(RTCx->DR, (RTC_DR_WDU | RTC_DR_MT | RTC_DR_MU | RTC_DR_DT | RTC_DR_DU | RTC_DR_YT | RTC_DR_YU), temp);
1408 }
1409 
1410 /**
1411   * @brief  Get date (WeekDay, Day, Month and Year) in BCD format
1412   * @note if shadow mode is disabled (BYPSHAD=0), need to check if RSF flag is set
1413   *       before reading this bit
1414   * @note helper macros __LL_RTC_GET_WEEKDAY, __LL_RTC_GET_YEAR, __LL_RTC_GET_MONTH,
1415   * and __LL_RTC_GET_DAY are available to get independently each parameter.
1416   * @rmtoll RTC_DR           WDU           LL_RTC_DATE_Get\n
1417   *         RTC_DR           MT            LL_RTC_DATE_Get\n
1418   *         RTC_DR           MU            LL_RTC_DATE_Get\n
1419   *         RTC_DR           DT            LL_RTC_DATE_Get\n
1420   *         RTC_DR           DU            LL_RTC_DATE_Get\n
1421   *         RTC_DR           YT            LL_RTC_DATE_Get\n
1422   *         RTC_DR           YU            LL_RTC_DATE_Get
1423   * @param  RTCx RTC Instance
1424   * @retval Combination of WeekDay, Day, Month and Year (Format: 0xWWDDMMYY).
1425   */
LL_RTC_DATE_Get(RTC_TypeDef * RTCx)1426 __STATIC_INLINE uint32_t LL_RTC_DATE_Get(RTC_TypeDef *RTCx)
1427 {
1428   register uint32_t temp;
1429 
1430   temp = READ_BIT(RTCx->DR, (RTC_DR_WDU | RTC_DR_MT | RTC_DR_MU | RTC_DR_DT | RTC_DR_DU | RTC_DR_YT | RTC_DR_YU));
1431   return (uint32_t)((((temp & RTC_DR_WDU) >> RTC_DR_WDU_Pos) << RTC_OFFSET_WEEKDAY) | \
1432                     (((((temp & RTC_DR_DT) >> RTC_DR_DT_Pos) << 4U) | ((temp & RTC_DR_DU) >> RTC_DR_DU_Pos)) << RTC_OFFSET_DAY) | \
1433                     (((((temp & RTC_DR_MT) >> RTC_DR_MT_Pos) << 4U) | ((temp & RTC_DR_MU) >> RTC_DR_MU_Pos)) << RTC_OFFSET_MONTH) | \
1434                     ((((temp & RTC_DR_YT) >> RTC_DR_YT_Pos) << 4U) | ((temp & RTC_DR_YU) >> RTC_DR_YU_Pos)));
1435 }
1436 
1437 /**
1438   * @}
1439   */
1440 
1441 /** @defgroup RTC_LL_EF_ALARMA ALARMA
1442   * @{
1443   */
1444 
1445 /**
1446   * @brief  Enable Alarm A
1447   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
1448   * @rmtoll RTC_CR           ALRAE         LL_RTC_ALMA_Enable
1449   * @param  RTCx RTC Instance
1450   * @retval None
1451   */
LL_RTC_ALMA_Enable(RTC_TypeDef * RTCx)1452 __STATIC_INLINE void LL_RTC_ALMA_Enable(RTC_TypeDef *RTCx)
1453 {
1454   SET_BIT(RTCx->CR, RTC_CR_ALRAE);
1455 }
1456 
1457 /**
1458   * @brief  Disable Alarm A
1459   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
1460   * @rmtoll RTC_CR           ALRAE         LL_RTC_ALMA_Disable
1461   * @param  RTCx RTC Instance
1462   * @retval None
1463   */
LL_RTC_ALMA_Disable(RTC_TypeDef * RTCx)1464 __STATIC_INLINE void LL_RTC_ALMA_Disable(RTC_TypeDef *RTCx)
1465 {
1466   CLEAR_BIT(RTCx->CR, RTC_CR_ALRAE);
1467 }
1468 
1469 /**
1470   * @brief  Specify the Alarm A masks.
1471   * @rmtoll RTC_ALRMAR       MSK4          LL_RTC_ALMA_SetMask\n
1472   *         RTC_ALRMAR       MSK3          LL_RTC_ALMA_SetMask\n
1473   *         RTC_ALRMAR       MSK2          LL_RTC_ALMA_SetMask\n
1474   *         RTC_ALRMAR       MSK1          LL_RTC_ALMA_SetMask
1475   * @param  RTCx RTC Instance
1476   * @param  Mask This parameter can be a combination of the following values:
1477   *         @arg @ref LL_RTC_ALMA_MASK_NONE
1478   *         @arg @ref LL_RTC_ALMA_MASK_DATEWEEKDAY
1479   *         @arg @ref LL_RTC_ALMA_MASK_HOURS
1480   *         @arg @ref LL_RTC_ALMA_MASK_MINUTES
1481   *         @arg @ref LL_RTC_ALMA_MASK_SECONDS
1482   *         @arg @ref LL_RTC_ALMA_MASK_ALL
1483   * @retval None
1484   */
LL_RTC_ALMA_SetMask(RTC_TypeDef * RTCx,uint32_t Mask)1485 __STATIC_INLINE void LL_RTC_ALMA_SetMask(RTC_TypeDef *RTCx, uint32_t Mask)
1486 {
1487   MODIFY_REG(RTCx->ALRMAR, RTC_ALRMAR_MSK4 | RTC_ALRMAR_MSK3 | RTC_ALRMAR_MSK2 | RTC_ALRMAR_MSK1, Mask);
1488 }
1489 
1490 /**
1491   * @brief  Get the Alarm A masks.
1492   * @rmtoll RTC_ALRMAR       MSK4          LL_RTC_ALMA_GetMask\n
1493   *         RTC_ALRMAR       MSK3          LL_RTC_ALMA_GetMask\n
1494   *         RTC_ALRMAR       MSK2          LL_RTC_ALMA_GetMask\n
1495   *         RTC_ALRMAR       MSK1          LL_RTC_ALMA_GetMask
1496   * @param  RTCx RTC Instance
1497   * @retval Returned value can be can be a combination of the following values:
1498   *         @arg @ref LL_RTC_ALMA_MASK_NONE
1499   *         @arg @ref LL_RTC_ALMA_MASK_DATEWEEKDAY
1500   *         @arg @ref LL_RTC_ALMA_MASK_HOURS
1501   *         @arg @ref LL_RTC_ALMA_MASK_MINUTES
1502   *         @arg @ref LL_RTC_ALMA_MASK_SECONDS
1503   *         @arg @ref LL_RTC_ALMA_MASK_ALL
1504   */
LL_RTC_ALMA_GetMask(RTC_TypeDef * RTCx)1505 __STATIC_INLINE uint32_t LL_RTC_ALMA_GetMask(RTC_TypeDef *RTCx)
1506 {
1507   return (uint32_t)(READ_BIT(RTCx->ALRMAR, RTC_ALRMAR_MSK4 | RTC_ALRMAR_MSK3 | RTC_ALRMAR_MSK2 | RTC_ALRMAR_MSK1));
1508 }
1509 
1510 /**
1511   * @brief  Enable AlarmA Week day selection (DU[3:0] represents the week day. DT[1:0] is do not care)
1512   * @rmtoll RTC_ALRMAR       WDSEL         LL_RTC_ALMA_EnableWeekday
1513   * @param  RTCx RTC Instance
1514   * @retval None
1515   */
LL_RTC_ALMA_EnableWeekday(RTC_TypeDef * RTCx)1516 __STATIC_INLINE void LL_RTC_ALMA_EnableWeekday(RTC_TypeDef *RTCx)
1517 {
1518   SET_BIT(RTCx->ALRMAR, RTC_ALRMAR_WDSEL);
1519 }
1520 
1521 /**
1522   * @brief  Disable AlarmA Week day selection (DU[3:0] represents the date )
1523   * @rmtoll RTC_ALRMAR       WDSEL         LL_RTC_ALMA_DisableWeekday
1524   * @param  RTCx RTC Instance
1525   * @retval None
1526   */
LL_RTC_ALMA_DisableWeekday(RTC_TypeDef * RTCx)1527 __STATIC_INLINE void LL_RTC_ALMA_DisableWeekday(RTC_TypeDef *RTCx)
1528 {
1529   CLEAR_BIT(RTCx->ALRMAR, RTC_ALRMAR_WDSEL);
1530 }
1531 
1532 /**
1533   * @brief  Set ALARM A Day in BCD format
1534   * @note helper macro __LL_RTC_CONVERT_BIN2BCD is available to convert Day from binary to BCD format
1535   * @rmtoll RTC_ALRMAR       DT            LL_RTC_ALMA_SetDay\n
1536   *         RTC_ALRMAR       DU            LL_RTC_ALMA_SetDay
1537   * @param  RTCx RTC Instance
1538   * @param  Day Value between Min_Data=0x01 and Max_Data=0x31
1539   * @retval None
1540   */
LL_RTC_ALMA_SetDay(RTC_TypeDef * RTCx,uint32_t Day)1541 __STATIC_INLINE void LL_RTC_ALMA_SetDay(RTC_TypeDef *RTCx, uint32_t Day)
1542 {
1543   MODIFY_REG(RTCx->ALRMAR, (RTC_ALRMAR_DT | RTC_ALRMAR_DU),
1544              (((Day & 0xF0U) << (RTC_ALRMAR_DT_Pos - 4U)) | ((Day & 0x0FU) << RTC_ALRMAR_DU_Pos)));
1545 }
1546 
1547 /**
1548   * @brief  Get ALARM A Day in BCD format
1549   * @note helper macro __LL_RTC_CONVERT_BCD2BIN is available to convert Day from BCD to Binary format
1550   * @rmtoll RTC_ALRMAR       DT            LL_RTC_ALMA_GetDay\n
1551   *         RTC_ALRMAR       DU            LL_RTC_ALMA_GetDay
1552   * @param  RTCx RTC Instance
1553   * @retval Value between Min_Data=0x01 and Max_Data=0x31
1554   */
LL_RTC_ALMA_GetDay(RTC_TypeDef * RTCx)1555 __STATIC_INLINE uint32_t LL_RTC_ALMA_GetDay(RTC_TypeDef *RTCx)
1556 {
1557   return ((READ_BIT(RTCx->ALRMAR, (RTC_ALRMAR_DT | RTC_ALRMAR_DU))) >> RTC_ALRMAR_DU_Pos);
1558 }
1559 
1560 /**
1561   * @brief  Set ALARM A Weekday
1562   * @rmtoll RTC_ALRMAR       DU            LL_RTC_ALMA_SetWeekDay
1563   * @param  RTCx RTC Instance
1564   * @param  WeekDay This parameter can be one of the following values:
1565   *         @arg @ref LL_RTC_WEEKDAY_MONDAY
1566   *         @arg @ref LL_RTC_WEEKDAY_TUESDAY
1567   *         @arg @ref LL_RTC_WEEKDAY_WEDNESDAY
1568   *         @arg @ref LL_RTC_WEEKDAY_THURSDAY
1569   *         @arg @ref LL_RTC_WEEKDAY_FRIDAY
1570   *         @arg @ref LL_RTC_WEEKDAY_SATURDAY
1571   *         @arg @ref LL_RTC_WEEKDAY_SUNDAY
1572   * @retval None
1573   */
LL_RTC_ALMA_SetWeekDay(RTC_TypeDef * RTCx,uint32_t WeekDay)1574 __STATIC_INLINE void LL_RTC_ALMA_SetWeekDay(RTC_TypeDef *RTCx, uint32_t WeekDay)
1575 {
1576   MODIFY_REG(RTCx->ALRMAR, RTC_ALRMAR_DU, WeekDay << RTC_ALRMAR_DU_Pos);
1577 }
1578 
1579 /**
1580   * @brief  Get ALARM A Weekday
1581   * @rmtoll RTC_ALRMAR       DU            LL_RTC_ALMA_GetWeekDay
1582   * @param  RTCx RTC Instance
1583   * @retval Returned value can be one of the following values:
1584   *         @arg @ref LL_RTC_WEEKDAY_MONDAY
1585   *         @arg @ref LL_RTC_WEEKDAY_TUESDAY
1586   *         @arg @ref LL_RTC_WEEKDAY_WEDNESDAY
1587   *         @arg @ref LL_RTC_WEEKDAY_THURSDAY
1588   *         @arg @ref LL_RTC_WEEKDAY_FRIDAY
1589   *         @arg @ref LL_RTC_WEEKDAY_SATURDAY
1590   *         @arg @ref LL_RTC_WEEKDAY_SUNDAY
1591   */
LL_RTC_ALMA_GetWeekDay(RTC_TypeDef * RTCx)1592 __STATIC_INLINE uint32_t LL_RTC_ALMA_GetWeekDay(RTC_TypeDef *RTCx)
1593 {
1594   return (uint32_t)(READ_BIT(RTCx->ALRMAR, RTC_ALRMAR_DU) >> RTC_ALRMAR_DU_Pos);
1595 }
1596 
1597 /**
1598   * @brief  Set Alarm A time format (AM/24-hour or PM notation)
1599   * @rmtoll RTC_ALRMAR       PM            LL_RTC_ALMA_SetTimeFormat
1600   * @param  RTCx RTC Instance
1601   * @param  TimeFormat This parameter can be one of the following values:
1602   *         @arg @ref LL_RTC_ALMA_TIME_FORMAT_AM
1603   *         @arg @ref LL_RTC_ALMA_TIME_FORMAT_PM
1604   * @retval None
1605   */
LL_RTC_ALMA_SetTimeFormat(RTC_TypeDef * RTCx,uint32_t TimeFormat)1606 __STATIC_INLINE void LL_RTC_ALMA_SetTimeFormat(RTC_TypeDef *RTCx, uint32_t TimeFormat)
1607 {
1608   MODIFY_REG(RTCx->ALRMAR, RTC_ALRMAR_PM, TimeFormat);
1609 }
1610 
1611 /**
1612   * @brief  Get Alarm A time format (AM or PM notation)
1613   * @rmtoll RTC_ALRMAR       PM            LL_RTC_ALMA_GetTimeFormat
1614   * @param  RTCx RTC Instance
1615   * @retval Returned value can be one of the following values:
1616   *         @arg @ref LL_RTC_ALMA_TIME_FORMAT_AM
1617   *         @arg @ref LL_RTC_ALMA_TIME_FORMAT_PM
1618   */
LL_RTC_ALMA_GetTimeFormat(RTC_TypeDef * RTCx)1619 __STATIC_INLINE uint32_t LL_RTC_ALMA_GetTimeFormat(RTC_TypeDef *RTCx)
1620 {
1621   return (uint32_t)(READ_BIT(RTCx->ALRMAR, RTC_ALRMAR_PM));
1622 }
1623 
1624 /**
1625   * @brief  Set ALARM A Hours in BCD format
1626   * @note helper macro __LL_RTC_CONVERT_BIN2BCD is available to convert Hours from binary to BCD format
1627   * @rmtoll RTC_ALRMAR       HT            LL_RTC_ALMA_SetHour\n
1628   *         RTC_ALRMAR       HU            LL_RTC_ALMA_SetHour
1629   * @param  RTCx RTC Instance
1630   * @param  Hours Value between Min_Data=0x01 and Max_Data=0x12 or between Min_Data=0x00 and Max_Data=0x23
1631   * @retval None
1632   */
LL_RTC_ALMA_SetHour(RTC_TypeDef * RTCx,uint32_t Hours)1633 __STATIC_INLINE void LL_RTC_ALMA_SetHour(RTC_TypeDef *RTCx, uint32_t Hours)
1634 {
1635   MODIFY_REG(RTCx->ALRMAR, (RTC_ALRMAR_HT | RTC_ALRMAR_HU),
1636              (((Hours & 0xF0U) << (RTC_ALRMAR_HT_Pos - 4U)) | ((Hours & 0x0FU) << RTC_ALRMAR_HU_Pos)));
1637 }
1638 
1639 /**
1640   * @brief  Get ALARM A Hours in BCD format
1641   * @note helper macro __LL_RTC_CONVERT_BCD2BIN is available to convert Hours from BCD to Binary format
1642   * @rmtoll RTC_ALRMAR       HT            LL_RTC_ALMA_GetHour\n
1643   *         RTC_ALRMAR       HU            LL_RTC_ALMA_GetHour
1644   * @param  RTCx RTC Instance
1645   * @retval Value between Min_Data=0x01 and Max_Data=0x12 or between Min_Data=0x00 and Max_Data=0x23
1646   */
LL_RTC_ALMA_GetHour(RTC_TypeDef * RTCx)1647 __STATIC_INLINE uint32_t LL_RTC_ALMA_GetHour(RTC_TypeDef *RTCx)
1648 {
1649   return ((READ_BIT(RTCx->ALRMAR, (RTC_ALRMAR_HT | RTC_ALRMAR_HU))) >> RTC_ALRMAR_HU_Pos);
1650 }
1651 
1652 /**
1653   * @brief  Set ALARM A Minutes in BCD format
1654   * @note helper macro __LL_RTC_CONVERT_BIN2BCD is available to convert Minutes from binary to BCD format
1655   * @rmtoll RTC_ALRMAR       MNT           LL_RTC_ALMA_SetMinute\n
1656   *         RTC_ALRMAR       MNU           LL_RTC_ALMA_SetMinute
1657   * @param  RTCx RTC Instance
1658   * @param  Minutes Value between Min_Data=0x00 and Max_Data=0x59
1659   * @retval None
1660   */
LL_RTC_ALMA_SetMinute(RTC_TypeDef * RTCx,uint32_t Minutes)1661 __STATIC_INLINE void LL_RTC_ALMA_SetMinute(RTC_TypeDef *RTCx, uint32_t Minutes)
1662 {
1663   MODIFY_REG(RTCx->ALRMAR, (RTC_ALRMAR_MNT | RTC_ALRMAR_MNU),
1664              (((Minutes & 0xF0U) << (RTC_ALRMAR_MNT_Pos - 4U)) | ((Minutes & 0x0FU) << RTC_ALRMAR_MNU_Pos)));
1665 }
1666 
1667 /**
1668   * @brief  Get ALARM A Minutes in BCD format
1669   * @note helper macro __LL_RTC_CONVERT_BCD2BIN is available to convert Minutes from BCD to Binary format
1670   * @rmtoll RTC_ALRMAR       MNT           LL_RTC_ALMA_GetMinute\n
1671   *         RTC_ALRMAR       MNU           LL_RTC_ALMA_GetMinute
1672   * @param  RTCx RTC Instance
1673   * @retval Value between Min_Data=0x00 and Max_Data=0x59
1674   */
LL_RTC_ALMA_GetMinute(RTC_TypeDef * RTCx)1675 __STATIC_INLINE uint32_t LL_RTC_ALMA_GetMinute(RTC_TypeDef *RTCx)
1676 {
1677   return ((READ_BIT(RTCx->ALRMAR, (RTC_ALRMAR_MNT | RTC_ALRMAR_MNU))) >> RTC_ALRMAR_MNU_Pos);
1678 }
1679 
1680 /**
1681   * @brief  Set ALARM A Seconds in BCD format
1682   * @note helper macro __LL_RTC_CONVERT_BIN2BCD is available to convert Seconds from binary to BCD format
1683   * @rmtoll RTC_ALRMAR       ST            LL_RTC_ALMA_SetSecond\n
1684   *         RTC_ALRMAR       SU            LL_RTC_ALMA_SetSecond
1685   * @param  RTCx RTC Instance
1686   * @param  Seconds Value between Min_Data=0x00 and Max_Data=0x59
1687   * @retval None
1688   */
LL_RTC_ALMA_SetSecond(RTC_TypeDef * RTCx,uint32_t Seconds)1689 __STATIC_INLINE void LL_RTC_ALMA_SetSecond(RTC_TypeDef *RTCx, uint32_t Seconds)
1690 {
1691   MODIFY_REG(RTCx->ALRMAR, (RTC_ALRMAR_ST | RTC_ALRMAR_SU),
1692              (((Seconds & 0xF0U) << (RTC_ALRMAR_ST_Pos - 4U)) | ((Seconds & 0x0FU) << RTC_ALRMAR_SU_Pos)));
1693 }
1694 
1695 /**
1696   * @brief  Get ALARM A Seconds in BCD format
1697   * @note helper macro __LL_RTC_CONVERT_BCD2BIN is available to convert Seconds from BCD to Binary format
1698   * @rmtoll RTC_ALRMAR       ST            LL_RTC_ALMA_GetSecond\n
1699   *         RTC_ALRMAR       SU            LL_RTC_ALMA_GetSecond
1700   * @param  RTCx RTC Instance
1701   * @retval Value between Min_Data=0x00 and Max_Data=0x59
1702   */
LL_RTC_ALMA_GetSecond(RTC_TypeDef * RTCx)1703 __STATIC_INLINE uint32_t LL_RTC_ALMA_GetSecond(RTC_TypeDef *RTCx)
1704 {
1705   return ((READ_BIT(RTCx->ALRMAR, (RTC_ALRMAR_ST | RTC_ALRMAR_SU))) >> RTC_ALRMAR_SU_Pos);
1706 }
1707 
1708 /**
1709   * @brief  Set Alarm A Time (hour, minute and second) in BCD format
1710   * @rmtoll RTC_ALRMAR       PM            LL_RTC_ALMA_ConfigTime\n
1711   *         RTC_ALRMAR       HT            LL_RTC_ALMA_ConfigTime\n
1712   *         RTC_ALRMAR       HU            LL_RTC_ALMA_ConfigTime\n
1713   *         RTC_ALRMAR       MNT           LL_RTC_ALMA_ConfigTime\n
1714   *         RTC_ALRMAR       MNU           LL_RTC_ALMA_ConfigTime\n
1715   *         RTC_ALRMAR       ST            LL_RTC_ALMA_ConfigTime\n
1716   *         RTC_ALRMAR       SU            LL_RTC_ALMA_ConfigTime
1717   * @param  RTCx RTC Instance
1718   * @param  Format12_24 This parameter can be one of the following values:
1719   *         @arg @ref LL_RTC_ALMA_TIME_FORMAT_AM
1720   *         @arg @ref LL_RTC_ALMA_TIME_FORMAT_PM
1721   * @param  Hours Value between Min_Data=0x01 and Max_Data=0x12 or between Min_Data=0x00 and Max_Data=0x23
1722   * @param  Minutes Value between Min_Data=0x00 and Max_Data=0x59
1723   * @param  Seconds Value between Min_Data=0x00 and Max_Data=0x59
1724   * @retval None
1725   */
LL_RTC_ALMA_ConfigTime(RTC_TypeDef * RTCx,uint32_t Format12_24,uint32_t Hours,uint32_t Minutes,uint32_t Seconds)1726 __STATIC_INLINE void LL_RTC_ALMA_ConfigTime(RTC_TypeDef *RTCx, uint32_t Format12_24, uint32_t Hours, uint32_t Minutes,
1727                                             uint32_t Seconds)
1728 {
1729   register uint32_t temp;
1730 
1731   temp = Format12_24 | (((Hours & 0xF0U) << (RTC_ALRMAR_HT_Pos - 4U)) | ((Hours & 0x0FU) << RTC_ALRMAR_HU_Pos))    | \
1732          (((Minutes & 0xF0U) << (RTC_ALRMAR_MNT_Pos - 4U)) | ((Minutes & 0x0FU) << RTC_ALRMAR_MNU_Pos)) | \
1733          (((Seconds & 0xF0U) << (RTC_ALRMAR_ST_Pos - 4U)) | ((Seconds & 0x0FU) << RTC_ALRMAR_SU_Pos));
1734 
1735   MODIFY_REG(RTCx->ALRMAR, RTC_ALRMAR_PM | RTC_ALRMAR_HT | RTC_ALRMAR_HU | RTC_ALRMAR_MNT | RTC_ALRMAR_MNU | RTC_ALRMAR_ST
1736              | RTC_ALRMAR_SU, temp);
1737 }
1738 
1739 /**
1740   * @brief  Get Alarm A Time (hour, minute and second) in BCD format
1741   * @note helper macros __LL_RTC_GET_HOUR, __LL_RTC_GET_MINUTE and __LL_RTC_GET_SECOND
1742   * are available to get independently each parameter.
1743   * @rmtoll RTC_ALRMAR       HT            LL_RTC_ALMA_GetTime\n
1744   *         RTC_ALRMAR       HU            LL_RTC_ALMA_GetTime\n
1745   *         RTC_ALRMAR       MNT           LL_RTC_ALMA_GetTime\n
1746   *         RTC_ALRMAR       MNU           LL_RTC_ALMA_GetTime\n
1747   *         RTC_ALRMAR       ST            LL_RTC_ALMA_GetTime\n
1748   *         RTC_ALRMAR       SU            LL_RTC_ALMA_GetTime
1749   * @param  RTCx RTC Instance
1750   * @retval Combination of hours, minutes and seconds.
1751   */
LL_RTC_ALMA_GetTime(RTC_TypeDef * RTCx)1752 __STATIC_INLINE uint32_t LL_RTC_ALMA_GetTime(RTC_TypeDef *RTCx)
1753 {
1754   return (uint32_t)((LL_RTC_ALMA_GetHour(RTCx) << RTC_OFFSET_HOUR) | (LL_RTC_ALMA_GetMinute(RTCx) << RTC_OFFSET_MINUTE) | LL_RTC_ALMA_GetSecond(RTCx));
1755 }
1756 
1757 /**
1758   * @brief  Set Alarm A Mask the most-significant bits starting at this bit
1759   * @note This register can be written only when ALRAE is reset in RTC_CR register,
1760   *       or in initialization mode.
1761   * @rmtoll RTC_ALRMASSR     MASKSS        LL_RTC_ALMA_SetSubSecondMask
1762   * @param  RTCx RTC Instance
1763   * @param  Mask Value between Min_Data=0x00 and Max_Data=0xF
1764   * @retval None
1765   */
LL_RTC_ALMA_SetSubSecondMask(RTC_TypeDef * RTCx,uint32_t Mask)1766 __STATIC_INLINE void LL_RTC_ALMA_SetSubSecondMask(RTC_TypeDef *RTCx, uint32_t Mask)
1767 {
1768   MODIFY_REG(RTCx->ALRMASSR, RTC_ALRMASSR_MASKSS, Mask << RTC_ALRMASSR_MASKSS_Pos);
1769 }
1770 
1771 /**
1772   * @brief  Get Alarm A Mask the most-significant bits starting at this bit
1773   * @rmtoll RTC_ALRMASSR     MASKSS        LL_RTC_ALMA_GetSubSecondMask
1774   * @param  RTCx RTC Instance
1775   * @retval Value between Min_Data=0x00 and Max_Data=0xF
1776   */
LL_RTC_ALMA_GetSubSecondMask(RTC_TypeDef * RTCx)1777 __STATIC_INLINE uint32_t LL_RTC_ALMA_GetSubSecondMask(RTC_TypeDef *RTCx)
1778 {
1779   return (uint32_t)(READ_BIT(RTCx->ALRMASSR, RTC_ALRMASSR_MASKSS) >> RTC_ALRMASSR_MASKSS_Pos);
1780 }
1781 
1782 /**
1783   * @brief  Set Alarm A Sub seconds value
1784   * @rmtoll RCT_ALRMASSR     SS            LL_RTC_ALMA_SetSubSecond
1785   * @param  RTCx RTC Instance
1786   * @param  Subsecond Value between Min_Data=0x00 and Max_Data=0x7FFF
1787   * @retval None
1788   */
LL_RTC_ALMA_SetSubSecond(RTC_TypeDef * RTCx,uint32_t Subsecond)1789 __STATIC_INLINE void LL_RTC_ALMA_SetSubSecond(RTC_TypeDef *RTCx, uint32_t Subsecond)
1790 {
1791   MODIFY_REG(RTCx->ALRMASSR, RTC_ALRMASSR_SS, Subsecond);
1792 }
1793 
1794 /**
1795   * @brief  Get Alarm A Sub seconds value
1796   * @rmtoll RCT_ALRMASSR     SS            LL_RTC_ALMA_GetSubSecond
1797   * @param  RTCx RTC Instance
1798   * @retval Value between Min_Data=0x00 and Max_Data=0x7FFF
1799   */
LL_RTC_ALMA_GetSubSecond(RTC_TypeDef * RTCx)1800 __STATIC_INLINE uint32_t LL_RTC_ALMA_GetSubSecond(RTC_TypeDef *RTCx)
1801 {
1802   return (uint32_t)(READ_BIT(RTCx->ALRMASSR, RTC_ALRMASSR_SS));
1803 }
1804 
1805 /**
1806   * @}
1807   */
1808 
1809 /** @defgroup RTC_LL_EF_Timestamp Timestamp
1810   * @{
1811   */
1812 
1813 /**
1814   * @brief  Enable Timestamp
1815   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
1816   * @rmtoll RTC_CR           ITSE           LL_RTC_TS_Enable
1817   * @param  RTCx RTC Instance
1818   * @retval None
1819   */
LL_RTC_TS_Enable(RTC_TypeDef * RTCx)1820 __STATIC_INLINE void LL_RTC_TS_Enable(RTC_TypeDef *RTCx)
1821 {
1822   SET_BIT(RTCx->CR, RTC_CR_TSE);
1823 }
1824 
1825 /**
1826   * @brief  Disable Timestamp
1827   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
1828   * @rmtoll RTC_CR           ITSE           LL_RTC_TS_Disable
1829   * @param  RTCx RTC Instance
1830   * @retval None
1831   */
LL_RTC_TS_Disable(RTC_TypeDef * RTCx)1832 __STATIC_INLINE void LL_RTC_TS_Disable(RTC_TypeDef *RTCx)
1833 {
1834   CLEAR_BIT(RTCx->CR, RTC_CR_TSE);
1835 }
1836 
1837 /**
1838   * @brief  Set Time-stamp event active edge
1839   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
1840   * @note TSE must be reset when TSEDGE is changed to avoid unwanted TSF setting
1841   * @rmtoll RTC_CR           TSEDGE        LL_RTC_TS_SetActiveEdge
1842   * @param  RTCx RTC Instance
1843   * @param  Edge This parameter can be one of the following values:
1844   *         @arg @ref LL_RTC_TIMESTAMP_EDGE_RISING
1845   *         @arg @ref LL_RTC_TIMESTAMP_EDGE_FALLING
1846   * @retval None
1847   */
LL_RTC_TS_SetActiveEdge(RTC_TypeDef * RTCx,uint32_t Edge)1848 __STATIC_INLINE void LL_RTC_TS_SetActiveEdge(RTC_TypeDef *RTCx, uint32_t Edge)
1849 {
1850   MODIFY_REG(RTCx->CR, RTC_CR_TSEDGE, Edge);
1851 }
1852 
1853 /**
1854   * @brief  Get Time-stamp event active edge
1855   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
1856   * @rmtoll RTC_CR           TSEDGE        LL_RTC_TS_GetActiveEdge
1857   * @param  RTCx RTC Instance
1858   * @retval Returned value can be one of the following values:
1859   *         @arg @ref LL_RTC_TIMESTAMP_EDGE_RISING
1860   *         @arg @ref LL_RTC_TIMESTAMP_EDGE_FALLING
1861   */
LL_RTC_TS_GetActiveEdge(RTC_TypeDef * RTCx)1862 __STATIC_INLINE uint32_t LL_RTC_TS_GetActiveEdge(RTC_TypeDef *RTCx)
1863 {
1864   return (uint32_t)(READ_BIT(RTCx->CR, RTC_CR_TSEDGE));
1865 }
1866 
1867 /**
1868   * @brief  Get Timestamp AM/PM notation (AM or 24-hour format)
1869   * @rmtoll RTC_TSTR         PM            LL_RTC_TS_GetTimeFormat
1870   * @param  RTCx RTC Instance
1871   * @retval Returned value can be one of the following values:
1872   *         @arg @ref LL_RTC_TS_TIME_FORMAT_AM
1873   *         @arg @ref LL_RTC_TS_TIME_FORMAT_PM
1874   */
LL_RTC_TS_GetTimeFormat(RTC_TypeDef * RTCx)1875 __STATIC_INLINE uint32_t LL_RTC_TS_GetTimeFormat(RTC_TypeDef *RTCx)
1876 {
1877   return (uint32_t)(READ_BIT(RTCx->TSTR, RTC_TSTR_PM));
1878 }
1879 
1880 /**
1881   * @brief  Get Timestamp Hours in BCD format
1882   * @note helper macro __LL_RTC_CONVERT_BCD2BIN is available to convert Hours from BCD to Binary format
1883   * @rmtoll RTC_TSTR         HT            LL_RTC_TS_GetHour\n
1884   *         RTC_TSTR         HU            LL_RTC_TS_GetHour
1885   * @param  RTCx RTC Instance
1886   * @retval Value between Min_Data=0x01 and Max_Data=0x12 or between Min_Data=0x00 and Max_Data=0x23
1887   */
LL_RTC_TS_GetHour(RTC_TypeDef * RTCx)1888 __STATIC_INLINE uint32_t LL_RTC_TS_GetHour(RTC_TypeDef *RTCx)
1889 {
1890   return (uint32_t)(READ_BIT(RTCx->TSTR, RTC_TSTR_HT | RTC_TSTR_HU) >> RTC_TSTR_HU_Pos);
1891 }
1892 
1893 /**
1894   * @brief  Get Timestamp Minutes in BCD format
1895   * @note helper macro __LL_RTC_CONVERT_BCD2BIN is available to convert Minutes from BCD to Binary format
1896   * @rmtoll RTC_TSTR         MNT           LL_RTC_TS_GetMinute\n
1897   *         RTC_TSTR         MNU           LL_RTC_TS_GetMinute
1898   * @param  RTCx RTC Instance
1899   * @retval Value between Min_Data=0x00 and Max_Data=0x59
1900   */
LL_RTC_TS_GetMinute(RTC_TypeDef * RTCx)1901 __STATIC_INLINE uint32_t LL_RTC_TS_GetMinute(RTC_TypeDef *RTCx)
1902 {
1903   return (uint32_t)(READ_BIT(RTCx->TSTR, RTC_TSTR_MNT | RTC_TSTR_MNU) >> RTC_TSTR_MNU_Pos);
1904 }
1905 
1906 /**
1907   * @brief  Get Timestamp Seconds in BCD format
1908   * @note helper macro __LL_RTC_CONVERT_BCD2BIN is available to convert Seconds from BCD to Binary format
1909   * @rmtoll RTC_TSTR         ST            LL_RTC_TS_GetSecond\n
1910   *         RTC_TSTR         SU            LL_RTC_TS_GetSecond
1911   * @param  RTCx RTC Instance
1912   * @retval Value between Min_Data=0x00 and Max_Data=0x59
1913   */
LL_RTC_TS_GetSecond(RTC_TypeDef * RTCx)1914 __STATIC_INLINE uint32_t LL_RTC_TS_GetSecond(RTC_TypeDef *RTCx)
1915 {
1916   return (uint32_t)(READ_BIT(RTCx->TSTR, RTC_TSTR_ST | RTC_TSTR_SU));
1917 }
1918 
1919 /**
1920   * @brief  Get Timestamp time (hour, minute and second) in BCD format
1921   * @note helper macros __LL_RTC_GET_HOUR, __LL_RTC_GET_MINUTE and __LL_RTC_GET_SECOND
1922   * are available to get independently each parameter.
1923   * @rmtoll RTC_TSTR         HT            LL_RTC_TS_GetTime\n
1924   *         RTC_TSTR         HU            LL_RTC_TS_GetTime\n
1925   *         RTC_TSTR         MNT           LL_RTC_TS_GetTime\n
1926   *         RTC_TSTR         MNU           LL_RTC_TS_GetTime\n
1927   *         RTC_TSTR         ST            LL_RTC_TS_GetTime\n
1928   *         RTC_TSTR         SU            LL_RTC_TS_GetTime
1929   * @param  RTCx RTC Instance
1930   * @retval Combination of hours, minutes and seconds.
1931   */
LL_RTC_TS_GetTime(RTC_TypeDef * RTCx)1932 __STATIC_INLINE uint32_t LL_RTC_TS_GetTime(RTC_TypeDef *RTCx)
1933 {
1934   return (uint32_t)(READ_BIT(RTCx->TSTR,
1935                              RTC_TSTR_HT | RTC_TSTR_HU | RTC_TSTR_MNT | RTC_TSTR_MNU | RTC_TSTR_ST | RTC_TSTR_SU));
1936 }
1937 
1938 /**
1939   * @brief  Get Timestamp Week day
1940   * @rmtoll RTC_TSDR         WDU           LL_RTC_TS_GetWeekDay
1941   * @param  RTCx RTC Instance
1942   * @retval Returned value can be one of the following values:
1943   *         @arg @ref LL_RTC_WEEKDAY_MONDAY
1944   *         @arg @ref LL_RTC_WEEKDAY_TUESDAY
1945   *         @arg @ref LL_RTC_WEEKDAY_WEDNESDAY
1946   *         @arg @ref LL_RTC_WEEKDAY_THURSDAY
1947   *         @arg @ref LL_RTC_WEEKDAY_FRIDAY
1948   *         @arg @ref LL_RTC_WEEKDAY_SATURDAY
1949   *         @arg @ref LL_RTC_WEEKDAY_SUNDAY
1950   */
LL_RTC_TS_GetWeekDay(RTC_TypeDef * RTCx)1951 __STATIC_INLINE uint32_t LL_RTC_TS_GetWeekDay(RTC_TypeDef *RTCx)
1952 {
1953   return (uint32_t)(READ_BIT(RTCx->TSDR, RTC_TSDR_WDU) >> RTC_TSDR_WDU_Pos);
1954 }
1955 
1956 /**
1957   * @brief  Get Timestamp Month in BCD format
1958   * @note helper macro __LL_RTC_CONVERT_BCD2BIN is available to convert Month from BCD to Binary format
1959   * @rmtoll RTC_TSDR         MT            LL_RTC_TS_GetMonth\n
1960   *         RTC_TSDR         MU            LL_RTC_TS_GetMonth
1961   * @param  RTCx RTC Instance
1962   * @retval Returned value can be one of the following values:
1963   *         @arg @ref LL_RTC_MONTH_JANUARY
1964   *         @arg @ref LL_RTC_MONTH_FEBRUARY
1965   *         @arg @ref LL_RTC_MONTH_MARCH
1966   *         @arg @ref LL_RTC_MONTH_APRIL
1967   *         @arg @ref LL_RTC_MONTH_MAY
1968   *         @arg @ref LL_RTC_MONTH_JUNE
1969   *         @arg @ref LL_RTC_MONTH_JULY
1970   *         @arg @ref LL_RTC_MONTH_AUGUST
1971   *         @arg @ref LL_RTC_MONTH_SEPTEMBER
1972   *         @arg @ref LL_RTC_MONTH_OCTOBER
1973   *         @arg @ref LL_RTC_MONTH_NOVEMBER
1974   *         @arg @ref LL_RTC_MONTH_DECEMBER
1975   */
LL_RTC_TS_GetMonth(RTC_TypeDef * RTCx)1976 __STATIC_INLINE uint32_t LL_RTC_TS_GetMonth(RTC_TypeDef *RTCx)
1977 {
1978   return (uint32_t)(READ_BIT(RTCx->TSDR, RTC_TSDR_MT | RTC_TSDR_MU) >> RTC_TSDR_MU_Pos);
1979 }
1980 
1981 /**
1982   * @brief  Get Timestamp Day in BCD format
1983   * @note helper macro __LL_RTC_CONVERT_BCD2BIN is available to convert Day from BCD to Binary format
1984   * @rmtoll RTC_TSDR         DT            LL_RTC_TS_GetDay\n
1985   *         RTC_TSDR         DU            LL_RTC_TS_GetDay
1986   * @param  RTCx RTC Instance
1987   * @retval Value between Min_Data=0x01 and Max_Data=0x31
1988   */
LL_RTC_TS_GetDay(RTC_TypeDef * RTCx)1989 __STATIC_INLINE uint32_t LL_RTC_TS_GetDay(RTC_TypeDef *RTCx)
1990 {
1991   return (uint32_t)(READ_BIT(RTCx->TSDR, RTC_TSDR_DT | RTC_TSDR_DU));
1992 }
1993 
1994 /**
1995   * @brief  Get Timestamp date (WeekDay, Day and Month) in BCD format
1996   * @note helper macros __LL_RTC_GET_WEEKDAY, __LL_RTC_GET_MONTH,
1997   * and __LL_RTC_GET_DAY are available to get independently each parameter.
1998   * @rmtoll RTC_TSDR         WDU           LL_RTC_TS_GetDate\n
1999   *         RTC_TSDR         MT            LL_RTC_TS_GetDate\n
2000   *         RTC_TSDR         MU            LL_RTC_TS_GetDate\n
2001   *         RTC_TSDR         DT            LL_RTC_TS_GetDate\n
2002   *         RTC_TSDR         DU            LL_RTC_TS_GetDate
2003   * @param  RTCx RTC Instance
2004   * @retval Combination of Weekday, Day and Month
2005   */
LL_RTC_TS_GetDate(RTC_TypeDef * RTCx)2006 __STATIC_INLINE uint32_t LL_RTC_TS_GetDate(RTC_TypeDef *RTCx)
2007 {
2008   return (uint32_t)(READ_BIT(RTCx->TSDR, RTC_TSDR_WDU | RTC_TSDR_MT | RTC_TSDR_MU | RTC_TSDR_DT | RTC_TSDR_DU));
2009 }
2010 
2011 /**
2012   * @brief  Get time-stamp sub second value
2013   * @rmtoll RTC_TSDR         SS            LL_RTC_TS_GetSubSecond
2014   * @param  RTCx RTC Instance
2015   * @retval Value between Min_Data=0x00 and Max_Data=0xFFFF
2016   */
LL_RTC_TS_GetSubSecond(RTC_TypeDef * RTCx)2017 __STATIC_INLINE uint32_t LL_RTC_TS_GetSubSecond(RTC_TypeDef *RTCx)
2018 {
2019   return (uint32_t)(READ_BIT(RTCx->TSSSR, RTC_TSSSR_SS));
2020 }
2021 
2022 /**
2023   * @}
2024   */
2025 
2026 /** @defgroup RTC_LL_EF_Calibration Calibration
2027   * @{
2028   */
2029 
2030 /**
2031   * @brief  Set Calibration output frequency (1 Hz or 512 Hz)
2032   * @note Bits are write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
2033   * @rmtoll RTC_CR           COE           LL_RTC_CAL_SetOutputFreq\n
2034   *         RTC_CR           COSEL         LL_RTC_CAL_SetOutputFreq
2035   * @param  RTCx RTC Instance
2036   * @param  Frequency This parameter can be one of the following values:
2037   *         @arg @ref LL_RTC_CALIB_OUTPUT_NONE
2038   *         @arg @ref LL_RTC_CALIB_OUTPUT_1HZ
2039   *         @arg @ref LL_RTC_CALIB_OUTPUT_512HZ
2040   * @retval None
2041   */
LL_RTC_CAL_SetOutputFreq(RTC_TypeDef * RTCx,uint32_t Frequency)2042 __STATIC_INLINE void LL_RTC_CAL_SetOutputFreq(RTC_TypeDef *RTCx, uint32_t Frequency)
2043 {
2044   MODIFY_REG(RTCx->CR, RTC_CR_COE | RTC_CR_COSEL, Frequency);
2045 }
2046 
2047 /**
2048   * @brief  Get Calibration output frequency (1 Hz or 512 Hz)
2049   * @rmtoll RTC_CR           COE           LL_RTC_CAL_GetOutputFreq\n
2050   *         RTC_CR           COSEL         LL_RTC_CAL_GetOutputFreq
2051   * @param  RTCx RTC Instance
2052   * @retval Returned value can be one of the following values:
2053   *         @arg @ref LL_RTC_CALIB_OUTPUT_NONE
2054   *         @arg @ref LL_RTC_CALIB_OUTPUT_1HZ
2055   *         @arg @ref LL_RTC_CALIB_OUTPUT_512HZ
2056   */
LL_RTC_CAL_GetOutputFreq(RTC_TypeDef * RTCx)2057 __STATIC_INLINE uint32_t LL_RTC_CAL_GetOutputFreq(RTC_TypeDef *RTCx)
2058 {
2059   return (uint32_t)(READ_BIT(RTCx->CR, RTC_CR_COE | RTC_CR_COSEL));
2060 }
2061 
2062 /**
2063   * @brief  Insert or not One RTCCLK pulse every 2exp11 pulses (frequency increased by 488.5 ppm)
2064   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
2065   * @note   Bit can be written only when RECALPF is set to 0
2066   * @rmtoll RTC_CALR         CALP          LL_RTC_CAL_SetPulse
2067   * @param  RTCx RTC Instance
2068   * @param  Pulse This parameter can be one of the following values:
2069   *         @arg @ref LL_RTC_CALIB_INSERTPULSE_NONE
2070   *         @arg @ref LL_RTC_CALIB_INSERTPULSE_SET
2071   * @retval None
2072   */
LL_RTC_CAL_SetPulse(RTC_TypeDef * RTCx,uint32_t Pulse)2073 __STATIC_INLINE void LL_RTC_CAL_SetPulse(RTC_TypeDef *RTCx, uint32_t Pulse)
2074 {
2075   MODIFY_REG(RTCx->CALR, RTC_CALR_CALP, Pulse);
2076 }
2077 
2078 /**
2079   * @brief  Check if one RTCCLK has been inserted or not every 2exp11 pulses (frequency increased by 488.5 ppm)
2080   * @rmtoll RTC_CALR         CALP          LL_RTC_CAL_IsPulseInserted
2081   * @param  RTCx RTC Instance
2082   * @retval State of bit (1 or 0).
2083   */
LL_RTC_CAL_IsPulseInserted(RTC_TypeDef * RTCx)2084 __STATIC_INLINE uint32_t LL_RTC_CAL_IsPulseInserted(RTC_TypeDef *RTCx)
2085 {
2086   return ((READ_BIT(RTCx->CALR, RTC_CALR_CALP) == (RTC_CALR_CALP)) ? 1UL : 0UL);
2087 }
2088 
2089 /**
2090   * @brief  Set the calibration cycle period
2091   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
2092   * @note   Bit can be written only when RECALPF is set to 0
2093   * @rmtoll RTC_CALR         CALW8         LL_RTC_CAL_SetPeriod\n
2094   *         RTC_CALR         CALW16        LL_RTC_CAL_SetPeriod
2095   * @param  RTCx RTC Instance
2096   * @param  Period This parameter can be one of the following values:
2097   *         @arg @ref LL_RTC_CALIB_PERIOD_32SEC
2098   *         @arg @ref LL_RTC_CALIB_PERIOD_16SEC
2099   *         @arg @ref LL_RTC_CALIB_PERIOD_8SEC
2100   * @retval None
2101   */
LL_RTC_CAL_SetPeriod(RTC_TypeDef * RTCx,uint32_t Period)2102 __STATIC_INLINE void LL_RTC_CAL_SetPeriod(RTC_TypeDef *RTCx, uint32_t Period)
2103 {
2104   MODIFY_REG(RTCx->CALR, RTC_CALR_CALW8 | RTC_CALR_CALW16, Period);
2105 }
2106 
2107 /**
2108   * @brief  Get the calibration cycle period
2109   * @rmtoll RTC_CALR         CALW8         LL_RTC_CAL_GetPeriod\n
2110   *         RTC_CALR         CALW16        LL_RTC_CAL_GetPeriod
2111   * @param  RTCx RTC Instance
2112   * @retval Returned value can be one of the following values:
2113   *         @arg @ref LL_RTC_CALIB_PERIOD_32SEC
2114   *         @arg @ref LL_RTC_CALIB_PERIOD_16SEC
2115   *         @arg @ref LL_RTC_CALIB_PERIOD_8SEC
2116   */
LL_RTC_CAL_GetPeriod(RTC_TypeDef * RTCx)2117 __STATIC_INLINE uint32_t LL_RTC_CAL_GetPeriod(RTC_TypeDef *RTCx)
2118 {
2119   return (uint32_t)(READ_BIT(RTCx->CALR, RTC_CALR_CALW8 | RTC_CALR_CALW16));
2120 }
2121 
2122 /**
2123   * @brief  Set Calibration minus
2124   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
2125   * @note   Bit can be written only when RECALPF is set to 0
2126   * @rmtoll RTC_CALR         CALM          LL_RTC_CAL_SetMinus
2127   * @param  RTCx RTC Instance
2128   * @param  CalibMinus Value between Min_Data=0x00 and Max_Data=0x1FF
2129   * @retval None
2130   */
LL_RTC_CAL_SetMinus(RTC_TypeDef * RTCx,uint32_t CalibMinus)2131 __STATIC_INLINE void LL_RTC_CAL_SetMinus(RTC_TypeDef *RTCx, uint32_t CalibMinus)
2132 {
2133   MODIFY_REG(RTCx->CALR, RTC_CALR_CALM, CalibMinus);
2134 }
2135 
2136 /**
2137   * @brief  Get Calibration minus
2138   * @rmtoll RTC_CALR         CALM          LL_RTC_CAL_GetMinus
2139   * @param  RTCx RTC Instance
2140   * @retval Value between Min_Data=0x00 and Max_Data= 0x1FF
2141   */
LL_RTC_CAL_GetMinus(RTC_TypeDef * RTCx)2142 __STATIC_INLINE uint32_t LL_RTC_CAL_GetMinus(RTC_TypeDef *RTCx)
2143 {
2144   return (uint32_t)(READ_BIT(RTCx->CALR, RTC_CALR_CALM));
2145 }
2146 
2147 /**
2148   * @}
2149   */
2150 
2151 /** @defgroup RTC_LL_EF_FLAG_Management FLAG_Management
2152   * @{
2153   */
2154 
2155 /**
2156   * @brief  Get Recalibration pending Flag
2157   * @rmtoll RTC_ICSR          RECALPF       LL_RTC_IsActiveFlag_RECALP
2158   * @param  RTCx RTC Instance
2159   * @retval State of bit (1 or 0).
2160   */
LL_RTC_IsActiveFlag_RECALP(RTC_TypeDef * RTCx)2161 __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_RECALP(RTC_TypeDef *RTCx)
2162 {
2163   return ((READ_BIT(RTCx->ICSR, RTC_ICSR_RECALPF) == (RTC_ICSR_RECALPF)) ? 1UL : 0UL);
2164 }
2165 
2166 /**
2167   * @brief  Get Time-stamp overflow flag
2168   * @rmtoll RTC_SR          TSOVF         LL_RTC_IsActiveFlag_TSOV
2169   * @param  RTCx RTC Instance
2170   * @retval State of bit (1 or 0).
2171   */
LL_RTC_IsActiveFlag_TSOV(RTC_TypeDef * RTCx)2172 __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_TSOV(RTC_TypeDef *RTCx)
2173 {
2174   return ((READ_BIT(RTCx->SR, RTC_SR_TSOVF) == (RTC_SR_TSOVF)) ? 1UL : 0UL);
2175 }
2176 
2177 /**
2178   * @brief  Get Time-stamp flag
2179   * @rmtoll RTC_SR          TSF           LL_RTC_IsActiveFlag_TS
2180   * @param  RTCx RTC Instance
2181   * @retval State of bit (1 or 0).
2182   */
LL_RTC_IsActiveFlag_TS(RTC_TypeDef * RTCx)2183 __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_TS(RTC_TypeDef *RTCx)
2184 {
2185   return ((READ_BIT(RTCx->SR, RTC_SR_TSF) == (RTC_SR_TSF)) ? 1UL : 0UL);
2186 }
2187 
2188 
2189 /**
2190   * @brief  Get Alarm A flag
2191   * @rmtoll RTC_SR          ALRAF         LL_RTC_IsActiveFlag_ALRA
2192   * @param  RTCx RTC Instance
2193   * @retval State of bit (1 or 0).
2194   */
LL_RTC_IsActiveFlag_ALRA(RTC_TypeDef * RTCx)2195 __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_ALRA(RTC_TypeDef *RTCx)
2196 {
2197   return ((READ_BIT(RTCx->SR, RTC_SR_ALRAF) == (RTC_SR_ALRAF)) ? 1UL : 0UL);
2198 }
2199 
2200 /**
2201   * @brief  Clear Time-stamp overflow flag
2202   * @rmtoll RTC_SCR          CTSOVF         LL_RTC_ClearFlag_TSOV
2203   * @param  RTCx RTC Instance
2204   * @retval None
2205   */
LL_RTC_ClearFlag_TSOV(RTC_TypeDef * RTCx)2206 __STATIC_INLINE void LL_RTC_ClearFlag_TSOV(RTC_TypeDef *RTCx)
2207 {
2208   WRITE_REG(RTCx->SCR, RTC_SCR_CTSOVF);
2209 }
2210 
2211 /**
2212   * @brief  Clear Time-stamp flag
2213   * @rmtoll RTC_SCR          CTSF           LL_RTC_ClearFlag_TS
2214   * @param  RTCx RTC Instance
2215   * @retval None
2216   */
LL_RTC_ClearFlag_TS(RTC_TypeDef * RTCx)2217 __STATIC_INLINE void LL_RTC_ClearFlag_TS(RTC_TypeDef *RTCx)
2218 {
2219   WRITE_REG(RTCx->SCR, RTC_SCR_CTSF);
2220 }
2221 
2222 
2223 /**
2224   * @brief  Clear Alarm A flag
2225   * @rmtoll RTC_SCR          CALRAF         LL_RTC_ClearFlag_ALRA
2226   * @param  RTCx RTC Instance
2227   * @retval None
2228   */
LL_RTC_ClearFlag_ALRA(RTC_TypeDef * RTCx)2229 __STATIC_INLINE void LL_RTC_ClearFlag_ALRA(RTC_TypeDef *RTCx)
2230 {
2231   WRITE_REG(RTCx->SCR, RTC_SCR_CALRAF);
2232 }
2233 
2234 /**
2235   * @brief  Get Initialization flag
2236   * @rmtoll RTC_ICSR          INITF         LL_RTC_IsActiveFlag_INIT
2237   * @param  RTCx RTC Instance
2238   * @retval State of bit (1 or 0).
2239   */
LL_RTC_IsActiveFlag_INIT(RTC_TypeDef * RTCx)2240 __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_INIT(RTC_TypeDef *RTCx)
2241 {
2242   return ((READ_BIT(RTCx->ICSR, RTC_ICSR_INITF) == (RTC_ICSR_INITF)) ? 1UL : 0UL);
2243 }
2244 
2245 /**
2246   * @brief  Get Registers synchronization flag
2247   * @rmtoll RTC_ICSR          RSF           LL_RTC_IsActiveFlag_RS
2248   * @param  RTCx RTC Instance
2249   * @retval State of bit (1 or 0).
2250   */
LL_RTC_IsActiveFlag_RS(RTC_TypeDef * RTCx)2251 __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_RS(RTC_TypeDef *RTCx)
2252 {
2253   return ((READ_BIT(RTCx->ICSR, RTC_ICSR_RSF) == (RTC_ICSR_RSF)) ? 1UL : 0UL);
2254 }
2255 
2256 /**
2257   * @brief  Clear Registers synchronization flag
2258   * @rmtoll RTC_ICSR          RSF           LL_RTC_ClearFlag_RS
2259   * @param  RTCx RTC Instance
2260   * @retval None
2261   */
LL_RTC_ClearFlag_RS(RTC_TypeDef * RTCx)2262 __STATIC_INLINE void LL_RTC_ClearFlag_RS(RTC_TypeDef *RTCx)
2263 {
2264   WRITE_REG(RTCx->ICSR, (~((RTC_ICSR_RSF | RTC_ICSR_INIT) & 0x000000FFU) | (RTCx->ICSR & RTC_ICSR_INIT)));
2265 }
2266 
2267 /**
2268   * @brief  Get Initialization status flag
2269   * @rmtoll RTC_ICSR          INITS         LL_RTC_IsActiveFlag_INITS
2270   * @param  RTCx RTC Instance
2271   * @retval State of bit (1 or 0).
2272   */
LL_RTC_IsActiveFlag_INITS(RTC_TypeDef * RTCx)2273 __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_INITS(RTC_TypeDef *RTCx)
2274 {
2275   return ((READ_BIT(RTCx->ICSR, RTC_ICSR_INITS) == (RTC_ICSR_INITS)) ? 1UL : 0UL);
2276 }
2277 
2278 /**
2279   * @brief  Get Shift operation pending flag
2280   * @rmtoll RTC_ICSR          SHPF          LL_RTC_IsActiveFlag_SHP
2281   * @param  RTCx RTC Instance
2282   * @retval State of bit (1 or 0).
2283   */
LL_RTC_IsActiveFlag_SHP(RTC_TypeDef * RTCx)2284 __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_SHP(RTC_TypeDef *RTCx)
2285 {
2286   return ((READ_BIT(RTCx->ICSR, RTC_ICSR_SHPF) == (RTC_ICSR_SHPF)) ? 1UL : 0UL);
2287 }
2288 
2289 
2290 /**
2291   * @brief  Get Alarm A write flag
2292   * @rmtoll RTC_ICSR          ALRAWF        LL_RTC_IsActiveFlag_ALRAW
2293   * @param  RTCx RTC Instance
2294   * @retval State of bit (1 or 0).
2295   */
LL_RTC_IsActiveFlag_ALRAW(RTC_TypeDef * RTCx)2296 __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_ALRAW(RTC_TypeDef *RTCx)
2297 {
2298   return ((READ_BIT(RTCx->ICSR, RTC_ICSR_ALRAWF) == (RTC_ICSR_ALRAWF)) ? 1UL : 0UL);
2299 }
2300 
2301 /**
2302   * @brief  Get Alarm A masked flag.
2303   * @rmtoll RTC_MISR          ALRAMF        LL_RTC_IsActiveFlag_ALRAM
2304   * @param  RTCx RTC Instance
2305   * @retval State of bit (1 or 0).
2306   */
LL_RTC_IsActiveFlag_ALRAM(RTC_TypeDef * RTCx)2307 __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_ALRAM(RTC_TypeDef *RTCx)
2308 {
2309   return ((READ_BIT(RTCx->MISR, RTC_MISR_ALRAMF) == (RTC_MISR_ALRAMF)) ? 1UL : 0UL);
2310 }
2311 
2312 /**
2313   * @brief  Get Time-stamp masked flag.
2314   * @rmtoll RTC_MISR          TSMF        LL_RTC_IsActiveFlag_TSM
2315   * @param  RTCx RTC Instance
2316   * @retval State of bit (1 or 0).
2317   */
LL_RTC_IsActiveFlag_TSM(RTC_TypeDef * RTCx)2318 __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_TSM(RTC_TypeDef *RTCx)
2319 {
2320   return ((READ_BIT(RTCx->MISR, RTC_MISR_TSMF) == (RTC_MISR_TSMF)) ? 1UL : 0UL);
2321 }
2322 
2323 /**
2324   * @brief  Get Time-stamp overflow masked flag.
2325   * @rmtoll RTC_MISR          TSOVMF        LL_RTC_IsActiveFlag_TSOVM
2326   * @param  RTCx RTC Instance
2327   * @retval State of bit (1 or 0).
2328   */
LL_RTC_IsActiveFlag_TSOVM(RTC_TypeDef * RTCx)2329 __STATIC_INLINE uint32_t LL_RTC_IsActiveFlag_TSOVM(RTC_TypeDef *RTCx)
2330 {
2331   return ((READ_BIT(RTCx->MISR, RTC_MISR_TSOVMF) == (RTC_MISR_TSOVMF)) ? 1UL : 0UL);
2332 }
2333 
2334 /**
2335   * @}
2336   */
2337 
2338 /** @defgroup RTC_LL_EF_IT_Management IT_Management
2339   * @{
2340   */
2341 
2342 /**
2343   * @brief  Enable Time-stamp interrupt
2344   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
2345   * @rmtoll RTC_CR          TSIE         LL_RTC_EnableIT_TS
2346   * @param  RTCx RTC Instance
2347   * @retval None
2348   */
LL_RTC_EnableIT_TS(RTC_TypeDef * RTCx)2349 __STATIC_INLINE void LL_RTC_EnableIT_TS(RTC_TypeDef *RTCx)
2350 {
2351   SET_BIT(RTCx->CR, RTC_CR_TSIE);
2352 }
2353 
2354 /**
2355   * @brief  Disable Time-stamp interrupt
2356   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
2357   * @rmtoll RTC_CR          TSIE         LL_RTC_DisableIT_TS
2358   * @param  RTCx RTC Instance
2359   * @retval None
2360   */
LL_RTC_DisableIT_TS(RTC_TypeDef * RTCx)2361 __STATIC_INLINE void LL_RTC_DisableIT_TS(RTC_TypeDef *RTCx)
2362 {
2363   CLEAR_BIT(RTCx->CR, RTC_CR_TSIE);
2364 }
2365 
2366 /**
2367   * @brief  Enable Alarm A interrupt
2368   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
2369   * @rmtoll RTC_CR           ALRAIE        LL_RTC_EnableIT_ALRA
2370   * @param  RTCx RTC Instance
2371   * @retval None
2372   */
LL_RTC_EnableIT_ALRA(RTC_TypeDef * RTCx)2373 __STATIC_INLINE void LL_RTC_EnableIT_ALRA(RTC_TypeDef *RTCx)
2374 {
2375   SET_BIT(RTCx->CR, RTC_CR_ALRAIE);
2376 }
2377 
2378 /**
2379   * @brief  Disable Alarm A interrupt
2380   * @note   Bit is write-protected. @ref LL_RTC_DisableWriteProtection function should be called before.
2381   * @rmtoll RTC_CR           ALRAIE        LL_RTC_DisableIT_ALRA
2382   * @param  RTCx RTC Instance
2383   * @retval None
2384   */
LL_RTC_DisableIT_ALRA(RTC_TypeDef * RTCx)2385 __STATIC_INLINE void LL_RTC_DisableIT_ALRA(RTC_TypeDef *RTCx)
2386 {
2387   CLEAR_BIT(RTCx->CR, RTC_CR_ALRAIE);
2388 }
2389 
2390 /**
2391   * @brief  Check if Time-stamp interrupt is enabled or not
2392   * @rmtoll RTC_CR           TSIE          LL_RTC_IsEnabledIT_TS
2393   * @param  RTCx RTC Instance
2394   * @retval State of bit (1 or 0).
2395   */
LL_RTC_IsEnabledIT_TS(RTC_TypeDef * RTCx)2396 __STATIC_INLINE uint32_t LL_RTC_IsEnabledIT_TS(RTC_TypeDef *RTCx)
2397 {
2398   return ((READ_BIT(RTCx->CR, RTC_CR_TSIE) == (RTC_CR_TSIE)) ? 1UL : 0UL);
2399 }
2400 
2401 /**
2402   * @brief  Check if Alarm A interrupt is enabled or not
2403   * @rmtoll RTC_CR           ALRAIE        LL_RTC_IsEnabledIT_ALRA
2404   * @param  RTCx RTC Instance
2405   * @retval State of bit (1 or 0).
2406   */
LL_RTC_IsEnabledIT_ALRA(RTC_TypeDef * RTCx)2407 __STATIC_INLINE uint32_t LL_RTC_IsEnabledIT_ALRA(RTC_TypeDef *RTCx)
2408 {
2409   return ((READ_BIT(RTCx->CR, RTC_CR_ALRAIE) == (RTC_CR_ALRAIE)) ? 1UL : 0UL);
2410 }
2411 
2412 /**
2413   * @}
2414   */
2415 
2416 #if defined(USE_FULL_LL_DRIVER)
2417 /** @defgroup RTC_LL_EF_Init Initialization and de-initialization functions
2418   * @{
2419   */
2420 
2421 ErrorStatus LL_RTC_DeInit(RTC_TypeDef *RTCx);
2422 ErrorStatus LL_RTC_Init(RTC_TypeDef *RTCx, LL_RTC_InitTypeDef *RTC_InitStruct);
2423 void        LL_RTC_StructInit(LL_RTC_InitTypeDef *RTC_InitStruct);
2424 ErrorStatus LL_RTC_TIME_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_TimeTypeDef *RTC_TimeStruct);
2425 void        LL_RTC_TIME_StructInit(LL_RTC_TimeTypeDef *RTC_TimeStruct);
2426 ErrorStatus LL_RTC_DATE_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_DateTypeDef *RTC_DateStruct);
2427 void        LL_RTC_DATE_StructInit(LL_RTC_DateTypeDef *RTC_DateStruct);
2428 ErrorStatus LL_RTC_ALMA_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_AlarmTypeDef *RTC_AlarmStruct);
2429 void        LL_RTC_ALMA_StructInit(LL_RTC_AlarmTypeDef *RTC_AlarmStruct);
2430 ErrorStatus LL_RTC_EnterInitMode(RTC_TypeDef *RTCx);
2431 ErrorStatus LL_RTC_ExitInitMode(RTC_TypeDef *RTCx);
2432 ErrorStatus LL_RTC_WaitForSynchro(RTC_TypeDef *RTCx);
2433 
2434 /**
2435   * @}
2436   */
2437 #endif /* USE_FULL_LL_DRIVER */
2438 
2439 /**
2440   * @}
2441   */
2442 
2443 /**
2444   * @}
2445   */
2446 
2447 #endif /* defined(RTC) */
2448 
2449 /**
2450   * @}
2451   */
2452 
2453 #ifdef __cplusplus
2454 }
2455 #endif
2456 
2457 #endif /* STM32C0xx_LL_RTC_H */
2458