STM32L443xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_ll_rtc.c 00004 * @author MCD Application Team 00005 * @brief RTC LL module driver. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * Copyright (c) 2017 STMicroelectronics. 00010 * All rights reserved. 00011 * 00012 * This software is licensed under terms that can be found in the LICENSE file 00013 * in the root directory of this software component. 00014 * If no LICENSE file comes with this software, it is provided AS-IS. 00015 * 00016 ****************************************************************************** 00017 */ 00018 #if defined(USE_FULL_LL_DRIVER) 00019 00020 /* Includes ------------------------------------------------------------------*/ 00021 #include "stm32l4xx_ll_rtc.h" 00022 #include "stm32l4xx_ll_cortex.h" 00023 #ifdef USE_FULL_ASSERT 00024 #include "stm32_assert.h" 00025 #else 00026 #define assert_param(expr) ((void)0U) 00027 #endif 00028 00029 /** @addtogroup STM32L4xx_LL_Driver 00030 * @{ 00031 */ 00032 00033 #if defined(RTC) 00034 00035 /** @addtogroup RTC_LL 00036 * @{ 00037 */ 00038 00039 /* Private types -------------------------------------------------------------*/ 00040 /* Private variables ---------------------------------------------------------*/ 00041 /* Private constants ---------------------------------------------------------*/ 00042 /** @addtogroup RTC_LL_Private_Constants 00043 * @{ 00044 */ 00045 /* Default values used for prescaler */ 00046 #define RTC_ASYNCH_PRESC_DEFAULT 0x0000007FU 00047 #define RTC_SYNCH_PRESC_DEFAULT 0x000000FFU 00048 00049 /* Values used for timeout */ 00050 #define RTC_INITMODE_TIMEOUT 1000U /* 1s when tick set to 1ms */ 00051 #define RTC_SYNCHRO_TIMEOUT 1000U /* 1s when tick set to 1ms */ 00052 /** 00053 * @} 00054 */ 00055 00056 /* Private macros ------------------------------------------------------------*/ 00057 /** @addtogroup RTC_LL_Private_Macros 00058 * @{ 00059 */ 00060 00061 #define IS_LL_RTC_HOURFORMAT(__VALUE__) (((__VALUE__) == LL_RTC_HOURFORMAT_24HOUR) \ 00062 || ((__VALUE__) == LL_RTC_HOURFORMAT_AMPM)) 00063 00064 #define IS_LL_RTC_ASYNCH_PREDIV(__VALUE__) ((__VALUE__) <= 0x7FU) 00065 00066 #define IS_LL_RTC_SYNCH_PREDIV(__VALUE__) ((__VALUE__) <= 0x7FFFU) 00067 00068 #define IS_LL_RTC_FORMAT(__VALUE__) (((__VALUE__) == LL_RTC_FORMAT_BIN) \ 00069 || ((__VALUE__) == LL_RTC_FORMAT_BCD)) 00070 00071 #define IS_LL_RTC_TIME_FORMAT(__VALUE__) (((__VALUE__) == LL_RTC_TIME_FORMAT_AM_OR_24) \ 00072 || ((__VALUE__) == LL_RTC_TIME_FORMAT_PM)) 00073 00074 #define IS_LL_RTC_HOUR12(__HOUR__) (((__HOUR__) > 0U) && ((__HOUR__) <= 12U)) 00075 #define IS_LL_RTC_HOUR24(__HOUR__) ((__HOUR__) <= 23U) 00076 #define IS_LL_RTC_MINUTES(__MINUTES__) ((__MINUTES__) <= 59U) 00077 #define IS_LL_RTC_SECONDS(__SECONDS__) ((__SECONDS__) <= 59U) 00078 00079 #define IS_LL_RTC_WEEKDAY(__VALUE__) (((__VALUE__) == LL_RTC_WEEKDAY_MONDAY) \ 00080 || ((__VALUE__) == LL_RTC_WEEKDAY_TUESDAY) \ 00081 || ((__VALUE__) == LL_RTC_WEEKDAY_WEDNESDAY) \ 00082 || ((__VALUE__) == LL_RTC_WEEKDAY_THURSDAY) \ 00083 || ((__VALUE__) == LL_RTC_WEEKDAY_FRIDAY) \ 00084 || ((__VALUE__) == LL_RTC_WEEKDAY_SATURDAY) \ 00085 || ((__VALUE__) == LL_RTC_WEEKDAY_SUNDAY)) 00086 00087 #define IS_LL_RTC_DAY(__DAY__) (((__DAY__) >= 1U) && ((__DAY__) <= 31U)) 00088 00089 #define IS_LL_RTC_MONTH(__MONTH__) (((__MONTH__) >= 1U) && ((__MONTH__) <= 12U)) 00090 00091 #define IS_LL_RTC_YEAR(__YEAR__) ((__YEAR__) <= 99U) 00092 00093 #define IS_LL_RTC_ALMA_MASK(__VALUE__) (((__VALUE__) == LL_RTC_ALMA_MASK_NONE) \ 00094 || ((__VALUE__) == LL_RTC_ALMA_MASK_DATEWEEKDAY) \ 00095 || ((__VALUE__) == LL_RTC_ALMA_MASK_HOURS) \ 00096 || ((__VALUE__) == LL_RTC_ALMA_MASK_MINUTES) \ 00097 || ((__VALUE__) == LL_RTC_ALMA_MASK_SECONDS) \ 00098 || ((__VALUE__) == LL_RTC_ALMA_MASK_ALL)) 00099 00100 #define IS_LL_RTC_ALMB_MASK(__VALUE__) (((__VALUE__) == LL_RTC_ALMB_MASK_NONE) \ 00101 || ((__VALUE__) == LL_RTC_ALMB_MASK_DATEWEEKDAY) \ 00102 || ((__VALUE__) == LL_RTC_ALMB_MASK_HOURS) \ 00103 || ((__VALUE__) == LL_RTC_ALMB_MASK_MINUTES) \ 00104 || ((__VALUE__) == LL_RTC_ALMB_MASK_SECONDS) \ 00105 || ((__VALUE__) == LL_RTC_ALMB_MASK_ALL)) 00106 00107 00108 #define IS_LL_RTC_ALMA_DATE_WEEKDAY_SEL(__SEL__) (((__SEL__) == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE) || \ 00109 ((__SEL__) == LL_RTC_ALMA_DATEWEEKDAYSEL_WEEKDAY)) 00110 00111 #define IS_LL_RTC_ALMB_DATE_WEEKDAY_SEL(__SEL__) (((__SEL__) == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE) || \ 00112 ((__SEL__) == LL_RTC_ALMB_DATEWEEKDAYSEL_WEEKDAY)) 00113 00114 00115 /** 00116 * @} 00117 */ 00118 /* Private function prototypes -----------------------------------------------*/ 00119 /* Exported functions --------------------------------------------------------*/ 00120 /** @addtogroup RTC_LL_Exported_Functions 00121 * @{ 00122 */ 00123 00124 /** @addtogroup RTC_LL_EF_Init 00125 * @{ 00126 */ 00127 00128 /** 00129 * @brief De-Initializes the RTC registers to their default reset values. 00130 * @note This function does not reset the RTC Clock source and RTC Backup Data 00131 * registers. 00132 * @param RTCx RTC Instance 00133 * @retval An ErrorStatus enumeration value: 00134 * - SUCCESS: RTC registers are de-initialized 00135 * - ERROR: RTC registers are not de-initialized 00136 */ 00137 ErrorStatus LL_RTC_DeInit(RTC_TypeDef *RTCx) 00138 { 00139 ErrorStatus status; 00140 00141 /* Check the parameter */ 00142 assert_param(IS_RTC_ALL_INSTANCE(RTCx)); 00143 00144 /* Disable the write protection for RTC registers */ 00145 LL_RTC_DisableWriteProtection(RTCx); 00146 00147 /* Set Initialization mode */ 00148 status = LL_RTC_EnterInitMode(RTCx); 00149 if (status != ERROR) 00150 { 00151 /* Reset TR, DR and CR registers */ 00152 LL_RTC_WriteReg(RTCx, TR, 0x00000000U); 00153 00154 LL_RTC_WriteReg(RTCx, WUTR, RTC_WUTR_WUT); 00155 LL_RTC_WriteReg(RTCx, DR, (RTC_DR_WDU_0 | RTC_DR_MU_0 | RTC_DR_DU_0)); 00156 /* Reset All CR bits except CR[2:0] */ 00157 LL_RTC_WriteReg(RTCx, CR, (LL_RTC_ReadReg(RTCx, CR) & RTC_CR_WUCKSEL)); 00158 00159 LL_RTC_WriteReg(RTCx, PRER, (RTC_PRER_PREDIV_A | RTC_SYNCH_PRESC_DEFAULT)); 00160 LL_RTC_WriteReg(RTCx, ALRMAR, 0x00000000U); 00161 LL_RTC_WriteReg(RTCx, ALRMBR, 0x00000000U); 00162 LL_RTC_WriteReg(RTCx, SHIFTR, 0x00000000U); 00163 LL_RTC_WriteReg(RTCx, CALR, 0x00000000U); 00164 LL_RTC_WriteReg(RTCx, ALRMASSR, 0x00000000U); 00165 LL_RTC_WriteReg(RTCx, ALRMBSSR, 0x00000000U); 00166 00167 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) 00168 #else /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */ 00169 /* Reset Tamper and alternate functions configuration register */ 00170 LL_RTC_WriteReg(RTCx, TAMPCR, 0x00000000U); 00171 00172 /* Reset Option register */ 00173 LL_RTC_WriteReg(RTCx, OR, 0x00000000U); 00174 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */ 00175 00176 /* Exit Initialization mode */ 00177 LL_RTC_DisableInitMode(RTCx); 00178 } 00179 00180 /* Enable the write protection for RTC registers */ 00181 LL_RTC_EnableWriteProtection(RTCx); 00182 00183 return status; 00184 } 00185 00186 /** 00187 * @brief Initializes the RTC registers according to the specified parameters 00188 * in RTC_InitStruct. 00189 * @param RTCx RTC Instance 00190 * @param RTC_InitStruct pointer to a @ref LL_RTC_InitTypeDef structure that contains 00191 * the configuration information for the RTC peripheral. 00192 * @note The RTC Prescaler register is write protected and can be written in 00193 * initialization mode only. 00194 * @retval An ErrorStatus enumeration value: 00195 * - SUCCESS: RTC registers are initialized 00196 * - ERROR: RTC registers are not initialized 00197 */ 00198 ErrorStatus LL_RTC_Init(RTC_TypeDef *RTCx, LL_RTC_InitTypeDef *RTC_InitStruct) 00199 { 00200 ErrorStatus status = ERROR; 00201 00202 /* Check the parameters */ 00203 assert_param(IS_RTC_ALL_INSTANCE(RTCx)); 00204 assert_param(IS_LL_RTC_HOURFORMAT(RTC_InitStruct->HourFormat)); 00205 assert_param(IS_LL_RTC_ASYNCH_PREDIV(RTC_InitStruct->AsynchPrescaler)); 00206 assert_param(IS_LL_RTC_SYNCH_PREDIV(RTC_InitStruct->SynchPrescaler)); 00207 00208 /* Disable the write protection for RTC registers */ 00209 LL_RTC_DisableWriteProtection(RTCx); 00210 00211 /* Set Initialization mode */ 00212 if (LL_RTC_EnterInitMode(RTCx) != ERROR) 00213 { 00214 /* Set Hour Format */ 00215 LL_RTC_SetHourFormat(RTCx, RTC_InitStruct->HourFormat); 00216 00217 /* Configure Synchronous and Asynchronous prescaler factor */ 00218 LL_RTC_SetSynchPrescaler(RTCx, RTC_InitStruct->SynchPrescaler); 00219 LL_RTC_SetAsynchPrescaler(RTCx, RTC_InitStruct->AsynchPrescaler); 00220 00221 /* Exit Initialization mode */ 00222 LL_RTC_DisableInitMode(RTCx); 00223 00224 status = SUCCESS; 00225 } 00226 /* Enable the write protection for RTC registers */ 00227 LL_RTC_EnableWriteProtection(RTCx); 00228 00229 return status; 00230 } 00231 00232 /** 00233 * @brief Set each @ref LL_RTC_InitTypeDef field to default value. 00234 * @param RTC_InitStruct pointer to a @ref LL_RTC_InitTypeDef structure which will be initialized. 00235 * @retval None 00236 */ 00237 void LL_RTC_StructInit(LL_RTC_InitTypeDef *RTC_InitStruct) 00238 { 00239 /* Set RTC_InitStruct fields to default values */ 00240 RTC_InitStruct->HourFormat = LL_RTC_HOURFORMAT_24HOUR; 00241 RTC_InitStruct->AsynchPrescaler = RTC_ASYNCH_PRESC_DEFAULT; 00242 RTC_InitStruct->SynchPrescaler = RTC_SYNCH_PRESC_DEFAULT; 00243 } 00244 00245 /** 00246 * @brief Set the RTC current time. 00247 * @param RTCx RTC Instance 00248 * @param RTC_Format This parameter can be one of the following values: 00249 * @arg @ref LL_RTC_FORMAT_BIN 00250 * @arg @ref LL_RTC_FORMAT_BCD 00251 * @param RTC_TimeStruct pointer to a RTC_TimeTypeDef structure that contains 00252 * the time configuration information for the RTC. 00253 * @retval An ErrorStatus enumeration value: 00254 * - SUCCESS: RTC Time register is configured 00255 * - ERROR: RTC Time register is not configured 00256 */ 00257 ErrorStatus LL_RTC_TIME_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_TimeTypeDef *RTC_TimeStruct) 00258 { 00259 ErrorStatus status = ERROR; 00260 00261 /* Check the parameters */ 00262 assert_param(IS_RTC_ALL_INSTANCE(RTCx)); 00263 assert_param(IS_LL_RTC_FORMAT(RTC_Format)); 00264 00265 if (RTC_Format == LL_RTC_FORMAT_BIN) 00266 { 00267 if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR) 00268 { 00269 assert_param(IS_LL_RTC_HOUR12(RTC_TimeStruct->Hours)); 00270 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_TimeStruct->TimeFormat)); 00271 } 00272 else 00273 { 00274 RTC_TimeStruct->TimeFormat = 0x00U; 00275 assert_param(IS_LL_RTC_HOUR24(RTC_TimeStruct->Hours)); 00276 } 00277 assert_param(IS_LL_RTC_MINUTES(RTC_TimeStruct->Minutes)); 00278 assert_param(IS_LL_RTC_SECONDS(RTC_TimeStruct->Seconds)); 00279 } 00280 else 00281 { 00282 if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR) 00283 { 00284 assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Hours))); 00285 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_TimeStruct->TimeFormat)); 00286 } 00287 else 00288 { 00289 RTC_TimeStruct->TimeFormat = 0x00U; 00290 assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Hours))); 00291 } 00292 assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Minutes))); 00293 assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_TimeStruct->Seconds))); 00294 } 00295 00296 /* Disable the write protection for RTC registers */ 00297 LL_RTC_DisableWriteProtection(RTCx); 00298 00299 /* Set Initialization mode */ 00300 if (LL_RTC_EnterInitMode(RTCx) != ERROR) 00301 { 00302 /* Check the input parameters format */ 00303 if (RTC_Format != LL_RTC_FORMAT_BIN) 00304 { 00305 LL_RTC_TIME_Config(RTCx, RTC_TimeStruct->TimeFormat, RTC_TimeStruct->Hours, 00306 RTC_TimeStruct->Minutes, RTC_TimeStruct->Seconds); 00307 } 00308 else 00309 { 00310 LL_RTC_TIME_Config(RTCx, RTC_TimeStruct->TimeFormat, __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct->Hours), 00311 __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct->Minutes), 00312 __LL_RTC_CONVERT_BIN2BCD(RTC_TimeStruct->Seconds)); 00313 } 00314 00315 /* Exit Initialization mode */ 00316 LL_RTC_DisableInitMode(RTCx); 00317 00318 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */ 00319 if (LL_RTC_IsShadowRegBypassEnabled(RTCx) == 0U) 00320 { 00321 status = LL_RTC_WaitForSynchro(RTCx); 00322 } 00323 else 00324 { 00325 status = SUCCESS; 00326 } 00327 } 00328 /* Enable the write protection for RTC registers */ 00329 LL_RTC_EnableWriteProtection(RTCx); 00330 00331 return status; 00332 } 00333 00334 /** 00335 * @brief Set each @ref LL_RTC_TimeTypeDef field to default value (Time = 00h:00min:00sec). 00336 * @param RTC_TimeStruct pointer to a @ref LL_RTC_TimeTypeDef structure which will be initialized. 00337 * @retval None 00338 */ 00339 void LL_RTC_TIME_StructInit(LL_RTC_TimeTypeDef *RTC_TimeStruct) 00340 { 00341 /* Time = 00h:00min:00sec */ 00342 RTC_TimeStruct->TimeFormat = LL_RTC_TIME_FORMAT_AM_OR_24; 00343 RTC_TimeStruct->Hours = 0U; 00344 RTC_TimeStruct->Minutes = 0U; 00345 RTC_TimeStruct->Seconds = 0U; 00346 } 00347 00348 /** 00349 * @brief Set the RTC current date. 00350 * @param RTCx RTC Instance 00351 * @param RTC_Format This parameter can be one of the following values: 00352 * @arg @ref LL_RTC_FORMAT_BIN 00353 * @arg @ref LL_RTC_FORMAT_BCD 00354 * @param RTC_DateStruct pointer to a RTC_DateTypeDef structure that contains 00355 * the date configuration information for the RTC. 00356 * @retval An ErrorStatus enumeration value: 00357 * - SUCCESS: RTC Day register is configured 00358 * - ERROR: RTC Day register is not configured 00359 */ 00360 ErrorStatus LL_RTC_DATE_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_DateTypeDef *RTC_DateStruct) 00361 { 00362 ErrorStatus status = ERROR; 00363 00364 /* Check the parameters */ 00365 assert_param(IS_RTC_ALL_INSTANCE(RTCx)); 00366 assert_param(IS_LL_RTC_FORMAT(RTC_Format)); 00367 00368 if ((RTC_Format == LL_RTC_FORMAT_BIN) && ((RTC_DateStruct->Month & 0x10U) == 0x10U)) 00369 { 00370 RTC_DateStruct->Month = (uint8_t)(((uint32_t) RTC_DateStruct->Month & (uint32_t)~(0x10U)) + 0x0AU); 00371 } 00372 00373 if (RTC_Format == LL_RTC_FORMAT_BIN) 00374 { 00375 assert_param(IS_LL_RTC_YEAR(RTC_DateStruct->Year)); 00376 assert_param(IS_LL_RTC_MONTH(RTC_DateStruct->Month)); 00377 assert_param(IS_LL_RTC_DAY(RTC_DateStruct->Day)); 00378 } 00379 else 00380 { 00381 assert_param(IS_LL_RTC_YEAR(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct->Year))); 00382 assert_param(IS_LL_RTC_MONTH(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct->Month))); 00383 assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct->Day))); 00384 } 00385 assert_param(IS_LL_RTC_WEEKDAY(RTC_DateStruct->WeekDay)); 00386 00387 /* Disable the write protection for RTC registers */ 00388 LL_RTC_DisableWriteProtection(RTCx); 00389 00390 /* Set Initialization mode */ 00391 if (LL_RTC_EnterInitMode(RTCx) != ERROR) 00392 { 00393 /* Check the input parameters format */ 00394 if (RTC_Format != LL_RTC_FORMAT_BIN) 00395 { 00396 LL_RTC_DATE_Config(RTCx, RTC_DateStruct->WeekDay, RTC_DateStruct->Day, RTC_DateStruct->Month, RTC_DateStruct->Year); 00397 } 00398 else 00399 { 00400 LL_RTC_DATE_Config(RTCx, RTC_DateStruct->WeekDay, __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct->Day), 00401 __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct->Month), __LL_RTC_CONVERT_BIN2BCD(RTC_DateStruct->Year)); 00402 } 00403 00404 /* Exit Initialization mode */ 00405 LL_RTC_DisableInitMode(RTCx); 00406 00407 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */ 00408 if (LL_RTC_IsShadowRegBypassEnabled(RTCx) == 0U) 00409 { 00410 status = LL_RTC_WaitForSynchro(RTCx); 00411 } 00412 else 00413 { 00414 status = SUCCESS; 00415 } 00416 } 00417 /* Enable the write protection for RTC registers */ 00418 LL_RTC_EnableWriteProtection(RTCx); 00419 00420 return status; 00421 } 00422 00423 /** 00424 * @brief Set each @ref LL_RTC_DateTypeDef field to default value (date = Monday, January 01 xx00) 00425 * @param RTC_DateStruct pointer to a @ref LL_RTC_DateTypeDef structure which will be initialized. 00426 * @retval None 00427 */ 00428 void LL_RTC_DATE_StructInit(LL_RTC_DateTypeDef *RTC_DateStruct) 00429 { 00430 /* Monday, January 01 xx00 */ 00431 RTC_DateStruct->WeekDay = LL_RTC_WEEKDAY_MONDAY; 00432 RTC_DateStruct->Day = 1U; 00433 RTC_DateStruct->Month = LL_RTC_MONTH_JANUARY; 00434 RTC_DateStruct->Year = 0U; 00435 } 00436 00437 /** 00438 * @brief Set the RTC Alarm A. 00439 * @note The Alarm register can only be written when the corresponding Alarm 00440 * is disabled (Use @ref LL_RTC_ALMA_Disable function). 00441 * @param RTCx RTC Instance 00442 * @param RTC_Format This parameter can be one of the following values: 00443 * @arg @ref LL_RTC_FORMAT_BIN 00444 * @arg @ref LL_RTC_FORMAT_BCD 00445 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure that 00446 * contains the alarm configuration parameters. 00447 * @retval An ErrorStatus enumeration value: 00448 * - SUCCESS: ALARMA registers are configured 00449 * - ERROR: ALARMA registers are not configured 00450 */ 00451 ErrorStatus LL_RTC_ALMA_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_AlarmTypeDef *RTC_AlarmStruct) 00452 { 00453 /* Check the parameters */ 00454 assert_param(IS_RTC_ALL_INSTANCE(RTCx)); 00455 assert_param(IS_LL_RTC_FORMAT(RTC_Format)); 00456 assert_param(IS_LL_RTC_ALMA_MASK(RTC_AlarmStruct->AlarmMask)); 00457 assert_param(IS_LL_RTC_ALMA_DATE_WEEKDAY_SEL(RTC_AlarmStruct->AlarmDateWeekDaySel)); 00458 00459 if (RTC_Format == LL_RTC_FORMAT_BIN) 00460 { 00461 if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR) 00462 { 00463 assert_param(IS_LL_RTC_HOUR12(RTC_AlarmStruct->AlarmTime.Hours)); 00464 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct->AlarmTime.TimeFormat)); 00465 } 00466 else 00467 { 00468 RTC_AlarmStruct->AlarmTime.TimeFormat = 0x00U; 00469 assert_param(IS_LL_RTC_HOUR24(RTC_AlarmStruct->AlarmTime.Hours)); 00470 } 00471 assert_param(IS_LL_RTC_MINUTES(RTC_AlarmStruct->AlarmTime.Minutes)); 00472 assert_param(IS_LL_RTC_SECONDS(RTC_AlarmStruct->AlarmTime.Seconds)); 00473 00474 if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE) 00475 { 00476 assert_param(IS_LL_RTC_DAY(RTC_AlarmStruct->AlarmDateWeekDay)); 00477 } 00478 else 00479 { 00480 assert_param(IS_LL_RTC_WEEKDAY(RTC_AlarmStruct->AlarmDateWeekDay)); 00481 } 00482 } 00483 else 00484 { 00485 if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR) 00486 { 00487 assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours))); 00488 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct->AlarmTime.TimeFormat)); 00489 } 00490 else 00491 { 00492 RTC_AlarmStruct->AlarmTime.TimeFormat = 0x00U; 00493 assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours))); 00494 } 00495 00496 assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Minutes))); 00497 assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Seconds))); 00498 00499 if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE) 00500 { 00501 assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmDateWeekDay))); 00502 } 00503 else 00504 { 00505 assert_param(IS_LL_RTC_WEEKDAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmDateWeekDay))); 00506 } 00507 } 00508 00509 /* Disable the write protection for RTC registers */ 00510 LL_RTC_DisableWriteProtection(RTCx); 00511 00512 /* Select weekday selection */ 00513 if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMA_DATEWEEKDAYSEL_DATE) 00514 { 00515 /* Set the date for ALARM */ 00516 LL_RTC_ALMA_DisableWeekday(RTCx); 00517 if (RTC_Format != LL_RTC_FORMAT_BIN) 00518 { 00519 LL_RTC_ALMA_SetDay(RTCx, RTC_AlarmStruct->AlarmDateWeekDay); 00520 } 00521 else 00522 { 00523 LL_RTC_ALMA_SetDay(RTCx, __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmDateWeekDay)); 00524 } 00525 } 00526 else 00527 { 00528 /* Set the week day for ALARM */ 00529 LL_RTC_ALMA_EnableWeekday(RTCx); 00530 LL_RTC_ALMA_SetWeekDay(RTCx, RTC_AlarmStruct->AlarmDateWeekDay); 00531 } 00532 00533 /* Configure the Alarm register */ 00534 if (RTC_Format != LL_RTC_FORMAT_BIN) 00535 { 00536 LL_RTC_ALMA_ConfigTime(RTCx, RTC_AlarmStruct->AlarmTime.TimeFormat, RTC_AlarmStruct->AlarmTime.Hours, 00537 RTC_AlarmStruct->AlarmTime.Minutes, RTC_AlarmStruct->AlarmTime.Seconds); 00538 } 00539 else 00540 { 00541 LL_RTC_ALMA_ConfigTime(RTCx, RTC_AlarmStruct->AlarmTime.TimeFormat, 00542 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Hours), 00543 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Minutes), 00544 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Seconds)); 00545 } 00546 /* Set ALARM mask */ 00547 LL_RTC_ALMA_SetMask(RTCx, RTC_AlarmStruct->AlarmMask); 00548 00549 /* Enable the write protection for RTC registers */ 00550 LL_RTC_EnableWriteProtection(RTCx); 00551 00552 return SUCCESS; 00553 } 00554 00555 /** 00556 * @brief Set the RTC Alarm B. 00557 * @note The Alarm register can only be written when the corresponding Alarm 00558 * is disabled (@ref LL_RTC_ALMB_Disable function). 00559 * @param RTCx RTC Instance 00560 * @param RTC_Format This parameter can be one of the following values: 00561 * @arg @ref LL_RTC_FORMAT_BIN 00562 * @arg @ref LL_RTC_FORMAT_BCD 00563 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure that 00564 * contains the alarm configuration parameters. 00565 * @retval An ErrorStatus enumeration value: 00566 * - SUCCESS: ALARMB registers are configured 00567 * - ERROR: ALARMB registers are not configured 00568 */ 00569 ErrorStatus LL_RTC_ALMB_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_AlarmTypeDef *RTC_AlarmStruct) 00570 { 00571 /* Check the parameters */ 00572 assert_param(IS_RTC_ALL_INSTANCE(RTCx)); 00573 assert_param(IS_LL_RTC_FORMAT(RTC_Format)); 00574 assert_param(IS_LL_RTC_ALMB_MASK(RTC_AlarmStruct->AlarmMask)); 00575 assert_param(IS_LL_RTC_ALMB_DATE_WEEKDAY_SEL(RTC_AlarmStruct->AlarmDateWeekDaySel)); 00576 00577 if (RTC_Format == LL_RTC_FORMAT_BIN) 00578 { 00579 if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR) 00580 { 00581 assert_param(IS_LL_RTC_HOUR12(RTC_AlarmStruct->AlarmTime.Hours)); 00582 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct->AlarmTime.TimeFormat)); 00583 } 00584 else 00585 { 00586 RTC_AlarmStruct->AlarmTime.TimeFormat = 0x00U; 00587 assert_param(IS_LL_RTC_HOUR24(RTC_AlarmStruct->AlarmTime.Hours)); 00588 } 00589 assert_param(IS_LL_RTC_MINUTES(RTC_AlarmStruct->AlarmTime.Minutes)); 00590 assert_param(IS_LL_RTC_SECONDS(RTC_AlarmStruct->AlarmTime.Seconds)); 00591 00592 if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE) 00593 { 00594 assert_param(IS_LL_RTC_DAY(RTC_AlarmStruct->AlarmDateWeekDay)); 00595 } 00596 else 00597 { 00598 assert_param(IS_LL_RTC_WEEKDAY(RTC_AlarmStruct->AlarmDateWeekDay)); 00599 } 00600 } 00601 else 00602 { 00603 if (LL_RTC_GetHourFormat(RTCx) != LL_RTC_HOURFORMAT_24HOUR) 00604 { 00605 assert_param(IS_LL_RTC_HOUR12(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours))); 00606 assert_param(IS_LL_RTC_TIME_FORMAT(RTC_AlarmStruct->AlarmTime.TimeFormat)); 00607 } 00608 else 00609 { 00610 RTC_AlarmStruct->AlarmTime.TimeFormat = 0x00U; 00611 assert_param(IS_LL_RTC_HOUR24(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Hours))); 00612 } 00613 00614 assert_param(IS_LL_RTC_MINUTES(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Minutes))); 00615 assert_param(IS_LL_RTC_SECONDS(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmTime.Seconds))); 00616 00617 if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE) 00618 { 00619 assert_param(IS_LL_RTC_DAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmDateWeekDay))); 00620 } 00621 else 00622 { 00623 assert_param(IS_LL_RTC_WEEKDAY(__LL_RTC_CONVERT_BCD2BIN(RTC_AlarmStruct->AlarmDateWeekDay))); 00624 } 00625 } 00626 00627 /* Disable the write protection for RTC registers */ 00628 LL_RTC_DisableWriteProtection(RTCx); 00629 00630 /* Select weekday selection */ 00631 if (RTC_AlarmStruct->AlarmDateWeekDaySel == LL_RTC_ALMB_DATEWEEKDAYSEL_DATE) 00632 { 00633 /* Set the date for ALARM */ 00634 LL_RTC_ALMB_DisableWeekday(RTCx); 00635 if (RTC_Format != LL_RTC_FORMAT_BIN) 00636 { 00637 LL_RTC_ALMB_SetDay(RTCx, RTC_AlarmStruct->AlarmDateWeekDay); 00638 } 00639 else 00640 { 00641 LL_RTC_ALMB_SetDay(RTCx, __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmDateWeekDay)); 00642 } 00643 } 00644 else 00645 { 00646 /* Set the week day for ALARM */ 00647 LL_RTC_ALMB_EnableWeekday(RTCx); 00648 LL_RTC_ALMB_SetWeekDay(RTCx, RTC_AlarmStruct->AlarmDateWeekDay); 00649 } 00650 00651 /* Configure the Alarm register */ 00652 if (RTC_Format != LL_RTC_FORMAT_BIN) 00653 { 00654 LL_RTC_ALMB_ConfigTime(RTCx, RTC_AlarmStruct->AlarmTime.TimeFormat, RTC_AlarmStruct->AlarmTime.Hours, 00655 RTC_AlarmStruct->AlarmTime.Minutes, RTC_AlarmStruct->AlarmTime.Seconds); 00656 } 00657 else 00658 { 00659 LL_RTC_ALMB_ConfigTime(RTCx, RTC_AlarmStruct->AlarmTime.TimeFormat, 00660 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Hours), 00661 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Minutes), 00662 __LL_RTC_CONVERT_BIN2BCD(RTC_AlarmStruct->AlarmTime.Seconds)); 00663 } 00664 /* Set ALARM mask */ 00665 LL_RTC_ALMB_SetMask(RTCx, RTC_AlarmStruct->AlarmMask); 00666 00667 /* Enable the write protection for RTC registers */ 00668 LL_RTC_EnableWriteProtection(RTCx); 00669 00670 return SUCCESS; 00671 } 00672 00673 /** 00674 * @brief Set each @ref LL_RTC_AlarmTypeDef of ALARMA field to default value (Time = 00h:00mn:00sec / 00675 * Day = 1st day of the month/Mask = all fields are masked). 00676 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure which will be initialized. 00677 * @retval None 00678 */ 00679 void LL_RTC_ALMA_StructInit(LL_RTC_AlarmTypeDef *RTC_AlarmStruct) 00680 { 00681 /* Alarm Time Settings : Time = 00h:00mn:00sec */ 00682 RTC_AlarmStruct->AlarmTime.TimeFormat = LL_RTC_ALMA_TIME_FORMAT_AM; 00683 RTC_AlarmStruct->AlarmTime.Hours = 0U; 00684 RTC_AlarmStruct->AlarmTime.Minutes = 0U; 00685 RTC_AlarmStruct->AlarmTime.Seconds = 0U; 00686 00687 /* Alarm Day Settings : Day = 1st day of the month */ 00688 RTC_AlarmStruct->AlarmDateWeekDaySel = LL_RTC_ALMA_DATEWEEKDAYSEL_DATE; 00689 RTC_AlarmStruct->AlarmDateWeekDay = 1U; 00690 00691 /* Alarm Masks Settings : Mask = all fields are not masked */ 00692 RTC_AlarmStruct->AlarmMask = LL_RTC_ALMA_MASK_NONE; 00693 } 00694 00695 /** 00696 * @brief Set each @ref LL_RTC_AlarmTypeDef of ALARMA field to default value (Time = 00h:00mn:00sec / 00697 * Day = 1st day of the month/Mask = all fields are masked). 00698 * @param RTC_AlarmStruct pointer to a @ref LL_RTC_AlarmTypeDef structure which will be initialized. 00699 * @retval None 00700 */ 00701 void LL_RTC_ALMB_StructInit(LL_RTC_AlarmTypeDef *RTC_AlarmStruct) 00702 { 00703 /* Alarm Time Settings : Time = 00h:00mn:00sec */ 00704 RTC_AlarmStruct->AlarmTime.TimeFormat = LL_RTC_ALMB_TIME_FORMAT_AM; 00705 RTC_AlarmStruct->AlarmTime.Hours = 0U; 00706 RTC_AlarmStruct->AlarmTime.Minutes = 0U; 00707 RTC_AlarmStruct->AlarmTime.Seconds = 0U; 00708 00709 /* Alarm Day Settings : Day = 1st day of the month */ 00710 RTC_AlarmStruct->AlarmDateWeekDaySel = LL_RTC_ALMB_DATEWEEKDAYSEL_DATE; 00711 RTC_AlarmStruct->AlarmDateWeekDay = 1U; 00712 00713 /* Alarm Masks Settings : Mask = all fields are not masked */ 00714 RTC_AlarmStruct->AlarmMask = LL_RTC_ALMB_MASK_NONE; 00715 } 00716 00717 /** 00718 * @brief Enters the RTC Initialization mode. 00719 * @note The RTC Initialization mode is write protected, use the 00720 * @ref LL_RTC_DisableWriteProtection before calling this function. 00721 * @param RTCx RTC Instance 00722 * @retval An ErrorStatus enumeration value: 00723 * - SUCCESS: RTC is in Init mode 00724 * - ERROR: RTC is not in Init mode 00725 */ 00726 ErrorStatus LL_RTC_EnterInitMode(RTC_TypeDef *RTCx) 00727 { 00728 __IO uint32_t timeout = RTC_INITMODE_TIMEOUT; 00729 ErrorStatus status = SUCCESS; 00730 uint32_t tmp; 00731 00732 /* Check the parameter */ 00733 assert_param(IS_RTC_ALL_INSTANCE(RTCx)); 00734 00735 /* Check if the Initialization mode is set */ 00736 if (LL_RTC_IsActiveFlag_INIT(RTCx) == 0U) 00737 { 00738 /* Set the Initialization mode */ 00739 LL_RTC_EnableInitMode(RTCx); 00740 00741 /* Wait till RTC is in INIT state and if Time out is reached exit */ 00742 tmp = LL_RTC_IsActiveFlag_INIT(RTCx); 00743 while ((timeout != 0U) && (tmp != 1U)) 00744 { 00745 if (LL_SYSTICK_IsActiveCounterFlag() == 1U) 00746 { 00747 timeout --; 00748 } 00749 tmp = LL_RTC_IsActiveFlag_INIT(RTCx); 00750 if (timeout == 0U) 00751 { 00752 status = ERROR; 00753 } 00754 } 00755 } 00756 return status; 00757 } 00758 00759 /** 00760 * @brief Exit the RTC Initialization mode. 00761 * @note When the initialization sequence is complete, the calendar restarts 00762 * counting after 4 RTCCLK cycles. 00763 * @note The RTC Initialization mode is write protected, use the 00764 * @ref LL_RTC_DisableWriteProtection before calling this function. 00765 * @param RTCx RTC Instance 00766 * @retval An ErrorStatus enumeration value: 00767 * - SUCCESS: RTC exited from in Init mode 00768 * - ERROR: Not applicable 00769 */ 00770 ErrorStatus LL_RTC_ExitInitMode(RTC_TypeDef *RTCx) 00771 { 00772 /* Check the parameter */ 00773 assert_param(IS_RTC_ALL_INSTANCE(RTCx)); 00774 00775 /* Disable initialization mode */ 00776 LL_RTC_DisableInitMode(RTCx); 00777 00778 return SUCCESS; 00779 } 00780 00781 /** 00782 * @brief Waits until the RTC Time and Day registers (RTC_TR and RTC_DR) are 00783 * synchronized with RTC APB clock. 00784 * @note The RTC Resynchronization mode is write protected, use the 00785 * @ref LL_RTC_DisableWriteProtection before calling this function. 00786 * @note To read the calendar through the shadow registers after Calendar 00787 * initialization, calendar update or after wakeup from low power modes 00788 * the software must first clear the RSF flag. 00789 * The software must then wait until it is set again before reading 00790 * the calendar, which means that the calendar registers have been 00791 * correctly copied into the RTC_TR and RTC_DR shadow registers. 00792 * @param RTCx RTC Instance 00793 * @retval An ErrorStatus enumeration value: 00794 * - SUCCESS: RTC registers are synchronised 00795 * - ERROR: RTC registers are not synchronised 00796 */ 00797 ErrorStatus LL_RTC_WaitForSynchro(RTC_TypeDef *RTCx) 00798 { 00799 __IO uint32_t timeout = RTC_SYNCHRO_TIMEOUT; 00800 ErrorStatus status = SUCCESS; 00801 uint32_t tmp; 00802 00803 /* Check the parameter */ 00804 assert_param(IS_RTC_ALL_INSTANCE(RTCx)); 00805 00806 /* Clear RSF flag */ 00807 LL_RTC_ClearFlag_RS(RTCx); 00808 00809 /* Wait the registers to be synchronised */ 00810 tmp = LL_RTC_IsActiveFlag_RS(RTCx); 00811 while ((timeout != 0U) && (tmp != 0U)) 00812 { 00813 if (LL_SYSTICK_IsActiveCounterFlag() == 1U) 00814 { 00815 timeout--; 00816 } 00817 tmp = LL_RTC_IsActiveFlag_RS(RTCx); 00818 if (timeout == 0U) 00819 { 00820 status = ERROR; 00821 } 00822 } 00823 00824 if (status != ERROR) 00825 { 00826 timeout = RTC_SYNCHRO_TIMEOUT; 00827 tmp = LL_RTC_IsActiveFlag_RS(RTCx); 00828 while ((timeout != 0U) && (tmp != 1U)) 00829 { 00830 if (LL_SYSTICK_IsActiveCounterFlag() == 1U) 00831 { 00832 timeout--; 00833 } 00834 tmp = LL_RTC_IsActiveFlag_RS(RTCx); 00835 if (timeout == 0U) 00836 { 00837 status = ERROR; 00838 } 00839 } 00840 } 00841 00842 return (status); 00843 } 00844 00845 /** 00846 * @} 00847 */ 00848 00849 /** 00850 * @} 00851 */ 00852 00853 /** 00854 * @} 00855 */ 00856 00857 #endif /* defined(RTC) */ 00858 00859 /** 00860 * @} 00861 */ 00862 00863 #endif /* USE_FULL_LL_DRIVER */