STM32F479xx HAL User Manual
stm32f4xx_hal_pwr_ex.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4xx_hal_pwr_ex.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of PWR HAL Extension module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
00010   * All rights reserved.</center></h2>
00011   *
00012   * This software component is licensed by ST under BSD 3-Clause license,
00013   * the "License"; You may not use this file except in compliance with the
00014   * License. You may obtain a copy of the License at:
00015   *                        opensource.org/licenses/BSD-3-Clause
00016   *
00017   ******************************************************************************
00018   */ 
00019 
00020 /* Define to prevent recursive inclusion -------------------------------------*/
00021 #ifndef __STM32F4xx_HAL_PWR_EX_H
00022 #define __STM32F4xx_HAL_PWR_EX_H
00023 
00024 #ifdef __cplusplus
00025  extern "C" {
00026 #endif
00027 
00028 /* Includes ------------------------------------------------------------------*/
00029 #include "stm32f4xx_hal_def.h"
00030 
00031 /** @addtogroup STM32F4xx_HAL_Driver
00032   * @{
00033   */
00034 
00035 /** @addtogroup PWREx
00036   * @{
00037   */ 
00038 
00039 /* Exported types ------------------------------------------------------------*/ 
00040 /* Exported constants --------------------------------------------------------*/
00041 /** @defgroup PWREx_Exported_Constants PWREx Exported Constants
00042   * @{
00043   */
00044 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
00045     defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
00046    
00047 /** @defgroup PWREx_Regulator_state_in_UnderDrive_mode PWREx Regulator state in UnderDrive mode
00048   * @{
00049   */
00050 #define PWR_MAINREGULATOR_UNDERDRIVE_ON                       PWR_CR_MRUDS
00051 #define PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON                   ((uint32_t)(PWR_CR_LPDS | PWR_CR_LPUDS))
00052 /**
00053   * @}
00054   */ 
00055   
00056 /** @defgroup PWREx_Over_Under_Drive_Flag PWREx Over Under Drive Flag
00057   * @{
00058   */
00059 #define PWR_FLAG_ODRDY                  PWR_CSR_ODRDY
00060 #define PWR_FLAG_ODSWRDY                PWR_CSR_ODSWRDY
00061 #define PWR_FLAG_UDRDY                  PWR_CSR_UDSWRDY
00062 /**
00063   * @}
00064   */
00065 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
00066 
00067 /** @defgroup PWREx_Regulator_Voltage_Scale PWREx Regulator Voltage Scale
00068   * @{
00069   */
00070 #if defined(STM32F405xx) || defined(STM32F407xx) || defined(STM32F415xx) || defined(STM32F417xx)   
00071 #define PWR_REGULATOR_VOLTAGE_SCALE1         PWR_CR_VOS             /* Scale 1 mode(default value at reset): the maximum value of fHCLK = 168 MHz. */
00072 #define PWR_REGULATOR_VOLTAGE_SCALE2         0x00000000U            /* Scale 2 mode: the maximum value of fHCLK = 144 MHz. */
00073 #else
00074 #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
00075                                                                        180 MHz by activating the over-drive mode. */
00076 #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
00077                                                                        168 MHz by activating the over-drive mode. */
00078 #define PWR_REGULATOR_VOLTAGE_SCALE3         PWR_CR_VOS_0           /* Scale 3 mode: the maximum value of fHCLK is 120 MHz. */
00079 #endif /* STM32F405xx || STM32F407xx || STM32F415xx || STM32F417xx */ 
00080 /**
00081   * @}
00082   */
00083 #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \
00084     defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
00085 /** @defgroup PWREx_WakeUp_Pins PWREx WakeUp Pins
00086   * @{
00087   */
00088 #define PWR_WAKEUP_PIN2                 0x00000080U
00089 #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \
00090     defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) 
00091 #define PWR_WAKEUP_PIN3                 0x00000040U
00092 #endif /* STM32F410xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Zx || STM32F412Vx || \
00093           STM32F412Rx || STM32F412Cx || STM32F413xx || STM32F423xx */
00094 /**
00095   * @}
00096   */   
00097 #endif /* STM32F410xx || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx ||
00098           STM32F413xx || STM32F423xx */
00099 
00100 /**
00101   * @}
00102   */ 
00103   
00104 /* Exported macro ------------------------------------------------------------*/
00105 /** @defgroup PWREx_Exported_Constants PWREx Exported Constants
00106   *  @{
00107   */
00108 
00109 #if defined(STM32F405xx) || defined(STM32F407xx) || defined(STM32F415xx) || defined(STM32F417xx)
00110 /** @brief  macros configure the main internal regulator output voltage.
00111   * @param  __REGULATOR__ specifies the regulator output voltage to achieve
00112   *         a tradeoff between performance and power consumption when the device does
00113   *         not operate at the maximum frequency (refer to the datasheets for more details).
00114   *          This parameter can be one of the following values:
00115   *            @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output Scale 1 mode
00116   *            @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output Scale 2 mode
00117   * @retval None
00118   */
00119 #define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__) do {                                                     \
00120                                                             __IO uint32_t tmpreg = 0x00U;                        \
00121                                                             MODIFY_REG(PWR->CR, PWR_CR_VOS, (__REGULATOR__));   \
00122                                                             /* Delay after an RCC peripheral clock enabling */  \
00123                                                             tmpreg = READ_BIT(PWR->CR, PWR_CR_VOS);             \
00124                                                             UNUSED(tmpreg);                                     \
00125                                                           } while(0U)
00126 #else
00127 /** @brief  macros configure the main internal regulator output voltage.
00128   * @param  __REGULATOR__ specifies the regulator output voltage to achieve
00129   *         a tradeoff between performance and power consumption when the device does
00130   *         not operate at the maximum frequency (refer to the datasheets for more details).
00131   *          This parameter can be one of the following values:
00132   *            @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output Scale 1 mode
00133   *            @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output Scale 2 mode
00134   *            @arg PWR_REGULATOR_VOLTAGE_SCALE3: Regulator voltage output Scale 3 mode
00135   * @retval None
00136   */
00137 #define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__) do {                                                     \
00138                                                             __IO uint32_t tmpreg = 0x00U;                        \
00139                                                             MODIFY_REG(PWR->CR, PWR_CR_VOS, (__REGULATOR__));   \
00140                                                             /* Delay after an RCC peripheral clock enabling */  \
00141                                                             tmpreg = READ_BIT(PWR->CR, PWR_CR_VOS);             \
00142                                                             UNUSED(tmpreg);                                     \
00143                                                           } while(0U)
00144 #endif /* STM32F405xx || STM32F407xx || STM32F415xx || STM32F417xx */ 
00145 
00146 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
00147     defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
00148 /** @brief Macros to enable or disable the Over drive mode.
00149   * @note  These macros can be used only for STM32F42xx/STM3243xx devices.
00150   */
00151 #define __HAL_PWR_OVERDRIVE_ENABLE() (*(__IO uint32_t *) CR_ODEN_BB = ENABLE)
00152 #define __HAL_PWR_OVERDRIVE_DISABLE() (*(__IO uint32_t *) CR_ODEN_BB = DISABLE)
00153 
00154 /** @brief Macros to enable or disable the Over drive switching.
00155   * @note  These macros can be used only for STM32F42xx/STM3243xx devices. 
00156   */
00157 #define __HAL_PWR_OVERDRIVESWITCHING_ENABLE() (*(__IO uint32_t *) CR_ODSWEN_BB = ENABLE)
00158 #define __HAL_PWR_OVERDRIVESWITCHING_DISABLE() (*(__IO uint32_t *) CR_ODSWEN_BB = DISABLE)
00159 
00160 /** @brief Macros to enable or disable the Under drive mode.
00161   * @note  This mode is enabled only with STOP low power mode.
00162   *        In this mode, the 1.2V domain is preserved in reduced leakage mode. This 
00163   *        mode is only available when the main regulator or the low power regulator 
00164   *        is in low voltage mode.      
00165   * @note  If the Under-drive mode was enabled, it is automatically disabled after 
00166   *        exiting Stop mode. 
00167   *        When the voltage regulator operates in Under-drive mode, an additional  
00168   *        startup delay is induced when waking up from Stop mode.
00169   */
00170 #define __HAL_PWR_UNDERDRIVE_ENABLE() (PWR->CR |= (uint32_t)PWR_CR_UDEN)
00171 #define __HAL_PWR_UNDERDRIVE_DISABLE() (PWR->CR &= (uint32_t)(~PWR_CR_UDEN))
00172 
00173 /** @brief  Check PWR flag is set or not.
00174   * @note   These macros can be used only for STM32F42xx/STM3243xx devices.
00175   * @param  __FLAG__ specifies the flag to check.
00176   *         This parameter can be one of the following values:
00177   *            @arg PWR_FLAG_ODRDY: This flag indicates that the Over-drive mode
00178   *                                 is ready 
00179   *            @arg PWR_FLAG_ODSWRDY: This flag indicates that the Over-drive mode
00180   *                                   switching is ready  
00181   *            @arg PWR_FLAG_UDRDY: This flag indicates that the Under-drive mode
00182   *                                 is enabled in Stop mode
00183   * @retval The new state of __FLAG__ (TRUE or FALSE).
00184   */
00185 #define __HAL_PWR_GET_ODRUDR_FLAG(__FLAG__) ((PWR->CSR & (__FLAG__)) == (__FLAG__))
00186 
00187 /** @brief Clear the Under-Drive Ready flag.
00188   * @note  These macros can be used only for STM32F42xx/STM3243xx devices.
00189   */
00190 #define __HAL_PWR_CLEAR_ODRUDR_FLAG() (PWR->CSR |= PWR_FLAG_UDRDY)
00191 
00192 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
00193 /**
00194   * @}
00195   */
00196 
00197 /* Exported functions --------------------------------------------------------*/
00198 /** @addtogroup PWREx_Exported_Functions PWREx Exported Functions
00199   *  @{
00200   */
00201  
00202 /** @addtogroup PWREx_Exported_Functions_Group1
00203   * @{
00204   */
00205 void HAL_PWREx_EnableFlashPowerDown(void);
00206 void HAL_PWREx_DisableFlashPowerDown(void); 
00207 HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg(void);
00208 HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg(void); 
00209 uint32_t HAL_PWREx_GetVoltageRange(void);
00210 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling);
00211 
00212 #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F401xC) ||\
00213     defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F412Zx) || defined(STM32F412Vx) ||\
00214     defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
00215 void HAL_PWREx_EnableMainRegulatorLowVoltage(void);
00216 void HAL_PWREx_DisableMainRegulatorLowVoltage(void);
00217 void HAL_PWREx_EnableLowRegulatorLowVoltage(void);
00218 void HAL_PWREx_DisableLowRegulatorLowVoltage(void);
00219 #endif /* STM32F410xx || STM32F401xC || STM32F401xE || STM32F411xE || STM32F412Zx || STM32F412Vx ||\
00220           STM32F412Rx || STM32F412Cx || STM32F413xx || STM32F423xx */
00221 
00222 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F446xx) ||\
00223     defined(STM32F469xx) || defined(STM32F479xx)
00224 HAL_StatusTypeDef HAL_PWREx_EnableOverDrive(void);
00225 HAL_StatusTypeDef HAL_PWREx_DisableOverDrive(void);
00226 HAL_StatusTypeDef HAL_PWREx_EnterUnderDriveSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
00227 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
00228 
00229 /**
00230   * @}
00231   */
00232 
00233 /**
00234   * @}
00235   */
00236 /* Private types -------------------------------------------------------------*/
00237 /* Private variables ---------------------------------------------------------*/
00238 /* Private constants ---------------------------------------------------------*/
00239 /** @defgroup PWREx_Private_Constants PWREx Private Constants
00240   * @{
00241   */
00242 
00243 /** @defgroup PWREx_register_alias_address PWREx Register alias address
00244   * @{
00245   */
00246 /* ------------- PWR registers bit address in the alias region ---------------*/
00247 /* --- CR Register ---*/
00248 /* Alias word address of FPDS bit */
00249 #define FPDS_BIT_NUMBER          PWR_CR_FPDS_Pos
00250 #define CR_FPDS_BB               (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (FPDS_BIT_NUMBER * 4U))
00251 
00252 /* Alias word address of ODEN bit   */
00253 #define ODEN_BIT_NUMBER          PWR_CR_ODEN_Pos
00254 #define CR_ODEN_BB               (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (ODEN_BIT_NUMBER * 4U))
00255 
00256 /* Alias word address of ODSWEN bit */
00257 #define ODSWEN_BIT_NUMBER        PWR_CR_ODSWEN_Pos
00258 #define CR_ODSWEN_BB             (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (ODSWEN_BIT_NUMBER * 4U))
00259     
00260 /* Alias word address of MRLVDS bit */
00261 #define MRLVDS_BIT_NUMBER        PWR_CR_MRLVDS_Pos
00262 #define CR_MRLVDS_BB             (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (MRLVDS_BIT_NUMBER * 4U))
00263 
00264 /* Alias word address of LPLVDS bit */
00265 #define LPLVDS_BIT_NUMBER        PWR_CR_LPLVDS_Pos
00266 #define CR_LPLVDS_BB             (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (LPLVDS_BIT_NUMBER * 4U))
00267 
00268  /**
00269   * @}
00270   */
00271 
00272 /** @defgroup PWREx_CSR_register_alias PWRx CSR Register alias address
00273   * @{
00274   */  
00275 /* --- CSR Register ---*/
00276 /* Alias word address of BRE bit */
00277 #define BRE_BIT_NUMBER   PWR_CSR_BRE_Pos
00278 #define CSR_BRE_BB      (uint32_t)(PERIPH_BB_BASE + (PWR_CSR_OFFSET_BB * 32U) + (BRE_BIT_NUMBER * 4U))
00279 
00280 /**
00281   * @}
00282   */
00283 
00284 /**
00285   * @}
00286   */
00287 
00288 /* Private macros ------------------------------------------------------------*/
00289 /** @defgroup PWREx_Private_Macros PWREx Private Macros
00290   * @{
00291   */
00292 
00293 /** @defgroup PWREx_IS_PWR_Definitions PWREx Private macros to check input parameters
00294   * @{
00295   */
00296 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
00297     defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
00298 #define IS_PWR_REGULATOR_UNDERDRIVE(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_UNDERDRIVE_ON) || \
00299                                                 ((REGULATOR) == PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON))
00300 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
00301 
00302 #if defined(STM32F405xx) || defined(STM32F407xx) || defined(STM32F415xx) || defined(STM32F417xx)
00303 #define IS_PWR_VOLTAGE_SCALING_RANGE(VOLTAGE) (((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE1) || \
00304                                                ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE2))
00305 #else
00306 #define IS_PWR_VOLTAGE_SCALING_RANGE(VOLTAGE) (((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE1) || \
00307                                                ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE2) || \
00308                                                ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE3))
00309 #endif /* STM32F405xx || STM32F407xx || STM32F415xx || STM32F417xx */ 
00310 
00311 #if defined(STM32F446xx)
00312 #define IS_PWR_WAKEUP_PIN(PIN) (((PIN) == PWR_WAKEUP_PIN1) || ((PIN) == PWR_WAKEUP_PIN2))
00313 #elif defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F412Zx) ||\
00314       defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) ||\
00315       defined(STM32F423xx)
00316 #define IS_PWR_WAKEUP_PIN(PIN) (((PIN) == PWR_WAKEUP_PIN1) || ((PIN) == PWR_WAKEUP_PIN2) || \
00317                                 ((PIN) == PWR_WAKEUP_PIN3))
00318 #else
00319 #define IS_PWR_WAKEUP_PIN(PIN) ((PIN) == PWR_WAKEUP_PIN1)
00320 #endif /* STM32F446xx */
00321 /**
00322   * @}
00323   */
00324 
00325 /**
00326   * @}
00327   */
00328 
00329 /**
00330   * @}
00331   */ 
00332 
00333 /**
00334   * @}
00335   */
00336   
00337 #ifdef __cplusplus
00338 }
00339 #endif
00340 
00341 
00342 #endif /* __STM32F4xx_HAL_PWR_EX_H */
00343 
00344 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/