mbed library sources

Dependents:   bare

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Wed Feb 26 09:45:12 2014 +0000
Revision:
106:ced8cbb51063
Parent:
76:aeb1df146756
Synchronized with git revision 4222735eff5868389433f0e9271976b39c8115cd

Full URL: https://github.com/mbedmicro/mbed/commit/4222735eff5868389433f0e9271976b39c8115cd/

[NUCLEO_xxx] Update STM32CubeF4 driver V1.0.0 + update license

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