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:
125:23cc3068a9e4
test with CLOCK_SETUP = 0

Who changed what in which revision?

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