2 ******************************************************************************
\r
3 * @file stm32l4xx_hal_pwr.h
\r
4 * @author MCD Application Team
\r
5 * @brief Header file of PWR HAL module.
\r
6 ******************************************************************************
\r
9 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
\r
10 * All rights reserved.</center></h2>
\r
12 * This software component is licensed by ST under BSD 3-Clause license,
\r
13 * the "License"; You may not use this file except in compliance with the
\r
14 * License. You may obtain a copy of the License at:
\r
15 * opensource.org/licenses/BSD-3-Clause
\r
17 ******************************************************************************
\r
20 /* Define to prevent recursive inclusion -------------------------------------*/
\r
21 #ifndef __STM32L4xx_HAL_PWR_H
\r
22 #define __STM32L4xx_HAL_PWR_H
\r
28 /* Includes ------------------------------------------------------------------*/
\r
29 #include "stm32l4xx_hal_def.h"
\r
31 /** @addtogroup STM32L4xx_HAL_Driver
\r
39 /* Exported types ------------------------------------------------------------*/
\r
41 /** @defgroup PWR_Exported_Types PWR Exported Types
\r
46 * @brief PWR PVD configuration structure definition
\r
50 uint32_t PVDLevel; /*!< PVDLevel: Specifies the PVD detection level.
\r
51 This parameter can be a value of @ref PWR_PVD_detection_level. */
\r
53 uint32_t Mode; /*!< Mode: Specifies the operating mode for the selected pins.
\r
54 This parameter can be a value of @ref PWR_PVD_Mode. */
\r
62 /* Exported constants --------------------------------------------------------*/
\r
64 /** @defgroup PWR_Exported_Constants PWR Exported Constants
\r
69 /** @defgroup PWR_PVD_detection_level Programmable Voltage Detection levels
\r
72 #define PWR_PVDLEVEL_0 PWR_CR2_PLS_LEV0 /*!< PVD threshold around 2.0 V */
\r
73 #define PWR_PVDLEVEL_1 PWR_CR2_PLS_LEV1 /*!< PVD threshold around 2.2 V */
\r
74 #define PWR_PVDLEVEL_2 PWR_CR2_PLS_LEV2 /*!< PVD threshold around 2.4 V */
\r
75 #define PWR_PVDLEVEL_3 PWR_CR2_PLS_LEV3 /*!< PVD threshold around 2.5 V */
\r
76 #define PWR_PVDLEVEL_4 PWR_CR2_PLS_LEV4 /*!< PVD threshold around 2.6 V */
\r
77 #define PWR_PVDLEVEL_5 PWR_CR2_PLS_LEV5 /*!< PVD threshold around 2.8 V */
\r
78 #define PWR_PVDLEVEL_6 PWR_CR2_PLS_LEV6 /*!< PVD threshold around 2.9 V */
\r
79 #define PWR_PVDLEVEL_7 PWR_CR2_PLS_LEV7 /*!< External input analog voltage (compared internally to VREFINT) */
\r
84 /** @defgroup PWR_PVD_Mode PWR PVD interrupt and event mode
\r
87 #define PWR_PVD_MODE_NORMAL ((uint32_t)0x00000000) /*!< Basic mode is used */
\r
88 #define PWR_PVD_MODE_IT_RISING ((uint32_t)0x00010001) /*!< External Interrupt Mode with Rising edge trigger detection */
\r
89 #define PWR_PVD_MODE_IT_FALLING ((uint32_t)0x00010002) /*!< External Interrupt Mode with Falling edge trigger detection */
\r
90 #define PWR_PVD_MODE_IT_RISING_FALLING ((uint32_t)0x00010003) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
\r
91 #define PWR_PVD_MODE_EVENT_RISING ((uint32_t)0x00020001) /*!< Event Mode with Rising edge trigger detection */
\r
92 #define PWR_PVD_MODE_EVENT_FALLING ((uint32_t)0x00020002) /*!< Event Mode with Falling edge trigger detection */
\r
93 #define PWR_PVD_MODE_EVENT_RISING_FALLING ((uint32_t)0x00020003) /*!< Event Mode with Rising/Falling edge trigger detection */
\r
101 /** @defgroup PWR_Regulator_state_in_SLEEP_STOP_mode PWR regulator mode
\r
104 #define PWR_MAINREGULATOR_ON ((uint32_t)0x00000000) /*!< Regulator in main mode */
\r
105 #define PWR_LOWPOWERREGULATOR_ON PWR_CR1_LPR /*!< Regulator in low-power mode */
\r
110 /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry
\r
113 #define PWR_SLEEPENTRY_WFI ((uint8_t)0x01) /*!< Wait For Interruption instruction to enter Sleep mode */
\r
114 #define PWR_SLEEPENTRY_WFE ((uint8_t)0x02) /*!< Wait For Event instruction to enter Sleep mode */
\r
119 /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry
\r
122 #define PWR_STOPENTRY_WFI ((uint8_t)0x01) /*!< Wait For Interruption instruction to enter Stop mode */
\r
123 #define PWR_STOPENTRY_WFE ((uint8_t)0x02) /*!< Wait For Event instruction to enter Stop mode */
\r
129 /** @defgroup PWR_PVD_EXTI_LINE PWR PVD external interrupt line
\r
132 #define PWR_EXTI_LINE_PVD ((uint32_t)0x00010000) /*!< External interrupt line 16 Connected to the PVD EXTI Line */
\r
137 /** @defgroup PWR_PVD_EVENT_LINE PWR PVD event line
\r
140 #define PWR_EVENT_LINE_PVD ((uint32_t)0x00010000) /*!< Event line 16 Connected to the PVD Event Line */
\r
149 /* Exported macros -----------------------------------------------------------*/
\r
150 /** @defgroup PWR_Exported_Macros PWR Exported Macros
\r
154 /** @brief Check whether or not a specific PWR flag is set.
\r
155 * @param __FLAG__: specifies the flag to check.
\r
156 * This parameter can be one of the following values:
\r
157 * @arg @ref PWR_FLAG_WUF1 Wake Up Flag 1. Indicates that a wakeup event
\r
158 * was received from the WKUP pin 1.
\r
159 * @arg @ref PWR_FLAG_WUF2 Wake Up Flag 2. Indicates that a wakeup event
\r
160 * was received from the WKUP pin 2.
\r
161 * @arg @ref PWR_FLAG_WUF3 Wake Up Flag 3. Indicates that a wakeup event
\r
162 * was received from the WKUP pin 3.
\r
163 * @arg @ref PWR_FLAG_WUF4 Wake Up Flag 4. Indicates that a wakeup event
\r
164 * was received from the WKUP pin 4.
\r
165 * @arg @ref PWR_FLAG_WUF5 Wake Up Flag 5. Indicates that a wakeup event
\r
166 * was received from the WKUP pin 5.
\r
167 * @arg @ref PWR_FLAG_SB StandBy Flag. Indicates that the system
\r
168 * entered StandBy mode.
\r
169 * @arg @ref PWR_FLAG_EXT_SMPS External SMPS Ready Flag. When available on device, indicates
\r
170 * that external switch can be closed to connect to the external SMPS, when the Range 2
\r
171 * of internal regulator is ready.
\r
172 * @arg @ref PWR_FLAG_WUFI Wake-Up Flag Internal. Set when a wakeup is detected on
\r
173 * the internal wakeup line.
\r
174 * @arg @ref PWR_FLAG_REGLPS Low Power Regulator Started. Indicates whether or not the
\r
175 * low-power regulator is ready.
\r
176 * @arg @ref PWR_FLAG_REGLPF Low Power Regulator Flag. Indicates whether the
\r
177 * regulator is ready in main mode or is in low-power mode.
\r
178 * @arg @ref PWR_FLAG_VOSF Voltage Scaling Flag. Indicates whether the regulator is ready
\r
179 * in the selected voltage range or is still changing to the required voltage level.
\r
180 * @arg @ref PWR_FLAG_PVDO Power Voltage Detector Output. Indicates whether VDD voltage is
\r
181 * below or above the selected PVD threshold.
\r
182 * @arg @ref PWR_FLAG_PVMO1 Peripheral Voltage Monitoring Output 1. Indicates whether VDDUSB voltage is
\r
183 * is below or above PVM1 threshold (applicable when USB feature is supported).
\r
185 * @arg @ref PWR_FLAG_PVMO2 Peripheral Voltage Monitoring Output 2. Indicates whether VDDIO2 voltage is
\r
186 * is below or above PVM2 threshold (applicable when VDDIO2 is present on device).
\r
188 * @arg @ref PWR_FLAG_PVMO3 Peripheral Voltage Monitoring Output 3. Indicates whether VDDA voltage is
\r
189 * is below or above PVM3 threshold.
\r
190 * @arg @ref PWR_FLAG_PVMO4 Peripheral Voltage Monitoring Output 4. Indicates whether VDDA voltage is
\r
191 * is below or above PVM4 threshold.
\r
193 * @retval The new state of __FLAG__ (TRUE or FALSE).
\r
195 #define __HAL_PWR_GET_FLAG(__FLAG__) ( ((((uint8_t)(__FLAG__)) >> 5U) == 1) ?\
\r
196 (PWR->SR1 & (1U << ((__FLAG__) & 31U))) :\
\r
197 (PWR->SR2 & (1U << ((__FLAG__) & 31U))) )
\r
199 /** @brief Clear a specific PWR flag.
\r
200 * @param __FLAG__: specifies the flag to clear.
\r
201 * This parameter can be one of the following values:
\r
202 * @arg @ref PWR_FLAG_WUF1 Wake Up Flag 1. Indicates that a wakeup event
\r
203 * was received from the WKUP pin 1.
\r
204 * @arg @ref PWR_FLAG_WUF2 Wake Up Flag 2. Indicates that a wakeup event
\r
205 * was received from the WKUP pin 2.
\r
206 * @arg @ref PWR_FLAG_WUF3 Wake Up Flag 3. Indicates that a wakeup event
\r
207 * was received from the WKUP pin 3.
\r
208 * @arg @ref PWR_FLAG_WUF4 Wake Up Flag 4. Indicates that a wakeup event
\r
209 * was received from the WKUP pin 4.
\r
210 * @arg @ref PWR_FLAG_WUF5 Wake Up Flag 5. Indicates that a wakeup event
\r
211 * was received from the WKUP pin 5.
\r
212 * @arg @ref PWR_FLAG_WU Encompasses all five Wake Up Flags.
\r
213 * @arg @ref PWR_FLAG_SB Standby Flag. Indicates that the system
\r
214 * entered Standby mode.
\r
217 #define __HAL_PWR_CLEAR_FLAG(__FLAG__) ( (((uint8_t)(__FLAG__)) == PWR_FLAG_WU) ?\
\r
218 (PWR->SCR = (__FLAG__)) :\
\r
219 (PWR->SCR = (1U << ((__FLAG__) & 31U))) )
\r
221 * @brief Enable the PVD Extended Interrupt Line.
\r
224 #define __HAL_PWR_PVD_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR1, PWR_EXTI_LINE_PVD)
\r
227 * @brief Disable the PVD Extended Interrupt Line.
\r
230 #define __HAL_PWR_PVD_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR1, PWR_EXTI_LINE_PVD)
\r
233 * @brief Enable the PVD Event Line.
\r
236 #define __HAL_PWR_PVD_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR1, PWR_EVENT_LINE_PVD)
\r
239 * @brief Disable the PVD Event Line.
\r
242 #define __HAL_PWR_PVD_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR1, PWR_EVENT_LINE_PVD)
\r
245 * @brief Enable the PVD Extended Interrupt Rising Trigger.
\r
248 #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR1, PWR_EXTI_LINE_PVD)
\r
251 * @brief Disable the PVD Extended Interrupt Rising Trigger.
\r
254 #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR1, PWR_EXTI_LINE_PVD)
\r
257 * @brief Enable the PVD Extended Interrupt Falling Trigger.
\r
260 #define __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR1, PWR_EXTI_LINE_PVD)
\r
264 * @brief Disable the PVD Extended Interrupt Falling Trigger.
\r
267 #define __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR1, PWR_EXTI_LINE_PVD)
\r
271 * @brief Enable the PVD Extended Interrupt Rising & Falling Trigger.
\r
274 #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_FALLING_EDGE() \
\r
276 __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE(); \
\r
277 __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE(); \
\r
281 * @brief Disable the PVD Extended Interrupt Rising & Falling Trigger.
\r
284 #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_FALLING_EDGE() \
\r
286 __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE(); \
\r
287 __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE(); \
\r
291 * @brief Generate a Software interrupt on selected EXTI line.
\r
294 #define __HAL_PWR_PVD_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER1, PWR_EXTI_LINE_PVD)
\r
297 * @brief Check whether or not the PVD EXTI interrupt flag is set.
\r
298 * @retval EXTI PVD Line Status.
\r
300 #define __HAL_PWR_PVD_EXTI_GET_FLAG() (EXTI->PR1 & PWR_EXTI_LINE_PVD)
\r
303 * @brief Clear the PVD EXTI interrupt flag.
\r
306 #define __HAL_PWR_PVD_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR1, PWR_EXTI_LINE_PVD)
\r
313 /* Private macros --------------------------------------------------------*/
\r
314 /** @addtogroup PWR_Private_Macros PWR Private Macros
\r
318 #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLEVEL_0) || ((LEVEL) == PWR_PVDLEVEL_1)|| \
\r
319 ((LEVEL) == PWR_PVDLEVEL_2) || ((LEVEL) == PWR_PVDLEVEL_3)|| \
\r
320 ((LEVEL) == PWR_PVDLEVEL_4) || ((LEVEL) == PWR_PVDLEVEL_5)|| \
\r
321 ((LEVEL) == PWR_PVDLEVEL_6) || ((LEVEL) == PWR_PVDLEVEL_7))
\r
323 #define IS_PWR_PVD_MODE(MODE) (((MODE) == PWR_PVD_MODE_NORMAL) ||\
\r
324 ((MODE) == PWR_PVD_MODE_IT_RISING) ||\
\r
325 ((MODE) == PWR_PVD_MODE_IT_FALLING) ||\
\r
326 ((MODE) == PWR_PVD_MODE_IT_RISING_FALLING) ||\
\r
327 ((MODE) == PWR_PVD_MODE_EVENT_RISING) ||\
\r
328 ((MODE) == PWR_PVD_MODE_EVENT_FALLING) ||\
\r
329 ((MODE) == PWR_PVD_MODE_EVENT_RISING_FALLING))
\r
331 #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \
\r
332 ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON))
\r
334 #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE))
\r
336 #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE) )
\r
342 /* Include PWR HAL Extended module */
\r
343 #include "stm32l4xx_hal_pwr_ex.h"
\r
345 /* Exported functions --------------------------------------------------------*/
\r
347 /** @addtogroup PWR_Exported_Functions PWR Exported Functions
\r
351 /** @addtogroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions
\r
355 /* Initialization and de-initialization functions *******************************/
\r
356 void HAL_PWR_DeInit(void);
\r
357 void HAL_PWR_EnableBkUpAccess(void);
\r
358 void HAL_PWR_DisableBkUpAccess(void);
\r
364 /** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions
\r
368 /* Peripheral Control functions ************************************************/
\r
369 HAL_StatusTypeDef HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD);
\r
370 void HAL_PWR_EnablePVD(void);
\r
371 void HAL_PWR_DisablePVD(void);
\r
374 /* WakeUp pins configuration functions ****************************************/
\r
375 void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity);
\r
376 void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx);
\r
378 /* Low Power modes configuration functions ************************************/
\r
379 void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry);
\r
380 void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
\r
381 void HAL_PWR_EnterSTANDBYMode(void);
\r
383 void HAL_PWR_EnableSleepOnExit(void);
\r
384 void HAL_PWR_DisableSleepOnExit(void);
\r
385 void HAL_PWR_EnableSEVOnPend(void);
\r
386 void HAL_PWR_DisableSEVOnPend(void);
\r
388 void HAL_PWR_PVDCallback(void);
\r
412 #endif /* __STM32L4xx_HAL_PWR_H */
\r
414 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r