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