mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
shaoziyang
Date:
Sat Sep 13 14:25:46 2014 +0000
Revision:
323:9e901b0a5aa1
Parent:
130:1dec54e4aec3
test with CLOCK_SETUP = 0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 130:1dec54e4aec3 1 /**
mbed_official 130:1dec54e4aec3 2 ******************************************************************************
mbed_official 130:1dec54e4aec3 3 * @file stm32f0xx_rtc.c
mbed_official 130:1dec54e4aec3 4 * @author MCD Application Team
mbed_official 130:1dec54e4aec3 5 * @version V1.3.0
mbed_official 130:1dec54e4aec3 6 * @date 16-January-2014
mbed_official 130:1dec54e4aec3 7 * @brief This file provides firmware functions to manage the following
mbed_official 130:1dec54e4aec3 8 * functionalities of the Real-Time Clock (RTC) peripheral:
mbed_official 130:1dec54e4aec3 9 * + Initialization
mbed_official 130:1dec54e4aec3 10 * + Calendar (Time and Date) configuration
mbed_official 130:1dec54e4aec3 11 * + Alarms (Alarm A) configuration
mbed_official 130:1dec54e4aec3 12 * + Daylight Saving configuration
mbed_official 130:1dec54e4aec3 13 * + Output pin Configuration
mbed_official 130:1dec54e4aec3 14 * + Digital Calibration configuration
mbed_official 130:1dec54e4aec3 15 * + TimeStamp configuration
mbed_official 130:1dec54e4aec3 16 * + Tampers configuration
mbed_official 130:1dec54e4aec3 17 * + Backup Data Registers configuration
mbed_official 130:1dec54e4aec3 18 * + Output Type Config configuration
mbed_official 130:1dec54e4aec3 19 * + Shift control synchronisation
mbed_official 130:1dec54e4aec3 20 * + Interrupts and flags management
mbed_official 130:1dec54e4aec3 21 *
mbed_official 130:1dec54e4aec3 22 @verbatim
mbed_official 130:1dec54e4aec3 23 ===============================================================================
mbed_official 130:1dec54e4aec3 24 ##### Backup Domain Operating Condition #####
mbed_official 130:1dec54e4aec3 25 ===============================================================================
mbed_official 130:1dec54e4aec3 26 [..] The real-time clock (RTC) and the RTC backup registers can be powered
mbed_official 130:1dec54e4aec3 27 from the VBAT voltage when the main VDD supply is powered off.
mbed_official 130:1dec54e4aec3 28 To retain the content of the RTC backup registers and supply the RTC
mbed_official 130:1dec54e4aec3 29 when VDD is turned off, VBAT pin can be connected to an optional
mbed_official 130:1dec54e4aec3 30 standby voltage supplied by a battery or by another source.
mbed_official 130:1dec54e4aec3 31
mbed_official 130:1dec54e4aec3 32 [..] To allow the RTC to operate even when the main digital supply (VDD)
mbed_official 130:1dec54e4aec3 33 is turned off, the VBAT pin powers the following blocks:
mbed_official 130:1dec54e4aec3 34 (#) The RTC
mbed_official 130:1dec54e4aec3 35 (#) The LSE oscillator
mbed_official 130:1dec54e4aec3 36 (#) PC13 to PC15 I/Os I/Os (when available)
mbed_official 130:1dec54e4aec3 37
mbed_official 130:1dec54e4aec3 38 [..] When the backup domain is supplied by VDD (analog switch connected
mbed_official 130:1dec54e4aec3 39 to VDD), the following functions are available:
mbed_official 130:1dec54e4aec3 40 (#) PC14 and PC15 can be used as either GPIO or LSE pins
mbed_official 130:1dec54e4aec3 41 (#) PC13 can be used as a GPIO or as the RTC_AF1 pin
mbed_official 130:1dec54e4aec3 42
mbed_official 130:1dec54e4aec3 43 [..] When the backup domain is supplied by VBAT (analog switch connected
mbed_official 130:1dec54e4aec3 44 to VBAT because VDD is not present), the following functions are available:
mbed_official 130:1dec54e4aec3 45 (#) PC14 and PC15 can be used as LSE pins only
mbed_official 130:1dec54e4aec3 46 (#) PC13 can be used as the RTC_AF1 pin
mbed_official 130:1dec54e4aec3 47
mbed_official 130:1dec54e4aec3 48 ##### Backup Domain Reset #####
mbed_official 130:1dec54e4aec3 49 ===============================================================================
mbed_official 130:1dec54e4aec3 50 [..] The backup domain reset sets all RTC registers and the RCC_BDCR
mbed_official 130:1dec54e4aec3 51 register to their reset values.
mbed_official 130:1dec54e4aec3 52 A backup domain reset is generated when one of the following events
mbed_official 130:1dec54e4aec3 53 occurs:
mbed_official 130:1dec54e4aec3 54 (#) Software reset, triggered by setting the BDRST bit in the
mbed_official 130:1dec54e4aec3 55 RCC Backup domain control register (RCC_BDCR). You can use the
mbed_official 130:1dec54e4aec3 56 RCC_BackupResetCmd().
mbed_official 130:1dec54e4aec3 57 (#) VDD or VBAT power on, if both supplies have previously been
mbed_official 130:1dec54e4aec3 58 powered off.
mbed_official 130:1dec54e4aec3 59
mbed_official 130:1dec54e4aec3 60 ##### Backup Domain Access #####
mbed_official 130:1dec54e4aec3 61 ===============================================================================
mbed_official 130:1dec54e4aec3 62 [..] After reset, the backup domain (RTC registers and RTC backup data
mbed_official 130:1dec54e4aec3 63 registers) is protected against possible unwanted write accesses.
mbed_official 130:1dec54e4aec3 64 [..] To enable access to the Backup Domain and RTC registers, proceed as follows:
mbed_official 130:1dec54e4aec3 65 (#) Enable the Power Controller (PWR) APB1 interface clock using the
mbed_official 130:1dec54e4aec3 66 RCC_APB1PeriphClockCmd() function.
mbed_official 130:1dec54e4aec3 67 (#) Enable access to Backup domain using the PWR_BackupAccessCmd() function.
mbed_official 130:1dec54e4aec3 68 (#) Select the RTC clock source using the RCC_RTCCLKConfig() function.
mbed_official 130:1dec54e4aec3 69 (#) Enable RTC Clock using the RCC_RTCCLKCmd() function.
mbed_official 130:1dec54e4aec3 70
mbed_official 130:1dec54e4aec3 71
mbed_official 130:1dec54e4aec3 72 ##### How to use this driver #####
mbed_official 130:1dec54e4aec3 73 ===============================================================================
mbed_official 130:1dec54e4aec3 74 [..]
mbed_official 130:1dec54e4aec3 75 (+) Enable the backup domain access (see description in the section above)
mbed_official 130:1dec54e4aec3 76 (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and
mbed_official 130:1dec54e4aec3 77 RTC hour format using the RTC_Init() function.
mbed_official 130:1dec54e4aec3 78
mbed_official 130:1dec54e4aec3 79 ***Time and Date configuration ***
mbed_official 130:1dec54e4aec3 80 ==================================
mbed_official 130:1dec54e4aec3 81 [..]
mbed_official 130:1dec54e4aec3 82 (+) To configure the RTC Calendar (Time and Date) use the RTC_SetTime()
mbed_official 130:1dec54e4aec3 83 and RTC_SetDate() functions.
mbed_official 130:1dec54e4aec3 84 (+) To read the RTC Calendar, use the RTC_GetTime() and RTC_GetDate()
mbed_official 130:1dec54e4aec3 85 functions.
mbed_official 130:1dec54e4aec3 86 (+) To read the RTC subsecond, use the RTC_GetSubSecond() function.
mbed_official 130:1dec54e4aec3 87 (+) Use the RTC_DayLightSavingConfig() function to add or sub one
mbed_official 130:1dec54e4aec3 88 hour to the RTC Calendar.
mbed_official 130:1dec54e4aec3 89
mbed_official 130:1dec54e4aec3 90 ***Alarm configuration ***
mbed_official 130:1dec54e4aec3 91 ==========================
mbed_official 130:1dec54e4aec3 92 [..]
mbed_official 130:1dec54e4aec3 93 (+) To configure the RTC Alarm use the RTC_SetAlarm() function.
mbed_official 130:1dec54e4aec3 94 (+) Enable the selected RTC Alarm using the RTC_AlarmCmd() function
mbed_official 130:1dec54e4aec3 95 (+) To read the RTC Alarm, use the RTC_GetAlarm() function.
mbed_official 130:1dec54e4aec3 96 (+) To read the RTC alarm SubSecond, use the RTC_GetAlarmSubSecond() function.
mbed_official 130:1dec54e4aec3 97
mbed_official 130:1dec54e4aec3 98 ***RTC Wakeup configuration***
mbed_official 130:1dec54e4aec3 99 ==========================
mbed_official 130:1dec54e4aec3 100 [..]
mbed_official 130:1dec54e4aec3 101 (+) Configure the RTC Wakeup Clock source use the RTC_WakeUpClockConfig()
mbed_official 130:1dec54e4aec3 102 function.
mbed_official 130:1dec54e4aec3 103 (+) Configure the RTC WakeUp Counter using the RTC_SetWakeUpCounter()
mbed_official 130:1dec54e4aec3 104 function
mbed_official 130:1dec54e4aec3 105 (+) Enable the RTC WakeUp using the RTC_WakeUpCmd() function
mbed_official 130:1dec54e4aec3 106 (+) To read the RTC WakeUp Counter register, use the RTC_GetWakeUpCounter()
mbed_official 130:1dec54e4aec3 107 function.
mbed_official 130:1dec54e4aec3 108
mbed_official 130:1dec54e4aec3 109 ***Outputs configuration ***
mbed_official 130:1dec54e4aec3 110 ============================
mbed_official 130:1dec54e4aec3 111 [..] The RTC has 2 different outputs:
mbed_official 130:1dec54e4aec3 112 (+) AFO_ALARM: this output is used to manage the RTC Alarm A.
mbed_official 130:1dec54e4aec3 113 To output the selected RTC signal on RTC_AF1 pin, use the
mbed_official 130:1dec54e4aec3 114 RTC_OutputConfig() function.
mbed_official 130:1dec54e4aec3 115 (+) AFO_CALIB: this output is 512Hz signal or 1Hz .
mbed_official 130:1dec54e4aec3 116 To output the RTC Clock on RTC_AF1 pin, use the RTC_CalibOutputCmd()
mbed_official 130:1dec54e4aec3 117 function.
mbed_official 130:1dec54e4aec3 118
mbed_official 130:1dec54e4aec3 119 ***Original Digital Calibration configuration ***
mbed_official 130:1dec54e4aec3 120 =================================
mbed_official 130:1dec54e4aec3 121 [..] Configure the RTC Original Digital Calibration Value and the corresponding
mbed_official 130:1dec54e4aec3 122 calibration cycle period (32s,16s and 8s) using the RTC_SmoothCalibConfig()
mbed_official 130:1dec54e4aec3 123 function.
mbed_official 130:1dec54e4aec3 124
mbed_official 130:1dec54e4aec3 125 ***TimeStamp configuration ***
mbed_official 130:1dec54e4aec3 126 ==============================
mbed_official 130:1dec54e4aec3 127 [..]
mbed_official 130:1dec54e4aec3 128 (+) Configure the RTC_AF1 trigger and enables the RTC TimeStamp
mbed_official 130:1dec54e4aec3 129 using the RTC_TimeStampCmd() function.
mbed_official 130:1dec54e4aec3 130 (+) To read the RTC TimeStamp Time and Date register, use the
mbed_official 130:1dec54e4aec3 131 RTC_GetTimeStamp() function.
mbed_official 130:1dec54e4aec3 132 (+) To read the RTC TimeStamp SubSecond register, use the
mbed_official 130:1dec54e4aec3 133 RTC_GetTimeStampSubSecond() function.
mbed_official 130:1dec54e4aec3 134
mbed_official 130:1dec54e4aec3 135 ***Tamper configuration ***
mbed_official 130:1dec54e4aec3 136 ===========================
mbed_official 130:1dec54e4aec3 137 [..]
mbed_official 130:1dec54e4aec3 138 (+) Configure the Tamper filter count using RTC_TamperFilterConfig()
mbed_official 130:1dec54e4aec3 139 function.
mbed_official 130:1dec54e4aec3 140 (+) Configure the RTC Tamper trigger Edge or Level according to the Tamper
mbed_official 130:1dec54e4aec3 141 filter (if equal to 0 Edge else Level) value using the RTC_TamperConfig() function
mbed_official 130:1dec54e4aec3 142 (+) Configure the Tamper sampling frequency using RTC_TamperSamplingFreqConfig()
mbed_official 130:1dec54e4aec3 143 function.
mbed_official 130:1dec54e4aec3 144 (+) Configure the Tamper precharge or discharge duration using
mbed_official 130:1dec54e4aec3 145 RTC_TamperPinsPrechargeDuration() function.
mbed_official 130:1dec54e4aec3 146 (+) Enable the Tamper Pull-UP using RTC_TamperPullUpDisableCmd() function.
mbed_official 130:1dec54e4aec3 147 (+) Enable the RTC Tamper using the RTC_TamperCmd() function.
mbed_official 130:1dec54e4aec3 148 (+) Enable the Time stamp on Tamper detection event using
mbed_official 130:1dec54e4aec3 149 RTC_TSOnTamperDetecCmd() function.
mbed_official 130:1dec54e4aec3 150
mbed_official 130:1dec54e4aec3 151 ***Backup Data Registers configuration ***
mbed_official 130:1dec54e4aec3 152 ==========================================
mbed_official 130:1dec54e4aec3 153 [..]
mbed_official 130:1dec54e4aec3 154 (+) To write to the RTC Backup Data registers, use the RTC_WriteBackupRegister()
mbed_official 130:1dec54e4aec3 155 function.
mbed_official 130:1dec54e4aec3 156 (+) To read the RTC Backup Data registers, use the RTC_ReadBackupRegister()
mbed_official 130:1dec54e4aec3 157 function.
mbed_official 130:1dec54e4aec3 158
mbed_official 130:1dec54e4aec3 159 ##### RTC and low power modes #####
mbed_official 130:1dec54e4aec3 160 ===============================================================================
mbed_official 130:1dec54e4aec3 161 [..] The MCU can be woken up from a low power mode by an RTC alternate
mbed_official 130:1dec54e4aec3 162 function.
mbed_official 130:1dec54e4aec3 163 [..] The RTC alternate functions are the RTC alarm (Alarm A), RTC tamper
mbed_official 130:1dec54e4aec3 164 event detection and RTC time stamp event detection.
mbed_official 130:1dec54e4aec3 165 These RTC alternate functions can wake up the system from the Stop
mbed_official 130:1dec54e4aec3 166 and Standby lowpower modes.
mbed_official 130:1dec54e4aec3 167 The system can also wake up from low power modes without depending
mbed_official 130:1dec54e4aec3 168 on an external interrupt (Auto-wakeup mode), by using the RTC alarm events.
mbed_official 130:1dec54e4aec3 169 [..] The RTC provides a programmable time base for waking up from the
mbed_official 130:1dec54e4aec3 170 Stop or Standby mode at regular intervals.
mbed_official 130:1dec54e4aec3 171 Wakeup from STOP and Standby modes is possible only when the RTC
mbed_official 130:1dec54e4aec3 172 clock source is LSE or LSI.
mbed_official 130:1dec54e4aec3 173
mbed_official 130:1dec54e4aec3 174 ##### Selection of RTC_AF1 alternate functions #####
mbed_official 130:1dec54e4aec3 175 ===============================================================================
mbed_official 130:1dec54e4aec3 176 [..] The RTC_AF1 pin (PC13) can be used for the following purposes:
mbed_official 130:1dec54e4aec3 177 (+) AFO_ALARM output
mbed_official 130:1dec54e4aec3 178 (+) AFO_CALIB output
mbed_official 130:1dec54e4aec3 179 (+) AFI_TAMPER
mbed_official 130:1dec54e4aec3 180 (+) AFI_TIMESTAMP
mbed_official 130:1dec54e4aec3 181
mbed_official 130:1dec54e4aec3 182 +------------------------------------------------------------------------------------------+
mbed_official 130:1dec54e4aec3 183 | Pin |AFO_ALARM |AFO_CALIB |AFI_TAMPER |AFI_TIMESTAMP | WKUP2 |ALARMOUTTYPE |
mbed_official 130:1dec54e4aec3 184 | configuration | ENABLED | ENABLED | ENABLED | ENABLED |ENABLED | AFO_ALARM |
mbed_official 130:1dec54e4aec3 185 | and function | | | | | |Configuration |
mbed_official 130:1dec54e4aec3 186 |-----------------|----------|----------|-----------|--------------|--------|--------------|
mbed_official 130:1dec54e4aec3 187 | Alarm out | | | | | Don't | |
mbed_official 130:1dec54e4aec3 188 | output OD | 1 | 0 |Don't care | Don't care | care | 0 |
mbed_official 130:1dec54e4aec3 189 |-----------------|----------|----------|-----------|--------------|--------|--------------|
mbed_official 130:1dec54e4aec3 190 | Alarm out | | | | | Don't | |
mbed_official 130:1dec54e4aec3 191 | output PP | 1 | 0 |Don't care | Don't care | care | 1 |
mbed_official 130:1dec54e4aec3 192 |-----------------|----------|----------|-----------|--------------|--------|--------------|
mbed_official 130:1dec54e4aec3 193 | Calibration out | | | | | Don't | |
mbed_official 130:1dec54e4aec3 194 | output PP | 0 | 1 |Don't care | Don't care | care | Don't care |
mbed_official 130:1dec54e4aec3 195 |-----------------|----------|----------|-----------|--------------|--------|--------------|
mbed_official 130:1dec54e4aec3 196 | TAMPER input | | | | | Don't | |
mbed_official 130:1dec54e4aec3 197 | floating | 0 | 0 | 1 | 0 | care | Don't care |
mbed_official 130:1dec54e4aec3 198 |-----------------|----------|----------|-----------|--------------|--------|--------------|
mbed_official 130:1dec54e4aec3 199 | TIMESTAMP and | | | | | Don't | |
mbed_official 130:1dec54e4aec3 200 | TAMPER input | 0 | 0 | 1 | 1 | care | Don't care |
mbed_official 130:1dec54e4aec3 201 | floating | | | | | | |
mbed_official 130:1dec54e4aec3 202 |-----------------|----------|----------|-----------|--------------|--------|--------------|
mbed_official 130:1dec54e4aec3 203 | TIMESTAMP input | | | | | Don't | |
mbed_official 130:1dec54e4aec3 204 | floating | 0 | 0 | 0 | 1 | care | Don't care |
mbed_official 130:1dec54e4aec3 205 |-----------------|----------|----------|-----------|--------------|--------|--------------|
mbed_official 130:1dec54e4aec3 206 | Wakeup Pin 2 | 0 | 0 | 0 | 0 | 1 | Don't care |
mbed_official 130:1dec54e4aec3 207 |-----------------|----------|----------|-----------|--------------|--------|--------------|
mbed_official 130:1dec54e4aec3 208 | Standard GPIO | 0 | 0 | 0 | 0 | 0 | Don't care |
mbed_official 130:1dec54e4aec3 209 +------------------------------------------------------------------------------------------+
mbed_official 130:1dec54e4aec3 210
mbed_official 130:1dec54e4aec3 211 @endverbatim
mbed_official 130:1dec54e4aec3 212
mbed_official 130:1dec54e4aec3 213 ******************************************************************************
mbed_official 130:1dec54e4aec3 214 * @attention
mbed_official 130:1dec54e4aec3 215 *
mbed_official 130:1dec54e4aec3 216 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 130:1dec54e4aec3 217 *
mbed_official 130:1dec54e4aec3 218 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 130:1dec54e4aec3 219 * are permitted provided that the following conditions are met:
mbed_official 130:1dec54e4aec3 220 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 130:1dec54e4aec3 221 * this list of conditions and the following disclaimer.
mbed_official 130:1dec54e4aec3 222 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 130:1dec54e4aec3 223 * this list of conditions and the following disclaimer in the documentation
mbed_official 130:1dec54e4aec3 224 * and/or other materials provided with the distribution.
mbed_official 130:1dec54e4aec3 225 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 130:1dec54e4aec3 226 * may be used to endorse or promote products derived from this software
mbed_official 130:1dec54e4aec3 227 * without specific prior written permission.
mbed_official 130:1dec54e4aec3 228 *
mbed_official 130:1dec54e4aec3 229 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 130:1dec54e4aec3 230 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 130:1dec54e4aec3 231 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 130:1dec54e4aec3 232 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 130:1dec54e4aec3 233 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 130:1dec54e4aec3 234 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 130:1dec54e4aec3 235 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 130:1dec54e4aec3 236 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 130:1dec54e4aec3 237 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 130:1dec54e4aec3 238 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 130:1dec54e4aec3 239 *
mbed_official 130:1dec54e4aec3 240 ******************************************************************************
mbed_official 130:1dec54e4aec3 241 */
mbed_official 130:1dec54e4aec3 242
mbed_official 130:1dec54e4aec3 243 /* Includes ------------------------------------------------------------------*/
mbed_official 130:1dec54e4aec3 244 #include "stm32f0xx_rtc.h"
mbed_official 130:1dec54e4aec3 245
mbed_official 130:1dec54e4aec3 246 /** @addtogroup STM32F0xx_StdPeriph_Driver
mbed_official 130:1dec54e4aec3 247 * @{
mbed_official 130:1dec54e4aec3 248 */
mbed_official 130:1dec54e4aec3 249
mbed_official 130:1dec54e4aec3 250 /** @defgroup RTC
mbed_official 130:1dec54e4aec3 251 * @brief RTC driver modules
mbed_official 130:1dec54e4aec3 252 * @{
mbed_official 130:1dec54e4aec3 253 */
mbed_official 130:1dec54e4aec3 254
mbed_official 130:1dec54e4aec3 255 /* Private typedef -----------------------------------------------------------*/
mbed_official 130:1dec54e4aec3 256 /* Private define ------------------------------------------------------------*/
mbed_official 130:1dec54e4aec3 257
mbed_official 130:1dec54e4aec3 258 /* Masks Definition */
mbed_official 130:1dec54e4aec3 259 #define RTC_TR_RESERVED_MASK ((uint32_t)0x007F7F7F)
mbed_official 130:1dec54e4aec3 260 #define RTC_DR_RESERVED_MASK ((uint32_t)0x00FFFF3F)
mbed_official 130:1dec54e4aec3 261 #define RTC_INIT_MASK ((uint32_t)0xFFFFFFFF)
mbed_official 130:1dec54e4aec3 262 #define RTC_RSF_MASK ((uint32_t)0xFFFFFF5F)
mbed_official 130:1dec54e4aec3 263 #define RTC_FLAGS_MASK ((uint32_t)(RTC_FLAG_TSOVF | RTC_FLAG_TSF | RTC_FLAG_ALRAF | \
mbed_official 130:1dec54e4aec3 264 RTC_FLAG_RSF | RTC_FLAG_INITS |RTC_FLAG_INITF | \
mbed_official 130:1dec54e4aec3 265 RTC_FLAG_TAMP1F | RTC_FLAG_TAMP2F | RTC_FLAG_RECALPF | \
mbed_official 130:1dec54e4aec3 266 RTC_FLAG_SHPF))
mbed_official 130:1dec54e4aec3 267
mbed_official 130:1dec54e4aec3 268 #define INITMODE_TIMEOUT ((uint32_t) 0x00004000)
mbed_official 130:1dec54e4aec3 269 #define SYNCHRO_TIMEOUT ((uint32_t) 0x00008000)
mbed_official 130:1dec54e4aec3 270 #define RECALPF_TIMEOUT ((uint32_t) 0x00001000)
mbed_official 130:1dec54e4aec3 271 #define SHPF_TIMEOUT ((uint32_t) 0x00001000)
mbed_official 130:1dec54e4aec3 272
mbed_official 130:1dec54e4aec3 273 /* Private macro -------------------------------------------------------------*/
mbed_official 130:1dec54e4aec3 274 /* Private variables ---------------------------------------------------------*/
mbed_official 130:1dec54e4aec3 275 /* Private function prototypes -----------------------------------------------*/
mbed_official 130:1dec54e4aec3 276 static uint8_t RTC_ByteToBcd2(uint8_t Value);
mbed_official 130:1dec54e4aec3 277 static uint8_t RTC_Bcd2ToByte(uint8_t Value);
mbed_official 130:1dec54e4aec3 278
mbed_official 130:1dec54e4aec3 279 /* Private functions ---------------------------------------------------------*/
mbed_official 130:1dec54e4aec3 280
mbed_official 130:1dec54e4aec3 281 /** @defgroup RTC_Private_Functions
mbed_official 130:1dec54e4aec3 282 * @{
mbed_official 130:1dec54e4aec3 283 */
mbed_official 130:1dec54e4aec3 284
mbed_official 130:1dec54e4aec3 285 /** @defgroup RTC_Group1 Initialization and Configuration functions
mbed_official 130:1dec54e4aec3 286 * @brief Initialization and Configuration functions
mbed_official 130:1dec54e4aec3 287 *
mbed_official 130:1dec54e4aec3 288 @verbatim
mbed_official 130:1dec54e4aec3 289 ===============================================================================
mbed_official 130:1dec54e4aec3 290 ##### Initialization and Configuration functions #####
mbed_official 130:1dec54e4aec3 291 ===============================================================================
mbed_official 130:1dec54e4aec3 292
mbed_official 130:1dec54e4aec3 293 [..] This section provide functions allowing to initialize and configure the RTC
mbed_official 130:1dec54e4aec3 294 Prescaler (Synchronous and Asynchronous), RTC Hour format, disable RTC registers
mbed_official 130:1dec54e4aec3 295 Write protection, enter and exit the RTC initialization mode, RTC registers
mbed_official 130:1dec54e4aec3 296 synchronization check and reference clock detection enable.
mbed_official 130:1dec54e4aec3 297
mbed_official 130:1dec54e4aec3 298 (#) The RTC Prescaler is programmed to generate the RTC 1Hz time base.
mbed_official 130:1dec54e4aec3 299 It is split into 2 programmable prescalers to minimize power consumption.
mbed_official 130:1dec54e4aec3 300 (++) A 7-bit asynchronous prescaler and A 13-bit synchronous prescaler.
mbed_official 130:1dec54e4aec3 301 (++) When both prescalers are used, it is recommended to configure the
mbed_official 130:1dec54e4aec3 302 asynchronous prescaler to a high value to minimize consumption.
mbed_official 130:1dec54e4aec3 303 (#) All RTC registers are Write protected. Writing to the RTC registers
mbed_official 130:1dec54e4aec3 304 is enabled by writing a key into the Write Protection register, RTC_WPR.
mbed_official 130:1dec54e4aec3 305 (#) To Configure the RTC Calendar, user application should enter
mbed_official 130:1dec54e4aec3 306 initialization mode. In this mode, the calendar counter is stopped
mbed_official 130:1dec54e4aec3 307 and its value can be updated. When the initialization sequence is
mbed_official 130:1dec54e4aec3 308 complete, the calendar restarts counting after 4 RTCCLK cycles.
mbed_official 130:1dec54e4aec3 309 (#) To read the calendar through the shadow registers after Calendar
mbed_official 130:1dec54e4aec3 310 initialization, calendar update or after wakeup from low power modes
mbed_official 130:1dec54e4aec3 311 the software must first clear the RSF flag. The software must then
mbed_official 130:1dec54e4aec3 312 wait until it is set again before reading the calendar, which means
mbed_official 130:1dec54e4aec3 313 that the calendar registers have been correctly copied into the
mbed_official 130:1dec54e4aec3 314 RTC_TR and RTC_DR shadow registers.The RTC_WaitForSynchro() function
mbed_official 130:1dec54e4aec3 315 implements the above software sequence (RSF clear and RSF check).
mbed_official 130:1dec54e4aec3 316
mbed_official 130:1dec54e4aec3 317 @endverbatim
mbed_official 130:1dec54e4aec3 318 * @{
mbed_official 130:1dec54e4aec3 319 */
mbed_official 130:1dec54e4aec3 320
mbed_official 130:1dec54e4aec3 321 /**
mbed_official 130:1dec54e4aec3 322 * @brief Deinitializes the RTC registers to their default reset values.
mbed_official 130:1dec54e4aec3 323 * @note This function doesn't reset the RTC Clock source and RTC Backup Data
mbed_official 130:1dec54e4aec3 324 * registers.
mbed_official 130:1dec54e4aec3 325 * @param None
mbed_official 130:1dec54e4aec3 326 * @retval An ErrorStatus enumeration value:
mbed_official 130:1dec54e4aec3 327 * - SUCCESS: RTC registers are deinitialized
mbed_official 130:1dec54e4aec3 328 * - ERROR: RTC registers are not deinitialized
mbed_official 130:1dec54e4aec3 329 */
mbed_official 130:1dec54e4aec3 330 ErrorStatus RTC_DeInit(void)
mbed_official 130:1dec54e4aec3 331 {
mbed_official 130:1dec54e4aec3 332 ErrorStatus status = ERROR;
mbed_official 130:1dec54e4aec3 333
mbed_official 130:1dec54e4aec3 334 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 335 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 336 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 337
mbed_official 130:1dec54e4aec3 338 /* Set Initialization mode */
mbed_official 130:1dec54e4aec3 339 if (RTC_EnterInitMode() == ERROR)
mbed_official 130:1dec54e4aec3 340 {
mbed_official 130:1dec54e4aec3 341 status = ERROR;
mbed_official 130:1dec54e4aec3 342 }
mbed_official 130:1dec54e4aec3 343 else
mbed_official 130:1dec54e4aec3 344 {
mbed_official 130:1dec54e4aec3 345 /* Reset TR, DR and CR registers */
mbed_official 130:1dec54e4aec3 346 RTC->TR = (uint32_t)0x00000000;
mbed_official 130:1dec54e4aec3 347 RTC->WUTR = (uint32_t)0x0000FFFF;
mbed_official 130:1dec54e4aec3 348 RTC->DR = (uint32_t)0x00002101;
mbed_official 130:1dec54e4aec3 349 RTC->CR &= (uint32_t)0x00000000;
mbed_official 130:1dec54e4aec3 350 RTC->PRER = (uint32_t)0x007F00FF;
mbed_official 130:1dec54e4aec3 351 RTC->ALRMAR = (uint32_t)0x00000000;
mbed_official 130:1dec54e4aec3 352 RTC->SHIFTR = (uint32_t)0x00000000;
mbed_official 130:1dec54e4aec3 353 RTC->CALR = (uint32_t)0x00000000;
mbed_official 130:1dec54e4aec3 354 RTC->ALRMASSR = (uint32_t)0x00000000;
mbed_official 130:1dec54e4aec3 355
mbed_official 130:1dec54e4aec3 356 /* Reset ISR register and exit initialization mode */
mbed_official 130:1dec54e4aec3 357 RTC->ISR = (uint32_t)0x00000000;
mbed_official 130:1dec54e4aec3 358
mbed_official 130:1dec54e4aec3 359 /* Reset Tamper and alternate functions configuration register */
mbed_official 130:1dec54e4aec3 360 RTC->TAFCR = 0x00000000;
mbed_official 130:1dec54e4aec3 361
mbed_official 130:1dec54e4aec3 362 /* Wait till the RTC RSF flag is set */
mbed_official 130:1dec54e4aec3 363 if (RTC_WaitForSynchro() == ERROR)
mbed_official 130:1dec54e4aec3 364 {
mbed_official 130:1dec54e4aec3 365 status = ERROR;
mbed_official 130:1dec54e4aec3 366 }
mbed_official 130:1dec54e4aec3 367 else
mbed_official 130:1dec54e4aec3 368 {
mbed_official 130:1dec54e4aec3 369 status = SUCCESS;
mbed_official 130:1dec54e4aec3 370 }
mbed_official 130:1dec54e4aec3 371
mbed_official 130:1dec54e4aec3 372 }
mbed_official 130:1dec54e4aec3 373
mbed_official 130:1dec54e4aec3 374 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 375 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 376
mbed_official 130:1dec54e4aec3 377 return status;
mbed_official 130:1dec54e4aec3 378 }
mbed_official 130:1dec54e4aec3 379
mbed_official 130:1dec54e4aec3 380 /**
mbed_official 130:1dec54e4aec3 381 * @brief Initializes the RTC registers according to the specified parameters
mbed_official 130:1dec54e4aec3 382 * in RTC_InitStruct.
mbed_official 130:1dec54e4aec3 383 * @param RTC_InitStruct: pointer to a RTC_InitTypeDef structure that contains
mbed_official 130:1dec54e4aec3 384 * the configuration information for the RTC peripheral.
mbed_official 130:1dec54e4aec3 385 * @note The RTC Prescaler register is write protected and can be written in
mbed_official 130:1dec54e4aec3 386 * initialization mode only.
mbed_official 130:1dec54e4aec3 387 * @retval An ErrorStatus enumeration value:
mbed_official 130:1dec54e4aec3 388 * - SUCCESS: RTC registers are initialized
mbed_official 130:1dec54e4aec3 389 * - ERROR: RTC registers are not initialized
mbed_official 130:1dec54e4aec3 390 */
mbed_official 130:1dec54e4aec3 391 ErrorStatus RTC_Init(RTC_InitTypeDef* RTC_InitStruct)
mbed_official 130:1dec54e4aec3 392 {
mbed_official 130:1dec54e4aec3 393 ErrorStatus status = ERROR;
mbed_official 130:1dec54e4aec3 394
mbed_official 130:1dec54e4aec3 395 /* Check the parameters */
mbed_official 130:1dec54e4aec3 396 assert_param(IS_RTC_HOUR_FORMAT(RTC_InitStruct->RTC_HourFormat));
mbed_official 130:1dec54e4aec3 397 assert_param(IS_RTC_ASYNCH_PREDIV(RTC_InitStruct->RTC_AsynchPrediv));
mbed_official 130:1dec54e4aec3 398 assert_param(IS_RTC_SYNCH_PREDIV(RTC_InitStruct->RTC_SynchPrediv));
mbed_official 130:1dec54e4aec3 399
mbed_official 130:1dec54e4aec3 400 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 401 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 402 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 403
mbed_official 130:1dec54e4aec3 404 /* Set Initialization mode */
mbed_official 130:1dec54e4aec3 405 if (RTC_EnterInitMode() == ERROR)
mbed_official 130:1dec54e4aec3 406 {
mbed_official 130:1dec54e4aec3 407 status = ERROR;
mbed_official 130:1dec54e4aec3 408 }
mbed_official 130:1dec54e4aec3 409 else
mbed_official 130:1dec54e4aec3 410 {
mbed_official 130:1dec54e4aec3 411 /* Clear RTC CR FMT Bit */
mbed_official 130:1dec54e4aec3 412 RTC->CR &= ((uint32_t)~(RTC_CR_FMT));
mbed_official 130:1dec54e4aec3 413 /* Set RTC_CR register */
mbed_official 130:1dec54e4aec3 414 RTC->CR |= ((uint32_t)(RTC_InitStruct->RTC_HourFormat));
mbed_official 130:1dec54e4aec3 415
mbed_official 130:1dec54e4aec3 416 /* Configure the RTC PRER */
mbed_official 130:1dec54e4aec3 417 RTC->PRER = (uint32_t)(RTC_InitStruct->RTC_SynchPrediv);
mbed_official 130:1dec54e4aec3 418 RTC->PRER |= (uint32_t)(RTC_InitStruct->RTC_AsynchPrediv << 16);
mbed_official 130:1dec54e4aec3 419
mbed_official 130:1dec54e4aec3 420 /* Exit Initialization mode */
mbed_official 130:1dec54e4aec3 421 RTC_ExitInitMode();
mbed_official 130:1dec54e4aec3 422
mbed_official 130:1dec54e4aec3 423 status = SUCCESS;
mbed_official 130:1dec54e4aec3 424 }
mbed_official 130:1dec54e4aec3 425 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 426 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 427
mbed_official 130:1dec54e4aec3 428 return status;
mbed_official 130:1dec54e4aec3 429 }
mbed_official 130:1dec54e4aec3 430
mbed_official 130:1dec54e4aec3 431 /**
mbed_official 130:1dec54e4aec3 432 * @brief Fills each RTC_InitStruct member with its default value.
mbed_official 130:1dec54e4aec3 433 * @param RTC_InitStruct: pointer to a RTC_InitTypeDef structure which will be
mbed_official 130:1dec54e4aec3 434 * initialized.
mbed_official 130:1dec54e4aec3 435 * @retval None
mbed_official 130:1dec54e4aec3 436 */
mbed_official 130:1dec54e4aec3 437 void RTC_StructInit(RTC_InitTypeDef* RTC_InitStruct)
mbed_official 130:1dec54e4aec3 438 {
mbed_official 130:1dec54e4aec3 439 /* Initialize the RTC_HourFormat member */
mbed_official 130:1dec54e4aec3 440 RTC_InitStruct->RTC_HourFormat = RTC_HourFormat_24;
mbed_official 130:1dec54e4aec3 441
mbed_official 130:1dec54e4aec3 442 /* Initialize the RTC_AsynchPrediv member */
mbed_official 130:1dec54e4aec3 443 RTC_InitStruct->RTC_AsynchPrediv = (uint32_t)0x7F;
mbed_official 130:1dec54e4aec3 444
mbed_official 130:1dec54e4aec3 445 /* Initialize the RTC_SynchPrediv member */
mbed_official 130:1dec54e4aec3 446 RTC_InitStruct->RTC_SynchPrediv = (uint32_t)0xFF;
mbed_official 130:1dec54e4aec3 447 }
mbed_official 130:1dec54e4aec3 448
mbed_official 130:1dec54e4aec3 449 /**
mbed_official 130:1dec54e4aec3 450 * @brief Enables or disables the RTC registers write protection.
mbed_official 130:1dec54e4aec3 451 * @note All the RTC registers are write protected except for RTC_ISR[13:8],
mbed_official 130:1dec54e4aec3 452 * RTC_TAFCR and RTC_BKPxR.
mbed_official 130:1dec54e4aec3 453 * @note Writing a wrong key reactivates the write protection.
mbed_official 130:1dec54e4aec3 454 * @note The protection mechanism is not affected by system reset.
mbed_official 130:1dec54e4aec3 455 * @param NewState: new state of the write protection.
mbed_official 130:1dec54e4aec3 456 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 457 * @retval None
mbed_official 130:1dec54e4aec3 458 */
mbed_official 130:1dec54e4aec3 459 void RTC_WriteProtectionCmd(FunctionalState NewState)
mbed_official 130:1dec54e4aec3 460 {
mbed_official 130:1dec54e4aec3 461 /* Check the parameters */
mbed_official 130:1dec54e4aec3 462 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 463
mbed_official 130:1dec54e4aec3 464 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 465 {
mbed_official 130:1dec54e4aec3 466 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 467 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 468 }
mbed_official 130:1dec54e4aec3 469 else
mbed_official 130:1dec54e4aec3 470 {
mbed_official 130:1dec54e4aec3 471 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 472 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 473 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 474 }
mbed_official 130:1dec54e4aec3 475 }
mbed_official 130:1dec54e4aec3 476
mbed_official 130:1dec54e4aec3 477 /**
mbed_official 130:1dec54e4aec3 478 * @brief Enters the RTC Initialization mode.
mbed_official 130:1dec54e4aec3 479 * @note The RTC Initialization mode is write protected, use the
mbed_official 130:1dec54e4aec3 480 * RTC_WriteProtectionCmd(DISABLE) before calling this function.
mbed_official 130:1dec54e4aec3 481 * @param None
mbed_official 130:1dec54e4aec3 482 * @retval An ErrorStatus enumeration value:
mbed_official 130:1dec54e4aec3 483 * - SUCCESS: RTC is in Init mode
mbed_official 130:1dec54e4aec3 484 * - ERROR: RTC is not in Init mode
mbed_official 130:1dec54e4aec3 485 */
mbed_official 130:1dec54e4aec3 486 ErrorStatus RTC_EnterInitMode(void)
mbed_official 130:1dec54e4aec3 487 {
mbed_official 130:1dec54e4aec3 488 __IO uint32_t initcounter = 0x00;
mbed_official 130:1dec54e4aec3 489 ErrorStatus status = ERROR;
mbed_official 130:1dec54e4aec3 490 uint32_t initstatus = 0x00;
mbed_official 130:1dec54e4aec3 491
mbed_official 130:1dec54e4aec3 492 /* Check if the Initialization mode is set */
mbed_official 130:1dec54e4aec3 493 if ((RTC->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
mbed_official 130:1dec54e4aec3 494 {
mbed_official 130:1dec54e4aec3 495 /* Set the Initialization mode */
mbed_official 130:1dec54e4aec3 496 RTC->ISR = (uint32_t)RTC_INIT_MASK;
mbed_official 130:1dec54e4aec3 497
mbed_official 130:1dec54e4aec3 498 /* Wait till RTC is in INIT state and if Time out is reached exit */
mbed_official 130:1dec54e4aec3 499 do
mbed_official 130:1dec54e4aec3 500 {
mbed_official 130:1dec54e4aec3 501 initstatus = RTC->ISR & RTC_ISR_INITF;
mbed_official 130:1dec54e4aec3 502 initcounter++;
mbed_official 130:1dec54e4aec3 503 } while((initcounter != INITMODE_TIMEOUT) && (initstatus == 0x00));
mbed_official 130:1dec54e4aec3 504
mbed_official 130:1dec54e4aec3 505 if ((RTC->ISR & RTC_ISR_INITF) != RESET)
mbed_official 130:1dec54e4aec3 506 {
mbed_official 130:1dec54e4aec3 507 status = SUCCESS;
mbed_official 130:1dec54e4aec3 508 }
mbed_official 130:1dec54e4aec3 509 else
mbed_official 130:1dec54e4aec3 510 {
mbed_official 130:1dec54e4aec3 511 status = ERROR;
mbed_official 130:1dec54e4aec3 512 }
mbed_official 130:1dec54e4aec3 513 }
mbed_official 130:1dec54e4aec3 514 else
mbed_official 130:1dec54e4aec3 515 {
mbed_official 130:1dec54e4aec3 516 status = SUCCESS;
mbed_official 130:1dec54e4aec3 517 }
mbed_official 130:1dec54e4aec3 518
mbed_official 130:1dec54e4aec3 519 return (status);
mbed_official 130:1dec54e4aec3 520 }
mbed_official 130:1dec54e4aec3 521
mbed_official 130:1dec54e4aec3 522 /**
mbed_official 130:1dec54e4aec3 523 * @brief Exits the RTC Initialization mode.
mbed_official 130:1dec54e4aec3 524 * @note When the initialization sequence is complete, the calendar restarts
mbed_official 130:1dec54e4aec3 525 * counting after 4 RTCCLK cycles.
mbed_official 130:1dec54e4aec3 526 * @note The RTC Initialization mode is write protected, use the
mbed_official 130:1dec54e4aec3 527 * RTC_WriteProtectionCmd(DISABLE) before calling this function.
mbed_official 130:1dec54e4aec3 528 * @param None
mbed_official 130:1dec54e4aec3 529 * @retval None
mbed_official 130:1dec54e4aec3 530 */
mbed_official 130:1dec54e4aec3 531 void RTC_ExitInitMode(void)
mbed_official 130:1dec54e4aec3 532 {
mbed_official 130:1dec54e4aec3 533 /* Exit Initialization mode */
mbed_official 130:1dec54e4aec3 534 RTC->ISR &= (uint32_t)~RTC_ISR_INIT;
mbed_official 130:1dec54e4aec3 535 }
mbed_official 130:1dec54e4aec3 536
mbed_official 130:1dec54e4aec3 537 /**
mbed_official 130:1dec54e4aec3 538 * @brief Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are
mbed_official 130:1dec54e4aec3 539 * synchronized with RTC APB clock.
mbed_official 130:1dec54e4aec3 540 * @note The RTC Resynchronization mode is write protected, use the
mbed_official 130:1dec54e4aec3 541 * RTC_WriteProtectionCmd(DISABLE) before calling this function.
mbed_official 130:1dec54e4aec3 542 * @note To read the calendar through the shadow registers after Calendar
mbed_official 130:1dec54e4aec3 543 * initialization, calendar update or after wakeup from low power modes
mbed_official 130:1dec54e4aec3 544 * the software must first clear the RSF flag.
mbed_official 130:1dec54e4aec3 545 * The software must then wait until it is set again before reading
mbed_official 130:1dec54e4aec3 546 * the calendar, which means that the calendar registers have been
mbed_official 130:1dec54e4aec3 547 * correctly copied into the RTC_TR and RTC_DR shadow registers.
mbed_official 130:1dec54e4aec3 548 * @param None
mbed_official 130:1dec54e4aec3 549 * @retval An ErrorStatus enumeration value:
mbed_official 130:1dec54e4aec3 550 * - SUCCESS: RTC registers are synchronised
mbed_official 130:1dec54e4aec3 551 * - ERROR: RTC registers are not synchronised
mbed_official 130:1dec54e4aec3 552 */
mbed_official 130:1dec54e4aec3 553 ErrorStatus RTC_WaitForSynchro(void)
mbed_official 130:1dec54e4aec3 554 {
mbed_official 130:1dec54e4aec3 555 __IO uint32_t synchrocounter = 0;
mbed_official 130:1dec54e4aec3 556 ErrorStatus status = ERROR;
mbed_official 130:1dec54e4aec3 557 uint32_t synchrostatus = 0x00;
mbed_official 130:1dec54e4aec3 558
mbed_official 130:1dec54e4aec3 559 if ((RTC->CR & RTC_CR_BYPSHAD) != RESET)
mbed_official 130:1dec54e4aec3 560 {
mbed_official 130:1dec54e4aec3 561 /* Bypass shadow mode */
mbed_official 130:1dec54e4aec3 562 status = SUCCESS;
mbed_official 130:1dec54e4aec3 563 }
mbed_official 130:1dec54e4aec3 564 else
mbed_official 130:1dec54e4aec3 565 {
mbed_official 130:1dec54e4aec3 566 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 567 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 568 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 569
mbed_official 130:1dec54e4aec3 570 /* Clear RSF flag */
mbed_official 130:1dec54e4aec3 571 RTC->ISR &= (uint32_t)RTC_RSF_MASK;
mbed_official 130:1dec54e4aec3 572
mbed_official 130:1dec54e4aec3 573 /* Wait the registers to be synchronised */
mbed_official 130:1dec54e4aec3 574 do
mbed_official 130:1dec54e4aec3 575 {
mbed_official 130:1dec54e4aec3 576 synchrostatus = RTC->ISR & RTC_ISR_RSF;
mbed_official 130:1dec54e4aec3 577 synchrocounter++;
mbed_official 130:1dec54e4aec3 578 } while((synchrocounter != SYNCHRO_TIMEOUT) && (synchrostatus == 0x00));
mbed_official 130:1dec54e4aec3 579
mbed_official 130:1dec54e4aec3 580 if ((RTC->ISR & RTC_ISR_RSF) != RESET)
mbed_official 130:1dec54e4aec3 581 {
mbed_official 130:1dec54e4aec3 582 status = SUCCESS;
mbed_official 130:1dec54e4aec3 583 }
mbed_official 130:1dec54e4aec3 584 else
mbed_official 130:1dec54e4aec3 585 {
mbed_official 130:1dec54e4aec3 586 status = ERROR;
mbed_official 130:1dec54e4aec3 587 }
mbed_official 130:1dec54e4aec3 588
mbed_official 130:1dec54e4aec3 589 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 590 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 591 }
mbed_official 130:1dec54e4aec3 592
mbed_official 130:1dec54e4aec3 593 return (status);
mbed_official 130:1dec54e4aec3 594 }
mbed_official 130:1dec54e4aec3 595
mbed_official 130:1dec54e4aec3 596 /**
mbed_official 130:1dec54e4aec3 597 * @brief Enables or disables the RTC reference clock detection.
mbed_official 130:1dec54e4aec3 598 * @param NewState: new state of the RTC reference clock.
mbed_official 130:1dec54e4aec3 599 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 600 * @retval An ErrorStatus enumeration value:
mbed_official 130:1dec54e4aec3 601 * - SUCCESS: RTC reference clock detection is enabled
mbed_official 130:1dec54e4aec3 602 * - ERROR: RTC reference clock detection is disabled
mbed_official 130:1dec54e4aec3 603 */
mbed_official 130:1dec54e4aec3 604 ErrorStatus RTC_RefClockCmd(FunctionalState NewState)
mbed_official 130:1dec54e4aec3 605 {
mbed_official 130:1dec54e4aec3 606 ErrorStatus status = ERROR;
mbed_official 130:1dec54e4aec3 607
mbed_official 130:1dec54e4aec3 608 /* Check the parameters */
mbed_official 130:1dec54e4aec3 609 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 610
mbed_official 130:1dec54e4aec3 611 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 612 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 613 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 614
mbed_official 130:1dec54e4aec3 615 /* Set Initialization mode */
mbed_official 130:1dec54e4aec3 616 if (RTC_EnterInitMode() == ERROR)
mbed_official 130:1dec54e4aec3 617 {
mbed_official 130:1dec54e4aec3 618 status = ERROR;
mbed_official 130:1dec54e4aec3 619 }
mbed_official 130:1dec54e4aec3 620 else
mbed_official 130:1dec54e4aec3 621 {
mbed_official 130:1dec54e4aec3 622 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 623 {
mbed_official 130:1dec54e4aec3 624 /* Enable the RTC reference clock detection */
mbed_official 130:1dec54e4aec3 625 RTC->CR |= RTC_CR_REFCKON;
mbed_official 130:1dec54e4aec3 626 }
mbed_official 130:1dec54e4aec3 627 else
mbed_official 130:1dec54e4aec3 628 {
mbed_official 130:1dec54e4aec3 629 /* Disable the RTC reference clock detection */
mbed_official 130:1dec54e4aec3 630 RTC->CR &= ~RTC_CR_REFCKON;
mbed_official 130:1dec54e4aec3 631 }
mbed_official 130:1dec54e4aec3 632 /* Exit Initialization mode */
mbed_official 130:1dec54e4aec3 633 RTC_ExitInitMode();
mbed_official 130:1dec54e4aec3 634
mbed_official 130:1dec54e4aec3 635 status = SUCCESS;
mbed_official 130:1dec54e4aec3 636 }
mbed_official 130:1dec54e4aec3 637
mbed_official 130:1dec54e4aec3 638 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 639 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 640
mbed_official 130:1dec54e4aec3 641 return status;
mbed_official 130:1dec54e4aec3 642 }
mbed_official 130:1dec54e4aec3 643
mbed_official 130:1dec54e4aec3 644 /**
mbed_official 130:1dec54e4aec3 645 * @brief Enables or Disables the Bypass Shadow feature.
mbed_official 130:1dec54e4aec3 646 * @note When the Bypass Shadow is enabled the calendar value are taken
mbed_official 130:1dec54e4aec3 647 * directly from the Calendar counter.
mbed_official 130:1dec54e4aec3 648 * @param NewState: new state of the Bypass Shadow feature.
mbed_official 130:1dec54e4aec3 649 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 650 * @retval None
mbed_official 130:1dec54e4aec3 651 */
mbed_official 130:1dec54e4aec3 652 void RTC_BypassShadowCmd(FunctionalState NewState)
mbed_official 130:1dec54e4aec3 653 {
mbed_official 130:1dec54e4aec3 654 /* Check the parameters */
mbed_official 130:1dec54e4aec3 655 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 656
mbed_official 130:1dec54e4aec3 657 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 658 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 659 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 660
mbed_official 130:1dec54e4aec3 661 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 662 {
mbed_official 130:1dec54e4aec3 663 /* Set the BYPSHAD bit */
mbed_official 130:1dec54e4aec3 664 RTC->CR |= (uint8_t)RTC_CR_BYPSHAD;
mbed_official 130:1dec54e4aec3 665 }
mbed_official 130:1dec54e4aec3 666 else
mbed_official 130:1dec54e4aec3 667 {
mbed_official 130:1dec54e4aec3 668 /* Reset the BYPSHAD bit */
mbed_official 130:1dec54e4aec3 669 RTC->CR &= (uint8_t)~RTC_CR_BYPSHAD;
mbed_official 130:1dec54e4aec3 670 }
mbed_official 130:1dec54e4aec3 671
mbed_official 130:1dec54e4aec3 672 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 673 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 674 }
mbed_official 130:1dec54e4aec3 675
mbed_official 130:1dec54e4aec3 676 /**
mbed_official 130:1dec54e4aec3 677 * @}
mbed_official 130:1dec54e4aec3 678 */
mbed_official 130:1dec54e4aec3 679
mbed_official 130:1dec54e4aec3 680 /** @defgroup RTC_Group2 Time and Date configuration functions
mbed_official 130:1dec54e4aec3 681 * @brief Time and Date configuration functions
mbed_official 130:1dec54e4aec3 682 *
mbed_official 130:1dec54e4aec3 683 @verbatim
mbed_official 130:1dec54e4aec3 684 ===============================================================================
mbed_official 130:1dec54e4aec3 685 ##### Time and Date configuration functions #####
mbed_official 130:1dec54e4aec3 686 ===============================================================================
mbed_official 130:1dec54e4aec3 687 [..] This section provide functions allowing to program and read the RTC
mbed_official 130:1dec54e4aec3 688 Calendar (Time and Date).
mbed_official 130:1dec54e4aec3 689
mbed_official 130:1dec54e4aec3 690 @endverbatim
mbed_official 130:1dec54e4aec3 691 * @{
mbed_official 130:1dec54e4aec3 692 */
mbed_official 130:1dec54e4aec3 693
mbed_official 130:1dec54e4aec3 694 /**
mbed_official 130:1dec54e4aec3 695 * @brief Set the RTC current time.
mbed_official 130:1dec54e4aec3 696 * @param RTC_Format: specifies the format of the entered parameters.
mbed_official 130:1dec54e4aec3 697 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 698 * @arg RTC_Format_BIN: Binary data format
mbed_official 130:1dec54e4aec3 699 * @arg RTC_Format_BCD: BCD data format
mbed_official 130:1dec54e4aec3 700 * @param RTC_TimeStruct: pointer to a RTC_TimeTypeDef structure that contains
mbed_official 130:1dec54e4aec3 701 * the time configuration information for the RTC.
mbed_official 130:1dec54e4aec3 702 * @retval An ErrorStatus enumeration value:
mbed_official 130:1dec54e4aec3 703 * - SUCCESS: RTC Time register is configured
mbed_official 130:1dec54e4aec3 704 * - ERROR: RTC Time register is not configured
mbed_official 130:1dec54e4aec3 705 */
mbed_official 130:1dec54e4aec3 706 ErrorStatus RTC_SetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct)
mbed_official 130:1dec54e4aec3 707 {
mbed_official 130:1dec54e4aec3 708 uint32_t tmpreg = 0;
mbed_official 130:1dec54e4aec3 709 ErrorStatus status = ERROR;
mbed_official 130:1dec54e4aec3 710
mbed_official 130:1dec54e4aec3 711 /* Check the parameters */
mbed_official 130:1dec54e4aec3 712 assert_param(IS_RTC_FORMAT(RTC_Format));
mbed_official 130:1dec54e4aec3 713
mbed_official 130:1dec54e4aec3 714 if (RTC_Format == RTC_Format_BIN)
mbed_official 130:1dec54e4aec3 715 {
mbed_official 130:1dec54e4aec3 716 if ((RTC->CR & RTC_CR_FMT) != (uint32_t)RESET)
mbed_official 130:1dec54e4aec3 717 {
mbed_official 130:1dec54e4aec3 718 assert_param(IS_RTC_HOUR12(RTC_TimeStruct->RTC_Hours));
mbed_official 130:1dec54e4aec3 719 assert_param(IS_RTC_H12(RTC_TimeStruct->RTC_H12));
mbed_official 130:1dec54e4aec3 720 }
mbed_official 130:1dec54e4aec3 721 else
mbed_official 130:1dec54e4aec3 722 {
mbed_official 130:1dec54e4aec3 723 RTC_TimeStruct->RTC_H12 = 0x00;
mbed_official 130:1dec54e4aec3 724 assert_param(IS_RTC_HOUR24(RTC_TimeStruct->RTC_Hours));
mbed_official 130:1dec54e4aec3 725 }
mbed_official 130:1dec54e4aec3 726 assert_param(IS_RTC_MINUTES(RTC_TimeStruct->RTC_Minutes));
mbed_official 130:1dec54e4aec3 727 assert_param(IS_RTC_SECONDS(RTC_TimeStruct->RTC_Seconds));
mbed_official 130:1dec54e4aec3 728 }
mbed_official 130:1dec54e4aec3 729 else
mbed_official 130:1dec54e4aec3 730 {
mbed_official 130:1dec54e4aec3 731 if ((RTC->CR & RTC_CR_FMT) != (uint32_t)RESET)
mbed_official 130:1dec54e4aec3 732 {
mbed_official 130:1dec54e4aec3 733 tmpreg = RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Hours);
mbed_official 130:1dec54e4aec3 734 assert_param(IS_RTC_HOUR12(tmpreg));
mbed_official 130:1dec54e4aec3 735 assert_param(IS_RTC_H12(RTC_TimeStruct->RTC_H12));
mbed_official 130:1dec54e4aec3 736 }
mbed_official 130:1dec54e4aec3 737 else
mbed_official 130:1dec54e4aec3 738 {
mbed_official 130:1dec54e4aec3 739 RTC_TimeStruct->RTC_H12 = 0x00;
mbed_official 130:1dec54e4aec3 740 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Hours)));
mbed_official 130:1dec54e4aec3 741 }
mbed_official 130:1dec54e4aec3 742 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Minutes)));
mbed_official 130:1dec54e4aec3 743 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Seconds)));
mbed_official 130:1dec54e4aec3 744 }
mbed_official 130:1dec54e4aec3 745
mbed_official 130:1dec54e4aec3 746 /* Check the input parameters format */
mbed_official 130:1dec54e4aec3 747 if (RTC_Format != RTC_Format_BIN)
mbed_official 130:1dec54e4aec3 748 {
mbed_official 130:1dec54e4aec3 749 tmpreg = (((uint32_t)(RTC_TimeStruct->RTC_Hours) << 16) | \
mbed_official 130:1dec54e4aec3 750 ((uint32_t)(RTC_TimeStruct->RTC_Minutes) << 8) | \
mbed_official 130:1dec54e4aec3 751 ((uint32_t)RTC_TimeStruct->RTC_Seconds) | \
mbed_official 130:1dec54e4aec3 752 ((uint32_t)(RTC_TimeStruct->RTC_H12) << 16));
mbed_official 130:1dec54e4aec3 753 }
mbed_official 130:1dec54e4aec3 754 else
mbed_official 130:1dec54e4aec3 755 {
mbed_official 130:1dec54e4aec3 756 tmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(RTC_TimeStruct->RTC_Hours) << 16) | \
mbed_official 130:1dec54e4aec3 757 ((uint32_t)RTC_ByteToBcd2(RTC_TimeStruct->RTC_Minutes) << 8) | \
mbed_official 130:1dec54e4aec3 758 ((uint32_t)RTC_ByteToBcd2(RTC_TimeStruct->RTC_Seconds)) | \
mbed_official 130:1dec54e4aec3 759 (((uint32_t)RTC_TimeStruct->RTC_H12) << 16));
mbed_official 130:1dec54e4aec3 760 }
mbed_official 130:1dec54e4aec3 761
mbed_official 130:1dec54e4aec3 762 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 763 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 764 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 765
mbed_official 130:1dec54e4aec3 766 /* Set Initialization mode */
mbed_official 130:1dec54e4aec3 767 if (RTC_EnterInitMode() == ERROR)
mbed_official 130:1dec54e4aec3 768 {
mbed_official 130:1dec54e4aec3 769 status = ERROR;
mbed_official 130:1dec54e4aec3 770 }
mbed_official 130:1dec54e4aec3 771 else
mbed_official 130:1dec54e4aec3 772 {
mbed_official 130:1dec54e4aec3 773 /* Set the RTC_TR register */
mbed_official 130:1dec54e4aec3 774 RTC->TR = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK);
mbed_official 130:1dec54e4aec3 775
mbed_official 130:1dec54e4aec3 776 /* Exit Initialization mode */
mbed_official 130:1dec54e4aec3 777 RTC_ExitInitMode();
mbed_official 130:1dec54e4aec3 778
mbed_official 130:1dec54e4aec3 779 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
mbed_official 130:1dec54e4aec3 780 if ((RTC->CR & RTC_CR_BYPSHAD) == RESET)
mbed_official 130:1dec54e4aec3 781 {
mbed_official 130:1dec54e4aec3 782 if (RTC_WaitForSynchro() == ERROR)
mbed_official 130:1dec54e4aec3 783 {
mbed_official 130:1dec54e4aec3 784 status = ERROR;
mbed_official 130:1dec54e4aec3 785 }
mbed_official 130:1dec54e4aec3 786 else
mbed_official 130:1dec54e4aec3 787 {
mbed_official 130:1dec54e4aec3 788 status = SUCCESS;
mbed_official 130:1dec54e4aec3 789 }
mbed_official 130:1dec54e4aec3 790 }
mbed_official 130:1dec54e4aec3 791 else
mbed_official 130:1dec54e4aec3 792 {
mbed_official 130:1dec54e4aec3 793 status = SUCCESS;
mbed_official 130:1dec54e4aec3 794 }
mbed_official 130:1dec54e4aec3 795
mbed_official 130:1dec54e4aec3 796 }
mbed_official 130:1dec54e4aec3 797 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 798 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 799
mbed_official 130:1dec54e4aec3 800 return status;
mbed_official 130:1dec54e4aec3 801 }
mbed_official 130:1dec54e4aec3 802
mbed_official 130:1dec54e4aec3 803 /**
mbed_official 130:1dec54e4aec3 804 * @brief Fills each RTC_TimeStruct member with its default value
mbed_official 130:1dec54e4aec3 805 * (Time = 00h:00min:00sec).
mbed_official 130:1dec54e4aec3 806 * @param RTC_TimeStruct: pointer to a RTC_TimeTypeDef structure which will be
mbed_official 130:1dec54e4aec3 807 * initialized.
mbed_official 130:1dec54e4aec3 808 * @retval None
mbed_official 130:1dec54e4aec3 809 */
mbed_official 130:1dec54e4aec3 810 void RTC_TimeStructInit(RTC_TimeTypeDef* RTC_TimeStruct)
mbed_official 130:1dec54e4aec3 811 {
mbed_official 130:1dec54e4aec3 812 /* Time = 00h:00min:00sec */
mbed_official 130:1dec54e4aec3 813 RTC_TimeStruct->RTC_H12 = RTC_H12_AM;
mbed_official 130:1dec54e4aec3 814 RTC_TimeStruct->RTC_Hours = 0;
mbed_official 130:1dec54e4aec3 815 RTC_TimeStruct->RTC_Minutes = 0;
mbed_official 130:1dec54e4aec3 816 RTC_TimeStruct->RTC_Seconds = 0;
mbed_official 130:1dec54e4aec3 817 }
mbed_official 130:1dec54e4aec3 818
mbed_official 130:1dec54e4aec3 819 /**
mbed_official 130:1dec54e4aec3 820 * @brief Get the RTC current Time.
mbed_official 130:1dec54e4aec3 821 * @param RTC_Format: specifies the format of the returned parameters.
mbed_official 130:1dec54e4aec3 822 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 823 * @arg RTC_Format_BIN: Binary data format
mbed_official 130:1dec54e4aec3 824 * @arg RTC_Format_BCD: BCD data format
mbed_official 130:1dec54e4aec3 825 * @param RTC_TimeStruct: pointer to a RTC_TimeTypeDef structure that will
mbed_official 130:1dec54e4aec3 826 * contain the returned current time configuration.
mbed_official 130:1dec54e4aec3 827 * @retval None
mbed_official 130:1dec54e4aec3 828 */
mbed_official 130:1dec54e4aec3 829 void RTC_GetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct)
mbed_official 130:1dec54e4aec3 830 {
mbed_official 130:1dec54e4aec3 831 uint32_t tmpreg = 0;
mbed_official 130:1dec54e4aec3 832
mbed_official 130:1dec54e4aec3 833 /* Check the parameters */
mbed_official 130:1dec54e4aec3 834 assert_param(IS_RTC_FORMAT(RTC_Format));
mbed_official 130:1dec54e4aec3 835
mbed_official 130:1dec54e4aec3 836 /* Get the RTC_TR register */
mbed_official 130:1dec54e4aec3 837 tmpreg = (uint32_t)(RTC->TR & RTC_TR_RESERVED_MASK);
mbed_official 130:1dec54e4aec3 838
mbed_official 130:1dec54e4aec3 839 /* Fill the structure fields with the read parameters */
mbed_official 130:1dec54e4aec3 840 RTC_TimeStruct->RTC_Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16);
mbed_official 130:1dec54e4aec3 841 RTC_TimeStruct->RTC_Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >>8);
mbed_official 130:1dec54e4aec3 842 RTC_TimeStruct->RTC_Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU));
mbed_official 130:1dec54e4aec3 843 RTC_TimeStruct->RTC_H12 = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16);
mbed_official 130:1dec54e4aec3 844
mbed_official 130:1dec54e4aec3 845 /* Check the input parameters format */
mbed_official 130:1dec54e4aec3 846 if (RTC_Format == RTC_Format_BIN)
mbed_official 130:1dec54e4aec3 847 {
mbed_official 130:1dec54e4aec3 848 /* Convert the structure parameters to Binary format */
mbed_official 130:1dec54e4aec3 849 RTC_TimeStruct->RTC_Hours = (uint8_t)RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Hours);
mbed_official 130:1dec54e4aec3 850 RTC_TimeStruct->RTC_Minutes = (uint8_t)RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Minutes);
mbed_official 130:1dec54e4aec3 851 RTC_TimeStruct->RTC_Seconds = (uint8_t)RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Seconds);
mbed_official 130:1dec54e4aec3 852 }
mbed_official 130:1dec54e4aec3 853 }
mbed_official 130:1dec54e4aec3 854
mbed_official 130:1dec54e4aec3 855 /**
mbed_official 130:1dec54e4aec3 856 * @brief Gets the RTC current Calendar Subseconds value.
mbed_official 130:1dec54e4aec3 857 * @note This function freeze the Time and Date registers after reading the
mbed_official 130:1dec54e4aec3 858 * SSR register.
mbed_official 130:1dec54e4aec3 859 * @param None
mbed_official 130:1dec54e4aec3 860 * @retval RTC current Calendar Subseconds value.
mbed_official 130:1dec54e4aec3 861 */
mbed_official 130:1dec54e4aec3 862 uint32_t RTC_GetSubSecond(void)
mbed_official 130:1dec54e4aec3 863 {
mbed_official 130:1dec54e4aec3 864 uint32_t tmpreg = 0;
mbed_official 130:1dec54e4aec3 865
mbed_official 130:1dec54e4aec3 866 /* Get subseconds values from the correspondent registers*/
mbed_official 130:1dec54e4aec3 867 tmpreg = (uint32_t)(RTC->SSR);
mbed_official 130:1dec54e4aec3 868
mbed_official 130:1dec54e4aec3 869 /* Read DR register to unfroze calendar registers */
mbed_official 130:1dec54e4aec3 870 (void) (RTC->DR);
mbed_official 130:1dec54e4aec3 871
mbed_official 130:1dec54e4aec3 872 return (tmpreg);
mbed_official 130:1dec54e4aec3 873 }
mbed_official 130:1dec54e4aec3 874
mbed_official 130:1dec54e4aec3 875 /**
mbed_official 130:1dec54e4aec3 876 * @brief Set the RTC current date.
mbed_official 130:1dec54e4aec3 877 * @param RTC_Format: specifies the format of the entered parameters.
mbed_official 130:1dec54e4aec3 878 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 879 * @arg RTC_Format_BIN: Binary data format
mbed_official 130:1dec54e4aec3 880 * @arg RTC_Format_BCD: BCD data format
mbed_official 130:1dec54e4aec3 881 * @param RTC_DateStruct: pointer to a RTC_DateTypeDef structure that contains
mbed_official 130:1dec54e4aec3 882 * the date configuration information for the RTC.
mbed_official 130:1dec54e4aec3 883 * @retval An ErrorStatus enumeration value:
mbed_official 130:1dec54e4aec3 884 * - SUCCESS: RTC Date register is configured
mbed_official 130:1dec54e4aec3 885 * - ERROR: RTC Date register is not configured
mbed_official 130:1dec54e4aec3 886 */
mbed_official 130:1dec54e4aec3 887 ErrorStatus RTC_SetDate(uint32_t RTC_Format, RTC_DateTypeDef* RTC_DateStruct)
mbed_official 130:1dec54e4aec3 888 {
mbed_official 130:1dec54e4aec3 889 uint32_t tmpreg = 0;
mbed_official 130:1dec54e4aec3 890 ErrorStatus status = ERROR;
mbed_official 130:1dec54e4aec3 891
mbed_official 130:1dec54e4aec3 892 /* Check the parameters */
mbed_official 130:1dec54e4aec3 893 assert_param(IS_RTC_FORMAT(RTC_Format));
mbed_official 130:1dec54e4aec3 894
mbed_official 130:1dec54e4aec3 895 if ((RTC_Format == RTC_Format_BIN) && ((RTC_DateStruct->RTC_Month & 0x10) == 0x10))
mbed_official 130:1dec54e4aec3 896 {
mbed_official 130:1dec54e4aec3 897 RTC_DateStruct->RTC_Month = (RTC_DateStruct->RTC_Month & (uint32_t)~(0x10)) + 0x0A;
mbed_official 130:1dec54e4aec3 898 }
mbed_official 130:1dec54e4aec3 899 if (RTC_Format == RTC_Format_BIN)
mbed_official 130:1dec54e4aec3 900 {
mbed_official 130:1dec54e4aec3 901 assert_param(IS_RTC_YEAR(RTC_DateStruct->RTC_Year));
mbed_official 130:1dec54e4aec3 902 assert_param(IS_RTC_MONTH(RTC_DateStruct->RTC_Month));
mbed_official 130:1dec54e4aec3 903 assert_param(IS_RTC_DATE(RTC_DateStruct->RTC_Date));
mbed_official 130:1dec54e4aec3 904 }
mbed_official 130:1dec54e4aec3 905 else
mbed_official 130:1dec54e4aec3 906 {
mbed_official 130:1dec54e4aec3 907 assert_param(IS_RTC_YEAR(RTC_Bcd2ToByte(RTC_DateStruct->RTC_Year)));
mbed_official 130:1dec54e4aec3 908 tmpreg = RTC_Bcd2ToByte(RTC_DateStruct->RTC_Month);
mbed_official 130:1dec54e4aec3 909 assert_param(IS_RTC_MONTH(tmpreg));
mbed_official 130:1dec54e4aec3 910 tmpreg = RTC_Bcd2ToByte(RTC_DateStruct->RTC_Date);
mbed_official 130:1dec54e4aec3 911 assert_param(IS_RTC_DATE(tmpreg));
mbed_official 130:1dec54e4aec3 912 }
mbed_official 130:1dec54e4aec3 913 assert_param(IS_RTC_WEEKDAY(RTC_DateStruct->RTC_WeekDay));
mbed_official 130:1dec54e4aec3 914
mbed_official 130:1dec54e4aec3 915 /* Check the input parameters format */
mbed_official 130:1dec54e4aec3 916 if (RTC_Format != RTC_Format_BIN)
mbed_official 130:1dec54e4aec3 917 {
mbed_official 130:1dec54e4aec3 918 tmpreg = ((((uint32_t)RTC_DateStruct->RTC_Year) << 16) | \
mbed_official 130:1dec54e4aec3 919 (((uint32_t)RTC_DateStruct->RTC_Month) << 8) | \
mbed_official 130:1dec54e4aec3 920 ((uint32_t)RTC_DateStruct->RTC_Date) | \
mbed_official 130:1dec54e4aec3 921 (((uint32_t)RTC_DateStruct->RTC_WeekDay) << 13));
mbed_official 130:1dec54e4aec3 922 }
mbed_official 130:1dec54e4aec3 923 else
mbed_official 130:1dec54e4aec3 924 {
mbed_official 130:1dec54e4aec3 925 tmpreg = (((uint32_t)RTC_ByteToBcd2(RTC_DateStruct->RTC_Year) << 16) | \
mbed_official 130:1dec54e4aec3 926 ((uint32_t)RTC_ByteToBcd2(RTC_DateStruct->RTC_Month) << 8) | \
mbed_official 130:1dec54e4aec3 927 ((uint32_t)RTC_ByteToBcd2(RTC_DateStruct->RTC_Date)) | \
mbed_official 130:1dec54e4aec3 928 ((uint32_t)RTC_DateStruct->RTC_WeekDay << 13));
mbed_official 130:1dec54e4aec3 929 }
mbed_official 130:1dec54e4aec3 930
mbed_official 130:1dec54e4aec3 931 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 932 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 933 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 934
mbed_official 130:1dec54e4aec3 935 /* Set Initialization mode */
mbed_official 130:1dec54e4aec3 936 if (RTC_EnterInitMode() == ERROR)
mbed_official 130:1dec54e4aec3 937 {
mbed_official 130:1dec54e4aec3 938 status = ERROR;
mbed_official 130:1dec54e4aec3 939 }
mbed_official 130:1dec54e4aec3 940 else
mbed_official 130:1dec54e4aec3 941 {
mbed_official 130:1dec54e4aec3 942 /* Set the RTC_DR register */
mbed_official 130:1dec54e4aec3 943 RTC->DR = (uint32_t)(tmpreg & RTC_DR_RESERVED_MASK);
mbed_official 130:1dec54e4aec3 944
mbed_official 130:1dec54e4aec3 945 /* Exit Initialization mode */
mbed_official 130:1dec54e4aec3 946 RTC_ExitInitMode();
mbed_official 130:1dec54e4aec3 947
mbed_official 130:1dec54e4aec3 948 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
mbed_official 130:1dec54e4aec3 949 if ((RTC->CR & RTC_CR_BYPSHAD) == RESET)
mbed_official 130:1dec54e4aec3 950 {
mbed_official 130:1dec54e4aec3 951 if (RTC_WaitForSynchro() == ERROR)
mbed_official 130:1dec54e4aec3 952 {
mbed_official 130:1dec54e4aec3 953 status = ERROR;
mbed_official 130:1dec54e4aec3 954 }
mbed_official 130:1dec54e4aec3 955 else
mbed_official 130:1dec54e4aec3 956 {
mbed_official 130:1dec54e4aec3 957 status = SUCCESS;
mbed_official 130:1dec54e4aec3 958 }
mbed_official 130:1dec54e4aec3 959 }
mbed_official 130:1dec54e4aec3 960 else
mbed_official 130:1dec54e4aec3 961 {
mbed_official 130:1dec54e4aec3 962 status = SUCCESS;
mbed_official 130:1dec54e4aec3 963 }
mbed_official 130:1dec54e4aec3 964 }
mbed_official 130:1dec54e4aec3 965 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 966 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 967
mbed_official 130:1dec54e4aec3 968 return status;
mbed_official 130:1dec54e4aec3 969 }
mbed_official 130:1dec54e4aec3 970
mbed_official 130:1dec54e4aec3 971 /**
mbed_official 130:1dec54e4aec3 972 * @brief Fills each RTC_DateStruct member with its default value
mbed_official 130:1dec54e4aec3 973 * (Monday, January 01 xx00).
mbed_official 130:1dec54e4aec3 974 * @param RTC_DateStruct: pointer to a RTC_DateTypeDef structure which will be
mbed_official 130:1dec54e4aec3 975 * initialized.
mbed_official 130:1dec54e4aec3 976 * @retval None
mbed_official 130:1dec54e4aec3 977 */
mbed_official 130:1dec54e4aec3 978 void RTC_DateStructInit(RTC_DateTypeDef* RTC_DateStruct)
mbed_official 130:1dec54e4aec3 979 {
mbed_official 130:1dec54e4aec3 980 /* Monday, January 01 xx00 */
mbed_official 130:1dec54e4aec3 981 RTC_DateStruct->RTC_WeekDay = RTC_Weekday_Monday;
mbed_official 130:1dec54e4aec3 982 RTC_DateStruct->RTC_Date = 1;
mbed_official 130:1dec54e4aec3 983 RTC_DateStruct->RTC_Month = RTC_Month_January;
mbed_official 130:1dec54e4aec3 984 RTC_DateStruct->RTC_Year = 0;
mbed_official 130:1dec54e4aec3 985 }
mbed_official 130:1dec54e4aec3 986
mbed_official 130:1dec54e4aec3 987 /**
mbed_official 130:1dec54e4aec3 988 * @brief Get the RTC current date.
mbed_official 130:1dec54e4aec3 989 * @param RTC_Format: specifies the format of the returned parameters.
mbed_official 130:1dec54e4aec3 990 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 991 * @arg RTC_Format_BIN: Binary data format
mbed_official 130:1dec54e4aec3 992 * @arg RTC_Format_BCD: BCD data format
mbed_official 130:1dec54e4aec3 993 * @param RTC_DateStruct: pointer to a RTC_DateTypeDef structure that will
mbed_official 130:1dec54e4aec3 994 * contain the returned current date configuration.
mbed_official 130:1dec54e4aec3 995 * @retval None
mbed_official 130:1dec54e4aec3 996 */
mbed_official 130:1dec54e4aec3 997 void RTC_GetDate(uint32_t RTC_Format, RTC_DateTypeDef* RTC_DateStruct)
mbed_official 130:1dec54e4aec3 998 {
mbed_official 130:1dec54e4aec3 999 uint32_t tmpreg = 0;
mbed_official 130:1dec54e4aec3 1000
mbed_official 130:1dec54e4aec3 1001 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1002 assert_param(IS_RTC_FORMAT(RTC_Format));
mbed_official 130:1dec54e4aec3 1003
mbed_official 130:1dec54e4aec3 1004 /* Get the RTC_TR register */
mbed_official 130:1dec54e4aec3 1005 tmpreg = (uint32_t)(RTC->DR & RTC_DR_RESERVED_MASK);
mbed_official 130:1dec54e4aec3 1006
mbed_official 130:1dec54e4aec3 1007 /* Fill the structure fields with the read parameters */
mbed_official 130:1dec54e4aec3 1008 RTC_DateStruct->RTC_Year = (uint8_t)((tmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16);
mbed_official 130:1dec54e4aec3 1009 RTC_DateStruct->RTC_Month = (uint8_t)((tmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8);
mbed_official 130:1dec54e4aec3 1010 RTC_DateStruct->RTC_Date = (uint8_t)(tmpreg & (RTC_DR_DT | RTC_DR_DU));
mbed_official 130:1dec54e4aec3 1011 RTC_DateStruct->RTC_WeekDay = (uint8_t)((tmpreg & (RTC_DR_WDU)) >> 13);
mbed_official 130:1dec54e4aec3 1012
mbed_official 130:1dec54e4aec3 1013 /* Check the input parameters format */
mbed_official 130:1dec54e4aec3 1014 if (RTC_Format == RTC_Format_BIN)
mbed_official 130:1dec54e4aec3 1015 {
mbed_official 130:1dec54e4aec3 1016 /* Convert the structure parameters to Binary format */
mbed_official 130:1dec54e4aec3 1017 RTC_DateStruct->RTC_Year = (uint8_t)RTC_Bcd2ToByte(RTC_DateStruct->RTC_Year);
mbed_official 130:1dec54e4aec3 1018 RTC_DateStruct->RTC_Month = (uint8_t)RTC_Bcd2ToByte(RTC_DateStruct->RTC_Month);
mbed_official 130:1dec54e4aec3 1019 RTC_DateStruct->RTC_Date = (uint8_t)RTC_Bcd2ToByte(RTC_DateStruct->RTC_Date);
mbed_official 130:1dec54e4aec3 1020 RTC_DateStruct->RTC_WeekDay = (uint8_t)(RTC_DateStruct->RTC_WeekDay);
mbed_official 130:1dec54e4aec3 1021 }
mbed_official 130:1dec54e4aec3 1022 }
mbed_official 130:1dec54e4aec3 1023
mbed_official 130:1dec54e4aec3 1024 /**
mbed_official 130:1dec54e4aec3 1025 * @}
mbed_official 130:1dec54e4aec3 1026 */
mbed_official 130:1dec54e4aec3 1027
mbed_official 130:1dec54e4aec3 1028 /** @defgroup RTC_Group3 Alarms configuration functions
mbed_official 130:1dec54e4aec3 1029 * @brief Alarms (Alarm A) configuration functions
mbed_official 130:1dec54e4aec3 1030 *
mbed_official 130:1dec54e4aec3 1031 @verbatim
mbed_official 130:1dec54e4aec3 1032 ===============================================================================
mbed_official 130:1dec54e4aec3 1033 ##### Alarms (Alarm A and Alarm B) configuration functions #####
mbed_official 130:1dec54e4aec3 1034 ===============================================================================
mbed_official 130:1dec54e4aec3 1035 [..] This section provide functions allowing to program and read the RTC
mbed_official 130:1dec54e4aec3 1036 Alarms.
mbed_official 130:1dec54e4aec3 1037
mbed_official 130:1dec54e4aec3 1038 @endverbatim
mbed_official 130:1dec54e4aec3 1039 * @{
mbed_official 130:1dec54e4aec3 1040 */
mbed_official 130:1dec54e4aec3 1041
mbed_official 130:1dec54e4aec3 1042 /**
mbed_official 130:1dec54e4aec3 1043 * @brief Set the specified RTC Alarm.
mbed_official 130:1dec54e4aec3 1044 * @note The Alarm register can only be written when the corresponding Alarm
mbed_official 130:1dec54e4aec3 1045 * is disabled (Use the RTC_AlarmCmd(DISABLE)).
mbed_official 130:1dec54e4aec3 1046 * @param RTC_Format: specifies the format of the returned parameters.
mbed_official 130:1dec54e4aec3 1047 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 1048 * @arg RTC_Format_BIN: Binary data format
mbed_official 130:1dec54e4aec3 1049 * @arg RTC_Format_BCD: BCD data format
mbed_official 130:1dec54e4aec3 1050 * @param RTC_Alarm: specifies the alarm to be configured.
mbed_official 130:1dec54e4aec3 1051 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 1052 * @arg RTC_Alarm_A: to select Alarm A
mbed_official 130:1dec54e4aec3 1053 * @param RTC_AlarmStruct: pointer to a RTC_AlarmTypeDef structure that
mbed_official 130:1dec54e4aec3 1054 * contains the alarm configuration parameters.
mbed_official 130:1dec54e4aec3 1055 * @retval None
mbed_official 130:1dec54e4aec3 1056 */
mbed_official 130:1dec54e4aec3 1057 void RTC_SetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmTypeDef* RTC_AlarmStruct)
mbed_official 130:1dec54e4aec3 1058 {
mbed_official 130:1dec54e4aec3 1059 uint32_t tmpreg = 0;
mbed_official 130:1dec54e4aec3 1060
mbed_official 130:1dec54e4aec3 1061 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1062 assert_param(IS_RTC_FORMAT(RTC_Format));
mbed_official 130:1dec54e4aec3 1063 assert_param(IS_RTC_ALARM(RTC_Alarm));
mbed_official 130:1dec54e4aec3 1064 assert_param(IS_RTC_ALARM_MASK(RTC_AlarmStruct->RTC_AlarmMask));
mbed_official 130:1dec54e4aec3 1065 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(RTC_AlarmStruct->RTC_AlarmDateWeekDaySel));
mbed_official 130:1dec54e4aec3 1066
mbed_official 130:1dec54e4aec3 1067 if (RTC_Format == RTC_Format_BIN)
mbed_official 130:1dec54e4aec3 1068 {
mbed_official 130:1dec54e4aec3 1069 if ((RTC->CR & RTC_CR_FMT) != (uint32_t)RESET)
mbed_official 130:1dec54e4aec3 1070 {
mbed_official 130:1dec54e4aec3 1071 assert_param(IS_RTC_HOUR12(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours));
mbed_official 130:1dec54e4aec3 1072 assert_param(IS_RTC_H12(RTC_AlarmStruct->RTC_AlarmTime.RTC_H12));
mbed_official 130:1dec54e4aec3 1073 }
mbed_official 130:1dec54e4aec3 1074 else
mbed_official 130:1dec54e4aec3 1075 {
mbed_official 130:1dec54e4aec3 1076 RTC_AlarmStruct->RTC_AlarmTime.RTC_H12 = 0x00;
mbed_official 130:1dec54e4aec3 1077 assert_param(IS_RTC_HOUR24(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours));
mbed_official 130:1dec54e4aec3 1078 }
mbed_official 130:1dec54e4aec3 1079 assert_param(IS_RTC_MINUTES(RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes));
mbed_official 130:1dec54e4aec3 1080 assert_param(IS_RTC_SECONDS(RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds));
mbed_official 130:1dec54e4aec3 1081
mbed_official 130:1dec54e4aec3 1082 if(RTC_AlarmStruct->RTC_AlarmDateWeekDaySel == RTC_AlarmDateWeekDaySel_Date)
mbed_official 130:1dec54e4aec3 1083 {
mbed_official 130:1dec54e4aec3 1084 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(RTC_AlarmStruct->RTC_AlarmDateWeekDay));
mbed_official 130:1dec54e4aec3 1085 }
mbed_official 130:1dec54e4aec3 1086 else
mbed_official 130:1dec54e4aec3 1087 {
mbed_official 130:1dec54e4aec3 1088 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(RTC_AlarmStruct->RTC_AlarmDateWeekDay));
mbed_official 130:1dec54e4aec3 1089 }
mbed_official 130:1dec54e4aec3 1090 }
mbed_official 130:1dec54e4aec3 1091 else
mbed_official 130:1dec54e4aec3 1092 {
mbed_official 130:1dec54e4aec3 1093 if ((RTC->CR & RTC_CR_FMT) != (uint32_t)RESET)
mbed_official 130:1dec54e4aec3 1094 {
mbed_official 130:1dec54e4aec3 1095 tmpreg = RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours);
mbed_official 130:1dec54e4aec3 1096 assert_param(IS_RTC_HOUR12(tmpreg));
mbed_official 130:1dec54e4aec3 1097 assert_param(IS_RTC_H12(RTC_AlarmStruct->RTC_AlarmTime.RTC_H12));
mbed_official 130:1dec54e4aec3 1098 }
mbed_official 130:1dec54e4aec3 1099 else
mbed_official 130:1dec54e4aec3 1100 {
mbed_official 130:1dec54e4aec3 1101 RTC_AlarmStruct->RTC_AlarmTime.RTC_H12 = 0x00;
mbed_official 130:1dec54e4aec3 1102 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours)));
mbed_official 130:1dec54e4aec3 1103 }
mbed_official 130:1dec54e4aec3 1104
mbed_official 130:1dec54e4aec3 1105 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes)));
mbed_official 130:1dec54e4aec3 1106 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds)));
mbed_official 130:1dec54e4aec3 1107
mbed_official 130:1dec54e4aec3 1108 if(RTC_AlarmStruct->RTC_AlarmDateWeekDaySel == RTC_AlarmDateWeekDaySel_Date)
mbed_official 130:1dec54e4aec3 1109 {
mbed_official 130:1dec54e4aec3 1110 tmpreg = RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmDateWeekDay);
mbed_official 130:1dec54e4aec3 1111 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg));
mbed_official 130:1dec54e4aec3 1112 }
mbed_official 130:1dec54e4aec3 1113 else
mbed_official 130:1dec54e4aec3 1114 {
mbed_official 130:1dec54e4aec3 1115 tmpreg = RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmDateWeekDay);
mbed_official 130:1dec54e4aec3 1116 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg));
mbed_official 130:1dec54e4aec3 1117 }
mbed_official 130:1dec54e4aec3 1118 }
mbed_official 130:1dec54e4aec3 1119
mbed_official 130:1dec54e4aec3 1120 /* Check the input parameters format */
mbed_official 130:1dec54e4aec3 1121 if (RTC_Format != RTC_Format_BIN)
mbed_official 130:1dec54e4aec3 1122 {
mbed_official 130:1dec54e4aec3 1123 tmpreg = (((uint32_t)(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours) << 16) | \
mbed_official 130:1dec54e4aec3 1124 ((uint32_t)(RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes) << 8) | \
mbed_official 130:1dec54e4aec3 1125 ((uint32_t)RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds) | \
mbed_official 130:1dec54e4aec3 1126 ((uint32_t)(RTC_AlarmStruct->RTC_AlarmTime.RTC_H12) << 16) | \
mbed_official 130:1dec54e4aec3 1127 ((uint32_t)(RTC_AlarmStruct->RTC_AlarmDateWeekDay) << 24) | \
mbed_official 130:1dec54e4aec3 1128 ((uint32_t)RTC_AlarmStruct->RTC_AlarmDateWeekDaySel) | \
mbed_official 130:1dec54e4aec3 1129 ((uint32_t)RTC_AlarmStruct->RTC_AlarmMask));
mbed_official 130:1dec54e4aec3 1130 }
mbed_official 130:1dec54e4aec3 1131 else
mbed_official 130:1dec54e4aec3 1132 {
mbed_official 130:1dec54e4aec3 1133 tmpreg = (((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours) << 16) | \
mbed_official 130:1dec54e4aec3 1134 ((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes) << 8) | \
mbed_official 130:1dec54e4aec3 1135 ((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds)) | \
mbed_official 130:1dec54e4aec3 1136 ((uint32_t)(RTC_AlarmStruct->RTC_AlarmTime.RTC_H12) << 16) | \
mbed_official 130:1dec54e4aec3 1137 ((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->RTC_AlarmDateWeekDay) << 24) | \
mbed_official 130:1dec54e4aec3 1138 ((uint32_t)RTC_AlarmStruct->RTC_AlarmDateWeekDaySel) | \
mbed_official 130:1dec54e4aec3 1139 ((uint32_t)RTC_AlarmStruct->RTC_AlarmMask));
mbed_official 130:1dec54e4aec3 1140 }
mbed_official 130:1dec54e4aec3 1141
mbed_official 130:1dec54e4aec3 1142 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1143 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 1144 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 1145
mbed_official 130:1dec54e4aec3 1146 /* Configure the Alarm register */
mbed_official 130:1dec54e4aec3 1147 RTC->ALRMAR = (uint32_t)tmpreg;
mbed_official 130:1dec54e4aec3 1148
mbed_official 130:1dec54e4aec3 1149 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1150 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 1151 }
mbed_official 130:1dec54e4aec3 1152
mbed_official 130:1dec54e4aec3 1153 /**
mbed_official 130:1dec54e4aec3 1154 * @brief Fills each RTC_AlarmStruct member with its default value
mbed_official 130:1dec54e4aec3 1155 * (Time = 00h:00mn:00sec / Date = 1st day of the month/Mask =
mbed_official 130:1dec54e4aec3 1156 * all fields are masked).
mbed_official 130:1dec54e4aec3 1157 * @param RTC_AlarmStruct: pointer to a @ref RTC_AlarmTypeDef structure which
mbed_official 130:1dec54e4aec3 1158 * will be initialized.
mbed_official 130:1dec54e4aec3 1159 * @retval None
mbed_official 130:1dec54e4aec3 1160 */
mbed_official 130:1dec54e4aec3 1161 void RTC_AlarmStructInit(RTC_AlarmTypeDef* RTC_AlarmStruct)
mbed_official 130:1dec54e4aec3 1162 {
mbed_official 130:1dec54e4aec3 1163 /* Alarm Time Settings : Time = 00h:00mn:00sec */
mbed_official 130:1dec54e4aec3 1164 RTC_AlarmStruct->RTC_AlarmTime.RTC_H12 = RTC_H12_AM;
mbed_official 130:1dec54e4aec3 1165 RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours = 0;
mbed_official 130:1dec54e4aec3 1166 RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes = 0;
mbed_official 130:1dec54e4aec3 1167 RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds = 0;
mbed_official 130:1dec54e4aec3 1168
mbed_official 130:1dec54e4aec3 1169 /* Alarm Date Settings : Date = 1st day of the month */
mbed_official 130:1dec54e4aec3 1170 RTC_AlarmStruct->RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;
mbed_official 130:1dec54e4aec3 1171 RTC_AlarmStruct->RTC_AlarmDateWeekDay = 1;
mbed_official 130:1dec54e4aec3 1172
mbed_official 130:1dec54e4aec3 1173 /* Alarm Masks Settings : Mask = all fields are not masked */
mbed_official 130:1dec54e4aec3 1174 RTC_AlarmStruct->RTC_AlarmMask = RTC_AlarmMask_None;
mbed_official 130:1dec54e4aec3 1175 }
mbed_official 130:1dec54e4aec3 1176
mbed_official 130:1dec54e4aec3 1177 /**
mbed_official 130:1dec54e4aec3 1178 * @brief Get the RTC Alarm value and masks.
mbed_official 130:1dec54e4aec3 1179 * @param RTC_Format: specifies the format of the output parameters.
mbed_official 130:1dec54e4aec3 1180 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 1181 * @arg RTC_Format_BIN: Binary data format
mbed_official 130:1dec54e4aec3 1182 * @arg RTC_Format_BCD: BCD data format
mbed_official 130:1dec54e4aec3 1183 * @param RTC_Alarm: specifies the alarm to be read.
mbed_official 130:1dec54e4aec3 1184 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 1185 * @arg RTC_Alarm_A: to select Alarm A
mbed_official 130:1dec54e4aec3 1186 * @param RTC_AlarmStruct: pointer to a RTC_AlarmTypeDef structure that will
mbed_official 130:1dec54e4aec3 1187 * contains the output alarm configuration values.
mbed_official 130:1dec54e4aec3 1188 * @retval None
mbed_official 130:1dec54e4aec3 1189 */
mbed_official 130:1dec54e4aec3 1190 void RTC_GetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmTypeDef* RTC_AlarmStruct)
mbed_official 130:1dec54e4aec3 1191 {
mbed_official 130:1dec54e4aec3 1192 uint32_t tmpreg = 0;
mbed_official 130:1dec54e4aec3 1193
mbed_official 130:1dec54e4aec3 1194 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1195 assert_param(IS_RTC_FORMAT(RTC_Format));
mbed_official 130:1dec54e4aec3 1196 assert_param(IS_RTC_ALARM(RTC_Alarm));
mbed_official 130:1dec54e4aec3 1197
mbed_official 130:1dec54e4aec3 1198 /* Get the RTC_ALRMAR register */
mbed_official 130:1dec54e4aec3 1199 tmpreg = (uint32_t)(RTC->ALRMAR);
mbed_official 130:1dec54e4aec3 1200
mbed_official 130:1dec54e4aec3 1201 /* Fill the structure with the read parameters */
mbed_official 130:1dec54e4aec3 1202 RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours = (uint32_t)((tmpreg & (RTC_ALRMAR_HT | \
mbed_official 130:1dec54e4aec3 1203 RTC_ALRMAR_HU)) >> 16);
mbed_official 130:1dec54e4aec3 1204 RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes = (uint32_t)((tmpreg & (RTC_ALRMAR_MNT | \
mbed_official 130:1dec54e4aec3 1205 RTC_ALRMAR_MNU)) >> 8);
mbed_official 130:1dec54e4aec3 1206 RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds = (uint32_t)(tmpreg & (RTC_ALRMAR_ST | \
mbed_official 130:1dec54e4aec3 1207 RTC_ALRMAR_SU));
mbed_official 130:1dec54e4aec3 1208 RTC_AlarmStruct->RTC_AlarmTime.RTC_H12 = (uint32_t)((tmpreg & RTC_ALRMAR_PM) >> 16);
mbed_official 130:1dec54e4aec3 1209 RTC_AlarmStruct->RTC_AlarmDateWeekDay = (uint32_t)((tmpreg & (RTC_ALRMAR_DT | RTC_ALRMAR_DU)) >> 24);
mbed_official 130:1dec54e4aec3 1210 RTC_AlarmStruct->RTC_AlarmDateWeekDaySel = (uint32_t)(tmpreg & RTC_ALRMAR_WDSEL);
mbed_official 130:1dec54e4aec3 1211 RTC_AlarmStruct->RTC_AlarmMask = (uint32_t)(tmpreg & RTC_AlarmMask_All);
mbed_official 130:1dec54e4aec3 1212
mbed_official 130:1dec54e4aec3 1213 if (RTC_Format == RTC_Format_BIN)
mbed_official 130:1dec54e4aec3 1214 {
mbed_official 130:1dec54e4aec3 1215 RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours = RTC_Bcd2ToByte(RTC_AlarmStruct-> \
mbed_official 130:1dec54e4aec3 1216 RTC_AlarmTime.RTC_Hours);
mbed_official 130:1dec54e4aec3 1217 RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes = RTC_Bcd2ToByte(RTC_AlarmStruct-> \
mbed_official 130:1dec54e4aec3 1218 RTC_AlarmTime.RTC_Minutes);
mbed_official 130:1dec54e4aec3 1219 RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds = RTC_Bcd2ToByte(RTC_AlarmStruct-> \
mbed_official 130:1dec54e4aec3 1220 RTC_AlarmTime.RTC_Seconds);
mbed_official 130:1dec54e4aec3 1221 RTC_AlarmStruct->RTC_AlarmDateWeekDay = RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmDateWeekDay);
mbed_official 130:1dec54e4aec3 1222 }
mbed_official 130:1dec54e4aec3 1223 }
mbed_official 130:1dec54e4aec3 1224
mbed_official 130:1dec54e4aec3 1225 /**
mbed_official 130:1dec54e4aec3 1226 * @brief Enables or disables the specified RTC Alarm.
mbed_official 130:1dec54e4aec3 1227 * @param RTC_Alarm: specifies the alarm to be configured.
mbed_official 130:1dec54e4aec3 1228 * This parameter can be any combination of the following values:
mbed_official 130:1dec54e4aec3 1229 * @arg RTC_Alarm_A: to select Alarm A
mbed_official 130:1dec54e4aec3 1230 * @param NewState: new state of the specified alarm.
mbed_official 130:1dec54e4aec3 1231 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 1232 * @retval An ErrorStatus enumeration value:
mbed_official 130:1dec54e4aec3 1233 * - SUCCESS: RTC Alarm is enabled/disabled
mbed_official 130:1dec54e4aec3 1234 * - ERROR: RTC Alarm is not enabled/disabled
mbed_official 130:1dec54e4aec3 1235 */
mbed_official 130:1dec54e4aec3 1236 ErrorStatus RTC_AlarmCmd(uint32_t RTC_Alarm, FunctionalState NewState)
mbed_official 130:1dec54e4aec3 1237 {
mbed_official 130:1dec54e4aec3 1238 __IO uint32_t alarmcounter = 0x00;
mbed_official 130:1dec54e4aec3 1239 uint32_t alarmstatus = 0x00;
mbed_official 130:1dec54e4aec3 1240 ErrorStatus status = ERROR;
mbed_official 130:1dec54e4aec3 1241
mbed_official 130:1dec54e4aec3 1242 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1243 assert_param(IS_RTC_CMD_ALARM(RTC_Alarm));
mbed_official 130:1dec54e4aec3 1244 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 1245
mbed_official 130:1dec54e4aec3 1246 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1247 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 1248 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 1249
mbed_official 130:1dec54e4aec3 1250 /* Configure the Alarm state */
mbed_official 130:1dec54e4aec3 1251 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 1252 {
mbed_official 130:1dec54e4aec3 1253 RTC->CR |= (uint32_t)RTC_Alarm;
mbed_official 130:1dec54e4aec3 1254
mbed_official 130:1dec54e4aec3 1255 status = SUCCESS;
mbed_official 130:1dec54e4aec3 1256 }
mbed_official 130:1dec54e4aec3 1257 else
mbed_official 130:1dec54e4aec3 1258 {
mbed_official 130:1dec54e4aec3 1259 /* Disable the Alarm in RTC_CR register */
mbed_official 130:1dec54e4aec3 1260 RTC->CR &= (uint32_t)~RTC_Alarm;
mbed_official 130:1dec54e4aec3 1261
mbed_official 130:1dec54e4aec3 1262 /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */
mbed_official 130:1dec54e4aec3 1263 do
mbed_official 130:1dec54e4aec3 1264 {
mbed_official 130:1dec54e4aec3 1265 alarmstatus = RTC->ISR & (RTC_Alarm >> 8);
mbed_official 130:1dec54e4aec3 1266 alarmcounter++;
mbed_official 130:1dec54e4aec3 1267 } while((alarmcounter != INITMODE_TIMEOUT) && (alarmstatus == 0x00));
mbed_official 130:1dec54e4aec3 1268
mbed_official 130:1dec54e4aec3 1269 if ((RTC->ISR & (RTC_Alarm >> 8)) == RESET)
mbed_official 130:1dec54e4aec3 1270 {
mbed_official 130:1dec54e4aec3 1271 status = ERROR;
mbed_official 130:1dec54e4aec3 1272 }
mbed_official 130:1dec54e4aec3 1273 else
mbed_official 130:1dec54e4aec3 1274 {
mbed_official 130:1dec54e4aec3 1275 status = SUCCESS;
mbed_official 130:1dec54e4aec3 1276 }
mbed_official 130:1dec54e4aec3 1277 }
mbed_official 130:1dec54e4aec3 1278
mbed_official 130:1dec54e4aec3 1279 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1280 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 1281
mbed_official 130:1dec54e4aec3 1282 return status;
mbed_official 130:1dec54e4aec3 1283 }
mbed_official 130:1dec54e4aec3 1284
mbed_official 130:1dec54e4aec3 1285 /**
mbed_official 130:1dec54e4aec3 1286 * @brief Configure the RTC AlarmA/B Subseconds value and mask.
mbed_official 130:1dec54e4aec3 1287 * @note This function is performed only when the Alarm is disabled.
mbed_official 130:1dec54e4aec3 1288 * @param RTC_Alarm: specifies the alarm to be configured.
mbed_official 130:1dec54e4aec3 1289 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 1290 * @arg RTC_Alarm_A: to select Alarm A
mbed_official 130:1dec54e4aec3 1291 * @param RTC_AlarmSubSecondValue: specifies the Subseconds value.
mbed_official 130:1dec54e4aec3 1292 * This parameter can be a value from 0 to 0x00007FFF.
mbed_official 130:1dec54e4aec3 1293 * @param RTC_AlarmSubSecondMask: specifies the Subseconds Mask.
mbed_official 130:1dec54e4aec3 1294 * This parameter can be any combination of the following values:
mbed_official 130:1dec54e4aec3 1295 * @arg RTC_AlarmSubSecondMask_All: All Alarm SS fields are masked.
mbed_official 130:1dec54e4aec3 1296 * There is no comparison on sub seconds for Alarm.
mbed_official 130:1dec54e4aec3 1297 * @arg RTC_AlarmSubSecondMask_SS14_1: SS[14:1] are don't care in Alarm comparison.
mbed_official 130:1dec54e4aec3 1298 * Only SS[0] is compared
mbed_official 130:1dec54e4aec3 1299 * @arg RTC_AlarmSubSecondMask_SS14_2: SS[14:2] are don't care in Alarm comparison.
mbed_official 130:1dec54e4aec3 1300 * Only SS[1:0] are compared
mbed_official 130:1dec54e4aec3 1301 * @arg RTC_AlarmSubSecondMask_SS14_3: SS[14:3] are don't care in Alarm comparison.
mbed_official 130:1dec54e4aec3 1302 * Only SS[2:0] are compared
mbed_official 130:1dec54e4aec3 1303 * @arg RTC_AlarmSubSecondMask_SS14_4: SS[14:4] are don't care in Alarm comparison.
mbed_official 130:1dec54e4aec3 1304 * Only SS[3:0] are compared
mbed_official 130:1dec54e4aec3 1305 * @arg RTC_AlarmSubSecondMask_SS14_5: SS[14:5] are don't care in Alarm comparison.
mbed_official 130:1dec54e4aec3 1306 * Only SS[4:0] are compared
mbed_official 130:1dec54e4aec3 1307 * @arg RTC_AlarmSubSecondMask_SS14_6: SS[14:6] are don't care in Alarm comparison.
mbed_official 130:1dec54e4aec3 1308 * Only SS[5:0] are compared
mbed_official 130:1dec54e4aec3 1309 * @arg RTC_AlarmSubSecondMask_SS14_7: SS[14:7] are don't care in Alarm comparison.
mbed_official 130:1dec54e4aec3 1310 * Only SS[6:0] are compared
mbed_official 130:1dec54e4aec3 1311 * @arg RTC_AlarmSubSecondMask_SS14_8: SS[14:8] are don't care in Alarm comparison.
mbed_official 130:1dec54e4aec3 1312 * Only SS[7:0] are compared
mbed_official 130:1dec54e4aec3 1313 * @arg RTC_AlarmSubSecondMask_SS14_9: SS[14:9] are don't care in Alarm comparison.
mbed_official 130:1dec54e4aec3 1314 * Only SS[8:0] are compared
mbed_official 130:1dec54e4aec3 1315 * @arg RTC_AlarmSubSecondMask_SS14_10: SS[14:10] are don't care in Alarm comparison.
mbed_official 130:1dec54e4aec3 1316 * Only SS[9:0] are compared
mbed_official 130:1dec54e4aec3 1317 * @arg RTC_AlarmSubSecondMask_SS14_11: SS[14:11] are don't care in Alarm comparison.
mbed_official 130:1dec54e4aec3 1318 * Only SS[10:0] are compared
mbed_official 130:1dec54e4aec3 1319 * @arg RTC_AlarmSubSecondMask_SS14_12: SS[14:12] are don't care in Alarm comparison.
mbed_official 130:1dec54e4aec3 1320 * Only SS[11:0] are compared
mbed_official 130:1dec54e4aec3 1321 * @arg RTC_AlarmSubSecondMask_SS14_13: SS[14:13] are don't care in Alarm comparison.
mbed_official 130:1dec54e4aec3 1322 * Only SS[12:0] are compared
mbed_official 130:1dec54e4aec3 1323 * @arg RTC_AlarmSubSecondMask_SS14: SS[14] is don't care in Alarm comparison.
mbed_official 130:1dec54e4aec3 1324 * Only SS[13:0] are compared
mbed_official 130:1dec54e4aec3 1325 * @arg RTC_AlarmSubSecondMask_None: SS[14:0] are compared and must match to activate alarm
mbed_official 130:1dec54e4aec3 1326 * @retval None
mbed_official 130:1dec54e4aec3 1327 */
mbed_official 130:1dec54e4aec3 1328 void RTC_AlarmSubSecondConfig(uint32_t RTC_Alarm, uint32_t RTC_AlarmSubSecondValue, uint8_t RTC_AlarmSubSecondMask)
mbed_official 130:1dec54e4aec3 1329 {
mbed_official 130:1dec54e4aec3 1330 uint32_t tmpreg = 0;
mbed_official 130:1dec54e4aec3 1331
mbed_official 130:1dec54e4aec3 1332 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1333 assert_param(IS_RTC_ALARM(RTC_Alarm));
mbed_official 130:1dec54e4aec3 1334 assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(RTC_AlarmSubSecondValue));
mbed_official 130:1dec54e4aec3 1335 assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(RTC_AlarmSubSecondMask));
mbed_official 130:1dec54e4aec3 1336
mbed_official 130:1dec54e4aec3 1337 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1338 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 1339 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 1340
mbed_official 130:1dec54e4aec3 1341 /* Configure the Alarm A or Alarm B SubSecond registers */
mbed_official 130:1dec54e4aec3 1342 tmpreg = (uint32_t) (((uint32_t)(RTC_AlarmSubSecondValue)) | ((uint32_t)(RTC_AlarmSubSecondMask) << 24));
mbed_official 130:1dec54e4aec3 1343
mbed_official 130:1dec54e4aec3 1344 /* Configure the AlarmA SubSecond register */
mbed_official 130:1dec54e4aec3 1345 RTC->ALRMASSR = tmpreg;
mbed_official 130:1dec54e4aec3 1346
mbed_official 130:1dec54e4aec3 1347 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1348 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 1349
mbed_official 130:1dec54e4aec3 1350 }
mbed_official 130:1dec54e4aec3 1351
mbed_official 130:1dec54e4aec3 1352 /**
mbed_official 130:1dec54e4aec3 1353 * @brief Gets the RTC Alarm Subseconds value.
mbed_official 130:1dec54e4aec3 1354 * @param RTC_Alarm: specifies the alarm to be read.
mbed_official 130:1dec54e4aec3 1355 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 1356 * @arg RTC_Alarm_A: to select Alarm A
mbed_official 130:1dec54e4aec3 1357 * @param None
mbed_official 130:1dec54e4aec3 1358 * @retval RTC Alarm Subseconds value.
mbed_official 130:1dec54e4aec3 1359 */
mbed_official 130:1dec54e4aec3 1360 uint32_t RTC_GetAlarmSubSecond(uint32_t RTC_Alarm)
mbed_official 130:1dec54e4aec3 1361 {
mbed_official 130:1dec54e4aec3 1362 uint32_t tmpreg = 0;
mbed_official 130:1dec54e4aec3 1363
mbed_official 130:1dec54e4aec3 1364 /* Get the RTC_ALRMAR register */
mbed_official 130:1dec54e4aec3 1365 tmpreg = (uint32_t)((RTC->ALRMASSR) & RTC_ALRMASSR_SS);
mbed_official 130:1dec54e4aec3 1366
mbed_official 130:1dec54e4aec3 1367 return (tmpreg);
mbed_official 130:1dec54e4aec3 1368 }
mbed_official 130:1dec54e4aec3 1369
mbed_official 130:1dec54e4aec3 1370 /**
mbed_official 130:1dec54e4aec3 1371 * @}
mbed_official 130:1dec54e4aec3 1372 */
mbed_official 130:1dec54e4aec3 1373
mbed_official 130:1dec54e4aec3 1374 /** @defgroup RTC_Group4 WakeUp Timer configuration functions
mbed_official 130:1dec54e4aec3 1375 * @brief WakeUp Timer configuration functions
mbed_official 130:1dec54e4aec3 1376 *
mbed_official 130:1dec54e4aec3 1377 @verbatim
mbed_official 130:1dec54e4aec3 1378 ===============================================================================
mbed_official 130:1dec54e4aec3 1379 ##### WakeUp Timer configuration functions #####
mbed_official 130:1dec54e4aec3 1380 ===============================================================================
mbed_official 130:1dec54e4aec3 1381
mbed_official 130:1dec54e4aec3 1382 [..] This section provide functions allowing to program and read the RTC WakeUp.
mbed_official 130:1dec54e4aec3 1383
mbed_official 130:1dec54e4aec3 1384 @endverbatim
mbed_official 130:1dec54e4aec3 1385 * @{
mbed_official 130:1dec54e4aec3 1386 */
mbed_official 130:1dec54e4aec3 1387
mbed_official 130:1dec54e4aec3 1388 /**
mbed_official 130:1dec54e4aec3 1389 * @brief Configures the RTC Wakeup clock source.
mbed_official 130:1dec54e4aec3 1390 * This function is available for STM32F072 devices.
mbed_official 130:1dec54e4aec3 1391 * @note The WakeUp Clock source can only be changed when the RTC WakeUp
mbed_official 130:1dec54e4aec3 1392 * is disabled (Use the RTC_WakeUpCmd(DISABLE)).
mbed_official 130:1dec54e4aec3 1393 * @param RTC_WakeUpClock: Wakeup Clock source.
mbed_official 130:1dec54e4aec3 1394 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 1395 * @arg RTC_WakeUpClock_RTCCLK_Div16
mbed_official 130:1dec54e4aec3 1396 * @arg RTC_WakeUpClock_RTCCLK_Div8
mbed_official 130:1dec54e4aec3 1397 * @arg RTC_WakeUpClock_RTCCLK_Div4
mbed_official 130:1dec54e4aec3 1398 * @arg RTC_WakeUpClock_RTCCLK_Div2
mbed_official 130:1dec54e4aec3 1399 * @arg RTC_WakeUpClock_CK_SPRE_16bits
mbed_official 130:1dec54e4aec3 1400 * @arg RTC_WakeUpClock_CK_SPRE_17bits
mbed_official 130:1dec54e4aec3 1401 * @retval None
mbed_official 130:1dec54e4aec3 1402 */
mbed_official 130:1dec54e4aec3 1403 void RTC_WakeUpClockConfig(uint32_t RTC_WakeUpClock)
mbed_official 130:1dec54e4aec3 1404 {
mbed_official 130:1dec54e4aec3 1405 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1406 assert_param(IS_RTC_WAKEUP_CLOCK(RTC_WakeUpClock));
mbed_official 130:1dec54e4aec3 1407
mbed_official 130:1dec54e4aec3 1408 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1409 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 1410 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 1411
mbed_official 130:1dec54e4aec3 1412 /* Clear the Wakeup Timer clock source bits in CR register */
mbed_official 130:1dec54e4aec3 1413 RTC->CR &= (uint32_t)~RTC_CR_WUCKSEL;
mbed_official 130:1dec54e4aec3 1414
mbed_official 130:1dec54e4aec3 1415 /* Configure the clock source */
mbed_official 130:1dec54e4aec3 1416 RTC->CR |= (uint32_t)RTC_WakeUpClock;
mbed_official 130:1dec54e4aec3 1417
mbed_official 130:1dec54e4aec3 1418 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1419 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 1420 }
mbed_official 130:1dec54e4aec3 1421
mbed_official 130:1dec54e4aec3 1422 /**
mbed_official 130:1dec54e4aec3 1423 * @brief Configures the RTC Wakeup counter.
mbed_official 130:1dec54e4aec3 1424 * This function is available for STM32F072 devices.
mbed_official 130:1dec54e4aec3 1425 * @note The RTC WakeUp counter can only be written when the RTC WakeUp
mbed_official 130:1dec54e4aec3 1426 * is disabled (Use the RTC_WakeUpCmd(DISABLE)).
mbed_official 130:1dec54e4aec3 1427 * @param RTC_WakeUpCounter: specifies the WakeUp counter.
mbed_official 130:1dec54e4aec3 1428 * This parameter can be a value from 0x0000 to 0xFFFF.
mbed_official 130:1dec54e4aec3 1429 * @retval None
mbed_official 130:1dec54e4aec3 1430 */
mbed_official 130:1dec54e4aec3 1431 void RTC_SetWakeUpCounter(uint32_t RTC_WakeUpCounter)
mbed_official 130:1dec54e4aec3 1432 {
mbed_official 130:1dec54e4aec3 1433 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1434 assert_param(IS_RTC_WAKEUP_COUNTER(RTC_WakeUpCounter));
mbed_official 130:1dec54e4aec3 1435
mbed_official 130:1dec54e4aec3 1436 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1437 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 1438 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 1439
mbed_official 130:1dec54e4aec3 1440 /* Configure the Wakeup Timer counter */
mbed_official 130:1dec54e4aec3 1441 RTC->WUTR = (uint32_t)RTC_WakeUpCounter;
mbed_official 130:1dec54e4aec3 1442
mbed_official 130:1dec54e4aec3 1443 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1444 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 1445 }
mbed_official 130:1dec54e4aec3 1446
mbed_official 130:1dec54e4aec3 1447 /**
mbed_official 130:1dec54e4aec3 1448 * @brief Returns the RTC WakeUp timer counter value.
mbed_official 130:1dec54e4aec3 1449 * This function is available for STM32F072 devices.
mbed_official 130:1dec54e4aec3 1450 * @param None
mbed_official 130:1dec54e4aec3 1451 * @retval The RTC WakeUp Counter value.
mbed_official 130:1dec54e4aec3 1452 */
mbed_official 130:1dec54e4aec3 1453 uint32_t RTC_GetWakeUpCounter(void)
mbed_official 130:1dec54e4aec3 1454 {
mbed_official 130:1dec54e4aec3 1455 /* Get the counter value */
mbed_official 130:1dec54e4aec3 1456 return ((uint32_t)(RTC->WUTR & RTC_WUTR_WUT));
mbed_official 130:1dec54e4aec3 1457 }
mbed_official 130:1dec54e4aec3 1458
mbed_official 130:1dec54e4aec3 1459 /**
mbed_official 130:1dec54e4aec3 1460 * @brief Enables or Disables the RTC WakeUp timer.
mbed_official 130:1dec54e4aec3 1461 * This function is available for STM32F072 devices.
mbed_official 130:1dec54e4aec3 1462 * @param NewState: new state of the WakeUp timer.
mbed_official 130:1dec54e4aec3 1463 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 1464 * @retval None
mbed_official 130:1dec54e4aec3 1465 */
mbed_official 130:1dec54e4aec3 1466 ErrorStatus RTC_WakeUpCmd(FunctionalState NewState)
mbed_official 130:1dec54e4aec3 1467 {
mbed_official 130:1dec54e4aec3 1468 __IO uint32_t wutcounter = 0x00;
mbed_official 130:1dec54e4aec3 1469 uint32_t wutwfstatus = 0x00;
mbed_official 130:1dec54e4aec3 1470 ErrorStatus status = ERROR;
mbed_official 130:1dec54e4aec3 1471
mbed_official 130:1dec54e4aec3 1472 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1473 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 1474
mbed_official 130:1dec54e4aec3 1475 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1476 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 1477 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 1478
mbed_official 130:1dec54e4aec3 1479 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 1480 {
mbed_official 130:1dec54e4aec3 1481 /* Enable the Wakeup Timer */
mbed_official 130:1dec54e4aec3 1482 RTC->CR |= (uint32_t)RTC_CR_WUTE;
mbed_official 130:1dec54e4aec3 1483 status = SUCCESS;
mbed_official 130:1dec54e4aec3 1484 }
mbed_official 130:1dec54e4aec3 1485 else
mbed_official 130:1dec54e4aec3 1486 {
mbed_official 130:1dec54e4aec3 1487 /* Disable the Wakeup Timer */
mbed_official 130:1dec54e4aec3 1488 RTC->CR &= (uint32_t)~RTC_CR_WUTE;
mbed_official 130:1dec54e4aec3 1489 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
mbed_official 130:1dec54e4aec3 1490 do
mbed_official 130:1dec54e4aec3 1491 {
mbed_official 130:1dec54e4aec3 1492 wutwfstatus = RTC->ISR & RTC_ISR_WUTWF;
mbed_official 130:1dec54e4aec3 1493 wutcounter++;
mbed_official 130:1dec54e4aec3 1494 } while((wutcounter != INITMODE_TIMEOUT) && (wutwfstatus == 0x00));
mbed_official 130:1dec54e4aec3 1495
mbed_official 130:1dec54e4aec3 1496 if ((RTC->ISR & RTC_ISR_WUTWF) == RESET)
mbed_official 130:1dec54e4aec3 1497 {
mbed_official 130:1dec54e4aec3 1498 status = ERROR;
mbed_official 130:1dec54e4aec3 1499 }
mbed_official 130:1dec54e4aec3 1500 else
mbed_official 130:1dec54e4aec3 1501 {
mbed_official 130:1dec54e4aec3 1502 status = SUCCESS;
mbed_official 130:1dec54e4aec3 1503 }
mbed_official 130:1dec54e4aec3 1504 }
mbed_official 130:1dec54e4aec3 1505
mbed_official 130:1dec54e4aec3 1506 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1507 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 1508
mbed_official 130:1dec54e4aec3 1509 return status;
mbed_official 130:1dec54e4aec3 1510 }
mbed_official 130:1dec54e4aec3 1511
mbed_official 130:1dec54e4aec3 1512 /**
mbed_official 130:1dec54e4aec3 1513 * @}
mbed_official 130:1dec54e4aec3 1514 */
mbed_official 130:1dec54e4aec3 1515
mbed_official 130:1dec54e4aec3 1516 /** @defgroup RTC_Group5 Daylight Saving configuration functions
mbed_official 130:1dec54e4aec3 1517 * @brief Daylight Saving configuration functions
mbed_official 130:1dec54e4aec3 1518 *
mbed_official 130:1dec54e4aec3 1519 @verbatim
mbed_official 130:1dec54e4aec3 1520 ===============================================================================
mbed_official 130:1dec54e4aec3 1521 ##### WakeUp Timer configuration functions #####
mbed_official 130:1dec54e4aec3 1522 ===============================================================================
mbed_official 130:1dec54e4aec3 1523 [..] This section provide functions allowing to program and read the RTC WakeUp.
mbed_official 130:1dec54e4aec3 1524
mbed_official 130:1dec54e4aec3 1525 This section provide functions allowing to configure the RTC DayLight Saving.
mbed_official 130:1dec54e4aec3 1526
mbed_official 130:1dec54e4aec3 1527 @endverbatim
mbed_official 130:1dec54e4aec3 1528 * @{
mbed_official 130:1dec54e4aec3 1529 */
mbed_official 130:1dec54e4aec3 1530
mbed_official 130:1dec54e4aec3 1531 /**
mbed_official 130:1dec54e4aec3 1532 * @brief Adds or substract one hour from the current time.
mbed_official 130:1dec54e4aec3 1533 * @param RTC_DayLightSaveOperation: the value of hour adjustment.
mbed_official 130:1dec54e4aec3 1534 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 1535 * @arg RTC_DayLightSaving_SUB1H: Substract one hour (winter time)
mbed_official 130:1dec54e4aec3 1536 * @arg RTC_DayLightSaving_ADD1H: Add one hour (summer time)
mbed_official 130:1dec54e4aec3 1537 * @param RTC_StoreOperation: Specifies the value to be written in the BCK bit
mbed_official 130:1dec54e4aec3 1538 * in CR register to store the operation.
mbed_official 130:1dec54e4aec3 1539 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 1540 * @arg RTC_StoreOperation_Reset: BCK Bit Reset
mbed_official 130:1dec54e4aec3 1541 * @arg RTC_StoreOperation_Set: BCK Bit Set
mbed_official 130:1dec54e4aec3 1542 * @retval None
mbed_official 130:1dec54e4aec3 1543 */
mbed_official 130:1dec54e4aec3 1544 void RTC_DayLightSavingConfig(uint32_t RTC_DayLightSaving, uint32_t RTC_StoreOperation)
mbed_official 130:1dec54e4aec3 1545 {
mbed_official 130:1dec54e4aec3 1546 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1547 assert_param(IS_RTC_DAYLIGHT_SAVING(RTC_DayLightSaving));
mbed_official 130:1dec54e4aec3 1548 assert_param(IS_RTC_STORE_OPERATION(RTC_StoreOperation));
mbed_official 130:1dec54e4aec3 1549
mbed_official 130:1dec54e4aec3 1550 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1551 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 1552 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 1553
mbed_official 130:1dec54e4aec3 1554 /* Clear the bits to be configured */
mbed_official 130:1dec54e4aec3 1555 RTC->CR &= (uint32_t)~(RTC_CR_BCK);
mbed_official 130:1dec54e4aec3 1556
mbed_official 130:1dec54e4aec3 1557 /* Configure the RTC_CR register */
mbed_official 130:1dec54e4aec3 1558 RTC->CR |= (uint32_t)(RTC_DayLightSaving | RTC_StoreOperation);
mbed_official 130:1dec54e4aec3 1559
mbed_official 130:1dec54e4aec3 1560 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1561 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 1562 }
mbed_official 130:1dec54e4aec3 1563
mbed_official 130:1dec54e4aec3 1564 /**
mbed_official 130:1dec54e4aec3 1565 * @brief Returns the RTC Day Light Saving stored operation.
mbed_official 130:1dec54e4aec3 1566 * @param None
mbed_official 130:1dec54e4aec3 1567 * @retval RTC Day Light Saving stored operation.
mbed_official 130:1dec54e4aec3 1568 * - RTC_StoreOperation_Reset
mbed_official 130:1dec54e4aec3 1569 * - RTC_StoreOperation_Set
mbed_official 130:1dec54e4aec3 1570 */
mbed_official 130:1dec54e4aec3 1571 uint32_t RTC_GetStoreOperation(void)
mbed_official 130:1dec54e4aec3 1572 {
mbed_official 130:1dec54e4aec3 1573 return (RTC->CR & RTC_CR_BCK);
mbed_official 130:1dec54e4aec3 1574 }
mbed_official 130:1dec54e4aec3 1575
mbed_official 130:1dec54e4aec3 1576 /**
mbed_official 130:1dec54e4aec3 1577 * @}
mbed_official 130:1dec54e4aec3 1578 */
mbed_official 130:1dec54e4aec3 1579
mbed_official 130:1dec54e4aec3 1580 /** @defgroup RTC_Group6 Output pin Configuration function
mbed_official 130:1dec54e4aec3 1581 * @brief Output pin Configuration function
mbed_official 130:1dec54e4aec3 1582 *
mbed_official 130:1dec54e4aec3 1583 @verbatim
mbed_official 130:1dec54e4aec3 1584 ===============================================================================
mbed_official 130:1dec54e4aec3 1585 ##### Output pin Configuration function #####
mbed_official 130:1dec54e4aec3 1586 ===============================================================================
mbed_official 130:1dec54e4aec3 1587 [..] This section provide functions allowing to configure the RTC Output source.
mbed_official 130:1dec54e4aec3 1588
mbed_official 130:1dec54e4aec3 1589 @endverbatim
mbed_official 130:1dec54e4aec3 1590 * @{
mbed_official 130:1dec54e4aec3 1591 */
mbed_official 130:1dec54e4aec3 1592
mbed_official 130:1dec54e4aec3 1593 /**
mbed_official 130:1dec54e4aec3 1594 * @brief Configures the RTC output source (AFO_ALARM).
mbed_official 130:1dec54e4aec3 1595 * @param RTC_Output: Specifies which signal will be routed to the RTC output.
mbed_official 130:1dec54e4aec3 1596 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 1597 * @arg RTC_Output_Disable: No output selected
mbed_official 130:1dec54e4aec3 1598 * @arg RTC_Output_AlarmA: signal of AlarmA mapped to output
mbed_official 130:1dec54e4aec3 1599 * @arg RTC_Output_WakeUp: signal of WakeUp mapped to output, available only for STM32F072 devices
mbed_official 130:1dec54e4aec3 1600 * @param RTC_OutputPolarity: Specifies the polarity of the output signal.
mbed_official 130:1dec54e4aec3 1601 * This parameter can be one of the following:
mbed_official 130:1dec54e4aec3 1602 * @arg RTC_OutputPolarity_High: The output pin is high when the
mbed_official 130:1dec54e4aec3 1603 * ALRAF is high (depending on OSEL)
mbed_official 130:1dec54e4aec3 1604 * @arg RTC_OutputPolarity_Low: The output pin is low when the
mbed_official 130:1dec54e4aec3 1605 * ALRAF is high (depending on OSEL)
mbed_official 130:1dec54e4aec3 1606 * @retval None
mbed_official 130:1dec54e4aec3 1607 */
mbed_official 130:1dec54e4aec3 1608 void RTC_OutputConfig(uint32_t RTC_Output, uint32_t RTC_OutputPolarity)
mbed_official 130:1dec54e4aec3 1609 {
mbed_official 130:1dec54e4aec3 1610 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1611 assert_param(IS_RTC_OUTPUT(RTC_Output));
mbed_official 130:1dec54e4aec3 1612 assert_param(IS_RTC_OUTPUT_POL(RTC_OutputPolarity));
mbed_official 130:1dec54e4aec3 1613
mbed_official 130:1dec54e4aec3 1614 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1615 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 1616 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 1617
mbed_official 130:1dec54e4aec3 1618 /* Clear the bits to be configured */
mbed_official 130:1dec54e4aec3 1619 RTC->CR &= (uint32_t)~(RTC_CR_OSEL | RTC_CR_POL);
mbed_official 130:1dec54e4aec3 1620
mbed_official 130:1dec54e4aec3 1621 /* Configure the output selection and polarity */
mbed_official 130:1dec54e4aec3 1622 RTC->CR |= (uint32_t)(RTC_Output | RTC_OutputPolarity);
mbed_official 130:1dec54e4aec3 1623
mbed_official 130:1dec54e4aec3 1624 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1625 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 1626 }
mbed_official 130:1dec54e4aec3 1627
mbed_official 130:1dec54e4aec3 1628 /**
mbed_official 130:1dec54e4aec3 1629 * @}
mbed_official 130:1dec54e4aec3 1630 */
mbed_official 130:1dec54e4aec3 1631
mbed_official 130:1dec54e4aec3 1632 /** @defgroup RTC_Group7 Digital Calibration configuration functions
mbed_official 130:1dec54e4aec3 1633 * @brief Digital Calibration configuration functions
mbed_official 130:1dec54e4aec3 1634 *
mbed_official 130:1dec54e4aec3 1635 @verbatim
mbed_official 130:1dec54e4aec3 1636 ===============================================================================
mbed_official 130:1dec54e4aec3 1637 ##### Digital Calibration configuration functions #####
mbed_official 130:1dec54e4aec3 1638 ===============================================================================
mbed_official 130:1dec54e4aec3 1639
mbed_official 130:1dec54e4aec3 1640 @endverbatim
mbed_official 130:1dec54e4aec3 1641 * @{
mbed_official 130:1dec54e4aec3 1642 */
mbed_official 130:1dec54e4aec3 1643
mbed_official 130:1dec54e4aec3 1644 /**
mbed_official 130:1dec54e4aec3 1645 * @brief Enables or disables the RTC clock to be output through the relative pin.
mbed_official 130:1dec54e4aec3 1646 * @param NewState: new state of the digital calibration Output.
mbed_official 130:1dec54e4aec3 1647 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 1648 * @retval None
mbed_official 130:1dec54e4aec3 1649 */
mbed_official 130:1dec54e4aec3 1650 void RTC_CalibOutputCmd(FunctionalState NewState)
mbed_official 130:1dec54e4aec3 1651 {
mbed_official 130:1dec54e4aec3 1652 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1653 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 1654
mbed_official 130:1dec54e4aec3 1655 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1656 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 1657 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 1658
mbed_official 130:1dec54e4aec3 1659 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 1660 {
mbed_official 130:1dec54e4aec3 1661 /* Enable the RTC clock output */
mbed_official 130:1dec54e4aec3 1662 RTC->CR |= (uint32_t)RTC_CR_COE;
mbed_official 130:1dec54e4aec3 1663 }
mbed_official 130:1dec54e4aec3 1664 else
mbed_official 130:1dec54e4aec3 1665 {
mbed_official 130:1dec54e4aec3 1666 /* Disable the RTC clock output */
mbed_official 130:1dec54e4aec3 1667 RTC->CR &= (uint32_t)~RTC_CR_COE;
mbed_official 130:1dec54e4aec3 1668 }
mbed_official 130:1dec54e4aec3 1669
mbed_official 130:1dec54e4aec3 1670 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1671 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 1672 }
mbed_official 130:1dec54e4aec3 1673
mbed_official 130:1dec54e4aec3 1674 /**
mbed_official 130:1dec54e4aec3 1675 * @brief Configure the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
mbed_official 130:1dec54e4aec3 1676 * @param RTC_CalibOutput: Select the Calibration output Selection .
mbed_official 130:1dec54e4aec3 1677 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 1678 * @arg RTC_CalibOutput_512Hz: A signal has a regular waveform at 512Hz.
mbed_official 130:1dec54e4aec3 1679 * @arg RTC_CalibOutput_1Hz: A signal has a regular waveform at 1Hz.
mbed_official 130:1dec54e4aec3 1680 * @retval None
mbed_official 130:1dec54e4aec3 1681 */
mbed_official 130:1dec54e4aec3 1682 void RTC_CalibOutputConfig(uint32_t RTC_CalibOutput)
mbed_official 130:1dec54e4aec3 1683 {
mbed_official 130:1dec54e4aec3 1684 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1685 assert_param(IS_RTC_CALIB_OUTPUT(RTC_CalibOutput));
mbed_official 130:1dec54e4aec3 1686
mbed_official 130:1dec54e4aec3 1687 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1688 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 1689 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 1690
mbed_official 130:1dec54e4aec3 1691 /*clear flags before config*/
mbed_official 130:1dec54e4aec3 1692 RTC->CR &= (uint32_t)~(RTC_CR_CALSEL);
mbed_official 130:1dec54e4aec3 1693
mbed_official 130:1dec54e4aec3 1694 /* Configure the RTC_CR register */
mbed_official 130:1dec54e4aec3 1695 RTC->CR |= (uint32_t)RTC_CalibOutput;
mbed_official 130:1dec54e4aec3 1696
mbed_official 130:1dec54e4aec3 1697 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1698 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 1699 }
mbed_official 130:1dec54e4aec3 1700
mbed_official 130:1dec54e4aec3 1701 /**
mbed_official 130:1dec54e4aec3 1702 * @brief Configures the Smooth Calibration Settings.
mbed_official 130:1dec54e4aec3 1703 * @param RTC_SmoothCalibPeriod: Select the Smooth Calibration Period.
mbed_official 130:1dec54e4aec3 1704 * This parameter can be can be one of the following values:
mbed_official 130:1dec54e4aec3 1705 * @arg RTC_SmoothCalibPeriod_32sec: The smooth calibration periode is 32s.
mbed_official 130:1dec54e4aec3 1706 * @arg RTC_SmoothCalibPeriod_16sec: The smooth calibration periode is 16s.
mbed_official 130:1dec54e4aec3 1707 * @arg RTC_SmoothCalibPeriod_8sec: The smooth calibartion periode is 8s.
mbed_official 130:1dec54e4aec3 1708 * @param RTC_SmoothCalibPlusPulses: Select to Set or reset the CALP bit.
mbed_official 130:1dec54e4aec3 1709 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 1710 * @arg RTC_SmoothCalibPlusPulses_Set: Add one RTCCLK puls every 2**11 pulses.
mbed_official 130:1dec54e4aec3 1711 * @arg RTC_SmoothCalibPlusPulses_Reset: No RTCCLK pulses are added.
mbed_official 130:1dec54e4aec3 1712 * @param RTC_SmouthCalibMinusPulsesValue: Select the value of CALM[8:0] bits.
mbed_official 130:1dec54e4aec3 1713 * This parameter can be one any value from 0 to 0x000001FF.
mbed_official 130:1dec54e4aec3 1714 * @retval An ErrorStatus enumeration value:
mbed_official 130:1dec54e4aec3 1715 * - SUCCESS: RTC Calib registers are configured
mbed_official 130:1dec54e4aec3 1716 * - ERROR: RTC Calib registers are not configured
mbed_official 130:1dec54e4aec3 1717 */
mbed_official 130:1dec54e4aec3 1718 ErrorStatus RTC_SmoothCalibConfig(uint32_t RTC_SmoothCalibPeriod,
mbed_official 130:1dec54e4aec3 1719 uint32_t RTC_SmoothCalibPlusPulses,
mbed_official 130:1dec54e4aec3 1720 uint32_t RTC_SmouthCalibMinusPulsesValue)
mbed_official 130:1dec54e4aec3 1721 {
mbed_official 130:1dec54e4aec3 1722 ErrorStatus status = ERROR;
mbed_official 130:1dec54e4aec3 1723 uint32_t recalpfcount = 0;
mbed_official 130:1dec54e4aec3 1724
mbed_official 130:1dec54e4aec3 1725 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1726 assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(RTC_SmoothCalibPeriod));
mbed_official 130:1dec54e4aec3 1727 assert_param(IS_RTC_SMOOTH_CALIB_PLUS(RTC_SmoothCalibPlusPulses));
mbed_official 130:1dec54e4aec3 1728 assert_param(IS_RTC_SMOOTH_CALIB_MINUS(RTC_SmouthCalibMinusPulsesValue));
mbed_official 130:1dec54e4aec3 1729
mbed_official 130:1dec54e4aec3 1730 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1731 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 1732 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 1733
mbed_official 130:1dec54e4aec3 1734 /* check if a calibration is pending*/
mbed_official 130:1dec54e4aec3 1735 if ((RTC->ISR & RTC_ISR_RECALPF) != RESET)
mbed_official 130:1dec54e4aec3 1736 {
mbed_official 130:1dec54e4aec3 1737 /* wait until the Calibration is completed*/
mbed_official 130:1dec54e4aec3 1738 while (((RTC->ISR & RTC_ISR_RECALPF) != RESET) && (recalpfcount != RECALPF_TIMEOUT))
mbed_official 130:1dec54e4aec3 1739 {
mbed_official 130:1dec54e4aec3 1740 recalpfcount++;
mbed_official 130:1dec54e4aec3 1741 }
mbed_official 130:1dec54e4aec3 1742 }
mbed_official 130:1dec54e4aec3 1743
mbed_official 130:1dec54e4aec3 1744 /* check if the calibration pending is completed or if there is no calibration operation at all*/
mbed_official 130:1dec54e4aec3 1745 if ((RTC->ISR & RTC_ISR_RECALPF) == RESET)
mbed_official 130:1dec54e4aec3 1746 {
mbed_official 130:1dec54e4aec3 1747 /* Configure the Smooth calibration settings */
mbed_official 130:1dec54e4aec3 1748 RTC->CALR = (uint32_t)((uint32_t)RTC_SmoothCalibPeriod | (uint32_t)RTC_SmoothCalibPlusPulses | (uint32_t)RTC_SmouthCalibMinusPulsesValue);
mbed_official 130:1dec54e4aec3 1749
mbed_official 130:1dec54e4aec3 1750 status = SUCCESS;
mbed_official 130:1dec54e4aec3 1751 }
mbed_official 130:1dec54e4aec3 1752 else
mbed_official 130:1dec54e4aec3 1753 {
mbed_official 130:1dec54e4aec3 1754 status = ERROR;
mbed_official 130:1dec54e4aec3 1755 }
mbed_official 130:1dec54e4aec3 1756
mbed_official 130:1dec54e4aec3 1757 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1758 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 1759
mbed_official 130:1dec54e4aec3 1760 return (ErrorStatus)(status);
mbed_official 130:1dec54e4aec3 1761 }
mbed_official 130:1dec54e4aec3 1762
mbed_official 130:1dec54e4aec3 1763 /**
mbed_official 130:1dec54e4aec3 1764 * @}
mbed_official 130:1dec54e4aec3 1765 */
mbed_official 130:1dec54e4aec3 1766
mbed_official 130:1dec54e4aec3 1767
mbed_official 130:1dec54e4aec3 1768 /** @defgroup RTC_Group8 TimeStamp configuration functions
mbed_official 130:1dec54e4aec3 1769 * @brief TimeStamp configuration functions
mbed_official 130:1dec54e4aec3 1770 *
mbed_official 130:1dec54e4aec3 1771 @verbatim
mbed_official 130:1dec54e4aec3 1772 ===============================================================================
mbed_official 130:1dec54e4aec3 1773 ##### TimeStamp configuration functions #####
mbed_official 130:1dec54e4aec3 1774 ===============================================================================
mbed_official 130:1dec54e4aec3 1775
mbed_official 130:1dec54e4aec3 1776 @endverbatim
mbed_official 130:1dec54e4aec3 1777 * @{
mbed_official 130:1dec54e4aec3 1778 */
mbed_official 130:1dec54e4aec3 1779
mbed_official 130:1dec54e4aec3 1780 /**
mbed_official 130:1dec54e4aec3 1781 * @brief Enables or Disables the RTC TimeStamp functionality with the
mbed_official 130:1dec54e4aec3 1782 * specified time stamp pin stimulating edge.
mbed_official 130:1dec54e4aec3 1783 * @param RTC_TimeStampEdge: Specifies the pin edge on which the TimeStamp is
mbed_official 130:1dec54e4aec3 1784 * activated.
mbed_official 130:1dec54e4aec3 1785 * This parameter can be one of the following:
mbed_official 130:1dec54e4aec3 1786 * @arg RTC_TimeStampEdge_Rising: the Time stamp event occurs on the rising
mbed_official 130:1dec54e4aec3 1787 * edge of the related pin.
mbed_official 130:1dec54e4aec3 1788 * @arg RTC_TimeStampEdge_Falling: the Time stamp event occurs on the
mbed_official 130:1dec54e4aec3 1789 * falling edge of the related pin.
mbed_official 130:1dec54e4aec3 1790 * @param NewState: new state of the TimeStamp.
mbed_official 130:1dec54e4aec3 1791 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 1792 * @retval None
mbed_official 130:1dec54e4aec3 1793 */
mbed_official 130:1dec54e4aec3 1794 void RTC_TimeStampCmd(uint32_t RTC_TimeStampEdge, FunctionalState NewState)
mbed_official 130:1dec54e4aec3 1795 {
mbed_official 130:1dec54e4aec3 1796 uint32_t tmpreg = 0;
mbed_official 130:1dec54e4aec3 1797
mbed_official 130:1dec54e4aec3 1798 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1799 assert_param(IS_RTC_TIMESTAMP_EDGE(RTC_TimeStampEdge));
mbed_official 130:1dec54e4aec3 1800 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 1801
mbed_official 130:1dec54e4aec3 1802 /* Get the RTC_CR register and clear the bits to be configured */
mbed_official 130:1dec54e4aec3 1803 tmpreg = (uint32_t)(RTC->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
mbed_official 130:1dec54e4aec3 1804
mbed_official 130:1dec54e4aec3 1805 /* Get the new configuration */
mbed_official 130:1dec54e4aec3 1806 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 1807 {
mbed_official 130:1dec54e4aec3 1808 tmpreg |= (uint32_t)(RTC_TimeStampEdge | RTC_CR_TSE);
mbed_official 130:1dec54e4aec3 1809 }
mbed_official 130:1dec54e4aec3 1810 else
mbed_official 130:1dec54e4aec3 1811 {
mbed_official 130:1dec54e4aec3 1812 tmpreg |= (uint32_t)(RTC_TimeStampEdge);
mbed_official 130:1dec54e4aec3 1813 }
mbed_official 130:1dec54e4aec3 1814
mbed_official 130:1dec54e4aec3 1815 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1816 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 1817 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 1818
mbed_official 130:1dec54e4aec3 1819 /* Configure the Time Stamp TSEDGE and Enable bits */
mbed_official 130:1dec54e4aec3 1820 RTC->CR = (uint32_t)tmpreg;
mbed_official 130:1dec54e4aec3 1821
mbed_official 130:1dec54e4aec3 1822 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 1823 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 1824 }
mbed_official 130:1dec54e4aec3 1825
mbed_official 130:1dec54e4aec3 1826 /**
mbed_official 130:1dec54e4aec3 1827 * @brief Get the RTC TimeStamp value and masks.
mbed_official 130:1dec54e4aec3 1828 * @param RTC_Format: specifies the format of the output parameters.
mbed_official 130:1dec54e4aec3 1829 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 1830 * @arg RTC_Format_BIN: Binary data format
mbed_official 130:1dec54e4aec3 1831 * @arg RTC_Format_BCD: BCD data format
mbed_official 130:1dec54e4aec3 1832 * @param RTC_StampTimeStruct: pointer to a RTC_TimeTypeDef structure that will
mbed_official 130:1dec54e4aec3 1833 * contains the TimeStamp time values.
mbed_official 130:1dec54e4aec3 1834 * @param RTC_StampDateStruct: pointer to a RTC_DateTypeDef structure that will
mbed_official 130:1dec54e4aec3 1835 * contains the TimeStamp date values.
mbed_official 130:1dec54e4aec3 1836 * @retval None
mbed_official 130:1dec54e4aec3 1837 */
mbed_official 130:1dec54e4aec3 1838 void RTC_GetTimeStamp(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_StampTimeStruct,
mbed_official 130:1dec54e4aec3 1839 RTC_DateTypeDef* RTC_StampDateStruct)
mbed_official 130:1dec54e4aec3 1840 {
mbed_official 130:1dec54e4aec3 1841 uint32_t tmptime = 0, tmpdate = 0;
mbed_official 130:1dec54e4aec3 1842
mbed_official 130:1dec54e4aec3 1843 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1844 assert_param(IS_RTC_FORMAT(RTC_Format));
mbed_official 130:1dec54e4aec3 1845
mbed_official 130:1dec54e4aec3 1846 /* Get the TimeStamp time and date registers values */
mbed_official 130:1dec54e4aec3 1847 tmptime = (uint32_t)(RTC->TSTR & RTC_TR_RESERVED_MASK);
mbed_official 130:1dec54e4aec3 1848 tmpdate = (uint32_t)(RTC->TSDR & RTC_DR_RESERVED_MASK);
mbed_official 130:1dec54e4aec3 1849
mbed_official 130:1dec54e4aec3 1850 /* Fill the Time structure fields with the read parameters */
mbed_official 130:1dec54e4aec3 1851 RTC_StampTimeStruct->RTC_Hours = (uint8_t)((tmptime & (RTC_TR_HT | RTC_TR_HU)) >> 16);
mbed_official 130:1dec54e4aec3 1852 RTC_StampTimeStruct->RTC_Minutes = (uint8_t)((tmptime & (RTC_TR_MNT | RTC_TR_MNU)) >> 8);
mbed_official 130:1dec54e4aec3 1853 RTC_StampTimeStruct->RTC_Seconds = (uint8_t)(tmptime & (RTC_TR_ST | RTC_TR_SU));
mbed_official 130:1dec54e4aec3 1854 RTC_StampTimeStruct->RTC_H12 = (uint8_t)((tmptime & (RTC_TR_PM)) >> 16);
mbed_official 130:1dec54e4aec3 1855
mbed_official 130:1dec54e4aec3 1856 /* Fill the Date structure fields with the read parameters */
mbed_official 130:1dec54e4aec3 1857 RTC_StampDateStruct->RTC_Year = 0;
mbed_official 130:1dec54e4aec3 1858 RTC_StampDateStruct->RTC_Month = (uint8_t)((tmpdate & (RTC_DR_MT | RTC_DR_MU)) >> 8);
mbed_official 130:1dec54e4aec3 1859 RTC_StampDateStruct->RTC_Date = (uint8_t)(tmpdate & (RTC_DR_DT | RTC_DR_DU));
mbed_official 130:1dec54e4aec3 1860 RTC_StampDateStruct->RTC_WeekDay = (uint8_t)((tmpdate & (RTC_DR_WDU)) >> 13);
mbed_official 130:1dec54e4aec3 1861
mbed_official 130:1dec54e4aec3 1862 /* Check the input parameters format */
mbed_official 130:1dec54e4aec3 1863 if (RTC_Format == RTC_Format_BIN)
mbed_official 130:1dec54e4aec3 1864 {
mbed_official 130:1dec54e4aec3 1865 /* Convert the Time structure parameters to Binary format */
mbed_official 130:1dec54e4aec3 1866 RTC_StampTimeStruct->RTC_Hours = (uint8_t)RTC_Bcd2ToByte(RTC_StampTimeStruct->RTC_Hours);
mbed_official 130:1dec54e4aec3 1867 RTC_StampTimeStruct->RTC_Minutes = (uint8_t)RTC_Bcd2ToByte(RTC_StampTimeStruct->RTC_Minutes);
mbed_official 130:1dec54e4aec3 1868 RTC_StampTimeStruct->RTC_Seconds = (uint8_t)RTC_Bcd2ToByte(RTC_StampTimeStruct->RTC_Seconds);
mbed_official 130:1dec54e4aec3 1869
mbed_official 130:1dec54e4aec3 1870 /* Convert the Date structure parameters to Binary format */
mbed_official 130:1dec54e4aec3 1871 RTC_StampDateStruct->RTC_Month = (uint8_t)RTC_Bcd2ToByte(RTC_StampDateStruct->RTC_Month);
mbed_official 130:1dec54e4aec3 1872 RTC_StampDateStruct->RTC_Date = (uint8_t)RTC_Bcd2ToByte(RTC_StampDateStruct->RTC_Date);
mbed_official 130:1dec54e4aec3 1873 RTC_StampDateStruct->RTC_WeekDay = (uint8_t)RTC_Bcd2ToByte(RTC_StampDateStruct->RTC_WeekDay);
mbed_official 130:1dec54e4aec3 1874 }
mbed_official 130:1dec54e4aec3 1875 }
mbed_official 130:1dec54e4aec3 1876
mbed_official 130:1dec54e4aec3 1877 /**
mbed_official 130:1dec54e4aec3 1878 * @brief Get the RTC timestamp Subseconds value.
mbed_official 130:1dec54e4aec3 1879 * @param None
mbed_official 130:1dec54e4aec3 1880 * @retval RTC current timestamp Subseconds value.
mbed_official 130:1dec54e4aec3 1881 */
mbed_official 130:1dec54e4aec3 1882 uint32_t RTC_GetTimeStampSubSecond(void)
mbed_official 130:1dec54e4aec3 1883 {
mbed_official 130:1dec54e4aec3 1884 /* Get timestamp subseconds values from the correspondent registers */
mbed_official 130:1dec54e4aec3 1885 return (uint32_t)(RTC->TSSSR);
mbed_official 130:1dec54e4aec3 1886 }
mbed_official 130:1dec54e4aec3 1887
mbed_official 130:1dec54e4aec3 1888 /**
mbed_official 130:1dec54e4aec3 1889 * @}
mbed_official 130:1dec54e4aec3 1890 */
mbed_official 130:1dec54e4aec3 1891
mbed_official 130:1dec54e4aec3 1892 /** @defgroup RTC_Group9 Tampers configuration functions
mbed_official 130:1dec54e4aec3 1893 * @brief Tampers configuration functions
mbed_official 130:1dec54e4aec3 1894 *
mbed_official 130:1dec54e4aec3 1895 @verbatim
mbed_official 130:1dec54e4aec3 1896 ===============================================================================
mbed_official 130:1dec54e4aec3 1897 ##### Tampers configuration functions #####
mbed_official 130:1dec54e4aec3 1898 ===============================================================================
mbed_official 130:1dec54e4aec3 1899
mbed_official 130:1dec54e4aec3 1900 @endverbatim
mbed_official 130:1dec54e4aec3 1901 * @{
mbed_official 130:1dec54e4aec3 1902 */
mbed_official 130:1dec54e4aec3 1903
mbed_official 130:1dec54e4aec3 1904 /**
mbed_official 130:1dec54e4aec3 1905 * @brief Configures the select Tamper pin edge.
mbed_official 130:1dec54e4aec3 1906 * @param RTC_Tamper: Selected tamper pin.
mbed_official 130:1dec54e4aec3 1907 * This parameter can be any combination of the following values:
mbed_official 130:1dec54e4aec3 1908 * @arg RTC_Tamper_1: Select Tamper 1.
mbed_official 130:1dec54e4aec3 1909 * @arg RTC_Tamper_2: Select Tamper 2.
mbed_official 130:1dec54e4aec3 1910 * @param RTC_TamperTrigger: Specifies the trigger on the tamper pin that
mbed_official 130:1dec54e4aec3 1911 * stimulates tamper event.
mbed_official 130:1dec54e4aec3 1912 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 1913 * @arg RTC_TamperTrigger_RisingEdge: Rising Edge of the tamper pin causes tamper event.
mbed_official 130:1dec54e4aec3 1914 * @arg RTC_TamperTrigger_FallingEdge: Falling Edge of the tamper pin causes tamper event.
mbed_official 130:1dec54e4aec3 1915 * @arg RTC_TamperTrigger_LowLevel: Low Level of the tamper pin causes tamper event.
mbed_official 130:1dec54e4aec3 1916 * @arg RTC_TamperTrigger_HighLevel: High Level of the tamper pin causes tamper event.
mbed_official 130:1dec54e4aec3 1917 * @retval None
mbed_official 130:1dec54e4aec3 1918 */
mbed_official 130:1dec54e4aec3 1919 void RTC_TamperTriggerConfig(uint32_t RTC_Tamper, uint32_t RTC_TamperTrigger)
mbed_official 130:1dec54e4aec3 1920 {
mbed_official 130:1dec54e4aec3 1921 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1922 assert_param(IS_RTC_TAMPER(RTC_Tamper));
mbed_official 130:1dec54e4aec3 1923 assert_param(IS_RTC_TAMPER_TRIGGER(RTC_TamperTrigger));
mbed_official 130:1dec54e4aec3 1924
mbed_official 130:1dec54e4aec3 1925 if (RTC_TamperTrigger == RTC_TamperTrigger_RisingEdge)
mbed_official 130:1dec54e4aec3 1926 {
mbed_official 130:1dec54e4aec3 1927 /* Configure the RTC_TAFCR register */
mbed_official 130:1dec54e4aec3 1928 RTC->TAFCR &= (uint32_t)((uint32_t)~(RTC_Tamper << 1));
mbed_official 130:1dec54e4aec3 1929 }
mbed_official 130:1dec54e4aec3 1930 else
mbed_official 130:1dec54e4aec3 1931 {
mbed_official 130:1dec54e4aec3 1932 /* Configure the RTC_TAFCR register */
mbed_official 130:1dec54e4aec3 1933 RTC->TAFCR |= (uint32_t)(RTC_Tamper << 1);
mbed_official 130:1dec54e4aec3 1934 }
mbed_official 130:1dec54e4aec3 1935 }
mbed_official 130:1dec54e4aec3 1936
mbed_official 130:1dec54e4aec3 1937 /**
mbed_official 130:1dec54e4aec3 1938 * @brief Enables or Disables the Tamper detection.
mbed_official 130:1dec54e4aec3 1939 * @param RTC_Tamper: Selected tamper pin.
mbed_official 130:1dec54e4aec3 1940 * This parameter can be any combination of the following values:
mbed_official 130:1dec54e4aec3 1941 * @arg RTC_Tamper_1: Select Tamper 1.
mbed_official 130:1dec54e4aec3 1942 * @arg RTC_Tamper_2: Select Tamper 2.
mbed_official 130:1dec54e4aec3 1943 * @param NewState: new state of the tamper pin.
mbed_official 130:1dec54e4aec3 1944 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 1945 * @retval None
mbed_official 130:1dec54e4aec3 1946 */
mbed_official 130:1dec54e4aec3 1947 void RTC_TamperCmd(uint32_t RTC_Tamper, FunctionalState NewState)
mbed_official 130:1dec54e4aec3 1948 {
mbed_official 130:1dec54e4aec3 1949 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1950 assert_param(IS_RTC_TAMPER(RTC_Tamper));
mbed_official 130:1dec54e4aec3 1951 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 1952
mbed_official 130:1dec54e4aec3 1953 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 1954 {
mbed_official 130:1dec54e4aec3 1955 /* Enable the selected Tamper pin */
mbed_official 130:1dec54e4aec3 1956 RTC->TAFCR |= (uint32_t)RTC_Tamper;
mbed_official 130:1dec54e4aec3 1957 }
mbed_official 130:1dec54e4aec3 1958 else
mbed_official 130:1dec54e4aec3 1959 {
mbed_official 130:1dec54e4aec3 1960 /* Disable the selected Tamper pin */
mbed_official 130:1dec54e4aec3 1961 RTC->TAFCR &= (uint32_t)~RTC_Tamper;
mbed_official 130:1dec54e4aec3 1962 }
mbed_official 130:1dec54e4aec3 1963 }
mbed_official 130:1dec54e4aec3 1964
mbed_official 130:1dec54e4aec3 1965 /**
mbed_official 130:1dec54e4aec3 1966 * @brief Configures the Tampers Filter.
mbed_official 130:1dec54e4aec3 1967 * @param RTC_TamperFilter: Specifies the tampers filter.
mbed_official 130:1dec54e4aec3 1968 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 1969 * @arg RTC_TamperFilter_Disable: Tamper filter is disabled.
mbed_official 130:1dec54e4aec3 1970 * @arg RTC_TamperFilter_2Sample: Tamper is activated after 2 consecutive
mbed_official 130:1dec54e4aec3 1971 * samples at the active level
mbed_official 130:1dec54e4aec3 1972 * @arg RTC_TamperFilter_4Sample: Tamper is activated after 4 consecutive
mbed_official 130:1dec54e4aec3 1973 * samples at the active level
mbed_official 130:1dec54e4aec3 1974 * @arg RTC_TamperFilter_8Sample: Tamper is activated after 8 consecutive
mbed_official 130:1dec54e4aec3 1975 * samples at the active level
mbed_official 130:1dec54e4aec3 1976 * @retval None
mbed_official 130:1dec54e4aec3 1977 */
mbed_official 130:1dec54e4aec3 1978 void RTC_TamperFilterConfig(uint32_t RTC_TamperFilter)
mbed_official 130:1dec54e4aec3 1979 {
mbed_official 130:1dec54e4aec3 1980 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1981 assert_param(IS_RTC_TAMPER_FILTER(RTC_TamperFilter));
mbed_official 130:1dec54e4aec3 1982
mbed_official 130:1dec54e4aec3 1983 /* Clear TAMPFLT[1:0] bits in the RTC_TAFCR register */
mbed_official 130:1dec54e4aec3 1984 RTC->TAFCR &= (uint32_t)~(RTC_TAFCR_TAMPFLT);
mbed_official 130:1dec54e4aec3 1985
mbed_official 130:1dec54e4aec3 1986 /* Configure the RTC_TAFCR register */
mbed_official 130:1dec54e4aec3 1987 RTC->TAFCR |= (uint32_t)RTC_TamperFilter;
mbed_official 130:1dec54e4aec3 1988 }
mbed_official 130:1dec54e4aec3 1989
mbed_official 130:1dec54e4aec3 1990 /**
mbed_official 130:1dec54e4aec3 1991 * @brief Configures the Tampers Sampling Frequency.
mbed_official 130:1dec54e4aec3 1992 * @param RTC_TamperSamplingFreq: Specifies the tampers Sampling Frequency.
mbed_official 130:1dec54e4aec3 1993 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 1994 * @arg RTC_TamperSamplingFreq_RTCCLK_Div32768: Each of the tamper inputs are sampled
mbed_official 130:1dec54e4aec3 1995 * with a frequency = RTCCLK / 32768
mbed_official 130:1dec54e4aec3 1996 * @arg RTC_TamperSamplingFreq_RTCCLK_Div16384: Each of the tamper inputs are sampled
mbed_official 130:1dec54e4aec3 1997 * with a frequency = RTCCLK / 16384
mbed_official 130:1dec54e4aec3 1998 * @arg RTC_TamperSamplingFreq_RTCCLK_Div8192: Each of the tamper inputs are sampled
mbed_official 130:1dec54e4aec3 1999 * with a frequency = RTCCLK / 8192
mbed_official 130:1dec54e4aec3 2000 * @arg RTC_TamperSamplingFreq_RTCCLK_Div4096: Each of the tamper inputs are sampled
mbed_official 130:1dec54e4aec3 2001 * with a frequency = RTCCLK / 4096
mbed_official 130:1dec54e4aec3 2002 * @arg RTC_TamperSamplingFreq_RTCCLK_Div2048: Each of the tamper inputs are sampled
mbed_official 130:1dec54e4aec3 2003 * with a frequency = RTCCLK / 2048
mbed_official 130:1dec54e4aec3 2004 * @arg RTC_TamperSamplingFreq_RTCCLK_Div1024: Each of the tamper inputs are sampled
mbed_official 130:1dec54e4aec3 2005 * with a frequency = RTCCLK / 1024
mbed_official 130:1dec54e4aec3 2006 * @arg RTC_TamperSamplingFreq_RTCCLK_Div512: Each of the tamper inputs are sampled
mbed_official 130:1dec54e4aec3 2007 * with a frequency = RTCCLK / 512
mbed_official 130:1dec54e4aec3 2008 * @arg RTC_TamperSamplingFreq_RTCCLK_Div256: Each of the tamper inputs are sampled
mbed_official 130:1dec54e4aec3 2009 * with a frequency = RTCCLK / 256
mbed_official 130:1dec54e4aec3 2010 * @retval None
mbed_official 130:1dec54e4aec3 2011 */
mbed_official 130:1dec54e4aec3 2012 void RTC_TamperSamplingFreqConfig(uint32_t RTC_TamperSamplingFreq)
mbed_official 130:1dec54e4aec3 2013 {
mbed_official 130:1dec54e4aec3 2014 /* Check the parameters */
mbed_official 130:1dec54e4aec3 2015 assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(RTC_TamperSamplingFreq));
mbed_official 130:1dec54e4aec3 2016
mbed_official 130:1dec54e4aec3 2017 /* Clear TAMPFREQ[2:0] bits in the RTC_TAFCR register */
mbed_official 130:1dec54e4aec3 2018 RTC->TAFCR &= (uint32_t)~(RTC_TAFCR_TAMPFREQ);
mbed_official 130:1dec54e4aec3 2019
mbed_official 130:1dec54e4aec3 2020 /* Configure the RTC_TAFCR register */
mbed_official 130:1dec54e4aec3 2021 RTC->TAFCR |= (uint32_t)RTC_TamperSamplingFreq;
mbed_official 130:1dec54e4aec3 2022 }
mbed_official 130:1dec54e4aec3 2023
mbed_official 130:1dec54e4aec3 2024 /**
mbed_official 130:1dec54e4aec3 2025 * @brief Configures the Tampers Pins input Precharge Duration.
mbed_official 130:1dec54e4aec3 2026 * @param RTC_TamperPrechargeDuration: Specifies the Tampers Pins input
mbed_official 130:1dec54e4aec3 2027 * Precharge Duration.
mbed_official 130:1dec54e4aec3 2028 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 2029 * @arg RTC_TamperPrechargeDuration_1RTCCLK: Tamper pins are pre-charged before sampling during 1 RTCCLK cycle
mbed_official 130:1dec54e4aec3 2030 * @arg RTC_TamperPrechargeDuration_2RTCCLK: Tamper pins are pre-charged before sampling during 2 RTCCLK cycle
mbed_official 130:1dec54e4aec3 2031 * @arg RTC_TamperPrechargeDuration_4RTCCLK: Tamper pins are pre-charged before sampling during 4 RTCCLK cycle
mbed_official 130:1dec54e4aec3 2032 * @arg RTC_TamperPrechargeDuration_8RTCCLK: Tamper pins are pre-charged before sampling during 8 RTCCLK cycle
mbed_official 130:1dec54e4aec3 2033 * @retval None
mbed_official 130:1dec54e4aec3 2034 */
mbed_official 130:1dec54e4aec3 2035 void RTC_TamperPinsPrechargeDuration(uint32_t RTC_TamperPrechargeDuration)
mbed_official 130:1dec54e4aec3 2036 {
mbed_official 130:1dec54e4aec3 2037 /* Check the parameters */
mbed_official 130:1dec54e4aec3 2038 assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(RTC_TamperPrechargeDuration));
mbed_official 130:1dec54e4aec3 2039
mbed_official 130:1dec54e4aec3 2040 /* Clear TAMPPRCH[1:0] bits in the RTC_TAFCR register */
mbed_official 130:1dec54e4aec3 2041 RTC->TAFCR &= (uint32_t)~(RTC_TAFCR_TAMPPRCH);
mbed_official 130:1dec54e4aec3 2042
mbed_official 130:1dec54e4aec3 2043 /* Configure the RTC_TAFCR register */
mbed_official 130:1dec54e4aec3 2044 RTC->TAFCR |= (uint32_t)RTC_TamperPrechargeDuration;
mbed_official 130:1dec54e4aec3 2045 }
mbed_official 130:1dec54e4aec3 2046
mbed_official 130:1dec54e4aec3 2047 /**
mbed_official 130:1dec54e4aec3 2048 * @brief Enables or Disables the TimeStamp on Tamper Detection Event.
mbed_official 130:1dec54e4aec3 2049 * @note The timestamp is valid even the TSE bit in tamper control register
mbed_official 130:1dec54e4aec3 2050 * is reset.
mbed_official 130:1dec54e4aec3 2051 * @param NewState: new state of the timestamp on tamper event.
mbed_official 130:1dec54e4aec3 2052 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 2053 * @retval None
mbed_official 130:1dec54e4aec3 2054 */
mbed_official 130:1dec54e4aec3 2055 void RTC_TimeStampOnTamperDetectionCmd(FunctionalState NewState)
mbed_official 130:1dec54e4aec3 2056 {
mbed_official 130:1dec54e4aec3 2057 /* Check the parameters */
mbed_official 130:1dec54e4aec3 2058 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 2059
mbed_official 130:1dec54e4aec3 2060 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 2061 {
mbed_official 130:1dec54e4aec3 2062 /* Save timestamp on tamper detection event */
mbed_official 130:1dec54e4aec3 2063 RTC->TAFCR |= (uint32_t)RTC_TAFCR_TAMPTS;
mbed_official 130:1dec54e4aec3 2064 }
mbed_official 130:1dec54e4aec3 2065 else
mbed_official 130:1dec54e4aec3 2066 {
mbed_official 130:1dec54e4aec3 2067 /* Tamper detection does not cause a timestamp to be saved */
mbed_official 130:1dec54e4aec3 2068 RTC->TAFCR &= (uint32_t)~RTC_TAFCR_TAMPTS;
mbed_official 130:1dec54e4aec3 2069 }
mbed_official 130:1dec54e4aec3 2070 }
mbed_official 130:1dec54e4aec3 2071
mbed_official 130:1dec54e4aec3 2072 /**
mbed_official 130:1dec54e4aec3 2073 * @brief Enables or Disables the Precharge of Tamper pin.
mbed_official 130:1dec54e4aec3 2074 * @param NewState: new state of tamper pull up.
mbed_official 130:1dec54e4aec3 2075 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 2076 * @retval None
mbed_official 130:1dec54e4aec3 2077 */
mbed_official 130:1dec54e4aec3 2078 void RTC_TamperPullUpCmd(FunctionalState NewState)
mbed_official 130:1dec54e4aec3 2079 {
mbed_official 130:1dec54e4aec3 2080 /* Check the parameters */
mbed_official 130:1dec54e4aec3 2081 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 2082
mbed_official 130:1dec54e4aec3 2083 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 2084 {
mbed_official 130:1dec54e4aec3 2085 /* Enable precharge of the selected Tamper pin */
mbed_official 130:1dec54e4aec3 2086 RTC->TAFCR &= (uint32_t)~RTC_TAFCR_TAMPPUDIS;
mbed_official 130:1dec54e4aec3 2087 }
mbed_official 130:1dec54e4aec3 2088 else
mbed_official 130:1dec54e4aec3 2089 {
mbed_official 130:1dec54e4aec3 2090 /* Disable precharge of the selected Tamper pin */
mbed_official 130:1dec54e4aec3 2091 RTC->TAFCR |= (uint32_t)RTC_TAFCR_TAMPPUDIS;
mbed_official 130:1dec54e4aec3 2092 }
mbed_official 130:1dec54e4aec3 2093 }
mbed_official 130:1dec54e4aec3 2094
mbed_official 130:1dec54e4aec3 2095 /**
mbed_official 130:1dec54e4aec3 2096 * @}
mbed_official 130:1dec54e4aec3 2097 */
mbed_official 130:1dec54e4aec3 2098
mbed_official 130:1dec54e4aec3 2099 /** @defgroup RTC_Group10 Backup Data Registers configuration functions
mbed_official 130:1dec54e4aec3 2100 * @brief Backup Data Registers configuration functions
mbed_official 130:1dec54e4aec3 2101 *
mbed_official 130:1dec54e4aec3 2102 @verbatim
mbed_official 130:1dec54e4aec3 2103 ===============================================================================
mbed_official 130:1dec54e4aec3 2104 ##### Backup Data Registers configuration functions #####
mbed_official 130:1dec54e4aec3 2105 ===============================================================================
mbed_official 130:1dec54e4aec3 2106
mbed_official 130:1dec54e4aec3 2107 @endverbatim
mbed_official 130:1dec54e4aec3 2108 * @{
mbed_official 130:1dec54e4aec3 2109 */
mbed_official 130:1dec54e4aec3 2110
mbed_official 130:1dec54e4aec3 2111 /**
mbed_official 130:1dec54e4aec3 2112 * @brief Writes a data in a specified RTC Backup data register.
mbed_official 130:1dec54e4aec3 2113 * @param RTC_BKP_DR: RTC Backup data Register number.
mbed_official 130:1dec54e4aec3 2114 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 4 to
mbed_official 130:1dec54e4aec3 2115 * specify the register.
mbed_official 130:1dec54e4aec3 2116 * @param Data: Data to be written in the specified RTC Backup data register.
mbed_official 130:1dec54e4aec3 2117 * @retval None
mbed_official 130:1dec54e4aec3 2118 */
mbed_official 130:1dec54e4aec3 2119 void RTC_WriteBackupRegister(uint32_t RTC_BKP_DR, uint32_t Data)
mbed_official 130:1dec54e4aec3 2120 {
mbed_official 130:1dec54e4aec3 2121 __IO uint32_t tmp = 0;
mbed_official 130:1dec54e4aec3 2122
mbed_official 130:1dec54e4aec3 2123 /* Check the parameters */
mbed_official 130:1dec54e4aec3 2124 assert_param(IS_RTC_BKP(RTC_BKP_DR));
mbed_official 130:1dec54e4aec3 2125
mbed_official 130:1dec54e4aec3 2126 tmp = RTC_BASE + 0x50;
mbed_official 130:1dec54e4aec3 2127 tmp += (RTC_BKP_DR * 4);
mbed_official 130:1dec54e4aec3 2128
mbed_official 130:1dec54e4aec3 2129 /* Write the specified register */
mbed_official 130:1dec54e4aec3 2130 *(__IO uint32_t *)tmp = (uint32_t)Data;
mbed_official 130:1dec54e4aec3 2131 }
mbed_official 130:1dec54e4aec3 2132
mbed_official 130:1dec54e4aec3 2133 /**
mbed_official 130:1dec54e4aec3 2134 * @brief Reads data from the specified RTC Backup data Register.
mbed_official 130:1dec54e4aec3 2135 * @param RTC_BKP_DR: RTC Backup data Register number.
mbed_official 130:1dec54e4aec3 2136 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to
mbed_official 130:1dec54e4aec3 2137 * specify the register.
mbed_official 130:1dec54e4aec3 2138 * @retval None
mbed_official 130:1dec54e4aec3 2139 */
mbed_official 130:1dec54e4aec3 2140 uint32_t RTC_ReadBackupRegister(uint32_t RTC_BKP_DR)
mbed_official 130:1dec54e4aec3 2141 {
mbed_official 130:1dec54e4aec3 2142 __IO uint32_t tmp = 0;
mbed_official 130:1dec54e4aec3 2143
mbed_official 130:1dec54e4aec3 2144 /* Check the parameters */
mbed_official 130:1dec54e4aec3 2145 assert_param(IS_RTC_BKP(RTC_BKP_DR));
mbed_official 130:1dec54e4aec3 2146
mbed_official 130:1dec54e4aec3 2147 tmp = RTC_BASE + 0x50;
mbed_official 130:1dec54e4aec3 2148 tmp += (RTC_BKP_DR * 4);
mbed_official 130:1dec54e4aec3 2149
mbed_official 130:1dec54e4aec3 2150 /* Read the specified register */
mbed_official 130:1dec54e4aec3 2151 return (*(__IO uint32_t *)tmp);
mbed_official 130:1dec54e4aec3 2152 }
mbed_official 130:1dec54e4aec3 2153
mbed_official 130:1dec54e4aec3 2154 /**
mbed_official 130:1dec54e4aec3 2155 * @}
mbed_official 130:1dec54e4aec3 2156 */
mbed_official 130:1dec54e4aec3 2157
mbed_official 130:1dec54e4aec3 2158 /** @defgroup RTC_Group11 Output Type Config configuration functions
mbed_official 130:1dec54e4aec3 2159 * @brief Output Type Config configuration functions
mbed_official 130:1dec54e4aec3 2160 *
mbed_official 130:1dec54e4aec3 2161 @verbatim
mbed_official 130:1dec54e4aec3 2162 ===============================================================================
mbed_official 130:1dec54e4aec3 2163 ##### Output Type Config configuration functions #####
mbed_official 130:1dec54e4aec3 2164 ===============================================================================
mbed_official 130:1dec54e4aec3 2165
mbed_official 130:1dec54e4aec3 2166 @endverbatim
mbed_official 130:1dec54e4aec3 2167 * @{
mbed_official 130:1dec54e4aec3 2168 */
mbed_official 130:1dec54e4aec3 2169
mbed_official 130:1dec54e4aec3 2170 /**
mbed_official 130:1dec54e4aec3 2171 * @brief Configures the RTC Output Pin mode.
mbed_official 130:1dec54e4aec3 2172 * @param RTC_OutputType: specifies the RTC Output (PC13) pin mode.
mbed_official 130:1dec54e4aec3 2173 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 2174 * @arg RTC_OutputType_OpenDrain: RTC Output (PC13) is configured in
mbed_official 130:1dec54e4aec3 2175 * Open Drain mode.
mbed_official 130:1dec54e4aec3 2176 * @arg RTC_OutputType_PushPull: RTC Output (PC13) is configured in
mbed_official 130:1dec54e4aec3 2177 * Push Pull mode.
mbed_official 130:1dec54e4aec3 2178 * @retval None
mbed_official 130:1dec54e4aec3 2179 */
mbed_official 130:1dec54e4aec3 2180 void RTC_OutputTypeConfig(uint32_t RTC_OutputType)
mbed_official 130:1dec54e4aec3 2181 {
mbed_official 130:1dec54e4aec3 2182 /* Check the parameters */
mbed_official 130:1dec54e4aec3 2183 assert_param(IS_RTC_OUTPUT_TYPE(RTC_OutputType));
mbed_official 130:1dec54e4aec3 2184
mbed_official 130:1dec54e4aec3 2185 RTC->TAFCR &= (uint32_t)~(RTC_TAFCR_ALARMOUTTYPE);
mbed_official 130:1dec54e4aec3 2186 RTC->TAFCR |= (uint32_t)(RTC_OutputType);
mbed_official 130:1dec54e4aec3 2187 }
mbed_official 130:1dec54e4aec3 2188
mbed_official 130:1dec54e4aec3 2189 /**
mbed_official 130:1dec54e4aec3 2190 * @}
mbed_official 130:1dec54e4aec3 2191 */
mbed_official 130:1dec54e4aec3 2192
mbed_official 130:1dec54e4aec3 2193 /** @defgroup RTC_Group12 Shift control synchronisation functions
mbed_official 130:1dec54e4aec3 2194 * @brief Shift control synchronisation functions
mbed_official 130:1dec54e4aec3 2195 *
mbed_official 130:1dec54e4aec3 2196 @verbatim
mbed_official 130:1dec54e4aec3 2197 ===============================================================================
mbed_official 130:1dec54e4aec3 2198 ##### Shift control synchronisation functions #####
mbed_official 130:1dec54e4aec3 2199 ===============================================================================
mbed_official 130:1dec54e4aec3 2200
mbed_official 130:1dec54e4aec3 2201 @endverbatim
mbed_official 130:1dec54e4aec3 2202 * @{
mbed_official 130:1dec54e4aec3 2203 */
mbed_official 130:1dec54e4aec3 2204
mbed_official 130:1dec54e4aec3 2205 /**
mbed_official 130:1dec54e4aec3 2206 * @brief Configures the Synchronization Shift Control Settings.
mbed_official 130:1dec54e4aec3 2207 * @note When REFCKON is set, firmware must not write to Shift control register
mbed_official 130:1dec54e4aec3 2208 * @param RTC_ShiftAdd1S: Select to add or not 1 second to the time Calendar.
mbed_official 130:1dec54e4aec3 2209 * This parameter can be one of the following values :
mbed_official 130:1dec54e4aec3 2210 * @arg RTC_ShiftAdd1S_Set: Add one second to the clock calendar.
mbed_official 130:1dec54e4aec3 2211 * @arg RTC_ShiftAdd1S_Reset: No effect.
mbed_official 130:1dec54e4aec3 2212 * @param RTC_ShiftSubFS: Select the number of Second Fractions to Substitute.
mbed_official 130:1dec54e4aec3 2213 * This parameter can be one any value from 0 to 0x7FFF.
mbed_official 130:1dec54e4aec3 2214 * @retval An ErrorStatus enumeration value:
mbed_official 130:1dec54e4aec3 2215 * - SUCCESS: RTC Shift registers are configured
mbed_official 130:1dec54e4aec3 2216 * - ERROR: RTC Shift registers are not configured
mbed_official 130:1dec54e4aec3 2217 */
mbed_official 130:1dec54e4aec3 2218 ErrorStatus RTC_SynchroShiftConfig(uint32_t RTC_ShiftAdd1S, uint32_t RTC_ShiftSubFS)
mbed_official 130:1dec54e4aec3 2219 {
mbed_official 130:1dec54e4aec3 2220 ErrorStatus status = ERROR;
mbed_official 130:1dec54e4aec3 2221 uint32_t shpfcount = 0;
mbed_official 130:1dec54e4aec3 2222
mbed_official 130:1dec54e4aec3 2223 /* Check the parameters */
mbed_official 130:1dec54e4aec3 2224 assert_param(IS_RTC_SHIFT_ADD1S(RTC_ShiftAdd1S));
mbed_official 130:1dec54e4aec3 2225 assert_param(IS_RTC_SHIFT_SUBFS(RTC_ShiftSubFS));
mbed_official 130:1dec54e4aec3 2226
mbed_official 130:1dec54e4aec3 2227 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 2228 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 2229 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 2230
mbed_official 130:1dec54e4aec3 2231 /* Check if a Shift is pending*/
mbed_official 130:1dec54e4aec3 2232 if ((RTC->ISR & RTC_ISR_SHPF) != RESET)
mbed_official 130:1dec54e4aec3 2233 {
mbed_official 130:1dec54e4aec3 2234 /* Wait until the shift is completed*/
mbed_official 130:1dec54e4aec3 2235 while (((RTC->ISR & RTC_ISR_SHPF) != RESET) && (shpfcount != SHPF_TIMEOUT))
mbed_official 130:1dec54e4aec3 2236 {
mbed_official 130:1dec54e4aec3 2237 shpfcount++;
mbed_official 130:1dec54e4aec3 2238 }
mbed_official 130:1dec54e4aec3 2239 }
mbed_official 130:1dec54e4aec3 2240
mbed_official 130:1dec54e4aec3 2241 /* Check if the Shift pending is completed or if there is no Shift operation at all*/
mbed_official 130:1dec54e4aec3 2242 if ((RTC->ISR & RTC_ISR_SHPF) == RESET)
mbed_official 130:1dec54e4aec3 2243 {
mbed_official 130:1dec54e4aec3 2244 /* check if the reference clock detection is disabled */
mbed_official 130:1dec54e4aec3 2245 if((RTC->CR & RTC_CR_REFCKON) == RESET)
mbed_official 130:1dec54e4aec3 2246 {
mbed_official 130:1dec54e4aec3 2247 /* Configure the Shift settings */
mbed_official 130:1dec54e4aec3 2248 RTC->SHIFTR = (uint32_t)(uint32_t)(RTC_ShiftSubFS) | (uint32_t)(RTC_ShiftAdd1S);
mbed_official 130:1dec54e4aec3 2249
mbed_official 130:1dec54e4aec3 2250 if(RTC_WaitForSynchro() == ERROR)
mbed_official 130:1dec54e4aec3 2251 {
mbed_official 130:1dec54e4aec3 2252 status = ERROR;
mbed_official 130:1dec54e4aec3 2253 }
mbed_official 130:1dec54e4aec3 2254 else
mbed_official 130:1dec54e4aec3 2255 {
mbed_official 130:1dec54e4aec3 2256 status = SUCCESS;
mbed_official 130:1dec54e4aec3 2257 }
mbed_official 130:1dec54e4aec3 2258 }
mbed_official 130:1dec54e4aec3 2259 else
mbed_official 130:1dec54e4aec3 2260 {
mbed_official 130:1dec54e4aec3 2261 status = ERROR;
mbed_official 130:1dec54e4aec3 2262 }
mbed_official 130:1dec54e4aec3 2263 }
mbed_official 130:1dec54e4aec3 2264 else
mbed_official 130:1dec54e4aec3 2265 {
mbed_official 130:1dec54e4aec3 2266 status = ERROR;
mbed_official 130:1dec54e4aec3 2267 }
mbed_official 130:1dec54e4aec3 2268
mbed_official 130:1dec54e4aec3 2269 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 2270 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 2271
mbed_official 130:1dec54e4aec3 2272 return (ErrorStatus)(status);
mbed_official 130:1dec54e4aec3 2273 }
mbed_official 130:1dec54e4aec3 2274
mbed_official 130:1dec54e4aec3 2275 /**
mbed_official 130:1dec54e4aec3 2276 * @}
mbed_official 130:1dec54e4aec3 2277 */
mbed_official 130:1dec54e4aec3 2278
mbed_official 130:1dec54e4aec3 2279 /** @defgroup RTC_Group13 Interrupts and flags management functions
mbed_official 130:1dec54e4aec3 2280 * @brief Interrupts and flags management functions
mbed_official 130:1dec54e4aec3 2281 *
mbed_official 130:1dec54e4aec3 2282 @verbatim
mbed_official 130:1dec54e4aec3 2283 ===============================================================================
mbed_official 130:1dec54e4aec3 2284 ##### Interrupts and flags management functions #####
mbed_official 130:1dec54e4aec3 2285 ===============================================================================
mbed_official 130:1dec54e4aec3 2286 [..] All RTC interrupts are connected to the EXTI controller.
mbed_official 130:1dec54e4aec3 2287
mbed_official 130:1dec54e4aec3 2288 (+) To enable the RTC Alarm interrupt, the following sequence is required:
mbed_official 130:1dec54e4aec3 2289 (++) Configure and enable the EXTI Line 17 in interrupt mode and select the rising
mbed_official 130:1dec54e4aec3 2290 edge sensitivity using the EXTI_Init() function.
mbed_official 130:1dec54e4aec3 2291 (++) Configure and enable the RTC_Alarm IRQ channel in the NVIC using the NVIC_Init()
mbed_official 130:1dec54e4aec3 2292 function.
mbed_official 130:1dec54e4aec3 2293 (++) Configure the RTC to generate RTC alarms (Alarm A) using
mbed_official 130:1dec54e4aec3 2294 the RTC_SetAlarm() and RTC_AlarmCmd() functions.
mbed_official 130:1dec54e4aec3 2295
mbed_official 130:1dec54e4aec3 2296 (+) To enable the RTC Tamper interrupt, the following sequence is required:
mbed_official 130:1dec54e4aec3 2297 (++) Configure and enable the EXTI Line 19 in interrupt mode and select the rising
mbed_official 130:1dec54e4aec3 2298 edge sensitivity using the EXTI_Init() function.
mbed_official 130:1dec54e4aec3 2299 (++) Configure and enable the TAMP_STAMP IRQ channel in the NVIC using the NVIC_Init()
mbed_official 130:1dec54e4aec3 2300 function.
mbed_official 130:1dec54e4aec3 2301 (++) Configure the RTC to detect the RTC tamper event using the
mbed_official 130:1dec54e4aec3 2302 RTC_TamperTriggerConfig() and RTC_TamperCmd() functions.
mbed_official 130:1dec54e4aec3 2303
mbed_official 130:1dec54e4aec3 2304 (+) To enable the RTC TimeStamp interrupt, the following sequence is required:
mbed_official 130:1dec54e4aec3 2305 (++) Configure and enable the EXTI Line 19 in interrupt mode and select the rising
mbed_official 130:1dec54e4aec3 2306 edge sensitivity using the EXTI_Init() function.
mbed_official 130:1dec54e4aec3 2307 (++) Configure and enable the TAMP_STAMP IRQ channel in the NVIC using the NVIC_Init()
mbed_official 130:1dec54e4aec3 2308 function.
mbed_official 130:1dec54e4aec3 2309 (++) Configure the RTC to detect the RTC time-stamp event using the
mbed_official 130:1dec54e4aec3 2310 RTC_TimeStampCmd() functions.
mbed_official 130:1dec54e4aec3 2311
mbed_official 130:1dec54e4aec3 2312 @endverbatim
mbed_official 130:1dec54e4aec3 2313 * @{
mbed_official 130:1dec54e4aec3 2314 */
mbed_official 130:1dec54e4aec3 2315
mbed_official 130:1dec54e4aec3 2316 /**
mbed_official 130:1dec54e4aec3 2317 * @brief Enables or disables the specified RTC interrupts.
mbed_official 130:1dec54e4aec3 2318 * @param RTC_IT: specifies the RTC interrupt sources to be enabled or disabled.
mbed_official 130:1dec54e4aec3 2319 * This parameter can be any combination of the following values:
mbed_official 130:1dec54e4aec3 2320 * @arg RTC_IT_TS: Time Stamp interrupt mask
mbed_official 130:1dec54e4aec3 2321 * @arg RTC_IT_WUT: WakeUp Timer interrupt mask, available only for STM32F072 devices
mbed_official 130:1dec54e4aec3 2322 * @arg RTC_IT_ALRA: Alarm A interrupt mask
mbed_official 130:1dec54e4aec3 2323 * @arg RTC_IT_TAMP: Tamper event interrupt mask
mbed_official 130:1dec54e4aec3 2324 * @param NewState: new state of the specified RTC interrupts.
mbed_official 130:1dec54e4aec3 2325 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 2326 * @retval None
mbed_official 130:1dec54e4aec3 2327 */
mbed_official 130:1dec54e4aec3 2328 void RTC_ITConfig(uint32_t RTC_IT, FunctionalState NewState)
mbed_official 130:1dec54e4aec3 2329 {
mbed_official 130:1dec54e4aec3 2330 /* Check the parameters */
mbed_official 130:1dec54e4aec3 2331 assert_param(IS_RTC_CONFIG_IT(RTC_IT));
mbed_official 130:1dec54e4aec3 2332 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 2333
mbed_official 130:1dec54e4aec3 2334 /* Disable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 2335 RTC->WPR = 0xCA;
mbed_official 130:1dec54e4aec3 2336 RTC->WPR = 0x53;
mbed_official 130:1dec54e4aec3 2337
mbed_official 130:1dec54e4aec3 2338 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 2339 {
mbed_official 130:1dec54e4aec3 2340 /* Configure the Interrupts in the RTC_CR register */
mbed_official 130:1dec54e4aec3 2341 RTC->CR |= (uint32_t)(RTC_IT & ~RTC_TAFCR_TAMPIE);
mbed_official 130:1dec54e4aec3 2342 /* Configure the Tamper Interrupt in the RTC_TAFCR */
mbed_official 130:1dec54e4aec3 2343 RTC->TAFCR |= (uint32_t)(RTC_IT & RTC_TAFCR_TAMPIE);
mbed_official 130:1dec54e4aec3 2344 }
mbed_official 130:1dec54e4aec3 2345 else
mbed_official 130:1dec54e4aec3 2346 {
mbed_official 130:1dec54e4aec3 2347 /* Configure the Interrupts in the RTC_CR register */
mbed_official 130:1dec54e4aec3 2348 RTC->CR &= (uint32_t)~(RTC_IT & (uint32_t)~RTC_TAFCR_TAMPIE);
mbed_official 130:1dec54e4aec3 2349 /* Configure the Tamper Interrupt in the RTC_TAFCR */
mbed_official 130:1dec54e4aec3 2350 RTC->TAFCR &= (uint32_t)~(RTC_IT & RTC_TAFCR_TAMPIE);
mbed_official 130:1dec54e4aec3 2351 }
mbed_official 130:1dec54e4aec3 2352 /* Enable the write protection for RTC registers */
mbed_official 130:1dec54e4aec3 2353 RTC->WPR = 0xFF;
mbed_official 130:1dec54e4aec3 2354 }
mbed_official 130:1dec54e4aec3 2355
mbed_official 130:1dec54e4aec3 2356 /**
mbed_official 130:1dec54e4aec3 2357 * @brief Checks whether the specified RTC flag is set or not.
mbed_official 130:1dec54e4aec3 2358 * @param RTC_FLAG: specifies the flag to check.
mbed_official 130:1dec54e4aec3 2359 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 2360 * @arg RTC_FLAG_RECALPF: RECALPF event flag
mbed_official 130:1dec54e4aec3 2361 * @arg RTC_FLAG_TAMP2F: Tamper 2 event flag
mbed_official 130:1dec54e4aec3 2362 * @arg RTC_FLAG_TAMP1F: Tamper 1 event flag
mbed_official 130:1dec54e4aec3 2363 * @arg RTC_FLAG_TSOVF: Time Stamp OverFlow flag
mbed_official 130:1dec54e4aec3 2364 * @arg RTC_FLAG_TSF: Time Stamp event flag
mbed_official 130:1dec54e4aec3 2365 * @arg RTC_FLAG_WUTF: WakeUp Timer flag, available only for STM32F072 devices
mbed_official 130:1dec54e4aec3 2366 * @arg RTC_FLAG_ALRAF: Alarm A flag
mbed_official 130:1dec54e4aec3 2367 * @arg RTC_FLAG_INITF: Initialization mode flag
mbed_official 130:1dec54e4aec3 2368 * @arg RTC_FLAG_RSF: Registers Synchronized flag
mbed_official 130:1dec54e4aec3 2369 * @arg RTC_FLAG_INITS: Registers Configured flag
mbed_official 130:1dec54e4aec3 2370 * @retval The new state of RTC_FLAG (SET or RESET).
mbed_official 130:1dec54e4aec3 2371 */
mbed_official 130:1dec54e4aec3 2372 FlagStatus RTC_GetFlagStatus(uint32_t RTC_FLAG)
mbed_official 130:1dec54e4aec3 2373 {
mbed_official 130:1dec54e4aec3 2374 FlagStatus bitstatus = RESET;
mbed_official 130:1dec54e4aec3 2375 uint32_t tmpreg = 0;
mbed_official 130:1dec54e4aec3 2376
mbed_official 130:1dec54e4aec3 2377 /* Check the parameters */
mbed_official 130:1dec54e4aec3 2378 assert_param(IS_RTC_GET_FLAG(RTC_FLAG));
mbed_official 130:1dec54e4aec3 2379
mbed_official 130:1dec54e4aec3 2380 /* Get all the flags */
mbed_official 130:1dec54e4aec3 2381 tmpreg = (uint32_t)(RTC->ISR & RTC_FLAGS_MASK);
mbed_official 130:1dec54e4aec3 2382
mbed_official 130:1dec54e4aec3 2383 /* Return the status of the flag */
mbed_official 130:1dec54e4aec3 2384 if ((tmpreg & RTC_FLAG) != (uint32_t)RESET)
mbed_official 130:1dec54e4aec3 2385 {
mbed_official 130:1dec54e4aec3 2386 bitstatus = SET;
mbed_official 130:1dec54e4aec3 2387 }
mbed_official 130:1dec54e4aec3 2388 else
mbed_official 130:1dec54e4aec3 2389 {
mbed_official 130:1dec54e4aec3 2390 bitstatus = RESET;
mbed_official 130:1dec54e4aec3 2391 }
mbed_official 130:1dec54e4aec3 2392 return bitstatus;
mbed_official 130:1dec54e4aec3 2393 }
mbed_official 130:1dec54e4aec3 2394
mbed_official 130:1dec54e4aec3 2395 /**
mbed_official 130:1dec54e4aec3 2396 * @brief Clears the RTC's pending flags.
mbed_official 130:1dec54e4aec3 2397 * @param RTC_FLAG: specifies the RTC flag to clear.
mbed_official 130:1dec54e4aec3 2398 * This parameter can be any combination of the following values:
mbed_official 130:1dec54e4aec3 2399 * @arg RTC_FLAG_TAMP2F: Tamper 2 event flag
mbed_official 130:1dec54e4aec3 2400 * @arg RTC_FLAG_TAMP1F: Tamper 1 event flag
mbed_official 130:1dec54e4aec3 2401 * @arg RTC_FLAG_TSOVF: Time Stamp Overflow flag
mbed_official 130:1dec54e4aec3 2402 * @arg RTC_FLAG_TSF: Time Stamp event flag
mbed_official 130:1dec54e4aec3 2403 * @arg RTC_FLAG_WUTF: WakeUp Timer flag, available only for STM32F072 devices
mbed_official 130:1dec54e4aec3 2404 * @arg RTC_FLAG_ALRAF: Alarm A flag
mbed_official 130:1dec54e4aec3 2405 * @arg RTC_FLAG_RSF: Registers Synchronized flag
mbed_official 130:1dec54e4aec3 2406 * @retval None
mbed_official 130:1dec54e4aec3 2407 */
mbed_official 130:1dec54e4aec3 2408 void RTC_ClearFlag(uint32_t RTC_FLAG)
mbed_official 130:1dec54e4aec3 2409 {
mbed_official 130:1dec54e4aec3 2410 /* Check the parameters */
mbed_official 130:1dec54e4aec3 2411 assert_param(IS_RTC_CLEAR_FLAG(RTC_FLAG));
mbed_official 130:1dec54e4aec3 2412
mbed_official 130:1dec54e4aec3 2413 /* Clear the Flags in the RTC_ISR register */
mbed_official 130:1dec54e4aec3 2414 RTC->ISR = (uint32_t)((uint32_t)(~((RTC_FLAG | RTC_ISR_INIT)& 0x0001FFFF) | (uint32_t)(RTC->ISR & RTC_ISR_INIT)));
mbed_official 130:1dec54e4aec3 2415 }
mbed_official 130:1dec54e4aec3 2416
mbed_official 130:1dec54e4aec3 2417 /**
mbed_official 130:1dec54e4aec3 2418 * @brief Checks whether the specified RTC interrupt has occurred or not.
mbed_official 130:1dec54e4aec3 2419 * @param RTC_IT: specifies the RTC interrupt source to check.
mbed_official 130:1dec54e4aec3 2420 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 2421 * @arg RTC_IT_TS: Time Stamp interrupt
mbed_official 130:1dec54e4aec3 2422 * @arg RTC_IT_WUT: WakeUp Timer interrupt, available only for STM32F072 devices
mbed_official 130:1dec54e4aec3 2423 * @arg RTC_IT_ALRA: Alarm A interrupt
mbed_official 130:1dec54e4aec3 2424 * @arg RTC_IT_TAMP1: Tamper1 event interrupt
mbed_official 130:1dec54e4aec3 2425 * @arg RTC_IT_TAMP2: Tamper2 event interrupt
mbed_official 130:1dec54e4aec3 2426 * @retval The new state of RTC_IT (SET or RESET).
mbed_official 130:1dec54e4aec3 2427 */
mbed_official 130:1dec54e4aec3 2428 ITStatus RTC_GetITStatus(uint32_t RTC_IT)
mbed_official 130:1dec54e4aec3 2429 {
mbed_official 130:1dec54e4aec3 2430 ITStatus bitstatus = RESET;
mbed_official 130:1dec54e4aec3 2431 uint32_t tmpreg = 0, enablestatus = 0;
mbed_official 130:1dec54e4aec3 2432
mbed_official 130:1dec54e4aec3 2433 /* Check the parameters */
mbed_official 130:1dec54e4aec3 2434 assert_param(IS_RTC_GET_IT(RTC_IT));
mbed_official 130:1dec54e4aec3 2435
mbed_official 130:1dec54e4aec3 2436 /* Get the TAMPER Interrupt enable bit and pending bit */
mbed_official 130:1dec54e4aec3 2437 tmpreg = (uint32_t)(RTC->TAFCR & (RTC_TAFCR_TAMPIE));
mbed_official 130:1dec54e4aec3 2438
mbed_official 130:1dec54e4aec3 2439 /* Get the Interrupt enable Status */
mbed_official 130:1dec54e4aec3 2440 enablestatus = (uint32_t)((RTC->CR & RTC_IT) | (tmpreg & ((RTC_IT >> (RTC_IT >> 18)) >> 15)));
mbed_official 130:1dec54e4aec3 2441
mbed_official 130:1dec54e4aec3 2442 /* Get the Interrupt pending bit */
mbed_official 130:1dec54e4aec3 2443 tmpreg = (uint32_t)((RTC->ISR & (uint32_t)(RTC_IT >> 4)));
mbed_official 130:1dec54e4aec3 2444
mbed_official 130:1dec54e4aec3 2445 /* Get the status of the Interrupt */
mbed_official 130:1dec54e4aec3 2446 if ((enablestatus != (uint32_t)RESET) && ((tmpreg & 0x0000FFFF) != (uint32_t)RESET))
mbed_official 130:1dec54e4aec3 2447 {
mbed_official 130:1dec54e4aec3 2448 bitstatus = SET;
mbed_official 130:1dec54e4aec3 2449 }
mbed_official 130:1dec54e4aec3 2450 else
mbed_official 130:1dec54e4aec3 2451 {
mbed_official 130:1dec54e4aec3 2452 bitstatus = RESET;
mbed_official 130:1dec54e4aec3 2453 }
mbed_official 130:1dec54e4aec3 2454 return bitstatus;
mbed_official 130:1dec54e4aec3 2455 }
mbed_official 130:1dec54e4aec3 2456
mbed_official 130:1dec54e4aec3 2457 /**
mbed_official 130:1dec54e4aec3 2458 * @brief Clears the RTC's interrupt pending bits.
mbed_official 130:1dec54e4aec3 2459 * @param RTC_IT: specifies the RTC interrupt pending bit to clear.
mbed_official 130:1dec54e4aec3 2460 * This parameter can be any combination of the following values:
mbed_official 130:1dec54e4aec3 2461 * @arg RTC_IT_TS: Time Stamp interrupt
mbed_official 130:1dec54e4aec3 2462 * @arg RTC_IT_WUT: WakeUp Timer interrupt, available only for STM32F072 devices
mbed_official 130:1dec54e4aec3 2463 * @arg RTC_IT_ALRA: Alarm A interrupt
mbed_official 130:1dec54e4aec3 2464 * @arg RTC_IT_TAMP1: Tamper1 event interrupt
mbed_official 130:1dec54e4aec3 2465 * @arg RTC_IT_TAMP2: Tamper2 event interrupt
mbed_official 130:1dec54e4aec3 2466 * @retval None
mbed_official 130:1dec54e4aec3 2467 */
mbed_official 130:1dec54e4aec3 2468 void RTC_ClearITPendingBit(uint32_t RTC_IT)
mbed_official 130:1dec54e4aec3 2469 {
mbed_official 130:1dec54e4aec3 2470 uint32_t tmpreg = 0;
mbed_official 130:1dec54e4aec3 2471
mbed_official 130:1dec54e4aec3 2472 /* Check the parameters */
mbed_official 130:1dec54e4aec3 2473 assert_param(IS_RTC_CLEAR_IT(RTC_IT));
mbed_official 130:1dec54e4aec3 2474
mbed_official 130:1dec54e4aec3 2475 /* Get the RTC_ISR Interrupt pending bits mask */
mbed_official 130:1dec54e4aec3 2476 tmpreg = (uint32_t)(RTC_IT >> 4);
mbed_official 130:1dec54e4aec3 2477
mbed_official 130:1dec54e4aec3 2478 /* Clear the interrupt pending bits in the RTC_ISR register */
mbed_official 130:1dec54e4aec3 2479 RTC->ISR = (uint32_t)((uint32_t)(~((tmpreg | RTC_ISR_INIT)& 0x0000FFFF) | (uint32_t)(RTC->ISR & RTC_ISR_INIT)));
mbed_official 130:1dec54e4aec3 2480 }
mbed_official 130:1dec54e4aec3 2481
mbed_official 130:1dec54e4aec3 2482 /**
mbed_official 130:1dec54e4aec3 2483 * @}
mbed_official 130:1dec54e4aec3 2484 */
mbed_official 130:1dec54e4aec3 2485
mbed_official 130:1dec54e4aec3 2486 /**
mbed_official 130:1dec54e4aec3 2487 * @brief Converts a 2 digit decimal to BCD format.
mbed_official 130:1dec54e4aec3 2488 * @param Value: Byte to be converted.
mbed_official 130:1dec54e4aec3 2489 * @retval Converted byte
mbed_official 130:1dec54e4aec3 2490 */
mbed_official 130:1dec54e4aec3 2491 static uint8_t RTC_ByteToBcd2(uint8_t Value)
mbed_official 130:1dec54e4aec3 2492 {
mbed_official 130:1dec54e4aec3 2493 uint8_t bcdhigh = 0;
mbed_official 130:1dec54e4aec3 2494
mbed_official 130:1dec54e4aec3 2495 while (Value >= 10)
mbed_official 130:1dec54e4aec3 2496 {
mbed_official 130:1dec54e4aec3 2497 bcdhigh++;
mbed_official 130:1dec54e4aec3 2498 Value -= 10;
mbed_official 130:1dec54e4aec3 2499 }
mbed_official 130:1dec54e4aec3 2500
mbed_official 130:1dec54e4aec3 2501 return ((uint8_t)(bcdhigh << 4) | Value);
mbed_official 130:1dec54e4aec3 2502 }
mbed_official 130:1dec54e4aec3 2503
mbed_official 130:1dec54e4aec3 2504 /**
mbed_official 130:1dec54e4aec3 2505 * @brief Convert from 2 digit BCD to Binary.
mbed_official 130:1dec54e4aec3 2506 * @param Value: BCD value to be converted.
mbed_official 130:1dec54e4aec3 2507 * @retval Converted word
mbed_official 130:1dec54e4aec3 2508 */
mbed_official 130:1dec54e4aec3 2509 static uint8_t RTC_Bcd2ToByte(uint8_t Value)
mbed_official 130:1dec54e4aec3 2510 {
mbed_official 130:1dec54e4aec3 2511 uint8_t tmp = 0;
mbed_official 130:1dec54e4aec3 2512 tmp = ((uint8_t)(Value & (uint8_t)0xF0) >> (uint8_t)0x4) * 10;
mbed_official 130:1dec54e4aec3 2513 return (tmp + (Value & (uint8_t)0x0F));
mbed_official 130:1dec54e4aec3 2514 }
mbed_official 130:1dec54e4aec3 2515
mbed_official 130:1dec54e4aec3 2516 /**
mbed_official 130:1dec54e4aec3 2517 * @}
mbed_official 130:1dec54e4aec3 2518 */
mbed_official 130:1dec54e4aec3 2519
mbed_official 130:1dec54e4aec3 2520 /**
mbed_official 130:1dec54e4aec3 2521 * @}
mbed_official 130:1dec54e4aec3 2522 */
mbed_official 130:1dec54e4aec3 2523
mbed_official 130:1dec54e4aec3 2524 /**
mbed_official 130:1dec54e4aec3 2525 * @}
mbed_official 130:1dec54e4aec3 2526 */
mbed_official 130:1dec54e4aec3 2527
mbed_official 130:1dec54e4aec3 2528 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/