1 /** 2 ****************************************************************************** 3 * @file stm32l4xx_hal_pwr.h 4 * @author MCD Application Team 5 * @brief Header file of PWR HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * <h2><center>© Copyright (c) 2017 STMicroelectronics. 10 * All rights reserved.</center></h2> 11 * 12 * This software component is licensed by ST under BSD 3-Clause license, 13 * the "License"; You may not use this file except in compliance with the 14 * License. You may obtain a copy of the License at: 15 * opensource.org/licenses/BSD-3-Clause 16 * 17 ****************************************************************************** 18 */ 19 20 /* Define to prevent recursive inclusion -------------------------------------*/ 21 #ifndef STM32L4xx_HAL_PWR_H 22 #define STM32L4xx_HAL_PWR_H 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /* Includes ------------------------------------------------------------------*/ 29 #include "stm32l4xx_hal_def.h" 30 31 /** @addtogroup STM32L4xx_HAL_Driver 32 * @{ 33 */ 34 35 /** @addtogroup PWR 36 * @{ 37 */ 38 39 /* Exported types ------------------------------------------------------------*/ 40 41 /** @defgroup PWR_Exported_Types PWR Exported Types 42 * @{ 43 */ 44 45 /** 46 * @brief PWR PVD configuration structure definition 47 */ 48 typedef struct 49 { 50 uint32_t PVDLevel; /*!< PVDLevel: Specifies the PVD detection level. 51 This parameter can be a value of @ref PWR_PVD_detection_level. */ 52 53 uint32_t Mode; /*!< Mode: Specifies the operating mode for the selected pins. 54 This parameter can be a value of @ref PWR_PVD_Mode. */ 55 }PWR_PVDTypeDef; 56 57 58 /** 59 * @} 60 */ 61 62 /* Exported constants --------------------------------------------------------*/ 63 64 /** @defgroup PWR_Exported_Constants PWR Exported Constants 65 * @{ 66 */ 67 68 69 /** @defgroup PWR_PVD_detection_level Programmable Voltage Detection levels 70 * @{ 71 */ 72 #define PWR_PVDLEVEL_0 PWR_CR2_PLS_LEV0 /*!< PVD threshold around 2.0 V */ 73 #define PWR_PVDLEVEL_1 PWR_CR2_PLS_LEV1 /*!< PVD threshold around 2.2 V */ 74 #define PWR_PVDLEVEL_2 PWR_CR2_PLS_LEV2 /*!< PVD threshold around 2.4 V */ 75 #define PWR_PVDLEVEL_3 PWR_CR2_PLS_LEV3 /*!< PVD threshold around 2.5 V */ 76 #define PWR_PVDLEVEL_4 PWR_CR2_PLS_LEV4 /*!< PVD threshold around 2.6 V */ 77 #define PWR_PVDLEVEL_5 PWR_CR2_PLS_LEV5 /*!< PVD threshold around 2.8 V */ 78 #define PWR_PVDLEVEL_6 PWR_CR2_PLS_LEV6 /*!< PVD threshold around 2.9 V */ 79 #define PWR_PVDLEVEL_7 PWR_CR2_PLS_LEV7 /*!< External input analog voltage (compared internally to VREFINT) */ 80 /** 81 * @} 82 */ 83 84 /** @defgroup PWR_PVD_Mode PWR PVD interrupt and event mode 85 * @{ 86 */ 87 #define PWR_PVD_MODE_NORMAL ((uint32_t)0x00000000) /*!< Basic mode is used */ 88 #define PWR_PVD_MODE_IT_RISING ((uint32_t)0x00010001) /*!< External Interrupt Mode with Rising edge trigger detection */ 89 #define PWR_PVD_MODE_IT_FALLING ((uint32_t)0x00010002) /*!< External Interrupt Mode with Falling edge trigger detection */ 90 #define PWR_PVD_MODE_IT_RISING_FALLING ((uint32_t)0x00010003) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */ 91 #define PWR_PVD_MODE_EVENT_RISING ((uint32_t)0x00020001) /*!< Event Mode with Rising edge trigger detection */ 92 #define PWR_PVD_MODE_EVENT_FALLING ((uint32_t)0x00020002) /*!< Event Mode with Falling edge trigger detection */ 93 #define PWR_PVD_MODE_EVENT_RISING_FALLING ((uint32_t)0x00020003) /*!< Event Mode with Rising/Falling edge trigger detection */ 94 /** 95 * @} 96 */ 97 98 99 100 101 /** @defgroup PWR_Regulator_state_in_SLEEP_STOP_mode PWR regulator mode 102 * @{ 103 */ 104 #define PWR_MAINREGULATOR_ON ((uint32_t)0x00000000) /*!< Regulator in main mode */ 105 #define PWR_LOWPOWERREGULATOR_ON PWR_CR1_LPR /*!< Regulator in low-power mode */ 106 /** 107 * @} 108 */ 109 110 /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry 111 * @{ 112 */ 113 #define PWR_SLEEPENTRY_WFI ((uint8_t)0x01) /*!< Wait For Interruption instruction to enter Sleep mode */ 114 #define PWR_SLEEPENTRY_WFE ((uint8_t)0x02) /*!< Wait For Event instruction to enter Sleep mode */ 115 /** 116 * @} 117 */ 118 119 /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry 120 * @{ 121 */ 122 #define PWR_STOPENTRY_WFI ((uint8_t)0x01) /*!< Wait For Interruption instruction to enter Stop mode */ 123 #define PWR_STOPENTRY_WFE ((uint8_t)0x02) /*!< Wait For Event instruction to enter Stop mode */ 124 /** 125 * @} 126 */ 127 128 129 /** @defgroup PWR_PVD_EXTI_LINE PWR PVD external interrupt line 130 * @{ 131 */ 132 #define PWR_EXTI_LINE_PVD ((uint32_t)0x00010000) /*!< External interrupt line 16 Connected to the PVD EXTI Line */ 133 /** 134 * @} 135 */ 136 137 /** @defgroup PWR_PVD_EVENT_LINE PWR PVD event line 138 * @{ 139 */ 140 #define PWR_EVENT_LINE_PVD ((uint32_t)0x00010000) /*!< Event line 16 Connected to the PVD Event Line */ 141 /** 142 * @} 143 */ 144 145 /** 146 * @} 147 */ 148 149 /* Exported macros -----------------------------------------------------------*/ 150 /** @defgroup PWR_Exported_Macros PWR Exported Macros 151 * @{ 152 */ 153 154 /** @brief Check whether or not a specific PWR flag is set. 155 * @param __FLAG__ specifies the flag to check. 156 * This parameter can be one of the following values: 157 * @arg @ref PWR_FLAG_WUF1 Wake Up Flag 1. Indicates that a wakeup event 158 * was received from the WKUP pin 1. 159 * @arg @ref PWR_FLAG_WUF2 Wake Up Flag 2. Indicates that a wakeup event 160 * was received from the WKUP pin 2. 161 * @arg @ref PWR_FLAG_WUF3 Wake Up Flag 3. Indicates that a wakeup event 162 * was received from the WKUP pin 3. 163 * @arg @ref PWR_FLAG_WUF4 Wake Up Flag 4. Indicates that a wakeup event 164 * was received from the WKUP pin 4. 165 * @arg @ref PWR_FLAG_WUF5 Wake Up Flag 5. Indicates that a wakeup event 166 * was received from the WKUP pin 5. 167 * @arg @ref PWR_FLAG_SB StandBy Flag. Indicates that the system 168 * entered StandBy mode. 169 * @arg @ref PWR_FLAG_EXT_SMPS External SMPS Ready Flag. When available on device, indicates 170 * that external switch can be closed to connect to the external SMPS, when the Range 2 171 * of internal regulator is ready. 172 * @arg @ref PWR_FLAG_WUFI Wake-Up Flag Internal. Set when a wakeup is detected on 173 * the internal wakeup line. 174 * @arg @ref PWR_FLAG_REGLPS Low Power Regulator Started. Indicates whether or not the 175 * low-power regulator is ready. 176 * @arg @ref PWR_FLAG_REGLPF Low Power Regulator Flag. Indicates whether the 177 * regulator is ready in main mode or is in low-power mode. 178 * @arg @ref PWR_FLAG_VOSF Voltage Scaling Flag. Indicates whether the regulator is ready 179 * in the selected voltage range or is still changing to the required voltage level. 180 * @arg @ref PWR_FLAG_PVDO Power Voltage Detector Output. Indicates whether VDD voltage is 181 * below or above the selected PVD threshold. 182 * @arg @ref PWR_FLAG_PVMO1 Peripheral Voltage Monitoring Output 1. Indicates whether VDDUSB voltage is 183 * is below or above PVM1 threshold (applicable when USB feature is supported). 184 @if STM32L486xx 185 * @arg @ref PWR_FLAG_PVMO2 Peripheral Voltage Monitoring Output 2. Indicates whether VDDIO2 voltage is 186 * is below or above PVM2 threshold (applicable when VDDIO2 is present on device). 187 @endif 188 * @arg @ref PWR_FLAG_PVMO3 Peripheral Voltage Monitoring Output 3. Indicates whether VDDA voltage is 189 * is below or above PVM3 threshold. 190 * @arg @ref PWR_FLAG_PVMO4 Peripheral Voltage Monitoring Output 4. Indicates whether VDDA voltage is 191 * is below or above PVM4 threshold. 192 * 193 * @retval The new state of __FLAG__ (TRUE or FALSE). 194 */ 195 #define __HAL_PWR_GET_FLAG(__FLAG__) ( ((((uint8_t)(__FLAG__)) >> 5U) == 1) ?\ 196 (PWR->SR1 & (1U << ((__FLAG__) & 31U))) :\ 197 (PWR->SR2 & (1U << ((__FLAG__) & 31U))) ) 198 199 /** @brief Clear a specific PWR flag. 200 * @param __FLAG__ specifies the flag to clear. 201 * This parameter can be one of the following values: 202 * @arg @ref PWR_FLAG_WUF1 Wake Up Flag 1. Indicates that a wakeup event 203 * was received from the WKUP pin 1. 204 * @arg @ref PWR_FLAG_WUF2 Wake Up Flag 2. Indicates that a wakeup event 205 * was received from the WKUP pin 2. 206 * @arg @ref PWR_FLAG_WUF3 Wake Up Flag 3. Indicates that a wakeup event 207 * was received from the WKUP pin 3. 208 * @arg @ref PWR_FLAG_WUF4 Wake Up Flag 4. Indicates that a wakeup event 209 * was received from the WKUP pin 4. 210 * @arg @ref PWR_FLAG_WUF5 Wake Up Flag 5. Indicates that a wakeup event 211 * was received from the WKUP pin 5. 212 * @arg @ref PWR_FLAG_WU Encompasses all five Wake Up Flags. 213 * @arg @ref PWR_FLAG_SB Standby Flag. Indicates that the system 214 * entered Standby mode. 215 * @retval None 216 */ 217 #define __HAL_PWR_CLEAR_FLAG(__FLAG__) ( (((uint8_t)(__FLAG__)) == PWR_FLAG_WU) ?\ 218 (PWR->SCR = (__FLAG__)) :\ 219 (PWR->SCR = (1U << ((__FLAG__) & 31U))) ) 220 /** 221 * @brief Enable the PVD Extended Interrupt Line. 222 * @retval None 223 */ 224 #define __HAL_PWR_PVD_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR1, PWR_EXTI_LINE_PVD) 225 226 /** 227 * @brief Disable the PVD Extended Interrupt Line. 228 * @retval None 229 */ 230 #define __HAL_PWR_PVD_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR1, PWR_EXTI_LINE_PVD) 231 232 /** 233 * @brief Enable the PVD Event Line. 234 * @retval None 235 */ 236 #define __HAL_PWR_PVD_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR1, PWR_EVENT_LINE_PVD) 237 238 /** 239 * @brief Disable the PVD Event Line. 240 * @retval None 241 */ 242 #define __HAL_PWR_PVD_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR1, PWR_EVENT_LINE_PVD) 243 244 /** 245 * @brief Enable the PVD Extended Interrupt Rising Trigger. 246 * @retval None 247 */ 248 #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR1, PWR_EXTI_LINE_PVD) 249 250 /** 251 * @brief Disable the PVD Extended Interrupt Rising Trigger. 252 * @retval None 253 */ 254 #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR1, PWR_EXTI_LINE_PVD) 255 256 /** 257 * @brief Enable the PVD Extended Interrupt Falling Trigger. 258 * @retval None 259 */ 260 #define __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR1, PWR_EXTI_LINE_PVD) 261 262 263 /** 264 * @brief Disable the PVD Extended Interrupt Falling Trigger. 265 * @retval None 266 */ 267 #define __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR1, PWR_EXTI_LINE_PVD) 268 269 270 /** 271 * @brief Enable the PVD Extended Interrupt Rising & Falling Trigger. 272 * @retval None 273 */ 274 #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_FALLING_EDGE() \ 275 do { \ 276 __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE(); \ 277 __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE(); \ 278 } while(0) 279 280 /** 281 * @brief Disable the PVD Extended Interrupt Rising & Falling Trigger. 282 * @retval None 283 */ 284 #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_FALLING_EDGE() \ 285 do { \ 286 __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE(); \ 287 __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE(); \ 288 } while(0) 289 290 /** 291 * @brief Generate a Software interrupt on selected EXTI line. 292 * @retval None 293 */ 294 #define __HAL_PWR_PVD_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER1, PWR_EXTI_LINE_PVD) 295 296 /** 297 * @brief Check whether or not the PVD EXTI interrupt flag is set. 298 * @retval EXTI PVD Line Status. 299 */ 300 #define __HAL_PWR_PVD_EXTI_GET_FLAG() (EXTI->PR1 & PWR_EXTI_LINE_PVD) 301 302 /** 303 * @brief Clear the PVD EXTI interrupt flag. 304 * @retval None 305 */ 306 #define __HAL_PWR_PVD_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR1, PWR_EXTI_LINE_PVD) 307 308 /** 309 * @} 310 */ 311 312 313 /* Private macros --------------------------------------------------------*/ 314 /** @addtogroup PWR_Private_Macros PWR Private Macros 315 * @{ 316 */ 317 318 #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLEVEL_0) || ((LEVEL) == PWR_PVDLEVEL_1)|| \ 319 ((LEVEL) == PWR_PVDLEVEL_2) || ((LEVEL) == PWR_PVDLEVEL_3)|| \ 320 ((LEVEL) == PWR_PVDLEVEL_4) || ((LEVEL) == PWR_PVDLEVEL_5)|| \ 321 ((LEVEL) == PWR_PVDLEVEL_6) || ((LEVEL) == PWR_PVDLEVEL_7)) 322 323 #define IS_PWR_PVD_MODE(MODE) (((MODE) == PWR_PVD_MODE_NORMAL) ||\ 324 ((MODE) == PWR_PVD_MODE_IT_RISING) ||\ 325 ((MODE) == PWR_PVD_MODE_IT_FALLING) ||\ 326 ((MODE) == PWR_PVD_MODE_IT_RISING_FALLING) ||\ 327 ((MODE) == PWR_PVD_MODE_EVENT_RISING) ||\ 328 ((MODE) == PWR_PVD_MODE_EVENT_FALLING) ||\ 329 ((MODE) == PWR_PVD_MODE_EVENT_RISING_FALLING)) 330 331 #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \ 332 ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON)) 333 334 #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE)) 335 336 #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE) ) 337 338 /** 339 * @} 340 */ 341 342 /* Include PWR HAL Extended module */ 343 #include "stm32l4xx_hal_pwr_ex.h" 344 345 /* Exported functions --------------------------------------------------------*/ 346 347 /** @addtogroup PWR_Exported_Functions PWR Exported Functions 348 * @{ 349 */ 350 351 /** @addtogroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions 352 * @{ 353 */ 354 355 /* Initialization and de-initialization functions *******************************/ 356 void HAL_PWR_DeInit(void); 357 void HAL_PWR_EnableBkUpAccess(void); 358 void HAL_PWR_DisableBkUpAccess(void); 359 360 /** 361 * @} 362 */ 363 364 /** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions 365 * @{ 366 */ 367 368 /* Peripheral Control functions ************************************************/ 369 HAL_StatusTypeDef HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD); 370 void HAL_PWR_EnablePVD(void); 371 void HAL_PWR_DisablePVD(void); 372 373 374 /* WakeUp pins configuration functions ****************************************/ 375 void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity); 376 void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx); 377 378 /* Low Power modes configuration functions ************************************/ 379 void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry); 380 void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry); 381 void HAL_PWR_EnterSTANDBYMode(void); 382 383 void HAL_PWR_EnableSleepOnExit(void); 384 void HAL_PWR_DisableSleepOnExit(void); 385 void HAL_PWR_EnableSEVOnPend(void); 386 void HAL_PWR_DisableSEVOnPend(void); 387 388 void HAL_PWR_PVDCallback(void); 389 390 391 /** 392 * @} 393 */ 394 395 /** 396 * @} 397 */ 398 399 /** 400 * @} 401 */ 402 403 /** 404 * @} 405 */ 406 407 #ifdef __cplusplus 408 } 409 #endif 410 411 412 #endif /* STM32L4xx_HAL_PWR_H */ 413 414 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 415