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:
80:66393a7b209d
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 stm32l1xx_pwr.c
mbed_official 76:aeb1df146756 4 * @author MCD Application Team
mbed_official 76:aeb1df146756 5 * @version V1.2.0
mbed_official 76:aeb1df146756 6 * @date 22-February-2013
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 * + RTC Domain Access
mbed_official 76:aeb1df146756 10 * + PVD configuration
mbed_official 76:aeb1df146756 11 * + WakeUp pins configuration
mbed_official 76:aeb1df146756 12 * + Ultra Low Power mode configuration
mbed_official 76:aeb1df146756 13 * + Voltage Scaling configuration
mbed_official 76:aeb1df146756 14 * + Low Power modes configuration
mbed_official 76:aeb1df146756 15 * + Flags management
mbed_official 76:aeb1df146756 16 *
mbed_official 76:aeb1df146756 17 ******************************************************************************
mbed_official 76:aeb1df146756 18 * @attention
mbed_official 76:aeb1df146756 19 *
mbed_official 76:aeb1df146756 20 * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
mbed_official 76:aeb1df146756 21 *
mbed_official 76:aeb1df146756 22 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
mbed_official 76:aeb1df146756 23 * You may not use this file except in compliance with the License.
mbed_official 76:aeb1df146756 24 * You may obtain a copy of the License at:
mbed_official 76:aeb1df146756 25 *
mbed_official 76:aeb1df146756 26 * http://www.st.com/software_license_agreement_liberty_v2
mbed_official 76:aeb1df146756 27 *
mbed_official 76:aeb1df146756 28 * Unless required by applicable law or agreed to in writing, software
mbed_official 76:aeb1df146756 29 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 76:aeb1df146756 30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 76:aeb1df146756 31 * See the License for the specific language governing permissions and
mbed_official 76:aeb1df146756 32 * limitations under the License.
mbed_official 76:aeb1df146756 33 *
mbed_official 76:aeb1df146756 34 ******************************************************************************
mbed_official 76:aeb1df146756 35 */
mbed_official 76:aeb1df146756 36
mbed_official 76:aeb1df146756 37 /* Includes ------------------------------------------------------------------*/
mbed_official 76:aeb1df146756 38 #include "stm32l1xx_pwr.h"
mbed_official 76:aeb1df146756 39 #include "stm32l1xx_rcc.h"
mbed_official 76:aeb1df146756 40
mbed_official 76:aeb1df146756 41 /** @addtogroup STM32L1xx_StdPeriph_Driver
mbed_official 76:aeb1df146756 42 * @{
mbed_official 76:aeb1df146756 43 */
mbed_official 76:aeb1df146756 44
mbed_official 76:aeb1df146756 45 /** @defgroup PWR
mbed_official 76:aeb1df146756 46 * @brief PWR driver modules
mbed_official 76:aeb1df146756 47 * @{
mbed_official 76:aeb1df146756 48 */
mbed_official 76:aeb1df146756 49
mbed_official 76:aeb1df146756 50 /* Private typedef -----------------------------------------------------------*/
mbed_official 76:aeb1df146756 51 /* Private define ------------------------------------------------------------*/
mbed_official 76:aeb1df146756 52 /* --------- PWR registers bit address in the alias region ---------- */
mbed_official 76:aeb1df146756 53 #define PWR_OFFSET (PWR_BASE - PERIPH_BASE)
mbed_official 76:aeb1df146756 54
mbed_official 76:aeb1df146756 55 /* --- CR Register ---*/
mbed_official 76:aeb1df146756 56
mbed_official 76:aeb1df146756 57 /* Alias word address of DBP bit */
mbed_official 76:aeb1df146756 58 #define CR_OFFSET (PWR_OFFSET + 0x00)
mbed_official 76:aeb1df146756 59 #define DBP_BitNumber 0x08
mbed_official 76:aeb1df146756 60 #define CR_DBP_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (DBP_BitNumber * 4))
mbed_official 76:aeb1df146756 61
mbed_official 76:aeb1df146756 62 /* Alias word address of PVDE bit */
mbed_official 76:aeb1df146756 63 #define PVDE_BitNumber 0x04
mbed_official 76:aeb1df146756 64 #define CR_PVDE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PVDE_BitNumber * 4))
mbed_official 76:aeb1df146756 65
mbed_official 76:aeb1df146756 66 /* Alias word address of ULP bit */
mbed_official 76:aeb1df146756 67 #define ULP_BitNumber 0x09
mbed_official 76:aeb1df146756 68 #define CR_ULP_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (ULP_BitNumber * 4))
mbed_official 76:aeb1df146756 69
mbed_official 76:aeb1df146756 70 /* Alias word address of FWU bit */
mbed_official 76:aeb1df146756 71 #define FWU_BitNumber 0x0A
mbed_official 76:aeb1df146756 72 #define CR_FWU_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (FWU_BitNumber * 4))
mbed_official 76:aeb1df146756 73
mbed_official 76:aeb1df146756 74 /* --- CSR Register ---*/
mbed_official 76:aeb1df146756 75
mbed_official 76:aeb1df146756 76 /* Alias word address of EWUP bit */
mbed_official 76:aeb1df146756 77 #define CSR_OFFSET (PWR_OFFSET + 0x04)
mbed_official 76:aeb1df146756 78 #define EWUP_BitNumber 0x08
mbed_official 76:aeb1df146756 79 #define CSR_EWUP_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (EWUP_BitNumber * 4))
mbed_official 76:aeb1df146756 80
mbed_official 76:aeb1df146756 81 /* ------------------ PWR registers bit mask ------------------------ */
mbed_official 76:aeb1df146756 82
mbed_official 76:aeb1df146756 83 /* CR register bit mask */
mbed_official 76:aeb1df146756 84 #define CR_DS_MASK ((uint32_t)0xFFFFFFFC)
mbed_official 76:aeb1df146756 85 #define CR_PLS_MASK ((uint32_t)0xFFFFFF1F)
mbed_official 76:aeb1df146756 86 #define CR_VOS_MASK ((uint32_t)0xFFFFE7FF)
mbed_official 76:aeb1df146756 87
mbed_official 76:aeb1df146756 88 /* Private macro -------------------------------------------------------------*/
mbed_official 76:aeb1df146756 89 /* Private variables ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 90 /* Private function prototypes -----------------------------------------------*/
mbed_official 76:aeb1df146756 91 /* Private functions ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 92
mbed_official 76:aeb1df146756 93 /** @defgroup PWR_Private_Functions
mbed_official 76:aeb1df146756 94 * @{
mbed_official 76:aeb1df146756 95 */
mbed_official 76:aeb1df146756 96
mbed_official 76:aeb1df146756 97 /** @defgroup PWR_Group1 RTC Domain Access function
mbed_official 76:aeb1df146756 98 * @brief RTC Domain Access function
mbed_official 76:aeb1df146756 99 *
mbed_official 76:aeb1df146756 100 @verbatim
mbed_official 76:aeb1df146756 101 ==============================================================================
mbed_official 76:aeb1df146756 102 ##### RTC Domain Access function #####
mbed_official 76:aeb1df146756 103 ==============================================================================
mbed_official 76:aeb1df146756 104
mbed_official 76:aeb1df146756 105 [..] After reset, the RTC Registers (RCC CSR Register, RTC registers and RTC backup
mbed_official 76:aeb1df146756 106 registers) are protected against possible stray write accesses.
mbed_official 76:aeb1df146756 107 [..] To enable access to RTC domain use the PWR_RTCAccessCmd(ENABLE) function.
mbed_official 76:aeb1df146756 108
mbed_official 76:aeb1df146756 109 @endverbatim
mbed_official 76:aeb1df146756 110 * @{
mbed_official 76:aeb1df146756 111 */
mbed_official 76:aeb1df146756 112
mbed_official 76:aeb1df146756 113 /**
mbed_official 76:aeb1df146756 114 * @brief Deinitializes the PWR peripheral registers to their default reset values.
mbed_official 76:aeb1df146756 115 * @note Before calling this function, the VOS[1:0] bits should be configured
mbed_official 76:aeb1df146756 116 * to "10" and the system frequency has to be configured accordingly.
mbed_official 76:aeb1df146756 117 * To configure the VOS[1:0] bits, use the PWR_VoltageScalingConfig()
mbed_official 76:aeb1df146756 118 * function.
mbed_official 76:aeb1df146756 119 * @note ULP and FWU bits are not reset by this function.
mbed_official 76:aeb1df146756 120 * @param None
mbed_official 76:aeb1df146756 121 * @retval None
mbed_official 76:aeb1df146756 122 */
mbed_official 76:aeb1df146756 123 void PWR_DeInit(void)
mbed_official 76:aeb1df146756 124 {
mbed_official 76:aeb1df146756 125 RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);
mbed_official 76:aeb1df146756 126 RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, DISABLE);
mbed_official 76:aeb1df146756 127 }
mbed_official 76:aeb1df146756 128
mbed_official 76:aeb1df146756 129 /**
mbed_official 76:aeb1df146756 130 * @brief Enables or disables access to the RTC and backup registers.
mbed_official 76:aeb1df146756 131 * @note If the HSE divided by 2, 4, 8 or 16 is used as the RTC clock, the
mbed_official 76:aeb1df146756 132 * RTC Domain Access should be kept enabled.
mbed_official 76:aeb1df146756 133 * @param NewState: new state of the access to the RTC and backup registers.
mbed_official 76:aeb1df146756 134 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 135 * @retval None
mbed_official 76:aeb1df146756 136 */
mbed_official 76:aeb1df146756 137 void PWR_RTCAccessCmd(FunctionalState NewState)
mbed_official 76:aeb1df146756 138 {
mbed_official 76:aeb1df146756 139 /* Check the parameters */
mbed_official 76:aeb1df146756 140 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 141
mbed_official 76:aeb1df146756 142 *(__IO uint32_t *) CR_DBP_BB = (uint32_t)NewState;
mbed_official 76:aeb1df146756 143 }
mbed_official 76:aeb1df146756 144
mbed_official 76:aeb1df146756 145 /**
mbed_official 76:aeb1df146756 146 * @}
mbed_official 76:aeb1df146756 147 */
mbed_official 76:aeb1df146756 148
mbed_official 76:aeb1df146756 149 /** @defgroup PWR_Group2 PVD configuration functions
mbed_official 76:aeb1df146756 150 * @brief PVD configuration functions
mbed_official 76:aeb1df146756 151 *
mbed_official 76:aeb1df146756 152 @verbatim
mbed_official 76:aeb1df146756 153 ==============================================================================
mbed_official 76:aeb1df146756 154 ##### PVD configuration functions #####
mbed_official 76:aeb1df146756 155 ==============================================================================
mbed_official 76:aeb1df146756 156 [..]
mbed_official 76:aeb1df146756 157 (+) The PVD is used to monitor the VDD power supply by comparing it to a threshold
mbed_official 76:aeb1df146756 158 selected by the PVD Level (PLS[2:0] bits in the PWR_CR).
mbed_official 76:aeb1df146756 159 (+) The PVD can use an external input analog voltage (PVD_IN) which is compared
mbed_official 76:aeb1df146756 160 internally to VREFINT. The PVD_IN (PB7) has to be configured in Analog mode
mbed_official 76:aeb1df146756 161 when PWR_PVDLevel_7 is selected (PLS[2:0] = 111).
mbed_official 76:aeb1df146756 162 (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower than the
mbed_official 76:aeb1df146756 163 PVD threshold. This event is internally connected to the EXTI line16
mbed_official 76:aeb1df146756 164 and can generate an interrupt if enabled through the EXTI registers.
mbed_official 76:aeb1df146756 165 (+) The PVD is stopped in Standby mode.
mbed_official 76:aeb1df146756 166
mbed_official 76:aeb1df146756 167 @endverbatim
mbed_official 76:aeb1df146756 168 * @{
mbed_official 76:aeb1df146756 169 */
mbed_official 76:aeb1df146756 170
mbed_official 76:aeb1df146756 171 /**
mbed_official 76:aeb1df146756 172 * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD).
mbed_official 76:aeb1df146756 173 * @param PWR_PVDLevel: specifies the PVD detection level.
mbed_official 76:aeb1df146756 174 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 175 * @arg PWR_PVDLevel_0: PVD detection level set to 1.9V.
mbed_official 76:aeb1df146756 176 * @arg PWR_PVDLevel_1: PVD detection level set to 2.1V.
mbed_official 76:aeb1df146756 177 * @arg PWR_PVDLevel_2: PVD detection level set to 2.3V.
mbed_official 76:aeb1df146756 178 * @arg PWR_PVDLevel_3: PVD detection level set to 2.5V.
mbed_official 76:aeb1df146756 179 * @arg PWR_PVDLevel_4: PVD detection level set to 2.7V.
mbed_official 76:aeb1df146756 180 * @arg PWR_PVDLevel_5: PVD detection level set to 2.9V.
mbed_official 76:aeb1df146756 181 * @arg PWR_PVDLevel_6: PVD detection level set to 3.1V.
mbed_official 76:aeb1df146756 182 * @arg PWR_PVDLevel_7: External input analog voltage (Compare internally to VREFINT).
mbed_official 76:aeb1df146756 183 * @retval None
mbed_official 76:aeb1df146756 184 */
mbed_official 76:aeb1df146756 185 void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel)
mbed_official 76:aeb1df146756 186 {
mbed_official 76:aeb1df146756 187 uint32_t tmpreg = 0;
mbed_official 76:aeb1df146756 188
mbed_official 76:aeb1df146756 189 /* Check the parameters */
mbed_official 76:aeb1df146756 190 assert_param(IS_PWR_PVD_LEVEL(PWR_PVDLevel));
mbed_official 76:aeb1df146756 191
mbed_official 76:aeb1df146756 192 tmpreg = PWR->CR;
mbed_official 76:aeb1df146756 193
mbed_official 76:aeb1df146756 194 /* Clear PLS[7:5] bits */
mbed_official 76:aeb1df146756 195 tmpreg &= CR_PLS_MASK;
mbed_official 76:aeb1df146756 196
mbed_official 76:aeb1df146756 197 /* Set PLS[7:5] bits according to PWR_PVDLevel value */
mbed_official 76:aeb1df146756 198 tmpreg |= PWR_PVDLevel;
mbed_official 76:aeb1df146756 199
mbed_official 76:aeb1df146756 200 /* Store the new value */
mbed_official 76:aeb1df146756 201 PWR->CR = tmpreg;
mbed_official 76:aeb1df146756 202 }
mbed_official 76:aeb1df146756 203
mbed_official 76:aeb1df146756 204 /**
mbed_official 76:aeb1df146756 205 * @brief Enables or disables the Power Voltage Detector(PVD).
mbed_official 76:aeb1df146756 206 * @param NewState: new state of the PVD.
mbed_official 76:aeb1df146756 207 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 208 * @retval None
mbed_official 76:aeb1df146756 209 */
mbed_official 76:aeb1df146756 210 void PWR_PVDCmd(FunctionalState NewState)
mbed_official 76:aeb1df146756 211 {
mbed_official 76:aeb1df146756 212 /* Check the parameters */
mbed_official 76:aeb1df146756 213 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 214
mbed_official 76:aeb1df146756 215 *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)NewState;
mbed_official 76:aeb1df146756 216 }
mbed_official 76:aeb1df146756 217
mbed_official 76:aeb1df146756 218 /**
mbed_official 76:aeb1df146756 219 * @}
mbed_official 76:aeb1df146756 220 */
mbed_official 76:aeb1df146756 221
mbed_official 76:aeb1df146756 222 /** @defgroup PWR_Group3 WakeUp pins configuration functions
mbed_official 76:aeb1df146756 223 * @brief WakeUp pins configuration functions
mbed_official 76:aeb1df146756 224 *
mbed_official 76:aeb1df146756 225 @verbatim
mbed_official 76:aeb1df146756 226 ==============================================================================
mbed_official 76:aeb1df146756 227 ##### WakeUp pin configuration functions #####
mbed_official 76:aeb1df146756 228 ==============================================================================
mbed_official 76:aeb1df146756 229
mbed_official 76:aeb1df146756 230 (+) WakeUp pins are used to wakeup the system from Standby mode. These pins are
mbed_official 76:aeb1df146756 231 forced in input pull down configuration and are active on rising edges.
mbed_official 76:aeb1df146756 232 (+) There are three WakeUp pins: WakeUp Pin 1 on PA.00, WakeUp Pin 2 on PC.13 and
mbed_official 76:aeb1df146756 233 WakeUp Pin 3 on PE.06.
mbed_official 76:aeb1df146756 234
mbed_official 76:aeb1df146756 235 @endverbatim
mbed_official 76:aeb1df146756 236 * @{
mbed_official 76:aeb1df146756 237 */
mbed_official 76:aeb1df146756 238
mbed_official 76:aeb1df146756 239 /**
mbed_official 76:aeb1df146756 240 * @brief Enables or disables the WakeUp Pin functionality.
mbed_official 76:aeb1df146756 241 * @param PWR_WakeUpPin: specifies the WakeUpPin.
mbed_official 76:aeb1df146756 242 * This parameter can be: PWR_WakeUpPin_1, PWR_WakeUpPin_2 or PWR_WakeUpPin_3.
mbed_official 76:aeb1df146756 243 * @param NewState: new state of the WakeUp Pin functionality.
mbed_official 76:aeb1df146756 244 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 245 * @retval None
mbed_official 76:aeb1df146756 246 */
mbed_official 76:aeb1df146756 247 void PWR_WakeUpPinCmd(uint32_t PWR_WakeUpPin, FunctionalState NewState)
mbed_official 76:aeb1df146756 248 {
mbed_official 76:aeb1df146756 249 __IO uint32_t tmp = 0;
mbed_official 76:aeb1df146756 250
mbed_official 76:aeb1df146756 251 /* Check the parameters */
mbed_official 76:aeb1df146756 252 assert_param(IS_PWR_WAKEUP_PIN(PWR_WakeUpPin));
mbed_official 76:aeb1df146756 253
mbed_official 76:aeb1df146756 254 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 255
mbed_official 76:aeb1df146756 256 tmp = CSR_EWUP_BB + PWR_WakeUpPin;
mbed_official 76:aeb1df146756 257
mbed_official 76:aeb1df146756 258 *(__IO uint32_t *) (tmp) = (uint32_t)NewState;
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
mbed_official 76:aeb1df146756 265 /** @defgroup PWR_Group4 Ultra Low Power mode configuration functions
mbed_official 76:aeb1df146756 266 * @brief Ultra Low Power mode configuration functions
mbed_official 76:aeb1df146756 267 *
mbed_official 76:aeb1df146756 268 @verbatim
mbed_official 76:aeb1df146756 269 ==============================================================================
mbed_official 76:aeb1df146756 270 ##### Ultra Low Power mode configuration functions #####
mbed_official 76:aeb1df146756 271 ==============================================================================
mbed_official 76:aeb1df146756 272 [..]
mbed_official 76:aeb1df146756 273 (+) The internal voltage reference consumption is not negligible, in particular
mbed_official 76:aeb1df146756 274 in Stop and Standby mode. To reduce power consumption, use the PWR_UltraLowPowerCmd()
mbed_official 76:aeb1df146756 275 function (ULP bit (Ultra low power) in the PWR_CR register) to disable the
mbed_official 76:aeb1df146756 276 internal voltage reference. However, in this case, when exiting from the
mbed_official 76:aeb1df146756 277 Stop/Standby mode, the functions managed through the internal voltage reference
mbed_official 76:aeb1df146756 278 are not reliable during the internal voltage reference startup time (up to 3 ms).
mbed_official 76:aeb1df146756 279 To reduce the wakeup time, the device can exit from Stop/Standby mode without
mbed_official 76:aeb1df146756 280 waiting for the internal voltage reference startup time. This is performed
mbed_official 76:aeb1df146756 281 by using the PWR_FastWakeUpCmd() function (setting the FWU bit (Fast
mbed_official 76:aeb1df146756 282 wakeup) in the PWR_CR register) before entering Stop/Standby mode.
mbed_official 76:aeb1df146756 283
mbed_official 76:aeb1df146756 284 @endverbatim
mbed_official 76:aeb1df146756 285 * @{
mbed_official 76:aeb1df146756 286 */
mbed_official 76:aeb1df146756 287
mbed_official 76:aeb1df146756 288 /**
mbed_official 76:aeb1df146756 289 * @brief Enables or disables the Fast WakeUp from Ultra Low Power mode.
mbed_official 76:aeb1df146756 290 * @param NewState: new state of the Fast WakeUp functionality.
mbed_official 76:aeb1df146756 291 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 292 * @retval None
mbed_official 76:aeb1df146756 293 */
mbed_official 76:aeb1df146756 294 void PWR_FastWakeUpCmd(FunctionalState NewState)
mbed_official 76:aeb1df146756 295 {
mbed_official 76:aeb1df146756 296 /* Check the parameters */
mbed_official 76:aeb1df146756 297 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 298
mbed_official 76:aeb1df146756 299 *(__IO uint32_t *) CR_FWU_BB = (uint32_t)NewState;
mbed_official 76:aeb1df146756 300 }
mbed_official 76:aeb1df146756 301
mbed_official 76:aeb1df146756 302 /**
mbed_official 76:aeb1df146756 303 * @brief Enables or disables the Ultra Low Power mode.
mbed_official 76:aeb1df146756 304 * @param NewState: new state of the Ultra Low Power mode.
mbed_official 76:aeb1df146756 305 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 306 * @retval None
mbed_official 76:aeb1df146756 307 */
mbed_official 76:aeb1df146756 308 void PWR_UltraLowPowerCmd(FunctionalState NewState)
mbed_official 76:aeb1df146756 309 {
mbed_official 76:aeb1df146756 310 /* Check the parameters */
mbed_official 76:aeb1df146756 311 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 312
mbed_official 76:aeb1df146756 313 *(__IO uint32_t *) CR_ULP_BB = (uint32_t)NewState;
mbed_official 76:aeb1df146756 314 }
mbed_official 76:aeb1df146756 315
mbed_official 76:aeb1df146756 316 /**
mbed_official 76:aeb1df146756 317 * @}
mbed_official 76:aeb1df146756 318 */
mbed_official 76:aeb1df146756 319
mbed_official 76:aeb1df146756 320 /** @defgroup PWR_Group5 Voltage Scaling configuration functions
mbed_official 76:aeb1df146756 321 * @brief Voltage Scaling configuration functions
mbed_official 76:aeb1df146756 322 *
mbed_official 76:aeb1df146756 323 @verbatim
mbed_official 76:aeb1df146756 324 ==============================================================================
mbed_official 76:aeb1df146756 325 ##### Voltage Scaling configuration functions #####
mbed_official 76:aeb1df146756 326 ==============================================================================
mbed_official 76:aeb1df146756 327
mbed_official 76:aeb1df146756 328 (+) The dynamic voltage scaling is a power management technique which consists in
mbed_official 76:aeb1df146756 329 increasing or decreasing the voltage used for the digital peripherals (VCORE),
mbed_official 76:aeb1df146756 330 according to the circumstances.
mbed_official 76:aeb1df146756 331
mbed_official 76:aeb1df146756 332 [..] Depending on the device voltage range, the maximum frequency and FLASH wait
mbed_official 76:aeb1df146756 333 state should be adapted accordingly:
mbed_official 76:aeb1df146756 334 [..]
mbed_official 76:aeb1df146756 335 +------------------------------------------------------------------+
mbed_official 76:aeb1df146756 336 | Wait states | HCLK clock frequency (MHz) |
mbed_official 76:aeb1df146756 337 | |------------------------------------------------|
mbed_official 76:aeb1df146756 338 | (Latency) | voltage range | voltage range |
mbed_official 76:aeb1df146756 339 | | 1.65 V - 3.6 V | 2.0 V - 3.6 V |
mbed_official 76:aeb1df146756 340 | |----------------|---------------|---------------|
mbed_official 76:aeb1df146756 341 | | Range 3 | Range 2 | Range 1 |
mbed_official 76:aeb1df146756 342 | | VCORE = 1.2 V | VCORE = 1.5 V | VCORE = 1.8 V |
mbed_official 76:aeb1df146756 343 |---------------- |----------------|---------------|---------------|
mbed_official 76:aeb1df146756 344 | 0WS(1CPU cycle) |0 < HCLK <= 2 |0 < HCLK <= 8 |0 < HCLK <= 16 |
mbed_official 76:aeb1df146756 345 |-----------------|----------------|---------------|---------------|
mbed_official 76:aeb1df146756 346 | 1WS(2CPU cycle) |2 < HCLK <= 4 |8 < HCLK <= 16 |16 < HCLK <= 32|
mbed_official 76:aeb1df146756 347 |-----------------|----------------|---------------|---------------|
mbed_official 76:aeb1df146756 348 | CPU Performance | Low | Medium | High |
mbed_official 76:aeb1df146756 349 |-----__----------|----------------|---------------|---------------|
mbed_official 76:aeb1df146756 350 |Power Performance| High | Medium | Low |
mbed_official 76:aeb1df146756 351 +------------------------------------------------------------------+
mbed_official 76:aeb1df146756 352
mbed_official 76:aeb1df146756 353 (+) To modify the Product voltage range, user application has to:
mbed_official 76:aeb1df146756 354 (++) Check VDD to identify which ranges are allowed (see table above).
mbed_official 76:aeb1df146756 355 (++) Check the PWR_FLAG_VOSF (Voltage Scaling update ongoing) using the PWR_GetFlagStatus()
mbed_official 76:aeb1df146756 356 function and wait until it is reset.
mbed_official 76:aeb1df146756 357 (++) Configure the Voltage range using the PWR_VoltageScalingConfig() function.
mbed_official 76:aeb1df146756 358
mbed_official 76:aeb1df146756 359 (+) When VCORE range 1 is selected and VDD drops below 2.0 V, the application must
mbed_official 76:aeb1df146756 360 reconfigure the system:
mbed_official 76:aeb1df146756 361 (++) Detect that VDD drops below 2.0 V using the PVD Level 1.
mbed_official 76:aeb1df146756 362 (++) Adapt the clock frequency to the voltage range that will be selected at next step.
mbed_official 76:aeb1df146756 363 (++) Select the required voltage range.
mbed_official 76:aeb1df146756 364 (++) When VCORE range 2 or range 3 is selected and VDD drops below 2.0 V, no system
mbed_official 76:aeb1df146756 365 reconfiguration is required.
mbed_official 76:aeb1df146756 366
mbed_official 76:aeb1df146756 367 (+) When VDD is above 2.0 V, any of the 3 voltage ranges can be selected.
mbed_official 76:aeb1df146756 368 (++) When the voltage range is above the targeted voltage range (e.g. from range
mbed_official 76:aeb1df146756 369 1 to 2).
mbed_official 76:aeb1df146756 370 (++) Adapt the clock frequency to the lower voltage range that will be selected
mbed_official 76:aeb1df146756 371 at next step.
mbed_official 76:aeb1df146756 372 (++) Select the required voltage range.
mbed_official 76:aeb1df146756 373 (++) When the voltage range is below the targeted voltage range (e.g. from range
mbed_official 76:aeb1df146756 374 3 to 1).
mbed_official 76:aeb1df146756 375 (++) Select the required voltage range.
mbed_official 76:aeb1df146756 376 (++) Tune the clock frequency if needed.
mbed_official 76:aeb1df146756 377
mbed_official 76:aeb1df146756 378 (+) When VDD is below 2.0 V, only range 2 and 3 can be selected:
mbed_official 76:aeb1df146756 379 (++) From range 2 to range 3.
mbed_official 76:aeb1df146756 380 (+++) Adapt the clock frequency to voltage range 3.
mbed_official 76:aeb1df146756 381 (+++) Select voltage range 3.
mbed_official 76:aeb1df146756 382 (++) From range 3 to range 2.
mbed_official 76:aeb1df146756 383 (+++) Select the voltage range 2.
mbed_official 76:aeb1df146756 384 (+++) Tune the clock frequency if needed.
mbed_official 76:aeb1df146756 385
mbed_official 76:aeb1df146756 386 @endverbatim
mbed_official 76:aeb1df146756 387 * @{
mbed_official 76:aeb1df146756 388 */
mbed_official 76:aeb1df146756 389
mbed_official 76:aeb1df146756 390 /**
mbed_official 76:aeb1df146756 391 * @brief Configures the voltage scaling range.
mbed_official 76:aeb1df146756 392 * @note During voltage scaling configuration, the system clock is stopped
mbed_official 76:aeb1df146756 393 * until the regulator is stabilized (VOSF = 0). This must be taken
mbed_official 76:aeb1df146756 394 * into account during application developement, in case a critical
mbed_official 76:aeb1df146756 395 * reaction time to interrupt is needed, and depending on peripheral
mbed_official 76:aeb1df146756 396 * used (timer, communication,...).
mbed_official 76:aeb1df146756 397 *
mbed_official 76:aeb1df146756 398 * @param PWR_VoltageScaling: specifies the voltage scaling range.
mbed_official 76:aeb1df146756 399 * This parameter can be:
mbed_official 76:aeb1df146756 400 * @arg PWR_VoltageScaling_Range1: Voltage Scaling Range 1 (VCORE = 1.8V).
mbed_official 76:aeb1df146756 401 * @arg PWR_VoltageScaling_Range2: Voltage Scaling Range 2 (VCORE = 1.5V).
mbed_official 76:aeb1df146756 402 * @arg PWR_VoltageScaling_Range3: Voltage Scaling Range 3 (VCORE = 1.2V)
mbed_official 76:aeb1df146756 403 * @retval None
mbed_official 76:aeb1df146756 404 */
mbed_official 76:aeb1df146756 405 void PWR_VoltageScalingConfig(uint32_t PWR_VoltageScaling)
mbed_official 76:aeb1df146756 406 {
mbed_official 76:aeb1df146756 407 uint32_t tmp = 0;
mbed_official 76:aeb1df146756 408
mbed_official 76:aeb1df146756 409 /* Check the parameters */
mbed_official 76:aeb1df146756 410 assert_param(IS_PWR_VOLTAGE_SCALING_RANGE(PWR_VoltageScaling));
mbed_official 76:aeb1df146756 411
mbed_official 76:aeb1df146756 412 tmp = PWR->CR;
mbed_official 76:aeb1df146756 413
mbed_official 76:aeb1df146756 414 tmp &= CR_VOS_MASK;
mbed_official 76:aeb1df146756 415 tmp |= PWR_VoltageScaling;
mbed_official 76:aeb1df146756 416
mbed_official 76:aeb1df146756 417 PWR->CR = tmp & 0xFFFFFFF3;
mbed_official 76:aeb1df146756 418
mbed_official 76:aeb1df146756 419 }
mbed_official 76:aeb1df146756 420
mbed_official 76:aeb1df146756 421 /**
mbed_official 76:aeb1df146756 422 * @}
mbed_official 76:aeb1df146756 423 */
mbed_official 76:aeb1df146756 424
mbed_official 76:aeb1df146756 425 /** @defgroup PWR_Group6 Low Power modes configuration functions
mbed_official 76:aeb1df146756 426 * @brief Low Power modes configuration functions
mbed_official 76:aeb1df146756 427 *
mbed_official 76:aeb1df146756 428 @verbatim
mbed_official 76:aeb1df146756 429 ==============================================================================
mbed_official 76:aeb1df146756 430 ##### Low Power modes configuration functions #####
mbed_official 76:aeb1df146756 431 ==============================================================================
mbed_official 76:aeb1df146756 432
mbed_official 76:aeb1df146756 433 [..] The devices feature five low-power modes:
mbed_official 76:aeb1df146756 434 (+) Low power run mode: regulator in low power mode, limited clock frequency,
mbed_official 76:aeb1df146756 435 limited number of peripherals running.
mbed_official 76:aeb1df146756 436 (+) Sleep mode: Cortex-M3 core stopped, peripherals kept running.
mbed_official 76:aeb1df146756 437 (+) Low power sleep mode: Cortex-M3 core stopped, limited clock frequency,
mbed_official 76:aeb1df146756 438 limited number of peripherals running, regulator in low power mode.
mbed_official 76:aeb1df146756 439 (+) Stop mode: all clocks are stopped, regulator running, regulator in low power mode.
mbed_official 76:aeb1df146756 440 (+) Standby mode: VCORE domain powered off.
mbed_official 76:aeb1df146756 441
mbed_official 76:aeb1df146756 442 *** Low power run mode (LP run) ***
mbed_official 76:aeb1df146756 443 ===================================
mbed_official 76:aeb1df146756 444 [..]
mbed_official 76:aeb1df146756 445 (+) Entry:
mbed_official 76:aeb1df146756 446 (++) Decrease the system frequency.
mbed_official 76:aeb1df146756 447 (++) The regulator is forced in low power mode using the PWR_EnterLowPowerRunMode()
mbed_official 76:aeb1df146756 448 function.
mbed_official 76:aeb1df146756 449 (+) Exit:
mbed_official 76:aeb1df146756 450 (++) The regulator is forced in Main regulator mode sing the PWR_EnterLowPowerRunMode()
mbed_official 76:aeb1df146756 451 function.
mbed_official 76:aeb1df146756 452 (++) Increase the system frequency if needed.
mbed_official 76:aeb1df146756 453
mbed_official 76:aeb1df146756 454 *** Sleep mode ***
mbed_official 76:aeb1df146756 455 ==================
mbed_official 76:aeb1df146756 456 [..]
mbed_official 76:aeb1df146756 457 (+) Entry:
mbed_official 76:aeb1df146756 458 (++) The Sleep mode is entered by using the PWR_EnterSleepMode(PWR_Regulator_ON,)
mbed_official 76:aeb1df146756 459 function with regulator ON.
mbed_official 76:aeb1df146756 460 (+) Exit:
mbed_official 76:aeb1df146756 461 (++) Any peripheral interrupt acknowledged by the nested vectored interrupt
mbed_official 76:aeb1df146756 462 controller (NVIC) can wake up the device from Sleep mode.
mbed_official 76:aeb1df146756 463
mbed_official 76:aeb1df146756 464 *** Low power sleep mode (LP sleep) ***
mbed_official 76:aeb1df146756 465 =======================================
mbed_official 76:aeb1df146756 466 [..]
mbed_official 76:aeb1df146756 467 (+) Entry:
mbed_official 76:aeb1df146756 468 (++) The Flash memory must be switched off by using the FLASH_SLEEPPowerDownCmd()
mbed_official 76:aeb1df146756 469 function.
mbed_official 76:aeb1df146756 470 (++) Decrease the system frequency.
mbed_official 76:aeb1df146756 471 (++) The regulator is forced in low power mode and the WFI or WFE instructions
mbed_official 76:aeb1df146756 472 are executed using the PWR_EnterSleepMode(PWR_Regulator_LowPower,) function
mbed_official 76:aeb1df146756 473 with regulator in LowPower.
mbed_official 76:aeb1df146756 474 (+) Exit:
mbed_official 76:aeb1df146756 475 (++) Any peripheral interrupt acknowledged by the nested vectored interrupt
mbed_official 76:aeb1df146756 476 controller (NVIC) can wake up the device from Sleep LP mode.
mbed_official 76:aeb1df146756 477
mbed_official 76:aeb1df146756 478 *** Stop mode ***
mbed_official 76:aeb1df146756 479 =================
mbed_official 76:aeb1df146756 480 [..] In Stop mode, all clocks in the VCORE domain are stopped, the PLL, the MSI,
mbed_official 76:aeb1df146756 481 the HSI and the HSE RC oscillators are disabled. Internal SRAM and register
mbed_official 76:aeb1df146756 482 contents are preserved.
mbed_official 76:aeb1df146756 483 The voltage regulator can be configured either in normal or low-power mode.
mbed_official 76:aeb1df146756 484 To minimize the consumption In Stop mode, VREFINT, the BOR, PVD, and temperature
mbed_official 76:aeb1df146756 485 sensor can be switched off before entering the Stop mode. They can be switched
mbed_official 76:aeb1df146756 486 on again by software after exiting the Stop mode using the PWR_UltraLowPowerCmd()
mbed_official 76:aeb1df146756 487 function.
mbed_official 76:aeb1df146756 488
mbed_official 76:aeb1df146756 489 (+) Entry:
mbed_official 76:aeb1df146756 490 (++) The Stop mode is entered using the PWR_EnterSTOPMode(PWR_Regulator_LowPower,)
mbed_official 76:aeb1df146756 491 function with regulator in LowPower or with Regulator ON.
mbed_official 76:aeb1df146756 492 (+) Exit:
mbed_official 76:aeb1df146756 493 (++) Any EXTI Line (Internal or External) configured in Interrupt/Event mode.
mbed_official 76:aeb1df146756 494
mbed_official 76:aeb1df146756 495 *** Standby mode ***
mbed_official 76:aeb1df146756 496 ====================
mbed_official 76:aeb1df146756 497 [..] The Standby mode allows to achieve the lowest power consumption. It is based
mbed_official 76:aeb1df146756 498 on the Cortex-M3 deepsleep mode, with the voltage regulator disabled.
mbed_official 76:aeb1df146756 499 The VCORE domain is consequently powered off. The PLL, the MSI, the HSI
mbed_official 76:aeb1df146756 500 oscillator and the HSE oscillator are also switched off. SRAM and register
mbed_official 76:aeb1df146756 501 contents are lost except for the RTC registers, RTC backup registers and
mbed_official 76:aeb1df146756 502 Standby circuitry.
mbed_official 76:aeb1df146756 503
mbed_official 76:aeb1df146756 504 [..] The voltage regulator is OFF.
mbed_official 76:aeb1df146756 505
mbed_official 76:aeb1df146756 506 [..] To minimize the consumption In Standby mode, VREFINT, the BOR, PVD, and temperature
mbed_official 76:aeb1df146756 507 sensor can be switched off before entering the Standby mode. They can be switched
mbed_official 76:aeb1df146756 508 on again by software after exiting the Standby mode using the PWR_UltraLowPowerCmd()
mbed_official 76:aeb1df146756 509 function.
mbed_official 76:aeb1df146756 510
mbed_official 76:aeb1df146756 511 (+) Entry:
mbed_official 76:aeb1df146756 512 (++) The Standby mode is entered using the PWR_EnterSTANDBYMode() function.
mbed_official 76:aeb1df146756 513 (+) Exit:
mbed_official 76:aeb1df146756 514 (++) WKUP pin rising edge, RTC alarm (Alarm A and Alarm B), RTC wakeup,
mbed_official 76:aeb1df146756 515 tamper event, time-stamp event, external reset in NRST pin, IWDG reset.
mbed_official 76:aeb1df146756 516
mbed_official 76:aeb1df146756 517 *** Auto-wakeup (AWU) from low-power mode ***
mbed_official 76:aeb1df146756 518 =============================================
mbed_official 76:aeb1df146756 519 [..]The MCU can be woken up from low-power mode by an RTC Alarm event, an RTC
mbed_official 76:aeb1df146756 520 Wakeup event, a tamper event, a time-stamp event, or a comparator event,
mbed_official 76:aeb1df146756 521 without depending on an external interrupt (Auto-wakeup mode).
mbed_official 76:aeb1df146756 522
mbed_official 76:aeb1df146756 523 (+) RTC auto-wakeup (AWU) from the Stop mode
mbed_official 76:aeb1df146756 524 (++) To wake up from the Stop mode with an RTC alarm event, it is necessary to:
mbed_official 76:aeb1df146756 525 (+++) Configure the EXTI Line 17 to be sensitive to rising edges (Interrupt
mbed_official 76:aeb1df146756 526 or Event modes) using the EXTI_Init() function.
mbed_official 76:aeb1df146756 527 (+++) Enable the RTC Alarm Interrupt using the RTC_ITConfig() function
mbed_official 76:aeb1df146756 528 (+++) Configure the RTC to generate the RTC alarm using the RTC_SetAlarm()
mbed_official 76:aeb1df146756 529 and RTC_AlarmCmd() functions.
mbed_official 76:aeb1df146756 530 (++) To wake up from the Stop mode with an RTC Tamper or time stamp event, it
mbed_official 76:aeb1df146756 531 is necessary to:
mbed_official 76:aeb1df146756 532 (+++) Configure the EXTI Line 19 to be sensitive to rising edges (Interrupt
mbed_official 76:aeb1df146756 533 or Event modes) using the EXTI_Init() function.
mbed_official 76:aeb1df146756 534 (+++) Enable the RTC Tamper or time stamp Interrupt using the RTC_ITConfig()
mbed_official 76:aeb1df146756 535 function.
mbed_official 76:aeb1df146756 536 (+++) Configure the RTC to detect the tamper or time stamp event using the
mbed_official 76:aeb1df146756 537 RTC_TimeStampConfig(), RTC_TamperTriggerConfig() and RTC_TamperCmd()
mbed_official 76:aeb1df146756 538 functions.
mbed_official 76:aeb1df146756 539 (++) To wake up from the Stop mode with an RTC WakeUp event, it is necessary to:
mbed_official 76:aeb1df146756 540 (+++) Configure the EXTI Line 20 to be sensitive to rising edges (Interrupt
mbed_official 76:aeb1df146756 541 or Event modes) using the EXTI_Init() function.
mbed_official 76:aeb1df146756 542 (+++) Enable the RTC WakeUp Interrupt using the RTC_ITConfig() function.
mbed_official 76:aeb1df146756 543 (+++) Configure the RTC to generate the RTC WakeUp event using the RTC_WakeUpClockConfig(),
mbed_official 76:aeb1df146756 544 RTC_SetWakeUpCounter() and RTC_WakeUpCmd() functions.
mbed_official 76:aeb1df146756 545
mbed_official 76:aeb1df146756 546 (+) RTC auto-wakeup (AWU) from the Standby mode
mbed_official 76:aeb1df146756 547 (++) To wake up from the Standby mode with an RTC alarm event, it is necessary to:
mbed_official 76:aeb1df146756 548 (+++) Enable the RTC Alarm Interrupt using the RTC_ITConfig() function.
mbed_official 76:aeb1df146756 549 (+++) Configure the RTC to generate the RTC alarm using the RTC_SetAlarm()
mbed_official 76:aeb1df146756 550 and RTC_AlarmCmd() functions.
mbed_official 76:aeb1df146756 551 (++) To wake up from the Standby mode with an RTC Tamper or time stamp event, it
mbed_official 76:aeb1df146756 552 is necessary to:
mbed_official 76:aeb1df146756 553 (+++) Enable the RTC Tamper or time stamp Interrupt using the RTC_ITConfig()
mbed_official 76:aeb1df146756 554 function.
mbed_official 76:aeb1df146756 555 (+++) Configure the RTC to detect the tamper or time stamp event using the
mbed_official 76:aeb1df146756 556 RTC_TimeStampConfig(), RTC_TamperTriggerConfig() and RTC_TamperCmd()
mbed_official 76:aeb1df146756 557 functions.
mbed_official 76:aeb1df146756 558 (++) To wake up from the Standby mode with an RTC WakeUp event, it is necessary to:
mbed_official 76:aeb1df146756 559 (+++) Enable the RTC WakeUp Interrupt using the RTC_ITConfig() function
mbed_official 76:aeb1df146756 560 (+++) Configure the RTC to generate the RTC WakeUp event using the RTC_WakeUpClockConfig(),
mbed_official 76:aeb1df146756 561 RTC_SetWakeUpCounter() and RTC_WakeUpCmd() functions.
mbed_official 76:aeb1df146756 562
mbed_official 76:aeb1df146756 563 (+) Comparator auto-wakeup (AWU) from the Stop mode
mbed_official 76:aeb1df146756 564 (++) To wake up from the Stop mode with an comparator 1 or comparator 2 wakeup
mbed_official 76:aeb1df146756 565 event, it is necessary to:
mbed_official 76:aeb1df146756 566 (+++) Configure the EXTI Line 21 for comparator 1 or EXTI Line 22 for comparator 2
mbed_official 76:aeb1df146756 567 to be sensitive to to the selected edges (falling, rising or falling
mbed_official 76:aeb1df146756 568 and rising) (Interrupt or Event modes) using the EXTI_Init() function.
mbed_official 76:aeb1df146756 569 (+++) Configure the comparator to generate the event.
mbed_official 76:aeb1df146756 570
mbed_official 76:aeb1df146756 571 @endverbatim
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 * @brief Enters/Exits the Low Power Run mode.
mbed_official 76:aeb1df146756 577 * @note Low power run mode can only be entered when VCORE is in range 2.
mbed_official 76:aeb1df146756 578 * In addition, the dynamic voltage scaling must not be used when Low
mbed_official 76:aeb1df146756 579 * power run mode is selected. Only Stop and Sleep modes with regulator
mbed_official 76:aeb1df146756 580 * configured in Low power mode is allowed when Low power run mode is
mbed_official 76:aeb1df146756 581 * selected.
mbed_official 76:aeb1df146756 582 * @note In Low power run mode, all I/O pins keep the same state as in Run mode.
mbed_official 76:aeb1df146756 583 * @param NewState: new state of the Low Power Run mode.
mbed_official 76:aeb1df146756 584 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 585 * @retval None
mbed_official 76:aeb1df146756 586 */
mbed_official 76:aeb1df146756 587 void PWR_EnterLowPowerRunMode(FunctionalState NewState)
mbed_official 76:aeb1df146756 588 {
mbed_official 76:aeb1df146756 589 /* Check the parameters */
mbed_official 76:aeb1df146756 590 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 591
mbed_official 76:aeb1df146756 592 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 593 {
mbed_official 76:aeb1df146756 594 PWR->CR |= PWR_CR_LPSDSR;
mbed_official 76:aeb1df146756 595 PWR->CR |= PWR_CR_LPRUN;
mbed_official 76:aeb1df146756 596 }
mbed_official 76:aeb1df146756 597 else
mbed_official 76:aeb1df146756 598 {
mbed_official 76:aeb1df146756 599 PWR->CR &= (uint32_t)~((uint32_t)PWR_CR_LPRUN);
mbed_official 76:aeb1df146756 600 PWR->CR &= (uint32_t)~((uint32_t)PWR_CR_LPSDSR);
mbed_official 76:aeb1df146756 601 }
mbed_official 76:aeb1df146756 602 }
mbed_official 76:aeb1df146756 603
mbed_official 76:aeb1df146756 604 /**
mbed_official 76:aeb1df146756 605 * @brief Enters Sleep mode.
mbed_official 76:aeb1df146756 606 * @note In Sleep mode, all I/O pins keep the same state as in Run mode.
mbed_official 76:aeb1df146756 607 * @param PWR_Regulator: specifies the regulator state in Sleep mode.
mbed_official 76:aeb1df146756 608 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 609 * @arg PWR_Regulator_ON: Sleep mode with regulator ON
mbed_official 76:aeb1df146756 610 * @arg PWR_Regulator_LowPower: Sleep mode with regulator in low power mode
mbed_official 76:aeb1df146756 611 * @note Low power sleep mode can only be entered when VCORE is in range 2.
mbed_official 76:aeb1df146756 612 * @note When the voltage regulator operates in low power mode, an additional
mbed_official 76:aeb1df146756 613 * startup delay is incurred when waking up from Low power sleep mode.
mbed_official 76:aeb1df146756 614 * @param PWR_SLEEPEntry: specifies if SLEEP mode in entered with WFI or WFE instruction.
mbed_official 76:aeb1df146756 615 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 616 * @arg PWR_SLEEPEntry_WFI: enter SLEEP mode with WFI instruction
mbed_official 76:aeb1df146756 617 * @arg PWR_SLEEPEntry_WFE: enter SLEEP mode with WFE instruction
mbed_official 76:aeb1df146756 618 * @retval None
mbed_official 76:aeb1df146756 619 */
mbed_official 76:aeb1df146756 620 void PWR_EnterSleepMode(uint32_t PWR_Regulator, uint8_t PWR_SLEEPEntry)
mbed_official 76:aeb1df146756 621 {
mbed_official 76:aeb1df146756 622 uint32_t tmpreg = 0;
mbed_official 76:aeb1df146756 623
mbed_official 76:aeb1df146756 624 /* Check the parameters */
mbed_official 76:aeb1df146756 625 assert_param(IS_PWR_REGULATOR(PWR_Regulator));
mbed_official 76:aeb1df146756 626
mbed_official 76:aeb1df146756 627 assert_param(IS_PWR_SLEEP_ENTRY(PWR_SLEEPEntry));
mbed_official 76:aeb1df146756 628
mbed_official 76:aeb1df146756 629 /* Select the regulator state in Sleep mode ---------------------------------*/
mbed_official 76:aeb1df146756 630 tmpreg = PWR->CR;
mbed_official 76:aeb1df146756 631
mbed_official 76:aeb1df146756 632 /* Clear PDDS and LPDSR bits */
mbed_official 76:aeb1df146756 633 tmpreg &= CR_DS_MASK;
mbed_official 76:aeb1df146756 634
mbed_official 76:aeb1df146756 635 /* Set LPDSR bit according to PWR_Regulator value */
mbed_official 76:aeb1df146756 636 tmpreg |= PWR_Regulator;
mbed_official 76:aeb1df146756 637
mbed_official 76:aeb1df146756 638 /* Store the new value */
mbed_official 76:aeb1df146756 639 PWR->CR = tmpreg;
mbed_official 76:aeb1df146756 640
mbed_official 76:aeb1df146756 641 /* Clear SLEEPDEEP bit of Cortex System Control Register */
mbed_official 76:aeb1df146756 642 SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP);
mbed_official 76:aeb1df146756 643
mbed_official 76:aeb1df146756 644 /* Select SLEEP mode entry -------------------------------------------------*/
mbed_official 76:aeb1df146756 645 if(PWR_SLEEPEntry == PWR_SLEEPEntry_WFI)
mbed_official 76:aeb1df146756 646 {
mbed_official 76:aeb1df146756 647 /* Request Wait For Interrupt */
mbed_official 76:aeb1df146756 648 __WFI();
mbed_official 76:aeb1df146756 649 }
mbed_official 76:aeb1df146756 650 else
mbed_official 76:aeb1df146756 651 {
mbed_official 76:aeb1df146756 652 /* Request Wait For Event */
mbed_official 76:aeb1df146756 653 __WFE();
mbed_official 76:aeb1df146756 654 }
mbed_official 76:aeb1df146756 655 }
mbed_official 76:aeb1df146756 656
mbed_official 76:aeb1df146756 657 /**
mbed_official 76:aeb1df146756 658 * @brief Enters STOP mode.
mbed_official 76:aeb1df146756 659 * @note In Stop mode, all I/O pins keep the same state as in Run mode.
mbed_official 76:aeb1df146756 660 * @note When exiting Stop mode by issuing an interrupt or a wakeup event,
mbed_official 76:aeb1df146756 661 * the MSI RC oscillator is selected as system clock.
mbed_official 76:aeb1df146756 662 * @note When the voltage regulator operates in low power mode, an additional
mbed_official 76:aeb1df146756 663 * startup delay is incurred when waking up from Stop mode.
mbed_official 76:aeb1df146756 664 * By keeping the internal regulator ON during Stop mode, the consumption
mbed_official 76:aeb1df146756 665 * is higher although the startup time is reduced.
mbed_official 76:aeb1df146756 666 * @param PWR_Regulator: specifies the regulator state in STOP mode.
mbed_official 76:aeb1df146756 667 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 668 * @arg PWR_Regulator_ON: STOP mode with regulator ON.
mbed_official 76:aeb1df146756 669 * @arg PWR_Regulator_LowPower: STOP mode with regulator in low power mode.
mbed_official 76:aeb1df146756 670 * @param PWR_STOPEntry: specifies if STOP mode in entered with WFI or WFE instruction.
mbed_official 76:aeb1df146756 671 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 672 * @arg PWR_STOPEntry_WFI: enter STOP mode with WFI instruction.
mbed_official 76:aeb1df146756 673 * @arg PWR_STOPEntry_WFE: enter STOP mode with WFE instruction.
mbed_official 76:aeb1df146756 674 * @retval None
mbed_official 76:aeb1df146756 675 */
mbed_official 76:aeb1df146756 676 void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry)
mbed_official 76:aeb1df146756 677 {
mbed_official 76:aeb1df146756 678 uint32_t tmpreg = 0;
mbed_official 76:aeb1df146756 679
mbed_official 76:aeb1df146756 680 /* Check the parameters */
mbed_official 76:aeb1df146756 681 assert_param(IS_PWR_REGULATOR(PWR_Regulator));
mbed_official 76:aeb1df146756 682 assert_param(IS_PWR_STOP_ENTRY(PWR_STOPEntry));
mbed_official 76:aeb1df146756 683
mbed_official 76:aeb1df146756 684 /* Select the regulator state in STOP mode ---------------------------------*/
mbed_official 76:aeb1df146756 685 tmpreg = PWR->CR;
mbed_official 76:aeb1df146756 686 /* Clear PDDS and LPDSR bits */
mbed_official 76:aeb1df146756 687 tmpreg &= CR_DS_MASK;
mbed_official 76:aeb1df146756 688
mbed_official 76:aeb1df146756 689 /* Set LPDSR bit according to PWR_Regulator value */
mbed_official 76:aeb1df146756 690 tmpreg |= PWR_Regulator;
mbed_official 76:aeb1df146756 691
mbed_official 76:aeb1df146756 692 /* Store the new value */
mbed_official 76:aeb1df146756 693 PWR->CR = tmpreg;
mbed_official 76:aeb1df146756 694
mbed_official 76:aeb1df146756 695 /* Set SLEEPDEEP bit of Cortex System Control Register */
mbed_official 76:aeb1df146756 696 SCB->SCR |= SCB_SCR_SLEEPDEEP;
mbed_official 76:aeb1df146756 697
mbed_official 76:aeb1df146756 698 /* Select STOP mode entry --------------------------------------------------*/
mbed_official 76:aeb1df146756 699 if(PWR_STOPEntry == PWR_STOPEntry_WFI)
mbed_official 76:aeb1df146756 700 {
mbed_official 76:aeb1df146756 701 /* Request Wait For Interrupt */
mbed_official 76:aeb1df146756 702 __WFI();
mbed_official 76:aeb1df146756 703 }
mbed_official 76:aeb1df146756 704 else
mbed_official 76:aeb1df146756 705 {
mbed_official 76:aeb1df146756 706 /* Request Wait For Event */
mbed_official 76:aeb1df146756 707 __WFE();
mbed_official 76:aeb1df146756 708 }
mbed_official 76:aeb1df146756 709 /* Reset SLEEPDEEP bit of Cortex System Control Register */
mbed_official 76:aeb1df146756 710 SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP);
mbed_official 76:aeb1df146756 711 }
mbed_official 76:aeb1df146756 712
mbed_official 76:aeb1df146756 713 /**
mbed_official 76:aeb1df146756 714 * @brief Enters STANDBY mode.
mbed_official 76:aeb1df146756 715 * @note In Standby mode, all I/O pins are high impedance except for:
mbed_official 76:aeb1df146756 716 * Reset pad (still available)
mbed_official 76:aeb1df146756 717 * RTC_AF1 pin (PC13) if configured for Wakeup pin 2 (WKUP2), tamper,
mbed_official 76:aeb1df146756 718 * time-stamp, RTC Alarm out, or RTC clock calibration out.
mbed_official 76:aeb1df146756 719 * WKUP pin 1 (PA0) and WKUP pin 3 (PE6), if enabled.
mbed_official 76:aeb1df146756 720 * @param None
mbed_official 76:aeb1df146756 721 * @retval None
mbed_official 76:aeb1df146756 722 */
mbed_official 76:aeb1df146756 723 void PWR_EnterSTANDBYMode(void)
mbed_official 76:aeb1df146756 724 {
mbed_official 76:aeb1df146756 725 /* Clear Wakeup flag */
mbed_official 76:aeb1df146756 726 PWR->CR |= PWR_CR_CWUF;
mbed_official 76:aeb1df146756 727
mbed_official 76:aeb1df146756 728 /* Select STANDBY mode */
mbed_official 76:aeb1df146756 729 PWR->CR |= PWR_CR_PDDS;
mbed_official 76:aeb1df146756 730
mbed_official 76:aeb1df146756 731 /* Set SLEEPDEEP bit of Cortex System Control Register */
mbed_official 76:aeb1df146756 732 SCB->SCR |= SCB_SCR_SLEEPDEEP;
mbed_official 76:aeb1df146756 733
mbed_official 76:aeb1df146756 734 /* This option is used to ensure that store operations are completed */
mbed_official 76:aeb1df146756 735 #if defined ( __CC_ARM )
mbed_official 76:aeb1df146756 736 __force_stores();
mbed_official 76:aeb1df146756 737 #endif
mbed_official 76:aeb1df146756 738 /* Request Wait For Interrupt */
mbed_official 76:aeb1df146756 739 __WFI();
mbed_official 76:aeb1df146756 740 }
mbed_official 76:aeb1df146756 741
mbed_official 76:aeb1df146756 742 /**
mbed_official 76:aeb1df146756 743 * @}
mbed_official 76:aeb1df146756 744 */
mbed_official 76:aeb1df146756 745
mbed_official 76:aeb1df146756 746 /** @defgroup PWR_Group7 Flags management functions
mbed_official 76:aeb1df146756 747 * @brief Flags management functions
mbed_official 76:aeb1df146756 748 *
mbed_official 76:aeb1df146756 749 @verbatim
mbed_official 76:aeb1df146756 750 ==============================================================================
mbed_official 76:aeb1df146756 751 ##### Flags management functions #####
mbed_official 76:aeb1df146756 752 ==============================================================================
mbed_official 76:aeb1df146756 753
mbed_official 76:aeb1df146756 754 @endverbatim
mbed_official 76:aeb1df146756 755 * @{
mbed_official 76:aeb1df146756 756 */
mbed_official 76:aeb1df146756 757
mbed_official 76:aeb1df146756 758 /**
mbed_official 76:aeb1df146756 759 * @brief Checks whether the specified PWR flag is set or not.
mbed_official 76:aeb1df146756 760 * @param PWR_FLAG: specifies the flag to check.
mbed_official 76:aeb1df146756 761 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 762 * @arg PWR_FLAG_WU: Wake Up flag. This flag indicates that a wakeup event
mbed_official 76:aeb1df146756 763 * was received from the WKUP pin or from the RTC alarm (Alarm A or Alarm B),
mbed_official 76:aeb1df146756 764 * RTC Tamper event, RTC TimeStamp event or RTC Wakeup.
mbed_official 76:aeb1df146756 765 * @arg PWR_FLAG_SB: StandBy flag. This flag indicates that the system was
mbed_official 76:aeb1df146756 766 * resumed from StandBy mode.
mbed_official 76:aeb1df146756 767 * @arg PWR_FLAG_PVDO: PVD Output. This flag is valid only if PVD is enabled
mbed_official 76:aeb1df146756 768 * by the PWR_PVDCmd() function.
mbed_official 76:aeb1df146756 769 * @arg PWR_FLAG_VREFINTRDY: Internal Voltage Reference Ready flag. This
mbed_official 76:aeb1df146756 770 * flag indicates the state of the internal voltage reference, VREFINT.
mbed_official 76:aeb1df146756 771 * @arg PWR_FLAG_VOS: Voltage Scaling select flag. A delay is required for
mbed_official 76:aeb1df146756 772 * the internal regulator to be ready after the voltage range is changed.
mbed_official 76:aeb1df146756 773 * The VOSF flag indicates that the regulator has reached the voltage level
mbed_official 76:aeb1df146756 774 * defined with bits VOS[1:0] of PWR_CR register.
mbed_official 76:aeb1df146756 775 * @arg PWR_FLAG_REGLP: Regulator LP flag. This flag is set by hardware
mbed_official 76:aeb1df146756 776 * when the MCU is in Low power run mode.
mbed_official 76:aeb1df146756 777 * When the MCU exits from Low power run mode, this flag stays SET until
mbed_official 76:aeb1df146756 778 * the regulator is ready in main mode. A polling on this flag is
mbed_official 76:aeb1df146756 779 * recommended to wait for the regulator main mode.
mbed_official 76:aeb1df146756 780 * This flag is RESET by hardware when the regulator is ready.
mbed_official 76:aeb1df146756 781 * @retval The new state of PWR_FLAG (SET or RESET).
mbed_official 76:aeb1df146756 782 */
mbed_official 76:aeb1df146756 783 FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG)
mbed_official 76:aeb1df146756 784 {
mbed_official 76:aeb1df146756 785 FlagStatus bitstatus = RESET;
mbed_official 76:aeb1df146756 786 /* Check the parameters */
mbed_official 76:aeb1df146756 787 assert_param(IS_PWR_GET_FLAG(PWR_FLAG));
mbed_official 76:aeb1df146756 788
mbed_official 76:aeb1df146756 789 if ((PWR->CSR & PWR_FLAG) != (uint32_t)RESET)
mbed_official 76:aeb1df146756 790 {
mbed_official 76:aeb1df146756 791 bitstatus = SET;
mbed_official 76:aeb1df146756 792 }
mbed_official 76:aeb1df146756 793 else
mbed_official 76:aeb1df146756 794 {
mbed_official 76:aeb1df146756 795 bitstatus = RESET;
mbed_official 76:aeb1df146756 796 }
mbed_official 76:aeb1df146756 797 /* Return the flag status */
mbed_official 76:aeb1df146756 798 return bitstatus;
mbed_official 76:aeb1df146756 799 }
mbed_official 76:aeb1df146756 800
mbed_official 76:aeb1df146756 801 /**
mbed_official 76:aeb1df146756 802 * @brief Clears the PWR's pending flags.
mbed_official 76:aeb1df146756 803 * @param PWR_FLAG: specifies the flag to clear.
mbed_official 76:aeb1df146756 804 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 805 * @arg PWR_FLAG_WU: Wake Up flag
mbed_official 76:aeb1df146756 806 * @arg PWR_FLAG_SB: StandBy flag
mbed_official 76:aeb1df146756 807 * @retval None
mbed_official 76:aeb1df146756 808 */
mbed_official 76:aeb1df146756 809 void PWR_ClearFlag(uint32_t PWR_FLAG)
mbed_official 76:aeb1df146756 810 {
mbed_official 76:aeb1df146756 811 /* Check the parameters */
mbed_official 76:aeb1df146756 812 assert_param(IS_PWR_CLEAR_FLAG(PWR_FLAG));
mbed_official 76:aeb1df146756 813
mbed_official 76:aeb1df146756 814 PWR->CR |= PWR_FLAG << 2;
mbed_official 76:aeb1df146756 815 }
mbed_official 76:aeb1df146756 816
mbed_official 76:aeb1df146756 817 /**
mbed_official 76:aeb1df146756 818 * @}
mbed_official 76:aeb1df146756 819 */
mbed_official 76:aeb1df146756 820
mbed_official 76:aeb1df146756 821 /**
mbed_official 76:aeb1df146756 822 * @}
mbed_official 76:aeb1df146756 823 */
mbed_official 76:aeb1df146756 824
mbed_official 76:aeb1df146756 825 /**
mbed_official 76:aeb1df146756 826 * @}
mbed_official 76:aeb1df146756 827 */
mbed_official 76:aeb1df146756 828
mbed_official 76:aeb1df146756 829 /**
mbed_official 76:aeb1df146756 830 * @}
mbed_official 76:aeb1df146756 831 */
mbed_official 76:aeb1df146756 832
mbed_official 76:aeb1df146756 833 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/