1 /** 2 ****************************************************************************** 3 * @file stm32f4xx_hal_pwr_ex.h 4 * @author MCD Application Team 5 * @brief Header file of PWR HAL Extension module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2017 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file in 13 * 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 /* Define to prevent recursive inclusion -------------------------------------*/ 19 #ifndef __STM32F4xx_HAL_PWR_EX_H 20 #define __STM32F4xx_HAL_PWR_EX_H 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 /* Includes ------------------------------------------------------------------*/ 27 #include "stm32f4xx_hal_def.h" 28 29 /** @addtogroup STM32F4xx_HAL_Driver 30 * @{ 31 */ 32 33 /** @addtogroup PWREx 34 * @{ 35 */ 36 37 /* Exported types ------------------------------------------------------------*/ 38 /* Exported constants --------------------------------------------------------*/ 39 /** @defgroup PWREx_Exported_Constants PWREx Exported Constants 40 * @{ 41 */ 42 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\ 43 defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) 44 45 /** @defgroup PWREx_Regulator_state_in_UnderDrive_mode PWREx Regulator state in UnderDrive mode 46 * @{ 47 */ 48 #define PWR_MAINREGULATOR_UNDERDRIVE_ON PWR_CR_MRUDS 49 #define PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON ((uint32_t)(PWR_CR_LPDS | PWR_CR_LPUDS)) 50 /** 51 * @} 52 */ 53 54 /** @defgroup PWREx_Over_Under_Drive_Flag PWREx Over Under Drive Flag 55 * @{ 56 */ 57 #define PWR_FLAG_ODRDY PWR_CSR_ODRDY 58 #define PWR_FLAG_ODSWRDY PWR_CSR_ODSWRDY 59 #define PWR_FLAG_UDRDY PWR_CSR_UDSWRDY 60 /** 61 * @} 62 */ 63 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */ 64 65 /** @defgroup PWREx_Regulator_Voltage_Scale PWREx Regulator Voltage Scale 66 * @{ 67 */ 68 #if defined(STM32F405xx) || defined(STM32F407xx) || defined(STM32F415xx) || defined(STM32F417xx) 69 #define PWR_REGULATOR_VOLTAGE_SCALE1 PWR_CR_VOS /* Scale 1 mode(default value at reset): the maximum value of fHCLK = 168 MHz. */ 70 #define PWR_REGULATOR_VOLTAGE_SCALE2 0x00000000U /* Scale 2 mode: the maximum value of fHCLK = 144 MHz. */ 71 #else 72 #define PWR_REGULATOR_VOLTAGE_SCALE1 PWR_CR_VOS /* Scale 1 mode(default value at reset): the maximum value of fHCLK is 168 MHz. It can be extended to 73 180 MHz by activating the over-drive mode. */ 74 #define PWR_REGULATOR_VOLTAGE_SCALE2 PWR_CR_VOS_1 /* Scale 2 mode: the maximum value of fHCLK is 144 MHz. It can be extended to 75 168 MHz by activating the over-drive mode. */ 76 #define PWR_REGULATOR_VOLTAGE_SCALE3 PWR_CR_VOS_0 /* Scale 3 mode: the maximum value of fHCLK is 120 MHz. */ 77 #endif /* STM32F405xx || STM32F407xx || STM32F415xx || STM32F417xx */ 78 /** 79 * @} 80 */ 81 #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \ 82 defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) 83 /** @defgroup PWREx_WakeUp_Pins PWREx WakeUp Pins 84 * @{ 85 */ 86 #define PWR_WAKEUP_PIN2 0x00000080U 87 #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \ 88 defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) 89 #define PWR_WAKEUP_PIN3 0x00000040U 90 #endif /* STM32F410xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Zx || STM32F412Vx || \ 91 STM32F412Rx || STM32F412Cx || STM32F413xx || STM32F423xx */ 92 /** 93 * @} 94 */ 95 #endif /* STM32F410xx || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx || 96 STM32F413xx || STM32F423xx */ 97 98 /** 99 * @} 100 */ 101 102 /* Exported macro ------------------------------------------------------------*/ 103 /** @defgroup PWREx_Exported_Constants PWREx Exported Constants 104 * @{ 105 */ 106 107 #if defined(STM32F405xx) || defined(STM32F407xx) || defined(STM32F415xx) || defined(STM32F417xx) 108 /** @brief macros configure the main internal regulator output voltage. 109 * @param __REGULATOR__ specifies the regulator output voltage to achieve 110 * a tradeoff between performance and power consumption when the device does 111 * not operate at the maximum frequency (refer to the datasheets for more details). 112 * This parameter can be one of the following values: 113 * @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output Scale 1 mode 114 * @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output Scale 2 mode 115 * @retval None 116 */ 117 #define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__) do { \ 118 __IO uint32_t tmpreg = 0x00U; \ 119 MODIFY_REG(PWR->CR, PWR_CR_VOS, (__REGULATOR__)); \ 120 /* Delay after an RCC peripheral clock enabling */ \ 121 tmpreg = READ_BIT(PWR->CR, PWR_CR_VOS); \ 122 UNUSED(tmpreg); \ 123 } while(0U) 124 #else 125 /** @brief macros configure the main internal regulator output voltage. 126 * @param __REGULATOR__ specifies the regulator output voltage to achieve 127 * a tradeoff between performance and power consumption when the device does 128 * not operate at the maximum frequency (refer to the datasheets for more details). 129 * This parameter can be one of the following values: 130 * @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output Scale 1 mode 131 * @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output Scale 2 mode 132 * @arg PWR_REGULATOR_VOLTAGE_SCALE3: Regulator voltage output Scale 3 mode 133 * @retval None 134 */ 135 #define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__) do { \ 136 __IO uint32_t tmpreg = 0x00U; \ 137 MODIFY_REG(PWR->CR, PWR_CR_VOS, (__REGULATOR__)); \ 138 /* Delay after an RCC peripheral clock enabling */ \ 139 tmpreg = READ_BIT(PWR->CR, PWR_CR_VOS); \ 140 UNUSED(tmpreg); \ 141 } while(0U) 142 #endif /* STM32F405xx || STM32F407xx || STM32F415xx || STM32F417xx */ 143 144 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\ 145 defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) 146 /** @brief Macros to enable or disable the Over drive mode. 147 * @note These macros can be used only for STM32F42xx/STM3243xx devices. 148 */ 149 #define __HAL_PWR_OVERDRIVE_ENABLE() (*(__IO uint32_t *) CR_ODEN_BB = ENABLE) 150 #define __HAL_PWR_OVERDRIVE_DISABLE() (*(__IO uint32_t *) CR_ODEN_BB = DISABLE) 151 152 /** @brief Macros to enable or disable the Over drive switching. 153 * @note These macros can be used only for STM32F42xx/STM3243xx devices. 154 */ 155 #define __HAL_PWR_OVERDRIVESWITCHING_ENABLE() (*(__IO uint32_t *) CR_ODSWEN_BB = ENABLE) 156 #define __HAL_PWR_OVERDRIVESWITCHING_DISABLE() (*(__IO uint32_t *) CR_ODSWEN_BB = DISABLE) 157 158 /** @brief Macros to enable or disable the Under drive mode. 159 * @note This mode is enabled only with STOP low power mode. 160 * In this mode, the 1.2V domain is preserved in reduced leakage mode. This 161 * mode is only available when the main regulator or the low power regulator 162 * is in low voltage mode. 163 * @note If the Under-drive mode was enabled, it is automatically disabled after 164 * exiting Stop mode. 165 * When the voltage regulator operates in Under-drive mode, an additional 166 * startup delay is induced when waking up from Stop mode. 167 */ 168 #define __HAL_PWR_UNDERDRIVE_ENABLE() (PWR->CR |= (uint32_t)PWR_CR_UDEN) 169 #define __HAL_PWR_UNDERDRIVE_DISABLE() (PWR->CR &= (uint32_t)(~PWR_CR_UDEN)) 170 171 /** @brief Check PWR flag is set or not. 172 * @note These macros can be used only for STM32F42xx/STM3243xx devices. 173 * @param __FLAG__ specifies the flag to check. 174 * This parameter can be one of the following values: 175 * @arg PWR_FLAG_ODRDY: This flag indicates that the Over-drive mode 176 * is ready 177 * @arg PWR_FLAG_ODSWRDY: This flag indicates that the Over-drive mode 178 * switching is ready 179 * @arg PWR_FLAG_UDRDY: This flag indicates that the Under-drive mode 180 * is enabled in Stop mode 181 * @retval The new state of __FLAG__ (TRUE or FALSE). 182 */ 183 #define __HAL_PWR_GET_ODRUDR_FLAG(__FLAG__) ((PWR->CSR & (__FLAG__)) == (__FLAG__)) 184 185 /** @brief Clear the Under-Drive Ready flag. 186 * @note These macros can be used only for STM32F42xx/STM3243xx devices. 187 */ 188 #define __HAL_PWR_CLEAR_ODRUDR_FLAG() (PWR->CSR |= PWR_FLAG_UDRDY) 189 190 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */ 191 /** 192 * @} 193 */ 194 195 /* Exported functions --------------------------------------------------------*/ 196 /** @addtogroup PWREx_Exported_Functions PWREx Exported Functions 197 * @{ 198 */ 199 200 /** @addtogroup PWREx_Exported_Functions_Group1 201 * @{ 202 */ 203 void HAL_PWREx_EnableFlashPowerDown(void); 204 void HAL_PWREx_DisableFlashPowerDown(void); 205 HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg(void); 206 HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg(void); 207 uint32_t HAL_PWREx_GetVoltageRange(void); 208 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling); 209 210 #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F401xC) ||\ 211 defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F412Zx) || defined(STM32F412Vx) ||\ 212 defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) 213 void HAL_PWREx_EnableMainRegulatorLowVoltage(void); 214 void HAL_PWREx_DisableMainRegulatorLowVoltage(void); 215 void HAL_PWREx_EnableLowRegulatorLowVoltage(void); 216 void HAL_PWREx_DisableLowRegulatorLowVoltage(void); 217 #endif /* STM32F410xx || STM32F401xC || STM32F401xE || STM32F411xE || STM32F412Zx || STM32F412Vx ||\ 218 STM32F412Rx || STM32F412Cx || STM32F413xx || STM32F423xx */ 219 220 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F446xx) ||\ 221 defined(STM32F469xx) || defined(STM32F479xx) 222 HAL_StatusTypeDef HAL_PWREx_EnableOverDrive(void); 223 HAL_StatusTypeDef HAL_PWREx_DisableOverDrive(void); 224 HAL_StatusTypeDef HAL_PWREx_EnterUnderDriveSTOPMode(uint32_t Regulator, uint8_t STOPEntry); 225 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */ 226 227 /** 228 * @} 229 */ 230 231 /** 232 * @} 233 */ 234 /* Private types -------------------------------------------------------------*/ 235 /* Private variables ---------------------------------------------------------*/ 236 /* Private constants ---------------------------------------------------------*/ 237 /** @defgroup PWREx_Private_Constants PWREx Private Constants 238 * @{ 239 */ 240 241 /** @defgroup PWREx_register_alias_address PWREx Register alias address 242 * @{ 243 */ 244 /* ------------- PWR registers bit address in the alias region ---------------*/ 245 /* --- CR Register ---*/ 246 /* Alias word address of FPDS bit */ 247 #define FPDS_BIT_NUMBER PWR_CR_FPDS_Pos 248 #define CR_FPDS_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (FPDS_BIT_NUMBER * 4U)) 249 250 /* Alias word address of ODEN bit */ 251 #define ODEN_BIT_NUMBER PWR_CR_ODEN_Pos 252 #define CR_ODEN_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (ODEN_BIT_NUMBER * 4U)) 253 254 /* Alias word address of ODSWEN bit */ 255 #define ODSWEN_BIT_NUMBER PWR_CR_ODSWEN_Pos 256 #define CR_ODSWEN_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (ODSWEN_BIT_NUMBER * 4U)) 257 258 /* Alias word address of MRLVDS bit */ 259 #define MRLVDS_BIT_NUMBER PWR_CR_MRLVDS_Pos 260 #define CR_MRLVDS_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (MRLVDS_BIT_NUMBER * 4U)) 261 262 /* Alias word address of LPLVDS bit */ 263 #define LPLVDS_BIT_NUMBER PWR_CR_LPLVDS_Pos 264 #define CR_LPLVDS_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (LPLVDS_BIT_NUMBER * 4U)) 265 266 /** 267 * @} 268 */ 269 270 /** @defgroup PWREx_CSR_register_alias PWRx CSR Register alias address 271 * @{ 272 */ 273 /* --- CSR Register ---*/ 274 /* Alias word address of BRE bit */ 275 #define BRE_BIT_NUMBER PWR_CSR_BRE_Pos 276 #define CSR_BRE_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CSR_OFFSET_BB * 32U) + (BRE_BIT_NUMBER * 4U)) 277 278 /** 279 * @} 280 */ 281 282 /** 283 * @} 284 */ 285 286 /* Private macros ------------------------------------------------------------*/ 287 /** @defgroup PWREx_Private_Macros PWREx Private Macros 288 * @{ 289 */ 290 291 /** @defgroup PWREx_IS_PWR_Definitions PWREx Private macros to check input parameters 292 * @{ 293 */ 294 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\ 295 defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) 296 #define IS_PWR_REGULATOR_UNDERDRIVE(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_UNDERDRIVE_ON) || \ 297 ((REGULATOR) == PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON)) 298 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */ 299 300 #if defined(STM32F405xx) || defined(STM32F407xx) || defined(STM32F415xx) || defined(STM32F417xx) 301 #define IS_PWR_VOLTAGE_SCALING_RANGE(VOLTAGE) (((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE1) || \ 302 ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE2)) 303 #else 304 #define IS_PWR_VOLTAGE_SCALING_RANGE(VOLTAGE) (((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE1) || \ 305 ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE2) || \ 306 ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE3)) 307 #endif /* STM32F405xx || STM32F407xx || STM32F415xx || STM32F417xx */ 308 309 #if defined(STM32F446xx) 310 #define IS_PWR_WAKEUP_PIN(PIN) (((PIN) == PWR_WAKEUP_PIN1) || ((PIN) == PWR_WAKEUP_PIN2)) 311 #elif defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F412Zx) ||\ 312 defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) ||\ 313 defined(STM32F423xx) 314 #define IS_PWR_WAKEUP_PIN(PIN) (((PIN) == PWR_WAKEUP_PIN1) || ((PIN) == PWR_WAKEUP_PIN2) || \ 315 ((PIN) == PWR_WAKEUP_PIN3)) 316 #else 317 #define IS_PWR_WAKEUP_PIN(PIN) ((PIN) == PWR_WAKEUP_PIN1) 318 #endif /* STM32F446xx */ 319 /** 320 * @} 321 */ 322 323 /** 324 * @} 325 */ 326 327 /** 328 * @} 329 */ 330 331 /** 332 * @} 333 */ 334 335 #ifdef __cplusplus 336 } 337 #endif 338 339 340 #endif /* __STM32F4xx_HAL_PWR_EX_H */ 341