mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
shaoziyang
Date:
Sat Sep 13 14:25:46 2014 +0000
Revision:
323:9e901b0a5aa1
Parent:
181:a4cbdfbbd2f4
test with CLOCK_SETUP = 0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 181:a4cbdfbbd2f4 1 /**
mbed_official 181:a4cbdfbbd2f4 2 ******************************************************************************
mbed_official 181:a4cbdfbbd2f4 3 * @file stm32l0xx_hal_pwr.c
mbed_official 181:a4cbdfbbd2f4 4 * @author MCD Application Team
mbed_official 181:a4cbdfbbd2f4 5 * @version V1.0.0
mbed_official 181:a4cbdfbbd2f4 6 * @date 22-April-2014
mbed_official 181:a4cbdfbbd2f4 7 * @brief PWR HAL module driver.
mbed_official 181:a4cbdfbbd2f4 8 *
mbed_official 181:a4cbdfbbd2f4 9 * This file provides firmware functions to manage the following
mbed_official 181:a4cbdfbbd2f4 10 * functionalities of the Power Controller (PWR) peripheral:
mbed_official 181:a4cbdfbbd2f4 11 * + Initialization/de-initialization functions
mbed_official 181:a4cbdfbbd2f4 12 * + Peripheral Control functions
mbed_official 181:a4cbdfbbd2f4 13 *
mbed_official 181:a4cbdfbbd2f4 14 @verbatim
mbed_official 181:a4cbdfbbd2f4 15 ******************************************************************************
mbed_official 181:a4cbdfbbd2f4 16 * @attention
mbed_official 181:a4cbdfbbd2f4 17 *
mbed_official 181:a4cbdfbbd2f4 18 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 181:a4cbdfbbd2f4 19 *
mbed_official 181:a4cbdfbbd2f4 20 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 181:a4cbdfbbd2f4 21 * are permitted provided that the following conditions are met:
mbed_official 181:a4cbdfbbd2f4 22 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 181:a4cbdfbbd2f4 23 * this list of conditions and the following disclaimer.
mbed_official 181:a4cbdfbbd2f4 24 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 181:a4cbdfbbd2f4 25 * this list of conditions and the following disclaimer in the documentation
mbed_official 181:a4cbdfbbd2f4 26 * and/or other materials provided with the distribution.
mbed_official 181:a4cbdfbbd2f4 27 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 181:a4cbdfbbd2f4 28 * may be used to endorse or promote products derived from this software
mbed_official 181:a4cbdfbbd2f4 29 * without specific prior written permission.
mbed_official 181:a4cbdfbbd2f4 30 *
mbed_official 181:a4cbdfbbd2f4 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 181:a4cbdfbbd2f4 32 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 181:a4cbdfbbd2f4 33 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 181:a4cbdfbbd2f4 34 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 181:a4cbdfbbd2f4 35 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 181:a4cbdfbbd2f4 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 181:a4cbdfbbd2f4 37 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 181:a4cbdfbbd2f4 38 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 181:a4cbdfbbd2f4 39 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 181:a4cbdfbbd2f4 40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 181:a4cbdfbbd2f4 41 *
mbed_official 181:a4cbdfbbd2f4 42 ******************************************************************************
mbed_official 181:a4cbdfbbd2f4 43 */
mbed_official 181:a4cbdfbbd2f4 44
mbed_official 181:a4cbdfbbd2f4 45 /* Includes ------------------------------------------------------------------*/
mbed_official 181:a4cbdfbbd2f4 46 #include "stm32l0xx_hal.h"
mbed_official 181:a4cbdfbbd2f4 47
mbed_official 181:a4cbdfbbd2f4 48 /** @addtogroup STM32L0xx_HAL_Driver
mbed_official 181:a4cbdfbbd2f4 49 * @{
mbed_official 181:a4cbdfbbd2f4 50 */
mbed_official 181:a4cbdfbbd2f4 51
mbed_official 181:a4cbdfbbd2f4 52 /** @defgroup PWR
mbed_official 181:a4cbdfbbd2f4 53 * @brief PWR HAL module driver
mbed_official 181:a4cbdfbbd2f4 54 * @{
mbed_official 181:a4cbdfbbd2f4 55 */
mbed_official 181:a4cbdfbbd2f4 56
mbed_official 181:a4cbdfbbd2f4 57 #ifdef HAL_PWR_MODULE_ENABLED
mbed_official 181:a4cbdfbbd2f4 58
mbed_official 181:a4cbdfbbd2f4 59 /* Private typedef -----------------------------------------------------------*/
mbed_official 181:a4cbdfbbd2f4 60 /* Private define ------------------------------------------------------------*/
mbed_official 181:a4cbdfbbd2f4 61 /* Private macro -------------------------------------------------------------*/
mbed_official 181:a4cbdfbbd2f4 62 /* Private variables ---------------------------------------------------------*/
mbed_official 181:a4cbdfbbd2f4 63 /* Private function prototypes -----------------------------------------------*/
mbed_official 181:a4cbdfbbd2f4 64 /* Private functions ---------------------------------------------------------*/
mbed_official 181:a4cbdfbbd2f4 65
mbed_official 181:a4cbdfbbd2f4 66 /** @defgroup PWR_Private_Functions
mbed_official 181:a4cbdfbbd2f4 67 * @{
mbed_official 181:a4cbdfbbd2f4 68 */
mbed_official 181:a4cbdfbbd2f4 69
mbed_official 181:a4cbdfbbd2f4 70 /** @defgroup PWR_Group1 Initialization and de-initialization functions
mbed_official 181:a4cbdfbbd2f4 71 * @brief Initialization and de-initialization functions
mbed_official 181:a4cbdfbbd2f4 72 *
mbed_official 181:a4cbdfbbd2f4 73 @verbatim
mbed_official 181:a4cbdfbbd2f4 74 ===============================================================================
mbed_official 181:a4cbdfbbd2f4 75 ##### Initialization and de-initialization functions #####
mbed_official 181:a4cbdfbbd2f4 76 ===============================================================================
mbed_official 181:a4cbdfbbd2f4 77 [..]
mbed_official 181:a4cbdfbbd2f4 78 After reset, the backup domain (RTC registers, RTC backup data
mbed_official 181:a4cbdfbbd2f4 79 registers) is protected against possible unwanted
mbed_official 181:a4cbdfbbd2f4 80 write accesses.
mbed_official 181:a4cbdfbbd2f4 81 To enable access to the RTC Domain and RTC registers, proceed as follows:
mbed_official 181:a4cbdfbbd2f4 82 (+) Enable the Power Controller (PWR) APB1 interface clock using the
mbed_official 181:a4cbdfbbd2f4 83 __PWR_CLK_ENABLE() macro.
mbed_official 181:a4cbdfbbd2f4 84 (+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function.
mbed_official 181:a4cbdfbbd2f4 85
mbed_official 181:a4cbdfbbd2f4 86 @endverbatim
mbed_official 181:a4cbdfbbd2f4 87 * @{
mbed_official 181:a4cbdfbbd2f4 88 */
mbed_official 181:a4cbdfbbd2f4 89
mbed_official 181:a4cbdfbbd2f4 90 /**
mbed_official 181:a4cbdfbbd2f4 91 * @brief Deinitializes the HAL PWR peripheral registers to their default reset values.
mbed_official 181:a4cbdfbbd2f4 92 * @param None
mbed_official 181:a4cbdfbbd2f4 93 * @retval None
mbed_official 181:a4cbdfbbd2f4 94 */
mbed_official 181:a4cbdfbbd2f4 95 void HAL_PWR_DeInit(void)
mbed_official 181:a4cbdfbbd2f4 96 {
mbed_official 181:a4cbdfbbd2f4 97 __PWR_FORCE_RESET();
mbed_official 181:a4cbdfbbd2f4 98 __PWR_RELEASE_RESET();
mbed_official 181:a4cbdfbbd2f4 99 }
mbed_official 181:a4cbdfbbd2f4 100
mbed_official 181:a4cbdfbbd2f4 101 /**
mbed_official 181:a4cbdfbbd2f4 102 * @brief Enables access to the backup domain (RTC registers, RTC
mbed_official 181:a4cbdfbbd2f4 103 * backup data registers ).
mbed_official 181:a4cbdfbbd2f4 104 * @note If the HSE divided by 2, 4, 8 or 16 is used as the RTC clock, the
mbed_official 181:a4cbdfbbd2f4 105 * Backup Domain Access should be kept enabled.
mbed_official 181:a4cbdfbbd2f4 106 * @param None
mbed_official 181:a4cbdfbbd2f4 107 * @retval None
mbed_official 181:a4cbdfbbd2f4 108 */
mbed_official 181:a4cbdfbbd2f4 109 void HAL_PWR_EnableBkUpAccess(void)
mbed_official 181:a4cbdfbbd2f4 110 {
mbed_official 181:a4cbdfbbd2f4 111 /* Enable access to RTC and backup registers */
mbed_official 181:a4cbdfbbd2f4 112 PWR->CR |= PWR_CR_DBP;
mbed_official 181:a4cbdfbbd2f4 113 }
mbed_official 181:a4cbdfbbd2f4 114
mbed_official 181:a4cbdfbbd2f4 115 /**
mbed_official 181:a4cbdfbbd2f4 116 * @brief Disables access to the backup domain (RTC registers, RTC
mbed_official 181:a4cbdfbbd2f4 117 * backup data registers).
mbed_official 181:a4cbdfbbd2f4 118 * @note If the HSE divided by 2, 4, 8 or 16 is used as the RTC clock, the
mbed_official 181:a4cbdfbbd2f4 119 * Backup Domain Access should be kept enabled.
mbed_official 181:a4cbdfbbd2f4 120 * @param None
mbed_official 181:a4cbdfbbd2f4 121 * @retval None
mbed_official 181:a4cbdfbbd2f4 122 */
mbed_official 181:a4cbdfbbd2f4 123 void HAL_PWR_DisableBkUpAccess(void)
mbed_official 181:a4cbdfbbd2f4 124 {
mbed_official 181:a4cbdfbbd2f4 125 /* Disable access to RTC and backup registers */
mbed_official 181:a4cbdfbbd2f4 126 PWR->CR &= (uint32_t)~((uint32_t)PWR_CR_DBP);
mbed_official 181:a4cbdfbbd2f4 127 }
mbed_official 181:a4cbdfbbd2f4 128
mbed_official 181:a4cbdfbbd2f4 129 /**
mbed_official 181:a4cbdfbbd2f4 130 * @}
mbed_official 181:a4cbdfbbd2f4 131 */
mbed_official 181:a4cbdfbbd2f4 132
mbed_official 181:a4cbdfbbd2f4 133 /** @defgroup PWR_Group2 Peripheral Control functions
mbed_official 181:a4cbdfbbd2f4 134 * @brief Low Power modes configuration functions
mbed_official 181:a4cbdfbbd2f4 135 *
mbed_official 181:a4cbdfbbd2f4 136 @verbatim
mbed_official 181:a4cbdfbbd2f4 137
mbed_official 181:a4cbdfbbd2f4 138 ===============================================================================
mbed_official 181:a4cbdfbbd2f4 139 ##### Peripheral Control functions #####
mbed_official 181:a4cbdfbbd2f4 140 ===============================================================================
mbed_official 181:a4cbdfbbd2f4 141
mbed_official 181:a4cbdfbbd2f4 142 *** PVD configuration ***
mbed_official 181:a4cbdfbbd2f4 143 =========================
mbed_official 181:a4cbdfbbd2f4 144 [..]
mbed_official 181:a4cbdfbbd2f4 145 (+) The PVD is used to monitor the VDD power supply by comparing it to a
mbed_official 181:a4cbdfbbd2f4 146 threshold selected by the PVD Level (PLS[2:0] bits in the PWR_CR).
mbed_official 181:a4cbdfbbd2f4 147 (+) The PVD can use an external input analog voltage (PVD_IN) which is compared
mbed_official 181:a4cbdfbbd2f4 148 internally to VREFINT. The PVD_IN (PB7) has to be configured in Analog mode
mbed_official 181:a4cbdfbbd2f4 149 when PWR_PVDLevel_7 is selected (PLS[2:0] = 111).
mbed_official 181:a4cbdfbbd2f4 150
mbed_official 181:a4cbdfbbd2f4 151 (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower
mbed_official 181:a4cbdfbbd2f4 152 than the PVD threshold. This event is internally connected to the EXTI
mbed_official 181:a4cbdfbbd2f4 153 line16 and can generate an interrupt if enabled. This is done through
mbed_official 181:a4cbdfbbd2f4 154 __HAL_PVD_EXTI_ENABLE_IT() macro.
mbed_official 181:a4cbdfbbd2f4 155 (+) The PVD is stopped in Standby mode.
mbed_official 181:a4cbdfbbd2f4 156
mbed_official 181:a4cbdfbbd2f4 157 *** WakeUp pin configuration ***
mbed_official 181:a4cbdfbbd2f4 158 ================================
mbed_official 181:a4cbdfbbd2f4 159 [..]
mbed_official 181:a4cbdfbbd2f4 160 (+) WakeUp pin is used to wake up the system from Standby mode. This pin is
mbed_official 181:a4cbdfbbd2f4 161 forced in input pull-down configuration and is active on rising edges.
mbed_official 181:a4cbdfbbd2f4 162 (+) There are two WakeUp pins:
mbed_official 181:a4cbdfbbd2f4 163 WakeUp Pin 1 on PA.00.
mbed_official 181:a4cbdfbbd2f4 164 WakeUp Pin 2 on PC.13.
mbed_official 181:a4cbdfbbd2f4 165
mbed_official 181:a4cbdfbbd2f4 166 [..]
mbed_official 181:a4cbdfbbd2f4 167 *** Main and Backup Regulators configuration ***
mbed_official 181:a4cbdfbbd2f4 168 ================================================
mbed_official 181:a4cbdfbbd2f4 169
mbed_official 181:a4cbdfbbd2f4 170 (+) The main internal regulator can be configured to have a tradeoff between
mbed_official 181:a4cbdfbbd2f4 171 performance and power consumption when the device does not operate at
mbed_official 181:a4cbdfbbd2f4 172 the maximum frequency. This is done through __HAL_PWR_VOLTAGESCALING_CONFIG()
mbed_official 181:a4cbdfbbd2f4 173 macro which configure VOS bit in PWR_CR register:
mbed_official 181:a4cbdfbbd2f4 174 (++) When this bit is set (Regulator voltage output Scale 1 mode selected)
mbed_official 181:a4cbdfbbd2f4 175 the System frequency can go up to 32 MHz.
mbed_official 181:a4cbdfbbd2f4 176 (++) When this bit is reset (Regulator voltage output Scale 2 mode selected)
mbed_official 181:a4cbdfbbd2f4 177 the System frequency can go up to 16 MHz.
mbed_official 181:a4cbdfbbd2f4 178 (++) When this bit is reset (Regulator voltage output Scale 3 mode selected)
mbed_official 181:a4cbdfbbd2f4 179 the System frequency can go up to 4.2 MHz.
mbed_official 181:a4cbdfbbd2f4 180
mbed_official 181:a4cbdfbbd2f4 181 Refer to the datasheets for more details.
mbed_official 181:a4cbdfbbd2f4 182
mbed_official 181:a4cbdfbbd2f4 183 *** Low Power modes configuration ***
mbed_official 181:a4cbdfbbd2f4 184 =====================================
mbed_official 181:a4cbdfbbd2f4 185 [..]
mbed_official 181:a4cbdfbbd2f4 186 The device features 5 low-power modes:
mbed_official 181:a4cbdfbbd2f4 187 (+) Low power run mode: regulator in low power mode, limited clock frequency,
mbed_official 181:a4cbdfbbd2f4 188 limited number of peripherals running.
mbed_official 181:a4cbdfbbd2f4 189 (+) Sleep mode: Cortex-M0+ core stopped, peripherals kept running.
mbed_official 181:a4cbdfbbd2f4 190 (+) Low power sleep mode: Cortex-M0+ core stopped, limited clock frequency,
mbed_official 181:a4cbdfbbd2f4 191 limited number of peripherals running, regulator in low power mode.
mbed_official 181:a4cbdfbbd2f4 192 (+) Stop mode: All clocks are stopped, regulator running, regulator in low power mode.
mbed_official 181:a4cbdfbbd2f4 193 (+) Standby mode: VCORE domain powered off
mbed_official 181:a4cbdfbbd2f4 194
mbed_official 181:a4cbdfbbd2f4 195 *** Low power run mode ***
mbed_official 181:a4cbdfbbd2f4 196 =========================
mbed_official 181:a4cbdfbbd2f4 197 [..]
mbed_official 181:a4cbdfbbd2f4 198 To further reduce the consumption when the system is in Run mode, the regulator can be
mbed_official 181:a4cbdfbbd2f4 199 configured in low power mode. In this mode, the system frequency should not exceed
mbed_official 181:a4cbdfbbd2f4 200 MSI frequency range1.
mbed_official 181:a4cbdfbbd2f4 201 In Low power run mode, all I/O pins keep the same state as in Run mode.
mbed_official 181:a4cbdfbbd2f4 202
mbed_official 181:a4cbdfbbd2f4 203 (+) Entry:
mbed_official 181:a4cbdfbbd2f4 204 (++) VCORE in range2
mbed_official 181:a4cbdfbbd2f4 205 (++) Decrease the system frequency tonot exceed the frequency of MSI frequency range1.
mbed_official 181:a4cbdfbbd2f4 206 (++) The regulator is forced in low power mode using the HAL_PWREx_EnableLowPowerRunMode()
mbed_official 181:a4cbdfbbd2f4 207 function.
mbed_official 181:a4cbdfbbd2f4 208 (+) Exit:
mbed_official 181:a4cbdfbbd2f4 209 (++) The regulator is forced in Main regulator mode using the HAL_PWREx_DisableLowPowerRunMode()
mbed_official 181:a4cbdfbbd2f4 210 function.
mbed_official 181:a4cbdfbbd2f4 211 (++) Increase the system frequency if needed.
mbed_official 181:a4cbdfbbd2f4 212
mbed_official 181:a4cbdfbbd2f4 213 *** Sleep mode ***
mbed_official 181:a4cbdfbbd2f4 214 ==================
mbed_official 181:a4cbdfbbd2f4 215 [..]
mbed_official 181:a4cbdfbbd2f4 216 (+) Entry:
mbed_official 181:a4cbdfbbd2f4 217 The Sleep mode is entered by using the HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFx)
mbed_official 181:a4cbdfbbd2f4 218 functions with
mbed_official 181:a4cbdfbbd2f4 219 (++) PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction
mbed_official 181:a4cbdfbbd2f4 220 (++) PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction
mbed_official 181:a4cbdfbbd2f4 221
mbed_official 181:a4cbdfbbd2f4 222 (+) Exit:
mbed_official 181:a4cbdfbbd2f4 223 (++) Any peripheral interrupt acknowledged by the nested vectored interrupt
mbed_official 181:a4cbdfbbd2f4 224 controller (NVIC) can wake up the device from Sleep mode.
mbed_official 181:a4cbdfbbd2f4 225
mbed_official 181:a4cbdfbbd2f4 226 *** Low power sleep mode ***
mbed_official 181:a4cbdfbbd2f4 227 ============================
mbed_official 181:a4cbdfbbd2f4 228 [..]
mbed_official 181:a4cbdfbbd2f4 229 (+) Entry:
mbed_official 181:a4cbdfbbd2f4 230 The Low power sleep mode is entered by using the HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFx)
mbed_official 181:a4cbdfbbd2f4 231 functions with
mbed_official 181:a4cbdfbbd2f4 232 (++) PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction
mbed_official 181:a4cbdfbbd2f4 233 (++) PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction
mbed_official 181:a4cbdfbbd2f4 234 (+) The Flash memory can be switched off by using the control bits (SLEEP_PD in the FLASH_ACR register.
mbed_official 181:a4cbdfbbd2f4 235 This reduces power consumption but increases the wake-up time.
mbed_official 181:a4cbdfbbd2f4 236
mbed_official 181:a4cbdfbbd2f4 237 (+) Exit:
mbed_official 181:a4cbdfbbd2f4 238 (++) If the WFI instruction was used to enter Low power sleep mode, any peripheral interrupt
mbed_official 181:a4cbdfbbd2f4 239 acknowledged by the nested vectored interrupt controller (NVIC) can wake up the device
mbed_official 181:a4cbdfbbd2f4 240 from Low power sleep mode. If the WFE instruction was used to enter Low power sleep mode,
mbed_official 181:a4cbdfbbd2f4 241 the MCU exits Sleep mode as soon as an event occurs.
mbed_official 181:a4cbdfbbd2f4 242
mbed_official 181:a4cbdfbbd2f4 243 *** Stop mode ***
mbed_official 181:a4cbdfbbd2f4 244 =================
mbed_official 181:a4cbdfbbd2f4 245 [..]
mbed_official 181:a4cbdfbbd2f4 246 The Stop mode is based on the Cortex™-M0+ deepsleep mode combined with peripheral
mbed_official 181:a4cbdfbbd2f4 247 clock gating. The voltage regulator can be configured either in normal or low-power mode.
mbed_official 181:a4cbdfbbd2f4 248 In Stop mode, all clocks in the VCORE domain are stopped, the PLL, the MSI, the HSI and
mbed_official 181:a4cbdfbbd2f4 249 the HSE RC oscillators are disabled. Internal SRAM and register contents are preserved.
mbed_official 181:a4cbdfbbd2f4 250 To get the lowest consumption in Stop mode, the internal Flash memory also enters low
mbed_official 181:a4cbdfbbd2f4 251 power mode. When the Flash memory is in power-down mode, an additional startup delay is
mbed_official 181:a4cbdfbbd2f4 252 incurred when waking up from Stop mode.
mbed_official 181:a4cbdfbbd2f4 253 To minimize the consumption In Stop mode, VREFINT, the BOR, PVD, and temperature
mbed_official 181:a4cbdfbbd2f4 254 sensor can be switched off before entering Stop mode. They can be switched on again by
mbed_official 181:a4cbdfbbd2f4 255 software after exiting Stop mode using the ULP bit in the PWR_CR register.
mbed_official 181:a4cbdfbbd2f4 256 In Stop mode, all I/O pins keep the same state as in Run mode.
mbed_official 181:a4cbdfbbd2f4 257
mbed_official 181:a4cbdfbbd2f4 258 (+) Entry:
mbed_official 181:a4cbdfbbd2f4 259 The Stop mode is entered using the HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI )
mbed_official 181:a4cbdfbbd2f4 260 function with:
mbed_official 181:a4cbdfbbd2f4 261 (++) Main regulator ON.
mbed_official 181:a4cbdfbbd2f4 262 (++) Low Power regulator ON.
mbed_official 181:a4cbdfbbd2f4 263 (++) PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction
mbed_official 181:a4cbdfbbd2f4 264 (++) PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction
mbed_official 181:a4cbdfbbd2f4 265 (+) Exit:
mbed_official 181:a4cbdfbbd2f4 266 (++) By issuing an interrupt or a wakeup event, the MSI or HSI16 RC
mbed_official 181:a4cbdfbbd2f4 267 oscillator is selected as system clock depending the bit STOPWUCK in the RCC_CFGR
mbed_official 181:a4cbdfbbd2f4 268 register
mbed_official 181:a4cbdfbbd2f4 269
mbed_official 181:a4cbdfbbd2f4 270 *** Standby mode ***
mbed_official 181:a4cbdfbbd2f4 271 ====================
mbed_official 181:a4cbdfbbd2f4 272 [..]
mbed_official 181:a4cbdfbbd2f4 273 The Standby mode allows to achieve the lowest power consumption. It is based on the
mbed_official 181:a4cbdfbbd2f4 274 Cortex™-M0+ deepsleep mode, with the voltage regulator disabled. The VCORE domain is
mbed_official 181:a4cbdfbbd2f4 275 consequently powered off. The PLL, the MSI, the HSI oscillator and the HSE oscillator are
mbed_official 181:a4cbdfbbd2f4 276 also switched off. SRAM and register contents are lost except for the RTC registers, RTC
mbed_official 181:a4cbdfbbd2f4 277 backup registers and Standby circuitry.
mbed_official 181:a4cbdfbbd2f4 278
mbed_official 181:a4cbdfbbd2f4 279 To minimize the consumption In Standby mode, VREFINT, the BOR, PVD, and temperature
mbed_official 181:a4cbdfbbd2f4 280 sensor can be switched off before entering the Standby mode. They can be switched
mbed_official 181:a4cbdfbbd2f4 281 on again by software after exiting the Standby mode.
mbed_official 181:a4cbdfbbd2f4 282 function.
mbed_official 181:a4cbdfbbd2f4 283
mbed_official 181:a4cbdfbbd2f4 284 (+) Entry:
mbed_official 181:a4cbdfbbd2f4 285 (++) The Standby mode is entered using the HAL_PWR_EnterSTANDBYMode() function.
mbed_official 181:a4cbdfbbd2f4 286 (+) Exit:
mbed_official 181:a4cbdfbbd2f4 287 (++) WKUP pin rising edge, RTC alarm (Alarm A and Alarm B), RTC wakeup,
mbed_official 181:a4cbdfbbd2f4 288 tamper event, time-stamp event, external reset in NRST pin, IWDG reset.
mbed_official 181:a4cbdfbbd2f4 289
mbed_official 181:a4cbdfbbd2f4 290 *** Auto-wakeup (AWU) from low-power mode ***
mbed_official 181:a4cbdfbbd2f4 291 =============================================
mbed_official 181:a4cbdfbbd2f4 292 [..]
mbed_official 181:a4cbdfbbd2f4 293 The MCU can be woken up from low-power mode by an RTC Alarm event, an RTC
mbed_official 181:a4cbdfbbd2f4 294 Wakeup event, a tamper event, a time-stamp event, or a comparator event,
mbed_official 181:a4cbdfbbd2f4 295 without depending on an external interrupt (Auto-wakeup mode).
mbed_official 181:a4cbdfbbd2f4 296
mbed_official 181:a4cbdfbbd2f4 297 (+) RTC auto-wakeup (AWU) from the Stop mode
mbed_official 181:a4cbdfbbd2f4 298 (++) To wake up from the Stop mode with an RTC alarm event, it is necessary to:
mbed_official 181:a4cbdfbbd2f4 299 (+++) Configure the EXTI Line 17 to be sensitive to rising edges (Interrupt
mbed_official 181:a4cbdfbbd2f4 300 or Event modes) using the EXTI_Init() function.
mbed_official 181:a4cbdfbbd2f4 301 (+++) Enable the RTC Alarm Interrupt using the RTC_ITConfig() function
mbed_official 181:a4cbdfbbd2f4 302 (+++) Configure the RTC to generate the RTC alarm using the RTC_SetAlarm()
mbed_official 181:a4cbdfbbd2f4 303 and RTC_AlarmCmd() functions.
mbed_official 181:a4cbdfbbd2f4 304 (++) To wake up from the Stop mode with an RTC Tamper or time stamp event, it
mbed_official 181:a4cbdfbbd2f4 305 is necessary to:
mbed_official 181:a4cbdfbbd2f4 306 (+++) Configure the EXTI Line 19 to be sensitive to rising edges (Interrupt
mbed_official 181:a4cbdfbbd2f4 307 or Event modes) using the EXTI_Init() function.
mbed_official 181:a4cbdfbbd2f4 308 (+++) Enable the RTC Tamper or time stamp Interrupt using the RTC_ITConfig()
mbed_official 181:a4cbdfbbd2f4 309 function.
mbed_official 181:a4cbdfbbd2f4 310 (+++) Configure the RTC to detect the tamper or time stamp event using the
mbed_official 181:a4cbdfbbd2f4 311 RTC_TimeStampConfig(), RTC_TamperTriggerConfig() and RTC_TamperCmd()
mbed_official 181:a4cbdfbbd2f4 312 functions.
mbed_official 181:a4cbdfbbd2f4 313 (++) To wake up from the Stop mode with an RTC WakeUp event, it is necessary to:
mbed_official 181:a4cbdfbbd2f4 314 (+++) Configure the EXTI Line 20 to be sensitive to rising edges (Interrupt
mbed_official 181:a4cbdfbbd2f4 315 or Event modes) using the EXTI_Init() function.
mbed_official 181:a4cbdfbbd2f4 316 (+++) Enable the RTC WakeUp Interrupt using the RTC_ITConfig() function.
mbed_official 181:a4cbdfbbd2f4 317 (+++) Configure the RTC to generate the RTC WakeUp event using the RTC_WakeUpClockConfig(),
mbed_official 181:a4cbdfbbd2f4 318 RTC_SetWakeUpCounter() and RTC_WakeUpCmd() functions.
mbed_official 181:a4cbdfbbd2f4 319
mbed_official 181:a4cbdfbbd2f4 320 (+) RTC auto-wakeup (AWU) from the Standby mode
mbed_official 181:a4cbdfbbd2f4 321 (++) To wake up from the Standby mode with an RTC alarm event, it is necessary to:
mbed_official 181:a4cbdfbbd2f4 322 (+++) Enable the RTC Alarm Interrupt using the RTC_ITConfig() function.
mbed_official 181:a4cbdfbbd2f4 323 (+++) Configure the RTC to generate the RTC alarm using the RTC_SetAlarm()
mbed_official 181:a4cbdfbbd2f4 324 and RTC_AlarmCmd() functions.
mbed_official 181:a4cbdfbbd2f4 325 (++) To wake up from the Standby mode with an RTC Tamper or time stamp event, it
mbed_official 181:a4cbdfbbd2f4 326 is necessary to:
mbed_official 181:a4cbdfbbd2f4 327 (+++) Enable the RTC Tamper or time stamp Interrupt using the RTC_ITConfig()
mbed_official 181:a4cbdfbbd2f4 328 function.
mbed_official 181:a4cbdfbbd2f4 329 (+++) Configure the RTC to detect the tamper or time stamp event using the
mbed_official 181:a4cbdfbbd2f4 330 RTC_TimeStampConfig(), RTC_TamperTriggerConfig() and RTC_TamperCmd()
mbed_official 181:a4cbdfbbd2f4 331 functions.
mbed_official 181:a4cbdfbbd2f4 332 (++) To wake up from the Standby mode with an RTC WakeUp event, it is necessary to:
mbed_official 181:a4cbdfbbd2f4 333 (+++) Enable the RTC WakeUp Interrupt using the RTC_ITConfig() function
mbed_official 181:a4cbdfbbd2f4 334 (+++) Configure the RTC to generate the RTC WakeUp event using the RTC_WakeUpClockConfig(),
mbed_official 181:a4cbdfbbd2f4 335 RTC_SetWakeUpCounter() and RTC_WakeUpCmd() functions.
mbed_official 181:a4cbdfbbd2f4 336
mbed_official 181:a4cbdfbbd2f4 337 (+) Comparator auto-wakeup (AWU) from the Stop mode
mbed_official 181:a4cbdfbbd2f4 338 (++) To wake up from the Stop mode with an comparator 1 or comparator 2 wakeup
mbed_official 181:a4cbdfbbd2f4 339 event, it is necessary to:
mbed_official 181:a4cbdfbbd2f4 340 (+++) Configure the EXTI Line 21 for comparator 1 or EXTI Line 22 for comparator 2
mbed_official 181:a4cbdfbbd2f4 341 to be sensitive to to the selected edges (falling, rising or falling
mbed_official 181:a4cbdfbbd2f4 342 and rising) (Interrupt or Event modes) using the EXTI_Init() function.
mbed_official 181:a4cbdfbbd2f4 343 (+++) Configure the comparator to generate the event.
mbed_official 181:a4cbdfbbd2f4 344
mbed_official 181:a4cbdfbbd2f4 345
mbed_official 181:a4cbdfbbd2f4 346
mbed_official 181:a4cbdfbbd2f4 347 @endverbatim
mbed_official 181:a4cbdfbbd2f4 348 * @{
mbed_official 181:a4cbdfbbd2f4 349 */
mbed_official 181:a4cbdfbbd2f4 350
mbed_official 181:a4cbdfbbd2f4 351 /**
mbed_official 181:a4cbdfbbd2f4 352 * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD).
mbed_official 181:a4cbdfbbd2f4 353 * @param sConfigPVD: pointer to an PWR_PVDTypeDef structure that contains the configuration
mbed_official 181:a4cbdfbbd2f4 354 * information for the PVD.
mbed_official 181:a4cbdfbbd2f4 355 * @note Refer to the electrical characteristics of your device datasheet for
mbed_official 181:a4cbdfbbd2f4 356 * more details about the voltage threshold corresponding to each
mbed_official 181:a4cbdfbbd2f4 357 * detection level.
mbed_official 181:a4cbdfbbd2f4 358 * @retval None
mbed_official 181:a4cbdfbbd2f4 359 */
mbed_official 181:a4cbdfbbd2f4 360 void HAL_PWR_PVDConfig(PWR_PVDTypeDef *sConfigPVD)
mbed_official 181:a4cbdfbbd2f4 361 {
mbed_official 181:a4cbdfbbd2f4 362 uint32_t tmpreg = 0;
mbed_official 181:a4cbdfbbd2f4 363
mbed_official 181:a4cbdfbbd2f4 364 /* Check the parameters */
mbed_official 181:a4cbdfbbd2f4 365 assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel));
mbed_official 181:a4cbdfbbd2f4 366
mbed_official 181:a4cbdfbbd2f4 367 tmpreg = PWR->CR;
mbed_official 181:a4cbdfbbd2f4 368
mbed_official 181:a4cbdfbbd2f4 369 /* Clear PLS[7:5] bits */
mbed_official 181:a4cbdfbbd2f4 370 tmpreg &= ~ (uint32_t)PWR_CR_PLS;
mbed_official 181:a4cbdfbbd2f4 371
mbed_official 181:a4cbdfbbd2f4 372 /* Set PLS[7:5] bits according to PVDLevel value */
mbed_official 181:a4cbdfbbd2f4 373 tmpreg |= sConfigPVD->PVDLevel;
mbed_official 181:a4cbdfbbd2f4 374
mbed_official 181:a4cbdfbbd2f4 375 /* Store the new value */
mbed_official 181:a4cbdfbbd2f4 376 PWR->CR = tmpreg;
mbed_official 181:a4cbdfbbd2f4 377
mbed_official 181:a4cbdfbbd2f4 378 /* Configure the EXTI 16 interrupt */
mbed_official 181:a4cbdfbbd2f4 379 if((sConfigPVD->Mode == PWR_MODE_IT_RISING_FALLING) ||\
mbed_official 181:a4cbdfbbd2f4 380 (sConfigPVD->Mode == PWR_MODE_IT_FALLING) ||\
mbed_official 181:a4cbdfbbd2f4 381 (sConfigPVD->Mode == PWR_MODE_IT_RISING))
mbed_official 181:a4cbdfbbd2f4 382 {
mbed_official 181:a4cbdfbbd2f4 383 __HAL_PVD_EXTI_ENABLE_IT(PWR_EXTI_LINE_PVD);
mbed_official 181:a4cbdfbbd2f4 384 }
mbed_official 181:a4cbdfbbd2f4 385 /* Configure the rising edge */
mbed_official 181:a4cbdfbbd2f4 386 if((sConfigPVD->Mode == PWR_MODE_IT_RISING_FALLING) ||\
mbed_official 181:a4cbdfbbd2f4 387 (sConfigPVD->Mode == PWR_MODE_IT_RISING))
mbed_official 181:a4cbdfbbd2f4 388 {
mbed_official 181:a4cbdfbbd2f4 389 EXTI->RTSR |= PWR_EXTI_LINE_PVD;
mbed_official 181:a4cbdfbbd2f4 390 }
mbed_official 181:a4cbdfbbd2f4 391 /* Configure the falling edge */
mbed_official 181:a4cbdfbbd2f4 392 if((sConfigPVD->Mode == PWR_MODE_IT_RISING_FALLING) ||\
mbed_official 181:a4cbdfbbd2f4 393 (sConfigPVD->Mode == PWR_MODE_IT_FALLING))
mbed_official 181:a4cbdfbbd2f4 394 {
mbed_official 181:a4cbdfbbd2f4 395 EXTI->FTSR |= PWR_EXTI_LINE_PVD;
mbed_official 181:a4cbdfbbd2f4 396 }
mbed_official 181:a4cbdfbbd2f4 397 }
mbed_official 181:a4cbdfbbd2f4 398
mbed_official 181:a4cbdfbbd2f4 399 /**
mbed_official 181:a4cbdfbbd2f4 400 * @brief Enables the Power Voltage Detector(PVD).
mbed_official 181:a4cbdfbbd2f4 401 * @param None
mbed_official 181:a4cbdfbbd2f4 402 * @retval None
mbed_official 181:a4cbdfbbd2f4 403 */
mbed_official 181:a4cbdfbbd2f4 404 void HAL_PWR_EnablePVD(void)
mbed_official 181:a4cbdfbbd2f4 405 {
mbed_official 181:a4cbdfbbd2f4 406 /* Enable the power voltage detector */
mbed_official 181:a4cbdfbbd2f4 407 PWR->CR |= PWR_CR_PVDE;
mbed_official 181:a4cbdfbbd2f4 408 }
mbed_official 181:a4cbdfbbd2f4 409
mbed_official 181:a4cbdfbbd2f4 410 /**
mbed_official 181:a4cbdfbbd2f4 411 * @brief Disables the Power Voltage Detector(PVD).
mbed_official 181:a4cbdfbbd2f4 412 * @param None
mbed_official 181:a4cbdfbbd2f4 413 * @retval None
mbed_official 181:a4cbdfbbd2f4 414 */
mbed_official 181:a4cbdfbbd2f4 415 void HAL_PWR_DisablePVD(void)
mbed_official 181:a4cbdfbbd2f4 416 {
mbed_official 181:a4cbdfbbd2f4 417 /* Disable the power voltage detector */
mbed_official 181:a4cbdfbbd2f4 418 PWR->CR &= (uint32_t)~((uint32_t)PWR_CR_PVDE);
mbed_official 181:a4cbdfbbd2f4 419 }
mbed_official 181:a4cbdfbbd2f4 420
mbed_official 181:a4cbdfbbd2f4 421 /**
mbed_official 181:a4cbdfbbd2f4 422 * @brief Enables the WakeUp PINx functionality.
mbed_official 181:a4cbdfbbd2f4 423 * @param WakeUpPinx: Specifies the Power Wake-Up pin to enable.
mbed_official 181:a4cbdfbbd2f4 424 * This parameter can be one of the following values:
mbed_official 181:a4cbdfbbd2f4 425 * @arg PWR_WAKEUP_PIN1
mbed_official 181:a4cbdfbbd2f4 426 * @arg PWR_WAKEUP_PIN2
mbed_official 181:a4cbdfbbd2f4 427 * @retval None
mbed_official 181:a4cbdfbbd2f4 428 */
mbed_official 181:a4cbdfbbd2f4 429 void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx)
mbed_official 181:a4cbdfbbd2f4 430 {
mbed_official 181:a4cbdfbbd2f4 431 /* Check the parameter */
mbed_official 181:a4cbdfbbd2f4 432 assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
mbed_official 181:a4cbdfbbd2f4 433 /* Enable the EWUPx pin */
mbed_official 181:a4cbdfbbd2f4 434 PWR->CSR |= WakeUpPinx;
mbed_official 181:a4cbdfbbd2f4 435 }
mbed_official 181:a4cbdfbbd2f4 436
mbed_official 181:a4cbdfbbd2f4 437 /**
mbed_official 181:a4cbdfbbd2f4 438 * @brief Disables the WakeUp PINx functionality.
mbed_official 181:a4cbdfbbd2f4 439 * @param WakeUpPinx: Specifies the Power Wake-Up pin to disable.
mbed_official 181:a4cbdfbbd2f4 440 * This parameter can be one of the following values:
mbed_official 181:a4cbdfbbd2f4 441 * @arg PWR_WAKEUP_PIN1
mbed_official 181:a4cbdfbbd2f4 442 * @arg PWR_WAKEUP_PIN2
mbed_official 181:a4cbdfbbd2f4 443 * @retval None
mbed_official 181:a4cbdfbbd2f4 444 */
mbed_official 181:a4cbdfbbd2f4 445 void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx)
mbed_official 181:a4cbdfbbd2f4 446 {
mbed_official 181:a4cbdfbbd2f4 447 /* Check the parameter */
mbed_official 181:a4cbdfbbd2f4 448 assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
mbed_official 181:a4cbdfbbd2f4 449 /* Disable the EWUPx pin */
mbed_official 181:a4cbdfbbd2f4 450 PWR->CSR &= ~WakeUpPinx;
mbed_official 181:a4cbdfbbd2f4 451 }
mbed_official 181:a4cbdfbbd2f4 452
mbed_official 181:a4cbdfbbd2f4 453 /**
mbed_official 181:a4cbdfbbd2f4 454 * @brief Enters Sleep mode.
mbed_official 181:a4cbdfbbd2f4 455 * @note In Sleep mode, all I/O pins keep the same state as in Run mode.
mbed_official 181:a4cbdfbbd2f4 456 * @param Regulator: Specifies the regulator state in SLEEP mode.
mbed_official 181:a4cbdfbbd2f4 457 * This parameter can be one of the following values:
mbed_official 181:a4cbdfbbd2f4 458 * @arg PWR_MAINREGULATOR_ON: SLEEP mode with regulator ON
mbed_official 181:a4cbdfbbd2f4 459 * @arg PWR_LOWPOWERREGULATOR_ON: SLEEP mode with low power regulator ON
mbed_official 181:a4cbdfbbd2f4 460 * @param SLEEPEntry: Specifies if SLEEP mode is entered with WFI or WFE instruction.
mbed_official 181:a4cbdfbbd2f4 461 * When WFI entry is used, tick interrupt have to be disabled if not desired as
mbed_official 181:a4cbdfbbd2f4 462 * the interrupt wake up source.
mbed_official 181:a4cbdfbbd2f4 463 * This parameter can be one of the following values:
mbed_official 181:a4cbdfbbd2f4 464 * @arg PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction
mbed_official 181:a4cbdfbbd2f4 465 * @arg PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction
mbed_official 181:a4cbdfbbd2f4 466 * @retval None
mbed_official 181:a4cbdfbbd2f4 467 */
mbed_official 181:a4cbdfbbd2f4 468 void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)
mbed_official 181:a4cbdfbbd2f4 469 {
mbed_official 181:a4cbdfbbd2f4 470 uint32_t tmpreg = 0;
mbed_official 181:a4cbdfbbd2f4 471 /* Check the parameters */
mbed_official 181:a4cbdfbbd2f4 472 assert_param(IS_PWR_REGULATOR(Regulator));
mbed_official 181:a4cbdfbbd2f4 473 assert_param(IS_PWR_SLEEP_ENTRY(SLEEPEntry));
mbed_official 181:a4cbdfbbd2f4 474
mbed_official 181:a4cbdfbbd2f4 475 /* Select the regulator state in Sleep mode ---------------------------------*/
mbed_official 181:a4cbdfbbd2f4 476 tmpreg = PWR->CR;
mbed_official 181:a4cbdfbbd2f4 477 /* Clear PDDS and LPDS bits */
mbed_official 181:a4cbdfbbd2f4 478 tmpreg &= (uint32_t)~(PWR_CR_PDDS | PWR_CR_LPSDSR);
mbed_official 181:a4cbdfbbd2f4 479
mbed_official 181:a4cbdfbbd2f4 480 /* Set LPSDSR bit according to PWR_Regulator value */
mbed_official 181:a4cbdfbbd2f4 481 tmpreg |= Regulator;
mbed_official 181:a4cbdfbbd2f4 482
mbed_official 181:a4cbdfbbd2f4 483 /* Store the new value */
mbed_official 181:a4cbdfbbd2f4 484 PWR->CR = tmpreg;
mbed_official 181:a4cbdfbbd2f4 485
mbed_official 181:a4cbdfbbd2f4 486 /* Clear SLEEPDEEP bit of Cortex System Control Register */
mbed_official 181:a4cbdfbbd2f4 487 SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
mbed_official 181:a4cbdfbbd2f4 488
mbed_official 181:a4cbdfbbd2f4 489 /* Select SLEEP mode entry -------------------------------------------------*/
mbed_official 181:a4cbdfbbd2f4 490 if(SLEEPEntry == PWR_SLEEPENTRY_WFI)
mbed_official 181:a4cbdfbbd2f4 491 {
mbed_official 181:a4cbdfbbd2f4 492 /* Request Wait For Interrupt */
mbed_official 181:a4cbdfbbd2f4 493 __WFI();
mbed_official 181:a4cbdfbbd2f4 494 }
mbed_official 181:a4cbdfbbd2f4 495 else
mbed_official 181:a4cbdfbbd2f4 496 {
mbed_official 181:a4cbdfbbd2f4 497 /* Request Wait For Event */
mbed_official 181:a4cbdfbbd2f4 498 __SEV();
mbed_official 181:a4cbdfbbd2f4 499 __WFE();
mbed_official 181:a4cbdfbbd2f4 500 __WFE();
mbed_official 181:a4cbdfbbd2f4 501 }
mbed_official 181:a4cbdfbbd2f4 502
mbed_official 181:a4cbdfbbd2f4 503 }
mbed_official 181:a4cbdfbbd2f4 504
mbed_official 181:a4cbdfbbd2f4 505 /**
mbed_official 181:a4cbdfbbd2f4 506 * @brief Enters Stop mode.
mbed_official 181:a4cbdfbbd2f4 507 * @note In Stop mode, all I/O pins keep the same state as in Run mode.
mbed_official 181:a4cbdfbbd2f4 508 * @note When exiting Stop mode by issuing an interrupt or a wakeup event,
mbed_official 181:a4cbdfbbd2f4 509 * MSI or HSI16 RCoscillator is selected as system clock depending
mbed_official 181:a4cbdfbbd2f4 510 * the bit STOPWUCK in the RCC_CFGR register.
mbed_official 181:a4cbdfbbd2f4 511 * @note When the voltage regulator operates in low power mode, an additional
mbed_official 181:a4cbdfbbd2f4 512 * startup delay is incurred when waking up from Stop mode.
mbed_official 181:a4cbdfbbd2f4 513 * By keeping the internal regulator ON during Stop mode, the consumption
mbed_official 181:a4cbdfbbd2f4 514 * is higher although the startup time is reduced.
mbed_official 181:a4cbdfbbd2f4 515 * @param Regulator: Specifies the regulator state in Stop mode.
mbed_official 181:a4cbdfbbd2f4 516 * This parameter can be one of the following values:
mbed_official 181:a4cbdfbbd2f4 517 * @arg PWR_MAINREGULATOR_ON: Stop mode with regulator ON
mbed_official 181:a4cbdfbbd2f4 518 * @arg PWR_LOWPOWERREGULATOR_ON: Stop mode with low power regulator ON
mbed_official 181:a4cbdfbbd2f4 519 * @param STOPEntry: Specifies if Stop mode in entered with WFI or WFE instruction.
mbed_official 181:a4cbdfbbd2f4 520 * This parameter can be one of the following values:
mbed_official 181:a4cbdfbbd2f4 521 * @arg PWR_STOPENTRY_WFI: Enter Stop mode with WFI instruction
mbed_official 181:a4cbdfbbd2f4 522 * @arg PWR_STOPENTRY_WFE: Enter Stop mode with WFE instruction
mbed_official 181:a4cbdfbbd2f4 523 * @retval None
mbed_official 181:a4cbdfbbd2f4 524 */
mbed_official 181:a4cbdfbbd2f4 525 void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
mbed_official 181:a4cbdfbbd2f4 526 {
mbed_official 181:a4cbdfbbd2f4 527 uint32_t tmpreg = 0;
mbed_official 181:a4cbdfbbd2f4 528
mbed_official 181:a4cbdfbbd2f4 529 /* Check the parameters */
mbed_official 181:a4cbdfbbd2f4 530 assert_param(IS_PWR_REGULATOR(Regulator));
mbed_official 181:a4cbdfbbd2f4 531 assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
mbed_official 181:a4cbdfbbd2f4 532
mbed_official 181:a4cbdfbbd2f4 533 /* Select the regulator state in Stop mode ---------------------------------*/
mbed_official 181:a4cbdfbbd2f4 534 tmpreg = PWR->CR;
mbed_official 181:a4cbdfbbd2f4 535 /* Clear PDDS and LPDS bits */
mbed_official 181:a4cbdfbbd2f4 536 tmpreg &= (uint32_t)~(PWR_CR_PDDS | PWR_CR_LPSDSR);
mbed_official 181:a4cbdfbbd2f4 537
mbed_official 181:a4cbdfbbd2f4 538 /* Set LPSDSR bit according to PWR_Regulator value */
mbed_official 181:a4cbdfbbd2f4 539 tmpreg |= Regulator;
mbed_official 181:a4cbdfbbd2f4 540
mbed_official 181:a4cbdfbbd2f4 541 /* Store the new value */
mbed_official 181:a4cbdfbbd2f4 542 PWR->CR = tmpreg;
mbed_official 181:a4cbdfbbd2f4 543
mbed_official 181:a4cbdfbbd2f4 544 /* Set SLEEPDEEP bit of Cortex System Control Register */
mbed_official 181:a4cbdfbbd2f4 545 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
mbed_official 181:a4cbdfbbd2f4 546
mbed_official 181:a4cbdfbbd2f4 547 /* Select Stop mode entry --------------------------------------------------*/
mbed_official 181:a4cbdfbbd2f4 548 if(STOPEntry == PWR_STOPENTRY_WFI)
mbed_official 181:a4cbdfbbd2f4 549 {
mbed_official 181:a4cbdfbbd2f4 550 /* Request Wait For Interrupt */
mbed_official 181:a4cbdfbbd2f4 551 __WFI();
mbed_official 181:a4cbdfbbd2f4 552 }
mbed_official 181:a4cbdfbbd2f4 553 else
mbed_official 181:a4cbdfbbd2f4 554 {
mbed_official 181:a4cbdfbbd2f4 555 /* Request Wait For Event */
mbed_official 181:a4cbdfbbd2f4 556 __SEV();
mbed_official 181:a4cbdfbbd2f4 557 __WFE();
mbed_official 181:a4cbdfbbd2f4 558 __WFE();
mbed_official 181:a4cbdfbbd2f4 559 }
mbed_official 181:a4cbdfbbd2f4 560
mbed_official 181:a4cbdfbbd2f4 561 /* Reset SLEEPDEEP bit of Cortex System Control Register */
mbed_official 181:a4cbdfbbd2f4 562 SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
mbed_official 181:a4cbdfbbd2f4 563 }
mbed_official 181:a4cbdfbbd2f4 564
mbed_official 181:a4cbdfbbd2f4 565 /**
mbed_official 181:a4cbdfbbd2f4 566 * @brief Enters Standby mode.
mbed_official 181:a4cbdfbbd2f4 567 * @note In Standby mode, all I/O pins are high impedance except for:
mbed_official 181:a4cbdfbbd2f4 568 * - Reset pad (still available)
mbed_official 181:a4cbdfbbd2f4 569 * - RTC_AF1 pin (PC13) if configured for tamper, time-stamp, RTC
mbed_official 181:a4cbdfbbd2f4 570 * Alarm out, or RTC clock calibration out.
mbed_official 181:a4cbdfbbd2f4 571 * - RTC_AF2 pin (PC13) if configured for tamper.
mbed_official 181:a4cbdfbbd2f4 572 * - WKUP pin 1 (PA0) if enabled.
mbed_official 181:a4cbdfbbd2f4 573 * - WKUP pin 2 (PC13) if enabled.
mbed_official 181:a4cbdfbbd2f4 574 * @param None
mbed_official 181:a4cbdfbbd2f4 575 * @retval None
mbed_official 181:a4cbdfbbd2f4 576 */
mbed_official 181:a4cbdfbbd2f4 577 void HAL_PWR_EnterSTANDBYMode(void)
mbed_official 181:a4cbdfbbd2f4 578 {
mbed_official 181:a4cbdfbbd2f4 579 /* Clear Wakeup flag */
mbed_official 181:a4cbdfbbd2f4 580 PWR->CR |= PWR_CR_CWUF;
mbed_official 181:a4cbdfbbd2f4 581
mbed_official 181:a4cbdfbbd2f4 582 /* Select Standby mode */
mbed_official 181:a4cbdfbbd2f4 583 PWR->CR |= PWR_CR_PDDS;
mbed_official 181:a4cbdfbbd2f4 584
mbed_official 181:a4cbdfbbd2f4 585 /* Set SLEEPDEEP bit of Cortex System Control Register */
mbed_official 181:a4cbdfbbd2f4 586 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
mbed_official 181:a4cbdfbbd2f4 587
mbed_official 181:a4cbdfbbd2f4 588 /* This option is used to ensure that store operations are completed */
mbed_official 181:a4cbdfbbd2f4 589 #if defined ( __CC_ARM)
mbed_official 181:a4cbdfbbd2f4 590 __force_stores();
mbed_official 181:a4cbdfbbd2f4 591 #endif
mbed_official 181:a4cbdfbbd2f4 592 /* Request Wait For Interrupt */
mbed_official 181:a4cbdfbbd2f4 593 __WFI();
mbed_official 181:a4cbdfbbd2f4 594 }
mbed_official 181:a4cbdfbbd2f4 595
mbed_official 181:a4cbdfbbd2f4 596 /**
mbed_official 181:a4cbdfbbd2f4 597 * @brief This function handles the PWR PVD interrupt request.
mbed_official 181:a4cbdfbbd2f4 598 * @note This API should be called under the PVD_IRQHandler().
mbed_official 181:a4cbdfbbd2f4 599 * @param None
mbed_official 181:a4cbdfbbd2f4 600 * @retval None
mbed_official 181:a4cbdfbbd2f4 601 */
mbed_official 181:a4cbdfbbd2f4 602 void HAL_PWR_PVD_IRQHandler(void)
mbed_official 181:a4cbdfbbd2f4 603 {
mbed_official 181:a4cbdfbbd2f4 604 /* Check PWR exti flag */
mbed_official 181:a4cbdfbbd2f4 605 if(__HAL_PVD_EXTI_GET_FLAG(PWR_EXTI_LINE_PVD) != RESET)
mbed_official 181:a4cbdfbbd2f4 606 {
mbed_official 181:a4cbdfbbd2f4 607 /* PWR PVD interrupt user callback */
mbed_official 181:a4cbdfbbd2f4 608 HAL_PWR_PVDCallback();
mbed_official 181:a4cbdfbbd2f4 609
mbed_official 181:a4cbdfbbd2f4 610 /* Clear PWR Exti pending bit */
mbed_official 181:a4cbdfbbd2f4 611 __HAL_PVD_EXTI_CLEAR_FLAG(PWR_EXTI_LINE_PVD);
mbed_official 181:a4cbdfbbd2f4 612 }
mbed_official 181:a4cbdfbbd2f4 613 }
mbed_official 181:a4cbdfbbd2f4 614
mbed_official 181:a4cbdfbbd2f4 615 /**
mbed_official 181:a4cbdfbbd2f4 616 * @brief PWR PVD interrupt callback
mbed_official 181:a4cbdfbbd2f4 617 * @param None
mbed_official 181:a4cbdfbbd2f4 618 * @retval None
mbed_official 181:a4cbdfbbd2f4 619 */
mbed_official 181:a4cbdfbbd2f4 620 __weak void HAL_PWR_PVDCallback(void)
mbed_official 181:a4cbdfbbd2f4 621 {
mbed_official 181:a4cbdfbbd2f4 622 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 181:a4cbdfbbd2f4 623 the HAL_PWR_PVDCallback could be implemented in the user file
mbed_official 181:a4cbdfbbd2f4 624 */
mbed_official 181:a4cbdfbbd2f4 625 }
mbed_official 181:a4cbdfbbd2f4 626
mbed_official 181:a4cbdfbbd2f4 627 /**
mbed_official 181:a4cbdfbbd2f4 628 * @}
mbed_official 181:a4cbdfbbd2f4 629 */
mbed_official 181:a4cbdfbbd2f4 630
mbed_official 181:a4cbdfbbd2f4 631 /**
mbed_official 181:a4cbdfbbd2f4 632 * @}
mbed_official 181:a4cbdfbbd2f4 633 */
mbed_official 181:a4cbdfbbd2f4 634
mbed_official 181:a4cbdfbbd2f4 635 #endif /* HAL_PWR_MODULE_ENABLED */
mbed_official 181:a4cbdfbbd2f4 636 /**
mbed_official 181:a4cbdfbbd2f4 637 * @}
mbed_official 181:a4cbdfbbd2f4 638 */
mbed_official 181:a4cbdfbbd2f4 639
mbed_official 181:a4cbdfbbd2f4 640 /**
mbed_official 181:a4cbdfbbd2f4 641 * @}
mbed_official 181:a4cbdfbbd2f4 642 */
mbed_official 181:a4cbdfbbd2f4 643
mbed_official 181:a4cbdfbbd2f4 644 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/