inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

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