mbed library sources

Fork of mbed-src by mbed official

Committer:
lzbpli
Date:
Thu Jul 07 06:48:59 2016 +0000
Revision:
636:b0d178e9fa10
Parent:
610:813dcc80987e
l053

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 610:813dcc80987e 1 /**
mbed_official 610:813dcc80987e 2 ******************************************************************************
mbed_official 610:813dcc80987e 3 * @file stm32l4xx_hal_pwr.c
mbed_official 610:813dcc80987e 4 * @author MCD Application Team
mbed_official 610:813dcc80987e 5 * @version V1.0.0
mbed_official 610:813dcc80987e 6 * @date 26-June-2015
mbed_official 610:813dcc80987e 7 * @brief PWR HAL module driver.
mbed_official 610:813dcc80987e 8 * This file provides firmware functions to manage the following
mbed_official 610:813dcc80987e 9 * functionalities of the Power Controller (PWR) peripheral:
mbed_official 610:813dcc80987e 10 * + Initialization/de-initialization functions
mbed_official 610:813dcc80987e 11 * + Peripheral Control functions
mbed_official 610:813dcc80987e 12 *
mbed_official 610:813dcc80987e 13 ******************************************************************************
mbed_official 610:813dcc80987e 14 * @attention
mbed_official 610:813dcc80987e 15 *
mbed_official 610:813dcc80987e 16 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
mbed_official 610:813dcc80987e 17 *
mbed_official 610:813dcc80987e 18 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 610:813dcc80987e 19 * are permitted provided that the following conditions are met:
mbed_official 610:813dcc80987e 20 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 610:813dcc80987e 21 * this list of conditions and the following disclaimer.
mbed_official 610:813dcc80987e 22 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 610:813dcc80987e 23 * this list of conditions and the following disclaimer in the documentation
mbed_official 610:813dcc80987e 24 * and/or other materials provided with the distribution.
mbed_official 610:813dcc80987e 25 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 610:813dcc80987e 26 * may be used to endorse or promote products derived from this software
mbed_official 610:813dcc80987e 27 * without specific prior written permission.
mbed_official 610:813dcc80987e 28 *
mbed_official 610:813dcc80987e 29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 610:813dcc80987e 30 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 610:813dcc80987e 31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 610:813dcc80987e 32 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 610:813dcc80987e 33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 610:813dcc80987e 34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 610:813dcc80987e 35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 610:813dcc80987e 36 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 610:813dcc80987e 37 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 610:813dcc80987e 38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 610:813dcc80987e 39 *
mbed_official 610:813dcc80987e 40 ******************************************************************************
mbed_official 610:813dcc80987e 41 */
mbed_official 610:813dcc80987e 42
mbed_official 610:813dcc80987e 43 /* Includes ------------------------------------------------------------------*/
mbed_official 610:813dcc80987e 44 #include "stm32l4xx_hal.h"
mbed_official 610:813dcc80987e 45
mbed_official 610:813dcc80987e 46 /** @addtogroup STM32L4xx_HAL_Driver
mbed_official 610:813dcc80987e 47 * @{
mbed_official 610:813dcc80987e 48 */
mbed_official 610:813dcc80987e 49
mbed_official 610:813dcc80987e 50 /** @defgroup PWR PWR
mbed_official 610:813dcc80987e 51 * @brief PWR HAL module driver
mbed_official 610:813dcc80987e 52 * @{
mbed_official 610:813dcc80987e 53 */
mbed_official 610:813dcc80987e 54
mbed_official 610:813dcc80987e 55 #ifdef HAL_PWR_MODULE_ENABLED
mbed_official 610:813dcc80987e 56
mbed_official 610:813dcc80987e 57 /* Private typedef -----------------------------------------------------------*/
mbed_official 610:813dcc80987e 58 /* Private define ------------------------------------------------------------*/
mbed_official 610:813dcc80987e 59
mbed_official 610:813dcc80987e 60 /** @defgroup PWR_Private_Defines PWR Private Defines
mbed_official 610:813dcc80987e 61 * @{
mbed_official 610:813dcc80987e 62 */
mbed_official 610:813dcc80987e 63
mbed_official 610:813dcc80987e 64 /** @defgroup PWR_PVD_Mode_Mask PWR PVD Mode Mask
mbed_official 610:813dcc80987e 65 * @{
mbed_official 610:813dcc80987e 66 */
mbed_official 610:813dcc80987e 67 #define PVD_MODE_IT ((uint32_t)0x00010000) /*!< Mask for interruption yielded by PVD threshold crossing */
mbed_official 610:813dcc80987e 68 #define PVD_MODE_EVT ((uint32_t)0x00020000) /*!< Mask for event yielded by PVD threshold crossing */
mbed_official 610:813dcc80987e 69 #define PVD_RISING_EDGE ((uint32_t)0x00000001) /*!< Mask for rising edge set as PVD trigger */
mbed_official 610:813dcc80987e 70 #define PVD_FALLING_EDGE ((uint32_t)0x00000002) /*!< Mask for falling edge set as PVD trigger */
mbed_official 610:813dcc80987e 71 /**
mbed_official 610:813dcc80987e 72 * @}
mbed_official 610:813dcc80987e 73 */
mbed_official 610:813dcc80987e 74
mbed_official 610:813dcc80987e 75 /**
mbed_official 610:813dcc80987e 76 * @}
mbed_official 610:813dcc80987e 77 */
mbed_official 610:813dcc80987e 78
mbed_official 610:813dcc80987e 79 /* Private macro -------------------------------------------------------------*/
mbed_official 610:813dcc80987e 80 /* Private variables ---------------------------------------------------------*/
mbed_official 610:813dcc80987e 81 /* Private function prototypes -----------------------------------------------*/
mbed_official 610:813dcc80987e 82 /* Exported functions --------------------------------------------------------*/
mbed_official 610:813dcc80987e 83
mbed_official 610:813dcc80987e 84 /** @defgroup PWR_Exported_Functions PWR Exported Functions
mbed_official 610:813dcc80987e 85 * @{
mbed_official 610:813dcc80987e 86 */
mbed_official 610:813dcc80987e 87
mbed_official 610:813dcc80987e 88 /** @defgroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions
mbed_official 610:813dcc80987e 89 * @brief Initialization and de-initialization functions
mbed_official 610:813dcc80987e 90 *
mbed_official 610:813dcc80987e 91 @verbatim
mbed_official 610:813dcc80987e 92 ===============================================================================
mbed_official 610:813dcc80987e 93 ##### Initialization and de-initialization functions #####
mbed_official 610:813dcc80987e 94 ===============================================================================
mbed_official 610:813dcc80987e 95 [..]
mbed_official 610:813dcc80987e 96
mbed_official 610:813dcc80987e 97 @endverbatim
mbed_official 610:813dcc80987e 98 * @{
mbed_official 610:813dcc80987e 99 */
mbed_official 610:813dcc80987e 100
mbed_official 610:813dcc80987e 101 /**
mbed_official 610:813dcc80987e 102 * @brief Deinitialize the HAL PWR peripheral registers to their default reset values.
mbed_official 610:813dcc80987e 103 * @retval None
mbed_official 610:813dcc80987e 104 */
mbed_official 610:813dcc80987e 105 void HAL_PWR_DeInit(void)
mbed_official 610:813dcc80987e 106 {
mbed_official 610:813dcc80987e 107 __HAL_RCC_PWR_FORCE_RESET();
mbed_official 610:813dcc80987e 108 __HAL_RCC_PWR_RELEASE_RESET();
mbed_official 610:813dcc80987e 109 }
mbed_official 610:813dcc80987e 110
mbed_official 610:813dcc80987e 111 /**
mbed_official 610:813dcc80987e 112 * @brief Enable access to the backup domain
mbed_official 610:813dcc80987e 113 * (RTC registers, RTC backup data registers).
mbed_official 610:813dcc80987e 114 * @note After reset, the backup domain is protected against
mbed_official 610:813dcc80987e 115 * possible unwanted write accesses.
mbed_official 610:813dcc80987e 116 * @note RTCSEL that sets the RTC clock source selection is in the RTC back-up domain.
mbed_official 610:813dcc80987e 117 * In order to set or modify the RTC clock, the backup domain access must be
mbed_official 610:813dcc80987e 118 * disabled.
mbed_official 610:813dcc80987e 119 * @note LSEON bit that switches on and off the LSE crystal belongs as well to the
mbed_official 610:813dcc80987e 120 * back-up domain.
mbed_official 610:813dcc80987e 121 * @retval None
mbed_official 610:813dcc80987e 122 */
mbed_official 610:813dcc80987e 123 void HAL_PWR_EnableBkUpAccess(void)
mbed_official 610:813dcc80987e 124 {
mbed_official 610:813dcc80987e 125 SET_BIT(PWR->CR1, PWR_CR1_DBP);
mbed_official 610:813dcc80987e 126 }
mbed_official 610:813dcc80987e 127
mbed_official 610:813dcc80987e 128 /**
mbed_official 610:813dcc80987e 129 * @brief Disable access to the backup domain
mbed_official 610:813dcc80987e 130 * (RTC registers, RTC backup data registers).
mbed_official 610:813dcc80987e 131 * @retval None
mbed_official 610:813dcc80987e 132 */
mbed_official 610:813dcc80987e 133 void HAL_PWR_DisableBkUpAccess(void)
mbed_official 610:813dcc80987e 134 {
mbed_official 610:813dcc80987e 135 CLEAR_BIT(PWR->CR1, PWR_CR1_DBP);
mbed_official 610:813dcc80987e 136 }
mbed_official 610:813dcc80987e 137
mbed_official 610:813dcc80987e 138
mbed_official 610:813dcc80987e 139
mbed_official 610:813dcc80987e 140
mbed_official 610:813dcc80987e 141 /**
mbed_official 610:813dcc80987e 142 * @}
mbed_official 610:813dcc80987e 143 */
mbed_official 610:813dcc80987e 144
mbed_official 610:813dcc80987e 145
mbed_official 610:813dcc80987e 146
mbed_official 610:813dcc80987e 147 /** @defgroup PWR_Exported_Functions_Group2 Peripheral Control functions
mbed_official 610:813dcc80987e 148 * @brief Low Power modes configuration functions
mbed_official 610:813dcc80987e 149 *
mbed_official 610:813dcc80987e 150 @verbatim
mbed_official 610:813dcc80987e 151
mbed_official 610:813dcc80987e 152 ===============================================================================
mbed_official 610:813dcc80987e 153 ##### Peripheral Control functions #####
mbed_official 610:813dcc80987e 154 ===============================================================================
mbed_official 610:813dcc80987e 155
mbed_official 610:813dcc80987e 156 [..]
mbed_official 610:813dcc80987e 157 *** PVD configuration ***
mbed_official 610:813dcc80987e 158 =========================
mbed_official 610:813dcc80987e 159 [..]
mbed_official 610:813dcc80987e 160 (+) The PVD is used to monitor the VDD power supply by comparing it to a
mbed_official 610:813dcc80987e 161 threshold selected by the PVD Level (PLS[2:0] bits in PWR_CR2 register).
mbed_official 610:813dcc80987e 162
mbed_official 610:813dcc80987e 163 (+) PVDO flag is available to indicate if VDD/VDDA is higher or lower
mbed_official 610:813dcc80987e 164 than the PVD threshold. This event is internally connected to the EXTI
mbed_official 610:813dcc80987e 165 line16 and can generate an interrupt if enabled. This is done through
mbed_official 610:813dcc80987e 166 __HAL_PVD_EXTI_ENABLE_IT() macro.
mbed_official 610:813dcc80987e 167 (+) The PVD is stopped in Standby mode.
mbed_official 610:813dcc80987e 168
mbed_official 610:813dcc80987e 169
mbed_official 610:813dcc80987e 170 *** WakeUp pin configuration ***
mbed_official 610:813dcc80987e 171 ================================
mbed_official 610:813dcc80987e 172 [..]
mbed_official 610:813dcc80987e 173 (+) WakeUp pins are used to wakeup the system from Standby mode or Shutdown mode.
mbed_official 610:813dcc80987e 174 The polarity of these pins can be set to configure event detection on high
mbed_official 610:813dcc80987e 175 level (rising edge) or low level (falling edge).
mbed_official 610:813dcc80987e 176
mbed_official 610:813dcc80987e 177
mbed_official 610:813dcc80987e 178
mbed_official 610:813dcc80987e 179 *** Low Power modes configuration ***
mbed_official 610:813dcc80987e 180 =====================================
mbed_official 610:813dcc80987e 181 [..]
mbed_official 610:813dcc80987e 182 The devices feature 8 low-power modes:
mbed_official 610:813dcc80987e 183 (+) Low-power Run mode: core and peripherals are running, regulator in low power mode.
mbed_official 610:813dcc80987e 184 (+) Sleep mode: Cortex-M4 core stopped, peripherals kept running, regulator in normal mode.
mbed_official 610:813dcc80987e 185 (+) Low-power Sleep mode: Cortex-M4 core stopped, peripherals kept running, regulator in low power mode.
mbed_official 610:813dcc80987e 186 (+) Stop 1 mode: all clocks are stopped except LSI and LSE, regulator in normal or low power mode.
mbed_official 610:813dcc80987e 187 (+) Stop 2 mode: all clocks are stopped except LSI and LSE, regulator in low power mode, reduced set of waking up IPs compared to Stop 1 mode.
mbed_official 610:813dcc80987e 188 (+) Standby mode with SRAM2: all clocks are stopped except LSI and LSE, SRAM2 content preserved, regulator in low power mode.
mbed_official 610:813dcc80987e 189 (+) Standby mode without SRAM2: all clocks are stopped except LSI and LSE, regulator off.
mbed_official 610:813dcc80987e 190 (+) Shutdown mode: all clocks are stopped except LSE, regulator off.
mbed_official 610:813dcc80987e 191
mbed_official 610:813dcc80987e 192
mbed_official 610:813dcc80987e 193 *** Low-power run mode ***
mbed_official 610:813dcc80987e 194 ==========================
mbed_official 610:813dcc80987e 195 [..]
mbed_official 610:813dcc80987e 196 (+) Entry: (from main run mode)
mbed_official 610:813dcc80987e 197 (++) set LPR bit with HAL_PWREx_EnableLowPowerRunMode() API after having decreased the system clock below 2 MHz.
mbed_official 610:813dcc80987e 198
mbed_official 610:813dcc80987e 199 (+) Exit:
mbed_official 610:813dcc80987e 200 (++) clear LPR bit then wait for REGLP bit to be reset with HAL_PWREx_DisableLowPowerRunMode() API. Only
mbed_official 610:813dcc80987e 201 then can the system clock frequency be increased above 2 MHz.
mbed_official 610:813dcc80987e 202
mbed_official 610:813dcc80987e 203
mbed_official 610:813dcc80987e 204 *** Sleep mode / Low-power sleep mode ***
mbed_official 610:813dcc80987e 205 =========================================
mbed_official 610:813dcc80987e 206 [..]
mbed_official 610:813dcc80987e 207 (+) Entry:
mbed_official 610:813dcc80987e 208 The Sleep mode / Low-power Sleep mode is entered thru HAL_PWR_EnterSLEEPMode() API
mbed_official 610:813dcc80987e 209 in specifying whether or not the regulator is forced to low-power mode and if exit is interrupt or event-triggered.
mbed_official 610:813dcc80987e 210 (++) PWR_MAINREGULATOR_ON: Sleep mode (regulator in main mode).
mbed_official 610:813dcc80987e 211 (++) PWR_LOWPOWERREGULATOR_ON: Low-power sleep (regulator in low power mode).
mbed_official 610:813dcc80987e 212 In the latter case, the system clock frequency must have been decreased below 2 MHz beforehand.
mbed_official 610:813dcc80987e 213 (++) PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction
mbed_official 610:813dcc80987e 214 (++) PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction
mbed_official 610:813dcc80987e 215
mbed_official 610:813dcc80987e 216 (+) WFI Exit:
mbed_official 610:813dcc80987e 217 (++) Any peripheral interrupt acknowledged by the nested vectored interrupt
mbed_official 610:813dcc80987e 218 controller (NVIC) or any wake-up event.
mbed_official 610:813dcc80987e 219
mbed_official 610:813dcc80987e 220 (+) WFE Exit:
mbed_official 610:813dcc80987e 221 (++) Any wake-up event such as an EXTI line configured in event mode.
mbed_official 610:813dcc80987e 222
mbed_official 610:813dcc80987e 223 [..] When exiting the Low-power sleep mode by issuing an interrupt or a wakeup event,
mbed_official 610:813dcc80987e 224 the MCU is in Low-power Run mode.
mbed_official 610:813dcc80987e 225
mbed_official 610:813dcc80987e 226 *** Stop 1 and Stop 2 modes ***
mbed_official 610:813dcc80987e 227 ===============================
mbed_official 610:813dcc80987e 228 [..]
mbed_official 610:813dcc80987e 229 (+) Entry:
mbed_official 610:813dcc80987e 230 The Stop 1 or Stop 2 modes are entered thru the following API's:
mbed_official 610:813dcc80987e 231 (++) HAL_PWR_EnterSTOPMode() [for legacy porting reasons] or HAL_PWREx_EnterSTOP1Mode() for mode 1
mbed_official 610:813dcc80987e 232 (++) HAL_PWREx_EnterSTOP2Mode for mode 2.
mbed_official 610:813dcc80987e 233 (+) Regulator setting (applicable to Stop 1 mode only):
mbed_official 610:813dcc80987e 234 (++) PWR_MAINREGULATOR_ON
mbed_official 610:813dcc80987e 235 (++) PWR_LOWPOWERREGULATOR_ON
mbed_official 610:813dcc80987e 236 (+) Exit (interrupt or event-triggered, specified when entering STOP mode):
mbed_official 610:813dcc80987e 237 (++) PWR_STOPENTRY_WFI: enter Stop mode with WFI instruction
mbed_official 610:813dcc80987e 238 (++) PWR_STOPENTRY_WFE: enter Stop mode with WFE instruction
mbed_official 610:813dcc80987e 239
mbed_official 610:813dcc80987e 240 (+) WFI Exit:
mbed_official 610:813dcc80987e 241 (++) Any EXTI Line (Internal or External) configured in Interrupt mode.
mbed_official 610:813dcc80987e 242 (++) Some specific communication peripherals (USART, LPUART, I2C) interrupts
mbed_official 610:813dcc80987e 243 when programmed in wakeup mode.
mbed_official 610:813dcc80987e 244 (+) WFE Exit:
mbed_official 610:813dcc80987e 245 (++) Any EXTI Line (Internal or External) configured in Event mode.
mbed_official 610:813dcc80987e 246
mbed_official 610:813dcc80987e 247 [..]
mbed_official 610:813dcc80987e 248 When exiting Stop 1 mode, the MCU is either in Run mode or in Low-power Run mode
mbed_official 610:813dcc80987e 249 depending on the LPR bit setting.
mbed_official 610:813dcc80987e 250 When exiting Stop 2 mode, the MCU is in Run mode.
mbed_official 610:813dcc80987e 251
mbed_official 610:813dcc80987e 252 *** Standby mode ***
mbed_official 610:813dcc80987e 253 ====================
mbed_official 610:813dcc80987e 254 [..]
mbed_official 610:813dcc80987e 255 The Standby mode offers two options:
mbed_official 610:813dcc80987e 256 (+) option a) all clocks off except LSI and LSE, RRS bit set (keeps voltage regulator in low power mode).
mbed_official 610:813dcc80987e 257 SRAM and registers contents are lost except for the SRAM2 content, the RTC registers, RTC backup registers
mbed_official 610:813dcc80987e 258 and Standby circuitry.
mbed_official 610:813dcc80987e 259 (+) option b) all clocks off except LSI and LSE, RRS bit cleared (voltage regulator then disabled).
mbed_official 610:813dcc80987e 260 SRAM and register contents are lost except for the RTC registers, RTC backup registers
mbed_official 610:813dcc80987e 261 and Standby circuitry.
mbed_official 610:813dcc80987e 262
mbed_official 610:813dcc80987e 263 (++) Entry:
mbed_official 610:813dcc80987e 264 (+++) The Standby mode is entered thru HAL_PWR_EnterSTANDBYMode() API.
mbed_official 610:813dcc80987e 265 SRAM1 and register contents are lost except for registers in the Backup domain and
mbed_official 610:813dcc80987e 266 Standby circuitry. SRAM2 content can be preserved if the bit RRS is set in PWR_CR3 register.
mbed_official 610:813dcc80987e 267 To enable this feature, the user can resort to HAL_PWREx_EnableSRAM2ContentRetention() API
mbed_official 610:813dcc80987e 268 to set RRS bit.
mbed_official 610:813dcc80987e 269
mbed_official 610:813dcc80987e 270 (++) Exit:
mbed_official 610:813dcc80987e 271 (+++) WKUP pin rising edge, RTC alarm or wakeup, tamper event, time-stamp event,
mbed_official 610:813dcc80987e 272 external reset in NRST pin, IWDG reset.
mbed_official 610:813dcc80987e 273
mbed_official 610:813dcc80987e 274 [..] After waking up from Standby mode, program execution restarts in the same way as after a Reset.
mbed_official 610:813dcc80987e 275
mbed_official 610:813dcc80987e 276
mbed_official 610:813dcc80987e 277 *** Shutdown mode ***
mbed_official 610:813dcc80987e 278 ======================
mbed_official 610:813dcc80987e 279 [..]
mbed_official 610:813dcc80987e 280 In Shutdown mode,
mbed_official 610:813dcc80987e 281 voltage regulator is disabled, all clocks are off except LSE, RRS bit is cleared.
mbed_official 610:813dcc80987e 282 SRAM and registers contents are lost except for backup domain registers.
mbed_official 610:813dcc80987e 283
mbed_official 610:813dcc80987e 284 (+) Entry:
mbed_official 610:813dcc80987e 285 The Shutdown mode is entered thru HAL_PWREx_EnterSHUTDOWNMode() API.
mbed_official 610:813dcc80987e 286
mbed_official 610:813dcc80987e 287 (+) Exit:
mbed_official 610:813dcc80987e 288 (++) WKUP pin rising edge, RTC alarm or wakeup, tamper event, time-stamp event,
mbed_official 610:813dcc80987e 289 external reset in NRST pin.
mbed_official 610:813dcc80987e 290
mbed_official 610:813dcc80987e 291 [..] After waking up from Shutdown mode, program execution restarts in the same way as after a Reset.
mbed_official 610:813dcc80987e 292
mbed_official 610:813dcc80987e 293
mbed_official 610:813dcc80987e 294 *** Auto-wakeup (AWU) from low-power mode ***
mbed_official 610:813dcc80987e 295 =============================================
mbed_official 610:813dcc80987e 296 [..]
mbed_official 610:813dcc80987e 297 The MCU can be woken up from low-power mode by an RTC Alarm event, an RTC
mbed_official 610:813dcc80987e 298 Wakeup event, a tamper event or a time-stamp event, without depending on
mbed_official 610:813dcc80987e 299 an external interrupt (Auto-wakeup mode).
mbed_official 610:813dcc80987e 300
mbed_official 610:813dcc80987e 301 (+) RTC auto-wakeup (AWU) from the Stop, Standby and Shutdown modes
mbed_official 610:813dcc80987e 302
mbed_official 610:813dcc80987e 303
mbed_official 610:813dcc80987e 304 (++) To wake up from the Stop mode with an RTC alarm event, it is necessary to
mbed_official 610:813dcc80987e 305 configure the RTC to generate the RTC alarm using the HAL_RTC_SetAlarm_IT() function.
mbed_official 610:813dcc80987e 306
mbed_official 610:813dcc80987e 307 (++) To wake up from the Stop mode with an RTC Tamper or time stamp event, it
mbed_official 610:813dcc80987e 308 is necessary to configure the RTC to detect the tamper or time stamp event using the
mbed_official 610:813dcc80987e 309 HAL_RTCEx_SetTimeStamp_IT() or HAL_RTCEx_SetTamper_IT() functions.
mbed_official 610:813dcc80987e 310
mbed_official 610:813dcc80987e 311 (++) To wake up from the Stop mode with an RTC WakeUp event, it is necessary to
mbed_official 610:813dcc80987e 312 configure the RTC to generate the RTC WakeUp event using the HAL_RTCEx_SetWakeUpTimer_IT() function.
mbed_official 610:813dcc80987e 313
mbed_official 610:813dcc80987e 314 @endverbatim
mbed_official 610:813dcc80987e 315 * @{
mbed_official 610:813dcc80987e 316 */
mbed_official 610:813dcc80987e 317
mbed_official 610:813dcc80987e 318
mbed_official 610:813dcc80987e 319
mbed_official 610:813dcc80987e 320 /**
mbed_official 610:813dcc80987e 321 * @brief Configure the voltage threshold detected by the Power Voltage Detector (PVD).
mbed_official 610:813dcc80987e 322 * @param sConfigPVD: pointer to a PWR_PVDTypeDef structure that contains the PVD
mbed_official 610:813dcc80987e 323 * configuration information.
mbed_official 610:813dcc80987e 324 * @note Refer to the electrical characteristics of your device datasheet for
mbed_official 610:813dcc80987e 325 * more details about the voltage thresholds corresponding to each
mbed_official 610:813dcc80987e 326 * detection level.
mbed_official 610:813dcc80987e 327 * @retval None
mbed_official 610:813dcc80987e 328 */
mbed_official 610:813dcc80987e 329 HAL_StatusTypeDef HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD)
mbed_official 610:813dcc80987e 330 {
mbed_official 610:813dcc80987e 331 /* Check the parameters */
mbed_official 610:813dcc80987e 332 assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel));
mbed_official 610:813dcc80987e 333 assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode));
mbed_official 610:813dcc80987e 334
mbed_official 610:813dcc80987e 335 /* Set PLS bits according to PVDLevel value */
mbed_official 610:813dcc80987e 336 MODIFY_REG(PWR->CR2, PWR_CR2_PLS, sConfigPVD->PVDLevel);
mbed_official 610:813dcc80987e 337
mbed_official 610:813dcc80987e 338 /* Clear any previous config. Keep it clear if no event or IT mode is selected */
mbed_official 610:813dcc80987e 339 __HAL_PWR_PVD_EXTI_DISABLE_EVENT();
mbed_official 610:813dcc80987e 340 __HAL_PWR_PVD_EXTI_DISABLE_IT();
mbed_official 610:813dcc80987e 341 __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE();
mbed_official 610:813dcc80987e 342 __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();
mbed_official 610:813dcc80987e 343
mbed_official 610:813dcc80987e 344 /* Configure interrupt mode */
mbed_official 610:813dcc80987e 345 if((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT)
mbed_official 610:813dcc80987e 346 {
mbed_official 610:813dcc80987e 347 __HAL_PWR_PVD_EXTI_ENABLE_IT();
mbed_official 610:813dcc80987e 348 }
mbed_official 610:813dcc80987e 349
mbed_official 610:813dcc80987e 350 /* Configure event mode */
mbed_official 610:813dcc80987e 351 if((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT)
mbed_official 610:813dcc80987e 352 {
mbed_official 610:813dcc80987e 353 __HAL_PWR_PVD_EXTI_ENABLE_EVENT();
mbed_official 610:813dcc80987e 354 }
mbed_official 610:813dcc80987e 355
mbed_official 610:813dcc80987e 356 /* Configure the edge */
mbed_official 610:813dcc80987e 357 if((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE)
mbed_official 610:813dcc80987e 358 {
mbed_official 610:813dcc80987e 359 __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();
mbed_official 610:813dcc80987e 360 }
mbed_official 610:813dcc80987e 361
mbed_official 610:813dcc80987e 362 if((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE)
mbed_official 610:813dcc80987e 363 {
mbed_official 610:813dcc80987e 364 __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();
mbed_official 610:813dcc80987e 365 }
mbed_official 610:813dcc80987e 366
mbed_official 610:813dcc80987e 367 return HAL_OK;
mbed_official 610:813dcc80987e 368 }
mbed_official 610:813dcc80987e 369
mbed_official 610:813dcc80987e 370
mbed_official 610:813dcc80987e 371 /**
mbed_official 610:813dcc80987e 372 * @brief Enable the Power Voltage Detector (PVD).
mbed_official 610:813dcc80987e 373 * @retval None
mbed_official 610:813dcc80987e 374 */
mbed_official 610:813dcc80987e 375 void HAL_PWR_EnablePVD(void)
mbed_official 610:813dcc80987e 376 {
mbed_official 610:813dcc80987e 377 SET_BIT(PWR->CR2, PWR_CR2_PVDE);
mbed_official 610:813dcc80987e 378 }
mbed_official 610:813dcc80987e 379
mbed_official 610:813dcc80987e 380 /**
mbed_official 610:813dcc80987e 381 * @brief Disable the Power Voltage Detector (PVD).
mbed_official 610:813dcc80987e 382 * @retval None
mbed_official 610:813dcc80987e 383 */
mbed_official 610:813dcc80987e 384 void HAL_PWR_DisablePVD(void)
mbed_official 610:813dcc80987e 385 {
mbed_official 610:813dcc80987e 386 CLEAR_BIT(PWR->CR2, PWR_CR2_PVDE);
mbed_official 610:813dcc80987e 387 }
mbed_official 610:813dcc80987e 388
mbed_official 610:813dcc80987e 389
mbed_official 610:813dcc80987e 390
mbed_official 610:813dcc80987e 391
mbed_official 610:813dcc80987e 392 /**
mbed_official 610:813dcc80987e 393 * @brief Enable the WakeUp PINx functionality.
mbed_official 610:813dcc80987e 394 * @param WakeUpPinPolarity: Specifies which Wake-Up pin to enable.
mbed_official 610:813dcc80987e 395 * This parameter can be one of the following legacy values which set the default polarity
mbed_official 610:813dcc80987e 396 * i.e. detection on high level (rising edge):
mbed_official 610:813dcc80987e 397 * @arg PWR_WAKEUP_PIN1, PWR_WAKEUP_PIN2, PWR_WAKEUP_PIN3, PWR_WAKEUP_PIN4, PWR_WAKEUP_PIN5
mbed_official 610:813dcc80987e 398 *
mbed_official 610:813dcc80987e 399 * or one of the following value where the user can explicitly specify the enabled pin and
mbed_official 610:813dcc80987e 400 * the chosen polarity:
mbed_official 610:813dcc80987e 401 * @arg PWR_WAKEUP_PIN1_HIGH or PWR_WAKEUP_PIN1_LOW
mbed_official 610:813dcc80987e 402 * @arg PWR_WAKEUP_PIN2_HIGH or PWR_WAKEUP_PIN2_LOW
mbed_official 610:813dcc80987e 403 * @arg PWR_WAKEUP_PIN3_HIGH or PWR_WAKEUP_PIN3_LOW
mbed_official 610:813dcc80987e 404 * @arg PWR_WAKEUP_PIN4_HIGH or PWR_WAKEUP_PIN4_LOW
mbed_official 610:813dcc80987e 405 * @arg PWR_WAKEUP_PIN5_HIGH or PWR_WAKEUP_PIN5_LOW
mbed_official 610:813dcc80987e 406 * @note PWR_WAKEUP_PINx and PWR_WAKEUP_PINx_HIGH are equivalent.
mbed_official 610:813dcc80987e 407 * @retval None
mbed_official 610:813dcc80987e 408 */
mbed_official 610:813dcc80987e 409 void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity)
mbed_official 610:813dcc80987e 410 {
mbed_official 610:813dcc80987e 411 assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinPolarity));
mbed_official 610:813dcc80987e 412
mbed_official 610:813dcc80987e 413 /* Specifies the Wake-Up pin polarity for the event detection
mbed_official 610:813dcc80987e 414 (rising or falling edge) */
mbed_official 610:813dcc80987e 415 MODIFY_REG(PWR->CR4, (PWR_CR3_EWUP & WakeUpPinPolarity), (WakeUpPinPolarity >> PWR_WUP_POLARITY_SHIFT));
mbed_official 610:813dcc80987e 416
mbed_official 610:813dcc80987e 417 /* Enable wake-up pin */
mbed_official 610:813dcc80987e 418 SET_BIT(PWR->CR3, (PWR_CR3_EWUP & WakeUpPinPolarity));
mbed_official 610:813dcc80987e 419
mbed_official 610:813dcc80987e 420
mbed_official 610:813dcc80987e 421 }
mbed_official 610:813dcc80987e 422
mbed_official 610:813dcc80987e 423 /**
mbed_official 610:813dcc80987e 424 * @brief Disable the WakeUp PINx functionality.
mbed_official 610:813dcc80987e 425 * @param WakeUpPinx: Specifies the Power Wake-Up pin to disable.
mbed_official 610:813dcc80987e 426 * This parameter can be one of the following values:
mbed_official 610:813dcc80987e 427 * @arg PWR_WAKEUP_PIN1, PWR_WAKEUP_PIN2, PWR_WAKEUP_PIN3, PWR_WAKEUP_PIN4, PWR_WAKEUP_PIN5
mbed_official 610:813dcc80987e 428 * @retval None
mbed_official 610:813dcc80987e 429 */
mbed_official 610:813dcc80987e 430 void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx)
mbed_official 610:813dcc80987e 431 {
mbed_official 610:813dcc80987e 432 assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
mbed_official 610:813dcc80987e 433
mbed_official 610:813dcc80987e 434 CLEAR_BIT(PWR->CR3, WakeUpPinx);
mbed_official 610:813dcc80987e 435 }
mbed_official 610:813dcc80987e 436
mbed_official 610:813dcc80987e 437
mbed_official 610:813dcc80987e 438 /**
mbed_official 610:813dcc80987e 439 * @brief Enter Sleep or Low-power Sleep mode.
mbed_official 610:813dcc80987e 440 * @note In Sleep/Low-power Sleep mode, all I/O pins keep the same state as in Run mode.
mbed_official 610:813dcc80987e 441 * @param Regulator: Specifies the regulator state in Sleep/Low-power Sleep mode.
mbed_official 610:813dcc80987e 442 * This parameter can be one of the following values:
mbed_official 610:813dcc80987e 443 * @arg PWR_MAINREGULATOR_ON: Sleep mode (regulator in main mode)
mbed_official 610:813dcc80987e 444 * @arg PWR_LOWPOWERREGULATOR_ON: Low-power Sleep mode (regulator in low-power mode)
mbed_official 610:813dcc80987e 445 * @note Low-power Sleep mode is entered from Low-power Run mode. Therefore, if not yet
mbed_official 610:813dcc80987e 446 * in Low-power Run mode before calling HAL_PWR_EnterSLEEPMode() with Regulator set
mbed_official 610:813dcc80987e 447 * to PWR_LOWPOWERREGULATOR_ON, the user can optionally configure the
mbed_official 610:813dcc80987e 448 * Flash in power-down monde in setting the SLEEP_PD bit in FLASH_ACR register.
mbed_official 610:813dcc80987e 449 * Additionally, the clock frequency must be reduced below 2 MHz.
mbed_official 610:813dcc80987e 450 * Setting SLEEP_PD in FLASH_ACR then appropriately reducing the clock frequency must
mbed_official 610:813dcc80987e 451 * be done before calling HAL_PWR_EnterSLEEPMode() API.
mbed_official 610:813dcc80987e 452 * @note When exiting Low-power Sleep mode, the MCU is in Low-power Run mode. To move in
mbed_official 610:813dcc80987e 453 * Run mode, the user must resort to HAL_PWREx_DisableLowPowerRunMode() API.
mbed_official 610:813dcc80987e 454 * @param SLEEPEntry: Specifies if Sleep mode is entered with WFI or WFE instruction.
mbed_official 610:813dcc80987e 455 * This parameter can be one of the following values:
mbed_official 610:813dcc80987e 456 * @arg PWR_SLEEPENTRY_WFI: enter Sleep or Low-power Sleep mode with WFI instruction
mbed_official 610:813dcc80987e 457 * @arg PWR_SLEEPENTRY_WFE: enter Sleep or Low-power Sleep mode with WFE instruction
mbed_official 610:813dcc80987e 458 * @note When WFI entry is used, tick interrupt have to be disabled if not desired as
mbed_official 610:813dcc80987e 459 * the interrupt wake up source.
mbed_official 610:813dcc80987e 460 * @retval None
mbed_official 610:813dcc80987e 461 */
mbed_official 610:813dcc80987e 462 void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)
mbed_official 610:813dcc80987e 463 {
mbed_official 610:813dcc80987e 464 /* Check the parameters */
mbed_official 610:813dcc80987e 465 assert_param(IS_PWR_REGULATOR(Regulator));
mbed_official 610:813dcc80987e 466 assert_param(IS_PWR_SLEEP_ENTRY(SLEEPEntry));
mbed_official 610:813dcc80987e 467
mbed_official 610:813dcc80987e 468 /* Set Regulator parameter */
mbed_official 610:813dcc80987e 469 if (Regulator == PWR_MAINREGULATOR_ON)
mbed_official 610:813dcc80987e 470 {
mbed_official 610:813dcc80987e 471 /* If in low-power run mode at this point, exit it */
mbed_official 610:813dcc80987e 472 if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_REGLPF))
mbed_official 610:813dcc80987e 473 {
mbed_official 610:813dcc80987e 474 HAL_PWREx_DisableLowPowerRunMode();
mbed_official 610:813dcc80987e 475 }
mbed_official 610:813dcc80987e 476 /* Regulator now in main mode. */
mbed_official 610:813dcc80987e 477 }
mbed_official 610:813dcc80987e 478 else
mbed_official 610:813dcc80987e 479 {
mbed_official 610:813dcc80987e 480 /* If in run mode, first move to low-power run mode.
mbed_official 610:813dcc80987e 481 The system clock frequency must be below 2 MHz at this point. */
mbed_official 610:813dcc80987e 482 if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_REGLPF) == RESET)
mbed_official 610:813dcc80987e 483 {
mbed_official 610:813dcc80987e 484 HAL_PWREx_EnableLowPowerRunMode();
mbed_official 610:813dcc80987e 485 }
mbed_official 610:813dcc80987e 486 }
mbed_official 610:813dcc80987e 487
mbed_official 610:813dcc80987e 488 /* Clear SLEEPDEEP bit of Cortex System Control Register */
mbed_official 610:813dcc80987e 489 CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
mbed_official 610:813dcc80987e 490
mbed_official 610:813dcc80987e 491 /* Select SLEEP mode entry -------------------------------------------------*/
mbed_official 610:813dcc80987e 492 if(SLEEPEntry == PWR_SLEEPENTRY_WFI)
mbed_official 610:813dcc80987e 493 {
mbed_official 610:813dcc80987e 494 /* Request Wait For Interrupt */
mbed_official 610:813dcc80987e 495 __WFI();
mbed_official 610:813dcc80987e 496 }
mbed_official 610:813dcc80987e 497 else
mbed_official 610:813dcc80987e 498 {
mbed_official 610:813dcc80987e 499 /* Request Wait For Event */
mbed_official 610:813dcc80987e 500 __SEV();
mbed_official 610:813dcc80987e 501 __WFE();
mbed_official 610:813dcc80987e 502 __WFE();
mbed_official 610:813dcc80987e 503 }
mbed_official 610:813dcc80987e 504
mbed_official 610:813dcc80987e 505 }
mbed_official 610:813dcc80987e 506
mbed_official 610:813dcc80987e 507
mbed_official 610:813dcc80987e 508 /**
mbed_official 610:813dcc80987e 509 * @brief Enter Stop 1 mode
mbed_official 610:813dcc80987e 510 * @note This API is named HAL_PWR_EnterSTOPMode to ensure compatibility with legacy code running
mbed_official 610:813dcc80987e 511 * on devices where only "Stop mode" is mentioned. On STM32L4, Stop 1 mode and Stop modes
mbed_official 610:813dcc80987e 512 * are equivalent.
mbed_official 610:813dcc80987e 513 * @note In Stop 1 mode, all I/O pins keep the same state as in Run mode.
mbed_official 610:813dcc80987e 514 * @note All clocks in the VCORE domain are stopped; the PLL, the MSI,
mbed_official 610:813dcc80987e 515 * the HSI and the HSE oscillators are disabled. Some peripherals with the wakeup capability
mbed_official 610:813dcc80987e 516 * (I2Cx, USARTx and LPUART) can switch on the HSI to receive a frame, and switch off the HSI
mbed_official 610:813dcc80987e 517 * after receiving the frame if it is not a wakeup frame. In this case, the HSI clock is propagated
mbed_official 610:813dcc80987e 518 * only to the peripheral requesting it.
mbed_official 610:813dcc80987e 519 * SRAM1, SRAM2 and register contents are preserved.
mbed_official 610:813dcc80987e 520 * The BOR is available.
mbed_official 610:813dcc80987e 521 * The voltage regulator can be configured either in normal or low-power mode.
mbed_official 610:813dcc80987e 522 * @note When exiting Stop 1 mode by issuing an interrupt or a wakeup event,
mbed_official 610:813dcc80987e 523 * the HSI RC oscillator is selected as system clock if STOPWUCK bit in RCC_CFGR register
mbed_official 610:813dcc80987e 524 * is set; the MSI oscillator is selected if STOPWUCK is cleared.
mbed_official 610:813dcc80987e 525 * @note When the voltage regulator operates in low power mode, an additional
mbed_official 610:813dcc80987e 526 * startup delay is incurred when waking up from Stop 1 mode.
mbed_official 610:813dcc80987e 527 * By keeping the internal regulator ON during Stop 1 mode, the consumption
mbed_official 610:813dcc80987e 528 * is higher although the startup time is reduced.
mbed_official 610:813dcc80987e 529 * @param Regulator: Specifies the regulator state in Stop 1 mode.
mbed_official 610:813dcc80987e 530 * This parameter can be one of the following values:
mbed_official 610:813dcc80987e 531 * @arg PWR_MAINREGULATOR_ON: Stop 1 mode with regulator ON
mbed_official 610:813dcc80987e 532 * @arg PWR_LOWPOWERREGULATOR_ON: Stop 1 mode with low power regulator ON
mbed_official 610:813dcc80987e 533 * @param STOPEntry: Specifies if Stop 1 mode in entered with WFI or WFE instruction.
mbed_official 610:813dcc80987e 534 * This parameter can be one of the following values:
mbed_official 610:813dcc80987e 535 * @arg PWR_STOPENTRY_WFI:Enter Stop 1 mode with WFI instruction
mbed_official 610:813dcc80987e 536 * @arg PWR_STOPENTRY_WFE: Enter Stop 1 mode with WFE instruction
mbed_official 610:813dcc80987e 537 * @retval None
mbed_official 610:813dcc80987e 538 */
mbed_official 610:813dcc80987e 539 void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
mbed_official 610:813dcc80987e 540 {
mbed_official 610:813dcc80987e 541 HAL_PWREx_EnterSTOP1Mode(Regulator, STOPEntry);
mbed_official 610:813dcc80987e 542 }
mbed_official 610:813dcc80987e 543
mbed_official 610:813dcc80987e 544 /**
mbed_official 610:813dcc80987e 545 * @brief Enter Standby mode.
mbed_official 610:813dcc80987e 546 * @note In Standby mode, the PLL, the HSI, the MSI and the HSE oscillators are switched
mbed_official 610:813dcc80987e 547 * off. The voltage regulator is disabled, except when SRAM2 content is preserved
mbed_official 610:813dcc80987e 548 * in which case the regulator is in low-power mode.
mbed_official 610:813dcc80987e 549 * SRAM1 and register contents are lost except for registers in the Backup domain and
mbed_official 610:813dcc80987e 550 * Standby circuitry. SRAM2 content can be preserved if the bit RRS is set in PWR_CR3 register.
mbed_official 610:813dcc80987e 551 * To enable this feature, the user can resort to HAL_PWREx_EnableSRAM2ContentRetention() API
mbed_official 610:813dcc80987e 552 * to set RRS bit.
mbed_official 610:813dcc80987e 553 * The BOR is available.
mbed_official 610:813dcc80987e 554 * @note The I/Os can be configured either with a pull-up or pull-down or can be kept in analog state.
mbed_official 610:813dcc80987e 555 * HAL_PWREx_EnableGPIOPullUp() and HAL_PWREx_EnableGPIOPullDown() respectively enable Pull Up and
mbed_official 610:813dcc80987e 556 * Pull Down state, HAL_PWREx_DisableGPIOPullUp() and HAL_PWREx_DisableGPIOPullDown() disable the
mbed_official 610:813dcc80987e 557 * same.
mbed_official 610:813dcc80987e 558 * These states are effective in Standby mode only if APC bit is set through
mbed_official 610:813dcc80987e 559 * HAL_PWREx_EnablePullUpPullDownConfig() API.
mbed_official 610:813dcc80987e 560 * @retval None
mbed_official 610:813dcc80987e 561 */
mbed_official 610:813dcc80987e 562 void HAL_PWR_EnterSTANDBYMode(void)
mbed_official 610:813dcc80987e 563 {
mbed_official 610:813dcc80987e 564 /* Set Stand-by mode */
mbed_official 610:813dcc80987e 565 MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_STANDBY);
mbed_official 610:813dcc80987e 566
mbed_official 610:813dcc80987e 567 /* Set SLEEPDEEP bit of Cortex System Control Register */
mbed_official 610:813dcc80987e 568 SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
mbed_official 610:813dcc80987e 569
mbed_official 610:813dcc80987e 570 /* This option is used to ensure that store operations are completed */
mbed_official 610:813dcc80987e 571 #if defined ( __CC_ARM)
mbed_official 610:813dcc80987e 572 __force_stores();
mbed_official 610:813dcc80987e 573 #endif
mbed_official 610:813dcc80987e 574 /* Request Wait For Interrupt */
mbed_official 610:813dcc80987e 575 __WFI();
mbed_official 610:813dcc80987e 576 }
mbed_official 610:813dcc80987e 577
mbed_official 610:813dcc80987e 578
mbed_official 610:813dcc80987e 579
mbed_official 610:813dcc80987e 580 /**
mbed_official 610:813dcc80987e 581 * @brief Indicate Sleep-On-Exit when returning from Handler mode to Thread mode.
mbed_official 610:813dcc80987e 582 * @note Set SLEEPONEXIT bit of SCR register. When this bit is set, the processor
mbed_official 610:813dcc80987e 583 * re-enters SLEEP mode when an interruption handling is over.
mbed_official 610:813dcc80987e 584 * Setting this bit is useful when the processor is expected to run only on
mbed_official 610:813dcc80987e 585 * interruptions handling.
mbed_official 610:813dcc80987e 586 * @retval None
mbed_official 610:813dcc80987e 587 */
mbed_official 610:813dcc80987e 588 void HAL_PWR_EnableSleepOnExit(void)
mbed_official 610:813dcc80987e 589 {
mbed_official 610:813dcc80987e 590 /* Set SLEEPONEXIT bit of Cortex System Control Register */
mbed_official 610:813dcc80987e 591 SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
mbed_official 610:813dcc80987e 592 }
mbed_official 610:813dcc80987e 593
mbed_official 610:813dcc80987e 594
mbed_official 610:813dcc80987e 595 /**
mbed_official 610:813dcc80987e 596 * @brief Disable Sleep-On-Exit feature when returning from Handler mode to Thread mode.
mbed_official 610:813dcc80987e 597 * @note Clear SLEEPONEXIT bit of SCR register. When this bit is set, the processor
mbed_official 610:813dcc80987e 598 * re-enters SLEEP mode when an interruption handling is over.
mbed_official 610:813dcc80987e 599 * @retval None
mbed_official 610:813dcc80987e 600 */
mbed_official 610:813dcc80987e 601 void HAL_PWR_DisableSleepOnExit(void)
mbed_official 610:813dcc80987e 602 {
mbed_official 610:813dcc80987e 603 /* Clear SLEEPONEXIT bit of Cortex System Control Register */
mbed_official 610:813dcc80987e 604 CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
mbed_official 610:813dcc80987e 605 }
mbed_official 610:813dcc80987e 606
mbed_official 610:813dcc80987e 607
mbed_official 610:813dcc80987e 608
mbed_official 610:813dcc80987e 609 /**
mbed_official 610:813dcc80987e 610 * @brief Enable CORTEX M4 SEVONPEND bit.
mbed_official 610:813dcc80987e 611 * @note Set SEVONPEND bit of SCR register. When this bit is set, this causes
mbed_official 610:813dcc80987e 612 * WFE to wake up when an interrupt moves from inactive to pended.
mbed_official 610:813dcc80987e 613 * @retval None
mbed_official 610:813dcc80987e 614 */
mbed_official 610:813dcc80987e 615 void HAL_PWR_EnableSEVOnPend(void)
mbed_official 610:813dcc80987e 616 {
mbed_official 610:813dcc80987e 617 /* Set SEVONPEND bit of Cortex System Control Register */
mbed_official 610:813dcc80987e 618 SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
mbed_official 610:813dcc80987e 619 }
mbed_official 610:813dcc80987e 620
mbed_official 610:813dcc80987e 621
mbed_official 610:813dcc80987e 622 /**
mbed_official 610:813dcc80987e 623 * @brief Disable CORTEX M4 SEVONPEND bit.
mbed_official 610:813dcc80987e 624 * @note Clear SEVONPEND bit of SCR register. When this bit is set, this causes
mbed_official 610:813dcc80987e 625 * WFE to wake up when an interrupt moves from inactive to pended.
mbed_official 610:813dcc80987e 626 * @retval None
mbed_official 610:813dcc80987e 627 */
mbed_official 610:813dcc80987e 628 void HAL_PWR_DisableSEVOnPend(void)
mbed_official 610:813dcc80987e 629 {
mbed_official 610:813dcc80987e 630 /* Clear SEVONPEND bit of Cortex System Control Register */
mbed_official 610:813dcc80987e 631 CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
mbed_official 610:813dcc80987e 632 }
mbed_official 610:813dcc80987e 633
mbed_official 610:813dcc80987e 634
mbed_official 610:813dcc80987e 635
mbed_official 610:813dcc80987e 636
mbed_official 610:813dcc80987e 637
mbed_official 610:813dcc80987e 638 /**
mbed_official 610:813dcc80987e 639 * @brief PWR PVD interrupt callback
mbed_official 610:813dcc80987e 640 * @retval None
mbed_official 610:813dcc80987e 641 */
mbed_official 610:813dcc80987e 642 __weak void HAL_PWR_PVDCallback(void)
mbed_official 610:813dcc80987e 643 {
mbed_official 610:813dcc80987e 644 /* NOTE : This function should not be modified; when the callback is needed,
mbed_official 610:813dcc80987e 645 the HAL_PWR_PVDCallback can be implemented in the user file
mbed_official 610:813dcc80987e 646 */
mbed_official 610:813dcc80987e 647 }
mbed_official 610:813dcc80987e 648
mbed_official 610:813dcc80987e 649 /**
mbed_official 610:813dcc80987e 650 * @}
mbed_official 610:813dcc80987e 651 */
mbed_official 610:813dcc80987e 652
mbed_official 610:813dcc80987e 653 /**
mbed_official 610:813dcc80987e 654 * @}
mbed_official 610:813dcc80987e 655 */
mbed_official 610:813dcc80987e 656
mbed_official 610:813dcc80987e 657 #endif /* HAL_PWR_MODULE_ENABLED */
mbed_official 610:813dcc80987e 658 /**
mbed_official 610:813dcc80987e 659 * @}
mbed_official 610:813dcc80987e 660 */
mbed_official 610:813dcc80987e 661
mbed_official 610:813dcc80987e 662 /**
mbed_official 610:813dcc80987e 663 * @}
mbed_official 610:813dcc80987e 664 */
mbed_official 610:813dcc80987e 665
mbed_official 610:813dcc80987e 666 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/