added prescaler for 16 bit pwm in LPC1347 target

Fork of mbed-dev by mbed official

Committer:
JojoS
Date:
Sat Sep 10 15:32:04 2016 +0000
Revision:
147:ba84b7dc41a7
Parent:
144:ef7eb2e8f9f7
added prescaler for 16 bit timers (solution as in LPC11xx), default prescaler 31 for max 28 ms period time

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 144:ef7eb2e8f9f7 1 /**
<> 144:ef7eb2e8f9f7 2 ******************************************************************************
<> 144:ef7eb2e8f9f7 3 * @file stm32f7xx_hal_rtc.c
<> 144:ef7eb2e8f9f7 4 * @author MCD Application Team
<> 144:ef7eb2e8f9f7 5 * @version V1.1.0
<> 144:ef7eb2e8f9f7 6 * @date 22-April-2016
<> 144:ef7eb2e8f9f7 7 * @brief RTC HAL module driver.
<> 144:ef7eb2e8f9f7 8 * This file provides firmware functions to manage the following
<> 144:ef7eb2e8f9f7 9 * functionalities of the Real Time Clock (RTC) peripheral:
<> 144:ef7eb2e8f9f7 10 * + Initialization and de-initialization functions
<> 144:ef7eb2e8f9f7 11 * + RTC Time and Date functions
<> 144:ef7eb2e8f9f7 12 * + RTC Alarm functions
<> 144:ef7eb2e8f9f7 13 * + Peripheral Control functions
<> 144:ef7eb2e8f9f7 14 * + Peripheral State functions
<> 144:ef7eb2e8f9f7 15 *
<> 144:ef7eb2e8f9f7 16 @verbatim
<> 144:ef7eb2e8f9f7 17 ==============================================================================
<> 144:ef7eb2e8f9f7 18 ##### Backup Domain Operating Condition #####
<> 144:ef7eb2e8f9f7 19 ==============================================================================
<> 144:ef7eb2e8f9f7 20 [..] The real-time clock (RTC), the RTC backup registers, and the backup
<> 144:ef7eb2e8f9f7 21 SRAM (BKP SRAM) can be powered from the VBAT voltage when the main
<> 144:ef7eb2e8f9f7 22 VDD supply is powered off.
<> 144:ef7eb2e8f9f7 23 To retain the content of the RTC backup registers, backup SRAM, and supply
<> 144:ef7eb2e8f9f7 24 the RTC when VDD is turned off, VBAT pin can be connected to an optional
<> 144:ef7eb2e8f9f7 25 standby voltage supplied by a battery or by another source.
<> 144:ef7eb2e8f9f7 26
<> 144:ef7eb2e8f9f7 27 [..] To allow the RTC operating even when the main digital supply (VDD) is turned
<> 144:ef7eb2e8f9f7 28 off, the VBAT pin powers the following blocks:
<> 144:ef7eb2e8f9f7 29 (#) The RTC
<> 144:ef7eb2e8f9f7 30 (#) The LSE oscillator
<> 144:ef7eb2e8f9f7 31 (#) The backup SRAM when the low power backup regulator is enabled
<> 144:ef7eb2e8f9f7 32 (#) PC13 to PC15 I/Os, plus PI8 I/O (when available)
<> 144:ef7eb2e8f9f7 33
<> 144:ef7eb2e8f9f7 34 [..] When the backup domain is supplied by VDD (analog switch connected to VDD),
<> 144:ef7eb2e8f9f7 35 the following pins are available:
<> 144:ef7eb2e8f9f7 36 (#) PC14 and PC15 can be used as either GPIO or LSE pins
<> 144:ef7eb2e8f9f7 37 (#) PC13 can be used as a GPIO or as the RTC_AF1 pin
<> 144:ef7eb2e8f9f7 38 (#) PI8 can be used as a GPIO or as the RTC_AF2 pin
<> 144:ef7eb2e8f9f7 39
<> 144:ef7eb2e8f9f7 40 [..] When the backup domain is supplied by VBAT (analog switch connected to VBAT
<> 144:ef7eb2e8f9f7 41 because VDD is not present), the following pins are available:
<> 144:ef7eb2e8f9f7 42 (#) PC14 and PC15 can be used as LSE pins only
<> 144:ef7eb2e8f9f7 43 (#) PC13 can be used as the RTC_AF1 pin
<> 144:ef7eb2e8f9f7 44 (#) PI8 can be used as the RTC_AF2 pin
<> 144:ef7eb2e8f9f7 45 (#) PC1 can be used as the RTC_AF3 pin
<> 144:ef7eb2e8f9f7 46
<> 144:ef7eb2e8f9f7 47 ##### Backup Domain Reset #####
<> 144:ef7eb2e8f9f7 48 ==================================================================
<> 144:ef7eb2e8f9f7 49 [..] The backup domain reset sets all RTC registers and the RCC_BDCR register
<> 144:ef7eb2e8f9f7 50 to their reset values. The BKPSRAM is not affected by this reset. The only
<> 144:ef7eb2e8f9f7 51 way to reset the BKPSRAM is through the Flash interface by requesting
<> 144:ef7eb2e8f9f7 52 a protection level change from 1 to 0.
<> 144:ef7eb2e8f9f7 53 [..] A backup domain reset is generated when one of the following events occurs:
<> 144:ef7eb2e8f9f7 54 (#) Software reset, triggered by setting the BDRST bit in the
<> 144:ef7eb2e8f9f7 55 RCC Backup domain control register (RCC_BDCR).
<> 144:ef7eb2e8f9f7 56 (#) VDD or VBAT power on, if both supplies have previously been powered off.
<> 144:ef7eb2e8f9f7 57
<> 144:ef7eb2e8f9f7 58 ##### Backup Domain Access #####
<> 144:ef7eb2e8f9f7 59 ==================================================================
<> 144:ef7eb2e8f9f7 60 [..] After reset, the backup domain (RTC registers, RTC backup data
<> 144:ef7eb2e8f9f7 61 registers and backup SRAM) is protected against possible unwanted write
<> 144:ef7eb2e8f9f7 62 accesses.
<> 144:ef7eb2e8f9f7 63 [..] To enable access to the RTC Domain and RTC registers, proceed as follows:
<> 144:ef7eb2e8f9f7 64 (+) Enable the Power Controller (PWR) APB1 interface clock using the
<> 144:ef7eb2e8f9f7 65 __HAL_RCC_PWR_CLK_ENABLE() function.
<> 144:ef7eb2e8f9f7 66 (+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function.
<> 144:ef7eb2e8f9f7 67 (+) Select the RTC clock source using the __HAL_RCC_RTC_CONFIG() function.
<> 144:ef7eb2e8f9f7 68 (+) Enable RTC Clock using the __HAL_RCC_RTC_ENABLE() function.
<> 144:ef7eb2e8f9f7 69
<> 144:ef7eb2e8f9f7 70
<> 144:ef7eb2e8f9f7 71 ##### How to use this driver #####
<> 144:ef7eb2e8f9f7 72 ==================================================================
<> 144:ef7eb2e8f9f7 73 [..]
<> 144:ef7eb2e8f9f7 74 (+) Enable the RTC domain access (see description in the section above).
<> 144:ef7eb2e8f9f7 75 (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour
<> 144:ef7eb2e8f9f7 76 format using the HAL_RTC_Init() function.
<> 144:ef7eb2e8f9f7 77
<> 144:ef7eb2e8f9f7 78 *** Time and Date configuration ***
<> 144:ef7eb2e8f9f7 79 ===================================
<> 144:ef7eb2e8f9f7 80 [..]
<> 144:ef7eb2e8f9f7 81 (+) To configure the RTC Calendar (Time and Date) use the HAL_RTC_SetTime()
<> 144:ef7eb2e8f9f7 82 and HAL_RTC_SetDate() functions.
<> 144:ef7eb2e8f9f7 83 (+) To read the RTC Calendar, use the HAL_RTC_GetTime() and HAL_RTC_GetDate() functions.
<> 144:ef7eb2e8f9f7 84
<> 144:ef7eb2e8f9f7 85 *** Alarm configuration ***
<> 144:ef7eb2e8f9f7 86 ===========================
<> 144:ef7eb2e8f9f7 87 [..]
<> 144:ef7eb2e8f9f7 88 (+) To configure the RTC Alarm use the HAL_RTC_SetAlarm() function.
<> 144:ef7eb2e8f9f7 89 You can also configure the RTC Alarm with interrupt mode using the HAL_RTC_SetAlarm_IT() function.
<> 144:ef7eb2e8f9f7 90 (+) To read the RTC Alarm, use the HAL_RTC_GetAlarm() function.
<> 144:ef7eb2e8f9f7 91
<> 144:ef7eb2e8f9f7 92 ##### RTC and low power modes #####
<> 144:ef7eb2e8f9f7 93 ==================================================================
<> 144:ef7eb2e8f9f7 94 [..] The MCU can be woken up from a low power mode by an RTC alternate
<> 144:ef7eb2e8f9f7 95 function.
<> 144:ef7eb2e8f9f7 96 [..] The RTC alternate functions are the RTC alarms (Alarm A and Alarm B),
<> 144:ef7eb2e8f9f7 97 RTC wakeup, RTC tamper event detection and RTC time stamp event detection.
<> 144:ef7eb2e8f9f7 98 These RTC alternate functions can wake up the system from the Stop and
<> 144:ef7eb2e8f9f7 99 Standby low power modes.
<> 144:ef7eb2e8f9f7 100 [..] The system can also wake up from low power modes without depending
<> 144:ef7eb2e8f9f7 101 on an external interrupt (Auto-wakeup mode), by using the RTC alarm
<> 144:ef7eb2e8f9f7 102 or the RTC wakeup events.
<> 144:ef7eb2e8f9f7 103 [..] The RTC provides a programmable time base for waking up from the
<> 144:ef7eb2e8f9f7 104 Stop or Standby mode at regular intervals.
<> 144:ef7eb2e8f9f7 105 Wakeup from STOP and STANDBY modes is possible only when the RTC clock source
<> 144:ef7eb2e8f9f7 106 is LSE or LSI.
<> 144:ef7eb2e8f9f7 107
<> 144:ef7eb2e8f9f7 108 @endverbatim
<> 144:ef7eb2e8f9f7 109 ******************************************************************************
<> 144:ef7eb2e8f9f7 110 * @attention
<> 144:ef7eb2e8f9f7 111 *
<> 144:ef7eb2e8f9f7 112 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
<> 144:ef7eb2e8f9f7 113 *
<> 144:ef7eb2e8f9f7 114 * Redistribution and use in source and binary forms, with or without modification,
<> 144:ef7eb2e8f9f7 115 * are permitted provided that the following conditions are met:
<> 144:ef7eb2e8f9f7 116 * 1. Redistributions of source code must retain the above copyright notice,
<> 144:ef7eb2e8f9f7 117 * this list of conditions and the following disclaimer.
<> 144:ef7eb2e8f9f7 118 * 2. Redistributions in binary form must reproduce the above copyright notice,
<> 144:ef7eb2e8f9f7 119 * this list of conditions and the following disclaimer in the documentation
<> 144:ef7eb2e8f9f7 120 * and/or other materials provided with the distribution.
<> 144:ef7eb2e8f9f7 121 * 3. Neither the name of STMicroelectronics nor the names of its contributors
<> 144:ef7eb2e8f9f7 122 * may be used to endorse or promote products derived from this software
<> 144:ef7eb2e8f9f7 123 * without specific prior written permission.
<> 144:ef7eb2e8f9f7 124 *
<> 144:ef7eb2e8f9f7 125 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
<> 144:ef7eb2e8f9f7 126 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
<> 144:ef7eb2e8f9f7 127 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
<> 144:ef7eb2e8f9f7 128 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
<> 144:ef7eb2e8f9f7 129 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
<> 144:ef7eb2e8f9f7 130 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
<> 144:ef7eb2e8f9f7 131 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
<> 144:ef7eb2e8f9f7 132 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
<> 144:ef7eb2e8f9f7 133 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
<> 144:ef7eb2e8f9f7 134 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<> 144:ef7eb2e8f9f7 135 *
<> 144:ef7eb2e8f9f7 136 ******************************************************************************
<> 144:ef7eb2e8f9f7 137 */
<> 144:ef7eb2e8f9f7 138
<> 144:ef7eb2e8f9f7 139 /* Includes ------------------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 140 #include "stm32f7xx_hal.h"
<> 144:ef7eb2e8f9f7 141
<> 144:ef7eb2e8f9f7 142 /** @addtogroup STM32F7xx_HAL_Driver
<> 144:ef7eb2e8f9f7 143 * @{
<> 144:ef7eb2e8f9f7 144 */
<> 144:ef7eb2e8f9f7 145
<> 144:ef7eb2e8f9f7 146 /** @defgroup RTC RTC
<> 144:ef7eb2e8f9f7 147 * @brief RTC HAL module driver
<> 144:ef7eb2e8f9f7 148 * @{
<> 144:ef7eb2e8f9f7 149 */
<> 144:ef7eb2e8f9f7 150
<> 144:ef7eb2e8f9f7 151 #ifdef HAL_RTC_MODULE_ENABLED
<> 144:ef7eb2e8f9f7 152
<> 144:ef7eb2e8f9f7 153 /* Private typedef -----------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 154 /* Private define ------------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 155 /* Private macro -------------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 156 /* Private variables ---------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 157 /* Private function prototypes -----------------------------------------------*/
<> 144:ef7eb2e8f9f7 158 /* Private functions ---------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 159
<> 144:ef7eb2e8f9f7 160 /** @defgroup RTC_Exported_Functions RTC Exported Functions
<> 144:ef7eb2e8f9f7 161 * @{
<> 144:ef7eb2e8f9f7 162 */
<> 144:ef7eb2e8f9f7 163
<> 144:ef7eb2e8f9f7 164 /** @defgroup RTC_Group1 Initialization and de-initialization functions
<> 144:ef7eb2e8f9f7 165 * @brief Initialization and Configuration functions
<> 144:ef7eb2e8f9f7 166 *
<> 144:ef7eb2e8f9f7 167 @verbatim
<> 144:ef7eb2e8f9f7 168 ===============================================================================
<> 144:ef7eb2e8f9f7 169 ##### Initialization and de-initialization functions #####
<> 144:ef7eb2e8f9f7 170 ===============================================================================
<> 144:ef7eb2e8f9f7 171 [..] This section provides functions allowing to initialize and configure the
<> 144:ef7eb2e8f9f7 172 RTC Prescaler (Synchronous and Asynchronous), RTC Hour format, disable
<> 144:ef7eb2e8f9f7 173 RTC registers Write protection, enter and exit the RTC initialization mode,
<> 144:ef7eb2e8f9f7 174 RTC registers synchronization check and reference clock detection enable.
<> 144:ef7eb2e8f9f7 175 (#) The RTC Prescaler is programmed to generate the RTC 1Hz time base.
<> 144:ef7eb2e8f9f7 176 It is split into 2 programmable prescalers to minimize power consumption.
<> 144:ef7eb2e8f9f7 177 (++) A 7-bit asynchronous prescaler and a 13-bit synchronous prescaler.
<> 144:ef7eb2e8f9f7 178 (++) When both prescalers are used, it is recommended to configure the
<> 144:ef7eb2e8f9f7 179 asynchronous prescaler to a high value to minimize power consumption.
<> 144:ef7eb2e8f9f7 180 (#) All RTC registers are Write protected. Writing to the RTC registers
<> 144:ef7eb2e8f9f7 181 is enabled by writing a key into the Write Protection register, RTC_WPR.
<> 144:ef7eb2e8f9f7 182 (#) To configure the RTC Calendar, user application should enter
<> 144:ef7eb2e8f9f7 183 initialization mode. In this mode, the calendar counter is stopped
<> 144:ef7eb2e8f9f7 184 and its value can be updated. When the initialization sequence is
<> 144:ef7eb2e8f9f7 185 complete, the calendar restarts counting after 4 RTCCLK cycles.
<> 144:ef7eb2e8f9f7 186 (#) To read the calendar through the shadow registers after Calendar
<> 144:ef7eb2e8f9f7 187 initialization, calendar update or after wakeup from low power modes
<> 144:ef7eb2e8f9f7 188 the software must first clear the RSF flag. The software must then
<> 144:ef7eb2e8f9f7 189 wait until it is set again before reading the calendar, which means
<> 144:ef7eb2e8f9f7 190 that the calendar registers have been correctly copied into the
<> 144:ef7eb2e8f9f7 191 RTC_TR and RTC_DR shadow registers.The HAL_RTC_WaitForSynchro() function
<> 144:ef7eb2e8f9f7 192 implements the above software sequence (RSF clear and RSF check).
<> 144:ef7eb2e8f9f7 193
<> 144:ef7eb2e8f9f7 194 @endverbatim
<> 144:ef7eb2e8f9f7 195 * @{
<> 144:ef7eb2e8f9f7 196 */
<> 144:ef7eb2e8f9f7 197
<> 144:ef7eb2e8f9f7 198 /**
<> 144:ef7eb2e8f9f7 199 * @brief Initializes the RTC peripheral
<> 144:ef7eb2e8f9f7 200 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
<> 144:ef7eb2e8f9f7 201 * the configuration information for RTC.
<> 144:ef7eb2e8f9f7 202 * @retval HAL status
<> 144:ef7eb2e8f9f7 203 */
<> 144:ef7eb2e8f9f7 204 HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc)
<> 144:ef7eb2e8f9f7 205 {
<> 144:ef7eb2e8f9f7 206 /* Check the RTC peripheral state */
<> 144:ef7eb2e8f9f7 207 if(hrtc == NULL)
<> 144:ef7eb2e8f9f7 208 {
<> 144:ef7eb2e8f9f7 209 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 210 }
<> 144:ef7eb2e8f9f7 211
<> 144:ef7eb2e8f9f7 212 /* Check the parameters */
<> 144:ef7eb2e8f9f7 213 assert_param(IS_RTC_ALL_INSTANCE(hrtc->Instance));
<> 144:ef7eb2e8f9f7 214 assert_param(IS_RTC_HOUR_FORMAT(hrtc->Init.HourFormat));
<> 144:ef7eb2e8f9f7 215 assert_param(IS_RTC_ASYNCH_PREDIV(hrtc->Init.AsynchPrediv));
<> 144:ef7eb2e8f9f7 216 assert_param(IS_RTC_SYNCH_PREDIV(hrtc->Init.SynchPrediv));
<> 144:ef7eb2e8f9f7 217 assert_param (IS_RTC_OUTPUT(hrtc->Init.OutPut));
<> 144:ef7eb2e8f9f7 218 assert_param (IS_RTC_OUTPUT_POL(hrtc->Init.OutPutPolarity));
<> 144:ef7eb2e8f9f7 219 assert_param(IS_RTC_OUTPUT_TYPE(hrtc->Init.OutPutType));
<> 144:ef7eb2e8f9f7 220
<> 144:ef7eb2e8f9f7 221 if(hrtc->State == HAL_RTC_STATE_RESET)
<> 144:ef7eb2e8f9f7 222 {
<> 144:ef7eb2e8f9f7 223 /* Allocate lock resource and initialize it */
<> 144:ef7eb2e8f9f7 224 hrtc->Lock = HAL_UNLOCKED;
<> 144:ef7eb2e8f9f7 225 /* Initialize RTC MSP */
<> 144:ef7eb2e8f9f7 226 HAL_RTC_MspInit(hrtc);
<> 144:ef7eb2e8f9f7 227 }
<> 144:ef7eb2e8f9f7 228
<> 144:ef7eb2e8f9f7 229 /* Set RTC state */
<> 144:ef7eb2e8f9f7 230 hrtc->State = HAL_RTC_STATE_BUSY;
<> 144:ef7eb2e8f9f7 231
<> 144:ef7eb2e8f9f7 232 /* Disable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 233 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
<> 144:ef7eb2e8f9f7 234
<> 144:ef7eb2e8f9f7 235 /* Set Initialization mode */
<> 144:ef7eb2e8f9f7 236 if(RTC_EnterInitMode(hrtc) != HAL_OK)
<> 144:ef7eb2e8f9f7 237 {
<> 144:ef7eb2e8f9f7 238 /* Enable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 239 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 240
<> 144:ef7eb2e8f9f7 241 /* Set RTC state */
<> 144:ef7eb2e8f9f7 242 hrtc->State = HAL_RTC_STATE_ERROR;
<> 144:ef7eb2e8f9f7 243
<> 144:ef7eb2e8f9f7 244 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 245 }
<> 144:ef7eb2e8f9f7 246 else
<> 144:ef7eb2e8f9f7 247 {
<> 144:ef7eb2e8f9f7 248 /* Clear RTC_CR FMT, OSEL and POL Bits */
<> 144:ef7eb2e8f9f7 249 hrtc->Instance->CR &= ((uint32_t)~(RTC_CR_FMT | RTC_CR_OSEL | RTC_CR_POL));
<> 144:ef7eb2e8f9f7 250 /* Set RTC_CR register */
<> 144:ef7eb2e8f9f7 251 hrtc->Instance->CR |= (uint32_t)(hrtc->Init.HourFormat | hrtc->Init.OutPut | hrtc->Init.OutPutPolarity);
<> 144:ef7eb2e8f9f7 252
<> 144:ef7eb2e8f9f7 253 /* Configure the RTC PRER */
<> 144:ef7eb2e8f9f7 254 hrtc->Instance->PRER = (uint32_t)(hrtc->Init.SynchPrediv);
<> 144:ef7eb2e8f9f7 255 hrtc->Instance->PRER |= (uint32_t)(hrtc->Init.AsynchPrediv << 16);
<> 144:ef7eb2e8f9f7 256
<> 144:ef7eb2e8f9f7 257 /* Exit Initialization mode */
<> 144:ef7eb2e8f9f7 258 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
<> 144:ef7eb2e8f9f7 259
<> 144:ef7eb2e8f9f7 260 hrtc->Instance->OR &= (uint32_t)~RTC_OR_ALARMTYPE;
<> 144:ef7eb2e8f9f7 261 hrtc->Instance->OR |= (uint32_t)(hrtc->Init.OutPutType);
<> 144:ef7eb2e8f9f7 262
<> 144:ef7eb2e8f9f7 263 /* Enable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 264 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 265
<> 144:ef7eb2e8f9f7 266 /* Set RTC state */
<> 144:ef7eb2e8f9f7 267 hrtc->State = HAL_RTC_STATE_READY;
<> 144:ef7eb2e8f9f7 268
<> 144:ef7eb2e8f9f7 269 return HAL_OK;
<> 144:ef7eb2e8f9f7 270 }
<> 144:ef7eb2e8f9f7 271 }
<> 144:ef7eb2e8f9f7 272
<> 144:ef7eb2e8f9f7 273 /**
<> 144:ef7eb2e8f9f7 274 * @brief DeInitializes the RTC peripheral
<> 144:ef7eb2e8f9f7 275 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
<> 144:ef7eb2e8f9f7 276 * the configuration information for RTC.
<> 144:ef7eb2e8f9f7 277 * @note This function doesn't reset the RTC Backup Data registers.
<> 144:ef7eb2e8f9f7 278 * @retval HAL status
<> 144:ef7eb2e8f9f7 279 */
<> 144:ef7eb2e8f9f7 280 HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc)
<> 144:ef7eb2e8f9f7 281 {
<> 144:ef7eb2e8f9f7 282 uint32_t tickstart = 0;
<> 144:ef7eb2e8f9f7 283
<> 144:ef7eb2e8f9f7 284 /* Check the parameters */
<> 144:ef7eb2e8f9f7 285 assert_param(IS_RTC_ALL_INSTANCE(hrtc->Instance));
<> 144:ef7eb2e8f9f7 286
<> 144:ef7eb2e8f9f7 287 /* Set RTC state */
<> 144:ef7eb2e8f9f7 288 hrtc->State = HAL_RTC_STATE_BUSY;
<> 144:ef7eb2e8f9f7 289
<> 144:ef7eb2e8f9f7 290 /* Disable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 291 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
<> 144:ef7eb2e8f9f7 292
<> 144:ef7eb2e8f9f7 293 /* Set Initialization mode */
<> 144:ef7eb2e8f9f7 294 if(RTC_EnterInitMode(hrtc) != HAL_OK)
<> 144:ef7eb2e8f9f7 295 {
<> 144:ef7eb2e8f9f7 296 /* Enable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 297 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 298
<> 144:ef7eb2e8f9f7 299 /* Set RTC state */
<> 144:ef7eb2e8f9f7 300 hrtc->State = HAL_RTC_STATE_ERROR;
<> 144:ef7eb2e8f9f7 301
<> 144:ef7eb2e8f9f7 302 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 303 }
<> 144:ef7eb2e8f9f7 304 else
<> 144:ef7eb2e8f9f7 305 {
<> 144:ef7eb2e8f9f7 306 /* Reset TR, DR and CR registers */
<> 144:ef7eb2e8f9f7 307 hrtc->Instance->TR = (uint32_t)0x00000000;
<> 144:ef7eb2e8f9f7 308 hrtc->Instance->DR = (uint32_t)0x00002101;
<> 144:ef7eb2e8f9f7 309 /* Reset All CR bits except CR[2:0] */
<> 144:ef7eb2e8f9f7 310 hrtc->Instance->CR &= (uint32_t)0x00000007;
<> 144:ef7eb2e8f9f7 311
<> 144:ef7eb2e8f9f7 312 /* Get tick */
<> 144:ef7eb2e8f9f7 313 tickstart = HAL_GetTick();
<> 144:ef7eb2e8f9f7 314
<> 144:ef7eb2e8f9f7 315 /* Wait till WUTWF flag is set and if Time out is reached exit */
<> 144:ef7eb2e8f9f7 316 while(((hrtc->Instance->ISR) & RTC_ISR_WUTWF) == (uint32_t)RESET)
<> 144:ef7eb2e8f9f7 317 {
<> 144:ef7eb2e8f9f7 318 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
<> 144:ef7eb2e8f9f7 319 {
<> 144:ef7eb2e8f9f7 320 /* Enable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 321 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 322
<> 144:ef7eb2e8f9f7 323 /* Set RTC state */
<> 144:ef7eb2e8f9f7 324 hrtc->State = HAL_RTC_STATE_TIMEOUT;
<> 144:ef7eb2e8f9f7 325
<> 144:ef7eb2e8f9f7 326 return HAL_TIMEOUT;
<> 144:ef7eb2e8f9f7 327 }
<> 144:ef7eb2e8f9f7 328 }
<> 144:ef7eb2e8f9f7 329
<> 144:ef7eb2e8f9f7 330 /* Reset all RTC CR register bits */
<> 144:ef7eb2e8f9f7 331 hrtc->Instance->CR &= (uint32_t)0x00000000;
<> 144:ef7eb2e8f9f7 332 hrtc->Instance->WUTR = (uint32_t)0x0000FFFF;
<> 144:ef7eb2e8f9f7 333 hrtc->Instance->PRER = (uint32_t)0x007F00FF;
<> 144:ef7eb2e8f9f7 334 hrtc->Instance->ALRMAR = (uint32_t)0x00000000;
<> 144:ef7eb2e8f9f7 335 hrtc->Instance->ALRMBR = (uint32_t)0x00000000;
<> 144:ef7eb2e8f9f7 336 hrtc->Instance->SHIFTR = (uint32_t)0x00000000;
<> 144:ef7eb2e8f9f7 337 hrtc->Instance->CALR = (uint32_t)0x00000000;
<> 144:ef7eb2e8f9f7 338 hrtc->Instance->ALRMASSR = (uint32_t)0x00000000;
<> 144:ef7eb2e8f9f7 339 hrtc->Instance->ALRMBSSR = (uint32_t)0x00000000;
<> 144:ef7eb2e8f9f7 340
<> 144:ef7eb2e8f9f7 341 /* Reset ISR register and exit initialization mode */
<> 144:ef7eb2e8f9f7 342 hrtc->Instance->ISR = (uint32_t)0x00000000;
<> 144:ef7eb2e8f9f7 343
<> 144:ef7eb2e8f9f7 344 /* Reset Tamper and alternate functions configuration register */
<> 144:ef7eb2e8f9f7 345 hrtc->Instance->TAMPCR = 0x00000000;
<> 144:ef7eb2e8f9f7 346
<> 144:ef7eb2e8f9f7 347 /* Reset Option register */
<> 144:ef7eb2e8f9f7 348 hrtc->Instance->OR = 0x00000000;
<> 144:ef7eb2e8f9f7 349
<> 144:ef7eb2e8f9f7 350 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
<> 144:ef7eb2e8f9f7 351 if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET)
<> 144:ef7eb2e8f9f7 352 {
<> 144:ef7eb2e8f9f7 353 if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
<> 144:ef7eb2e8f9f7 354 {
<> 144:ef7eb2e8f9f7 355 /* Enable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 356 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 357
<> 144:ef7eb2e8f9f7 358 hrtc->State = HAL_RTC_STATE_ERROR;
<> 144:ef7eb2e8f9f7 359
<> 144:ef7eb2e8f9f7 360 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 361 }
<> 144:ef7eb2e8f9f7 362 }
<> 144:ef7eb2e8f9f7 363 }
<> 144:ef7eb2e8f9f7 364
<> 144:ef7eb2e8f9f7 365 /* Enable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 366 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 367
<> 144:ef7eb2e8f9f7 368 /* De-Initialize RTC MSP */
<> 144:ef7eb2e8f9f7 369 HAL_RTC_MspDeInit(hrtc);
<> 144:ef7eb2e8f9f7 370
<> 144:ef7eb2e8f9f7 371 hrtc->State = HAL_RTC_STATE_RESET;
<> 144:ef7eb2e8f9f7 372
<> 144:ef7eb2e8f9f7 373 /* Release Lock */
<> 144:ef7eb2e8f9f7 374 __HAL_UNLOCK(hrtc);
<> 144:ef7eb2e8f9f7 375
<> 144:ef7eb2e8f9f7 376 return HAL_OK;
<> 144:ef7eb2e8f9f7 377 }
<> 144:ef7eb2e8f9f7 378
<> 144:ef7eb2e8f9f7 379 /**
<> 144:ef7eb2e8f9f7 380 * @brief Initializes the RTC MSP.
<> 144:ef7eb2e8f9f7 381 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
<> 144:ef7eb2e8f9f7 382 * the configuration information for RTC.
<> 144:ef7eb2e8f9f7 383 * @retval None
<> 144:ef7eb2e8f9f7 384 */
<> 144:ef7eb2e8f9f7 385 __weak void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
<> 144:ef7eb2e8f9f7 386 {
<> 144:ef7eb2e8f9f7 387 /* Prevent unused argument(s) compilation warning */
<> 144:ef7eb2e8f9f7 388 UNUSED(hrtc);
<> 144:ef7eb2e8f9f7 389
<> 144:ef7eb2e8f9f7 390 /* NOTE : This function Should not be modified, when the callback is needed,
<> 144:ef7eb2e8f9f7 391 the HAL_RTC_MspInit could be implemented in the user file
<> 144:ef7eb2e8f9f7 392 */
<> 144:ef7eb2e8f9f7 393 }
<> 144:ef7eb2e8f9f7 394
<> 144:ef7eb2e8f9f7 395 /**
<> 144:ef7eb2e8f9f7 396 * @brief DeInitializes the RTC MSP.
<> 144:ef7eb2e8f9f7 397 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
<> 144:ef7eb2e8f9f7 398 * the configuration information for RTC.
<> 144:ef7eb2e8f9f7 399 * @retval None
<> 144:ef7eb2e8f9f7 400 */
<> 144:ef7eb2e8f9f7 401 __weak void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
<> 144:ef7eb2e8f9f7 402 {
<> 144:ef7eb2e8f9f7 403 /* Prevent unused argument(s) compilation warning */
<> 144:ef7eb2e8f9f7 404 UNUSED(hrtc);
<> 144:ef7eb2e8f9f7 405
<> 144:ef7eb2e8f9f7 406 /* NOTE : This function Should not be modified, when the callback is needed,
<> 144:ef7eb2e8f9f7 407 the HAL_RTC_MspDeInit could be implemented in the user file
<> 144:ef7eb2e8f9f7 408 */
<> 144:ef7eb2e8f9f7 409 }
<> 144:ef7eb2e8f9f7 410
<> 144:ef7eb2e8f9f7 411 /**
<> 144:ef7eb2e8f9f7 412 * @}
<> 144:ef7eb2e8f9f7 413 */
<> 144:ef7eb2e8f9f7 414
<> 144:ef7eb2e8f9f7 415 /** @defgroup RTC_Group2 RTC Time and Date functions
<> 144:ef7eb2e8f9f7 416 * @brief RTC Time and Date functions
<> 144:ef7eb2e8f9f7 417 *
<> 144:ef7eb2e8f9f7 418 @verbatim
<> 144:ef7eb2e8f9f7 419 ===============================================================================
<> 144:ef7eb2e8f9f7 420 ##### RTC Time and Date functions #####
<> 144:ef7eb2e8f9f7 421 ===============================================================================
<> 144:ef7eb2e8f9f7 422
<> 144:ef7eb2e8f9f7 423 [..] This section provides functions allowing to configure Time and Date features
<> 144:ef7eb2e8f9f7 424
<> 144:ef7eb2e8f9f7 425 @endverbatim
<> 144:ef7eb2e8f9f7 426 * @{
<> 144:ef7eb2e8f9f7 427 */
<> 144:ef7eb2e8f9f7 428
<> 144:ef7eb2e8f9f7 429 /**
<> 144:ef7eb2e8f9f7 430 * @brief Sets RTC current time.
<> 144:ef7eb2e8f9f7 431 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
<> 144:ef7eb2e8f9f7 432 * the configuration information for RTC.
<> 144:ef7eb2e8f9f7 433 * @param sTime: Pointer to Time structure
<> 144:ef7eb2e8f9f7 434 * @param Format: Specifies the format of the entered parameters.
<> 144:ef7eb2e8f9f7 435 * This parameter can be one of the following values:
<> 144:ef7eb2e8f9f7 436 * @arg FORMAT_BIN: Binary data format
<> 144:ef7eb2e8f9f7 437 * @arg FORMAT_BCD: BCD data format
<> 144:ef7eb2e8f9f7 438 * @retval HAL status
<> 144:ef7eb2e8f9f7 439 */
<> 144:ef7eb2e8f9f7 440 HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format)
<> 144:ef7eb2e8f9f7 441 {
<> 144:ef7eb2e8f9f7 442 uint32_t tmpreg = 0;
<> 144:ef7eb2e8f9f7 443
<> 144:ef7eb2e8f9f7 444 /* Check the parameters */
<> 144:ef7eb2e8f9f7 445 assert_param(IS_RTC_FORMAT(Format));
<> 144:ef7eb2e8f9f7 446 assert_param(IS_RTC_DAYLIGHT_SAVING(sTime->DayLightSaving));
<> 144:ef7eb2e8f9f7 447 assert_param(IS_RTC_STORE_OPERATION(sTime->StoreOperation));
<> 144:ef7eb2e8f9f7 448
<> 144:ef7eb2e8f9f7 449 /* Process Locked */
<> 144:ef7eb2e8f9f7 450 __HAL_LOCK(hrtc);
<> 144:ef7eb2e8f9f7 451
<> 144:ef7eb2e8f9f7 452 hrtc->State = HAL_RTC_STATE_BUSY;
<> 144:ef7eb2e8f9f7 453
<> 144:ef7eb2e8f9f7 454 if(Format == RTC_FORMAT_BIN)
<> 144:ef7eb2e8f9f7 455 {
<> 144:ef7eb2e8f9f7 456 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
<> 144:ef7eb2e8f9f7 457 {
<> 144:ef7eb2e8f9f7 458 assert_param(IS_RTC_HOUR12(sTime->Hours));
<> 144:ef7eb2e8f9f7 459 assert_param(IS_RTC_HOURFORMAT12(sTime->TimeFormat));
<> 144:ef7eb2e8f9f7 460 }
<> 144:ef7eb2e8f9f7 461 else
<> 144:ef7eb2e8f9f7 462 {
<> 144:ef7eb2e8f9f7 463 sTime->TimeFormat = 0x00;
<> 144:ef7eb2e8f9f7 464 assert_param(IS_RTC_HOUR24(sTime->Hours));
<> 144:ef7eb2e8f9f7 465 }
<> 144:ef7eb2e8f9f7 466 assert_param(IS_RTC_MINUTES(sTime->Minutes));
<> 144:ef7eb2e8f9f7 467 assert_param(IS_RTC_SECONDS(sTime->Seconds));
<> 144:ef7eb2e8f9f7 468
<> 144:ef7eb2e8f9f7 469 tmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(sTime->Hours) << 16) | \
<> 144:ef7eb2e8f9f7 470 ((uint32_t)RTC_ByteToBcd2(sTime->Minutes) << 8) | \
<> 144:ef7eb2e8f9f7 471 ((uint32_t)RTC_ByteToBcd2(sTime->Seconds)) | \
<> 144:ef7eb2e8f9f7 472 (((uint32_t)sTime->TimeFormat) << 16));
<> 144:ef7eb2e8f9f7 473 }
<> 144:ef7eb2e8f9f7 474 else
<> 144:ef7eb2e8f9f7 475 {
<> 144:ef7eb2e8f9f7 476 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
<> 144:ef7eb2e8f9f7 477 {
<> 144:ef7eb2e8f9f7 478 tmpreg = RTC_Bcd2ToByte(sTime->Hours);
<> 144:ef7eb2e8f9f7 479 assert_param(IS_RTC_HOUR12(tmpreg));
<> 144:ef7eb2e8f9f7 480 assert_param(IS_RTC_HOURFORMAT12(sTime->TimeFormat));
<> 144:ef7eb2e8f9f7 481 }
<> 144:ef7eb2e8f9f7 482 else
<> 144:ef7eb2e8f9f7 483 {
<> 144:ef7eb2e8f9f7 484 sTime->TimeFormat = 0x00;
<> 144:ef7eb2e8f9f7 485 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sTime->Hours)));
<> 144:ef7eb2e8f9f7 486 }
<> 144:ef7eb2e8f9f7 487 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sTime->Minutes)));
<> 144:ef7eb2e8f9f7 488 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sTime->Seconds)));
<> 144:ef7eb2e8f9f7 489 tmpreg = (((uint32_t)(sTime->Hours) << 16) | \
<> 144:ef7eb2e8f9f7 490 ((uint32_t)(sTime->Minutes) << 8) | \
<> 144:ef7eb2e8f9f7 491 ((uint32_t)sTime->Seconds) | \
<> 144:ef7eb2e8f9f7 492 ((uint32_t)(sTime->TimeFormat) << 16));
<> 144:ef7eb2e8f9f7 493 }
<> 144:ef7eb2e8f9f7 494
<> 144:ef7eb2e8f9f7 495 /* Disable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 496 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
<> 144:ef7eb2e8f9f7 497
<> 144:ef7eb2e8f9f7 498 /* Set Initialization mode */
<> 144:ef7eb2e8f9f7 499 if(RTC_EnterInitMode(hrtc) != HAL_OK)
<> 144:ef7eb2e8f9f7 500 {
<> 144:ef7eb2e8f9f7 501 /* Enable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 502 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 503
<> 144:ef7eb2e8f9f7 504 /* Set RTC state */
<> 144:ef7eb2e8f9f7 505 hrtc->State = HAL_RTC_STATE_ERROR;
<> 144:ef7eb2e8f9f7 506
<> 144:ef7eb2e8f9f7 507 /* Process Unlocked */
<> 144:ef7eb2e8f9f7 508 __HAL_UNLOCK(hrtc);
<> 144:ef7eb2e8f9f7 509
<> 144:ef7eb2e8f9f7 510 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 511 }
<> 144:ef7eb2e8f9f7 512 else
<> 144:ef7eb2e8f9f7 513 {
<> 144:ef7eb2e8f9f7 514 /* Set the RTC_TR register */
<> 144:ef7eb2e8f9f7 515 hrtc->Instance->TR = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK);
<> 144:ef7eb2e8f9f7 516
<> 144:ef7eb2e8f9f7 517 /* Clear the bits to be configured */
<> 144:ef7eb2e8f9f7 518 hrtc->Instance->CR &= (uint32_t)~RTC_CR_BCK;
<> 144:ef7eb2e8f9f7 519
<> 144:ef7eb2e8f9f7 520 /* Configure the RTC_CR register */
<> 144:ef7eb2e8f9f7 521 hrtc->Instance->CR |= (uint32_t)(sTime->DayLightSaving | sTime->StoreOperation);
<> 144:ef7eb2e8f9f7 522
<> 144:ef7eb2e8f9f7 523 /* Exit Initialization mode */
<> 144:ef7eb2e8f9f7 524 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
<> 144:ef7eb2e8f9f7 525
<> 144:ef7eb2e8f9f7 526 /* If CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
<> 144:ef7eb2e8f9f7 527 if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET)
<> 144:ef7eb2e8f9f7 528 {
<> 144:ef7eb2e8f9f7 529 if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
<> 144:ef7eb2e8f9f7 530 {
<> 144:ef7eb2e8f9f7 531 /* Enable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 532 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 533
<> 144:ef7eb2e8f9f7 534 hrtc->State = HAL_RTC_STATE_ERROR;
<> 144:ef7eb2e8f9f7 535
<> 144:ef7eb2e8f9f7 536 /* Process Unlocked */
<> 144:ef7eb2e8f9f7 537 __HAL_UNLOCK(hrtc);
<> 144:ef7eb2e8f9f7 538
<> 144:ef7eb2e8f9f7 539 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 540 }
<> 144:ef7eb2e8f9f7 541 }
<> 144:ef7eb2e8f9f7 542
<> 144:ef7eb2e8f9f7 543 /* Enable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 544 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 545
<> 144:ef7eb2e8f9f7 546 hrtc->State = HAL_RTC_STATE_READY;
<> 144:ef7eb2e8f9f7 547
<> 144:ef7eb2e8f9f7 548 __HAL_UNLOCK(hrtc);
<> 144:ef7eb2e8f9f7 549
<> 144:ef7eb2e8f9f7 550 return HAL_OK;
<> 144:ef7eb2e8f9f7 551 }
<> 144:ef7eb2e8f9f7 552 }
<> 144:ef7eb2e8f9f7 553
<> 144:ef7eb2e8f9f7 554 /**
<> 144:ef7eb2e8f9f7 555 * @brief Gets RTC current time.
<> 144:ef7eb2e8f9f7 556 * @param hrtc: RTC handle
<> 144:ef7eb2e8f9f7 557 * @param sTime: Pointer to Time structure with Hours, Minutes and Seconds fields returned
<> 144:ef7eb2e8f9f7 558 * with input format (BIN or BCD), also SubSeconds field returning the
<> 144:ef7eb2e8f9f7 559 * RTC_SSR register content and SecondFraction field the Synchronous pre-scaler
<> 144:ef7eb2e8f9f7 560 * factor to be used for second fraction ratio computation.
<> 144:ef7eb2e8f9f7 561 * @param Format: Specifies the format of the entered parameters.
<> 144:ef7eb2e8f9f7 562 * This parameter can be one of the following values:
<> 144:ef7eb2e8f9f7 563 * @arg RTC_FORMAT_BIN: Binary data format
<> 144:ef7eb2e8f9f7 564 * @arg RTC_FORMAT_BCD: BCD data format
<> 144:ef7eb2e8f9f7 565 * @note You can use SubSeconds and SecondFraction (sTime structure fields returned) to convert SubSeconds
<> 144:ef7eb2e8f9f7 566 * value in second fraction ratio with time unit following generic formula:
<> 144:ef7eb2e8f9f7 567 * Second fraction ratio * time_unit= [(SecondFraction-SubSeconds)/(SecondFraction+1)] * time_unit
<> 144:ef7eb2e8f9f7 568 * This conversion can be performed only if no shift operation is pending (ie. SHFP=0) when PREDIV_S >= SS
<> 144:ef7eb2e8f9f7 569 * @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values
<> 144:ef7eb2e8f9f7 570 * in the higher-order calendar shadow registers to ensure consistency between the time and date values.
<> 144:ef7eb2e8f9f7 571 * Reading RTC current time locks the values in calendar shadow registers until Current date is read
<> 144:ef7eb2e8f9f7 572 * to ensure consistency between the time and date values.
<> 144:ef7eb2e8f9f7 573 * @retval HAL status
<> 144:ef7eb2e8f9f7 574 */
<> 144:ef7eb2e8f9f7 575 HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format)
<> 144:ef7eb2e8f9f7 576 {
<> 144:ef7eb2e8f9f7 577 uint32_t tmpreg = 0;
<> 144:ef7eb2e8f9f7 578
<> 144:ef7eb2e8f9f7 579 /* Check the parameters */
<> 144:ef7eb2e8f9f7 580 assert_param(IS_RTC_FORMAT(Format));
<> 144:ef7eb2e8f9f7 581
<> 144:ef7eb2e8f9f7 582 /* Get subseconds values from the correspondent registers*/
<> 144:ef7eb2e8f9f7 583 sTime->SubSeconds = (uint32_t)(hrtc->Instance->SSR);
<> 144:ef7eb2e8f9f7 584
<> 144:ef7eb2e8f9f7 585 /* Get SecondFraction structure field from the corresponding register field*/
<> 144:ef7eb2e8f9f7 586 sTime->SecondFraction = (uint32_t)(hrtc->Instance->PRER & RTC_PRER_PREDIV_S);
<> 144:ef7eb2e8f9f7 587
<> 144:ef7eb2e8f9f7 588 /* Get the TR register */
<> 144:ef7eb2e8f9f7 589 tmpreg = (uint32_t)(hrtc->Instance->TR & RTC_TR_RESERVED_MASK);
<> 144:ef7eb2e8f9f7 590
<> 144:ef7eb2e8f9f7 591 /* Fill the structure fields with the read parameters */
<> 144:ef7eb2e8f9f7 592 sTime->Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16);
<> 144:ef7eb2e8f9f7 593 sTime->Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >>8);
<> 144:ef7eb2e8f9f7 594 sTime->Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU));
<> 144:ef7eb2e8f9f7 595 sTime->TimeFormat = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16);
<> 144:ef7eb2e8f9f7 596
<> 144:ef7eb2e8f9f7 597 /* Check the input parameters format */
<> 144:ef7eb2e8f9f7 598 if(Format == RTC_FORMAT_BIN)
<> 144:ef7eb2e8f9f7 599 {
<> 144:ef7eb2e8f9f7 600 /* Convert the time structure parameters to Binary format */
<> 144:ef7eb2e8f9f7 601 sTime->Hours = (uint8_t)RTC_Bcd2ToByte(sTime->Hours);
<> 144:ef7eb2e8f9f7 602 sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes);
<> 144:ef7eb2e8f9f7 603 sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds);
<> 144:ef7eb2e8f9f7 604 }
<> 144:ef7eb2e8f9f7 605
<> 144:ef7eb2e8f9f7 606 return HAL_OK;
<> 144:ef7eb2e8f9f7 607 }
<> 144:ef7eb2e8f9f7 608
<> 144:ef7eb2e8f9f7 609 /**
<> 144:ef7eb2e8f9f7 610 * @brief Sets RTC current date.
<> 144:ef7eb2e8f9f7 611 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
<> 144:ef7eb2e8f9f7 612 * the configuration information for RTC.
<> 144:ef7eb2e8f9f7 613 * @param sDate: Pointer to date structure
<> 144:ef7eb2e8f9f7 614 * @param Format: specifies the format of the entered parameters.
<> 144:ef7eb2e8f9f7 615 * This parameter can be one of the following values:
<> 144:ef7eb2e8f9f7 616 * @arg RTC_FORMAT_BIN: Binary data format
<> 144:ef7eb2e8f9f7 617 * @arg RTC_FORMAT_BCD: BCD data format
<> 144:ef7eb2e8f9f7 618 * @retval HAL status
<> 144:ef7eb2e8f9f7 619 */
<> 144:ef7eb2e8f9f7 620 HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format)
<> 144:ef7eb2e8f9f7 621 {
<> 144:ef7eb2e8f9f7 622 uint32_t datetmpreg = 0;
<> 144:ef7eb2e8f9f7 623
<> 144:ef7eb2e8f9f7 624 /* Check the parameters */
<> 144:ef7eb2e8f9f7 625 assert_param(IS_RTC_FORMAT(Format));
<> 144:ef7eb2e8f9f7 626
<> 144:ef7eb2e8f9f7 627 /* Process Locked */
<> 144:ef7eb2e8f9f7 628 __HAL_LOCK(hrtc);
<> 144:ef7eb2e8f9f7 629
<> 144:ef7eb2e8f9f7 630 hrtc->State = HAL_RTC_STATE_BUSY;
<> 144:ef7eb2e8f9f7 631
<> 144:ef7eb2e8f9f7 632 if((Format == RTC_FORMAT_BIN) && ((sDate->Month & 0x10U) == 0x10U))
<> 144:ef7eb2e8f9f7 633 {
<> 144:ef7eb2e8f9f7 634 sDate->Month = (uint8_t)((sDate->Month & (uint8_t)~(0x10U)) + (uint8_t)0x0AU);
<> 144:ef7eb2e8f9f7 635 }
<> 144:ef7eb2e8f9f7 636
<> 144:ef7eb2e8f9f7 637 assert_param(IS_RTC_WEEKDAY(sDate->WeekDay));
<> 144:ef7eb2e8f9f7 638
<> 144:ef7eb2e8f9f7 639 if(Format == RTC_FORMAT_BIN)
<> 144:ef7eb2e8f9f7 640 {
<> 144:ef7eb2e8f9f7 641 assert_param(IS_RTC_YEAR(sDate->Year));
<> 144:ef7eb2e8f9f7 642 assert_param(IS_RTC_MONTH(sDate->Month));
<> 144:ef7eb2e8f9f7 643 assert_param(IS_RTC_DATE(sDate->Date));
<> 144:ef7eb2e8f9f7 644
<> 144:ef7eb2e8f9f7 645 datetmpreg = (((uint32_t)RTC_ByteToBcd2(sDate->Year) << 16) | \
<> 144:ef7eb2e8f9f7 646 ((uint32_t)RTC_ByteToBcd2(sDate->Month) << 8) | \
<> 144:ef7eb2e8f9f7 647 ((uint32_t)RTC_ByteToBcd2(sDate->Date)) | \
<> 144:ef7eb2e8f9f7 648 ((uint32_t)sDate->WeekDay << 13));
<> 144:ef7eb2e8f9f7 649 }
<> 144:ef7eb2e8f9f7 650 else
<> 144:ef7eb2e8f9f7 651 {
<> 144:ef7eb2e8f9f7 652 assert_param(IS_RTC_YEAR(RTC_Bcd2ToByte(sDate->Year)));
<> 144:ef7eb2e8f9f7 653 datetmpreg = RTC_Bcd2ToByte(sDate->Month);
<> 144:ef7eb2e8f9f7 654 assert_param(IS_RTC_MONTH(datetmpreg));
<> 144:ef7eb2e8f9f7 655 datetmpreg = RTC_Bcd2ToByte(sDate->Date);
<> 144:ef7eb2e8f9f7 656 assert_param(IS_RTC_DATE(datetmpreg));
<> 144:ef7eb2e8f9f7 657
<> 144:ef7eb2e8f9f7 658 datetmpreg = ((((uint32_t)sDate->Year) << 16) | \
<> 144:ef7eb2e8f9f7 659 (((uint32_t)sDate->Month) << 8) | \
<> 144:ef7eb2e8f9f7 660 ((uint32_t)sDate->Date) | \
<> 144:ef7eb2e8f9f7 661 (((uint32_t)sDate->WeekDay) << 13));
<> 144:ef7eb2e8f9f7 662 }
<> 144:ef7eb2e8f9f7 663
<> 144:ef7eb2e8f9f7 664 /* Disable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 665 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
<> 144:ef7eb2e8f9f7 666
<> 144:ef7eb2e8f9f7 667 /* Set Initialization mode */
<> 144:ef7eb2e8f9f7 668 if(RTC_EnterInitMode(hrtc) != HAL_OK)
<> 144:ef7eb2e8f9f7 669 {
<> 144:ef7eb2e8f9f7 670 /* Enable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 671 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 672
<> 144:ef7eb2e8f9f7 673 /* Set RTC state*/
<> 144:ef7eb2e8f9f7 674 hrtc->State = HAL_RTC_STATE_ERROR;
<> 144:ef7eb2e8f9f7 675
<> 144:ef7eb2e8f9f7 676 /* Process Unlocked */
<> 144:ef7eb2e8f9f7 677 __HAL_UNLOCK(hrtc);
<> 144:ef7eb2e8f9f7 678
<> 144:ef7eb2e8f9f7 679 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 680 }
<> 144:ef7eb2e8f9f7 681 else
<> 144:ef7eb2e8f9f7 682 {
<> 144:ef7eb2e8f9f7 683 /* Set the RTC_DR register */
<> 144:ef7eb2e8f9f7 684 hrtc->Instance->DR = (uint32_t)(datetmpreg & RTC_DR_RESERVED_MASK);
<> 144:ef7eb2e8f9f7 685
<> 144:ef7eb2e8f9f7 686 /* Exit Initialization mode */
<> 144:ef7eb2e8f9f7 687 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
<> 144:ef7eb2e8f9f7 688
<> 144:ef7eb2e8f9f7 689 /* If CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
<> 144:ef7eb2e8f9f7 690 if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET)
<> 144:ef7eb2e8f9f7 691 {
<> 144:ef7eb2e8f9f7 692 if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
<> 144:ef7eb2e8f9f7 693 {
<> 144:ef7eb2e8f9f7 694 /* Enable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 695 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 696
<> 144:ef7eb2e8f9f7 697 hrtc->State = HAL_RTC_STATE_ERROR;
<> 144:ef7eb2e8f9f7 698
<> 144:ef7eb2e8f9f7 699 /* Process Unlocked */
<> 144:ef7eb2e8f9f7 700 __HAL_UNLOCK(hrtc);
<> 144:ef7eb2e8f9f7 701
<> 144:ef7eb2e8f9f7 702 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 703 }
<> 144:ef7eb2e8f9f7 704 }
<> 144:ef7eb2e8f9f7 705
<> 144:ef7eb2e8f9f7 706 /* Enable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 707 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 708
<> 144:ef7eb2e8f9f7 709 hrtc->State = HAL_RTC_STATE_READY ;
<> 144:ef7eb2e8f9f7 710
<> 144:ef7eb2e8f9f7 711 /* Process Unlocked */
<> 144:ef7eb2e8f9f7 712 __HAL_UNLOCK(hrtc);
<> 144:ef7eb2e8f9f7 713
<> 144:ef7eb2e8f9f7 714 return HAL_OK;
<> 144:ef7eb2e8f9f7 715 }
<> 144:ef7eb2e8f9f7 716 }
<> 144:ef7eb2e8f9f7 717
<> 144:ef7eb2e8f9f7 718 /**
<> 144:ef7eb2e8f9f7 719 * @brief Gets RTC current date.
<> 144:ef7eb2e8f9f7 720 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
<> 144:ef7eb2e8f9f7 721 * the configuration information for RTC.
<> 144:ef7eb2e8f9f7 722 * @param sDate: Pointer to Date structure
<> 144:ef7eb2e8f9f7 723 * @param Format: Specifies the format of the entered parameters.
<> 144:ef7eb2e8f9f7 724 * This parameter can be one of the following values:
<> 144:ef7eb2e8f9f7 725 * @arg RTC_FORMAT_BIN: Binary data format
<> 144:ef7eb2e8f9f7 726 * @arg RTC_FORMAT_BCD: BCD data format
<> 144:ef7eb2e8f9f7 727 * @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values
<> 144:ef7eb2e8f9f7 728 * in the higher-order calendar shadow registers to ensure consistency between the time and date values.
<> 144:ef7eb2e8f9f7 729 * Reading RTC current time locks the values in calendar shadow registers until Current date is read.
<> 144:ef7eb2e8f9f7 730 * @retval HAL status
<> 144:ef7eb2e8f9f7 731 */
<> 144:ef7eb2e8f9f7 732 HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format)
<> 144:ef7eb2e8f9f7 733 {
<> 144:ef7eb2e8f9f7 734 uint32_t datetmpreg = 0;
<> 144:ef7eb2e8f9f7 735
<> 144:ef7eb2e8f9f7 736 /* Check the parameters */
<> 144:ef7eb2e8f9f7 737 assert_param(IS_RTC_FORMAT(Format));
<> 144:ef7eb2e8f9f7 738
<> 144:ef7eb2e8f9f7 739 /* Get the DR register */
<> 144:ef7eb2e8f9f7 740 datetmpreg = (uint32_t)(hrtc->Instance->DR & RTC_DR_RESERVED_MASK);
<> 144:ef7eb2e8f9f7 741
<> 144:ef7eb2e8f9f7 742 /* Fill the structure fields with the read parameters */
<> 144:ef7eb2e8f9f7 743 sDate->Year = (uint8_t)((datetmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16);
<> 144:ef7eb2e8f9f7 744 sDate->Month = (uint8_t)((datetmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8);
<> 144:ef7eb2e8f9f7 745 sDate->Date = (uint8_t)(datetmpreg & (RTC_DR_DT | RTC_DR_DU));
<> 144:ef7eb2e8f9f7 746 sDate->WeekDay = (uint8_t)((datetmpreg & (RTC_DR_WDU)) >> 13);
<> 144:ef7eb2e8f9f7 747
<> 144:ef7eb2e8f9f7 748 /* Check the input parameters format */
<> 144:ef7eb2e8f9f7 749 if(Format == RTC_FORMAT_BIN)
<> 144:ef7eb2e8f9f7 750 {
<> 144:ef7eb2e8f9f7 751 /* Convert the date structure parameters to Binary format */
<> 144:ef7eb2e8f9f7 752 sDate->Year = (uint8_t)RTC_Bcd2ToByte(sDate->Year);
<> 144:ef7eb2e8f9f7 753 sDate->Month = (uint8_t)RTC_Bcd2ToByte(sDate->Month);
<> 144:ef7eb2e8f9f7 754 sDate->Date = (uint8_t)RTC_Bcd2ToByte(sDate->Date);
<> 144:ef7eb2e8f9f7 755 }
<> 144:ef7eb2e8f9f7 756 return HAL_OK;
<> 144:ef7eb2e8f9f7 757 }
<> 144:ef7eb2e8f9f7 758
<> 144:ef7eb2e8f9f7 759 /**
<> 144:ef7eb2e8f9f7 760 * @}
<> 144:ef7eb2e8f9f7 761 */
<> 144:ef7eb2e8f9f7 762
<> 144:ef7eb2e8f9f7 763 /** @defgroup RTC_Group3 RTC Alarm functions
<> 144:ef7eb2e8f9f7 764 * @brief RTC Alarm functions
<> 144:ef7eb2e8f9f7 765 *
<> 144:ef7eb2e8f9f7 766 @verbatim
<> 144:ef7eb2e8f9f7 767 ===============================================================================
<> 144:ef7eb2e8f9f7 768 ##### RTC Alarm functions #####
<> 144:ef7eb2e8f9f7 769 ===============================================================================
<> 144:ef7eb2e8f9f7 770
<> 144:ef7eb2e8f9f7 771 [..] This section provides functions allowing to configure Alarm feature
<> 144:ef7eb2e8f9f7 772
<> 144:ef7eb2e8f9f7 773 @endverbatim
<> 144:ef7eb2e8f9f7 774 * @{
<> 144:ef7eb2e8f9f7 775 */
<> 144:ef7eb2e8f9f7 776 /**
<> 144:ef7eb2e8f9f7 777 * @brief Sets the specified RTC Alarm.
<> 144:ef7eb2e8f9f7 778 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
<> 144:ef7eb2e8f9f7 779 * the configuration information for RTC.
<> 144:ef7eb2e8f9f7 780 * @param sAlarm: Pointer to Alarm structure
<> 144:ef7eb2e8f9f7 781 * @param Format: Specifies the format of the entered parameters.
<> 144:ef7eb2e8f9f7 782 * This parameter can be one of the following values:
<> 144:ef7eb2e8f9f7 783 * @arg FORMAT_BIN: Binary data format
<> 144:ef7eb2e8f9f7 784 * @arg FORMAT_BCD: BCD data format
<> 144:ef7eb2e8f9f7 785 * @retval HAL status
<> 144:ef7eb2e8f9f7 786 */
<> 144:ef7eb2e8f9f7 787 HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format)
<> 144:ef7eb2e8f9f7 788 {
<> 144:ef7eb2e8f9f7 789 uint32_t tickstart = 0;
<> 144:ef7eb2e8f9f7 790 uint32_t tmpreg = 0, subsecondtmpreg = 0;
<> 144:ef7eb2e8f9f7 791
<> 144:ef7eb2e8f9f7 792 /* Check the parameters */
<> 144:ef7eb2e8f9f7 793 assert_param(IS_RTC_FORMAT(Format));
<> 144:ef7eb2e8f9f7 794 assert_param(IS_RTC_ALARM(sAlarm->Alarm));
<> 144:ef7eb2e8f9f7 795 assert_param(IS_RTC_ALARM_MASK(sAlarm->AlarmMask));
<> 144:ef7eb2e8f9f7 796 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel));
<> 144:ef7eb2e8f9f7 797 assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds));
<> 144:ef7eb2e8f9f7 798 assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask));
<> 144:ef7eb2e8f9f7 799
<> 144:ef7eb2e8f9f7 800 /* Process Locked */
<> 144:ef7eb2e8f9f7 801 __HAL_LOCK(hrtc);
<> 144:ef7eb2e8f9f7 802
<> 144:ef7eb2e8f9f7 803 hrtc->State = HAL_RTC_STATE_BUSY;
<> 144:ef7eb2e8f9f7 804
<> 144:ef7eb2e8f9f7 805 if(Format == RTC_FORMAT_BIN)
<> 144:ef7eb2e8f9f7 806 {
<> 144:ef7eb2e8f9f7 807 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
<> 144:ef7eb2e8f9f7 808 {
<> 144:ef7eb2e8f9f7 809 assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours));
<> 144:ef7eb2e8f9f7 810 assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
<> 144:ef7eb2e8f9f7 811 }
<> 144:ef7eb2e8f9f7 812 else
<> 144:ef7eb2e8f9f7 813 {
<> 144:ef7eb2e8f9f7 814 sAlarm->AlarmTime.TimeFormat = 0x00;
<> 144:ef7eb2e8f9f7 815 assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours));
<> 144:ef7eb2e8f9f7 816 }
<> 144:ef7eb2e8f9f7 817 assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes));
<> 144:ef7eb2e8f9f7 818 assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds));
<> 144:ef7eb2e8f9f7 819
<> 144:ef7eb2e8f9f7 820 if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
<> 144:ef7eb2e8f9f7 821 {
<> 144:ef7eb2e8f9f7 822 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay));
<> 144:ef7eb2e8f9f7 823 }
<> 144:ef7eb2e8f9f7 824 else
<> 144:ef7eb2e8f9f7 825 {
<> 144:ef7eb2e8f9f7 826 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay));
<> 144:ef7eb2e8f9f7 827 }
<> 144:ef7eb2e8f9f7 828
<> 144:ef7eb2e8f9f7 829 tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << 16) | \
<> 144:ef7eb2e8f9f7 830 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << 8) | \
<> 144:ef7eb2e8f9f7 831 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \
<> 144:ef7eb2e8f9f7 832 ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \
<> 144:ef7eb2e8f9f7 833 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << 24) | \
<> 144:ef7eb2e8f9f7 834 ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
<> 144:ef7eb2e8f9f7 835 ((uint32_t)sAlarm->AlarmMask));
<> 144:ef7eb2e8f9f7 836 }
<> 144:ef7eb2e8f9f7 837 else
<> 144:ef7eb2e8f9f7 838 {
<> 144:ef7eb2e8f9f7 839 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
<> 144:ef7eb2e8f9f7 840 {
<> 144:ef7eb2e8f9f7 841 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours);
<> 144:ef7eb2e8f9f7 842 assert_param(IS_RTC_HOUR12(tmpreg));
<> 144:ef7eb2e8f9f7 843 assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
<> 144:ef7eb2e8f9f7 844 }
<> 144:ef7eb2e8f9f7 845 else
<> 144:ef7eb2e8f9f7 846 {
<> 144:ef7eb2e8f9f7 847 sAlarm->AlarmTime.TimeFormat = 0x00;
<> 144:ef7eb2e8f9f7 848 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours)));
<> 144:ef7eb2e8f9f7 849 }
<> 144:ef7eb2e8f9f7 850
<> 144:ef7eb2e8f9f7 851 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes)));
<> 144:ef7eb2e8f9f7 852 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds)));
<> 144:ef7eb2e8f9f7 853
<> 144:ef7eb2e8f9f7 854 if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
<> 144:ef7eb2e8f9f7 855 {
<> 144:ef7eb2e8f9f7 856 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
<> 144:ef7eb2e8f9f7 857 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg));
<> 144:ef7eb2e8f9f7 858 }
<> 144:ef7eb2e8f9f7 859 else
<> 144:ef7eb2e8f9f7 860 {
<> 144:ef7eb2e8f9f7 861 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
<> 144:ef7eb2e8f9f7 862 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg));
<> 144:ef7eb2e8f9f7 863 }
<> 144:ef7eb2e8f9f7 864
<> 144:ef7eb2e8f9f7 865 tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << 16) | \
<> 144:ef7eb2e8f9f7 866 ((uint32_t)(sAlarm->AlarmTime.Minutes) << 8) | \
<> 144:ef7eb2e8f9f7 867 ((uint32_t) sAlarm->AlarmTime.Seconds) | \
<> 144:ef7eb2e8f9f7 868 ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \
<> 144:ef7eb2e8f9f7 869 ((uint32_t)(sAlarm->AlarmDateWeekDay) << 24) | \
<> 144:ef7eb2e8f9f7 870 ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
<> 144:ef7eb2e8f9f7 871 ((uint32_t)sAlarm->AlarmMask));
<> 144:ef7eb2e8f9f7 872 }
<> 144:ef7eb2e8f9f7 873
<> 144:ef7eb2e8f9f7 874 /* Configure the Alarm A or Alarm B Sub Second registers */
<> 144:ef7eb2e8f9f7 875 subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask));
<> 144:ef7eb2e8f9f7 876
<> 144:ef7eb2e8f9f7 877 /* Disable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 878 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
<> 144:ef7eb2e8f9f7 879
<> 144:ef7eb2e8f9f7 880 /* Configure the Alarm register */
<> 144:ef7eb2e8f9f7 881 if(sAlarm->Alarm == RTC_ALARM_A)
<> 144:ef7eb2e8f9f7 882 {
<> 144:ef7eb2e8f9f7 883 /* Disable the Alarm A interrupt */
<> 144:ef7eb2e8f9f7 884 __HAL_RTC_ALARMA_DISABLE(hrtc);
<> 144:ef7eb2e8f9f7 885
<> 144:ef7eb2e8f9f7 886 /* In case of interrupt mode is used, the interrupt source must disabled */
<> 144:ef7eb2e8f9f7 887 __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA);
<> 144:ef7eb2e8f9f7 888
<> 144:ef7eb2e8f9f7 889 /* Get tick */
<> 144:ef7eb2e8f9f7 890 tickstart = HAL_GetTick();
<> 144:ef7eb2e8f9f7 891
<> 144:ef7eb2e8f9f7 892 /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */
<> 144:ef7eb2e8f9f7 893 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET)
<> 144:ef7eb2e8f9f7 894 {
<> 144:ef7eb2e8f9f7 895 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
<> 144:ef7eb2e8f9f7 896 {
<> 144:ef7eb2e8f9f7 897 /* Enable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 898 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 899
<> 144:ef7eb2e8f9f7 900 hrtc->State = HAL_RTC_STATE_TIMEOUT;
<> 144:ef7eb2e8f9f7 901
<> 144:ef7eb2e8f9f7 902 /* Process Unlocked */
<> 144:ef7eb2e8f9f7 903 __HAL_UNLOCK(hrtc);
<> 144:ef7eb2e8f9f7 904
<> 144:ef7eb2e8f9f7 905 return HAL_TIMEOUT;
<> 144:ef7eb2e8f9f7 906 }
<> 144:ef7eb2e8f9f7 907 }
<> 144:ef7eb2e8f9f7 908
<> 144:ef7eb2e8f9f7 909 hrtc->Instance->ALRMAR = (uint32_t)tmpreg;
<> 144:ef7eb2e8f9f7 910 /* Configure the Alarm A Sub Second register */
<> 144:ef7eb2e8f9f7 911 hrtc->Instance->ALRMASSR = subsecondtmpreg;
<> 144:ef7eb2e8f9f7 912 /* Configure the Alarm state: Enable Alarm */
<> 144:ef7eb2e8f9f7 913 __HAL_RTC_ALARMA_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 914 }
<> 144:ef7eb2e8f9f7 915 else
<> 144:ef7eb2e8f9f7 916 {
<> 144:ef7eb2e8f9f7 917 /* Disable the Alarm B interrupt */
<> 144:ef7eb2e8f9f7 918 __HAL_RTC_ALARMB_DISABLE(hrtc);
<> 144:ef7eb2e8f9f7 919
<> 144:ef7eb2e8f9f7 920 /* In case of interrupt mode is used, the interrupt source must disabled */
<> 144:ef7eb2e8f9f7 921 __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRB);
<> 144:ef7eb2e8f9f7 922
<> 144:ef7eb2e8f9f7 923 /* Get tick */
<> 144:ef7eb2e8f9f7 924 tickstart = HAL_GetTick();
<> 144:ef7eb2e8f9f7 925
<> 144:ef7eb2e8f9f7 926 /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */
<> 144:ef7eb2e8f9f7 927 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET)
<> 144:ef7eb2e8f9f7 928 {
<> 144:ef7eb2e8f9f7 929 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
<> 144:ef7eb2e8f9f7 930 {
<> 144:ef7eb2e8f9f7 931 /* Enable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 932 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 933
<> 144:ef7eb2e8f9f7 934 hrtc->State = HAL_RTC_STATE_TIMEOUT;
<> 144:ef7eb2e8f9f7 935
<> 144:ef7eb2e8f9f7 936 /* Process Unlocked */
<> 144:ef7eb2e8f9f7 937 __HAL_UNLOCK(hrtc);
<> 144:ef7eb2e8f9f7 938
<> 144:ef7eb2e8f9f7 939 return HAL_TIMEOUT;
<> 144:ef7eb2e8f9f7 940 }
<> 144:ef7eb2e8f9f7 941 }
<> 144:ef7eb2e8f9f7 942
<> 144:ef7eb2e8f9f7 943 hrtc->Instance->ALRMBR = (uint32_t)tmpreg;
<> 144:ef7eb2e8f9f7 944 /* Configure the Alarm B Sub Second register */
<> 144:ef7eb2e8f9f7 945 hrtc->Instance->ALRMBSSR = subsecondtmpreg;
<> 144:ef7eb2e8f9f7 946 /* Configure the Alarm state: Enable Alarm */
<> 144:ef7eb2e8f9f7 947 __HAL_RTC_ALARMB_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 948 }
<> 144:ef7eb2e8f9f7 949
<> 144:ef7eb2e8f9f7 950 /* Enable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 951 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 952
<> 144:ef7eb2e8f9f7 953 /* Change RTC state */
<> 144:ef7eb2e8f9f7 954 hrtc->State = HAL_RTC_STATE_READY;
<> 144:ef7eb2e8f9f7 955
<> 144:ef7eb2e8f9f7 956 /* Process Unlocked */
<> 144:ef7eb2e8f9f7 957 __HAL_UNLOCK(hrtc);
<> 144:ef7eb2e8f9f7 958
<> 144:ef7eb2e8f9f7 959 return HAL_OK;
<> 144:ef7eb2e8f9f7 960 }
<> 144:ef7eb2e8f9f7 961
<> 144:ef7eb2e8f9f7 962 /**
<> 144:ef7eb2e8f9f7 963 * @brief Sets the specified RTC Alarm with Interrupt
<> 144:ef7eb2e8f9f7 964 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
<> 144:ef7eb2e8f9f7 965 * the configuration information for RTC.
<> 144:ef7eb2e8f9f7 966 * @param sAlarm: Pointer to Alarm structure
<> 144:ef7eb2e8f9f7 967 * @param Format: Specifies the format of the entered parameters.
<> 144:ef7eb2e8f9f7 968 * This parameter can be one of the following values:
<> 144:ef7eb2e8f9f7 969 * @arg FORMAT_BIN: Binary data format
<> 144:ef7eb2e8f9f7 970 * @arg FORMAT_BCD: BCD data format
<> 144:ef7eb2e8f9f7 971 * @note The Alarm register can only be written when the corresponding Alarm
<> 144:ef7eb2e8f9f7 972 * is disabled (Use the HAL_RTC_DeactivateAlarm()).
<> 144:ef7eb2e8f9f7 973 * @note The HAL_RTC_SetTime() must be called before enabling the Alarm feature.
<> 144:ef7eb2e8f9f7 974 * @retval HAL status
<> 144:ef7eb2e8f9f7 975 */
<> 144:ef7eb2e8f9f7 976 HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format)
<> 144:ef7eb2e8f9f7 977 {
<> 144:ef7eb2e8f9f7 978 uint32_t tickstart = 0;
<> 144:ef7eb2e8f9f7 979 uint32_t tmpreg = 0, subsecondtmpreg = 0;
<> 144:ef7eb2e8f9f7 980
<> 144:ef7eb2e8f9f7 981 /* Check the parameters */
<> 144:ef7eb2e8f9f7 982 assert_param(IS_RTC_FORMAT(Format));
<> 144:ef7eb2e8f9f7 983 assert_param(IS_RTC_ALARM(sAlarm->Alarm));
<> 144:ef7eb2e8f9f7 984 assert_param(IS_RTC_ALARM_MASK(sAlarm->AlarmMask));
<> 144:ef7eb2e8f9f7 985 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel));
<> 144:ef7eb2e8f9f7 986 assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds));
<> 144:ef7eb2e8f9f7 987 assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask));
<> 144:ef7eb2e8f9f7 988
<> 144:ef7eb2e8f9f7 989 /* Process Locked */
<> 144:ef7eb2e8f9f7 990 __HAL_LOCK(hrtc);
<> 144:ef7eb2e8f9f7 991
<> 144:ef7eb2e8f9f7 992 hrtc->State = HAL_RTC_STATE_BUSY;
<> 144:ef7eb2e8f9f7 993
<> 144:ef7eb2e8f9f7 994 if(Format == RTC_FORMAT_BIN)
<> 144:ef7eb2e8f9f7 995 {
<> 144:ef7eb2e8f9f7 996 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
<> 144:ef7eb2e8f9f7 997 {
<> 144:ef7eb2e8f9f7 998 assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours));
<> 144:ef7eb2e8f9f7 999 assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
<> 144:ef7eb2e8f9f7 1000 }
<> 144:ef7eb2e8f9f7 1001 else
<> 144:ef7eb2e8f9f7 1002 {
<> 144:ef7eb2e8f9f7 1003 sAlarm->AlarmTime.TimeFormat = 0x00;
<> 144:ef7eb2e8f9f7 1004 assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours));
<> 144:ef7eb2e8f9f7 1005 }
<> 144:ef7eb2e8f9f7 1006 assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes));
<> 144:ef7eb2e8f9f7 1007 assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds));
<> 144:ef7eb2e8f9f7 1008
<> 144:ef7eb2e8f9f7 1009 if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
<> 144:ef7eb2e8f9f7 1010 {
<> 144:ef7eb2e8f9f7 1011 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay));
<> 144:ef7eb2e8f9f7 1012 }
<> 144:ef7eb2e8f9f7 1013 else
<> 144:ef7eb2e8f9f7 1014 {
<> 144:ef7eb2e8f9f7 1015 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay));
<> 144:ef7eb2e8f9f7 1016 }
<> 144:ef7eb2e8f9f7 1017 tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << 16) | \
<> 144:ef7eb2e8f9f7 1018 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << 8) | \
<> 144:ef7eb2e8f9f7 1019 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \
<> 144:ef7eb2e8f9f7 1020 ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \
<> 144:ef7eb2e8f9f7 1021 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << 24) | \
<> 144:ef7eb2e8f9f7 1022 ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
<> 144:ef7eb2e8f9f7 1023 ((uint32_t)sAlarm->AlarmMask));
<> 144:ef7eb2e8f9f7 1024 }
<> 144:ef7eb2e8f9f7 1025 else
<> 144:ef7eb2e8f9f7 1026 {
<> 144:ef7eb2e8f9f7 1027 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
<> 144:ef7eb2e8f9f7 1028 {
<> 144:ef7eb2e8f9f7 1029 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours);
<> 144:ef7eb2e8f9f7 1030 assert_param(IS_RTC_HOUR12(tmpreg));
<> 144:ef7eb2e8f9f7 1031 assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
<> 144:ef7eb2e8f9f7 1032 }
<> 144:ef7eb2e8f9f7 1033 else
<> 144:ef7eb2e8f9f7 1034 {
<> 144:ef7eb2e8f9f7 1035 sAlarm->AlarmTime.TimeFormat = 0x00;
<> 144:ef7eb2e8f9f7 1036 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours)));
<> 144:ef7eb2e8f9f7 1037 }
<> 144:ef7eb2e8f9f7 1038
<> 144:ef7eb2e8f9f7 1039 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes)));
<> 144:ef7eb2e8f9f7 1040 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds)));
<> 144:ef7eb2e8f9f7 1041
<> 144:ef7eb2e8f9f7 1042 if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
<> 144:ef7eb2e8f9f7 1043 {
<> 144:ef7eb2e8f9f7 1044 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
<> 144:ef7eb2e8f9f7 1045 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg));
<> 144:ef7eb2e8f9f7 1046 }
<> 144:ef7eb2e8f9f7 1047 else
<> 144:ef7eb2e8f9f7 1048 {
<> 144:ef7eb2e8f9f7 1049 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
<> 144:ef7eb2e8f9f7 1050 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg));
<> 144:ef7eb2e8f9f7 1051 }
<> 144:ef7eb2e8f9f7 1052 tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << 16) | \
<> 144:ef7eb2e8f9f7 1053 ((uint32_t)(sAlarm->AlarmTime.Minutes) << 8) | \
<> 144:ef7eb2e8f9f7 1054 ((uint32_t) sAlarm->AlarmTime.Seconds) | \
<> 144:ef7eb2e8f9f7 1055 ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \
<> 144:ef7eb2e8f9f7 1056 ((uint32_t)(sAlarm->AlarmDateWeekDay) << 24) | \
<> 144:ef7eb2e8f9f7 1057 ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
<> 144:ef7eb2e8f9f7 1058 ((uint32_t)sAlarm->AlarmMask));
<> 144:ef7eb2e8f9f7 1059 }
<> 144:ef7eb2e8f9f7 1060 /* Configure the Alarm A or Alarm B Sub Second registers */
<> 144:ef7eb2e8f9f7 1061 subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask));
<> 144:ef7eb2e8f9f7 1062
<> 144:ef7eb2e8f9f7 1063 /* Disable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 1064 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
<> 144:ef7eb2e8f9f7 1065
<> 144:ef7eb2e8f9f7 1066 /* Configure the Alarm register */
<> 144:ef7eb2e8f9f7 1067 if(sAlarm->Alarm == RTC_ALARM_A)
<> 144:ef7eb2e8f9f7 1068 {
<> 144:ef7eb2e8f9f7 1069 /* Disable the Alarm A interrupt */
<> 144:ef7eb2e8f9f7 1070 __HAL_RTC_ALARMA_DISABLE(hrtc);
<> 144:ef7eb2e8f9f7 1071
<> 144:ef7eb2e8f9f7 1072 /* Clear flag alarm A */
<> 144:ef7eb2e8f9f7 1073 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);
<> 144:ef7eb2e8f9f7 1074
<> 144:ef7eb2e8f9f7 1075 /* Get tick */
<> 144:ef7eb2e8f9f7 1076 tickstart = HAL_GetTick();
<> 144:ef7eb2e8f9f7 1077
<> 144:ef7eb2e8f9f7 1078 /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */
<> 144:ef7eb2e8f9f7 1079 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET)
<> 144:ef7eb2e8f9f7 1080 {
<> 144:ef7eb2e8f9f7 1081 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
<> 144:ef7eb2e8f9f7 1082 {
<> 144:ef7eb2e8f9f7 1083 /* Enable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 1084 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 1085
<> 144:ef7eb2e8f9f7 1086 hrtc->State = HAL_RTC_STATE_TIMEOUT;
<> 144:ef7eb2e8f9f7 1087
<> 144:ef7eb2e8f9f7 1088 /* Process Unlocked */
<> 144:ef7eb2e8f9f7 1089 __HAL_UNLOCK(hrtc);
<> 144:ef7eb2e8f9f7 1090
<> 144:ef7eb2e8f9f7 1091 return HAL_TIMEOUT;
<> 144:ef7eb2e8f9f7 1092 }
<> 144:ef7eb2e8f9f7 1093 }
<> 144:ef7eb2e8f9f7 1094
<> 144:ef7eb2e8f9f7 1095 hrtc->Instance->ALRMAR = (uint32_t)tmpreg;
<> 144:ef7eb2e8f9f7 1096 /* Configure the Alarm A Sub Second register */
<> 144:ef7eb2e8f9f7 1097 hrtc->Instance->ALRMASSR = subsecondtmpreg;
<> 144:ef7eb2e8f9f7 1098 /* Configure the Alarm state: Enable Alarm */
<> 144:ef7eb2e8f9f7 1099 __HAL_RTC_ALARMA_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 1100 /* Configure the Alarm interrupt */
<> 144:ef7eb2e8f9f7 1101 __HAL_RTC_ALARM_ENABLE_IT(hrtc,RTC_IT_ALRA);
<> 144:ef7eb2e8f9f7 1102 }
<> 144:ef7eb2e8f9f7 1103 else
<> 144:ef7eb2e8f9f7 1104 {
<> 144:ef7eb2e8f9f7 1105 /* Disable the Alarm B interrupt */
<> 144:ef7eb2e8f9f7 1106 __HAL_RTC_ALARMB_DISABLE(hrtc);
<> 144:ef7eb2e8f9f7 1107
<> 144:ef7eb2e8f9f7 1108 /* Clear flag alarm B */
<> 144:ef7eb2e8f9f7 1109 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF);
<> 144:ef7eb2e8f9f7 1110
<> 144:ef7eb2e8f9f7 1111 /* Get tick */
<> 144:ef7eb2e8f9f7 1112 tickstart = HAL_GetTick();
<> 144:ef7eb2e8f9f7 1113
<> 144:ef7eb2e8f9f7 1114 /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */
<> 144:ef7eb2e8f9f7 1115 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET)
<> 144:ef7eb2e8f9f7 1116 {
<> 144:ef7eb2e8f9f7 1117 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
<> 144:ef7eb2e8f9f7 1118 {
<> 144:ef7eb2e8f9f7 1119 /* Enable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 1120 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 1121
<> 144:ef7eb2e8f9f7 1122 hrtc->State = HAL_RTC_STATE_TIMEOUT;
<> 144:ef7eb2e8f9f7 1123
<> 144:ef7eb2e8f9f7 1124 /* Process Unlocked */
<> 144:ef7eb2e8f9f7 1125 __HAL_UNLOCK(hrtc);
<> 144:ef7eb2e8f9f7 1126
<> 144:ef7eb2e8f9f7 1127 return HAL_TIMEOUT;
<> 144:ef7eb2e8f9f7 1128 }
<> 144:ef7eb2e8f9f7 1129 }
<> 144:ef7eb2e8f9f7 1130
<> 144:ef7eb2e8f9f7 1131 hrtc->Instance->ALRMBR = (uint32_t)tmpreg;
<> 144:ef7eb2e8f9f7 1132 /* Configure the Alarm B Sub Second register */
<> 144:ef7eb2e8f9f7 1133 hrtc->Instance->ALRMBSSR = subsecondtmpreg;
<> 144:ef7eb2e8f9f7 1134 /* Configure the Alarm state: Enable Alarm */
<> 144:ef7eb2e8f9f7 1135 __HAL_RTC_ALARMB_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 1136 /* Configure the Alarm interrupt */
<> 144:ef7eb2e8f9f7 1137 __HAL_RTC_ALARM_ENABLE_IT(hrtc, RTC_IT_ALRB);
<> 144:ef7eb2e8f9f7 1138 }
<> 144:ef7eb2e8f9f7 1139
<> 144:ef7eb2e8f9f7 1140 /* RTC Alarm Interrupt Configuration: EXTI configuration */
<> 144:ef7eb2e8f9f7 1141 __HAL_RTC_ALARM_EXTI_ENABLE_IT();
<> 144:ef7eb2e8f9f7 1142
<> 144:ef7eb2e8f9f7 1143 EXTI->RTSR |= RTC_EXTI_LINE_ALARM_EVENT;
<> 144:ef7eb2e8f9f7 1144
<> 144:ef7eb2e8f9f7 1145 /* Enable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 1146 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 1147
<> 144:ef7eb2e8f9f7 1148 hrtc->State = HAL_RTC_STATE_READY;
<> 144:ef7eb2e8f9f7 1149
<> 144:ef7eb2e8f9f7 1150 /* Process Unlocked */
<> 144:ef7eb2e8f9f7 1151 __HAL_UNLOCK(hrtc);
<> 144:ef7eb2e8f9f7 1152
<> 144:ef7eb2e8f9f7 1153 return HAL_OK;
<> 144:ef7eb2e8f9f7 1154 }
<> 144:ef7eb2e8f9f7 1155
<> 144:ef7eb2e8f9f7 1156 /**
<> 144:ef7eb2e8f9f7 1157 * @brief Deactive the specified RTC Alarm
<> 144:ef7eb2e8f9f7 1158 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
<> 144:ef7eb2e8f9f7 1159 * the configuration information for RTC.
<> 144:ef7eb2e8f9f7 1160 * @param Alarm: Specifies the Alarm.
<> 144:ef7eb2e8f9f7 1161 * This parameter can be one of the following values:
<> 144:ef7eb2e8f9f7 1162 * @arg RTC_ALARM_A: AlarmA
<> 144:ef7eb2e8f9f7 1163 * @arg RTC_ALARM_B: AlarmB
<> 144:ef7eb2e8f9f7 1164 * @retval HAL status
<> 144:ef7eb2e8f9f7 1165 */
<> 144:ef7eb2e8f9f7 1166 HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm)
<> 144:ef7eb2e8f9f7 1167 {
<> 144:ef7eb2e8f9f7 1168 uint32_t tickstart = 0;
<> 144:ef7eb2e8f9f7 1169
<> 144:ef7eb2e8f9f7 1170 /* Check the parameters */
<> 144:ef7eb2e8f9f7 1171 assert_param(IS_RTC_ALARM(Alarm));
<> 144:ef7eb2e8f9f7 1172
<> 144:ef7eb2e8f9f7 1173 /* Process Locked */
<> 144:ef7eb2e8f9f7 1174 __HAL_LOCK(hrtc);
<> 144:ef7eb2e8f9f7 1175
<> 144:ef7eb2e8f9f7 1176 hrtc->State = HAL_RTC_STATE_BUSY;
<> 144:ef7eb2e8f9f7 1177
<> 144:ef7eb2e8f9f7 1178 /* Disable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 1179 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
<> 144:ef7eb2e8f9f7 1180
<> 144:ef7eb2e8f9f7 1181 if(Alarm == RTC_ALARM_A)
<> 144:ef7eb2e8f9f7 1182 {
<> 144:ef7eb2e8f9f7 1183 /* AlarmA */
<> 144:ef7eb2e8f9f7 1184 __HAL_RTC_ALARMA_DISABLE(hrtc);
<> 144:ef7eb2e8f9f7 1185
<> 144:ef7eb2e8f9f7 1186 /* In case of interrupt mode is used, the interrupt source must disabled */
<> 144:ef7eb2e8f9f7 1187 __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA);
<> 144:ef7eb2e8f9f7 1188
<> 144:ef7eb2e8f9f7 1189 /* Get tick */
<> 144:ef7eb2e8f9f7 1190 tickstart = HAL_GetTick();
<> 144:ef7eb2e8f9f7 1191
<> 144:ef7eb2e8f9f7 1192 /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */
<> 144:ef7eb2e8f9f7 1193 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET)
<> 144:ef7eb2e8f9f7 1194 {
<> 144:ef7eb2e8f9f7 1195 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
<> 144:ef7eb2e8f9f7 1196 {
<> 144:ef7eb2e8f9f7 1197 /* Enable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 1198 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 1199
<> 144:ef7eb2e8f9f7 1200 hrtc->State = HAL_RTC_STATE_TIMEOUT;
<> 144:ef7eb2e8f9f7 1201
<> 144:ef7eb2e8f9f7 1202 /* Process Unlocked */
<> 144:ef7eb2e8f9f7 1203 __HAL_UNLOCK(hrtc);
<> 144:ef7eb2e8f9f7 1204
<> 144:ef7eb2e8f9f7 1205 return HAL_TIMEOUT;
<> 144:ef7eb2e8f9f7 1206 }
<> 144:ef7eb2e8f9f7 1207 }
<> 144:ef7eb2e8f9f7 1208 }
<> 144:ef7eb2e8f9f7 1209 else
<> 144:ef7eb2e8f9f7 1210 {
<> 144:ef7eb2e8f9f7 1211 /* AlarmB */
<> 144:ef7eb2e8f9f7 1212 __HAL_RTC_ALARMB_DISABLE(hrtc);
<> 144:ef7eb2e8f9f7 1213
<> 144:ef7eb2e8f9f7 1214 /* In case of interrupt mode is used, the interrupt source must disabled */
<> 144:ef7eb2e8f9f7 1215 __HAL_RTC_ALARM_DISABLE_IT(hrtc,RTC_IT_ALRB);
<> 144:ef7eb2e8f9f7 1216
<> 144:ef7eb2e8f9f7 1217 /* Get tick */
<> 144:ef7eb2e8f9f7 1218 tickstart = HAL_GetTick();
<> 144:ef7eb2e8f9f7 1219
<> 144:ef7eb2e8f9f7 1220 /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */
<> 144:ef7eb2e8f9f7 1221 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET)
<> 144:ef7eb2e8f9f7 1222 {
<> 144:ef7eb2e8f9f7 1223 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
<> 144:ef7eb2e8f9f7 1224 {
<> 144:ef7eb2e8f9f7 1225 /* Enable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 1226 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 1227
<> 144:ef7eb2e8f9f7 1228 hrtc->State = HAL_RTC_STATE_TIMEOUT;
<> 144:ef7eb2e8f9f7 1229
<> 144:ef7eb2e8f9f7 1230 /* Process Unlocked */
<> 144:ef7eb2e8f9f7 1231 __HAL_UNLOCK(hrtc);
<> 144:ef7eb2e8f9f7 1232
<> 144:ef7eb2e8f9f7 1233 return HAL_TIMEOUT;
<> 144:ef7eb2e8f9f7 1234 }
<> 144:ef7eb2e8f9f7 1235 }
<> 144:ef7eb2e8f9f7 1236 }
<> 144:ef7eb2e8f9f7 1237 /* Enable the write protection for RTC registers */
<> 144:ef7eb2e8f9f7 1238 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
<> 144:ef7eb2e8f9f7 1239
<> 144:ef7eb2e8f9f7 1240 hrtc->State = HAL_RTC_STATE_READY;
<> 144:ef7eb2e8f9f7 1241
<> 144:ef7eb2e8f9f7 1242 /* Process Unlocked */
<> 144:ef7eb2e8f9f7 1243 __HAL_UNLOCK(hrtc);
<> 144:ef7eb2e8f9f7 1244
<> 144:ef7eb2e8f9f7 1245 return HAL_OK;
<> 144:ef7eb2e8f9f7 1246 }
<> 144:ef7eb2e8f9f7 1247
<> 144:ef7eb2e8f9f7 1248 /**
<> 144:ef7eb2e8f9f7 1249 * @brief Gets the RTC Alarm value and masks.
<> 144:ef7eb2e8f9f7 1250 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
<> 144:ef7eb2e8f9f7 1251 * the configuration information for RTC.
<> 144:ef7eb2e8f9f7 1252 * @param sAlarm: Pointer to Date structure
<> 144:ef7eb2e8f9f7 1253 * @param Alarm: Specifies the Alarm.
<> 144:ef7eb2e8f9f7 1254 * This parameter can be one of the following values:
<> 144:ef7eb2e8f9f7 1255 * @arg RTC_ALARM_A: AlarmA
<> 144:ef7eb2e8f9f7 1256 * @arg RTC_ALARM_B: AlarmB
<> 144:ef7eb2e8f9f7 1257 * @param Format: Specifies the format of the entered parameters.
<> 144:ef7eb2e8f9f7 1258 * This parameter can be one of the following values:
<> 144:ef7eb2e8f9f7 1259 * @arg RTC_FORMAT_BIN: Binary data format
<> 144:ef7eb2e8f9f7 1260 * @arg RTC_FORMAT_BCD: BCD data format
<> 144:ef7eb2e8f9f7 1261 * @retval HAL status
<> 144:ef7eb2e8f9f7 1262 */
<> 144:ef7eb2e8f9f7 1263 HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format)
<> 144:ef7eb2e8f9f7 1264 {
<> 144:ef7eb2e8f9f7 1265 uint32_t tmpreg = 0, subsecondtmpreg = 0;
<> 144:ef7eb2e8f9f7 1266
<> 144:ef7eb2e8f9f7 1267 /* Check the parameters */
<> 144:ef7eb2e8f9f7 1268 assert_param(IS_RTC_FORMAT(Format));
<> 144:ef7eb2e8f9f7 1269 assert_param(IS_RTC_ALARM(Alarm));
<> 144:ef7eb2e8f9f7 1270
<> 144:ef7eb2e8f9f7 1271 if(Alarm == RTC_ALARM_A)
<> 144:ef7eb2e8f9f7 1272 {
<> 144:ef7eb2e8f9f7 1273 /* AlarmA */
<> 144:ef7eb2e8f9f7 1274 sAlarm->Alarm = RTC_ALARM_A;
<> 144:ef7eb2e8f9f7 1275
<> 144:ef7eb2e8f9f7 1276 tmpreg = (uint32_t)(hrtc->Instance->ALRMAR);
<> 144:ef7eb2e8f9f7 1277 subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMASSR ) & RTC_ALRMASSR_SS);
<> 144:ef7eb2e8f9f7 1278 }
<> 144:ef7eb2e8f9f7 1279 else
<> 144:ef7eb2e8f9f7 1280 {
<> 144:ef7eb2e8f9f7 1281 sAlarm->Alarm = RTC_ALARM_B;
<> 144:ef7eb2e8f9f7 1282
<> 144:ef7eb2e8f9f7 1283 tmpreg = (uint32_t)(hrtc->Instance->ALRMBR);
<> 144:ef7eb2e8f9f7 1284 subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMBSSR) & RTC_ALRMBSSR_SS);
<> 144:ef7eb2e8f9f7 1285 }
<> 144:ef7eb2e8f9f7 1286
<> 144:ef7eb2e8f9f7 1287 /* Fill the structure with the read parameters */
<> 144:ef7eb2e8f9f7 1288 sAlarm->AlarmTime.Hours = (uint32_t)((tmpreg & (RTC_ALRMAR_HT | RTC_ALRMAR_HU)) >> 16);
<> 144:ef7eb2e8f9f7 1289 sAlarm->AlarmTime.Minutes = (uint32_t)((tmpreg & (RTC_ALRMAR_MNT | RTC_ALRMAR_MNU)) >> 8);
<> 144:ef7eb2e8f9f7 1290 sAlarm->AlarmTime.Seconds = (uint32_t)(tmpreg & (RTC_ALRMAR_ST | RTC_ALRMAR_SU));
<> 144:ef7eb2e8f9f7 1291 sAlarm->AlarmTime.TimeFormat = (uint32_t)((tmpreg & RTC_ALRMAR_PM) >> 16);
<> 144:ef7eb2e8f9f7 1292 sAlarm->AlarmTime.SubSeconds = (uint32_t) subsecondtmpreg;
<> 144:ef7eb2e8f9f7 1293 sAlarm->AlarmDateWeekDay = (uint32_t)((tmpreg & (RTC_ALRMAR_DT | RTC_ALRMAR_DU)) >> 24);
<> 144:ef7eb2e8f9f7 1294 sAlarm->AlarmDateWeekDaySel = (uint32_t)(tmpreg & RTC_ALRMAR_WDSEL);
<> 144:ef7eb2e8f9f7 1295 sAlarm->AlarmMask = (uint32_t)(tmpreg & RTC_ALARMMASK_ALL);
<> 144:ef7eb2e8f9f7 1296
<> 144:ef7eb2e8f9f7 1297 if(Format == RTC_FORMAT_BIN)
<> 144:ef7eb2e8f9f7 1298 {
<> 144:ef7eb2e8f9f7 1299 sAlarm->AlarmTime.Hours = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours);
<> 144:ef7eb2e8f9f7 1300 sAlarm->AlarmTime.Minutes = RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes);
<> 144:ef7eb2e8f9f7 1301 sAlarm->AlarmTime.Seconds = RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds);
<> 144:ef7eb2e8f9f7 1302 sAlarm->AlarmDateWeekDay = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
<> 144:ef7eb2e8f9f7 1303 }
<> 144:ef7eb2e8f9f7 1304
<> 144:ef7eb2e8f9f7 1305 return HAL_OK;
<> 144:ef7eb2e8f9f7 1306 }
<> 144:ef7eb2e8f9f7 1307
<> 144:ef7eb2e8f9f7 1308 /**
<> 144:ef7eb2e8f9f7 1309 * @brief This function handles Alarm interrupt request.
<> 144:ef7eb2e8f9f7 1310 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
<> 144:ef7eb2e8f9f7 1311 * the configuration information for RTC.
<> 144:ef7eb2e8f9f7 1312 * @retval None
<> 144:ef7eb2e8f9f7 1313 */
<> 144:ef7eb2e8f9f7 1314 void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef* hrtc)
<> 144:ef7eb2e8f9f7 1315 {
<> 144:ef7eb2e8f9f7 1316 if(__HAL_RTC_ALARM_GET_IT(hrtc, RTC_IT_ALRA))
<> 144:ef7eb2e8f9f7 1317 {
<> 144:ef7eb2e8f9f7 1318 /* Get the status of the Interrupt */
<> 144:ef7eb2e8f9f7 1319 if((uint32_t)(hrtc->Instance->CR & RTC_IT_ALRA) != (uint32_t)RESET)
<> 144:ef7eb2e8f9f7 1320 {
<> 144:ef7eb2e8f9f7 1321 /* AlarmA callback */
<> 144:ef7eb2e8f9f7 1322 HAL_RTC_AlarmAEventCallback(hrtc);
<> 144:ef7eb2e8f9f7 1323
<> 144:ef7eb2e8f9f7 1324 /* Clear the Alarm interrupt pending bit */
<> 144:ef7eb2e8f9f7 1325 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc,RTC_FLAG_ALRAF);
<> 144:ef7eb2e8f9f7 1326 }
<> 144:ef7eb2e8f9f7 1327 }
<> 144:ef7eb2e8f9f7 1328
<> 144:ef7eb2e8f9f7 1329 if(__HAL_RTC_ALARM_GET_IT(hrtc, RTC_IT_ALRB))
<> 144:ef7eb2e8f9f7 1330 {
<> 144:ef7eb2e8f9f7 1331 /* Get the status of the Interrupt */
<> 144:ef7eb2e8f9f7 1332 if((uint32_t)(hrtc->Instance->CR & RTC_IT_ALRB) != (uint32_t)RESET)
<> 144:ef7eb2e8f9f7 1333 {
<> 144:ef7eb2e8f9f7 1334 /* AlarmB callback */
<> 144:ef7eb2e8f9f7 1335 HAL_RTCEx_AlarmBEventCallback(hrtc);
<> 144:ef7eb2e8f9f7 1336
<> 144:ef7eb2e8f9f7 1337 /* Clear the Alarm interrupt pending bit */
<> 144:ef7eb2e8f9f7 1338 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc,RTC_FLAG_ALRBF);
<> 144:ef7eb2e8f9f7 1339 }
<> 144:ef7eb2e8f9f7 1340 }
<> 144:ef7eb2e8f9f7 1341
<> 144:ef7eb2e8f9f7 1342 /* Clear the EXTI's line Flag for RTC Alarm */
<> 144:ef7eb2e8f9f7 1343 __HAL_RTC_ALARM_EXTI_CLEAR_FLAG();
<> 144:ef7eb2e8f9f7 1344
<> 144:ef7eb2e8f9f7 1345 /* Change RTC state */
<> 144:ef7eb2e8f9f7 1346 hrtc->State = HAL_RTC_STATE_READY;
<> 144:ef7eb2e8f9f7 1347 }
<> 144:ef7eb2e8f9f7 1348
<> 144:ef7eb2e8f9f7 1349 /**
<> 144:ef7eb2e8f9f7 1350 * @brief Alarm A callback.
<> 144:ef7eb2e8f9f7 1351 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
<> 144:ef7eb2e8f9f7 1352 * the configuration information for RTC.
<> 144:ef7eb2e8f9f7 1353 * @retval None
<> 144:ef7eb2e8f9f7 1354 */
<> 144:ef7eb2e8f9f7 1355 __weak void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
<> 144:ef7eb2e8f9f7 1356 {
<> 144:ef7eb2e8f9f7 1357 /* Prevent unused argument(s) compilation warning */
<> 144:ef7eb2e8f9f7 1358 UNUSED(hrtc);
<> 144:ef7eb2e8f9f7 1359
<> 144:ef7eb2e8f9f7 1360 /* NOTE : This function Should not be modified, when the callback is needed,
<> 144:ef7eb2e8f9f7 1361 the HAL_RTC_AlarmAEventCallback could be implemented in the user file
<> 144:ef7eb2e8f9f7 1362 */
<> 144:ef7eb2e8f9f7 1363 }
<> 144:ef7eb2e8f9f7 1364
<> 144:ef7eb2e8f9f7 1365 /**
<> 144:ef7eb2e8f9f7 1366 * @brief This function handles AlarmA Polling request.
<> 144:ef7eb2e8f9f7 1367 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
<> 144:ef7eb2e8f9f7 1368 * the configuration information for RTC.
<> 144:ef7eb2e8f9f7 1369 * @param Timeout: Timeout duration
<> 144:ef7eb2e8f9f7 1370 * @retval HAL status
<> 144:ef7eb2e8f9f7 1371 */
<> 144:ef7eb2e8f9f7 1372 HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
<> 144:ef7eb2e8f9f7 1373 {
<> 144:ef7eb2e8f9f7 1374 uint32_t tickstart = 0;
<> 144:ef7eb2e8f9f7 1375
<> 144:ef7eb2e8f9f7 1376 /* Get tick */
<> 144:ef7eb2e8f9f7 1377 tickstart = HAL_GetTick();
<> 144:ef7eb2e8f9f7 1378
<> 144:ef7eb2e8f9f7 1379 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAF) == RESET)
<> 144:ef7eb2e8f9f7 1380 {
<> 144:ef7eb2e8f9f7 1381 if(Timeout != HAL_MAX_DELAY)
<> 144:ef7eb2e8f9f7 1382 {
<> 144:ef7eb2e8f9f7 1383 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
<> 144:ef7eb2e8f9f7 1384 {
<> 144:ef7eb2e8f9f7 1385 hrtc->State = HAL_RTC_STATE_TIMEOUT;
<> 144:ef7eb2e8f9f7 1386 return HAL_TIMEOUT;
<> 144:ef7eb2e8f9f7 1387 }
<> 144:ef7eb2e8f9f7 1388 }
<> 144:ef7eb2e8f9f7 1389 }
<> 144:ef7eb2e8f9f7 1390
<> 144:ef7eb2e8f9f7 1391 /* Clear the Alarm interrupt pending bit */
<> 144:ef7eb2e8f9f7 1392 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);
<> 144:ef7eb2e8f9f7 1393
<> 144:ef7eb2e8f9f7 1394 /* Change RTC state */
<> 144:ef7eb2e8f9f7 1395 hrtc->State = HAL_RTC_STATE_READY;
<> 144:ef7eb2e8f9f7 1396
<> 144:ef7eb2e8f9f7 1397 return HAL_OK;
<> 144:ef7eb2e8f9f7 1398 }
<> 144:ef7eb2e8f9f7 1399
<> 144:ef7eb2e8f9f7 1400 /**
<> 144:ef7eb2e8f9f7 1401 * @}
<> 144:ef7eb2e8f9f7 1402 */
<> 144:ef7eb2e8f9f7 1403
<> 144:ef7eb2e8f9f7 1404 /** @defgroup RTC_Group4 Peripheral Control functions
<> 144:ef7eb2e8f9f7 1405 * @brief Peripheral Control functions
<> 144:ef7eb2e8f9f7 1406 *
<> 144:ef7eb2e8f9f7 1407 @verbatim
<> 144:ef7eb2e8f9f7 1408 ===============================================================================
<> 144:ef7eb2e8f9f7 1409 ##### Peripheral Control functions #####
<> 144:ef7eb2e8f9f7 1410 ===============================================================================
<> 144:ef7eb2e8f9f7 1411 [..]
<> 144:ef7eb2e8f9f7 1412 This subsection provides functions allowing to
<> 144:ef7eb2e8f9f7 1413 (+) Wait for RTC Time and Date Synchronization
<> 144:ef7eb2e8f9f7 1414
<> 144:ef7eb2e8f9f7 1415 @endverbatim
<> 144:ef7eb2e8f9f7 1416 * @{
<> 144:ef7eb2e8f9f7 1417 */
<> 144:ef7eb2e8f9f7 1418
<> 144:ef7eb2e8f9f7 1419 /**
<> 144:ef7eb2e8f9f7 1420 * @brief Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are
<> 144:ef7eb2e8f9f7 1421 * synchronized with RTC APB clock.
<> 144:ef7eb2e8f9f7 1422 * @note The RTC Resynchronization mode is write protected, use the
<> 144:ef7eb2e8f9f7 1423 * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function.
<> 144:ef7eb2e8f9f7 1424 * @note To read the calendar through the shadow registers after Calendar
<> 144:ef7eb2e8f9f7 1425 * initialization, calendar update or after wakeup from low power modes
<> 144:ef7eb2e8f9f7 1426 * the software must first clear the RSF flag.
<> 144:ef7eb2e8f9f7 1427 * The software must then wait until it is set again before reading
<> 144:ef7eb2e8f9f7 1428 * the calendar, which means that the calendar registers have been
<> 144:ef7eb2e8f9f7 1429 * correctly copied into the RTC_TR and RTC_DR shadow registers.
<> 144:ef7eb2e8f9f7 1430 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
<> 144:ef7eb2e8f9f7 1431 * the configuration information for RTC.
<> 144:ef7eb2e8f9f7 1432 * @retval HAL status
<> 144:ef7eb2e8f9f7 1433 */
<> 144:ef7eb2e8f9f7 1434 HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef* hrtc)
<> 144:ef7eb2e8f9f7 1435 {
<> 144:ef7eb2e8f9f7 1436 uint32_t tickstart = 0;
<> 144:ef7eb2e8f9f7 1437
<> 144:ef7eb2e8f9f7 1438 /* Clear RSF flag */
<> 144:ef7eb2e8f9f7 1439 hrtc->Instance->ISR &= (uint32_t)RTC_RSF_MASK;
<> 144:ef7eb2e8f9f7 1440
<> 144:ef7eb2e8f9f7 1441 /* Get tick */
<> 144:ef7eb2e8f9f7 1442 tickstart = HAL_GetTick();
<> 144:ef7eb2e8f9f7 1443
<> 144:ef7eb2e8f9f7 1444 /* Wait the registers to be synchronised */
<> 144:ef7eb2e8f9f7 1445 while((hrtc->Instance->ISR & RTC_ISR_RSF) == (uint32_t)RESET)
<> 144:ef7eb2e8f9f7 1446 {
<> 144:ef7eb2e8f9f7 1447 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
<> 144:ef7eb2e8f9f7 1448 {
<> 144:ef7eb2e8f9f7 1449 return HAL_TIMEOUT;
<> 144:ef7eb2e8f9f7 1450 }
<> 144:ef7eb2e8f9f7 1451 }
<> 144:ef7eb2e8f9f7 1452
<> 144:ef7eb2e8f9f7 1453 return HAL_OK;
<> 144:ef7eb2e8f9f7 1454 }
<> 144:ef7eb2e8f9f7 1455
<> 144:ef7eb2e8f9f7 1456 /**
<> 144:ef7eb2e8f9f7 1457 * @}
<> 144:ef7eb2e8f9f7 1458 */
<> 144:ef7eb2e8f9f7 1459
<> 144:ef7eb2e8f9f7 1460 /** @defgroup RTC_Group5 Peripheral State functions
<> 144:ef7eb2e8f9f7 1461 * @brief Peripheral State functions
<> 144:ef7eb2e8f9f7 1462 *
<> 144:ef7eb2e8f9f7 1463 @verbatim
<> 144:ef7eb2e8f9f7 1464 ===============================================================================
<> 144:ef7eb2e8f9f7 1465 ##### Peripheral State functions #####
<> 144:ef7eb2e8f9f7 1466 ===============================================================================
<> 144:ef7eb2e8f9f7 1467 [..]
<> 144:ef7eb2e8f9f7 1468 This subsection provides functions allowing to
<> 144:ef7eb2e8f9f7 1469 (+) Get RTC state
<> 144:ef7eb2e8f9f7 1470
<> 144:ef7eb2e8f9f7 1471 @endverbatim
<> 144:ef7eb2e8f9f7 1472 * @{
<> 144:ef7eb2e8f9f7 1473 */
<> 144:ef7eb2e8f9f7 1474 /**
<> 144:ef7eb2e8f9f7 1475 * @brief Returns the RTC state.
<> 144:ef7eb2e8f9f7 1476 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
<> 144:ef7eb2e8f9f7 1477 * the configuration information for RTC.
<> 144:ef7eb2e8f9f7 1478 * @retval HAL state
<> 144:ef7eb2e8f9f7 1479 */
<> 144:ef7eb2e8f9f7 1480 HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef* hrtc)
<> 144:ef7eb2e8f9f7 1481 {
<> 144:ef7eb2e8f9f7 1482 return hrtc->State;
<> 144:ef7eb2e8f9f7 1483 }
<> 144:ef7eb2e8f9f7 1484
<> 144:ef7eb2e8f9f7 1485 /**
<> 144:ef7eb2e8f9f7 1486 * @}
<> 144:ef7eb2e8f9f7 1487 */
<> 144:ef7eb2e8f9f7 1488
<> 144:ef7eb2e8f9f7 1489 /**
<> 144:ef7eb2e8f9f7 1490 * @brief Enters the RTC Initialization mode.
<> 144:ef7eb2e8f9f7 1491 * @note The RTC Initialization mode is write protected, use the
<> 144:ef7eb2e8f9f7 1492 * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function.
<> 144:ef7eb2e8f9f7 1493 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
<> 144:ef7eb2e8f9f7 1494 * the configuration information for RTC.
<> 144:ef7eb2e8f9f7 1495 * @retval HAL status
<> 144:ef7eb2e8f9f7 1496 */
<> 144:ef7eb2e8f9f7 1497 HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef* hrtc)
<> 144:ef7eb2e8f9f7 1498 {
<> 144:ef7eb2e8f9f7 1499 uint32_t tickstart = 0;
<> 144:ef7eb2e8f9f7 1500
<> 144:ef7eb2e8f9f7 1501 /* Check if the Initialization mode is set */
<> 144:ef7eb2e8f9f7 1502 if((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
<> 144:ef7eb2e8f9f7 1503 {
<> 144:ef7eb2e8f9f7 1504 /* Set the Initialization mode */
<> 144:ef7eb2e8f9f7 1505 hrtc->Instance->ISR = (uint32_t)RTC_INIT_MASK;
<> 144:ef7eb2e8f9f7 1506
<> 144:ef7eb2e8f9f7 1507 /* Get tick */
<> 144:ef7eb2e8f9f7 1508 tickstart = HAL_GetTick();
<> 144:ef7eb2e8f9f7 1509
<> 144:ef7eb2e8f9f7 1510 /* Wait till RTC is in INIT state and if Time out is reached exit */
<> 144:ef7eb2e8f9f7 1511 while((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
<> 144:ef7eb2e8f9f7 1512 {
<> 144:ef7eb2e8f9f7 1513 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
<> 144:ef7eb2e8f9f7 1514 {
<> 144:ef7eb2e8f9f7 1515 return HAL_TIMEOUT;
<> 144:ef7eb2e8f9f7 1516 }
<> 144:ef7eb2e8f9f7 1517 }
<> 144:ef7eb2e8f9f7 1518 }
<> 144:ef7eb2e8f9f7 1519
<> 144:ef7eb2e8f9f7 1520 return HAL_OK;
<> 144:ef7eb2e8f9f7 1521 }
<> 144:ef7eb2e8f9f7 1522
<> 144:ef7eb2e8f9f7 1523
<> 144:ef7eb2e8f9f7 1524 /**
<> 144:ef7eb2e8f9f7 1525 * @brief Converts a 2 digit decimal to BCD format.
<> 144:ef7eb2e8f9f7 1526 * @param Value: Byte to be converted
<> 144:ef7eb2e8f9f7 1527 * @retval Converted byte
<> 144:ef7eb2e8f9f7 1528 */
<> 144:ef7eb2e8f9f7 1529 uint8_t RTC_ByteToBcd2(uint8_t Value)
<> 144:ef7eb2e8f9f7 1530 {
<> 144:ef7eb2e8f9f7 1531 uint32_t bcdhigh = 0;
<> 144:ef7eb2e8f9f7 1532
<> 144:ef7eb2e8f9f7 1533 while(Value >= 10)
<> 144:ef7eb2e8f9f7 1534 {
<> 144:ef7eb2e8f9f7 1535 bcdhigh++;
<> 144:ef7eb2e8f9f7 1536 Value -= 10;
<> 144:ef7eb2e8f9f7 1537 }
<> 144:ef7eb2e8f9f7 1538
<> 144:ef7eb2e8f9f7 1539 return ((uint8_t)(bcdhigh << 4) | Value);
<> 144:ef7eb2e8f9f7 1540 }
<> 144:ef7eb2e8f9f7 1541
<> 144:ef7eb2e8f9f7 1542 /**
<> 144:ef7eb2e8f9f7 1543 * @brief Converts from 2 digit BCD to Binary.
<> 144:ef7eb2e8f9f7 1544 * @param Value: BCD value to be converted
<> 144:ef7eb2e8f9f7 1545 * @retval Converted word
<> 144:ef7eb2e8f9f7 1546 */
<> 144:ef7eb2e8f9f7 1547 uint8_t RTC_Bcd2ToByte(uint8_t Value)
<> 144:ef7eb2e8f9f7 1548 {
<> 144:ef7eb2e8f9f7 1549 uint32_t tmp = 0;
<> 144:ef7eb2e8f9f7 1550 tmp = ((uint8_t)(Value & (uint8_t)0xF0) >> (uint8_t)0x4) * 10;
<> 144:ef7eb2e8f9f7 1551 return (tmp + (Value & (uint8_t)0x0F));
<> 144:ef7eb2e8f9f7 1552 }
<> 144:ef7eb2e8f9f7 1553
<> 144:ef7eb2e8f9f7 1554 /**
<> 144:ef7eb2e8f9f7 1555 * @}
<> 144:ef7eb2e8f9f7 1556 */
<> 144:ef7eb2e8f9f7 1557
<> 144:ef7eb2e8f9f7 1558 #endif /* HAL_RTC_MODULE_ENABLED */
<> 144:ef7eb2e8f9f7 1559 /**
<> 144:ef7eb2e8f9f7 1560 * @}
<> 144:ef7eb2e8f9f7 1561 */
<> 144:ef7eb2e8f9f7 1562
<> 144:ef7eb2e8f9f7 1563 /**
<> 144:ef7eb2e8f9f7 1564 * @}
<> 144:ef7eb2e8f9f7 1565 */
<> 144:ef7eb2e8f9f7 1566
<> 144:ef7eb2e8f9f7 1567 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/