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