mbed library sources

Dependents:   Marvino mbot

Fork of mbed-src by mbed official

Committer:
jaerts
Date:
Tue Dec 22 13:22:16 2015 +0000
Revision:
637:ed69428d4850
Parent:
155:8435094ec241
Add very shady LPC1768 CAN Filter implementation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 155:8435094ec241 1 /**
mbed_official 155:8435094ec241 2 ******************************************************************************
mbed_official 155:8435094ec241 3 * @file stm32f30x_pwr.c
mbed_official 155:8435094ec241 4 * @author MCD Application Team
mbed_official 155:8435094ec241 5 * @version V1.1.0
mbed_official 155:8435094ec241 6 * @date 27-February-2014
mbed_official 155:8435094ec241 7 * @brief This file provides firmware functions to manage the following
mbed_official 155:8435094ec241 8 * functionalities of the Power Controller (PWR) peripheral:
mbed_official 155:8435094ec241 9 * + Backup Domain Access
mbed_official 155:8435094ec241 10 * + PVD configuration
mbed_official 155:8435094ec241 11 * + WakeUp pins configuration
mbed_official 155:8435094ec241 12 * + Low Power modes configuration
mbed_official 155:8435094ec241 13 * + Flags management
mbed_official 155:8435094ec241 14 *
mbed_official 155:8435094ec241 15 ******************************************************************************
mbed_official 155:8435094ec241 16 * @attention
mbed_official 155:8435094ec241 17 *
mbed_official 155:8435094ec241 18 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 155:8435094ec241 19 *
mbed_official 155:8435094ec241 20 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 155:8435094ec241 21 * are permitted provided that the following conditions are met:
mbed_official 155:8435094ec241 22 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 155:8435094ec241 23 * this list of conditions and the following disclaimer.
mbed_official 155:8435094ec241 24 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 155:8435094ec241 25 * this list of conditions and the following disclaimer in the documentation
mbed_official 155:8435094ec241 26 * and/or other materials provided with the distribution.
mbed_official 155:8435094ec241 27 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 155:8435094ec241 28 * may be used to endorse or promote products derived from this software
mbed_official 155:8435094ec241 29 * without specific prior written permission.
mbed_official 155:8435094ec241 30 *
mbed_official 155:8435094ec241 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 155:8435094ec241 32 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 155:8435094ec241 33 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 155:8435094ec241 34 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 155:8435094ec241 35 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 155:8435094ec241 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 155:8435094ec241 37 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 155:8435094ec241 38 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 155:8435094ec241 39 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 155:8435094ec241 40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 155:8435094ec241 41 *
mbed_official 155:8435094ec241 42 ******************************************************************************
mbed_official 155:8435094ec241 43 */
mbed_official 155:8435094ec241 44
mbed_official 155:8435094ec241 45 /* Includes ------------------------------------------------------------------*/
mbed_official 155:8435094ec241 46 #include "stm32f30x_pwr.h"
mbed_official 155:8435094ec241 47 #include "stm32f30x_rcc.h"
mbed_official 155:8435094ec241 48
mbed_official 155:8435094ec241 49 /** @addtogroup STM32F30x_StdPeriph_Driver
mbed_official 155:8435094ec241 50 * @{
mbed_official 155:8435094ec241 51 */
mbed_official 155:8435094ec241 52
mbed_official 155:8435094ec241 53 /** @defgroup PWR
mbed_official 155:8435094ec241 54 * @brief PWR driver modules
mbed_official 155:8435094ec241 55 * @{
mbed_official 155:8435094ec241 56 */
mbed_official 155:8435094ec241 57
mbed_official 155:8435094ec241 58 /* Private typedef -----------------------------------------------------------*/
mbed_official 155:8435094ec241 59 /* Private define ------------------------------------------------------------*/
mbed_official 155:8435094ec241 60 /* --------- PWR registers bit address in the alias region ---------- */
mbed_official 155:8435094ec241 61 #define PWR_OFFSET (PWR_BASE - PERIPH_BASE)
mbed_official 155:8435094ec241 62
mbed_official 155:8435094ec241 63 /* --- CR Register ---*/
mbed_official 155:8435094ec241 64
mbed_official 155:8435094ec241 65 /* Alias word address of DBP bit */
mbed_official 155:8435094ec241 66 #define CR_OFFSET (PWR_OFFSET + 0x00)
mbed_official 155:8435094ec241 67 #define DBP_BitNumber 0x08
mbed_official 155:8435094ec241 68 #define CR_DBP_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (DBP_BitNumber * 4))
mbed_official 155:8435094ec241 69
mbed_official 155:8435094ec241 70 /* Alias word address of PVDE bit */
mbed_official 155:8435094ec241 71 #define PVDE_BitNumber 0x04
mbed_official 155:8435094ec241 72 #define CR_PVDE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PVDE_BitNumber * 4))
mbed_official 155:8435094ec241 73
mbed_official 155:8435094ec241 74 /* ------------------ PWR registers bit mask ------------------------ */
mbed_official 155:8435094ec241 75
mbed_official 155:8435094ec241 76 /* CR register bit mask */
mbed_official 155:8435094ec241 77 #define CR_DS_MASK ((uint32_t)0xFFFFFFFC)
mbed_official 155:8435094ec241 78 #define CR_PLS_MASK ((uint32_t)0xFFFFFF1F)
mbed_official 155:8435094ec241 79
mbed_official 155:8435094ec241 80 /* Private macro -------------------------------------------------------------*/
mbed_official 155:8435094ec241 81 /* Private variables ---------------------------------------------------------*/
mbed_official 155:8435094ec241 82 /* Private function prototypes -----------------------------------------------*/
mbed_official 155:8435094ec241 83 /* Private functions ---------------------------------------------------------*/
mbed_official 155:8435094ec241 84
mbed_official 155:8435094ec241 85 /** @defgroup PWR_Private_Functions
mbed_official 155:8435094ec241 86 * @{
mbed_official 155:8435094ec241 87 */
mbed_official 155:8435094ec241 88
mbed_official 155:8435094ec241 89 /** @defgroup PWR_Group1 Backup Domain Access function
mbed_official 155:8435094ec241 90 * @brief Backup Domain Access function
mbed_official 155:8435094ec241 91 *
mbed_official 155:8435094ec241 92 @verbatim
mbed_official 155:8435094ec241 93 ==============================================================================
mbed_official 155:8435094ec241 94 ##### Backup Domain Access function #####
mbed_official 155:8435094ec241 95 ==============================================================================
mbed_official 155:8435094ec241 96
mbed_official 155:8435094ec241 97 [..] After reset, the Backup Domain Registers (RCC BDCR Register, RTC registers
mbed_official 155:8435094ec241 98 and RTC backup registers) are protected against possible stray write accesses.
mbed_official 155:8435094ec241 99 [..] To enable access to Backup domain use the PWR_BackupAccessCmd(ENABLE) function.
mbed_official 155:8435094ec241 100
mbed_official 155:8435094ec241 101 @endverbatim
mbed_official 155:8435094ec241 102 * @{
mbed_official 155:8435094ec241 103 */
mbed_official 155:8435094ec241 104
mbed_official 155:8435094ec241 105 /**
mbed_official 155:8435094ec241 106 * @brief Deinitializes the PWR peripheral registers to their default reset values.
mbed_official 155:8435094ec241 107 * @param None
mbed_official 155:8435094ec241 108 * @retval None
mbed_official 155:8435094ec241 109 */
mbed_official 155:8435094ec241 110 void PWR_DeInit(void)
mbed_official 155:8435094ec241 111 {
mbed_official 155:8435094ec241 112 RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);
mbed_official 155:8435094ec241 113 RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, DISABLE);
mbed_official 155:8435094ec241 114 }
mbed_official 155:8435094ec241 115
mbed_official 155:8435094ec241 116 /**
mbed_official 155:8435094ec241 117 * @brief Enables or disables access to the RTC and backup registers.
mbed_official 155:8435094ec241 118 * @note If the HSE divided by 32 is used as the RTC clock, the
mbed_official 155:8435094ec241 119 * Backup Domain Access should be kept enabled.
mbed_official 155:8435094ec241 120 * @param NewState: new state of the access to the RTC and backup registers.
mbed_official 155:8435094ec241 121 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 122 * @retval None
mbed_official 155:8435094ec241 123 */
mbed_official 155:8435094ec241 124 void PWR_BackupAccessCmd(FunctionalState NewState)
mbed_official 155:8435094ec241 125 {
mbed_official 155:8435094ec241 126 /* Check the parameters */
mbed_official 155:8435094ec241 127 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 128 *(__IO uint32_t *) CR_DBP_BB = (uint32_t)NewState;
mbed_official 155:8435094ec241 129 }
mbed_official 155:8435094ec241 130
mbed_official 155:8435094ec241 131 /**
mbed_official 155:8435094ec241 132 * @}
mbed_official 155:8435094ec241 133 */
mbed_official 155:8435094ec241 134
mbed_official 155:8435094ec241 135 /** @defgroup PWR_Group2 PVD configuration functions
mbed_official 155:8435094ec241 136 * @brief PVD configuration functions
mbed_official 155:8435094ec241 137 *
mbed_official 155:8435094ec241 138 @verbatim
mbed_official 155:8435094ec241 139 ===============================================================================
mbed_official 155:8435094ec241 140 ##### PVD configuration functions #####
mbed_official 155:8435094ec241 141 ==============================================================================
mbed_official 155:8435094ec241 142 [..]
mbed_official 155:8435094ec241 143 (+) The PVD is used to monitor the VDD power supply by comparing it to a threshold
mbed_official 155:8435094ec241 144 selected by the PVD Level (PLS[2:0] bits in the PWR_CR).
mbed_official 155:8435094ec241 145 (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower than the
mbed_official 155:8435094ec241 146 PVD threshold. This event is internally connected to the EXTI line16
mbed_official 155:8435094ec241 147 and can generate an interrupt if enabled through the EXTI registers.
mbed_official 155:8435094ec241 148 (+) The PVD is stopped in Standby mode.
mbed_official 155:8435094ec241 149
mbed_official 155:8435094ec241 150 @endverbatim
mbed_official 155:8435094ec241 151 * @{
mbed_official 155:8435094ec241 152 */
mbed_official 155:8435094ec241 153
mbed_official 155:8435094ec241 154 /**
mbed_official 155:8435094ec241 155 * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD).
mbed_official 155:8435094ec241 156 * @param PWR_PVDLevel: specifies the PVD detection level
mbed_official 155:8435094ec241 157 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 158 * @arg PWR_PVDLevel_0: PVD detection level set to 2.18V
mbed_official 155:8435094ec241 159 * @arg PWR_PVDLevel_1: PVD detection level set to 2.28V
mbed_official 155:8435094ec241 160 * @arg PWR_PVDLevel_2: PVD detection level set to 2.38V
mbed_official 155:8435094ec241 161 * @arg PWR_PVDLevel_3: PVD detection level set to 2.48V
mbed_official 155:8435094ec241 162 * @arg PWR_PVDLevel_4: PVD detection level set to 2.58V
mbed_official 155:8435094ec241 163 * @arg PWR_PVDLevel_5: PVD detection level set to 2.68V
mbed_official 155:8435094ec241 164 * @arg PWR_PVDLevel_6: PVD detection level set to 2.78V
mbed_official 155:8435094ec241 165 * @arg PWR_PVDLevel_7: PVD detection level set to 2.88V
mbed_official 155:8435094ec241 166 * @retval None
mbed_official 155:8435094ec241 167 */
mbed_official 155:8435094ec241 168 void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel)
mbed_official 155:8435094ec241 169 {
mbed_official 155:8435094ec241 170 uint32_t tmpreg = 0;
mbed_official 155:8435094ec241 171
mbed_official 155:8435094ec241 172 /* Check the parameters */
mbed_official 155:8435094ec241 173 assert_param(IS_PWR_PVD_LEVEL(PWR_PVDLevel));
mbed_official 155:8435094ec241 174
mbed_official 155:8435094ec241 175 tmpreg = PWR->CR;
mbed_official 155:8435094ec241 176
mbed_official 155:8435094ec241 177 /* Clear PLS[7:5] bits */
mbed_official 155:8435094ec241 178 tmpreg &= CR_PLS_MASK;
mbed_official 155:8435094ec241 179
mbed_official 155:8435094ec241 180 /* Set PLS[7:5] bits according to PWR_PVDLevel value */
mbed_official 155:8435094ec241 181 tmpreg |= PWR_PVDLevel;
mbed_official 155:8435094ec241 182
mbed_official 155:8435094ec241 183 /* Store the new value */
mbed_official 155:8435094ec241 184 PWR->CR = tmpreg;
mbed_official 155:8435094ec241 185 }
mbed_official 155:8435094ec241 186
mbed_official 155:8435094ec241 187 /**
mbed_official 155:8435094ec241 188 * @brief Enables or disables the Power Voltage Detector(PVD).
mbed_official 155:8435094ec241 189 * @param NewState: new state of the PVD.
mbed_official 155:8435094ec241 190 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 191 * @retval None
mbed_official 155:8435094ec241 192 */
mbed_official 155:8435094ec241 193 void PWR_PVDCmd(FunctionalState NewState)
mbed_official 155:8435094ec241 194 {
mbed_official 155:8435094ec241 195 /* Check the parameters */
mbed_official 155:8435094ec241 196 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 197 *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)NewState;
mbed_official 155:8435094ec241 198 }
mbed_official 155:8435094ec241 199
mbed_official 155:8435094ec241 200 /**
mbed_official 155:8435094ec241 201 * @}
mbed_official 155:8435094ec241 202 */
mbed_official 155:8435094ec241 203
mbed_official 155:8435094ec241 204 /** @defgroup PWR_Group3 WakeUp pins configuration functions
mbed_official 155:8435094ec241 205 * @brief WakeUp pins configuration functions
mbed_official 155:8435094ec241 206 *
mbed_official 155:8435094ec241 207 @verbatim
mbed_official 155:8435094ec241 208 ===============================================================================
mbed_official 155:8435094ec241 209 ##### WakeUp pins configuration functions #####
mbed_official 155:8435094ec241 210 ===============================================================================
mbed_official 155:8435094ec241 211 [..]
mbed_official 155:8435094ec241 212 (+) WakeUp pins are used to wakeup the system from Standby mode. These pins are
mbed_official 155:8435094ec241 213 forced in input pull down configuration and are active on rising edges.
mbed_official 155:8435094ec241 214 (+) There are three WakeUp pins: WakeUp Pin 1 on PA.00, WakeUp Pin 2 on PC.13 and
mbed_official 155:8435094ec241 215 WakeUp Pin 3 on PE.06.
mbed_official 155:8435094ec241 216
mbed_official 155:8435094ec241 217 @endverbatim
mbed_official 155:8435094ec241 218 * @{
mbed_official 155:8435094ec241 219 */
mbed_official 155:8435094ec241 220
mbed_official 155:8435094ec241 221 /**
mbed_official 155:8435094ec241 222 * @brief Enables or disables the WakeUp Pin functionality.
mbed_official 155:8435094ec241 223 * @param PWR_WakeUpPin: specifies the WakeUpPin.
mbed_official 155:8435094ec241 224 * This parameter can be: PWR_WakeUpPin_1, PWR_WakeUpPin_2 or PWR_WakeUpPin_3.
mbed_official 155:8435094ec241 225 * @param NewState: new state of the WakeUp Pin functionality.
mbed_official 155:8435094ec241 226 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 227 * @retval None
mbed_official 155:8435094ec241 228 */
mbed_official 155:8435094ec241 229 void PWR_WakeUpPinCmd(uint32_t PWR_WakeUpPin, FunctionalState NewState)
mbed_official 155:8435094ec241 230 {
mbed_official 155:8435094ec241 231 /* Check the parameters */
mbed_official 155:8435094ec241 232 assert_param(IS_PWR_WAKEUP_PIN(PWR_WakeUpPin));
mbed_official 155:8435094ec241 233 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 234
mbed_official 155:8435094ec241 235 if (NewState != DISABLE)
mbed_official 155:8435094ec241 236 {
mbed_official 155:8435094ec241 237 /* Enable the EWUPx pin */
mbed_official 155:8435094ec241 238 PWR->CSR |= PWR_WakeUpPin;
mbed_official 155:8435094ec241 239 }
mbed_official 155:8435094ec241 240 else
mbed_official 155:8435094ec241 241 {
mbed_official 155:8435094ec241 242 /* Disable the EWUPx pin */
mbed_official 155:8435094ec241 243 PWR->CSR &= ~PWR_WakeUpPin;
mbed_official 155:8435094ec241 244 }
mbed_official 155:8435094ec241 245 }
mbed_official 155:8435094ec241 246
mbed_official 155:8435094ec241 247 /**
mbed_official 155:8435094ec241 248 * @}
mbed_official 155:8435094ec241 249 */
mbed_official 155:8435094ec241 250
mbed_official 155:8435094ec241 251
mbed_official 155:8435094ec241 252 /** @defgroup PWR_Group4 Low Power modes configuration functions
mbed_official 155:8435094ec241 253 * @brief Low Power modes configuration functions
mbed_official 155:8435094ec241 254 *
mbed_official 155:8435094ec241 255 @verbatim
mbed_official 155:8435094ec241 256 ===============================================================================
mbed_official 155:8435094ec241 257 ##### Low Power modes configuration functions #####
mbed_official 155:8435094ec241 258 ==============================================================================
mbed_official 155:8435094ec241 259
mbed_official 155:8435094ec241 260 [..] The devices feature three low-power modes:
mbed_official 155:8435094ec241 261 (+) Sleep mode: Cortex-M4 core stopped, peripherals kept running.
mbed_official 155:8435094ec241 262 (+) Stop mode: all clocks are stopped, regulator running, regulator in low power mode
mbed_official 155:8435094ec241 263 (+) Standby mode: VCORE domain powered off
mbed_official 155:8435094ec241 264
mbed_official 155:8435094ec241 265 *** Sleep mode ***
mbed_official 155:8435094ec241 266 ==================
mbed_official 155:8435094ec241 267 [..]
mbed_official 155:8435094ec241 268 (+) Entry:
mbed_official 155:8435094ec241 269 (++) The Sleep mode is entered by executing the WFE() or WFI() instructions.
mbed_official 155:8435094ec241 270 (+) Exit:
mbed_official 155:8435094ec241 271 (++) Any peripheral interrupt acknowledged by the nested vectored interrupt
mbed_official 155:8435094ec241 272 controller (NVIC) can wake up the device from Sleep mode.
mbed_official 155:8435094ec241 273
mbed_official 155:8435094ec241 274 *** Stop mode ***
mbed_official 155:8435094ec241 275 =================
mbed_official 155:8435094ec241 276 [..] In Stop mode, all clocks in the VCORE domain are stopped, the PLL, the HSI,
mbed_official 155:8435094ec241 277 and the HSE RC oscillators are disabled. Internal SRAM and register
mbed_official 155:8435094ec241 278 contents are preserved.
mbed_official 155:8435094ec241 279 The voltage regulator can be configured either in normal or low-power mode.
mbed_official 155:8435094ec241 280
mbed_official 155:8435094ec241 281 (+) Entry:
mbed_official 155:8435094ec241 282 (++) The Stop mode is entered using the PWR_EnterSTOPMode(PWR_Regulator_LowPower,)
mbed_official 155:8435094ec241 283 function with regulator in LowPower or with Regulator ON.
mbed_official 155:8435094ec241 284 (+) Exit:
mbed_official 155:8435094ec241 285 (++) Any EXTI Line (Internal or External) configured in Interrupt/Event mode
mbed_official 155:8435094ec241 286 or any internal IPs (I2C or UASRT) wakeup event.
mbed_official 155:8435094ec241 287
mbed_official 155:8435094ec241 288 *** Standby mode ***
mbed_official 155:8435094ec241 289 ====================
mbed_official 155:8435094ec241 290 [..] The Standby mode allows to achieve the lowest power consumption. It is based
mbed_official 155:8435094ec241 291 on the Cortex-M4 deepsleep mode, with the voltage regulator disabled.
mbed_official 155:8435094ec241 292 The VCORE domain is consequently powered off. The PLL, the HSI, and the HSE
mbed_official 155:8435094ec241 293 oscillator are also switched off. SRAM and register
mbed_official 155:8435094ec241 294 contents are lost except for the Backup domain (RTC registers, RTC backup
mbed_official 155:8435094ec241 295 registers and Standby circuitry).
mbed_official 155:8435094ec241 296
mbed_official 155:8435094ec241 297 [..] The voltage regulator is OFF.
mbed_official 155:8435094ec241 298
mbed_official 155:8435094ec241 299 (+) Entry:
mbed_official 155:8435094ec241 300 (++) The Standby mode is entered using the PWR_EnterSTANDBYMode() function.
mbed_official 155:8435094ec241 301 (+) Exit:
mbed_official 155:8435094ec241 302 (++) WKUP pin rising edge, RTC alarm (Alarm A and Alarm B), RTC wakeup,
mbed_official 155:8435094ec241 303 tamper event, time-stamp event, external reset in NRST pin, IWDG reset.
mbed_official 155:8435094ec241 304
mbed_official 155:8435094ec241 305 *** Auto-wakeup (AWU) from low-power mode ***
mbed_official 155:8435094ec241 306 =============================================
mbed_official 155:8435094ec241 307 [..] The MCU can be woken up from low-power mode by an RTC Alarm event, a tamper
mbed_official 155:8435094ec241 308 event, a time-stamp event, or a comparator event, without depending on an
mbed_official 155:8435094ec241 309 external interrupt (Auto-wakeup mode).
mbed_official 155:8435094ec241 310
mbed_official 155:8435094ec241 311 (+) RTC auto-wakeup (AWU) from the Stop mode
mbed_official 155:8435094ec241 312 (++) To wake up from the Stop mode with an RTC alarm event, it is necessary to:
mbed_official 155:8435094ec241 313 (+++) Configure the EXTI Line 17 to be sensitive to rising edges (Interrupt
mbed_official 155:8435094ec241 314 or Event modes) using the EXTI_Init() function.
mbed_official 155:8435094ec241 315 (+++) Enable the RTC Alarm Interrupt using the RTC_ITConfig() function
mbed_official 155:8435094ec241 316 (+++) Configure the RTC to generate the RTC alarm using the RTC_SetAlarm()
mbed_official 155:8435094ec241 317 and RTC_AlarmCmd() functions.
mbed_official 155:8435094ec241 318 (++) To wake up from the Stop mode with an RTC Tamper or time stamp event, it
mbed_official 155:8435094ec241 319 is necessary to:
mbed_official 155:8435094ec241 320 (+++) Configure the EXTI Line 19 to be sensitive to rising edges (Interrupt
mbed_official 155:8435094ec241 321 or Event modes) using the EXTI_Init() function.
mbed_official 155:8435094ec241 322 (+++) Enable the RTC Tamper or time stamp Interrupt using the RTC_ITConfig()
mbed_official 155:8435094ec241 323 function.
mbed_official 155:8435094ec241 324 (+++) Configure the RTC to detect the tamper or time stamp event using the
mbed_official 155:8435094ec241 325 RTC_TimeStampConfig(), RTC_TamperTriggerConfig() and RTC_TamperCmd()
mbed_official 155:8435094ec241 326 functions.
mbed_official 155:8435094ec241 327
mbed_official 155:8435094ec241 328 (+) RTC auto-wakeup (AWU) from the Standby mode
mbed_official 155:8435094ec241 329 (++) To wake up from the Standby mode with an RTC alarm event, it is necessary to:
mbed_official 155:8435094ec241 330 (+++) Enable the RTC Alarm Interrupt using the RTC_ITConfig() function.
mbed_official 155:8435094ec241 331 (+++) Configure the RTC to generate the RTC alarm using the RTC_SetAlarm()
mbed_official 155:8435094ec241 332 and RTC_AlarmCmd() functions.
mbed_official 155:8435094ec241 333 (++) To wake up from the Standby mode with an RTC Tamper or time stamp event, it
mbed_official 155:8435094ec241 334 is necessary to:
mbed_official 155:8435094ec241 335 (+++) Enable the RTC Tamper or time stamp Interrupt using the RTC_ITConfig()
mbed_official 155:8435094ec241 336 function.
mbed_official 155:8435094ec241 337 (+++) Configure the RTC to detect the tamper or time stamp event using the
mbed_official 155:8435094ec241 338 RTC_TimeStampConfig(), RTC_TamperTriggerConfig() and RTC_TamperCmd()
mbed_official 155:8435094ec241 339 functions.
mbed_official 155:8435094ec241 340
mbed_official 155:8435094ec241 341 (+) Comparator auto-wakeup (AWU) from the Stop mode
mbed_official 155:8435094ec241 342 (++) To wake up from the Stop mode with a comparator wakeup event, it is necessary to:
mbed_official 155:8435094ec241 343 (+++) Configure the correspondant comparator EXTI Line to be sensitive to
mbed_official 155:8435094ec241 344 the selected edges (falling, rising or falling and rising)
mbed_official 155:8435094ec241 345 (Interrupt or Event modes) using the EXTI_Init() function.
mbed_official 155:8435094ec241 346 (+++) Configure the comparator to generate the event.
mbed_official 155:8435094ec241 347
mbed_official 155:8435094ec241 348 @endverbatim
mbed_official 155:8435094ec241 349 * @{
mbed_official 155:8435094ec241 350 */
mbed_official 155:8435094ec241 351
mbed_official 155:8435094ec241 352 /**
mbed_official 155:8435094ec241 353 * @brief Enters Sleep mode.
mbed_official 155:8435094ec241 354 * @note In Sleep mode, all I/O pins keep the same state as in Run mode.
mbed_official 155:8435094ec241 355 * @param PWR_SLEEPEntry: specifies if SLEEP mode in entered with WFI or WFE instruction.
mbed_official 155:8435094ec241 356 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 357 * @arg PWR_SLEEPEntry_WFI: enter SLEEP mode with WFI instruction
mbed_official 155:8435094ec241 358 * @arg PWR_SLEEPEntry_WFE: enter SLEEP mode with WFE instruction
mbed_official 155:8435094ec241 359 * @retval None
mbed_official 155:8435094ec241 360 */
mbed_official 155:8435094ec241 361 void PWR_EnterSleepMode(uint8_t PWR_SLEEPEntry)
mbed_official 155:8435094ec241 362 {
mbed_official 155:8435094ec241 363 /* Check the parameters */
mbed_official 155:8435094ec241 364 assert_param(IS_PWR_SLEEP_ENTRY(PWR_SLEEPEntry));
mbed_official 155:8435094ec241 365
mbed_official 155:8435094ec241 366 /* Clear SLEEPDEEP bit of Cortex System Control Register */
mbed_official 155:8435094ec241 367 SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
mbed_official 155:8435094ec241 368
mbed_official 155:8435094ec241 369 /* Select SLEEP mode entry -------------------------------------------------*/
mbed_official 155:8435094ec241 370 if(PWR_SLEEPEntry == PWR_SLEEPEntry_WFI)
mbed_official 155:8435094ec241 371 {
mbed_official 155:8435094ec241 372 /* Request Wait For Interrupt */
mbed_official 155:8435094ec241 373 __WFI();
mbed_official 155:8435094ec241 374 }
mbed_official 155:8435094ec241 375 else
mbed_official 155:8435094ec241 376 {
mbed_official 155:8435094ec241 377 /* Request Wait For Event */
mbed_official 155:8435094ec241 378 __WFE();
mbed_official 155:8435094ec241 379 }
mbed_official 155:8435094ec241 380 }
mbed_official 155:8435094ec241 381
mbed_official 155:8435094ec241 382 /**
mbed_official 155:8435094ec241 383 * @brief Enters STOP mode.
mbed_official 155:8435094ec241 384 * @note In Stop mode, all I/O pins keep the same state as in Run mode.
mbed_official 155:8435094ec241 385 * @note When exiting Stop mode by issuing an interrupt or a wakeup event,
mbed_official 155:8435094ec241 386 * the HSI RC oscillator is selected as system clock.
mbed_official 155:8435094ec241 387 * @note When the voltage regulator operates in low power mode, an additional
mbed_official 155:8435094ec241 388 * startup delay is incurred when waking up from Stop mode.
mbed_official 155:8435094ec241 389 * By keeping the internal regulator ON during Stop mode, the consumption
mbed_official 155:8435094ec241 390 * is higher although the startup time is reduced.
mbed_official 155:8435094ec241 391 * @param PWR_Regulator: specifies the regulator state in STOP mode.
mbed_official 155:8435094ec241 392 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 393 * @arg PWR_Regulator_ON: STOP mode with regulator ON
mbed_official 155:8435094ec241 394 * @arg PWR_Regulator_LowPower: STOP mode with regulator in low power mode
mbed_official 155:8435094ec241 395 * @param PWR_STOPEntry: specifies if STOP mode in entered with WFI or WFE instruction.
mbed_official 155:8435094ec241 396 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 397 * @arg PWR_STOPEntry_WFI: enter STOP mode with WFI instruction
mbed_official 155:8435094ec241 398 * @arg PWR_STOPEntry_WFE: enter STOP mode with WFE instruction
mbed_official 155:8435094ec241 399 * @retval None
mbed_official 155:8435094ec241 400 */
mbed_official 155:8435094ec241 401 void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry)
mbed_official 155:8435094ec241 402 {
mbed_official 155:8435094ec241 403 uint32_t tmpreg = 0;
mbed_official 155:8435094ec241 404
mbed_official 155:8435094ec241 405 /* Check the parameters */
mbed_official 155:8435094ec241 406 assert_param(IS_PWR_REGULATOR(PWR_Regulator));
mbed_official 155:8435094ec241 407 assert_param(IS_PWR_STOP_ENTRY(PWR_STOPEntry));
mbed_official 155:8435094ec241 408
mbed_official 155:8435094ec241 409 /* Select the regulator state in STOP mode ---------------------------------*/
mbed_official 155:8435094ec241 410 tmpreg = PWR->CR;
mbed_official 155:8435094ec241 411 /* Clear PDDS and LPDSR bits */
mbed_official 155:8435094ec241 412 tmpreg &= CR_DS_MASK;
mbed_official 155:8435094ec241 413
mbed_official 155:8435094ec241 414 /* Set LPDSR bit according to PWR_Regulator value */
mbed_official 155:8435094ec241 415 tmpreg |= PWR_Regulator;
mbed_official 155:8435094ec241 416
mbed_official 155:8435094ec241 417 /* Store the new value */
mbed_official 155:8435094ec241 418 PWR->CR = tmpreg;
mbed_official 155:8435094ec241 419
mbed_official 155:8435094ec241 420 /* Set SLEEPDEEP bit of Cortex System Control Register */
mbed_official 155:8435094ec241 421 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
mbed_official 155:8435094ec241 422
mbed_official 155:8435094ec241 423 /* Select STOP mode entry --------------------------------------------------*/
mbed_official 155:8435094ec241 424 if(PWR_STOPEntry == PWR_STOPEntry_WFI)
mbed_official 155:8435094ec241 425 {
mbed_official 155:8435094ec241 426 /* Request Wait For Interrupt */
mbed_official 155:8435094ec241 427 __WFI();
mbed_official 155:8435094ec241 428 }
mbed_official 155:8435094ec241 429 else
mbed_official 155:8435094ec241 430 {
mbed_official 155:8435094ec241 431 /* Request Wait For Event */
mbed_official 155:8435094ec241 432 __WFE();
mbed_official 155:8435094ec241 433 }
mbed_official 155:8435094ec241 434 /* Reset SLEEPDEEP bit of Cortex System Control Register */
mbed_official 155:8435094ec241 435 SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
mbed_official 155:8435094ec241 436 }
mbed_official 155:8435094ec241 437
mbed_official 155:8435094ec241 438 /**
mbed_official 155:8435094ec241 439 * @brief Enters STANDBY mode.
mbed_official 155:8435094ec241 440 * @note In Standby mode, all I/O pins are high impedance except for:
mbed_official 155:8435094ec241 441 * @note Reset pad (still available)
mbed_official 155:8435094ec241 442 * @note RTC_AF1 pin (PC13) if configured for Wakeup pin 2 (WKUP2), tamper,
mbed_official 155:8435094ec241 443 * time-stamp, RTC Alarm out, or RTC clock calibration out.
mbed_official 155:8435094ec241 444 * @note WKUP pin 1 (PA0) and WKUP pin 3 (PE6), if enabled.
mbed_official 155:8435094ec241 445 * @param None
mbed_official 155:8435094ec241 446 * @retval None
mbed_official 155:8435094ec241 447 */
mbed_official 155:8435094ec241 448 void PWR_EnterSTANDBYMode(void)
mbed_official 155:8435094ec241 449 {
mbed_official 155:8435094ec241 450 /* Clear Wakeup flag */
mbed_official 155:8435094ec241 451 PWR->CR |= PWR_CR_CWUF;
mbed_official 155:8435094ec241 452
mbed_official 155:8435094ec241 453 /* Select STANDBY mode */
mbed_official 155:8435094ec241 454 PWR->CR |= PWR_CR_PDDS;
mbed_official 155:8435094ec241 455
mbed_official 155:8435094ec241 456 /* Set SLEEPDEEP bit of Cortex System Control Register */
mbed_official 155:8435094ec241 457 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
mbed_official 155:8435094ec241 458
mbed_official 155:8435094ec241 459 /* This option is used to ensure that store operations are completed */
mbed_official 155:8435094ec241 460 #if defined ( __CC_ARM )
mbed_official 155:8435094ec241 461 __force_stores();
mbed_official 155:8435094ec241 462 #endif
mbed_official 155:8435094ec241 463 /* Request Wait For Interrupt */
mbed_official 155:8435094ec241 464 __WFI();
mbed_official 155:8435094ec241 465 }
mbed_official 155:8435094ec241 466
mbed_official 155:8435094ec241 467 /**
mbed_official 155:8435094ec241 468 * @}
mbed_official 155:8435094ec241 469 */
mbed_official 155:8435094ec241 470
mbed_official 155:8435094ec241 471 /** @defgroup PWR_Group5 Flags management functions
mbed_official 155:8435094ec241 472 * @brief Flags management functions
mbed_official 155:8435094ec241 473 *
mbed_official 155:8435094ec241 474 @verbatim
mbed_official 155:8435094ec241 475 ===============================================================================
mbed_official 155:8435094ec241 476 ##### Flags management functions #####
mbed_official 155:8435094ec241 477 ===============================================================================
mbed_official 155:8435094ec241 478
mbed_official 155:8435094ec241 479 @endverbatim
mbed_official 155:8435094ec241 480 * @{
mbed_official 155:8435094ec241 481 */
mbed_official 155:8435094ec241 482
mbed_official 155:8435094ec241 483 /**
mbed_official 155:8435094ec241 484 * @brief Checks whether the specified PWR flag is set or not.
mbed_official 155:8435094ec241 485 * @param PWR_FLAG: specifies the flag to check.
mbed_official 155:8435094ec241 486 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 487 * @arg PWR_FLAG_WU: Wake Up flag. This flag indicates that a wakeup event
mbed_official 155:8435094ec241 488 * was received from the WKUP pin or from the RTC alarm (Alarm A or Alarm B),
mbed_official 155:8435094ec241 489 * RTC Tamper event, RTC TimeStamp event or RTC Wakeup.
mbed_official 155:8435094ec241 490 * @arg PWR_FLAG_SB: StandBy flag. This flag indicates that the system was
mbed_official 155:8435094ec241 491 * resumed from StandBy mode.
mbed_official 155:8435094ec241 492 * @arg PWR_FLAG_PVDO: PVD Output. This flag is valid only if PVD is enabled
mbed_official 155:8435094ec241 493 * by the PWR_PVDCmd() function.
mbed_official 155:8435094ec241 494 * @arg PWR_FLAG_VREFINTRDY: Internal Voltage Reference Ready flag. This
mbed_official 155:8435094ec241 495 * flag indicates the state of the internal voltage reference, VREFINT.
mbed_official 155:8435094ec241 496 * @retval The new state of PWR_FLAG (SET or RESET).
mbed_official 155:8435094ec241 497 */
mbed_official 155:8435094ec241 498 FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG)
mbed_official 155:8435094ec241 499 {
mbed_official 155:8435094ec241 500 FlagStatus bitstatus = RESET;
mbed_official 155:8435094ec241 501 /* Check the parameters */
mbed_official 155:8435094ec241 502 assert_param(IS_PWR_GET_FLAG(PWR_FLAG));
mbed_official 155:8435094ec241 503
mbed_official 155:8435094ec241 504 if ((PWR->CSR & PWR_FLAG) != (uint32_t)RESET)
mbed_official 155:8435094ec241 505 {
mbed_official 155:8435094ec241 506 bitstatus = SET;
mbed_official 155:8435094ec241 507 }
mbed_official 155:8435094ec241 508 else
mbed_official 155:8435094ec241 509 {
mbed_official 155:8435094ec241 510 bitstatus = RESET;
mbed_official 155:8435094ec241 511 }
mbed_official 155:8435094ec241 512 /* Return the flag status */
mbed_official 155:8435094ec241 513 return bitstatus;
mbed_official 155:8435094ec241 514 }
mbed_official 155:8435094ec241 515
mbed_official 155:8435094ec241 516 /**
mbed_official 155:8435094ec241 517 * @brief Clears the PWR's pending flags.
mbed_official 155:8435094ec241 518 * @param PWR_FLAG: specifies the flag to clear.
mbed_official 155:8435094ec241 519 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 520 * @arg PWR_FLAG_WU: Wake Up flag
mbed_official 155:8435094ec241 521 * @arg PWR_FLAG_SB: StandBy flag
mbed_official 155:8435094ec241 522 * @retval None
mbed_official 155:8435094ec241 523 */
mbed_official 155:8435094ec241 524 void PWR_ClearFlag(uint32_t PWR_FLAG)
mbed_official 155:8435094ec241 525 {
mbed_official 155:8435094ec241 526 /* Check the parameters */
mbed_official 155:8435094ec241 527 assert_param(IS_PWR_CLEAR_FLAG(PWR_FLAG));
mbed_official 155:8435094ec241 528
mbed_official 155:8435094ec241 529 PWR->CR |= PWR_FLAG << 2;
mbed_official 155:8435094ec241 530 }
mbed_official 155:8435094ec241 531
mbed_official 155:8435094ec241 532 /**
mbed_official 155:8435094ec241 533 * @}
mbed_official 155:8435094ec241 534 */
mbed_official 155:8435094ec241 535
mbed_official 155:8435094ec241 536 /**
mbed_official 155:8435094ec241 537 * @}
mbed_official 155:8435094ec241 538 */
mbed_official 155:8435094ec241 539
mbed_official 155:8435094ec241 540 /**
mbed_official 155:8435094ec241 541 * @}
mbed_official 155:8435094ec241 542 */
mbed_official 155:8435094ec241 543
mbed_official 155:8435094ec241 544 /**
mbed_official 155:8435094ec241 545 * @}
mbed_official 155:8435094ec241 546 */
mbed_official 155:8435094ec241 547
mbed_official 155:8435094ec241 548 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/