comparison Common/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_rtc.c @ 128:c78bcbd5deda FlipDisplay

Added current STM32 standandard libraries in version independend folder structure
author Ideenmodellierer
date Sun, 17 Feb 2019 21:12:22 +0100
parents
children
comparison
equal deleted inserted replaced
127:1369f8660eaa 128:c78bcbd5deda
1 /**
2 ******************************************************************************
3 * @file stm32f4xx_ll_rtc.c
4 * @author MCD Application Team
5 * @brief RTC LL module driver.
6 ******************************************************************************
7 * @attention
8 *
9 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
10 *
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. Neither the name of STMicroelectronics nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 ******************************************************************************
34 */
35 #if defined(USE_FULL_LL_DRIVER)
36
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f4xx_ll_rtc.h"
39 #include "stm32f4xx_ll_cortex.h"
40 #ifdef USE_FULL_ASSERT
41 #include "stm32_assert.h"
42 #else
43 #define assert_param(expr) ((void)0U)
44 #endif
45
46 /** @addtogroup STM32F4xx_LL_Driver
47 * @{
48 */
49
50 #if defined(RTC)
51
52 /** @addtogroup RTC_LL
53 * @{
54 */
55
56 /* Private types -------------------------------------------------------------*/
57 /* Private variables ---------------------------------------------------------*/
58 /* Private constants ---------------------------------------------------------*/
59 /** @addtogroup RTC_LL_Private_Constants
60 * @{
61 */
62 /* Default values used for prescaler */
63 #define RTC_ASYNCH_PRESC_DEFAULT 0x0000007FU
64 #define RTC_SYNCH_PRESC_DEFAULT 0x000000FFU
65
66 /* Values used for timeout */
67 #define RTC_INITMODE_TIMEOUT 1000U /* 1s when tick set to 1ms */
68 #define RTC_SYNCHRO_TIMEOUT 1000U /* 1s when tick set to 1ms */
69 /**
70 * @}
71 */
72
73 /* Private macros ------------------------------------------------------------*/
74 /** @addtogroup RTC_LL_Private_Macros
75 * @{
76 */
77
78 #define IS_LL_RTC_HOURFORMAT(__VALUE__) (((__VALUE__) == LL_RTC_HOURFORMAT_24HOUR) \
79 || ((__VALUE__) == LL_RTC_HOURFORMAT_AMPM))
80
81 #define IS_LL_RTC_ASYNCH_PREDIV(__VALUE__) ((__VALUE__) <= 0x7FU)
82
83 #define IS_LL_RTC_SYNCH_PREDIV(__VALUE__) ((__VALUE__) <= 0x7FFFU)
84
85 #define IS_LL_RTC_FORMAT(__VALUE__) (((__VALUE__) == LL_RTC_FORMAT_BIN) \
86 || ((__VALUE__) == LL_RTC_FORMAT_BCD))
87
88 #define IS_LL_RTC_TIME_FORMAT(__VALUE__) (((__VALUE__) == LL_RTC_TIME_FORMAT_AM_OR_24) \
89 || ((__VALUE__) == LL_RTC_TIME_FORMAT_PM))
90
91 #define IS_LL_RTC_HOUR12(__HOUR__) (((__HOUR__) > 0U) && ((__HOUR__) <= 12U))
92 #define IS_LL_RTC_HOUR24(__HOUR__) ((__HOUR__) <= 23U)
93 #define IS_LL_RTC_MINUTES(__MINUTES__) ((__MINUTES__) <= 59U)
94 #define IS_LL_RTC_SECONDS(__SECONDS__) ((__SECONDS__) <= 59U)
95
96 #define IS_LL_RTC_WEEKDAY(__VALUE__) (((__VALUE__) == LL_RTC_WEEKDAY_MONDAY) \
97 || ((__VALUE__) == LL_RTC_WEEKDAY_TUESDAY) \
98 || ((__VALUE__) == LL_RTC_WEEKDAY_WEDNESDAY) \
99 || ((__VALUE__) == LL_RTC_WEEKDAY_THURSDAY) \
100 || ((__VALUE__) == LL_RTC_WEEKDAY_FRIDAY) \
101 || ((__VALUE__) == LL_RTC_WEEKDAY_SATURDAY) \
102 || ((__VALUE__) == LL_RTC_WEEKDAY_SUNDAY))
103
104 #define IS_LL_RTC_DAY(__DAY__) (((__DAY__) >= 1U) && ((__DAY__) <= 31U))
105
106 #define IS_LL_RTC_MONTH(__VALUE__) (((__VALUE__) == LL_RTC_MONTH_JANUARY) \
107 || ((__VALUE__) == LL_RTC_MONTH_FEBRUARY) \
108 || ((__VALUE__) == LL_RTC_MONTH_MARCH) \
109 || ((__VALUE__) == LL_RTC_MONTH_APRIL) \
110 || ((__VALUE__) == LL_RTC_MONTH_MAY) \
111 || ((__VALUE__) == LL_RTC_MONTH_JUNE) \
112 || ((__VALUE__) == LL_RTC_MONTH_JULY) \
113 || ((__VALUE__) == LL_RTC_MONTH_AUGUST) \
114 || ((__VALUE__) == LL_RTC_MONTH_SEPTEMBER) \
115 || ((__VALUE__) == LL_RTC_MONTH_OCTOBER) \
116 || ((__VALUE__) == LL_RTC_MONTH_NOVEMBER) \
117 || ((__VALUE__) == LL_RTC_MONTH_DECEMBER))
118
119 #define IS_LL_RTC_YEAR(__YEAR__) ((__YEAR__) <= 99U)
120
121 #define IS_LL_RTC_ALMA_MASK(__VALUE__) (((__VALUE__) == LL_RTC_ALMA_MASK_NONE) \
122 || ((__VALUE__) == LL_RTC_ALMA_MASK_DATEWEEKDAY) \
123 || ((__VALUE__) == LL_RTC_ALMA_MASK_HOURS) \
124 || ((__VALUE__) == LL_RTC_ALMA_MASK_MINUTES) \
125 || ((__VALUE__) == LL_RTC_ALMA_MASK_SECONDS) \
126 || ((__VALUE__) == LL_RTC_ALMA_MASK_ALL))
127
128 #define IS_LL_RTC_ALMB_MASK(__VALUE__) (((__VALUE__) == LL_RTC_ALMB_MASK_NONE) \
129 || ((__VALUE__) == LL_RTC_ALMB_MASK_DATEWEEKDAY) \
130 || ((__VALUE__) == LL_RTC_ALMB_MASK_HOURS) \
131 || ((__VALUE__) == LL_RTC_ALMB_MASK_MINUTES) \
132 || ((__VALUE__) == LL_RTC_ALMB_MASK_SECONDS) \
133 || ((__VALUE__) == LL_RTC_ALMB_MASK_ALL))
134
135
136 #define IS_LL_RTC_ALMA_DATE_WEEKDAY_SEL(__SEL__) (((__SEL__) == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE) || \
137 ((__SEL__) == LL_RTC_ALMA_DATEWEEKDAYSEL_WEEKDAY))
138
139 #define IS_LL_RTC_ALMB_DATE_WEEKDAY_SEL(__SEL__) (((__SEL__) == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE) || \
140 ((__SEL__) == LL_RTC_ALMB_DATEWEEKDAYSEL_WEEKDAY))
141
142
143 /**
144 * @}
145 */
146 /* Private function prototypes -----------------------------------------------*/
147 /* Exported functions --------------------------------------------------------*/
148 /** @addtogroup RTC_LL_Exported_Functions
149 * @{
150 */
151
152 /** @addtogroup RTC_LL_EF_Init
153 * @{
154 */
155
156 /**
157 * @brief De-Initializes the RTC registers to their default reset values.
158 * @note This function doesn't reset the RTC Clock source and RTC Backup Data
159 * registers.
160 * @param RTCx RTC Instance
161 * @retval An ErrorStatus enumeration value:
162 * - SUCCESS: RTC registers are de-initialized
163 * - ERROR: RTC registers are not de-initialized
164 */
165 ErrorStatus LL_RTC_DeInit(RTC_TypeDef *RTCx)
166 {
167 ErrorStatus status = ERROR;
168
169 /* Check the parameter */
170 assert_param(IS_RTC_ALL_INSTANCE(RTCx));
171
172 /* Disable the write protection for RTC registers */
173 LL_RTC_DisableWriteProtection(RTCx);
174
175 /* Set Initialization mode */
176 if (LL_RTC_EnterInitMode(RTCx) != ERROR)
177 {
178 /* Reset TR, DR and CR registers */
179 LL_RTC_WriteReg(RTCx, TR, 0x00000000U);
180 #if defined(RTC_WAKEUP_SUPPORT)
181 LL_RTC_WriteReg(RTCx, WUTR, RTC_WUTR_WUT);
182 #endif /* RTC_WAKEUP_SUPPORT */
183 LL_RTC_WriteReg(RTCx, DR , (RTC_DR_WDU_0 | RTC_DR_MU_0 | RTC_DR_DU_0));
184 /* Reset All CR bits except CR[2:0] */
185 #if defined(RTC_WAKEUP_SUPPORT)
186 LL_RTC_WriteReg(RTCx, CR, (LL_RTC_ReadReg(RTCx, CR) & RTC_CR_WUCKSEL));
187 #else
188 LL_RTC_WriteReg(RTCx, CR, 0x00000000U);
189 #endif /* RTC_WAKEUP_SUPPORT */
190 LL_RTC_WriteReg(RTCx, PRER, (RTC_PRER_PREDIV_A | RTC_SYNCH_PRESC_DEFAULT));
191 LL_RTC_WriteReg(RTCx, ALRMAR, 0x00000000U);
192 LL_RTC_WriteReg(RTCx, ALRMBR, 0x00000000U);
193 LL_RTC_WriteReg(RTCx, SHIFTR, 0x00000000U);
194 LL_RTC_WriteReg(RTCx, CALR, 0x00000000U);
195 LL_RTC_WriteReg(RTCx, ALRMASSR, 0x00000000U);
196 LL_RTC_WriteReg(RTCx, ALRMBSSR, 0x00000000U);
197
198 /* Reset ISR register and exit initialization mode */
199 LL_RTC_WriteReg(RTCx, ISR, 0x00000000U);
200
201 /* Reset Tamper and alternate functions configuration register */
202 LL_RTC_WriteReg(RTCx, TAFCR, 0x00000000U);
203
204 /* Wait till the RTC RSF flag is set */
205 status = LL_RTC_WaitForSynchro(RTCx);
206 }
207
208 /* Enable the write protection for RTC registers */
209 LL_RTC_EnableWriteProtection(RTCx);
210
211 return status;
212 }
213
214 /**
215 * @brief Initializes the RTC registers according to the specified parameters
216 * in RTC_InitStruct.
217 * @param RTCx RTC Instance
218 * @param RTC_InitStruct pointer to a @ref LL_RTC_InitTypeDef structure that contains
219 * the configuration information for the RTC peripheral.
220 * @note The RTC Prescaler register is write protected and can be written in
221 * initialization mode only.
222 * @retval An ErrorStatus enumeration value:
223 * - SUCCESS: RTC registers are initialized
224 * - ERROR: RTC registers are not initialized
225 */
226 ErrorStatus LL_RTC_Init(RTC_TypeDef *RTCx, LL_RTC_InitTypeDef *RTC_InitStruct)
227 {
228 ErrorStatus status = ERROR;
229
230 /* Check the parameters */
231 assert_param(IS_RTC_ALL_INSTANCE(RTCx));
232 assert_param(IS_LL_RTC_HOURFORMAT(RTC_InitStruct->HourFormat));
233 assert_param(IS_LL_RTC_ASYNCH_PREDIV(RTC_InitStruct->AsynchPrescaler));
234 assert_param(IS_LL_RTC_SYNCH_PREDIV(RTC_InitStruct->SynchPrescaler));
235
236 /* Disable the write protection for RTC registers */
237 LL_RTC_DisableWriteProtection(RTCx);
238
239 /* Set Initialization mode */
240 if (LL_RTC_EnterInitMode(RTCx) != ERROR)
241 {
242 /* Set Hour Format */
243 LL_RTC_SetHourFormat(RTCx, RTC_InitStruct->HourFormat);
244
245 /* Configure Synchronous and Asynchronous prescaler factor */
246 LL_RTC_SetSynchPrescaler(RTCx, RTC_InitStruct->SynchPrescaler);
247 LL_RTC_SetAsynchPrescaler(RTCx, RTC_InitStruct->AsynchPrescaler);
248
249 /* Exit Initialization mode */
250 LL_RTC_DisableInitMode(RTCx);
251
252 status = SUCCESS;
253 }
254 /* Enable the write protection for RTC registers */
255 LL_RTC_EnableWriteProtection(RTCx);
256
257 return status;
258 }
259
260 /**
261 * @brief Set each @ref LL_RTC_InitTypeDef field to default value.
262 * @param RTC_InitStruct pointer to a @ref LL_RTC_InitTypeDef structure which will be initialized.
263 * @retval None
264 */
265 void LL_RTC_StructInit(LL_RTC_InitTypeDef *RTC_InitStruct)
266 {
267 /* Set RTC_InitStruct fields to default values */
268 RTC_InitStruct->HourFormat = LL_RTC_HOURFORMAT_24HOUR;
269 RTC_InitStruct->AsynchPrescaler = RTC_ASYNCH_PRESC_DEFAULT;
270 RTC_InitStruct->SynchPrescaler = RTC_SYNCH_PRESC_DEFAULT;
271 }
272
273 /**
274 * @brief Set the RTC current time.
275 * @param RTCx RTC Instance
276 * @param RTC_Format This parameter can be one of the following values:
277 * @arg @ref LL_RTC_FORMAT_BIN
278 * @arg @ref LL_RTC_FORMAT_BCD
279 * @param RTC_TimeStruct pointer to a RTC_TimeTypeDef structure that contains
280 * the time configuration information for the RTC.
281 * @retval An ErrorStatus enumeration value:
282 * - SUCCESS: RTC Time register is configured
283 * - ERROR: RTC Time register is not configured
284 */
285 ErrorStatus LL_RTC_TIME_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_TimeTypeDef *RTC_TimeStruct)
286 {
287 ErrorStatus status = ERROR;
288
289 /* Check the parameters */
290 assert_param(IS_RTC_ALL_INSTANCE(RTCx));
291 assert_param(IS_LL_RTC_FORMAT(RTC_Format));
292
293 if (RTC_Format == LL_RTC_FORMAT_BIN)
294 {
295 if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR)
296 {
297 assert_param(IS_LL_RTC_HOUR12(RTC_TimeStruct->Hours));
298 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_TimeStruct->TimeFormat));
299 }
300 else
301 {
302 RTC_TimeStruct->TimeFormat = 0x00U;
303 assert_param(IS_LL_RTC_HOUR24(RTC_TimeStruct->Hours));
304 }
305 assert_param(IS_LL_RTC_MINUTES(RTC_TimeStruct->Minutes));
306 assert_param(IS_LL_RTC_SECONDS(RTC_TimeStruct->Seconds));
307 }
308 else
309 {
310 if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR)
311 {
312 assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Hours)));
313 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_TimeStruct->TimeFormat));
314 }
315 else
316 {
317 RTC_TimeStruct->TimeFormat = 0x00U;
318 assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Hours)));
319 }
320 assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Minutes)));
321 assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Seconds)));
322 }
323
324 /* Disable the write protection for RTC registers */
325 LL_RTC_DisableWriteProtection(RTCx);
326
327 /* Set Initialization mode */
328 if (LL_RTC_EnterInitMode(RTCx) != ERROR)
329 {
330 /* Check the input parameters format */
331 if (RTC_Format != LL_RTC_FORMAT_BIN)
332 {
333 LL_RTC_TIME_Config(RTCx, RTC_TimeStruct->TimeFormat, RTC_TimeStruct->Hours,
334 RTC_TimeStruct->Minutes, RTC_TimeStruct->Seconds);
335 }
336 else
337 {
338 LL_RTC_TIME_Config(RTCx, RTC_TimeStruct->TimeFormat, __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct->Hours),
339 __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct->Minutes),
340 __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct->Seconds));
341 }
342
343 /* Exit Initialization mode */
344 LL_RTC_DisableInitMode(RTC);
345
346 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
347 if (LL_RTC_IsShadowRegBypassEnabled(RTCx) == 0U)
348 {
349 status = LL_RTC_WaitForSynchro(RTCx);
350 }
351 else
352 {
353 status = SUCCESS;
354 }
355 }
356 /* Enable the write protection for RTC registers */
357 LL_RTC_EnableWriteProtection(RTCx);
358
359 return status;
360 }
361
362 /**
363 * @brief Set each @ref LL_RTC_TimeTypeDef field to default value (Time = 00h:00min:00sec).
364 * @param RTC_TimeStruct pointer to a @ref LL_RTC_TimeTypeDef structure which will be initialized.
365 * @retval None
366 */
367 void LL_RTC_TIME_StructInit(LL_RTC_TimeTypeDef *RTC_TimeStruct)
368 {
369 /* Time = 00h:00min:00sec */
370 RTC_TimeStruct->TimeFormat = LL_RTC_TIME_FORMAT_AM_OR_24;
371 RTC_TimeStruct->Hours = 0U;
372 RTC_TimeStruct->Minutes = 0U;
373 RTC_TimeStruct->Seconds = 0U;
374 }
375
376 /**
377 * @brief Set the RTC current date.
378 * @param RTCx RTC Instance
379 * @param RTC_Format This parameter can be one of the following values:
380 * @arg @ref LL_RTC_FORMAT_BIN
381 * @arg @ref LL_RTC_FORMAT_BCD
382 * @param RTC_DateStruct pointer to a RTC_DateTypeDef structure that contains
383 * the date configuration information for the RTC.
384 * @retval An ErrorStatus enumeration value:
385 * - SUCCESS: RTC Day register is configured
386 * - ERROR: RTC Day register is not configured
387 */
388 ErrorStatus LL_RTC_DATE_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_DateTypeDef *RTC_DateStruct)
389 {
390 ErrorStatus status = ERROR;
391
392 /* Check the parameters */
393 assert_param(IS_RTC_ALL_INSTANCE(RTCx));
394 assert_param(IS_LL_RTC_FORMAT(RTC_Format));
395
396 if ((RTC_Format == LL_RTC_FORMAT_BIN) && ((RTC_DateStruct->Month & 0x10U) == 0x10U))
397 {
398 RTC_DateStruct->Month = (RTC_DateStruct->Month & (uint32_t)~(0x10U)) + 0x0AU;
399 }
400 if (RTC_Format == LL_RTC_FORMAT_BIN)
401 {
402 assert_param(IS_LL_RTC_YEAR(RTC_DateStruct->Year));
403 assert_param(IS_LL_RTC_MONTH(RTC_DateStruct->Month));
404 assert_param(IS_LL_RTC_DAY(RTC_DateStruct->Day));
405 }
406 else
407 {
408 assert_param(IS_LL_RTC_YEAR(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct->Year)));
409 assert_param(IS_LL_RTC_MONTH(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct->Month)));
410 assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct->Day)));
411 }
412 assert_param(IS_LL_RTC_WEEKDAY(RTC_DateStruct->WeekDay));
413
414 /* Disable the write protection for RTC registers */
415 LL_RTC_DisableWriteProtection(RTCx);
416
417 /* Set Initialization mode */
418 if (LL_RTC_EnterInitMode(RTCx) != ERROR)
419 {
420 /* Check the input parameters format */
421 if (RTC_Format != LL_RTC_FORMAT_BIN)
422 {
423 LL_RTC_DATE_Config(RTCx, RTC_DateStruct->WeekDay, RTC_DateStruct->Day, RTC_DateStruct->Month, RTC_DateStruct->Year);
424 }
425 else
426 {
427 LL_RTC_DATE_Config(RTCx, RTC_DateStruct->WeekDay, __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct->Day),
428 __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct->Month), __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct->Year));
429 }
430
431 /* Exit Initialization mode */
432 LL_RTC_DisableInitMode(RTC);
433
434 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
435 if (LL_RTC_IsShadowRegBypassEnabled(RTCx) == 0U)
436 {
437 status = LL_RTC_WaitForSynchro(RTCx);
438 }
439 else
440 {
441 status = SUCCESS;
442 }
443 }
444 /* Enable the write protection for RTC registers */
445 LL_RTC_EnableWriteProtection(RTCx);
446
447 return status;
448 }
449
450 /**
451 * @brief Set each @ref LL_RTC_DateTypeDef field to default value (date = Monday, January 01 xx00)
452 * @param RTC_DateStruct pointer to a @ref LL_RTC_DateTypeDef structure which will be initialized.
453 * @retval None
454 */
455 void LL_RTC_DATE_StructInit(LL_RTC_DateTypeDef *RTC_DateStruct)
456 {
457 /* Monday, January 01 xx00 */
458 RTC_DateStruct->WeekDay = LL_RTC_WEEKDAY_MONDAY;
459 RTC_DateStruct->Day = 1U;
460 RTC_DateStruct->Month = LL_RTC_MONTH_JANUARY;
461 RTC_DateStruct->Year = 0U;
462 }
463
464 /**
465 * @brief Set the RTC Alarm A.
466 * @note The Alarm register can only be written when the corresponding Alarm
467 * is disabled (Use @ref LL_RTC_ALMA_Disable function).
468 * @param RTCx RTC Instance
469 * @param RTC_Format This parameter can be one of the following values:
470 * @arg @ref LL_RTC_FORMAT_BIN
471 * @arg @ref LL_RTC_FORMAT_BCD
472 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure that
473 * contains the alarm configuration parameters.
474 * @retval An ErrorStatus enumeration value:
475 * - SUCCESS: ALARMA registers are configured
476 * - ERROR: ALARMA registers are not configured
477 */
478 ErrorStatus LL_RTC_ALMA_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_AlarmTypeDef *RTC_AlarmStruct)
479 {
480 /* Check the parameters */
481 assert_param(IS_RTC_ALL_INSTANCE(RTCx));
482 assert_param(IS_LL_RTC_FORMAT(RTC_Format));
483 assert_param(IS_LL_RTC_ALMA_MASK(RTC_AlarmStruct->AlarmMask));
484 assert_param(IS_LL_RTC_ALMA_DATE_WEEKDAY_SEL(RTC_AlarmStruct->AlarmDateWeekDaySel));
485
486 if (RTC_Format == LL_RTC_FORMAT_BIN)
487 {
488 if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR)
489 {
490 assert_param(IS_LL_RTC_HOUR12(RTC_AlarmStruct->AlarmTime.Hours));
491 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct->AlarmTime.TimeFormat));
492 }
493 else
494 {
495 RTC_AlarmStruct->AlarmTime.TimeFormat = 0x00U;
496 assert_param(IS_LL_RTC_HOUR24(RTC_AlarmStruct->AlarmTime.Hours));
497 }
498 assert_param(IS_LL_RTC_MINUTES(RTC_AlarmStruct->AlarmTime.Minutes));
499 assert_param(IS_LL_RTC_SECONDS(RTC_AlarmStruct->AlarmTime.Seconds));
500
501 if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE)
502 {
503 assert_param(IS_LL_RTC_DAY(RTC_AlarmStruct->AlarmDateWeekDay));
504 }
505 else
506 {
507 assert_param(IS_LL_RTC_WEEKDAY(RTC_AlarmStruct->AlarmDateWeekDay));
508 }
509 }
510 else
511 {
512 if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR)
513 {
514 assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours)));
515 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct->AlarmTime.TimeFormat));
516 }
517 else
518 {
519 RTC_AlarmStruct->AlarmTime.TimeFormat = 0x00U;
520 assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours)));
521 }
522
523 assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Minutes)));
524 assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Seconds)));
525
526 if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE)
527 {
528 assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmDateWeekDay)));
529 }
530 else
531 {
532 assert_param(IS_LL_RTC_WEEKDAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmDateWeekDay)));
533 }
534 }
535
536 /* Disable the write protection for RTC registers */
537 LL_RTC_DisableWriteProtection(RTCx);
538
539 /* Select weekday selection */
540 if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE)
541 {
542 /* Set the date for ALARM */
543 LL_RTC_ALMA_DisableWeekday(RTCx);
544 if (RTC_Format != LL_RTC_FORMAT_BIN)
545 {
546 LL_RTC_ALMA_SetDay(RTCx, RTC_AlarmStruct->AlarmDateWeekDay);
547 }
548 else
549 {
550 LL_RTC_ALMA_SetDay(RTCx, __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmDateWeekDay));
551 }
552 }
553 else
554 {
555 /* Set the week day for ALARM */
556 LL_RTC_ALMA_EnableWeekday(RTCx);
557 LL_RTC_ALMA_SetWeekDay(RTCx, RTC_AlarmStruct->AlarmDateWeekDay);
558 }
559
560 /* Configure the Alarm register */
561 if (RTC_Format != LL_RTC_FORMAT_BIN)
562 {
563 LL_RTC_ALMA_ConfigTime(RTCx, RTC_AlarmStruct->AlarmTime.TimeFormat, RTC_AlarmStruct->AlarmTime.Hours,
564 RTC_AlarmStruct->AlarmTime.Minutes, RTC_AlarmStruct->AlarmTime.Seconds);
565 }
566 else
567 {
568 LL_RTC_ALMA_ConfigTime(RTCx, RTC_AlarmStruct->AlarmTime.TimeFormat,
569 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Hours),
570 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Minutes),
571 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Seconds));
572 }
573 /* Set ALARM mask */
574 LL_RTC_ALMA_SetMask(RTCx, RTC_AlarmStruct->AlarmMask);
575
576 /* Enable the write protection for RTC registers */
577 LL_RTC_EnableWriteProtection(RTCx);
578
579 return SUCCESS;
580 }
581
582 /**
583 * @brief Set the RTC Alarm B.
584 * @note The Alarm register can only be written when the corresponding Alarm
585 * is disabled (@ref LL_RTC_ALMB_Disable function).
586 * @param RTCx RTC Instance
587 * @param RTC_Format This parameter can be one of the following values:
588 * @arg @ref LL_RTC_FORMAT_BIN
589 * @arg @ref LL_RTC_FORMAT_BCD
590 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure that
591 * contains the alarm configuration parameters.
592 * @retval An ErrorStatus enumeration value:
593 * - SUCCESS: ALARMB registers are configured
594 * - ERROR: ALARMB registers are not configured
595 */
596 ErrorStatus LL_RTC_ALMB_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_AlarmTypeDef *RTC_AlarmStruct)
597 {
598 /* Check the parameters */
599 assert_param(IS_RTC_ALL_INSTANCE(RTCx));
600 assert_param(IS_LL_RTC_FORMAT(RTC_Format));
601 assert_param(IS_LL_RTC_ALMB_MASK(RTC_AlarmStruct->AlarmMask));
602 assert_param(IS_LL_RTC_ALMB_DATE_WEEKDAY_SEL(RTC_AlarmStruct->AlarmDateWeekDaySel));
603
604 if (RTC_Format == LL_RTC_FORMAT_BIN)
605 {
606 if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR)
607 {
608 assert_param(IS_LL_RTC_HOUR12(RTC_AlarmStruct->AlarmTime.Hours));
609 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct->AlarmTime.TimeFormat));
610 }
611 else
612 {
613 RTC_AlarmStruct->AlarmTime.TimeFormat = 0x00U;
614 assert_param(IS_LL_RTC_HOUR24(RTC_AlarmStruct->AlarmTime.Hours));
615 }
616 assert_param(IS_LL_RTC_MINUTES(RTC_AlarmStruct->AlarmTime.Minutes));
617 assert_param(IS_LL_RTC_SECONDS(RTC_AlarmStruct->AlarmTime.Seconds));
618
619 if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE)
620 {
621 assert_param(IS_LL_RTC_DAY(RTC_AlarmStruct->AlarmDateWeekDay));
622 }
623 else
624 {
625 assert_param(IS_LL_RTC_WEEKDAY(RTC_AlarmStruct->AlarmDateWeekDay));
626 }
627 }
628 else
629 {
630 if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR)
631 {
632 assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours)));
633 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct->AlarmTime.TimeFormat));
634 }
635 else
636 {
637 RTC_AlarmStruct->AlarmTime.TimeFormat = 0x00U;
638 assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours)));
639 }
640
641 assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Minutes)));
642 assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Seconds)));
643
644 if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE)
645 {
646 assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmDateWeekDay)));
647 }
648 else
649 {
650 assert_param(IS_LL_RTC_WEEKDAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmDateWeekDay)));
651 }
652 }
653
654 /* Disable the write protection for RTC registers */
655 LL_RTC_DisableWriteProtection(RTCx);
656
657 /* Select weekday selection */
658 if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE)
659 {
660 /* Set the date for ALARM */
661 LL_RTC_ALMB_DisableWeekday(RTCx);
662 if (RTC_Format != LL_RTC_FORMAT_BIN)
663 {
664 LL_RTC_ALMB_SetDay(RTCx, RTC_AlarmStruct->AlarmDateWeekDay);
665 }
666 else
667 {
668 LL_RTC_ALMB_SetDay(RTCx, __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmDateWeekDay));
669 }
670 }
671 else
672 {
673 /* Set the week day for ALARM */
674 LL_RTC_ALMB_EnableWeekday(RTCx);
675 LL_RTC_ALMB_SetWeekDay(RTCx, RTC_AlarmStruct->AlarmDateWeekDay);
676 }
677
678 /* Configure the Alarm register */
679 if (RTC_Format != LL_RTC_FORMAT_BIN)
680 {
681 LL_RTC_ALMB_ConfigTime(RTCx, RTC_AlarmStruct->AlarmTime.TimeFormat, RTC_AlarmStruct->AlarmTime.Hours,
682 RTC_AlarmStruct->AlarmTime.Minutes, RTC_AlarmStruct->AlarmTime.Seconds);
683 }
684 else
685 {
686 LL_RTC_ALMB_ConfigTime(RTCx, RTC_AlarmStruct->AlarmTime.TimeFormat,
687 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Hours),
688 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Minutes),
689 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Seconds));
690 }
691 /* Set ALARM mask */
692 LL_RTC_ALMB_SetMask(RTCx, RTC_AlarmStruct->AlarmMask);
693
694 /* Enable the write protection for RTC registers */
695 LL_RTC_EnableWriteProtection(RTCx);
696
697 return SUCCESS;
698 }
699
700 /**
701 * @brief Set each @ref LL_RTC_AlarmTypeDef of ALARMA field to default value (Time = 00h:00mn:00sec /
702 * Day = 1st day of the month/Mask = all fields are masked).
703 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure which will be initialized.
704 * @retval None
705 */
706 void LL_RTC_ALMA_StructInit(LL_RTC_AlarmTypeDef *RTC_AlarmStruct)
707 {
708 /* Alarm Time Settings : Time = 00h:00mn:00sec */
709 RTC_AlarmStruct->AlarmTime.TimeFormat = LL_RTC_ALMA_TIME_FORMAT_AM;
710 RTC_AlarmStruct->AlarmTime.Hours = 0U;
711 RTC_AlarmStruct->AlarmTime.Minutes = 0U;
712 RTC_AlarmStruct->AlarmTime.Seconds = 0U;
713
714 /* Alarm Day Settings : Day = 1st day of the month */
715 RTC_AlarmStruct->AlarmDateWeekDaySel = LL_RTC_ALMA_DATEWEEKDAYSEL_DATE;
716 RTC_AlarmStruct->AlarmDateWeekDay = 1U;
717
718 /* Alarm Masks Settings : Mask = all fields are not masked */
719 RTC_AlarmStruct->AlarmMask = LL_RTC_ALMA_MASK_NONE;
720 }
721
722 /**
723 * @brief Set each @ref LL_RTC_AlarmTypeDef of ALARMA field to default value (Time = 00h:00mn:00sec /
724 * Day = 1st day of the month/Mask = all fields are masked).
725 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure which will be initialized.
726 * @retval None
727 */
728 void LL_RTC_ALMB_StructInit(LL_RTC_AlarmTypeDef *RTC_AlarmStruct)
729 {
730 /* Alarm Time Settings : Time = 00h:00mn:00sec */
731 RTC_AlarmStruct->AlarmTime.TimeFormat = LL_RTC_ALMB_TIME_FORMAT_AM;
732 RTC_AlarmStruct->AlarmTime.Hours = 0U;
733 RTC_AlarmStruct->AlarmTime.Minutes = 0U;
734 RTC_AlarmStruct->AlarmTime.Seconds = 0U;
735
736 /* Alarm Day Settings : Day = 1st day of the month */
737 RTC_AlarmStruct->AlarmDateWeekDaySel = LL_RTC_ALMB_DATEWEEKDAYSEL_DATE;
738 RTC_AlarmStruct->AlarmDateWeekDay = 1U;
739
740 /* Alarm Masks Settings : Mask = all fields are not masked */
741 RTC_AlarmStruct->AlarmMask = LL_RTC_ALMB_MASK_NONE;
742 }
743
744 /**
745 * @brief Enters the RTC Initialization mode.
746 * @note The RTC Initialization mode is write protected, use the
747 * @ref LL_RTC_DisableWriteProtection before calling this function.
748 * @param RTCx RTC Instance
749 * @retval An ErrorStatus enumeration value:
750 * - SUCCESS: RTC is in Init mode
751 * - ERROR: RTC is not in Init mode
752 */
753 ErrorStatus LL_RTC_EnterInitMode(RTC_TypeDef *RTCx)
754 {
755 __IO uint32_t timeout = RTC_INITMODE_TIMEOUT;
756 ErrorStatus status = SUCCESS;
757 uint32_t tmp = 0U;
758
759 /* Check the parameter */
760 assert_param(IS_RTC_ALL_INSTANCE(RTCx));
761
762 /* Check if the Initialization mode is set */
763 if (LL_RTC_IsActiveFlag_INIT(RTCx) == 0U)
764 {
765 /* Set the Initialization mode */
766 LL_RTC_EnableInitMode(RTCx);
767
768 /* Wait till RTC is in INIT state and if Time out is reached exit */
769 tmp = LL_RTC_IsActiveFlag_INIT(RTCx);
770 while ((timeout != 0U) && (tmp != 1U))
771 {
772 if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
773 {
774 timeout --;
775 }
776 tmp = LL_RTC_IsActiveFlag_INIT(RTCx);
777 if (timeout == 0U)
778 {
779 status = ERROR;
780 }
781 }
782 }
783 return status;
784 }
785
786 /**
787 * @brief Exit the RTC Initialization mode.
788 * @note When the initialization sequence is complete, the calendar restarts
789 * counting after 4 RTCCLK cycles.
790 * @note The RTC Initialization mode is write protected, use the
791 * @ref LL_RTC_DisableWriteProtection before calling this function.
792 * @param RTCx RTC Instance
793 * @retval An ErrorStatus enumeration value:
794 * - SUCCESS: RTC exited from in Init mode
795 * - ERROR: Not applicable
796 */
797 ErrorStatus LL_RTC_ExitInitMode(RTC_TypeDef *RTCx)
798 {
799 /* Check the parameter */
800 assert_param(IS_RTC_ALL_INSTANCE(RTCx));
801
802 /* Disable initialization mode */
803 LL_RTC_DisableInitMode(RTCx);
804
805 return SUCCESS;
806 }
807
808 /**
809 * @brief Waits until the RTC Time and Day registers (RTC_TR and RTC_DR) are
810 * synchronized with RTC APB clock.
811 * @note The RTC Resynchronization mode is write protected, use the
812 * @ref LL_RTC_DisableWriteProtection before calling this function.
813 * @note To read the calendar through the shadow registers after Calendar
814 * initialization, calendar update or after wakeup from low power modes
815 * the software must first clear the RSF flag.
816 * The software must then wait until it is set again before reading
817 * the calendar, which means that the calendar registers have been
818 * correctly copied into the RTC_TR and RTC_DR shadow registers.
819 * @param RTCx RTC Instance
820 * @retval An ErrorStatus enumeration value:
821 * - SUCCESS: RTC registers are synchronised
822 * - ERROR: RTC registers are not synchronised
823 */
824 ErrorStatus LL_RTC_WaitForSynchro(RTC_TypeDef *RTCx)
825 {
826 __IO uint32_t timeout = RTC_SYNCHRO_TIMEOUT;
827 ErrorStatus status = SUCCESS;
828 uint32_t tmp = 0U;
829
830 /* Check the parameter */
831 assert_param(IS_RTC_ALL_INSTANCE(RTCx));
832
833 /* Clear RSF flag */
834 LL_RTC_ClearFlag_RS(RTCx);
835
836 /* Wait the registers to be synchronised */
837 tmp = LL_RTC_IsActiveFlag_RS(RTCx);
838 while ((timeout != 0U) && (tmp != 0U))
839 {
840 if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
841 {
842 timeout--;
843 }
844 tmp = LL_RTC_IsActiveFlag_RS(RTCx);
845 if (timeout == 0U)
846 {
847 status = ERROR;
848 }
849 }
850
851 if (status != ERROR)
852 {
853 timeout = RTC_SYNCHRO_TIMEOUT;
854 tmp = LL_RTC_IsActiveFlag_RS(RTCx);
855 while ((timeout != 0U) && (tmp != 1U))
856 {
857 if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
858 {
859 timeout--;
860 }
861 tmp = LL_RTC_IsActiveFlag_RS(RTCx);
862 if (timeout == 0U)
863 {
864 status = ERROR;
865 }
866 }
867 }
868
869 return (status);
870 }
871
872 /**
873 * @}
874 */
875
876 /**
877 * @}
878 */
879
880 /**
881 * @}
882 */
883
884 #endif /* defined(RTC) */
885
886 /**
887 * @}
888 */
889
890 #endif /* USE_FULL_LL_DRIVER */
891
892 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/