TUKS MCU Introductory course / TUKS-COURSE-TIMER
Committer:
elmot
Date:
Sat Feb 25 00:23:53 2017 +0000
Revision:
2:5acdd8565d02
Parent:
1:d0dfbce63a89
Ready to show

Who changed what in which revision?

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