1 | /** |
---|
2 | ****************************************************************************** |
---|
3 | * @file stm32g0xx_hal_pwr.h |
---|
4 | * @author MCD Application Team |
---|
5 | * @brief Header file of PWR HAL module. |
---|
6 | ****************************************************************************** |
---|
7 | * @attention |
---|
8 | * |
---|
9 | * Copyright (c) 2018 STMicroelectronics. |
---|
10 | * All rights reserved. |
---|
11 | * |
---|
12 | * This software is licensed under terms that can be found in the LICENSE file |
---|
13 | * in the root directory of this software component. |
---|
14 | * If no LICENSE file comes with this software, it is provided AS-IS. |
---|
15 | * |
---|
16 | ****************************************************************************** |
---|
17 | */ |
---|
18 | |
---|
19 | /* Define to prevent recursive inclusion -------------------------------------*/ |
---|
20 | #ifndef STM32G0xx_HAL_PWR_H |
---|
21 | #define STM32G0xx_HAL_PWR_H |
---|
22 | |
---|
23 | #ifdef __cplusplus |
---|
24 | extern "C" { |
---|
25 | #endif |
---|
26 | |
---|
27 | /* Includes ------------------------------------------------------------------*/ |
---|
28 | #include "stm32g0xx_hal_def.h" |
---|
29 | |
---|
30 | /** @addtogroup STM32G0xx_HAL_Driver |
---|
31 | * @{ |
---|
32 | */ |
---|
33 | |
---|
34 | /** @defgroup PWR PWR |
---|
35 | * @brief PWR HAL module driver |
---|
36 | * @{ |
---|
37 | */ |
---|
38 | |
---|
39 | /* Exported types ------------------------------------------------------------*/ |
---|
40 | /** @defgroup PWR_Exported_Types PWR Exported Types |
---|
41 | * @{ |
---|
42 | */ |
---|
43 | |
---|
44 | /** |
---|
45 | * @} |
---|
46 | */ |
---|
47 | |
---|
48 | /* Exported constants --------------------------------------------------------*/ |
---|
49 | /** @defgroup PWR_Exported_Constants PWR Exported Constants |
---|
50 | * @{ |
---|
51 | */ |
---|
52 | |
---|
53 | /** @defgroup PWR_WakeUp_Pins PWR WakeUp pins |
---|
54 | * @{ |
---|
55 | */ |
---|
56 | #define PWR_WAKEUP_PIN1 PWR_CR3_EWUP1 /*!< Wakeup pin 1 (with high level detection) */ |
---|
57 | #define PWR_WAKEUP_PIN2 PWR_CR3_EWUP2 /*!< Wakeup pin 2 (with high level detection) */ |
---|
58 | #if defined(PWR_CR3_EWUP3) |
---|
59 | #define PWR_WAKEUP_PIN3 PWR_CR3_EWUP3 /*!< Wakeup pin 3 (with high level detection) */ |
---|
60 | #endif /* PWR_CR3_EWUP3 */ |
---|
61 | #define PWR_WAKEUP_PIN4 PWR_CR3_EWUP4 /*!< Wakeup pin 4 (with high level detection) */ |
---|
62 | #if defined(PWR_CR3_EWUP5) |
---|
63 | #define PWR_WAKEUP_PIN5 PWR_CR3_EWUP5 /*!< Wakeup pin 5 (with high level detection) */ |
---|
64 | #endif /* PWR_CR3_EWUP5 */ |
---|
65 | #define PWR_WAKEUP_PIN6 PWR_CR3_EWUP6 /*!< Wakeup pin 6 (with high level detection) */ |
---|
66 | #define PWR_WAKEUP_PIN1_HIGH PWR_CR3_EWUP1 /*!< Wakeup pin 1 (with high level detection) */ |
---|
67 | #define PWR_WAKEUP_PIN2_HIGH PWR_CR3_EWUP2 /*!< Wakeup pin 2 (with high level detection) */ |
---|
68 | #if defined(PWR_CR3_EWUP3) |
---|
69 | #define PWR_WAKEUP_PIN3_HIGH PWR_CR3_EWUP3 /*!< Wakeup pin 3 (with high level detection) */ |
---|
70 | #endif /* PWR_CR3_EWUP3 */ |
---|
71 | #define PWR_WAKEUP_PIN4_HIGH PWR_CR3_EWUP4 /*!< Wakeup pin 4 (with high level detection) */ |
---|
72 | #if defined(PWR_CR3_EWUP5) |
---|
73 | #define PWR_WAKEUP_PIN5_HIGH PWR_CR3_EWUP5 /*!< Wakeup pin 5 (with high level detection) */ |
---|
74 | #endif /* PWR_CR3_EWUP5*/ |
---|
75 | #define PWR_WAKEUP_PIN6_HIGH PWR_CR3_EWUP6 /*!< Wakeup pin 6 (with high level detection) */ |
---|
76 | #define PWR_WAKEUP_PIN1_LOW ((PWR_CR4_WP1 << PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP1) /*!< Wakeup pin 1 (with low level detection) */ |
---|
77 | #define PWR_WAKEUP_PIN2_LOW ((PWR_CR4_WP2 << PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP2) /*!< Wakeup pin 2 (with low level detection) */ |
---|
78 | #if defined(PWR_CR3_EWUP3) |
---|
79 | #define PWR_WAKEUP_PIN3_LOW ((PWR_CR4_WP3 << PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP3) /*!< Wakeup pin 3 (with low level detection) */ |
---|
80 | #endif /* PWR_CR3_EWUP3 */ |
---|
81 | #define PWR_WAKEUP_PIN4_LOW ((PWR_CR4_WP4 << PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP4) /*!< Wakeup pin 4 (with low level detection) */ |
---|
82 | #if defined(PWR_CR3_EWUP5) |
---|
83 | #define PWR_WAKEUP_PIN5_LOW ((PWR_CR4_WP5 << PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP5) /*!< Wakeup pin 5 (with low level detection) */ |
---|
84 | #endif /* PWR_CR3_EWUP5 */ |
---|
85 | #define PWR_WAKEUP_PIN6_LOW ((PWR_CR4_WP6 << PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP6) /*!< Wakeup pin 6 (with low level detection) */ |
---|
86 | /** |
---|
87 | * @} |
---|
88 | */ |
---|
89 | |
---|
90 | /** @defgroup PWR_Low_Power_Mode_Selection PWR Low Power Mode Selection |
---|
91 | * @{ |
---|
92 | */ |
---|
93 | #define PWR_LOWPOWERMODE_STOP0 (0x00000000u) /*!< Stop 0: stop mode with main regulator */ |
---|
94 | #define PWR_LOWPOWERMODE_STOP1 (PWR_CR1_LPMS_0) /*!< Stop 1: stop mode with low power regulator */ |
---|
95 | #define PWR_LOWPOWERMODE_STANDBY (PWR_CR1_LPMS_0 | PWR_CR1_LPMS_1) /*!< Standby mode */ |
---|
96 | #if defined(PWR_SHDW_SUPPORT) |
---|
97 | #define PWR_LOWPOWERMODE_SHUTDOWN (PWR_CR1_LPMS_2) /*!< Shutdown mode */ |
---|
98 | #endif /* PWR_SHDW_SUPPORT */ |
---|
99 | /** |
---|
100 | * @} |
---|
101 | */ |
---|
102 | |
---|
103 | /** @defgroup PWR_Regulator_state_in_SLEEP_STOP_mode PWR regulator mode |
---|
104 | * @{ |
---|
105 | */ |
---|
106 | #define PWR_MAINREGULATOR_ON (0x00000000u) /*!< Regulator in main mode */ |
---|
107 | #define PWR_LOWPOWERREGULATOR_ON PWR_CR1_LPR /*!< Regulator in low-power mode */ |
---|
108 | /** |
---|
109 | * @} |
---|
110 | */ |
---|
111 | |
---|
112 | /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry |
---|
113 | * @{ |
---|
114 | */ |
---|
115 | #define PWR_SLEEPENTRY_WFI ((uint8_t)0x01u) /*!< Wait For Interruption instruction to enter Sleep mode */ |
---|
116 | #define PWR_SLEEPENTRY_WFE ((uint8_t)0x02u) /*!< Wait For Event instruction to enter Sleep mode */ |
---|
117 | /** |
---|
118 | * @} |
---|
119 | */ |
---|
120 | |
---|
121 | /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry |
---|
122 | * @{ |
---|
123 | */ |
---|
124 | #define PWR_STOPENTRY_WFI ((uint8_t)0x01u) /*!< Wait For Interruption instruction to enter Stop mode */ |
---|
125 | #define PWR_STOPENTRY_WFE ((uint8_t)0x02u) /*!< Wait For Event instruction to enter Stop mode */ |
---|
126 | /** |
---|
127 | * @} |
---|
128 | */ |
---|
129 | |
---|
130 | /** @defgroup PWR_Flag PWR Status Flags |
---|
131 | * @brief Elements values convention: 0000 00XX 000Y YYYYb |
---|
132 | * - Y YYYY : Flag position in the XX register (5 bits) |
---|
133 | * - XX : Status register (2 bits) |
---|
134 | * - 01: SR1 register |
---|
135 | * - 10: SR2 register |
---|
136 | * The only exception is PWR_FLAG_WU, encompassing all |
---|
137 | * wake-up flags and set to PWR_SR1_WUF. |
---|
138 | * @{ |
---|
139 | */ |
---|
140 | #define PWR_FLAG_WUF1 (0x00010000u | PWR_SR1_WUF1) /*!< Wakeup event on wakeup pin 1 */ |
---|
141 | #define PWR_FLAG_WUF2 (0x00010000u | PWR_SR1_WUF2) /*!< Wakeup event on wakeup pin 2 */ |
---|
142 | #if defined(PWR_CR3_EWUP3) |
---|
143 | #define PWR_FLAG_WUF3 (0x00010000u | PWR_SR1_WUF3) /*!< Wakeup event on wakeup pin 3 */ |
---|
144 | #endif /* PWR_CR3_EWUP3 */ |
---|
145 | #define PWR_FLAG_WUF4 (0x00010000u | PWR_SR1_WUF4) /*!< Wakeup event on wakeup pin 4 */ |
---|
146 | #if defined(PWR_CR3_EWUP5) |
---|
147 | #define PWR_FLAG_WUF5 (0x00010000u | PWR_SR1_WUF5) /*!< Wakeup event on wakeup pin 5 */ |
---|
148 | #endif /* PWR_CR3_EWUP5 */ |
---|
149 | #define PWR_FLAG_WUF6 (0x00010000u | PWR_SR1_WUF6) /*!< Wakeup event on wakeup pin 6 */ |
---|
150 | #define PWR_FLAG_WUF (0x00010000u | PWR_SR1_WUF) /*!< Wakeup event on all wakeup pin */ |
---|
151 | #define PWR_FLAG_SB (0x00010000u | PWR_SR1_SBF) /*!< Standby flag */ |
---|
152 | #define PWR_FLAG_WUFI (0x00010000u | PWR_SR1_WUFI) /*!< Wakeup on internal wakeup line */ |
---|
153 | #define PWR_FLAG_FLASH_READY (0x00020000u | PWR_SR2_FLASH_RDY) /*!< Flash ready */ |
---|
154 | #define PWR_FLAG_REGLPS (0x00020000u | PWR_SR2_REGLPS) /*!< Regulator Low Power started */ |
---|
155 | #define PWR_FLAG_REGLPF (0x00020000u | PWR_SR2_REGLPF) /*!< Regulator Low Power flag */ |
---|
156 | #if defined(PWR_PVD_SUPPORT) |
---|
157 | #define PWR_FLAG_PVDO (0x00020000u | PWR_SR2_PVDO) /*!< Power Voltage Detector output */ |
---|
158 | #endif /* PWR_PVD_SUPPORT */ |
---|
159 | #if defined(PWR_PVM_SUPPORT) |
---|
160 | #define PWR_FLAG_PVMO_USB (0x00020000u | PWR_SR2_PVMO_USB) /*!< Power Voltage Monitoring output */ |
---|
161 | #endif /* PWR_PVM_SUPPORT */ |
---|
162 | |
---|
163 | /** |
---|
164 | * @} |
---|
165 | */ |
---|
166 | |
---|
167 | /** |
---|
168 | * @} |
---|
169 | */ |
---|
170 | |
---|
171 | /* Exported macros -----------------------------------------------------------*/ |
---|
172 | /** @defgroup PWR_Exported_Macros PWR Exported Macros |
---|
173 | * @{ |
---|
174 | */ |
---|
175 | /** @brief Check whether or not a specific PWR flag is set. |
---|
176 | * @param __FLAG__ specifies the flag to check. |
---|
177 | * This parameter can be one a combination of following values: |
---|
178 | * @arg PWR_FLAG_WUF1: Wake Up Flag 1. Indicates that a wakeup event |
---|
179 | * was received from the WKUP pin 1. |
---|
180 | * @arg PWR_FLAG_WUF2: Wake Up Flag 2. Indicates that a wakeup event |
---|
181 | * was received from the WKUP pin 2. |
---|
182 | * @arg PWR_FLAG_WUF3: Wake Up Flag 3. Indicates that a wakeup event |
---|
183 | * was received from the WKUP pin 3. (*) |
---|
184 | * @arg PWR_FLAG_WUF4: Wake Up Flag 4. Indicates that a wakeup event |
---|
185 | * was received from the WKUP pin 4. |
---|
186 | * @arg PWR_FLAG_WUF5: Wake Up Flag 5. Indicates that a wakeup event |
---|
187 | * was received from the WKUP pin 5. (*) |
---|
188 | * @arg PWR_FLAG_WUF6: Wake Up Flag 6. Indicates that a wakeup event |
---|
189 | * was received from the WKUP pin 6. |
---|
190 | * @arg PWR_FLAG_SB: StandBy Flag. Indicates that the system |
---|
191 | * entered StandBy mode. |
---|
192 | * @arg PWR_FLAG_WUFI: Wake-Up Flag Internal. Set when a wakeup is |
---|
193 | * detected on the internal wakeup line. |
---|
194 | * OR a combination of following values: |
---|
195 | * @arg PWR_FLAG_FLASH_READY: Flash is ready. Indicates whether flash |
---|
196 | * can be used or not |
---|
197 | * @arg PWR_FLAG_REGLPS: Low Power Regulator Started. Indicates whether |
---|
198 | * or not the low-power regulator is ready. |
---|
199 | * @arg PWR_FLAG_REGLPF: Low Power Regulator Flag. Indicates whether the |
---|
200 | * regulator is ready in main mode or is in low-power mode. |
---|
201 | * @if defined(STM32G081xx) |
---|
202 | * @arg PWR_FLAG_PVDO: Power Voltage Detector Output. Indicates whether |
---|
203 | * VDD voltage is below or above the selected PVD threshold. |
---|
204 | * @endif |
---|
205 | * @retval The new state of __FLAG__ (TRUE or FALSE). |
---|
206 | */ |
---|
207 | #define __HAL_PWR_GET_FLAG(__FLAG__) (((__FLAG__) & 0x00010000u) ?\ |
---|
208 | ((PWR->SR1 & ((__FLAG__) & ~0x00030000u)) == ((__FLAG__) & ~0x00030000u)) :\ |
---|
209 | ((PWR->SR2 & ((__FLAG__) & ~0x00030000u)) == ((__FLAG__) & ~0x00030000u))) |
---|
210 | |
---|
211 | /** @brief Clear a specific PWR flag. |
---|
212 | * @param __FLAG__ specifies the flag to clear. |
---|
213 | * This parameter can be a combination of following values: |
---|
214 | * @arg PWR_FLAG_WUF1: Wake Up Flag 1. Indicates that a wakeup event |
---|
215 | * was received from the WKUP pin 1. |
---|
216 | * @arg PWR_FLAG_WUF2: Wake Up Flag 2. Indicates that a wakeup event |
---|
217 | * was received from the WKUP pin 2. |
---|
218 | * @arg PWR_FLAG_WUF3: Wake Up Flag 3. Indicates that a wakeup event |
---|
219 | * was received from the WKUP pin 3. (*) |
---|
220 | * @arg PWR_FLAG_WUF4: Wake Up Flag 4. Indicates that a wakeup event |
---|
221 | * was received from the WKUP pin 4. |
---|
222 | * @arg PWR_FLAG_WUF5: Wake Up Flag 5. Indicates that a wakeup event |
---|
223 | * was received from the WKUP pin 5. (*) |
---|
224 | * @arg PWR_FLAG_WUF6: Wake Up Flag 6. Indicates that a wakeup event |
---|
225 | * was received from the WKUP pin 6. |
---|
226 | * @arg PWR_FLAG_WUF: Encompasses all Wake Up Flags. |
---|
227 | * @arg PWR_FLAG_SB: Standby Flag. Indicates that the system |
---|
228 | * entered Standby mode. |
---|
229 | * @retval None |
---|
230 | */ |
---|
231 | #define __HAL_PWR_CLEAR_FLAG(__FLAG__) (PWR->SCR = (__FLAG__)) |
---|
232 | |
---|
233 | /** |
---|
234 | * @} |
---|
235 | */ |
---|
236 | |
---|
237 | /* Private constants-------------------------------------------------------*/ |
---|
238 | /** @defgroup PWR_WUP_Polarity Shift to apply to retrieve polarity information from PWR_WAKEUP_PINy_xxx constants |
---|
239 | * @{ |
---|
240 | */ |
---|
241 | #define PWR_WUP_POLARITY_SHIFT 0x08u /*!< Internal constant used to retrieve wakeup pin polariry */ |
---|
242 | /** |
---|
243 | * @} |
---|
244 | */ |
---|
245 | |
---|
246 | /* Private macros --------------------------------------------------------*/ |
---|
247 | /** @defgroup PWR_Private_Macros PWR Private Macros |
---|
248 | * @{ |
---|
249 | */ |
---|
250 | |
---|
251 | #define IS_PWR_WAKEUP_PIN(PIN) ((((PIN) & ((PWR_CR4_WP << 8U) | (PWR_CR3_EWUP))) != 0x00000000u) && \ |
---|
252 | (((PIN) & ~((PWR_CR4_WP << 8U) | (PWR_CR3_EWUP))) == 0x00000000u)) |
---|
253 | |
---|
254 | #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \ |
---|
255 | ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON)) |
---|
256 | |
---|
257 | #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || \ |
---|
258 | ((ENTRY) == PWR_SLEEPENTRY_WFE)) |
---|
259 | |
---|
260 | #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || \ |
---|
261 | ((ENTRY) == PWR_STOPENTRY_WFE)) |
---|
262 | /** |
---|
263 | * @} |
---|
264 | */ |
---|
265 | |
---|
266 | /* Include PWR HAL Extended module */ |
---|
267 | #include "stm32g0xx_hal_pwr_ex.h" |
---|
268 | |
---|
269 | /* Exported functions --------------------------------------------------------*/ |
---|
270 | /** @defgroup PWR_Exported_Functions PWR Exported Functions |
---|
271 | * @{ |
---|
272 | */ |
---|
273 | |
---|
274 | /** @defgroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions |
---|
275 | * @{ |
---|
276 | */ |
---|
277 | |
---|
278 | /* Initialization and de-initialization functions *******************************/ |
---|
279 | void HAL_PWR_DeInit(void); |
---|
280 | /** |
---|
281 | * @} |
---|
282 | */ |
---|
283 | |
---|
284 | /** @defgroup PWR_Exported_Functions_Group2 Peripheral Control functions |
---|
285 | * @{ |
---|
286 | */ |
---|
287 | /* Peripheral Control functions ************************************************/ |
---|
288 | void HAL_PWR_EnableBkUpAccess(void); |
---|
289 | void HAL_PWR_DisableBkUpAccess(void); |
---|
290 | |
---|
291 | /* WakeUp pins configuration functions ****************************************/ |
---|
292 | void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity); |
---|
293 | void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx); |
---|
294 | |
---|
295 | /* Low Power modes configuration functions ************************************/ |
---|
296 | void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry); |
---|
297 | void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry); |
---|
298 | void HAL_PWR_EnterSTANDBYMode(void); |
---|
299 | void HAL_PWR_EnableSleepOnExit(void); |
---|
300 | void HAL_PWR_DisableSleepOnExit(void); |
---|
301 | void HAL_PWR_EnableSEVOnPend(void); |
---|
302 | void HAL_PWR_DisableSEVOnPend(void); |
---|
303 | |
---|
304 | /** |
---|
305 | * @} |
---|
306 | */ |
---|
307 | |
---|
308 | /** |
---|
309 | * @} |
---|
310 | */ |
---|
311 | |
---|
312 | /** |
---|
313 | * @} |
---|
314 | */ |
---|
315 | |
---|
316 | /** |
---|
317 | * @} |
---|
318 | */ |
---|
319 | |
---|
320 | #ifdef __cplusplus |
---|
321 | } |
---|
322 | #endif |
---|
323 | |
---|
324 | |
---|
325 | #endif /* STM32G0xx_HAL_PWR_H */ |
---|