STM32H735xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32h7xx_hal_pwr.c 00004 * @author MCD Application Team 00005 * @brief PWR HAL module driver. 00006 * This file provides firmware functions to manage the following 00007 * functionalities of the Power Controller (PWR) peripheral: 00008 * + Initialization and de-initialization functions. 00009 * + Peripheral Control functions. 00010 * + Interrupt Handling functions. 00011 ****************************************************************************** 00012 * @attention 00013 * 00014 * Copyright (c) 2017 STMicroelectronics. 00015 * All rights reserved. 00016 * 00017 * This software is licensed under terms that can be found in the LICENSE file 00018 * in the root directory of this software component. 00019 * If no LICENSE file comes with this software, it is provided AS-IS. 00020 * 00021 ****************************************************************************** 00022 @verbatim 00023 ============================================================================== 00024 ##### PWR peripheral overview ##### 00025 ============================================================================== 00026 [..] 00027 (#) The Power control (PWR) provides an overview of the supply architecture 00028 for the different power domains and of the supply configuration 00029 controller. 00030 In the H7 family, the number of power domains is different between 00031 device lines. This difference is due to characteristics of each device. 00032 00033 (#) Domain architecture overview for the different H7 lines: 00034 (+) Dual core lines are STM32H745, STM32H747, STM32H755 and STM32H757. 00035 These devices have 3 power domains (D1, D2 and D3). 00036 The domain D1 contains a CPU (Cortex-M7), a Flash memory and some 00037 peripherals. The D2 domain contains peripherals and a CPU 00038 (Cortex-M4). The D3 domain contains the system control, I/O logic 00039 and low-power peripherals. 00040 (+) STM32H72x, STM32H73x, STM32H742, STM32H743, STM32H750 and STM32H753 00041 devices have 3 power domains (D1, D2 and D3). 00042 The domain D1 contains a CPU (Cortex-M7), a Flash memory and some 00043 peripherals. The D2 domain contains peripherals. The D3 domains 00044 contains the system control, I/O logic and low-power peripherals. 00045 (+) STM32H7Axxx and STM32H7Bxxx devices have 2 power domains (CD and SRD). 00046 The core domain (CD) contains a CPU (Cortex-M7), a Flash 00047 memory and peripherals. The SmartRun domain contains the system 00048 control, I/O logic and low-power peripherals. 00049 00050 (#) Every entity have low power mode as described below : 00051 (#) The CPU low power modes are : 00052 (+) CPU CRUN. 00053 (+) CPU CSLEEP. 00054 (+) CPU CSTOP. 00055 (#) The domain low power modes are : 00056 (+) DRUN. 00057 (+) DSTOP. 00058 (+) DSTANDBY. 00059 (#) The SYSTEM low power modes are : 00060 (+) RUN* : The Run* mode is entered after a POR reset and a wakeup from 00061 Standby. In Run* mode, the performance is limited and the 00062 system supply configuration shall be programmed. The system 00063 enters Run mode only when the ACTVOSRDY bit in PWR control 00064 status register 1 (PWR_CSR1) is set to 1. 00065 (+) RUN. 00066 (+) STOP. 00067 (+) STANDBY. 00068 00069 ============================================================================== 00070 ##### How to use this driver ##### 00071 ============================================================================== 00072 [..] 00073 (#) Power management peripheral is active by default at startup level in 00074 STM32h7xx lines. 00075 00076 (#) Call HAL_PWR_EnableBkUpAccess() and HAL_PWR_DisableBkUpAccess() functions 00077 to enable/disable access to the backup domain (RTC registers, RTC backup 00078 data registers and backup SRAM). 00079 00080 (#) Call HAL_PWR_ConfigPVD() after setting parameters to be configured (event 00081 mode and voltage threshold) in order to set up the Power Voltage Detector, 00082 then use HAL_PWR_EnablePVD() and HAL_PWR_DisablePVD() functions to start 00083 and stop the PVD detection. 00084 (+) PVD level could be one of the following values : 00085 (++) 1V95 00086 (++) 2V1 00087 (++) 2V25 00088 (++) 2V4 00089 (++) 2V55 00090 (++) 2V7 00091 (++) 2V85 00092 (++) External voltage level 00093 00094 (#) Call HAL_PWR_EnableWakeUpPin() and HAL_PWR_DisableWakeUpPin() functions 00095 with the right parameter to configure the wake up pin polarity (Low or 00096 High) and to enable and disable it. 00097 00098 (#) Call HAL_PWR_EnterSLEEPMode() function to enter the current Core in SLEEP 00099 mode. Wake-up from SLEEP mode could be following to an event or an 00100 interrupt according to low power mode intrinsic request called (__WFI() 00101 or __WFE()). 00102 Please ensure to clear all CPU pending events by calling 00103 HAL_PWREx_ClearPendingEvent() function when trying to enter the Cortex-Mx 00104 in SLEEP mode with __WFE() entry. 00105 00106 (#) Call HAL_PWR_EnterSTOPMode() function to enter the whole system to Stop 0 00107 mode for single core devices. For dual core devices, this API will enter 00108 the domain (containing Cortex-Mx that executing this function) in DSTOP 00109 mode. According to the used parameter, user could select the regulator to 00110 be kept actif in low power mode and wake-up event type. 00111 Please ensure to clear all CPU pending events by calling 00112 HAL_PWREx_ClearPendingEvent() function when trying to enter the Cortex-Mx 00113 in CSTOP mode with __WFE() entry. 00114 00115 (#) Call HAL_PWR_EnterSTANDBYMode() function to enter the whole system in 00116 STANDBY mode for single core devices. For dual core devices, this API 00117 will enter the domain (containing Cortex-Mx that executing this function) 00118 in DSTANDBY mode. 00119 00120 (#) Call HAL_PWR_EnableSleepOnExit() and HAL_PWR_DisableSleepOnExit() APIs to 00121 enable and disable the Cortex-Mx re-entring in SLEEP mode after an 00122 interruption handling is over. 00123 00124 (#) Call HAL_PWR_EnableSEVOnPend() and HAL_PWR_DisableSEVOnPend() functions 00125 to configure the Cortex-Mx to wake-up after any pending event / interrupt 00126 even if it's disabled or has insufficient priority to cause exception 00127 entry. 00128 00129 (#) Call HAL_PWR_PVD_IRQHandler() function to handle the PWR PVD interrupt 00130 request. 00131 00132 *** PWR HAL driver macros list *** 00133 ============================================= 00134 [..] 00135 Below the list of most used macros in PWR HAL driver. 00136 00137 (+) __HAL_PWR_VOLTAGESCALING_CONFIG() : Configure the main internal 00138 regulator output voltage. 00139 (+) __HAL_PWR_GET_FLAG() : Get the PWR pending flags. 00140 (+) __HAL_PWR_CLEAR_FLAG() : Clear the PWR pending flags. 00141 00142 @endverbatim 00143 */ 00144 00145 /* Includes ------------------------------------------------------------------*/ 00146 #include "stm32h7xx_hal.h" 00147 00148 /** @addtogroup STM32H7xx_HAL_Driver 00149 * @{ 00150 */ 00151 00152 /** @defgroup PWR PWR 00153 * @brief PWR HAL module driver 00154 * @{ 00155 */ 00156 00157 #ifdef HAL_PWR_MODULE_ENABLED 00158 00159 /* Private typedef -----------------------------------------------------------*/ 00160 /* Private define ------------------------------------------------------------*/ 00161 00162 /** @addtogroup PWR_Private_Constants PWR Private Constants 00163 * @{ 00164 */ 00165 00166 /** @defgroup PWR_PVD_Mode_Mask PWR PVD Mode Mask 00167 * @{ 00168 */ 00169 #if !defined (DUAL_CORE) 00170 #define PVD_MODE_IT (0x00010000U) 00171 #define PVD_MODE_EVT (0x00020000U) 00172 #endif /* !defined (DUAL_CORE) */ 00173 00174 #define PVD_RISING_EDGE (0x00000001U) 00175 #define PVD_FALLING_EDGE (0x00000002U) 00176 #define PVD_RISING_FALLING_EDGE (0x00000003U) 00177 /** 00178 * @} 00179 */ 00180 00181 /** 00182 * @} 00183 */ 00184 00185 /* Private macro -------------------------------------------------------------*/ 00186 /* Private variables ---------------------------------------------------------*/ 00187 /* Private function prototypes -----------------------------------------------*/ 00188 /* Private functions ---------------------------------------------------------*/ 00189 00190 /** @defgroup PWR_Exported_Functions PWR Exported Functions 00191 * @{ 00192 */ 00193 00194 /** @defgroup PWR_Exported_Functions_Group1 Initialization and De-Initialization Functions 00195 * @brief Initialization and De-Initialization functions 00196 * 00197 @verbatim 00198 =============================================================================== 00199 ##### Initialization and De-Initialization Functions ##### 00200 =============================================================================== 00201 [..] 00202 This section provides functions allowing to deinitialize power peripheral. 00203 00204 [..] 00205 After system reset, the backup domain (RTC registers, RTC backup data 00206 registers and backup SRAM) is protected against possible unwanted write 00207 accesses. 00208 The HAL_PWR_EnableBkUpAccess() function enables the access to the backup 00209 domain. 00210 The HAL_PWR_DisableBkUpAccess() function disables the access to the backup 00211 domain. 00212 00213 @endverbatim 00214 * @{ 00215 */ 00216 00217 /** 00218 * @brief Deinitialize the HAL PWR peripheral registers to their default reset 00219 * values. 00220 * @note This functionality is not available in this product. 00221 * The prototype is kept just to maintain compatibility with other 00222 * products. 00223 * @retval None. 00224 */ 00225 void HAL_PWR_DeInit (void) 00226 { 00227 } 00228 00229 /** 00230 * @brief Enable access to the backup domain (RTC registers, RTC backup data 00231 * registers and backup SRAM). 00232 * @note If the HSE divided by 2, 3, ..31 is used as the RTC clock, the 00233 * Backup Domain Access should be kept enabled. 00234 * @retval None. 00235 */ 00236 void HAL_PWR_EnableBkUpAccess (void) 00237 { 00238 /* Enable access to RTC and backup registers */ 00239 SET_BIT (PWR->CR1, PWR_CR1_DBP); 00240 } 00241 00242 /** 00243 * @brief Disable access to the backup domain (RTC registers, RTC backup data 00244 * registers and backup SRAM). 00245 * @note If the HSE divided by 2, 3, ..31 is used as the RTC clock, the 00246 * Backup Domain Access should be kept enabled. 00247 * @retval None. 00248 */ 00249 void HAL_PWR_DisableBkUpAccess (void) 00250 { 00251 /* Disable access to RTC and backup registers */ 00252 CLEAR_BIT (PWR->CR1, PWR_CR1_DBP); 00253 } 00254 /** 00255 * @} 00256 */ 00257 00258 /** @defgroup PWR_Exported_Functions_Group2 Peripheral Control Functions 00259 * @brief Power Control functions 00260 * 00261 @verbatim 00262 =============================================================================== 00263 ##### Peripheral Control Functions ##### 00264 =============================================================================== 00265 [..] 00266 This section provides functions allowing to control power peripheral. 00267 00268 *** PVD configuration *** 00269 ========================= 00270 [..] 00271 (+) The PVD is used to monitor the VDD power supply by comparing it to a 00272 threshold selected by the PVD Level (PLS[7:0] bits in the PWR_CR1 00273 register). 00274 00275 (+) A PVDO flag is available to indicate if VDD is higher or lower 00276 than the PVD threshold. This event is internally connected to the EXTI 00277 line 16 to generate an interrupt if enabled. 00278 It is configurable through __HAL_PWR_PVD_EXTI_ENABLE_IT() macro. 00279 00280 (+) The PVD is stopped in STANDBY mode. 00281 00282 *** Wake-up pin configuration *** 00283 ================================= 00284 [..] 00285 (+) Wake-up pin is used to wake up the system from STANDBY mode. 00286 The pin pull is configurable through the WKUPEPR register to be in 00287 No-pull, Pull-up and Pull-down. 00288 The pin polarity is configurable through the WKUPEPR register to be 00289 active on rising or falling edges. 00290 00291 (+) There are up to six Wake-up pin in the STM32H7 devices family. 00292 00293 *** Low Power modes configuration *** 00294 ===================================== 00295 [..] 00296 The device present 3 principles low-power modes features: 00297 (+) SLEEP mode : Cortex-Mx is stopped and all PWR domains are remaining 00298 active (Powered and Clocked). 00299 00300 (+) STOP mode : Cortex-Mx is stopped, clocks are stopped and the 00301 regulator is running. The Main regulator or the LP 00302 regulator could be selected. 00303 00304 (+) STANDBY mode : All PWR domains enter DSTANDBY mode and the VCORE 00305 supply regulator is powered off. 00306 00307 *** SLEEP mode *** 00308 ================== 00309 [..] 00310 (+) Entry: 00311 The SLEEP mode is entered by using the HAL_PWR_EnterSLEEPMode(Regulator, 00312 SLEEPEntry) function. 00313 00314 (++) PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction. 00315 (++) PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction. 00316 00317 -@@- The Regulator parameter is not used for the STM32H7 family 00318 and is kept as parameter just to maintain compatibility with the 00319 lower power families (STM32L). 00320 00321 (+) Exit: 00322 Any peripheral interrupt acknowledged by the nested vectored interrupt 00323 controller (NVIC) can wake up the device from SLEEP mode. 00324 00325 *** STOP mode *** 00326 ================= 00327 [..] 00328 In system STOP mode, all clocks in the 1.2V domain are stopped, the PLL, 00329 the HSI, and the HSE RC oscillators are disabled. Internal SRAM and 00330 register contents are preserved. 00331 The voltage regulator can be configured either in normal or low-power mode. 00332 To minimize the consumption in STOP mode, FLASH can be powered off before 00333 entering the STOP mode using the HAL_PWREx_EnableFlashPowerDown() function. 00334 It can be switched on again by software after exiting the STOP mode using 00335 the HAL_PWREx_DisableFlashPowerDown() function. 00336 00337 (+) Entry: 00338 The STOP mode is entered using the HAL_PWR_EnterSTOPMode(Regulator, 00339 STOPEntry) function with: 00340 00341 (++) Regulator: 00342 (+++) PWR_MAINREGULATOR_ON: Main regulator ON. 00343 (+++) PWR_LOWPOWERREGULATOR_ON: Low Power regulator ON. 00344 00345 (++) STOPEntry: 00346 (+++) PWR_STOPENTRY_WFI: enter STOP mode with WFI instruction. 00347 (+++) PWR_STOPENTRY_WFE: enter STOP mode with WFE instruction. 00348 00349 (+) Exit: 00350 Any EXTI Line (Internal or External) configured in Interrupt/Event mode. 00351 00352 *** STANDBY mode *** 00353 ==================== 00354 [..] 00355 (+) 00356 The system STANDBY mode allows to achieve the lowest power consumption. 00357 It is based on the Cortex-Mx deep SLEEP mode, with the voltage regulator 00358 disabled. The system is consequently powered off. The PLL, the HSI 00359 oscillator and the HSE oscillator are also switched off. SRAM and register 00360 contents are lost except for the RTC registers, RTC backup registers, 00361 backup SRAM and standby circuitry. 00362 00363 [..] 00364 The voltage regulator is OFF. 00365 00366 (++) Entry: 00367 (+++) The STANDBY mode is entered using the HAL_PWR_EnterSTANDBYMode() 00368 function. 00369 00370 (++) Exit: 00371 (+++) WKUP pin rising or falling edge, RTC alarm (Alarm A and Alarm B), 00372 RTC wakeup, tamper event, time stamp event, external reset in NRST 00373 pin, IWDG reset. 00374 00375 *** Auto-wakeup (AWU) from low-power mode *** 00376 ============================================= 00377 [..] 00378 (+) The MCU can be woken up from low-power mode by an RTC Alarm event, an 00379 RTC Wakeup event, a tamper event or a time-stamp event, without 00380 depending on an external interrupt (Auto-wakeup mode). 00381 00382 (+) RTC auto-wakeup (AWU) from the STOP and STANDBY modes 00383 00384 (++) To wake up from the STOP mode with an RTC alarm event, it is 00385 necessary to configure the RTC to generate the RTC alarm using the 00386 HAL_RTC_SetAlarm_IT() function. 00387 00388 (++) To wake up from the STOP mode with an RTC Tamper or time stamp event, 00389 it is necessary to configure the RTC to detect the tamper or time 00390 stamp event using the HAL_RTCEx_SetTimeStamp_IT() or 00391 HAL_RTCEx_SetTamper_IT() functions. 00392 00393 (++) To wake up from the STOP mode with an RTC WakeUp event, it is 00394 necessary to configure the RTC to generate the RTC WakeUp event 00395 using the HAL_RTCEx_SetWakeUpTimer_IT() function. 00396 00397 @endverbatim 00398 * @{ 00399 */ 00400 00401 /** 00402 * @brief Configure the event mode and the voltage threshold detected by the 00403 * Programmable Voltage Detector(PVD). 00404 * @param sConfigPVD : Pointer to an PWR_PVDTypeDef structure that contains 00405 * the configuration information for the PVD. 00406 * @note Refer to the electrical characteristics of your device datasheet for 00407 * more details about the voltage threshold corresponding to each 00408 * detection level. 00409 * @note For dual core devices, please ensure to configure the EXTI lines for 00410 * the different Cortex-Mx through PWR_Exported_Macro provided by this 00411 * driver. All combination are allowed: wake up only Cortex-M7, wake up 00412 * only Cortex-M4 or wake up Cortex-M7 and Cortex-M4. 00413 * @retval None. 00414 */ 00415 void HAL_PWR_ConfigPVD (PWR_PVDTypeDef *sConfigPVD) 00416 { 00417 /* Check the PVD configuration parameter */ 00418 if (sConfigPVD == NULL) 00419 { 00420 return; 00421 } 00422 00423 /* Check the parameters */ 00424 assert_param (IS_PWR_PVD_LEVEL (sConfigPVD->PVDLevel)); 00425 assert_param (IS_PWR_PVD_MODE (sConfigPVD->Mode)); 00426 00427 /* Set PLS[7:5] bits according to PVDLevel value */ 00428 MODIFY_REG (PWR->CR1, PWR_CR1_PLS, sConfigPVD->PVDLevel); 00429 00430 /* Clear previous config */ 00431 #if !defined (DUAL_CORE) 00432 __HAL_PWR_PVD_EXTI_DISABLE_EVENT (); 00433 __HAL_PWR_PVD_EXTI_DISABLE_IT (); 00434 #endif /* !defined (DUAL_CORE) */ 00435 00436 __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE (); 00437 __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE (); 00438 00439 #if !defined (DUAL_CORE) 00440 /* Interrupt mode configuration */ 00441 if ((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT) 00442 { 00443 __HAL_PWR_PVD_EXTI_ENABLE_IT (); 00444 } 00445 00446 /* Event mode configuration */ 00447 if ((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT) 00448 { 00449 __HAL_PWR_PVD_EXTI_ENABLE_EVENT (); 00450 } 00451 #endif /* !defined (DUAL_CORE) */ 00452 00453 /* Rising edge configuration */ 00454 if ((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE) 00455 { 00456 __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE (); 00457 } 00458 00459 /* Falling edge configuration */ 00460 if ((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE) 00461 { 00462 __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE (); 00463 } 00464 } 00465 00466 /** 00467 * @brief Enable the Programmable Voltage Detector (PVD). 00468 * @retval None. 00469 */ 00470 void HAL_PWR_EnablePVD (void) 00471 { 00472 /* Enable the power voltage detector */ 00473 SET_BIT (PWR->CR1, PWR_CR1_PVDEN); 00474 } 00475 00476 /** 00477 * @brief Disable the Programmable Voltage Detector (PVD). 00478 * @retval None. 00479 */ 00480 void HAL_PWR_DisablePVD (void) 00481 { 00482 /* Disable the power voltage detector */ 00483 CLEAR_BIT (PWR->CR1, PWR_CR1_PVDEN); 00484 } 00485 00486 /** 00487 * @brief Enable the WakeUp PINx functionality. 00488 * @param WakeUpPinPolarity : Specifies which Wake-Up pin to enable. 00489 * This parameter can be one of the following legacy values, which 00490 * sets the default (rising edge): 00491 * @arg PWR_WAKEUP_PIN1, PWR_WAKEUP_PIN2, PWR_WAKEUP_PIN3, 00492 * PWR_WAKEUP_PIN4, PWR_WAKEUP_PIN5, PWR_WAKEUP_PIN6. 00493 * or one of the following values where the user can explicitly states 00494 * the enabled pin and the chosen polarity: 00495 * @arg PWR_WAKEUP_PIN1_HIGH, PWR_WAKEUP_PIN1_LOW, 00496 * PWR_WAKEUP_PIN2_HIGH, PWR_WAKEUP_PIN2_LOW, 00497 * PWR_WAKEUP_PIN3_HIGH, PWR_WAKEUP_PIN3_LOW, 00498 * PWR_WAKEUP_PIN4_HIGH, PWR_WAKEUP_PIN4_LOW, 00499 * PWR_WAKEUP_PIN5_HIGH, PWR_WAKEUP_PIN5_LOW, 00500 * PWR_WAKEUP_PIN6_HIGH, PWR_WAKEUP_PIN6_LOW. 00501 * @note PWR_WAKEUP_PINx and PWR_WAKEUP_PINx_HIGH are equivalent. 00502 * @note The PWR_WAKEUP_PIN3_HIGH, PWR_WAKEUP_PIN3_LOW, PWR_WAKEUP_PIN5_HIGH 00503 * and PWR_WAKEUP_PIN5_LOW are available only for devices that includes 00504 * GPIOI port. 00505 * @retval None. 00506 */ 00507 void HAL_PWR_EnableWakeUpPin (uint32_t WakeUpPinPolarity) 00508 { 00509 /* Check the parameters */ 00510 assert_param (IS_PWR_WAKEUP_PIN (WakeUpPinPolarity)); 00511 00512 /* 00513 Enable and Specify the Wake-Up pin polarity and the pull configuration 00514 for the event detection (rising or falling edge). 00515 */ 00516 MODIFY_REG (PWR->WKUPEPR, PWR_EWUP_MASK, WakeUpPinPolarity); 00517 } 00518 00519 /** 00520 * @brief Disable the WakeUp PINx functionality. 00521 * @param WakeUpPinx : Specifies the Power Wake-Up pin to disable. 00522 * This parameter can be one of the following values: 00523 * @arg PWR_WAKEUP_PIN1, PWR_WAKEUP_PIN2, PWR_WAKEUP_PIN3, 00524 * PWR_WAKEUP_PIN4, PWR_WAKEUP_PIN5, PWR_WAKEUP_PIN6, 00525 * PWR_WAKEUP_PIN1_HIGH, PWR_WAKEUP_PIN1_LOW, 00526 * PWR_WAKEUP_PIN2_HIGH, PWR_WAKEUP_PIN2_LOW, 00527 * PWR_WAKEUP_PIN3_HIGH, PWR_WAKEUP_PIN3_LOW, 00528 * PWR_WAKEUP_PIN4_HIGH, PWR_WAKEUP_PIN4_LOW, 00529 * PWR_WAKEUP_PIN5_HIGH, PWR_WAKEUP_PIN5_LOW, 00530 * PWR_WAKEUP_PIN6_HIGH, PWR_WAKEUP_PIN6_LOW. 00531 * @note The PWR_WAKEUP_PIN3_HIGH, PWR_WAKEUP_PIN3_LOW, PWR_WAKEUP_PIN5_HIGH 00532 * and PWR_WAKEUP_PIN5_LOW are available only for devices that includes 00533 * GPIOI port. 00534 * @retval None. 00535 */ 00536 void HAL_PWR_DisableWakeUpPin (uint32_t WakeUpPinx) 00537 { 00538 /* Check the parameters */ 00539 assert_param (IS_PWR_WAKEUP_PIN (WakeUpPinx)); 00540 00541 /* Disable the wake up pin selected */ 00542 CLEAR_BIT (PWR->WKUPEPR, (PWR_WKUPEPR_WKUPEN & WakeUpPinx)); 00543 } 00544 00545 /** 00546 * @brief Enter the current core in SLEEP mode (CSLEEP). 00547 * @param Regulator : Specifies the regulator state in SLEEP mode. 00548 * This parameter can be one of the following values: 00549 * @arg PWR_MAINREGULATOR_ON : SLEEP mode with regulator ON. 00550 * @arg PWR_LOWPOWERREGULATOR_ON : SLEEP mode with low power 00551 * regulator ON. 00552 * @note This parameter is not used for the STM32H7 family and is kept as 00553 * parameter just to maintain compatibility with the lower power 00554 * families. 00555 * @param SLEEPEntry : Specifies if SLEEP mode is entered with WFI or WFE 00556 * intrinsic instruction. 00557 * This parameter can be one of the following values: 00558 * @arg PWR_SLEEPENTRY_WFI : enter SLEEP mode with WFI instruction. 00559 * @arg PWR_SLEEPENTRY_WFE : enter SLEEP mode with WFE instruction. 00560 * @note Ensure to clear pending events before calling this API through 00561 * HAL_PWREx_ClearPendingEvent() when the SLEEP entry is WFE. 00562 * @retval None. 00563 */ 00564 void HAL_PWR_EnterSLEEPMode (uint32_t Regulator, uint8_t SLEEPEntry) 00565 { 00566 /* Check the parameters */ 00567 assert_param (IS_PWR_REGULATOR (Regulator)); 00568 assert_param (IS_PWR_SLEEP_ENTRY (SLEEPEntry)); 00569 00570 /* Clear SLEEPDEEP bit of Cortex System Control Register */ 00571 CLEAR_BIT (SCB->SCR, SCB_SCR_SLEEPDEEP_Msk); 00572 00573 /* Select SLEEP mode entry */ 00574 if (SLEEPEntry == PWR_SLEEPENTRY_WFI) 00575 { 00576 /* Request Wait For Interrupt */ 00577 __WFI (); 00578 } 00579 else 00580 { 00581 /* Request Wait For Event */ 00582 __WFE (); 00583 } 00584 } 00585 00586 /** 00587 * @brief Enter STOP mode. 00588 * @note For single core devices, this API will enter the system in STOP mode 00589 * with all domains in DSTOP, if RUN_D3/RUN_SRD bit in CPUCR register is 00590 * cleared. 00591 * For dual core devices, this API will enter the domain (containing 00592 * Cortex-Mx that executing this function) in DSTOP mode. If all 00593 * Cortex-Mx domains are in DSTOP and RUN_D3 bit in CPUCR register is 00594 * cleared, all the system will enter in STOP mode. 00595 * @param Regulator : Specifies the regulator state in STOP mode. 00596 * This parameter can be one of the following values: 00597 * @arg PWR_MAINREGULATOR_ON : STOP mode with regulator ON. 00598 * @arg PWR_LOWPOWERREGULATOR_ON : STOP mode with low power 00599 * regulator ON. 00600 * @param STOPEntry : Specifies if STOP mode in entered with WFI or WFE 00601 * intrinsic instruction. 00602 * This parameter can be one of the following values: 00603 * @arg PWR_STOPENTRY_WFI : Enter STOP mode with WFI instruction. 00604 * @arg PWR_STOPENTRY_WFE : Enter STOP mode with WFE instruction. 00605 * @note In System STOP mode, all I/O pins keep the same state as in Run mode. 00606 * @note When exiting System STOP mode by issuing an interrupt or a wakeup 00607 * event, the HSI RC oscillator is selected as default system wakeup 00608 * clock. 00609 * @note In System STOP mode, when the voltage regulator operates in low 00610 * power mode, an additional startup delay is incurred when the system 00611 * is waking up. By keeping the internal regulator ON during STOP mode, 00612 * the consumption is higher although the startup time is reduced. 00613 * @retval None. 00614 */ 00615 void HAL_PWR_EnterSTOPMode (uint32_t Regulator, uint8_t STOPEntry) 00616 { 00617 /* Check the parameters */ 00618 assert_param (IS_PWR_REGULATOR (Regulator)); 00619 assert_param (IS_PWR_STOP_ENTRY (STOPEntry)); 00620 00621 /* Select the regulator state in STOP mode */ 00622 MODIFY_REG (PWR->CR1, PWR_CR1_LPDS, Regulator); 00623 00624 /* Configure the PWR mode for the different Domains */ 00625 #if defined (DUAL_CORE) 00626 /* Check CPU ID */ 00627 if (HAL_GetCurrentCPUID () == CM7_CPUID) 00628 { 00629 /* Keep DSTOP mode when Cortex-M7 enters DEEP-SLEEP */ 00630 CLEAR_BIT (PWR->CPUCR, (PWR_CPUCR_PDDS_D1 | PWR_CPUCR_PDDS_D3)); 00631 } 00632 else 00633 { 00634 /* Keep DSTOP mode when Cortex-M4 enters DEEP-SLEEP */ 00635 CLEAR_BIT (PWR->CPUCR, (PWR_CPUCR_PDDS_D2 | PWR_CPUCR_PDDS_D3)); 00636 } 00637 #else /* Single core devices */ 00638 /* Keep DSTOP mode when Cortex-M7 enter in DEEP-SLEEP */ 00639 CLEAR_BIT (PWR->CPUCR, (PWR_CPUCR_PDDS_D1 | PWR_CPUCR_PDDS_D3)); 00640 00641 #if defined (PWR_CPUCR_PDDS_D2) 00642 /* Keep DSTOP mode when Cortex-M7 enter in DEEP-SLEEP */ 00643 CLEAR_BIT (PWR->CPUCR, PWR_CPUCR_PDDS_D2); 00644 #endif /* PWR_CPUCR_PDDS_D2 */ 00645 #endif /* defined (DUAL_CORE) */ 00646 00647 /* Set SLEEPDEEP bit of Cortex System Control Register */ 00648 SET_BIT (SCB->SCR, SCB_SCR_SLEEPDEEP_Msk); 00649 00650 /* Ensure that all instructions are done before entering STOP mode */ 00651 __DSB (); 00652 __ISB (); 00653 00654 /* Select STOP mode entry */ 00655 if (STOPEntry == PWR_STOPENTRY_WFI) 00656 { 00657 /* Request Wait For Interrupt */ 00658 __WFI (); 00659 } 00660 else 00661 { 00662 /* Request Wait For Event */ 00663 __WFE (); 00664 } 00665 00666 /* Clear SLEEPDEEP bit of Cortex-Mx in the System Control Register */ 00667 CLEAR_BIT (SCB->SCR, SCB_SCR_SLEEPDEEP_Msk); 00668 } 00669 00670 /** 00671 * @brief Enter STANDBY mode. 00672 * @note For single core devices, this API will enter the system in STANDBY 00673 * mode with all domains in DSTANDBY, if RUN_D3/RUN_SRD bit in CPUCR 00674 * register is cleared. 00675 * For dual core devices, this API will enter the domain (containing 00676 * Cortex-Mx that executing this function) in DSTANDBY mode. If all 00677 * Cortex-Mx domains are in DSTANDBY and RUN_D3 bit in CPUCR register 00678 * is cleared, all the system will enter in STANDBY mode. 00679 * @note The system enters Standby mode only when all domains are in DSTANDBY. 00680 * @note When the System exit STANDBY mode by issuing an interrupt or a 00681 * wakeup event, the HSI RC oscillator is selected as system clock. 00682 * @note It is recommended to disable all regulators before entring STANDBY 00683 * mode for power consumption saving purpose. 00684 * @retval None. 00685 */ 00686 void HAL_PWR_EnterSTANDBYMode (void) 00687 { 00688 /* Configure the PWR mode for the different Domains */ 00689 #if defined (DUAL_CORE) 00690 /* Check CPU ID */ 00691 if (HAL_GetCurrentCPUID () == CM7_CPUID) 00692 { 00693 /* Enter DSTANDBY mode when Cortex-M7 enters DEEP-SLEEP */ 00694 SET_BIT (PWR->CPUCR, (PWR_CPUCR_PDDS_D1 | PWR_CPUCR_PDDS_D3)); 00695 SET_BIT (PWR->CPU2CR, (PWR_CPU2CR_PDDS_D1 | PWR_CPU2CR_PDDS_D3)); 00696 } 00697 else 00698 { 00699 /* Enter DSTANDBY mode when Cortex-M4 enters DEEP-SLEEP */ 00700 SET_BIT (PWR->CPUCR, (PWR_CPUCR_PDDS_D2 | PWR_CPUCR_PDDS_D3)); 00701 SET_BIT (PWR->CPU2CR, (PWR_CPU2CR_PDDS_D2 | PWR_CPU2CR_PDDS_D3)); 00702 } 00703 #else /* Single core devices */ 00704 /* Enter DSTANDBY mode when Cortex-M7 enters DEEP-SLEEP */ 00705 SET_BIT (PWR->CPUCR, (PWR_CPUCR_PDDS_D1 | PWR_CPUCR_PDDS_D3)); 00706 00707 #if defined (PWR_CPUCR_PDDS_D2) 00708 /* Enter DSTANDBY mode when Cortex-M7 enters DEEP-SLEEP */ 00709 SET_BIT (PWR->CPUCR, PWR_CPUCR_PDDS_D2); 00710 #endif /* PWR_CPUCR_PDDS_D2 */ 00711 #endif /* defined (DUAL_CORE) */ 00712 00713 /* Set SLEEPDEEP bit of Cortex System Control Register */ 00714 SET_BIT (SCB->SCR, SCB_SCR_SLEEPDEEP_Msk); 00715 00716 /* Ensure that all instructions are done before entering STOP mode */ 00717 __DSB (); 00718 __ISB (); 00719 00720 /* This option is used to ensure that store operations are completed */ 00721 #if defined (__CC_ARM) 00722 __force_stores(); 00723 #endif /* defined (__CC_ARM) */ 00724 00725 /* Request Wait For Interrupt */ 00726 __WFI (); 00727 } 00728 00729 /** 00730 * @brief Indicate Sleep-On-Exit feature when returning from Handler mode to 00731 * Thread mode. 00732 * @note Set SLEEPONEXIT bit of SCR register. When this bit is set, the 00733 * processor re-enters SLEEP mode when an interruption handling is over. 00734 * Setting this bit is useful when the processor is expected to run 00735 * only on interruptions handling. 00736 * @retval None. 00737 */ 00738 void HAL_PWR_EnableSleepOnExit (void) 00739 { 00740 /* Set SLEEPONEXIT bit of Cortex-Mx System Control Register */ 00741 SET_BIT (SCB->SCR, SCB_SCR_SLEEPONEXIT_Msk); 00742 } 00743 00744 /** 00745 * @brief Disable Sleep-On-Exit feature when returning from Handler mode to 00746 * Thread mode. 00747 * @note Clears SLEEPONEXIT bit of SCR register. When this bit is set, the 00748 * processor re-enters SLEEP mode when an interruption handling is over. 00749 * @retval None 00750 */ 00751 void HAL_PWR_DisableSleepOnExit (void) 00752 { 00753 /* Clear SLEEPONEXIT bit of Cortex-Mx System Control Register */ 00754 CLEAR_BIT (SCB->SCR, SCB_SCR_SLEEPONEXIT_Msk); 00755 } 00756 00757 /** 00758 * @brief Enable CORTEX SEVONPEND feature. 00759 * @note Sets SEVONPEND bit of SCR register. When this bit is set, any 00760 * pending event / interrupt even if it's disabled or has insufficient 00761 * priority to cause exception entry wakes up the Cortex-Mx. 00762 * @retval None. 00763 */ 00764 void HAL_PWR_EnableSEVOnPend (void) 00765 { 00766 /* Set SEVONPEND bit of Cortex-Mx System Control Register */ 00767 SET_BIT (SCB->SCR, SCB_SCR_SEVONPEND_Msk); 00768 } 00769 00770 /** 00771 * @brief Disable CORTEX SEVONPEND feature. 00772 * @note Resets SEVONPEND bit of SCR register. When this bit is reset, only 00773 * enabled pending causes exception entry wakes up the Cortex-Mx. 00774 * @retval None. 00775 */ 00776 void HAL_PWR_DisableSEVOnPend (void) 00777 { 00778 /* Clear SEVONPEND bit of Cortex System Control Register */ 00779 CLEAR_BIT (SCB->SCR, SCB_SCR_SEVONPEND_Msk); 00780 } 00781 /** 00782 * @} 00783 */ 00784 00785 /** @defgroup PWR_Exported_Functions_Group3 Interrupt Handling Functions 00786 * @brief Interrupt Handling functions 00787 * 00788 @verbatim 00789 =============================================================================== 00790 ##### Interrupt Handling Functions ##### 00791 =============================================================================== 00792 [..] 00793 This section provides functions allowing to handle the PVD pending 00794 interrupts. 00795 00796 @endverbatim 00797 * @{ 00798 */ 00799 00800 /** 00801 * @brief This function handles the PWR PVD interrupt request. 00802 * @note This API should be called under the PVD_AVD_IRQHandler(). 00803 * @retval None. 00804 */ 00805 void HAL_PWR_PVD_IRQHandler (void) 00806 { 00807 #if defined (DUAL_CORE) 00808 /* Check Cortex-Mx ID */ 00809 if (HAL_GetCurrentCPUID () == CM7_CPUID) 00810 { 00811 /* Check PWR EXTI D1 flag */ 00812 if(__HAL_PWR_PVD_EXTI_GET_FLAG () != 0U) 00813 { 00814 /* Clear PWR EXTI D1 pending bit */ 00815 __HAL_PWR_PVD_EXTI_CLEAR_FLAG (); 00816 00817 /* PWR PVD interrupt user callback */ 00818 HAL_PWR_PVDCallback (); 00819 } 00820 } 00821 else 00822 { 00823 /* Check PWR EXTI D2 flag */ 00824 if (__HAL_PWR_PVD_EXTID2_GET_FLAG () != 0U) 00825 { 00826 /* Clear PWR EXTI D2 pending bit */ 00827 __HAL_PWR_PVD_EXTID2_CLEAR_FLAG (); 00828 00829 /* PWR PVD interrupt user callback */ 00830 HAL_PWR_PVDCallback (); 00831 } 00832 } 00833 #else /* Single core devices */ 00834 /* PVD EXTI line interrupt detected */ 00835 if (__HAL_PWR_PVD_EXTI_GET_FLAG () != 0U) 00836 { 00837 /* Clear PWR EXTI pending bit */ 00838 __HAL_PWR_PVD_EXTI_CLEAR_FLAG (); 00839 00840 /* PWR PVD interrupt user callback */ 00841 HAL_PWR_PVDCallback (); 00842 } 00843 #endif /* defined (DUAL_CORE) */ 00844 } 00845 00846 /** 00847 * @brief PWR PVD interrupt callback. 00848 * @retval None. 00849 */ 00850 __weak void HAL_PWR_PVDCallback (void) 00851 { 00852 /* NOTE : This function should not be modified, when the callback is needed, 00853 the HAL_PWR_PVDCallback can be implemented in the user file 00854 */ 00855 } 00856 00857 /** 00858 * @} 00859 */ 00860 00861 /** 00862 * @} 00863 */ 00864 00865 #endif /* HAL_PWR_MODULE_ENABLED */ 00866 /** 00867 * @} 00868 */ 00869 00870 /** 00871 * @} 00872 */ 00873