STM32F439xx 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</center></h2>
00010   *
00011   * Redistribution and use in source and binary forms, with or without modification,
00012   * are permitted provided that the following conditions are met:
00013   *   1. Redistributions of source code must retain the above copyright notice,
00014   *      this list of conditions and the following disclaimer.
00015   *   2. Redistributions in binary form must reproduce the above copyright notice,
00016   *      this list of conditions and the following disclaimer in the documentation
00017   *      and/or other materials provided with the distribution.
00018   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00019   *      may be used to endorse or promote products derived from this software
00020   *      without specific prior written permission.
00021   *
00022   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00023   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00025   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00026   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00028   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00030   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00031   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032   *
00033   ******************************************************************************
00034   */ 
00035 
00036 /* Define to prevent recursive inclusion -------------------------------------*/
00037 #ifndef __STM32F4xx_HAL_PWR_EX_H
00038 #define __STM32F4xx_HAL_PWR_EX_H
00039 
00040 #ifdef __cplusplus
00041  extern "C" {
00042 #endif
00043 
00044 /* Includes ------------------------------------------------------------------*/
00045 #include "stm32f4xx_hal_def.h"
00046 
00047 /** @addtogroup STM32F4xx_HAL_Driver
00048   * @{
00049   */
00050 
00051 /** @addtogroup PWREx
00052   * @{
00053   */ 
00054 
00055 /* Exported types ------------------------------------------------------------*/ 
00056 /* Exported constants --------------------------------------------------------*/
00057 /** @defgroup PWREx_Exported_Constants PWREx Exported Constants
00058   * @{
00059   */
00060 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
00061     defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
00062    
00063 /** @defgroup PWREx_Regulator_state_in_UnderDrive_mode PWREx Regulator state in UnderDrive mode
00064   * @{
00065   */
00066 #define PWR_MAINREGULATOR_UNDERDRIVE_ON                       PWR_CR_MRUDS
00067 #define PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON                   ((uint32_t)(PWR_CR_LPDS | PWR_CR_LPUDS))
00068 /**
00069   * @}
00070   */ 
00071   
00072 /** @defgroup PWREx_Over_Under_Drive_Flag PWREx Over Under Drive Flag
00073   * @{
00074   */
00075 #define PWR_FLAG_ODRDY                  PWR_CSR_ODRDY
00076 #define PWR_FLAG_ODSWRDY                PWR_CSR_ODSWRDY
00077 #define PWR_FLAG_UDRDY                  PWR_CSR_UDSWRDY
00078 /**
00079   * @}
00080   */
00081 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
00082 
00083 /** @defgroup PWREx_Regulator_Voltage_Scale PWREx Regulator Voltage Scale
00084   * @{
00085   */
00086 #if defined(STM32F405xx) || defined(STM32F407xx) || defined(STM32F415xx) || defined(STM32F417xx)   
00087 #define PWR_REGULATOR_VOLTAGE_SCALE1         PWR_CR_VOS             /* Scale 1 mode(default value at reset): the maximum value of fHCLK = 168 MHz. */
00088 #define PWR_REGULATOR_VOLTAGE_SCALE2         0x00000000U            /* Scale 2 mode: the maximum value of fHCLK = 144 MHz. */
00089 #else
00090 #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
00091                                                                        180 MHz by activating the over-drive mode. */
00092 #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
00093                                                                        168 MHz by activating the over-drive mode. */
00094 #define PWR_REGULATOR_VOLTAGE_SCALE3         PWR_CR_VOS_0           /* Scale 3 mode: the maximum value of fHCLK is 120 MHz. */
00095 #endif /* STM32F405xx || STM32F407xx || STM32F415xx || STM32F417xx */ 
00096 /**
00097   * @}
00098   */
00099 #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \
00100     defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
00101 /** @defgroup PWREx_WakeUp_Pins PWREx WakeUp Pins
00102   * @{
00103   */
00104 #define PWR_WAKEUP_PIN2                 0x00000080U
00105 #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \
00106     defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) 
00107 #define PWR_WAKEUP_PIN3                 0x00000040U
00108 #endif /* STM32F410xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Zx || STM32F412Vx || \
00109           STM32F412Rx || STM32F412Cx || STM32F413xx || STM32F423xx */
00110 /**
00111   * @}
00112   */   
00113 #endif /* STM32F410xx || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx ||
00114           STM32F413xx || STM32F423xx */
00115 
00116 /**
00117   * @}
00118   */ 
00119   
00120 /* Exported macro ------------------------------------------------------------*/
00121 /** @defgroup PWREx_Exported_Constants PWREx Exported Constants
00122   *  @{
00123   */
00124 
00125 #if defined(STM32F405xx) || defined(STM32F407xx) || defined(STM32F415xx) || defined(STM32F417xx)
00126 /** @brief  macros configure the main internal regulator output voltage.
00127   * @param  __REGULATOR__ specifies the regulator output voltage to achieve
00128   *         a tradeoff between performance and power consumption when the device does
00129   *         not operate at the maximum frequency (refer to the datasheets for more details).
00130   *          This parameter can be one of the following values:
00131   *            @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output Scale 1 mode
00132   *            @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output Scale 2 mode
00133   * @retval None
00134   */
00135 #define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__) do {                                                     \
00136                                                             __IO uint32_t tmpreg = 0x00U;                        \
00137                                                             MODIFY_REG(PWR->CR, PWR_CR_VOS, (__REGULATOR__));   \
00138                                                             /* Delay after an RCC peripheral clock enabling */  \
00139                                                             tmpreg = READ_BIT(PWR->CR, PWR_CR_VOS);             \
00140                                                             UNUSED(tmpreg);                                     \
00141                                                           } while(0U)
00142 #else
00143 /** @brief  macros configure the main internal regulator output voltage.
00144   * @param  __REGULATOR__ specifies the regulator output voltage to achieve
00145   *         a tradeoff between performance and power consumption when the device does
00146   *         not operate at the maximum frequency (refer to the datasheets for more details).
00147   *          This parameter can be one of the following values:
00148   *            @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output Scale 1 mode
00149   *            @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output Scale 2 mode
00150   *            @arg PWR_REGULATOR_VOLTAGE_SCALE3: Regulator voltage output Scale 3 mode
00151   * @retval None
00152   */
00153 #define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__) do {                                                     \
00154                                                             __IO uint32_t tmpreg = 0x00U;                        \
00155                                                             MODIFY_REG(PWR->CR, PWR_CR_VOS, (__REGULATOR__));   \
00156                                                             /* Delay after an RCC peripheral clock enabling */  \
00157                                                             tmpreg = READ_BIT(PWR->CR, PWR_CR_VOS);             \
00158                                                             UNUSED(tmpreg);                                     \
00159                                                           } while(0U)
00160 #endif /* STM32F405xx || STM32F407xx || STM32F415xx || STM32F417xx */ 
00161 
00162 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
00163     defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
00164 /** @brief Macros to enable or disable the Over drive mode.
00165   * @note  These macros can be used only for STM32F42xx/STM3243xx devices.
00166   */
00167 #define __HAL_PWR_OVERDRIVE_ENABLE() (*(__IO uint32_t *) CR_ODEN_BB = ENABLE)
00168 #define __HAL_PWR_OVERDRIVE_DISABLE() (*(__IO uint32_t *) CR_ODEN_BB = DISABLE)
00169 
00170 /** @brief Macros to enable or disable the Over drive switching.
00171   * @note  These macros can be used only for STM32F42xx/STM3243xx devices. 
00172   */
00173 #define __HAL_PWR_OVERDRIVESWITCHING_ENABLE() (*(__IO uint32_t *) CR_ODSWEN_BB = ENABLE)
00174 #define __HAL_PWR_OVERDRIVESWITCHING_DISABLE() (*(__IO uint32_t *) CR_ODSWEN_BB = DISABLE)
00175 
00176 /** @brief Macros to enable or disable the Under drive mode.
00177   * @note  This mode is enabled only with STOP low power mode.
00178   *        In this mode, the 1.2V domain is preserved in reduced leakage mode. This 
00179   *        mode is only available when the main regulator or the low power regulator 
00180   *        is in low voltage mode.      
00181   * @note  If the Under-drive mode was enabled, it is automatically disabled after 
00182   *        exiting Stop mode. 
00183   *        When the voltage regulator operates in Under-drive mode, an additional  
00184   *        startup delay is induced when waking up from Stop mode.
00185   */
00186 #define __HAL_PWR_UNDERDRIVE_ENABLE() (PWR->CR |= (uint32_t)PWR_CR_UDEN)
00187 #define __HAL_PWR_UNDERDRIVE_DISABLE() (PWR->CR &= (uint32_t)(~PWR_CR_UDEN))
00188 
00189 /** @brief  Check PWR flag is set or not.
00190   * @note   These macros can be used only for STM32F42xx/STM3243xx devices.
00191   * @param  __FLAG__ specifies the flag to check.
00192   *         This parameter can be one of the following values:
00193   *            @arg PWR_FLAG_ODRDY: This flag indicates that the Over-drive mode
00194   *                                 is ready 
00195   *            @arg PWR_FLAG_ODSWRDY: This flag indicates that the Over-drive mode
00196   *                                   switching is ready  
00197   *            @arg PWR_FLAG_UDRDY: This flag indicates that the Under-drive mode
00198   *                                 is enabled in Stop mode
00199   * @retval The new state of __FLAG__ (TRUE or FALSE).
00200   */
00201 #define __HAL_PWR_GET_ODRUDR_FLAG(__FLAG__) ((PWR->CSR & (__FLAG__)) == (__FLAG__))
00202 
00203 /** @brief Clear the Under-Drive Ready flag.
00204   * @note  These macros can be used only for STM32F42xx/STM3243xx devices.
00205   */
00206 #define __HAL_PWR_CLEAR_ODRUDR_FLAG() (PWR->CSR |= PWR_FLAG_UDRDY)
00207 
00208 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
00209 /**
00210   * @}
00211   */
00212 
00213 /* Exported functions --------------------------------------------------------*/
00214 /** @addtogroup PWREx_Exported_Functions PWREx Exported Functions
00215   *  @{
00216   */
00217  
00218 /** @addtogroup PWREx_Exported_Functions_Group1
00219   * @{
00220   */
00221 void HAL_PWREx_EnableFlashPowerDown(void);
00222 void HAL_PWREx_DisableFlashPowerDown(void); 
00223 HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg(void);
00224 HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg(void); 
00225 uint32_t HAL_PWREx_GetVoltageRange(void);
00226 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling);
00227 
00228 #if defined(STM32F469xx) || defined(STM32F479xx)
00229 void HAL_PWREx_EnableWakeUpPinPolarityRisingEdge(void);
00230 void HAL_PWREx_EnableWakeUpPinPolarityFallingEdge(void);
00231 #endif /* STM32F469xx || STM32F479xx */
00232 
00233 #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F401xC) ||\
00234     defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F412Zx) || defined(STM32F412Vx) ||\
00235     defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
00236 void HAL_PWREx_EnableMainRegulatorLowVoltage(void);
00237 void HAL_PWREx_DisableMainRegulatorLowVoltage(void);
00238 void HAL_PWREx_EnableLowRegulatorLowVoltage(void);
00239 void HAL_PWREx_DisableLowRegulatorLowVoltage(void);
00240 #endif /* STM32F410xx || STM32F401xC || STM32F401xE || STM32F411xE || STM32F412Zx || STM32F412Vx ||\
00241           STM32F412Rx || STM32F412Cx || STM32F413xx || STM32F423xx */
00242 
00243 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F446xx) ||\
00244     defined(STM32F469xx) || defined(STM32F479xx)
00245 HAL_StatusTypeDef HAL_PWREx_EnableOverDrive(void);
00246 HAL_StatusTypeDef HAL_PWREx_DisableOverDrive(void);
00247 HAL_StatusTypeDef HAL_PWREx_EnterUnderDriveSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
00248 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
00249 
00250 /**
00251   * @}
00252   */
00253 
00254 /**
00255   * @}
00256   */
00257 /* Private types -------------------------------------------------------------*/
00258 /* Private variables ---------------------------------------------------------*/
00259 /* Private constants ---------------------------------------------------------*/
00260 /** @defgroup PWREx_Private_Constants PWREx Private Constants
00261   * @{
00262   */
00263 
00264 /** @defgroup PWREx_register_alias_address PWREx Register alias address
00265   * @{
00266   */
00267 /* ------------- PWR registers bit address in the alias region ---------------*/
00268 /* --- CR Register ---*/
00269 /* Alias word address of FPDS bit */
00270 #define FPDS_BIT_NUMBER          PWR_CR_FPDS_Pos
00271 #define CR_FPDS_BB               (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (FPDS_BIT_NUMBER * 4U))
00272 
00273 /* Alias word address of ODEN bit   */
00274 #define ODEN_BIT_NUMBER          PWR_CR_ODEN_Pos
00275 #define CR_ODEN_BB               (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (ODEN_BIT_NUMBER * 4U))
00276 
00277 /* Alias word address of ODSWEN bit */
00278 #define ODSWEN_BIT_NUMBER        PWR_CR_ODSWEN_Pos
00279 #define CR_ODSWEN_BB             (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (ODSWEN_BIT_NUMBER * 4U))
00280     
00281 /* Alias word address of MRLVDS bit */
00282 #define MRLVDS_BIT_NUMBER        PWR_CR_MRLVDS_Pos
00283 #define CR_MRLVDS_BB             (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (MRLVDS_BIT_NUMBER * 4U))
00284 
00285 /* Alias word address of LPLVDS bit */
00286 #define LPLVDS_BIT_NUMBER        PWR_CR_LPLVDS_Pos
00287 #define CR_LPLVDS_BB             (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (LPLVDS_BIT_NUMBER * 4U))
00288 
00289  /**
00290   * @}
00291   */
00292 
00293 /** @defgroup PWREx_CSR_register_alias PWRx CSR Register alias address
00294   * @{
00295   */  
00296 /* --- CSR Register ---*/
00297 /* Alias word address of BRE bit */
00298 #define BRE_BIT_NUMBER   PWR_CSR_BRE_Pos
00299 #define CSR_BRE_BB      (uint32_t)(PERIPH_BB_BASE + (PWR_CSR_OFFSET_BB * 32U) + (BRE_BIT_NUMBER * 4U))
00300 
00301 #if defined(STM32F469xx) || defined(STM32F479xx)
00302 /* Alias word address of WUPP bit */
00303 #define WUPP_BIT_NUMBER   PWR_CSR_WUPP_Pos
00304 #define CSR_WUPP_BB      (PERIPH_BB_BASE + (PWR_CSR_OFFSET_BB * 32U) + (WUPP_BIT_NUMBER * 4U))
00305 #endif /* STM32F469xx || STM32F479xx */
00306 /**
00307   * @}
00308   */
00309 
00310 /**
00311   * @}
00312   */
00313 
00314 /* Private macros ------------------------------------------------------------*/
00315 /** @defgroup PWREx_Private_Macros PWREx Private Macros
00316   * @{
00317   */
00318 
00319 /** @defgroup PWREx_IS_PWR_Definitions PWREx Private macros to check input parameters
00320   * @{
00321   */
00322 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
00323     defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
00324 #define IS_PWR_REGULATOR_UNDERDRIVE(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_UNDERDRIVE_ON) || \
00325                                                 ((REGULATOR) == PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON))
00326 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
00327 
00328 #if defined(STM32F405xx) || defined(STM32F407xx) || defined(STM32F415xx) || defined(STM32F417xx)
00329 #define IS_PWR_VOLTAGE_SCALING_RANGE(VOLTAGE) (((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE1) || \
00330                                                ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE2))
00331 #else
00332 #define IS_PWR_VOLTAGE_SCALING_RANGE(VOLTAGE) (((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE1) || \
00333                                                ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE2) || \
00334                                                ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE3))
00335 #endif /* STM32F405xx || STM32F407xx || STM32F415xx || STM32F417xx */ 
00336 
00337 #if defined(STM32F446xx)
00338 #define IS_PWR_WAKEUP_PIN(PIN) (((PIN) == PWR_WAKEUP_PIN1) || ((PIN) == PWR_WAKEUP_PIN2))
00339 #elif defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F412Zx) ||\
00340       defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) ||\
00341       defined(STM32F423xx)
00342 #define IS_PWR_WAKEUP_PIN(PIN) (((PIN) == PWR_WAKEUP_PIN1) || ((PIN) == PWR_WAKEUP_PIN2) || \
00343                                 ((PIN) == PWR_WAKEUP_PIN3))
00344 #else
00345 #define IS_PWR_WAKEUP_PIN(PIN) ((PIN) == PWR_WAKEUP_PIN1)
00346 #endif /* STM32F446xx */
00347 /**
00348   * @}
00349   */
00350 
00351 /**
00352   * @}
00353   */
00354 
00355 /**
00356   * @}
00357   */ 
00358 
00359 /**
00360   * @}
00361   */
00362   
00363 #ifdef __cplusplus
00364 }
00365 #endif
00366 
00367 
00368 #endif /* __STM32F4xx_HAL_PWR_EX_H */
00369 
00370 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/