mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Wed Jul 01 09:45:11 2015 +0100
Revision:
579:53297373a894
Parent:
489:119543c9f674
Synchronized with git revision d5b4d2ab9c47edb4dc5776e7177b0c2263459081

Full URL: https://github.com/mbedmicro/mbed/commit/d5b4d2ab9c47edb4dc5776e7177b0c2263459081/

Initial version of drivers for SAMR21

Who changed what in which revision?

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