mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Jan 27 14:30:07 2014 +0000
Revision:
76:aeb1df146756
Child:
106:ced8cbb51063
Synchronized with git revision a31ec9c5f7bcb5c8a1b2eced103f6a1dfa921abd

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

Add NUCLEO_L152RE

Who changed what in which revision?

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