2 ******************************************************************************
3 * @file stm32g4xx_hal_pwr.h
4 * @author MCD Application Team
5 * @brief Header file of PWR HAL module.
6 ******************************************************************************
9 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.</center></h2>
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
17 ******************************************************************************
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef STM32G4xx_HAL_PWR_H
22 #define STM32G4xx_HAL_PWR_H
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32g4xx_hal_def.h"
31 /** @addtogroup STM32G4xx_HAL_Driver
39 /* Exported types ------------------------------------------------------------*/
41 /** @defgroup PWR_Exported_Types PWR Exported Types
46 * @brief PWR PVD configuration structure definition
50 uint32_t PVDLevel
; /*!< PVDLevel: Specifies the PVD detection level.
51 This parameter can be a value of @ref PWR_PVD_detection_level. */
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. */
62 /* Exported constants --------------------------------------------------------*/
64 /** @defgroup PWR_Exported_Constants PWR Exported Constants
69 /** @defgroup PWR_PVD_detection_level Programmable Voltage Detection levels
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) */
84 /** @defgroup PWR_PVD_Mode PWR PVD interrupt and event mode
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 */
101 /** @defgroup PWR_Regulator_state_in_SLEEP_STOP_mode PWR regulator mode
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 */
110 /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry
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 */
119 /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry
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 */
129 /** @defgroup PWR_PVD_EXTI_LINE PWR PVD external interrupt line
132 #define PWR_EXTI_LINE_PVD ((uint32_t)0x00010000) /*!< External interrupt line 16 Connected to the PVD EXTI Line */
137 /** @defgroup PWR_PVD_EVENT_LINE PWR PVD event line
140 #define PWR_EVENT_LINE_PVD ((uint32_t)0x00010000) /*!< Event line 16 Connected to the PVD Event Line */
149 /* Exported macros -----------------------------------------------------------*/
150 /** @defgroup PWR_Exported_Macros PWR Exported Macros
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_WUFI Wake-Up Flag Internal. Set when a wakeup is detected on
170 * the internal wakeup line.
171 * @arg @ref PWR_FLAG_REGLPS Low Power Regulator Started. Indicates whether or not the
172 * low-power regulator is ready.
173 * @arg @ref PWR_FLAG_REGLPF Low Power Regulator Flag. Indicates whether the
174 * regulator is ready in main mode or is in low-power mode.
175 * @arg @ref PWR_FLAG_VOSF Voltage Scaling Flag. Indicates whether the regulator is ready
176 * in the selected voltage range or is still changing to the required voltage level.
177 * @arg @ref PWR_FLAG_PVDO Power Voltage Detector Output. Indicates whether VDD voltage is
178 * below or above the selected PVD threshold.
180 * @arg @ref PWR_FLAG_PVMO1 Peripheral Voltage Monitoring Output 1. Indicates whether VDDUSB voltage is
181 * is below or above PVM1 threshold (applicable when USB feature is supported).
184 * @arg @ref PWR_FLAG_PVMO2 Peripheral Voltage Monitoring Output 2. Indicates whether VDDIO2 voltage is
185 * is below or above PVM2 threshold (applicable when VDDIO2 is present on device).
187 * @arg @ref PWR_FLAG_PVMO3 Peripheral Voltage Monitoring Output 3. Indicates whether VDDA voltage is
188 * is below or above PVM3 threshold.
189 * @arg @ref PWR_FLAG_PVMO4 Peripheral Voltage Monitoring Output 4. Indicates whether VDDA voltage is
190 * is below or above PVM4 threshold.
192 * @retval The new state of __FLAG__ (TRUE or FALSE).
194 #define __HAL_PWR_GET_FLAG(__FLAG__) ( ((((uint8_t)(__FLAG__)) >> 5U) == 1) ?\
195 (PWR->SR1 & (1U << ((__FLAG__) & 31U))) :\
196 (PWR->SR2 & (1U << ((__FLAG__) & 31U))) )
198 /** @brief Clear a specific PWR flag.
199 * @param __FLAG__: specifies the flag to clear.
200 * This parameter can be one of the following values:
201 * @arg @ref PWR_FLAG_WUF1 Wake Up Flag 1. Indicates that a wakeup event
202 * was received from the WKUP pin 1.
203 * @arg @ref PWR_FLAG_WUF2 Wake Up Flag 2. Indicates that a wakeup event
204 * was received from the WKUP pin 2.
205 * @arg @ref PWR_FLAG_WUF3 Wake Up Flag 3. Indicates that a wakeup event
206 * was received from the WKUP pin 3.
207 * @arg @ref PWR_FLAG_WUF4 Wake Up Flag 4. Indicates that a wakeup event
208 * was received from the WKUP pin 4.
209 * @arg @ref PWR_FLAG_WUF5 Wake Up Flag 5. Indicates that a wakeup event
210 * was received from the WKUP pin 5.
211 * @arg @ref PWR_FLAG_WU Encompasses all five Wake Up Flags.
212 * @arg @ref PWR_FLAG_SB Standby Flag. Indicates that the system
213 * entered Standby mode.
216 #define __HAL_PWR_CLEAR_FLAG(__FLAG__) ( (((uint8_t)(__FLAG__)) == PWR_FLAG_WU) ?\
217 (PWR->SCR = (__FLAG__)) :\
218 (PWR->SCR = (1U << ((__FLAG__) & 31U))) )
220 * @brief Enable the PVD Extended Interrupt Line.
223 #define __HAL_PWR_PVD_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR1, PWR_EXTI_LINE_PVD)
226 * @brief Disable the PVD Extended Interrupt Line.
229 #define __HAL_PWR_PVD_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR1, PWR_EXTI_LINE_PVD)
232 * @brief Enable the PVD Event Line.
235 #define __HAL_PWR_PVD_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR1, PWR_EVENT_LINE_PVD)
238 * @brief Disable the PVD Event Line.
241 #define __HAL_PWR_PVD_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR1, PWR_EVENT_LINE_PVD)
244 * @brief Enable the PVD Extended Interrupt Rising Trigger.
247 #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR1, PWR_EXTI_LINE_PVD)
250 * @brief Disable the PVD Extended Interrupt Rising Trigger.
253 #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR1, PWR_EXTI_LINE_PVD)
256 * @brief Enable the PVD Extended Interrupt Falling Trigger.
259 #define __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR1, PWR_EXTI_LINE_PVD)
263 * @brief Disable the PVD Extended Interrupt Falling Trigger.
266 #define __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR1, PWR_EXTI_LINE_PVD)
270 * @brief Enable the PVD Extended Interrupt Rising & Falling Trigger.
273 #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_FALLING_EDGE() \
275 __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE(); \
276 __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE(); \
280 * @brief Disable the PVD Extended Interrupt Rising & Falling Trigger.
283 #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_FALLING_EDGE() \
285 __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE(); \
286 __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE(); \
290 * @brief Generate a Software interrupt on selected EXTI line.
293 #define __HAL_PWR_PVD_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER1, PWR_EXTI_LINE_PVD)
296 * @brief Check whether or not the PVD EXTI interrupt flag is set.
297 * @retval EXTI PVD Line Status.
299 #define __HAL_PWR_PVD_EXTI_GET_FLAG() (EXTI->PR1 & PWR_EXTI_LINE_PVD)
302 * @brief Clear the PVD EXTI interrupt flag.
305 #define __HAL_PWR_PVD_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR1, PWR_EXTI_LINE_PVD)
312 /* Private macros --------------------------------------------------------*/
313 /** @addtogroup PWR_Private_Macros PWR Private Macros
317 #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLEVEL_0) || ((LEVEL) == PWR_PVDLEVEL_1)|| \
318 ((LEVEL) == PWR_PVDLEVEL_2) || ((LEVEL) == PWR_PVDLEVEL_3)|| \
319 ((LEVEL) == PWR_PVDLEVEL_4) || ((LEVEL) == PWR_PVDLEVEL_5)|| \
320 ((LEVEL) == PWR_PVDLEVEL_6) || ((LEVEL) == PWR_PVDLEVEL_7))
322 #define IS_PWR_PVD_MODE(MODE) (((MODE) == PWR_PVD_MODE_NORMAL) ||\
323 ((MODE) == PWR_PVD_MODE_IT_RISING) ||\
324 ((MODE) == PWR_PVD_MODE_IT_FALLING) ||\
325 ((MODE) == PWR_PVD_MODE_IT_RISING_FALLING) ||\
326 ((MODE) == PWR_PVD_MODE_EVENT_RISING) ||\
327 ((MODE) == PWR_PVD_MODE_EVENT_FALLING) ||\
328 ((MODE) == PWR_PVD_MODE_EVENT_RISING_FALLING))
330 #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \
331 ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON))
333 #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE))
335 #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE) )
341 /* Include PWR HAL Extended module */
342 #include "stm32g4xx_hal_pwr_ex.h"
344 /* Exported functions --------------------------------------------------------*/
346 /** @addtogroup PWR_Exported_Functions PWR Exported Functions
350 /** @addtogroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions
354 /* Initialization and de-initialization functions *******************************/
355 void HAL_PWR_DeInit(void);
356 void HAL_PWR_EnableBkUpAccess(void);
357 void HAL_PWR_DisableBkUpAccess(void);
363 /** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions
367 /* Peripheral Control functions ************************************************/
368 HAL_StatusTypeDef
HAL_PWR_ConfigPVD(PWR_PVDTypeDef
*sConfigPVD
);
369 void HAL_PWR_EnablePVD(void);
370 void HAL_PWR_DisablePVD(void);
373 /* WakeUp pins configuration functions ****************************************/
374 void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity
);
375 void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx
);
377 /* Low Power modes configuration functions ************************************/
378 void HAL_PWR_EnterSLEEPMode(uint32_t Regulator
, uint8_t SLEEPEntry
);
379 void HAL_PWR_EnterSTOPMode(uint32_t Regulator
, uint8_t STOPEntry
);
380 void HAL_PWR_EnterSTANDBYMode(void);
382 void HAL_PWR_EnableSleepOnExit(void);
383 void HAL_PWR_DisableSleepOnExit(void);
384 void HAL_PWR_EnableSEVOnPend(void);
385 void HAL_PWR_DisableSEVOnPend(void);
387 void HAL_PWR_PVDCallback(void);
411 #endif /* STM32G4xx_HAL_PWR_H */
413 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/