1 /**
2   ******************************************************************************
3   * @file    stm32c0xx_hal_pwr.h
4   * @author  MCD Application Team
5   * @brief   Header file of PWR HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2022 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 STM32C0xx_HAL_PWR_H
21 #define STM32C0xx_HAL_PWR_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32c0xx_hal_def.h"
29 
30 /** @addtogroup STM32C0xx_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 #define PWR_WAKEUP_PIN3                     PWR_CR3_EWUP3  /*!< Wakeup pin 3 (with high level detection) */
59 #define PWR_WAKEUP_PIN4                     PWR_CR3_EWUP4  /*!< Wakeup pin 4 (with high level detection) */
60 #if defined(PWR_CR3_EWUP5)
61 #define PWR_WAKEUP_PIN5                     PWR_CR3_EWUP5  /*!< Wakeup pin 5 (with high level detection) */
62 #endif /* PWR_CR3_EWUP5 */
63 #define PWR_WAKEUP_PIN6                     PWR_CR3_EWUP6  /*!< Wakeup pin 6 (with high level detection) */
64 #define PWR_WAKEUP_PIN1_HIGH                PWR_CR3_EWUP1  /*!< Wakeup pin 1 (with high level detection) */
65 #define PWR_WAKEUP_PIN2_HIGH                PWR_CR3_EWUP2  /*!< Wakeup pin 2 (with high level detection) */
66 #define PWR_WAKEUP_PIN3_HIGH                PWR_CR3_EWUP3  /*!< Wakeup pin 3 (with high level detection) */
67 #define PWR_WAKEUP_PIN4_HIGH                PWR_CR3_EWUP4  /*!< Wakeup pin 4 (with high level detection) */
68 #if defined(PWR_CR3_EWUP5)
69 #define PWR_WAKEUP_PIN5_HIGH                PWR_CR3_EWUP5  /*!< Wakeup pin 5 (with high level detection) */
70 #endif /* PWR_CR3_EWUP5*/
71 #define PWR_WAKEUP_PIN6_HIGH                PWR_CR3_EWUP6  /*!< Wakeup pin 6 (with high level detection) */
72 #define PWR_WAKEUP_PIN1_LOW                 ((PWR_CR4_WP1 << PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP1) /*!< Wakeup pin 1 (with low level detection) */
73 #define PWR_WAKEUP_PIN2_LOW                 ((PWR_CR4_WP2 << PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP2) /*!< Wakeup pin 2 (with low level detection) */
74 #define PWR_WAKEUP_PIN3_LOW                 ((PWR_CR4_WP3 << PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP3) /*!< Wakeup pin 3 (with low level detection) */
75 #define PWR_WAKEUP_PIN4_LOW                 ((PWR_CR4_WP4 << PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP4) /*!< Wakeup pin 4 (with low level detection) */
76 #if defined(PWR_CR3_EWUP5)
77 #define PWR_WAKEUP_PIN5_LOW                 ((PWR_CR4_WP5 << PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP5) /*!< Wakeup pin 5 (with low level detection) */
78 #endif /* PWR_CR3_EWUP5 */
79 #define PWR_WAKEUP_PIN6_LOW                 ((PWR_CR4_WP6 << PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP6) /*!< Wakeup pin 6 (with low level detection) */
80 /**
81   * @}
82   */
83 
84 /** @defgroup PWR_Low_Power_Mode_Selection  PWR Low Power Mode Selection
85   * @{
86   */
87 #define PWR_LOWPOWERMODE_STOP0              (0x00000000u)                       /*!< Stop 0: stop mode with main regulator */
88 #define PWR_LOWPOWERMODE_STANDBY            (PWR_CR1_LPMS_0 | PWR_CR1_LPMS_1)   /*!< Standby mode */
89 #define PWR_LOWPOWERMODE_SHUTDOWN           (PWR_CR1_LPMS_2)                    /*!< Shutdown mode */
90 /**
91   * @}
92   */
93 
94 /** @defgroup PWR_Regulator_state_in_SLEEP_STOP_mode  PWR regulator mode
95   * @{
96   */
97 #define PWR_MAINREGULATOR_ON                (0x00000000u)  /*!< Regulator in main mode      */
98 
99 /**
100   * @}
101   */
102 
103 /** @defgroup PWR_SLEEP_mode_entry  PWR SLEEP mode entry
104   * @{
105   */
106 #define PWR_SLEEPENTRY_WFI                  ((uint8_t)0x01u)        /*!< Wait For Interruption instruction to enter Sleep mode */
107 #define PWR_SLEEPENTRY_WFE                  ((uint8_t)0x02u)        /*!< Wait For Event instruction to enter Sleep mode        */
108 /**
109   * @}
110   */
111 
112 /** @defgroup PWR_STOP_mode_entry  PWR STOP mode entry
113   * @{
114   */
115 #define PWR_STOPENTRY_WFI                   ((uint8_t)0x01u)        /*!< Wait For Interruption instruction to enter Stop mode */
116 #define PWR_STOPENTRY_WFE                   ((uint8_t)0x02u)        /*!< Wait For Event instruction to enter Stop mode        */
117 /**
118   * @}
119   */
120 
121 
122 /** @defgroup PWREx_Flag  PWR Status Flags
123   * @brief  Elements values convention: 0000 00XX 000Y YYYYb
124   *           - Y YYYY  : Flag position in the XX register (5 bits)
125   *           - XX  : Status register (2 bits)
126   *                 - 01: SR1 register
127   *                 - 10: SR2 register
128   *         The only exception is PWR_FLAG_WU, encompassing all
129   *         wake-up flags and set to PWR_SR1_WUF.
130   * @{
131   */
132 #define PWR_FLAG_WUF1                       (0x00010000u | PWR_SR1_WUF1)      /*!< Wakeup event on wakeup pin 1 */
133 #define PWR_FLAG_WUF2                       (0x00010000u | PWR_SR1_WUF2)      /*!< Wakeup event on wakeup pin 2 */
134 #define PWR_FLAG_WUF3                       (0x00010000u | PWR_SR1_WUF3)      /*!< Wakeup event on wakeup pin 3 */
135 #define PWR_FLAG_WUF4                       (0x00010000u | PWR_SR1_WUF4)      /*!< Wakeup event on wakeup pin 4 */
136 #if defined(PWR_CR3_EWUP5)
137 #define PWR_FLAG_WUF5                       (0x00010000u | PWR_SR1_WUF5)      /*!< Wakeup event on wakeup pin 5 */
138 #endif /* PWR_CR3_EWUP5 */
139 #define PWR_FLAG_WUF6                       (0x00010000u | PWR_SR1_WUF6)      /*!< Wakeup event on wakeup pin 6 */
140 #define PWR_FLAG_WUF                        (0x00010000u | PWR_SR1_WUF)       /*!< Wakeup event on all wakeup pin  */
141 #define PWR_FLAG_SB                         (0x00010000u | PWR_SR1_SBF)       /*!< Standby flag */
142 #define PWR_FLAG_WUFI                       (0x00010000u | PWR_SR1_WUFI)      /*!< Wakeup on internal wakeup line */
143 #define PWR_FLAG_FLASH_READY                (0x00020000u | PWR_SR2_FLASH_RDY) /*!< Flash ready */
144 #if defined(PWR_PVM_SUPPORT)
145 #define PWR_FLAG_PVMO_USB                   (0x00020000u | PWR_SR2_PVMO_VDDIO2)  /*!< Power Voltage Monitoring output */
146 #endif /* PWR_PVM_SUPPORT */
147 /**
148   * @}
149   */
150 
151 /**
152   * @}
153   */
154 
155 /* Exported macros -----------------------------------------------------------*/
156 /** @defgroup PWR_Exported_Macros  PWR Exported Macros
157   * @{
158   */
159 /** @brief  Check whether or not a specific PWR flag is set.
160   * @param  __FLAG__  specifies the flag to check.
161   *         This parameter can be one a combination of following values:
162   *            @arg PWR_FLAG_WUF1: Wake Up Flag 1. Indicates that a wakeup event
163   *                  was received from the WKUP pin 1.
164   *            @arg PWR_FLAG_WUF2: Wake Up Flag 2. Indicates that a wakeup event
165   *                  was received from the WKUP pin 2.
166   *            @arg PWR_FLAG_WUF3: Wake Up Flag 3. Indicates that a wakeup event
167   *                  was received from the WKUP pin 3.
168   *            @arg PWR_FLAG_WUF4: Wake Up Flag 4. Indicates that a wakeup event
169   *                  was received from the WKUP pin 4.
170   *            @arg PWR_FLAG_WUF5: Wake Up Flag 5. Indicates that a wakeup event
171   *                  was received from the WKUP pin 5. (*)
172   *            @arg PWR_FLAG_WUF6: Wake Up Flag 6. Indicates that a wakeup event
173   *                  was received from the WKUP pin 6.
174   *            @arg PWR_FLAG_SB: StandBy Flag. Indicates that the system
175   *                  entered StandBy mode.
176   *            @arg PWR_FLAG_WUFI: Wake-Up Flag Internal. Set when a wakeup is
177   *                 detected on the internal wakeup line.
178   *         OR a combination of following values:
179   *            @arg PWR_FLAG_FLASH_READY: Flash is ready. Indicates whether flash
180   *                 can be used or not
181   *            @arg PWR_FLAG_PVMO_USB: Peripheral Voltage Monitoring Output. Indicates whether VDDUSB voltage
182   *                  is below or above PVM threshold. (*)
183   * @note (*) Availability depends on devices
184   * @retval The new state of __FLAG__ (TRUE or FALSE).
185   */
186 #define __HAL_PWR_GET_FLAG(__FLAG__)        (((__FLAG__) & 0x00010000u) ?\
187                                              ((PWR->SR1 & ((__FLAG__) & ~0x00030000u)) == \
188                                               ((__FLAG__) & ~0x00030000u)) :\
189                                              ((PWR->SR2 & ((__FLAG__) & ~0x00030000u)) == \
190                                               ((__FLAG__) & ~0x00030000u)))
191 
192 /** @brief  Clear a specific PWR flag.
193   * @param  __FLAG__  specifies the flag to clear.
194   *         This parameter can be a combination of following values:
195   *            @arg PWR_FLAG_WUF1: Wake Up Flag 1. Indicates that a wakeup event
196   *                  was received from the WKUP pin 1.
197   *            @arg PWR_FLAG_WUF2: Wake Up Flag 2. Indicates that a wakeup event
198   *                  was received from the WKUP pin 2.
199   *            @arg PWR_FLAG_WUF3: Wake Up Flag 3. Indicates that a wakeup event
200   *                  was received from the WKUP pin 3.
201   *            @arg PWR_FLAG_WUF4: Wake Up Flag 4. Indicates that a wakeup event
202   *                  was received from the WKUP pin 4.
203   *            @arg PWR_FLAG_WUF5: Wake Up Flag 5. Indicates that a wakeup event
204   *                  was received from the WKUP pin 5. (*)
205   *            @arg PWR_FLAG_WUF6: Wake Up Flag 6. Indicates that a wakeup event
206   *                  was received from the WKUP pin 6.
207   *            @arg PWR_FLAG_SB: Standby Flag. Indicates that the system
208   *                  entered Standby mode.
209   * @note (*) Availability depends on devices
210   * @retval None
211   */
212 #define __HAL_PWR_CLEAR_FLAG(__FLAG__)      (PWR->SCR = (__FLAG__))
213 
214 /**
215   * @}
216   */
217 
218 /* Private constants-------------------------------------------------------*/
219 /** @defgroup PWREx_WUP_Polarity Shift to apply to retrieve polarity information from PWR_WAKEUP_PINy_xxx constants
220   * @{
221   */
222 #define PWR_WUP_POLARITY_SHIFT              0x08u   /*!< Internal constant used to retrieve wakeup pin polariry */
223 /**
224   * @}
225   */
226 
227 /* Private macros --------------------------------------------------------*/
228 /** @defgroup PWR_Private_Macros  PWR Private Macros
229   * @{
230   */
231 #define IS_PWR_WAKEUP_PIN(PIN)                    ((((PIN) & ((PWR_CR4_WP << 8U) | (PWR_CR3_EWUP))) != 0x00000000u) && \
232                                                    (((PIN) & ~((PWR_CR4_WP << 8U) | (PWR_CR3_EWUP))) == 0x00000000u))
233 
234 #define IS_PWR_REGULATOR(REGULATOR)               ((REGULATOR) == PWR_MAINREGULATOR_ON)
235 
236 #define IS_PWR_SLEEP_ENTRY(ENTRY)                 (((ENTRY) == PWR_SLEEPENTRY_WFI) || \
237                                                    ((ENTRY) == PWR_SLEEPENTRY_WFE))
238 
239 #define IS_PWR_STOP_ENTRY(ENTRY)                  (((ENTRY) == PWR_STOPENTRY_WFI) || \
240                                                    ((ENTRY) == PWR_STOPENTRY_WFE))
241 /**
242   * @}
243   */
244 
245 /* Include PWR HAL Extended module */
246 #include "stm32c0xx_hal_pwr_ex.h"
247 
248 /* Exported functions --------------------------------------------------------*/
249 /** @defgroup PWR_Exported_Functions  PWR Exported Functions
250   * @{
251   */
252 
253 /** @defgroup PWR_Exported_Functions_Group1  Initialization and de-initialization functions
254   * @{
255   */
256 
257 /* Initialization and de-initialization functions *******************************/
258 void              HAL_PWR_DeInit(void);
259 /**
260   * @}
261   */
262 
263 /** @defgroup PWR_Exported_Functions_Group2  Peripheral Control functions
264   * @{
265   */
266 /* Peripheral Control functions  ************************************************/
267 /* WakeUp pins configuration functions ****************************************/
268 void              HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity);
269 void              HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx);
270 
271 /* Low Power modes configuration functions ************************************/
272 void              HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry);
273 void              HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
274 void              HAL_PWR_EnterSTANDBYMode(void);
275 void              HAL_PWR_EnableSleepOnExit(void);
276 void              HAL_PWR_DisableSleepOnExit(void);
277 void              HAL_PWR_EnableSEVOnPend(void);
278 void              HAL_PWR_DisableSEVOnPend(void);
279 /**
280   * @}
281   */
282 
283 /**
284   * @}
285   */
286 
287 /**
288   * @}
289   */
290 
291 /**
292   * @}
293   */
294 
295 #ifdef __cplusplus
296 }
297 #endif
298 
299 
300 #endif /* STM32C0xx_HAL_PWR_H */
301