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