STM32F479xx HAL User Manual
stm32f4xx_hal_pwr_ex.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4xx_hal_pwr_ex.c
00004   * @author  MCD Application Team
00005   * @brief   Extended PWR HAL module driver.
00006   *          This file provides firmware functions to manage the following 
00007   *          functionalities of PWR extension peripheral:           
00008   *           + Peripheral Extended features functions
00009   *         
00010   ******************************************************************************
00011   * @attention
00012   *
00013   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
00014   * All rights reserved.</center></h2>
00015   *
00016   * This software component is licensed by ST under BSD 3-Clause license,
00017   * the "License"; You may not use this file except in compliance with the
00018   * License. You may obtain a copy of the License at:
00019   *                        opensource.org/licenses/BSD-3-Clause
00020   *
00021   ******************************************************************************
00022   */ 
00023 
00024 /* Includes ------------------------------------------------------------------*/
00025 #include "stm32f4xx_hal.h"
00026 
00027 /** @addtogroup STM32F4xx_HAL_Driver
00028   * @{
00029   */
00030 
00031 /** @defgroup PWREx PWREx
00032   * @brief PWR HAL module driver
00033   * @{
00034   */
00035 
00036 #ifdef HAL_PWR_MODULE_ENABLED
00037 
00038 /* Private typedef -----------------------------------------------------------*/
00039 /* Private define ------------------------------------------------------------*/
00040 /** @addtogroup PWREx_Private_Constants
00041   * @{
00042   */    
00043 #define PWR_OVERDRIVE_TIMEOUT_VALUE  1000U
00044 #define PWR_UDERDRIVE_TIMEOUT_VALUE  1000U
00045 #define PWR_BKPREG_TIMEOUT_VALUE     1000U
00046 #define PWR_VOSRDY_TIMEOUT_VALUE     1000U
00047 /**
00048   * @}
00049   */
00050 
00051    
00052 /* Private macro -------------------------------------------------------------*/
00053 /* Private variables ---------------------------------------------------------*/
00054 /* Private function prototypes -----------------------------------------------*/
00055 /* Private functions ---------------------------------------------------------*/
00056 /** @defgroup PWREx_Exported_Functions PWREx Exported Functions
00057   *  @{
00058   */
00059 
00060 /** @defgroup PWREx_Exported_Functions_Group1 Peripheral Extended features functions 
00061   *  @brief Peripheral Extended features functions 
00062   *
00063 @verbatim   
00064 
00065  ===============================================================================
00066                  ##### Peripheral extended features functions #####
00067  ===============================================================================
00068 
00069     *** Main and Backup Regulators configuration ***
00070     ================================================
00071     [..] 
00072       (+) The backup domain includes 4 Kbytes of backup SRAM accessible only from 
00073           the CPU, and address in 32-bit, 16-bit or 8-bit mode. Its content is 
00074           retained even in Standby or VBAT mode when the low power backup regulator
00075           is enabled. It can be considered as an internal EEPROM when VBAT is 
00076           always present. You can use the HAL_PWREx_EnableBkUpReg() function to 
00077           enable the low power backup regulator. 
00078 
00079       (+) When the backup domain is supplied by VDD (analog switch connected to VDD) 
00080           the backup SRAM is powered from VDD which replaces the VBAT power supply to 
00081           save battery life.
00082 
00083       (+) The backup SRAM is not mass erased by a tamper event. It is read 
00084           protected to prevent confidential data, such as cryptographic private 
00085           key, from being accessed. The backup SRAM can be erased only through 
00086           the Flash interface when a protection level change from level 1 to 
00087           level 0 is requested. 
00088       -@- Refer to the description of Read protection (RDP) in the Flash 
00089           programming manual.
00090 
00091       (+) The main internal regulator can be configured to have a tradeoff between 
00092           performance and power consumption when the device does not operate at 
00093           the maximum frequency. This is done through __HAL_PWR_MAINREGULATORMODE_CONFIG() 
00094           macro which configure VOS bit in PWR_CR register
00095           
00096         Refer to the product datasheets for more details.
00097 
00098     *** FLASH Power Down configuration ****
00099     =======================================
00100     [..] 
00101       (+) By setting the FPDS bit in the PWR_CR register by using the 
00102           HAL_PWREx_EnableFlashPowerDown() function, the Flash memory also enters power 
00103           down mode when the device enters Stop mode. When the Flash memory 
00104           is in power down mode, an additional startup delay is incurred when 
00105           waking up from Stop mode.
00106           
00107            (+) For STM32F42xxx/43xxx/446xx/469xx/479xx Devices, the scale can be modified only when the PLL 
00108            is OFF and the HSI or HSE clock source is selected as system clock. 
00109            The new value programmed is active only when the PLL is ON.
00110            When the PLL is OFF, the voltage scale 3 is automatically selected. 
00111         Refer to the datasheets for more details.
00112 
00113     *** Over-Drive and Under-Drive configuration ****
00114     =================================================
00115     [..]         
00116        (+) For STM32F42xxx/43xxx/446xx/469xx/479xx Devices, in Run mode: the main regulator has
00117            2 operating modes available:
00118         (++) Normal mode: The CPU and core logic operate at maximum frequency at a given 
00119              voltage scaling (scale 1, scale 2 or scale 3)
00120         (++) Over-drive mode: This mode allows the CPU and the core logic to operate at a 
00121             higher frequency than the normal mode for a given voltage scaling (scale 1,  
00122             scale 2 or scale 3). This mode is enabled through HAL_PWREx_EnableOverDrive() function and
00123             disabled by HAL_PWREx_DisableOverDrive() function, to enter or exit from Over-drive mode please follow 
00124             the sequence described in Reference manual.
00125              
00126        (+) For STM32F42xxx/43xxx/446xx/469xx/479xx Devices, in Stop mode: the main regulator or low power regulator 
00127            supplies a low power voltage to the 1.2V domain, thus preserving the content of registers 
00128            and internal SRAM. 2 operating modes are available:
00129          (++) Normal mode: the 1.2V domain is preserved in nominal leakage mode. This mode is only 
00130               available when the main regulator or the low power regulator is used in Scale 3 or 
00131               low voltage mode.
00132          (++) Under-drive mode: the 1.2V domain is preserved in reduced leakage mode. This mode is only
00133               available when the main regulator or the low power regulator is in low voltage mode.
00134 
00135 @endverbatim
00136   * @{
00137   */
00138 
00139 /**
00140   * @brief Enables the Backup Regulator.
00141   * @retval HAL status
00142   */
00143 HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg(void)
00144 {
00145   uint32_t tickstart = 0U;
00146 
00147   *(__IO uint32_t *) CSR_BRE_BB = (uint32_t)ENABLE;
00148 
00149   /* Get tick */
00150   tickstart = HAL_GetTick();
00151 
00152   /* Wait till Backup regulator ready flag is set */  
00153   while(__HAL_PWR_GET_FLAG(PWR_FLAG_BRR) == RESET)
00154   {
00155     if((HAL_GetTick() - tickstart ) > PWR_BKPREG_TIMEOUT_VALUE)
00156     {
00157       return HAL_TIMEOUT;
00158     } 
00159   }
00160   return HAL_OK;
00161 }
00162 
00163 /**
00164   * @brief Disables the Backup Regulator.
00165   * @retval HAL status
00166   */
00167 HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg(void)
00168 {
00169   uint32_t tickstart = 0U;
00170 
00171   *(__IO uint32_t *) CSR_BRE_BB = (uint32_t)DISABLE;
00172 
00173   /* Get tick */
00174   tickstart = HAL_GetTick();
00175 
00176   /* Wait till Backup regulator ready flag is set */  
00177   while(__HAL_PWR_GET_FLAG(PWR_FLAG_BRR) != RESET)
00178   {
00179     if((HAL_GetTick() - tickstart ) > PWR_BKPREG_TIMEOUT_VALUE)
00180     {
00181       return HAL_TIMEOUT;
00182     } 
00183   }
00184   return HAL_OK;
00185 }
00186 
00187 /**
00188   * @brief Enables the Flash Power Down in Stop mode.
00189   * @retval None
00190   */
00191 void HAL_PWREx_EnableFlashPowerDown(void)
00192 {
00193   *(__IO uint32_t *) CR_FPDS_BB = (uint32_t)ENABLE;
00194 }
00195 
00196 /**
00197   * @brief Disables the Flash Power Down in Stop mode.
00198   * @retval None
00199   */
00200 void HAL_PWREx_DisableFlashPowerDown(void)
00201 {
00202   *(__IO uint32_t *) CR_FPDS_BB = (uint32_t)DISABLE;
00203 }
00204 
00205 /**
00206   * @brief Return Voltage Scaling Range.
00207   * @retval The configured scale for the regulator voltage(VOS bit field).
00208   *         The returned value can be one of the following:
00209   *            - @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output Scale 1 mode
00210   *            - @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output Scale 2 mode
00211   *            - @arg PWR_REGULATOR_VOLTAGE_SCALE3: Regulator voltage output Scale 3 mode
00212   */  
00213 uint32_t HAL_PWREx_GetVoltageRange(void)
00214 {
00215   return (PWR->CR & PWR_CR_VOS);
00216 }
00217 
00218 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx)
00219 /**
00220   * @brief Configures the main internal regulator output voltage.
00221   * @param  VoltageScaling specifies the regulator output voltage to achieve
00222   *         a tradeoff between performance and power consumption.
00223   *          This parameter can be one of the following values:
00224   *            @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output range 1 mode,
00225   *                                               the maximum value of fHCLK = 168 MHz.
00226   *            @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output range 2 mode,
00227   *                                               the maximum value of fHCLK = 144 MHz.
00228   * @note  When moving from Range 1 to Range 2, the system frequency must be decreased to
00229   *        a value below 144 MHz before calling HAL_PWREx_ConfigVoltageScaling() API.
00230   *        When moving from Range 2 to Range 1, the system frequency can be increased to
00231   *        a value up to 168 MHz after calling HAL_PWREx_ConfigVoltageScaling() API.
00232   * @retval HAL Status
00233   */
00234 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)
00235 {
00236   uint32_t tickstart = 0U;
00237   
00238   assert_param(IS_PWR_VOLTAGE_SCALING_RANGE(VoltageScaling));
00239   
00240   /* Enable PWR RCC Clock Peripheral */
00241   __HAL_RCC_PWR_CLK_ENABLE();
00242   
00243   /* Set Range */
00244   __HAL_PWR_VOLTAGESCALING_CONFIG(VoltageScaling);
00245   
00246   /* Get Start Tick*/
00247   tickstart = HAL_GetTick();
00248   while((__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY) == RESET))
00249   {
00250     if((HAL_GetTick() - tickstart ) > PWR_VOSRDY_TIMEOUT_VALUE)
00251     {
00252       return HAL_TIMEOUT;
00253     } 
00254   }
00255 
00256   return HAL_OK;
00257 }
00258 
00259 #elif defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \
00260       defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) || \
00261       defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F469xx) || \
00262       defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || \
00263       defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
00264 /**
00265   * @brief Configures the main internal regulator output voltage.
00266   * @param  VoltageScaling specifies the regulator output voltage to achieve
00267   *         a tradeoff between performance and power consumption.
00268   *          This parameter can be one of the following values:
00269   *            @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output range 1 mode,
00270   *                                               the maximum value of fHCLK is 168 MHz. It can be extended to
00271   *                                               180 MHz by activating the over-drive mode.
00272   *            @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output range 2 mode,
00273   *                                               the maximum value of fHCLK is 144 MHz. It can be extended to,                
00274   *                                               168 MHz by activating the over-drive mode.
00275   *            @arg PWR_REGULATOR_VOLTAGE_SCALE3: Regulator voltage output range 3 mode,
00276   *                                               the maximum value of fHCLK is 120 MHz.
00277   * @note To update the system clock frequency(SYSCLK):
00278   *        - Set the HSI or HSE as system clock frequency using the HAL_RCC_ClockConfig().
00279   *        - Call the HAL_RCC_OscConfig() to configure the PLL.
00280   *        - Call HAL_PWREx_ConfigVoltageScaling() API to adjust the voltage scale.
00281   *        - Set the new system clock frequency using the HAL_RCC_ClockConfig().
00282   * @note The scale can be modified only when the HSI or HSE clock source is selected 
00283   *        as system clock source, otherwise the API returns HAL_ERROR.  
00284   * @note When the PLL is OFF, the voltage scale 3 is automatically selected and the VOS bits
00285   *       value in the PWR_CR1 register are not taken in account.
00286   * @note This API forces the PLL state ON to allow the possibility to configure the voltage scale 1 or 2.
00287   * @note The new voltage scale is active only when the PLL is ON.  
00288   * @retval HAL Status
00289   */
00290 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)
00291 {
00292   uint32_t tickstart = 0U;
00293   
00294   assert_param(IS_PWR_VOLTAGE_SCALING_RANGE(VoltageScaling));
00295   
00296   /* Enable PWR RCC Clock Peripheral */
00297   __HAL_RCC_PWR_CLK_ENABLE();
00298   
00299   /* Check if the PLL is used as system clock or not */
00300   if(__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_PLL)
00301   {
00302     /* Disable the main PLL */
00303     __HAL_RCC_PLL_DISABLE();
00304     
00305     /* Get Start Tick */
00306     tickstart = HAL_GetTick();    
00307     /* Wait till PLL is disabled */  
00308     while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET)
00309     {
00310       if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
00311       {
00312         return HAL_TIMEOUT;
00313       }
00314     }
00315     
00316     /* Set Range */
00317     __HAL_PWR_VOLTAGESCALING_CONFIG(VoltageScaling);
00318     
00319     /* Enable the main PLL */
00320     __HAL_RCC_PLL_ENABLE();
00321     
00322     /* Get Start Tick */
00323     tickstart = HAL_GetTick();
00324     /* Wait till PLL is ready */  
00325     while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)
00326     {
00327       if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
00328       {
00329         return HAL_TIMEOUT;
00330       } 
00331     }
00332     
00333     /* Get Start Tick */
00334     tickstart = HAL_GetTick();
00335     while((__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY) == RESET))
00336     {
00337       if((HAL_GetTick() - tickstart ) > PWR_VOSRDY_TIMEOUT_VALUE)
00338       {
00339         return HAL_TIMEOUT;
00340       } 
00341     }
00342   }
00343   else
00344   {
00345     return HAL_ERROR;
00346   }
00347 
00348   return HAL_OK;
00349 }
00350 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx */
00351 
00352 #if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) ||\
00353     defined(STM32F411xE) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) ||\
00354     defined(STM32F413xx) || defined(STM32F423xx)
00355 /**
00356   * @brief Enables Main Regulator low voltage mode.
00357   * @note  This mode is only available for STM32F401xx/STM32F410xx/STM32F411xx/STM32F412Zx/STM32F412Rx/STM32F412Vx/STM32F412Cx/
00358   *        STM32F413xx/STM32F423xx devices.   
00359   * @retval None
00360   */
00361 void HAL_PWREx_EnableMainRegulatorLowVoltage(void)
00362 {
00363   *(__IO uint32_t *) CR_MRLVDS_BB = (uint32_t)ENABLE;
00364 }
00365 
00366 /**
00367   * @brief Disables Main Regulator low voltage mode.
00368   * @note  This mode is only available for STM32F401xx/STM32F410xx/STM32F411xx/STM32F412Zx/STM32F412Rx/STM32F412Vx/STM32F412Cx/
00369   *        STM32F413xx/STM32F423xxdevices. 
00370   * @retval None
00371   */
00372 void HAL_PWREx_DisableMainRegulatorLowVoltage(void)
00373 {
00374   *(__IO uint32_t *) CR_MRLVDS_BB = (uint32_t)DISABLE;
00375 }
00376 
00377 /**
00378   * @brief Enables Low Power Regulator low voltage mode.
00379   * @note  This mode is only available for STM32F401xx/STM32F410xx/STM32F411xx/STM32F412Zx/STM32F412Rx/STM32F412Vx/STM32F412Cx/
00380   *        STM32F413xx/STM32F423xx devices.   
00381   * @retval None
00382   */
00383 void HAL_PWREx_EnableLowRegulatorLowVoltage(void)
00384 {
00385   *(__IO uint32_t *) CR_LPLVDS_BB = (uint32_t)ENABLE;
00386 }
00387 
00388 /**
00389   * @brief Disables Low Power Regulator low voltage mode.
00390   * @note  This mode is only available for STM32F401xx/STM32F410xx/STM32F411xx/STM32F412Zx/STM32F412Rx/STM32F412Vx/STM32F412Cx/
00391   *        STM32F413xx/STM32F423xx  devices.   
00392   * @retval None
00393   */
00394 void HAL_PWREx_DisableLowRegulatorLowVoltage(void)
00395 {
00396   *(__IO uint32_t *) CR_LPLVDS_BB = (uint32_t)DISABLE;
00397 }
00398 
00399 #endif /* STM32F401xC || STM32F401xE || STM32F410xx || STM32F411xE || STM32F412Zx || STM32F412Rx || STM32F412Vx || STM32F412Cx ||
00400           STM32F413xx || STM32F423xx */
00401 
00402 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
00403     defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
00404 /**
00405   * @brief  Activates the Over-Drive mode.
00406   * @note   This function can be used only for STM32F42xx/STM32F43xx/STM32F446xx/STM32F469xx/STM32F479xx devices.
00407   *         This mode allows the CPU and the core logic to operate at a higher frequency
00408   *         than the normal mode for a given voltage scaling (scale 1, scale 2 or scale 3).   
00409   * @note   It is recommended to enter or exit Over-drive mode when the application is not running 
00410   *         critical tasks and when the system clock source is either HSI or HSE. 
00411   *         During the Over-drive switch activation, no peripheral clocks should be enabled.   
00412   *         The peripheral clocks must be enabled once the Over-drive mode is activated.   
00413   * @retval HAL status
00414   */
00415 HAL_StatusTypeDef HAL_PWREx_EnableOverDrive(void)
00416 {
00417   uint32_t tickstart = 0U;
00418 
00419   __HAL_RCC_PWR_CLK_ENABLE();
00420   
00421   /* Enable the Over-drive to extend the clock frequency to 180 Mhz */
00422   __HAL_PWR_OVERDRIVE_ENABLE();
00423 
00424   /* Get tick */
00425   tickstart = HAL_GetTick();
00426 
00427   while(!__HAL_PWR_GET_FLAG(PWR_FLAG_ODRDY))
00428   {
00429     if((HAL_GetTick() - tickstart) > PWR_OVERDRIVE_TIMEOUT_VALUE)
00430     {
00431       return HAL_TIMEOUT;
00432     }
00433   }
00434   
00435   /* Enable the Over-drive switch */
00436   __HAL_PWR_OVERDRIVESWITCHING_ENABLE();
00437 
00438   /* Get tick */
00439   tickstart = HAL_GetTick();
00440 
00441   while(!__HAL_PWR_GET_FLAG(PWR_FLAG_ODSWRDY))
00442   {
00443     if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)
00444     {
00445       return HAL_TIMEOUT;
00446     }
00447   } 
00448   return HAL_OK;
00449 }
00450 
00451 /**
00452   * @brief  Deactivates the Over-Drive mode.
00453   * @note   This function can be used only for STM32F42xx/STM32F43xx/STM32F446xx/STM32F469xx/STM32F479xx devices.
00454   *         This mode allows the CPU and the core logic to operate at a higher frequency
00455   *         than the normal mode for a given voltage scaling (scale 1, scale 2 or scale 3).    
00456   * @note   It is recommended to enter or exit Over-drive mode when the application is not running 
00457   *         critical tasks and when the system clock source is either HSI or HSE. 
00458   *         During the Over-drive switch activation, no peripheral clocks should be enabled.   
00459   *         The peripheral clocks must be enabled once the Over-drive mode is activated.
00460   * @retval HAL status
00461   */
00462 HAL_StatusTypeDef HAL_PWREx_DisableOverDrive(void)
00463 {
00464   uint32_t tickstart = 0U;
00465   
00466   __HAL_RCC_PWR_CLK_ENABLE();
00467     
00468   /* Disable the Over-drive switch */
00469   __HAL_PWR_OVERDRIVESWITCHING_DISABLE();
00470   
00471   /* Get tick */
00472   tickstart = HAL_GetTick();
00473  
00474   while(__HAL_PWR_GET_FLAG(PWR_FLAG_ODSWRDY))
00475   {
00476     if((HAL_GetTick() - tickstart) > PWR_OVERDRIVE_TIMEOUT_VALUE)
00477     {
00478       return HAL_TIMEOUT;
00479     }
00480   } 
00481   
00482   /* Disable the Over-drive */
00483   __HAL_PWR_OVERDRIVE_DISABLE();
00484 
00485   /* Get tick */
00486   tickstart = HAL_GetTick();
00487 
00488   while(__HAL_PWR_GET_FLAG(PWR_FLAG_ODRDY))
00489   {
00490     if((HAL_GetTick() - tickstart) > PWR_OVERDRIVE_TIMEOUT_VALUE)
00491     {
00492       return HAL_TIMEOUT;
00493     }
00494   }
00495   
00496   return HAL_OK;
00497 }
00498 
00499 /**
00500   * @brief  Enters in Under-Drive STOP mode.
00501   *  
00502   * @note   This mode is only available for STM32F42xxx/STM32F43xxx/STM32F446xx/STM32F469xx/STM32F479xx devices.
00503   * 
00504   * @note    This mode can be selected only when the Under-Drive is already active 
00505   *   
00506   * @note    This mode is enabled only with STOP low power mode.
00507   *          In this mode, the 1.2V domain is preserved in reduced leakage mode. This 
00508   *          mode is only available when the main regulator or the low power regulator 
00509   *          is in low voltage mode
00510   *        
00511   * @note   If the Under-drive mode was enabled, it is automatically disabled after 
00512   *         exiting Stop mode. 
00513   *         When the voltage regulator operates in Under-drive mode, an additional  
00514   *         startup delay is induced when waking up from Stop mode.
00515   *                    
00516   * @note   In Stop mode, all I/O pins keep the same state as in Run mode.
00517   *   
00518   * @note   When exiting Stop mode by issuing an interrupt or a wake-up event, 
00519   *         the HSI RC oscillator is selected as system clock.
00520   *           
00521   * @note   When the voltage regulator operates in low power mode, an additional 
00522   *         startup delay is incurred when waking up from Stop mode. 
00523   *         By keeping the internal regulator ON during Stop mode, the consumption 
00524   *         is higher although the startup time is reduced.
00525   *     
00526   * @param  Regulator specifies the regulator state in STOP mode.
00527   *          This parameter can be one of the following values:
00528   *            @arg PWR_MAINREGULATOR_UNDERDRIVE_ON:  Main Regulator in under-drive mode 
00529   *                 and Flash memory in power-down when the device is in Stop under-drive mode
00530   *            @arg PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON:  Low Power Regulator in under-drive mode 
00531   *                and Flash memory in power-down when the device is in Stop under-drive mode
00532   * @param  STOPEntry specifies if STOP mode in entered with WFI or WFE instruction.
00533   *          This parameter can be one of the following values:
00534   *            @arg PWR_SLEEPENTRY_WFI: enter STOP mode with WFI instruction
00535   *            @arg PWR_SLEEPENTRY_WFE: enter STOP mode with WFE instruction
00536   * @retval None
00537   */
00538 HAL_StatusTypeDef HAL_PWREx_EnterUnderDriveSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
00539 {
00540   uint32_t tmpreg1 = 0U;
00541 
00542   /* Check the parameters */
00543   assert_param(IS_PWR_REGULATOR_UNDERDRIVE(Regulator));
00544   assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
00545   
00546   /* Enable Power ctrl clock */
00547   __HAL_RCC_PWR_CLK_ENABLE();
00548   /* Enable the Under-drive Mode ---------------------------------------------*/
00549   /* Clear Under-drive flag */
00550   __HAL_PWR_CLEAR_ODRUDR_FLAG();
00551   
00552   /* Enable the Under-drive */ 
00553   __HAL_PWR_UNDERDRIVE_ENABLE();
00554 
00555   /* Select the regulator state in STOP mode ---------------------------------*/
00556   tmpreg1 = PWR->CR;
00557   /* Clear PDDS, LPDS, MRLUDS and LPLUDS bits */
00558   tmpreg1 &= (uint32_t)~(PWR_CR_PDDS | PWR_CR_LPDS | PWR_CR_LPUDS | PWR_CR_MRUDS);
00559   
00560   /* Set LPDS, MRLUDS and LPLUDS bits according to PWR_Regulator value */
00561   tmpreg1 |= Regulator;
00562   
00563   /* Store the new value */
00564   PWR->CR = tmpreg1;
00565   
00566   /* Set SLEEPDEEP bit of Cortex System Control Register */
00567   SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
00568   
00569   /* Select STOP mode entry --------------------------------------------------*/
00570   if(STOPEntry == PWR_SLEEPENTRY_WFI)
00571   {   
00572     /* Request Wait For Interrupt */
00573     __WFI();
00574   }
00575   else
00576   {
00577     /* Request Wait For Event */
00578     __WFE();
00579   }
00580   /* Reset SLEEPDEEP bit of Cortex System Control Register */
00581   SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
00582 
00583   return HAL_OK;  
00584 }
00585 
00586 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
00587 /**
00588   * @}
00589   */
00590 
00591 /**
00592   * @}
00593   */
00594 
00595 #endif /* HAL_PWR_MODULE_ENABLED */
00596 /**
00597   * @}
00598   */
00599 
00600 /**
00601   * @}
00602   */
00603 
00604 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/