STM32L443xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_hal_pwr.h 00004 * @author MCD Application Team 00005 * @brief Header file of PWR HAL module. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * Copyright (c) 2017 STMicroelectronics. 00010 * All rights reserved. 00011 * 00012 * This software is licensed under terms that can be found in the LICENSE file 00013 * in the root directory of this software component. 00014 * If no LICENSE file comes with this software, it is provided AS-IS. 00015 * 00016 ****************************************************************************** 00017 */ 00018 00019 /* Define to prevent recursive inclusion -------------------------------------*/ 00020 #ifndef STM32L4xx_HAL_PWR_H 00021 #define STM32L4xx_HAL_PWR_H 00022 00023 #ifdef __cplusplus 00024 extern "C" { 00025 #endif 00026 00027 /* Includes ------------------------------------------------------------------*/ 00028 #include "stm32l4xx_hal_def.h" 00029 00030 /** @addtogroup STM32L4xx_HAL_Driver 00031 * @{ 00032 */ 00033 00034 /** @addtogroup PWR 00035 * @{ 00036 */ 00037 00038 /* Exported types ------------------------------------------------------------*/ 00039 00040 /** @defgroup PWR_Exported_Types PWR Exported Types 00041 * @{ 00042 */ 00043 00044 /** 00045 * @brief PWR PVD configuration structure definition 00046 */ 00047 typedef struct 00048 { 00049 uint32_t PVDLevel; /*!< PVDLevel: Specifies the PVD detection level. 00050 This parameter can be a value of @ref PWR_PVD_detection_level. */ 00051 00052 uint32_t Mode; /*!< Mode: Specifies the operating mode for the selected pins. 00053 This parameter can be a value of @ref PWR_PVD_Mode. */ 00054 }PWR_PVDTypeDef; 00055 00056 00057 /** 00058 * @} 00059 */ 00060 00061 /* Exported constants --------------------------------------------------------*/ 00062 00063 /** @defgroup PWR_Exported_Constants PWR Exported Constants 00064 * @{ 00065 */ 00066 00067 00068 /** @defgroup PWR_PVD_detection_level Programmable Voltage Detection levels 00069 * @{ 00070 */ 00071 #define PWR_PVDLEVEL_0 PWR_CR2_PLS_LEV0 /*!< PVD threshold around 2.0 V */ 00072 #define PWR_PVDLEVEL_1 PWR_CR2_PLS_LEV1 /*!< PVD threshold around 2.2 V */ 00073 #define PWR_PVDLEVEL_2 PWR_CR2_PLS_LEV2 /*!< PVD threshold around 2.4 V */ 00074 #define PWR_PVDLEVEL_3 PWR_CR2_PLS_LEV3 /*!< PVD threshold around 2.5 V */ 00075 #define PWR_PVDLEVEL_4 PWR_CR2_PLS_LEV4 /*!< PVD threshold around 2.6 V */ 00076 #define PWR_PVDLEVEL_5 PWR_CR2_PLS_LEV5 /*!< PVD threshold around 2.8 V */ 00077 #define PWR_PVDLEVEL_6 PWR_CR2_PLS_LEV6 /*!< PVD threshold around 2.9 V */ 00078 #define PWR_PVDLEVEL_7 PWR_CR2_PLS_LEV7 /*!< External input analog voltage (compared internally to VREFINT) */ 00079 /** 00080 * @} 00081 */ 00082 00083 /** @defgroup PWR_PVD_Mode PWR PVD interrupt and event mode 00084 * @{ 00085 */ 00086 #define PWR_PVD_MODE_NORMAL ((uint32_t)0x00000000) /*!< Basic mode is used */ 00087 #define PWR_PVD_MODE_IT_RISING ((uint32_t)0x00010001) /*!< External Interrupt Mode with Rising edge trigger detection */ 00088 #define PWR_PVD_MODE_IT_FALLING ((uint32_t)0x00010002) /*!< External Interrupt Mode with Falling edge trigger detection */ 00089 #define PWR_PVD_MODE_IT_RISING_FALLING ((uint32_t)0x00010003) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */ 00090 #define PWR_PVD_MODE_EVENT_RISING ((uint32_t)0x00020001) /*!< Event Mode with Rising edge trigger detection */ 00091 #define PWR_PVD_MODE_EVENT_FALLING ((uint32_t)0x00020002) /*!< Event Mode with Falling edge trigger detection */ 00092 #define PWR_PVD_MODE_EVENT_RISING_FALLING ((uint32_t)0x00020003) /*!< Event Mode with Rising/Falling edge trigger detection */ 00093 /** 00094 * @} 00095 */ 00096 00097 00098 00099 00100 /** @defgroup PWR_Regulator_state_in_SLEEP_STOP_mode PWR regulator mode 00101 * @{ 00102 */ 00103 #define PWR_MAINREGULATOR_ON ((uint32_t)0x00000000) /*!< Regulator in main mode */ 00104 #define PWR_LOWPOWERREGULATOR_ON PWR_CR1_LPR /*!< Regulator in low-power mode */ 00105 /** 00106 * @} 00107 */ 00108 00109 /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry 00110 * @{ 00111 */ 00112 #define PWR_SLEEPENTRY_WFI ((uint8_t)0x01) /*!< Wait For Interruption instruction to enter Sleep mode */ 00113 #define PWR_SLEEPENTRY_WFE ((uint8_t)0x02) /*!< Wait For Event instruction to enter Sleep mode */ 00114 /** 00115 * @} 00116 */ 00117 00118 /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry 00119 * @{ 00120 */ 00121 #define PWR_STOPENTRY_WFI ((uint8_t)0x01) /*!< Wait For Interruption instruction to enter Stop mode */ 00122 #define PWR_STOPENTRY_WFE ((uint8_t)0x02) /*!< Wait For Event instruction to enter Stop mode */ 00123 /** 00124 * @} 00125 */ 00126 00127 00128 /** @defgroup PWR_PVD_EXTI_LINE PWR PVD external interrupt line 00129 * @{ 00130 */ 00131 #define PWR_EXTI_LINE_PVD ((uint32_t)0x00010000) /*!< External interrupt line 16 Connected to the PVD EXTI Line */ 00132 /** 00133 * @} 00134 */ 00135 00136 /** @defgroup PWR_PVD_EVENT_LINE PWR PVD event line 00137 * @{ 00138 */ 00139 #define PWR_EVENT_LINE_PVD ((uint32_t)0x00010000) /*!< Event line 16 Connected to the PVD Event Line */ 00140 /** 00141 * @} 00142 */ 00143 00144 /** 00145 * @} 00146 */ 00147 00148 /* Exported macros -----------------------------------------------------------*/ 00149 /** @defgroup PWR_Exported_Macros PWR Exported Macros 00150 * @{ 00151 */ 00152 00153 /** @brief Check whether or not a specific PWR flag is set. 00154 * @param __FLAG__ specifies the flag to check. 00155 * This parameter can be one of the following values: 00156 * @arg @ref PWR_FLAG_WUF1 Wake Up Flag 1. Indicates that a wakeup event 00157 * was received from the WKUP pin 1. 00158 * @arg @ref PWR_FLAG_WUF2 Wake Up Flag 2. Indicates that a wakeup event 00159 * was received from the WKUP pin 2. 00160 * @arg @ref PWR_FLAG_WUF3 Wake Up Flag 3. Indicates that a wakeup event 00161 * was received from the WKUP pin 3. 00162 * @arg @ref PWR_FLAG_WUF4 Wake Up Flag 4. Indicates that a wakeup event 00163 * was received from the WKUP pin 4. 00164 * @arg @ref PWR_FLAG_WUF5 Wake Up Flag 5. Indicates that a wakeup event 00165 * was received from the WKUP pin 5. 00166 * @arg @ref PWR_FLAG_SB StandBy Flag. Indicates that the system 00167 * entered StandBy mode. 00168 * @arg @ref PWR_FLAG_EXT_SMPS External SMPS Ready Flag. When available on device, indicates 00169 * that external switch can be closed to connect to the external SMPS, when the Range 2 00170 * of internal regulator is ready. 00171 * @arg @ref PWR_FLAG_WUFI Wake-Up Flag Internal. Set when a wakeup is detected on 00172 * the internal wakeup line. 00173 * @arg @ref PWR_FLAG_REGLPS Low Power Regulator Started. Indicates whether or not the 00174 * low-power regulator is ready. 00175 * @arg @ref PWR_FLAG_REGLPF Low Power Regulator Flag. Indicates whether the 00176 * regulator is ready in main mode or is in low-power mode. 00177 * @arg @ref PWR_FLAG_VOSF Voltage Scaling Flag. Indicates whether the regulator is ready 00178 * in the selected voltage range or is still changing to the required voltage level. 00179 * @arg @ref PWR_FLAG_PVDO Power Voltage Detector Output. Indicates whether VDD voltage is 00180 * below or above the selected PVD threshold. 00181 * @arg @ref PWR_FLAG_PVMO1 Peripheral Voltage Monitoring Output 1. Indicates whether VDDUSB voltage is 00182 * is below or above PVM1 threshold (applicable when USB feature is supported). 00183 @if STM32L486xx 00184 * @arg @ref PWR_FLAG_PVMO2 Peripheral Voltage Monitoring Output 2. Indicates whether VDDIO2 voltage is 00185 * is below or above PVM2 threshold (applicable when VDDIO2 is present on device). 00186 @endif 00187 * @arg @ref PWR_FLAG_PVMO3 Peripheral Voltage Monitoring Output 3. Indicates whether VDDA voltage is 00188 * is below or above PVM3 threshold. 00189 * @arg @ref PWR_FLAG_PVMO4 Peripheral Voltage Monitoring Output 4. Indicates whether VDDA voltage is 00190 * is below or above PVM4 threshold. 00191 * 00192 * @retval The new state of __FLAG__ (TRUE or FALSE). 00193 */ 00194 #define __HAL_PWR_GET_FLAG(__FLAG__) ( ((((uint8_t)(__FLAG__)) >> 5U) == 1) ?\ 00195 (PWR->SR1 & (1U << ((__FLAG__) & 31U))) :\ 00196 (PWR->SR2 & (1U << ((__FLAG__) & 31U))) ) 00197 00198 /** @brief Clear a specific PWR flag. 00199 * @param __FLAG__ specifies the flag to clear. 00200 * This parameter can be one of the following values: 00201 * @arg @ref PWR_FLAG_WUF1 Wake Up Flag 1. Indicates that a wakeup event 00202 * was received from the WKUP pin 1. 00203 * @arg @ref PWR_FLAG_WUF2 Wake Up Flag 2. Indicates that a wakeup event 00204 * was received from the WKUP pin 2. 00205 * @arg @ref PWR_FLAG_WUF3 Wake Up Flag 3. Indicates that a wakeup event 00206 * was received from the WKUP pin 3. 00207 * @arg @ref PWR_FLAG_WUF4 Wake Up Flag 4. Indicates that a wakeup event 00208 * was received from the WKUP pin 4. 00209 * @arg @ref PWR_FLAG_WUF5 Wake Up Flag 5. Indicates that a wakeup event 00210 * was received from the WKUP pin 5. 00211 * @arg @ref PWR_FLAG_WU Encompasses all five Wake Up Flags. 00212 * @arg @ref PWR_FLAG_SB Standby Flag. Indicates that the system 00213 * entered Standby mode. 00214 * @retval None 00215 */ 00216 #define __HAL_PWR_CLEAR_FLAG(__FLAG__) ( (((uint8_t)(__FLAG__)) == PWR_FLAG_WU) ?\ 00217 (PWR->SCR = (__FLAG__)) :\ 00218 (PWR->SCR = (1U << ((__FLAG__) & 31U))) ) 00219 /** 00220 * @brief Enable the PVD Extended Interrupt Line. 00221 * @retval None 00222 */ 00223 #define __HAL_PWR_PVD_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR1, PWR_EXTI_LINE_PVD) 00224 00225 /** 00226 * @brief Disable the PVD Extended Interrupt Line. 00227 * @retval None 00228 */ 00229 #define __HAL_PWR_PVD_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR1, PWR_EXTI_LINE_PVD) 00230 00231 /** 00232 * @brief Enable the PVD Event Line. 00233 * @retval None 00234 */ 00235 #define __HAL_PWR_PVD_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR1, PWR_EVENT_LINE_PVD) 00236 00237 /** 00238 * @brief Disable the PVD Event Line. 00239 * @retval None 00240 */ 00241 #define __HAL_PWR_PVD_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR1, PWR_EVENT_LINE_PVD) 00242 00243 /** 00244 * @brief Enable the PVD Extended Interrupt Rising Trigger. 00245 * @retval None 00246 */ 00247 #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR1, PWR_EXTI_LINE_PVD) 00248 00249 /** 00250 * @brief Disable the PVD Extended Interrupt Rising Trigger. 00251 * @retval None 00252 */ 00253 #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR1, PWR_EXTI_LINE_PVD) 00254 00255 /** 00256 * @brief Enable the PVD Extended Interrupt Falling Trigger. 00257 * @retval None 00258 */ 00259 #define __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR1, PWR_EXTI_LINE_PVD) 00260 00261 00262 /** 00263 * @brief Disable the PVD Extended Interrupt Falling Trigger. 00264 * @retval None 00265 */ 00266 #define __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR1, PWR_EXTI_LINE_PVD) 00267 00268 00269 /** 00270 * @brief Enable the PVD Extended Interrupt Rising & Falling Trigger. 00271 * @retval None 00272 */ 00273 #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_FALLING_EDGE() \ 00274 do { \ 00275 __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE(); \ 00276 __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE(); \ 00277 } while(0) 00278 00279 /** 00280 * @brief Disable the PVD Extended Interrupt Rising & Falling Trigger. 00281 * @retval None 00282 */ 00283 #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_FALLING_EDGE() \ 00284 do { \ 00285 __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE(); \ 00286 __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE(); \ 00287 } while(0) 00288 00289 /** 00290 * @brief Generate a Software interrupt on selected EXTI line. 00291 * @retval None 00292 */ 00293 #define __HAL_PWR_PVD_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER1, PWR_EXTI_LINE_PVD) 00294 00295 /** 00296 * @brief Check whether or not the PVD EXTI interrupt flag is set. 00297 * @retval EXTI PVD Line Status. 00298 */ 00299 #define __HAL_PWR_PVD_EXTI_GET_FLAG() (EXTI->PR1 & PWR_EXTI_LINE_PVD) 00300 00301 /** 00302 * @brief Clear the PVD EXTI interrupt flag. 00303 * @retval None 00304 */ 00305 #define __HAL_PWR_PVD_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR1, PWR_EXTI_LINE_PVD) 00306 00307 /** 00308 * @} 00309 */ 00310 00311 00312 /* Private macros --------------------------------------------------------*/ 00313 /** @addtogroup PWR_Private_Macros PWR Private Macros 00314 * @{ 00315 */ 00316 00317 #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLEVEL_0) || ((LEVEL) == PWR_PVDLEVEL_1)|| \ 00318 ((LEVEL) == PWR_PVDLEVEL_2) || ((LEVEL) == PWR_PVDLEVEL_3)|| \ 00319 ((LEVEL) == PWR_PVDLEVEL_4) || ((LEVEL) == PWR_PVDLEVEL_5)|| \ 00320 ((LEVEL) == PWR_PVDLEVEL_6) || ((LEVEL) == PWR_PVDLEVEL_7)) 00321 00322 #define IS_PWR_PVD_MODE(MODE) (((MODE) == PWR_PVD_MODE_NORMAL) ||\ 00323 ((MODE) == PWR_PVD_MODE_IT_RISING) ||\ 00324 ((MODE) == PWR_PVD_MODE_IT_FALLING) ||\ 00325 ((MODE) == PWR_PVD_MODE_IT_RISING_FALLING) ||\ 00326 ((MODE) == PWR_PVD_MODE_EVENT_RISING) ||\ 00327 ((MODE) == PWR_PVD_MODE_EVENT_FALLING) ||\ 00328 ((MODE) == PWR_PVD_MODE_EVENT_RISING_FALLING)) 00329 00330 #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \ 00331 ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON)) 00332 00333 #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE)) 00334 00335 #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE) ) 00336 00337 /** 00338 * @} 00339 */ 00340 00341 /* Include PWR HAL Extended module */ 00342 #include "stm32l4xx_hal_pwr_ex.h" 00343 00344 /* Exported functions --------------------------------------------------------*/ 00345 00346 /** @addtogroup PWR_Exported_Functions PWR Exported Functions 00347 * @{ 00348 */ 00349 00350 /** @addtogroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions 00351 * @{ 00352 */ 00353 00354 /* Initialization and de-initialization functions *******************************/ 00355 void HAL_PWR_DeInit(void); 00356 void HAL_PWR_EnableBkUpAccess(void); 00357 void HAL_PWR_DisableBkUpAccess(void); 00358 00359 /** 00360 * @} 00361 */ 00362 00363 /** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions 00364 * @{ 00365 */ 00366 00367 /* Peripheral Control functions ************************************************/ 00368 HAL_StatusTypeDef HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD); 00369 void HAL_PWR_EnablePVD(void); 00370 void HAL_PWR_DisablePVD(void); 00371 00372 00373 /* WakeUp pins configuration functions ****************************************/ 00374 void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity); 00375 void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx); 00376 00377 /* Low Power modes configuration functions ************************************/ 00378 void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry); 00379 void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry); 00380 void HAL_PWR_EnterSTANDBYMode(void); 00381 00382 void HAL_PWR_EnableSleepOnExit(void); 00383 void HAL_PWR_DisableSleepOnExit(void); 00384 void HAL_PWR_EnableSEVOnPend(void); 00385 void HAL_PWR_DisableSEVOnPend(void); 00386 00387 void HAL_PWR_PVDCallback(void); 00388 00389 00390 /** 00391 * @} 00392 */ 00393 00394 /** 00395 * @} 00396 */ 00397 00398 /** 00399 * @} 00400 */ 00401 00402 /** 00403 * @} 00404 */ 00405 00406 #ifdef __cplusplus 00407 } 00408 #endif 00409 00410 00411 #endif /* STM32L4xx_HAL_PWR_H */