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:
235:685d5f11838f
test with CLOCK_SETUP = 0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 235:685d5f11838f 1 /**
mbed_official 235:685d5f11838f 2 ******************************************************************************
mbed_official 235:685d5f11838f 3 * @file stm32f4xx_hal_pwr.c
mbed_official 235:685d5f11838f 4 * @author MCD Application Team
mbed_official 235:685d5f11838f 5 * @version V1.1.0
mbed_official 235:685d5f11838f 6 * @date 19-June-2014
mbed_official 235:685d5f11838f 7 * @brief PWR HAL module driver.
mbed_official 235:685d5f11838f 8 * This file provides firmware functions to manage the following
mbed_official 235:685d5f11838f 9 * functionalities of the Power Controller (PWR) peripheral:
mbed_official 235:685d5f11838f 10 * + Initialization and de-initialization functions
mbed_official 235:685d5f11838f 11 * + Peripheral Control functions
mbed_official 235:685d5f11838f 12 *
mbed_official 235:685d5f11838f 13 ******************************************************************************
mbed_official 235:685d5f11838f 14 * @attention
mbed_official 235:685d5f11838f 15 *
mbed_official 235:685d5f11838f 16 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 235:685d5f11838f 17 *
mbed_official 235:685d5f11838f 18 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 235:685d5f11838f 19 * are permitted provided that the following conditions are met:
mbed_official 235:685d5f11838f 20 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 235:685d5f11838f 21 * this list of conditions and the following disclaimer.
mbed_official 235:685d5f11838f 22 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 235:685d5f11838f 23 * this list of conditions and the following disclaimer in the documentation
mbed_official 235:685d5f11838f 24 * and/or other materials provided with the distribution.
mbed_official 235:685d5f11838f 25 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 235:685d5f11838f 26 * may be used to endorse or promote products derived from this software
mbed_official 235:685d5f11838f 27 * without specific prior written permission.
mbed_official 235:685d5f11838f 28 *
mbed_official 235:685d5f11838f 29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 235:685d5f11838f 30 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 235:685d5f11838f 31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 235:685d5f11838f 32 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 235:685d5f11838f 33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 235:685d5f11838f 34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 235:685d5f11838f 35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 235:685d5f11838f 36 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 235:685d5f11838f 37 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 235:685d5f11838f 38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 235:685d5f11838f 39 *
mbed_official 235:685d5f11838f 40 ******************************************************************************
mbed_official 235:685d5f11838f 41 */
mbed_official 235:685d5f11838f 42
mbed_official 235:685d5f11838f 43 /* Includes ------------------------------------------------------------------*/
mbed_official 235:685d5f11838f 44 #include "stm32f4xx_hal.h"
mbed_official 235:685d5f11838f 45
mbed_official 235:685d5f11838f 46 /** @addtogroup STM32F4xx_HAL_Driver
mbed_official 235:685d5f11838f 47 * @{
mbed_official 235:685d5f11838f 48 */
mbed_official 235:685d5f11838f 49
mbed_official 235:685d5f11838f 50 /** @defgroup PWR
mbed_official 235:685d5f11838f 51 * @brief PWR HAL module driver
mbed_official 235:685d5f11838f 52 * @{
mbed_official 235:685d5f11838f 53 */
mbed_official 235:685d5f11838f 54
mbed_official 235:685d5f11838f 55 #ifdef HAL_PWR_MODULE_ENABLED
mbed_official 235:685d5f11838f 56
mbed_official 235:685d5f11838f 57 /* Private typedef -----------------------------------------------------------*/
mbed_official 235:685d5f11838f 58 /* Private define ------------------------------------------------------------*/
mbed_official 235:685d5f11838f 59 /* Private macro -------------------------------------------------------------*/
mbed_official 235:685d5f11838f 60 /* Private variables ---------------------------------------------------------*/
mbed_official 235:685d5f11838f 61 /* Private function prototypes -----------------------------------------------*/
mbed_official 235:685d5f11838f 62 /* Private functions ---------------------------------------------------------*/
mbed_official 235:685d5f11838f 63
mbed_official 235:685d5f11838f 64 /** @defgroup PWR_Private_Functions
mbed_official 235:685d5f11838f 65 * @{
mbed_official 235:685d5f11838f 66 */
mbed_official 235:685d5f11838f 67
mbed_official 235:685d5f11838f 68 /** @defgroup PWR_Group1 Initialization and de-initialization functions
mbed_official 235:685d5f11838f 69 * @brief Initialization and de-initialization functions
mbed_official 235:685d5f11838f 70 *
mbed_official 235:685d5f11838f 71 @verbatim
mbed_official 235:685d5f11838f 72 ===============================================================================
mbed_official 235:685d5f11838f 73 ##### Initialization and de-initialization functions #####
mbed_official 235:685d5f11838f 74 ===============================================================================
mbed_official 235:685d5f11838f 75 [..]
mbed_official 235:685d5f11838f 76 After reset, the backup domain (RTC registers, RTC backup data
mbed_official 235:685d5f11838f 77 registers and backup SRAM) is protected against possible unwanted
mbed_official 235:685d5f11838f 78 write accesses.
mbed_official 235:685d5f11838f 79 To enable access to the RTC Domain and RTC registers, proceed as follows:
mbed_official 235:685d5f11838f 80 (+) Enable the Power Controller (PWR) APB1 interface clock using the
mbed_official 235:685d5f11838f 81 __PWR_CLK_ENABLE() macro.
mbed_official 235:685d5f11838f 82 (+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function.
mbed_official 235:685d5f11838f 83
mbed_official 235:685d5f11838f 84 @endverbatim
mbed_official 235:685d5f11838f 85 * @{
mbed_official 235:685d5f11838f 86 */
mbed_official 235:685d5f11838f 87
mbed_official 235:685d5f11838f 88 /**
mbed_official 235:685d5f11838f 89 * @brief Deinitializes the HAL PWR peripheral registers to their default reset values.
mbed_official 235:685d5f11838f 90 * @param None
mbed_official 235:685d5f11838f 91 * @retval None
mbed_official 235:685d5f11838f 92 */
mbed_official 235:685d5f11838f 93 void HAL_PWR_DeInit(void)
mbed_official 235:685d5f11838f 94 {
mbed_official 235:685d5f11838f 95 __PWR_FORCE_RESET();
mbed_official 235:685d5f11838f 96 __PWR_RELEASE_RESET();
mbed_official 235:685d5f11838f 97 }
mbed_official 235:685d5f11838f 98
mbed_official 235:685d5f11838f 99 /**
mbed_official 235:685d5f11838f 100 * @brief Enables access to the backup domain (RTC registers, RTC
mbed_official 235:685d5f11838f 101 * backup data registers and backup SRAM).
mbed_official 235:685d5f11838f 102 * @note If the HSE divided by 2, 3, ..31 is used as the RTC clock, the
mbed_official 235:685d5f11838f 103 * Backup Domain Access should be kept enabled.
mbed_official 235:685d5f11838f 104 * @param None
mbed_official 235:685d5f11838f 105 * @retval None
mbed_official 235:685d5f11838f 106 */
mbed_official 235:685d5f11838f 107 void HAL_PWR_EnableBkUpAccess(void)
mbed_official 235:685d5f11838f 108 {
mbed_official 235:685d5f11838f 109 *(__IO uint32_t *) CR_DBP_BB = (uint32_t)ENABLE;
mbed_official 235:685d5f11838f 110 }
mbed_official 235:685d5f11838f 111
mbed_official 235:685d5f11838f 112 /**
mbed_official 235:685d5f11838f 113 * @brief Disables access to the backup domain (RTC registers, RTC
mbed_official 235:685d5f11838f 114 * backup data registers and backup SRAM).
mbed_official 235:685d5f11838f 115 * @note If the HSE divided by 2, 3, ..31 is used as the RTC clock, the
mbed_official 235:685d5f11838f 116 * Backup Domain Access should be kept enabled.
mbed_official 235:685d5f11838f 117 * @param None
mbed_official 235:685d5f11838f 118 * @retval None
mbed_official 235:685d5f11838f 119 */
mbed_official 235:685d5f11838f 120 void HAL_PWR_DisableBkUpAccess(void)
mbed_official 235:685d5f11838f 121 {
mbed_official 235:685d5f11838f 122 *(__IO uint32_t *) CR_DBP_BB = (uint32_t)DISABLE;
mbed_official 235:685d5f11838f 123 }
mbed_official 235:685d5f11838f 124
mbed_official 235:685d5f11838f 125 /**
mbed_official 235:685d5f11838f 126 * @}
mbed_official 235:685d5f11838f 127 */
mbed_official 235:685d5f11838f 128
mbed_official 235:685d5f11838f 129 /** @defgroup PWR_Group2 Peripheral Control functions
mbed_official 235:685d5f11838f 130 * @brief Low Power modes configuration functions
mbed_official 235:685d5f11838f 131 *
mbed_official 235:685d5f11838f 132 @verbatim
mbed_official 235:685d5f11838f 133
mbed_official 235:685d5f11838f 134 ===============================================================================
mbed_official 235:685d5f11838f 135 ##### Peripheral Control functions #####
mbed_official 235:685d5f11838f 136 ===============================================================================
mbed_official 235:685d5f11838f 137
mbed_official 235:685d5f11838f 138 *** PVD configuration ***
mbed_official 235:685d5f11838f 139 =========================
mbed_official 235:685d5f11838f 140 [..]
mbed_official 235:685d5f11838f 141 (+) The PVD is used to monitor the VDD power supply by comparing it to a
mbed_official 235:685d5f11838f 142 threshold selected by the PVD Level (PLS[2:0] bits in the PWR_CR).
mbed_official 235:685d5f11838f 143 (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower
mbed_official 235:685d5f11838f 144 than the PVD threshold. This event is internally connected to the EXTI
mbed_official 235:685d5f11838f 145 line16 and can generate an interrupt if enabled. This is done through
mbed_official 235:685d5f11838f 146 __HAL_PVD_EXTI_ENABLE_IT() macro.
mbed_official 235:685d5f11838f 147 (+) The PVD is stopped in Standby mode.
mbed_official 235:685d5f11838f 148
mbed_official 235:685d5f11838f 149 *** WakeUp pin configuration ***
mbed_official 235:685d5f11838f 150 ================================
mbed_official 235:685d5f11838f 151 [..]
mbed_official 235:685d5f11838f 152 (+) WakeUp pin is used to wake up the system from Standby mode. This pin is
mbed_official 235:685d5f11838f 153 forced in input pull-down configuration and is active on rising edges.
mbed_official 235:685d5f11838f 154 (+) There is only one WakeUp pin: WakeUp Pin 1 on PA.00.
mbed_official 235:685d5f11838f 155
mbed_official 235:685d5f11838f 156 *** Low Power modes configuration ***
mbed_official 235:685d5f11838f 157 =====================================
mbed_official 235:685d5f11838f 158 [..]
mbed_official 235:685d5f11838f 159 The devices feature 3 low-power modes:
mbed_official 235:685d5f11838f 160 (+) Sleep mode: Cortex-M4 core stopped, peripherals kept running.
mbed_official 235:685d5f11838f 161 (+) Stop mode: all clocks are stopped, regulator running, regulator
mbed_official 235:685d5f11838f 162 in low power mode
mbed_official 235:685d5f11838f 163 (+) Standby mode: 1.2V domain powered off.
mbed_official 235:685d5f11838f 164
mbed_official 235:685d5f11838f 165 *** Sleep mode ***
mbed_official 235:685d5f11838f 166 ==================
mbed_official 235:685d5f11838f 167 [..]
mbed_official 235:685d5f11838f 168 (+) Entry:
mbed_official 235:685d5f11838f 169 The Sleep mode is entered by using the HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI)
mbed_official 235:685d5f11838f 170 functions with
mbed_official 235:685d5f11838f 171 (++) PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction
mbed_official 235:685d5f11838f 172 (++) PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction
mbed_official 235:685d5f11838f 173
mbed_official 235:685d5f11838f 174 -@@- The Regulator parameter is not used for the STM32F4 family
mbed_official 235:685d5f11838f 175 and is kept as parameter just to maintain compatibility with the
mbed_official 235:685d5f11838f 176 lower power families (STM32L).
mbed_official 235:685d5f11838f 177 (+) Exit:
mbed_official 235:685d5f11838f 178 Any peripheral interrupt acknowledged by the nested vectored interrupt
mbed_official 235:685d5f11838f 179 controller (NVIC) can wake up the device from Sleep mode.
mbed_official 235:685d5f11838f 180
mbed_official 235:685d5f11838f 181 *** Stop mode ***
mbed_official 235:685d5f11838f 182 =================
mbed_official 235:685d5f11838f 183 [..]
mbed_official 235:685d5f11838f 184 In Stop mode, all clocks in the 1.2V domain are stopped, the PLL, the HSI,
mbed_official 235:685d5f11838f 185 and the HSE RC oscillators are disabled. Internal SRAM and register contents
mbed_official 235:685d5f11838f 186 are preserved.
mbed_official 235:685d5f11838f 187 The voltage regulator can be configured either in normal or low-power mode.
mbed_official 235:685d5f11838f 188 To minimize the consumption In Stop mode, FLASH can be powered off before
mbed_official 235:685d5f11838f 189 entering the Stop mode using the HAL_PWR_EnableFlashPowerDown() function.
mbed_official 235:685d5f11838f 190 It can be switched on again by software after exiting the Stop mode using
mbed_official 235:685d5f11838f 191 the HAL_PWR_DisableFlashPowerDown() function.
mbed_official 235:685d5f11838f 192
mbed_official 235:685d5f11838f 193 (+) Entry:
mbed_official 235:685d5f11838f 194 The Stop mode is entered using the HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON)
mbed_official 235:685d5f11838f 195 function with:
mbed_official 235:685d5f11838f 196 (++) Main regulator ON.
mbed_official 235:685d5f11838f 197 (++) Low Power regulator ON.
mbed_official 235:685d5f11838f 198 (+) Exit:
mbed_official 235:685d5f11838f 199 Any EXTI Line (Internal or External) configured in Interrupt/Event mode.
mbed_official 235:685d5f11838f 200
mbed_official 235:685d5f11838f 201 *** Standby mode ***
mbed_official 235:685d5f11838f 202 ====================
mbed_official 235:685d5f11838f 203 [..]
mbed_official 235:685d5f11838f 204 (+)
mbed_official 235:685d5f11838f 205 The Standby mode allows to achieve the lowest power consumption. It is based
mbed_official 235:685d5f11838f 206 on the Cortex-M4 deep sleep mode, with the voltage regulator disabled.
mbed_official 235:685d5f11838f 207 The 1.2V domain is consequently powered off. The PLL, the HSI oscillator and
mbed_official 235:685d5f11838f 208 the HSE oscillator are also switched off. SRAM and register contents are lost
mbed_official 235:685d5f11838f 209 except for the RTC registers, RTC backup registers, backup SRAM and Standby
mbed_official 235:685d5f11838f 210 circuitry.
mbed_official 235:685d5f11838f 211
mbed_official 235:685d5f11838f 212 The voltage regulator is OFF.
mbed_official 235:685d5f11838f 213
mbed_official 235:685d5f11838f 214 (++) Entry:
mbed_official 235:685d5f11838f 215 (+++) The Standby mode is entered using the HAL_PWR_EnterSTANDBYMode() function.
mbed_official 235:685d5f11838f 216 (++) Exit:
mbed_official 235:685d5f11838f 217 (+++) WKUP pin rising edge, RTC alarm (Alarm A and Alarm B), RTC wakeup,
mbed_official 235:685d5f11838f 218 tamper event, time-stamp event, external reset in NRST pin, IWDG reset.
mbed_official 235:685d5f11838f 219
mbed_official 235:685d5f11838f 220 *** Auto-wakeup (AWU) from low-power mode ***
mbed_official 235:685d5f11838f 221 =============================================
mbed_official 235:685d5f11838f 222 [..]
mbed_official 235:685d5f11838f 223
mbed_official 235:685d5f11838f 224 (+) The MCU can be woken up from low-power mode by an RTC Alarm event, an RTC
mbed_official 235:685d5f11838f 225 Wakeup event, a tamper event or a time-stamp event, without depending on
mbed_official 235:685d5f11838f 226 an external interrupt (Auto-wakeup mode).
mbed_official 235:685d5f11838f 227
mbed_official 235:685d5f11838f 228 (+) RTC auto-wakeup (AWU) from the Stop and Standby modes
mbed_official 235:685d5f11838f 229
mbed_official 235:685d5f11838f 230 (++) To wake up from the Stop mode with an RTC alarm event, it is necessary to
mbed_official 235:685d5f11838f 231 configure the RTC to generate the RTC alarm using the HAL_RTC_SetAlarm_IT() function.
mbed_official 235:685d5f11838f 232
mbed_official 235:685d5f11838f 233 (++) To wake up from the Stop mode with an RTC Tamper or time stamp event, it
mbed_official 235:685d5f11838f 234 is necessary to configure the RTC to detect the tamper or time stamp event using the
mbed_official 235:685d5f11838f 235 HAL_RTCEx_SetTimeStamp_IT() or HAL_RTCEx_SetTamper_IT() functions.
mbed_official 235:685d5f11838f 236
mbed_official 235:685d5f11838f 237 (++) To wake up from the Stop mode with an RTC WakeUp event, it is necessary to
mbed_official 235:685d5f11838f 238 configure the RTC to generate the RTC WakeUp event using the HAL_RTCEx_SetWakeUpTimer_IT() function.
mbed_official 235:685d5f11838f 239
mbed_official 235:685d5f11838f 240 @endverbatim
mbed_official 235:685d5f11838f 241 * @{
mbed_official 235:685d5f11838f 242 */
mbed_official 235:685d5f11838f 243
mbed_official 235:685d5f11838f 244 /**
mbed_official 235:685d5f11838f 245 * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD).
mbed_official 235:685d5f11838f 246 * @param sConfigPVD: pointer to an PWR_PVDTypeDef structure that contains the configuration
mbed_official 235:685d5f11838f 247 * information for the PVD.
mbed_official 235:685d5f11838f 248 * @note Refer to the electrical characteristics of your device datasheet for
mbed_official 235:685d5f11838f 249 * more details about the voltage threshold corresponding to each
mbed_official 235:685d5f11838f 250 * detection level.
mbed_official 235:685d5f11838f 251 * @retval None
mbed_official 235:685d5f11838f 252 */
mbed_official 235:685d5f11838f 253 void HAL_PWR_PVDConfig(PWR_PVDTypeDef *sConfigPVD)
mbed_official 235:685d5f11838f 254 {
mbed_official 235:685d5f11838f 255 uint32_t tmpreg = 0;
mbed_official 235:685d5f11838f 256
mbed_official 235:685d5f11838f 257 /* Check the parameters */
mbed_official 235:685d5f11838f 258 assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel));
mbed_official 235:685d5f11838f 259 assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode));
mbed_official 235:685d5f11838f 260
mbed_official 235:685d5f11838f 261 tmpreg = PWR->CR;
mbed_official 235:685d5f11838f 262
mbed_official 235:685d5f11838f 263 /* Clear PLS[7:5] bits */
mbed_official 235:685d5f11838f 264 tmpreg &= ~ (uint32_t)PWR_CR_PLS;
mbed_official 235:685d5f11838f 265
mbed_official 235:685d5f11838f 266 /* Set PLS[7:5] bits according to PVDLevel value */
mbed_official 235:685d5f11838f 267 tmpreg |= sConfigPVD->PVDLevel;
mbed_official 235:685d5f11838f 268
mbed_official 235:685d5f11838f 269 /* Store the new value */
mbed_official 235:685d5f11838f 270 PWR->CR = tmpreg;
mbed_official 235:685d5f11838f 271
mbed_official 235:685d5f11838f 272 /* Configure the EXTI 16 interrupt */
mbed_official 235:685d5f11838f 273 if((sConfigPVD->Mode == PWR_MODE_IT_RISING_FALLING) ||\
mbed_official 235:685d5f11838f 274 (sConfigPVD->Mode == PWR_MODE_IT_FALLING) ||\
mbed_official 235:685d5f11838f 275 (sConfigPVD->Mode == PWR_MODE_IT_RISING))
mbed_official 235:685d5f11838f 276 {
mbed_official 235:685d5f11838f 277 __HAL_PVD_EXTI_ENABLE_IT(PWR_EXTI_LINE_PVD);
mbed_official 235:685d5f11838f 278 }
mbed_official 235:685d5f11838f 279 /* Clear the edge trigger for the EXTI Line 16 (PVD) */
mbed_official 235:685d5f11838f 280 EXTI->RTSR &= ~EXTI_RTSR_TR16;
mbed_official 235:685d5f11838f 281 EXTI->FTSR &= ~EXTI_FTSR_TR16;
mbed_official 235:685d5f11838f 282 /* Configure the rising edge */
mbed_official 235:685d5f11838f 283 if((sConfigPVD->Mode == PWR_MODE_IT_RISING_FALLING) ||\
mbed_official 235:685d5f11838f 284 (sConfigPVD->Mode == PWR_MODE_IT_RISING))
mbed_official 235:685d5f11838f 285 {
mbed_official 235:685d5f11838f 286 EXTI->RTSR |= PWR_EXTI_LINE_PVD;
mbed_official 235:685d5f11838f 287 }
mbed_official 235:685d5f11838f 288 /* Configure the falling edge */
mbed_official 235:685d5f11838f 289 if((sConfigPVD->Mode == PWR_MODE_IT_RISING_FALLING) ||\
mbed_official 235:685d5f11838f 290 (sConfigPVD->Mode == PWR_MODE_IT_FALLING))
mbed_official 235:685d5f11838f 291 {
mbed_official 235:685d5f11838f 292 EXTI->FTSR |= PWR_EXTI_LINE_PVD;
mbed_official 235:685d5f11838f 293 }
mbed_official 235:685d5f11838f 294 }
mbed_official 235:685d5f11838f 295
mbed_official 235:685d5f11838f 296 /**
mbed_official 235:685d5f11838f 297 * @brief Enables the Power Voltage Detector(PVD).
mbed_official 235:685d5f11838f 298 * @param None
mbed_official 235:685d5f11838f 299 * @retval None
mbed_official 235:685d5f11838f 300 */
mbed_official 235:685d5f11838f 301 void HAL_PWR_EnablePVD(void)
mbed_official 235:685d5f11838f 302 {
mbed_official 235:685d5f11838f 303 *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)ENABLE;
mbed_official 235:685d5f11838f 304 }
mbed_official 235:685d5f11838f 305
mbed_official 235:685d5f11838f 306 /**
mbed_official 235:685d5f11838f 307 * @brief Disables the Power Voltage Detector(PVD).
mbed_official 235:685d5f11838f 308 * @param None
mbed_official 235:685d5f11838f 309 * @retval None
mbed_official 235:685d5f11838f 310 */
mbed_official 235:685d5f11838f 311 void HAL_PWR_DisablePVD(void)
mbed_official 235:685d5f11838f 312 {
mbed_official 235:685d5f11838f 313 *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)DISABLE;
mbed_official 235:685d5f11838f 314 }
mbed_official 235:685d5f11838f 315
mbed_official 235:685d5f11838f 316 /**
mbed_official 235:685d5f11838f 317 * @brief Enables the WakeUp PINx functionality.
mbed_official 235:685d5f11838f 318 * @param WakeUpPinx: Specifies the Power Wake-Up pin to enable.
mbed_official 235:685d5f11838f 319 * This parameter can be one of the following values:
mbed_official 235:685d5f11838f 320 * @arg PWR_WAKEUP_PIN1
mbed_official 235:685d5f11838f 321 * @retval None
mbed_official 235:685d5f11838f 322 */
mbed_official 235:685d5f11838f 323 void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx)
mbed_official 235:685d5f11838f 324 {
mbed_official 235:685d5f11838f 325 /* Check the parameter */
mbed_official 235:685d5f11838f 326 assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
mbed_official 235:685d5f11838f 327 *(__IO uint32_t *) CSR_EWUP_BB = (uint32_t)ENABLE;
mbed_official 235:685d5f11838f 328 }
mbed_official 235:685d5f11838f 329
mbed_official 235:685d5f11838f 330 /**
mbed_official 235:685d5f11838f 331 * @brief Disables the WakeUp PINx functionality.
mbed_official 235:685d5f11838f 332 * @param WakeUpPinx: Specifies the Power Wake-Up pin to disable.
mbed_official 235:685d5f11838f 333 * This parameter can be one of the following values:
mbed_official 235:685d5f11838f 334 * @arg PWR_WAKEUP_PIN1
mbed_official 235:685d5f11838f 335 * @retval None
mbed_official 235:685d5f11838f 336 */
mbed_official 235:685d5f11838f 337 void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx)
mbed_official 235:685d5f11838f 338 {
mbed_official 235:685d5f11838f 339 /* Check the parameter */
mbed_official 235:685d5f11838f 340 assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
mbed_official 235:685d5f11838f 341 *(__IO uint32_t *) CSR_EWUP_BB = (uint32_t)DISABLE;
mbed_official 235:685d5f11838f 342 }
mbed_official 235:685d5f11838f 343
mbed_official 235:685d5f11838f 344 /**
mbed_official 235:685d5f11838f 345 * @brief Enters Sleep mode.
mbed_official 235:685d5f11838f 346 *
mbed_official 235:685d5f11838f 347 * @note In Sleep mode, all I/O pins keep the same state as in Run mode.
mbed_official 235:685d5f11838f 348 *
mbed_official 235:685d5f11838f 349 * @note In Sleep mode, the systick is stopped to avoid exit from this mode with
mbed_official 235:685d5f11838f 350 * systick interrupt when used as time base for Timeout
mbed_official 235:685d5f11838f 351 *
mbed_official 235:685d5f11838f 352 * @param Regulator: Specifies the regulator state in SLEEP mode.
mbed_official 235:685d5f11838f 353 * This parameter can be one of the following values:
mbed_official 235:685d5f11838f 354 * @arg PWR_MAINREGULATOR_ON: SLEEP mode with regulator ON
mbed_official 235:685d5f11838f 355 * @arg PWR_LOWPOWERREGULATOR_ON: SLEEP mode with low power regulator ON
mbed_official 235:685d5f11838f 356 * @note This parameter is not used for the STM32F4 family and is kept as parameter
mbed_official 235:685d5f11838f 357 * just to maintain compatibility with the lower power families.
mbed_official 235:685d5f11838f 358 * @param SLEEPEntry: Specifies if SLEEP mode in entered with WFI or WFE instruction.
mbed_official 235:685d5f11838f 359 * This parameter can be one of the following values:
mbed_official 235:685d5f11838f 360 * @arg PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction
mbed_official 235:685d5f11838f 361 * @arg PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction
mbed_official 235:685d5f11838f 362 * @retval None
mbed_official 235:685d5f11838f 363 */
mbed_official 235:685d5f11838f 364 void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)
mbed_official 235:685d5f11838f 365 {
mbed_official 235:685d5f11838f 366 /* Check the parameters */
mbed_official 235:685d5f11838f 367 assert_param(IS_PWR_REGULATOR(Regulator));
mbed_official 235:685d5f11838f 368 assert_param(IS_PWR_SLEEP_ENTRY(SLEEPEntry));
mbed_official 235:685d5f11838f 369
mbed_official 235:685d5f11838f 370 /* Select SLEEP mode entry -------------------------------------------------*/
mbed_official 235:685d5f11838f 371 if(SLEEPEntry == PWR_SLEEPENTRY_WFI)
mbed_official 235:685d5f11838f 372 {
mbed_official 235:685d5f11838f 373 /* Request Wait For Interrupt */
mbed_official 235:685d5f11838f 374 __WFI();
mbed_official 235:685d5f11838f 375 }
mbed_official 235:685d5f11838f 376 else
mbed_official 235:685d5f11838f 377 {
mbed_official 235:685d5f11838f 378 /* Request Wait For Event */
mbed_official 235:685d5f11838f 379 __SEV();
mbed_official 235:685d5f11838f 380 __WFE();
mbed_official 235:685d5f11838f 381 __WFE();
mbed_official 235:685d5f11838f 382 }
mbed_official 235:685d5f11838f 383 }
mbed_official 235:685d5f11838f 384
mbed_official 235:685d5f11838f 385 /**
mbed_official 235:685d5f11838f 386 * @brief Enters Stop mode.
mbed_official 235:685d5f11838f 387 * @note In Stop mode, all I/O pins keep the same state as in Run mode.
mbed_official 235:685d5f11838f 388 * @note When exiting Stop mode by issuing an interrupt or a wakeup event,
mbed_official 235:685d5f11838f 389 * the HSI RC oscillator is selected as system clock.
mbed_official 235:685d5f11838f 390 * @note When the voltage regulator operates in low power mode, an additional
mbed_official 235:685d5f11838f 391 * startup delay is incurred when waking up from Stop mode.
mbed_official 235:685d5f11838f 392 * By keeping the internal regulator ON during Stop mode, the consumption
mbed_official 235:685d5f11838f 393 * is higher although the startup time is reduced.
mbed_official 235:685d5f11838f 394 * @param Regulator: Specifies the regulator state in Stop mode.
mbed_official 235:685d5f11838f 395 * This parameter can be one of the following values:
mbed_official 235:685d5f11838f 396 * @arg PWR_MAINREGULATOR_ON: Stop mode with regulator ON
mbed_official 235:685d5f11838f 397 * @arg PWR_LOWPOWERREGULATOR_ON: Stop mode with low power regulator ON
mbed_official 235:685d5f11838f 398 * @param STOPEntry: Specifies if Stop mode in entered with WFI or WFE instruction.
mbed_official 235:685d5f11838f 399 * This parameter can be one of the following values:
mbed_official 235:685d5f11838f 400 * @arg PWR_STOPENTRY_WFI: Enter Stop mode with WFI instruction
mbed_official 235:685d5f11838f 401 * @arg PWR_STOPENTRY_WFE: Enter Stop mode with WFE instruction
mbed_official 235:685d5f11838f 402 * @retval None
mbed_official 235:685d5f11838f 403 */
mbed_official 235:685d5f11838f 404 void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
mbed_official 235:685d5f11838f 405 {
mbed_official 235:685d5f11838f 406 uint32_t tmpreg = 0;
mbed_official 235:685d5f11838f 407
mbed_official 235:685d5f11838f 408 /* Check the parameters */
mbed_official 235:685d5f11838f 409 assert_param(IS_PWR_REGULATOR(Regulator));
mbed_official 235:685d5f11838f 410 assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
mbed_official 235:685d5f11838f 411
mbed_official 235:685d5f11838f 412 /* Select the regulator state in Stop mode ---------------------------------*/
mbed_official 235:685d5f11838f 413 tmpreg = PWR->CR;
mbed_official 235:685d5f11838f 414 /* Clear PDDS and LPDS bits */
mbed_official 235:685d5f11838f 415 tmpreg &= (uint32_t)~(PWR_CR_PDDS | PWR_CR_LPDS);
mbed_official 235:685d5f11838f 416
mbed_official 235:685d5f11838f 417 /* Set LPDS, MRLVDS and LPLVDS bits according to Regulator value */
mbed_official 235:685d5f11838f 418 tmpreg |= Regulator;
mbed_official 235:685d5f11838f 419
mbed_official 235:685d5f11838f 420 /* Store the new value */
mbed_official 235:685d5f11838f 421 PWR->CR = tmpreg;
mbed_official 235:685d5f11838f 422
mbed_official 235:685d5f11838f 423 /* Set SLEEPDEEP bit of Cortex System Control Register */
mbed_official 235:685d5f11838f 424 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
mbed_official 235:685d5f11838f 425
mbed_official 235:685d5f11838f 426 /* Select Stop mode entry --------------------------------------------------*/
mbed_official 235:685d5f11838f 427 if(STOPEntry == PWR_STOPENTRY_WFI)
mbed_official 235:685d5f11838f 428 {
mbed_official 235:685d5f11838f 429 /* Request Wait For Interrupt */
mbed_official 235:685d5f11838f 430 __WFI();
mbed_official 235:685d5f11838f 431 }
mbed_official 235:685d5f11838f 432 else
mbed_official 235:685d5f11838f 433 {
mbed_official 235:685d5f11838f 434 /* Request Wait For Event */
mbed_official 235:685d5f11838f 435 __WFE();
mbed_official 235:685d5f11838f 436 }
mbed_official 235:685d5f11838f 437 /* Reset SLEEPDEEP bit of Cortex System Control Register */
mbed_official 235:685d5f11838f 438 SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
mbed_official 235:685d5f11838f 439 }
mbed_official 235:685d5f11838f 440
mbed_official 235:685d5f11838f 441 /**
mbed_official 235:685d5f11838f 442 * @brief Enters Standby mode.
mbed_official 235:685d5f11838f 443 * @note In Standby mode, all I/O pins are high impedance except for:
mbed_official 235:685d5f11838f 444 * - Reset pad (still available)
mbed_official 235:685d5f11838f 445 * - RTC_AF1 pin (PC13) if configured for tamper, time-stamp, RTC
mbed_official 235:685d5f11838f 446 * Alarm out, or RTC clock calibration out.
mbed_official 235:685d5f11838f 447 * - RTC_AF2 pin (PI8) if configured for tamper or time-stamp.
mbed_official 235:685d5f11838f 448 * - WKUP pin 1 (PA0) if enabled.
mbed_official 235:685d5f11838f 449 * @param None
mbed_official 235:685d5f11838f 450 * @retval None
mbed_official 235:685d5f11838f 451 */
mbed_official 235:685d5f11838f 452 void HAL_PWR_EnterSTANDBYMode(void)
mbed_official 235:685d5f11838f 453 {
mbed_official 235:685d5f11838f 454 /* Select Standby mode */
mbed_official 235:685d5f11838f 455 PWR->CR |= PWR_CR_PDDS;
mbed_official 235:685d5f11838f 456
mbed_official 235:685d5f11838f 457 /* Set SLEEPDEEP bit of Cortex System Control Register */
mbed_official 235:685d5f11838f 458 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
mbed_official 235:685d5f11838f 459
mbed_official 235:685d5f11838f 460 /* This option is used to ensure that store operations are completed */
mbed_official 235:685d5f11838f 461 #if defined ( __CC_ARM)
mbed_official 235:685d5f11838f 462 __force_stores();
mbed_official 235:685d5f11838f 463 #endif
mbed_official 235:685d5f11838f 464 /* Request Wait For Interrupt */
mbed_official 235:685d5f11838f 465 __WFI();
mbed_official 235:685d5f11838f 466 }
mbed_official 235:685d5f11838f 467
mbed_official 235:685d5f11838f 468 /**
mbed_official 235:685d5f11838f 469 * @brief This function handles the PWR PVD interrupt request.
mbed_official 235:685d5f11838f 470 * @note This API should be called under the PVD_IRQHandler().
mbed_official 235:685d5f11838f 471 * @param None
mbed_official 235:685d5f11838f 472 * @retval None
mbed_official 235:685d5f11838f 473 */
mbed_official 235:685d5f11838f 474 void HAL_PWR_PVD_IRQHandler(void)
mbed_official 235:685d5f11838f 475 {
mbed_official 235:685d5f11838f 476 /* Check PWR exti flag */
mbed_official 235:685d5f11838f 477 if(__HAL_PVD_EXTI_GET_FLAG(PWR_EXTI_LINE_PVD) != RESET)
mbed_official 235:685d5f11838f 478 {
mbed_official 235:685d5f11838f 479 /* PWR PVD interrupt user callback */
mbed_official 235:685d5f11838f 480 HAL_PWR_PVDCallback();
mbed_official 235:685d5f11838f 481
mbed_official 235:685d5f11838f 482 /* Clear PWR Exti pending bit */
mbed_official 235:685d5f11838f 483 __HAL_PVD_EXTI_CLEAR_FLAG(PWR_EXTI_LINE_PVD);
mbed_official 235:685d5f11838f 484 }
mbed_official 235:685d5f11838f 485 }
mbed_official 235:685d5f11838f 486
mbed_official 235:685d5f11838f 487 /**
mbed_official 235:685d5f11838f 488 * @brief PWR PVD interrupt callback
mbed_official 235:685d5f11838f 489 * @param None
mbed_official 235:685d5f11838f 490 * @retval None
mbed_official 235:685d5f11838f 491 */
mbed_official 235:685d5f11838f 492 __weak void HAL_PWR_PVDCallback(void)
mbed_official 235:685d5f11838f 493 {
mbed_official 235:685d5f11838f 494 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 235:685d5f11838f 495 the HAL_PWR_PVDCallback could be implemented in the user file
mbed_official 235:685d5f11838f 496 */
mbed_official 235:685d5f11838f 497 }
mbed_official 235:685d5f11838f 498
mbed_official 235:685d5f11838f 499 /**
mbed_official 235:685d5f11838f 500 * @}
mbed_official 235:685d5f11838f 501 */
mbed_official 235:685d5f11838f 502
mbed_official 235:685d5f11838f 503 /**
mbed_official 235:685d5f11838f 504 * @}
mbed_official 235:685d5f11838f 505 */
mbed_official 235:685d5f11838f 506
mbed_official 235:685d5f11838f 507 #endif /* HAL_PWR_MODULE_ENABLED */
mbed_official 235:685d5f11838f 508 /**
mbed_official 235:685d5f11838f 509 * @}
mbed_official 235:685d5f11838f 510 */
mbed_official 235:685d5f11838f 511
mbed_official 235:685d5f11838f 512 /**
mbed_official 235:685d5f11838f 513 * @}
mbed_official 235:685d5f11838f 514 */
mbed_official 235:685d5f11838f 515
mbed_official 235:685d5f11838f 516 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/