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