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