2 ******************************************************************************
3 * @file stm32l0xx_hal_pwr_ex.c
4 * @author MCD Application Team
6 * @date 06-February-2015
7 * @brief Extended PWR HAL module driver.
8 * This file provides firmware functions to manage the following
9 * functionalities of the Power Controller (PWR) peripheral:
10 * + Extended Initialization and de-initialization functions
11 * + Extended Peripheral Control functions
13 ******************************************************************************
16 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
18 * Redistribution and use in source and binary forms, with or without modification,
19 * are permitted provided that the following conditions are met:
20 * 1. Redistributions of source code must retain the above copyright notice,
21 * this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright notice,
23 * this list of conditions and the following disclaimer in the documentation
24 * and/or other materials provided with the distribution.
25 * 3. Neither the name of STMicroelectronics nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 ******************************************************************************
43 /* Includes ------------------------------------------------------------------*/
44 #include "stm32l0xx_hal.h"
46 #ifdef HAL_PWR_MODULE_ENABLED
47 /** @addtogroup STM32L0xx_HAL_Driver
55 /** @defgroup PWR_Extended_TimeOut_Value PWR Extended Flag Setting Time Out Value
58 #define PWR_FLAG_SETTING_DELAY_US 50
64 /** @addtogroup PWREx_Exported_Functions
65 * @brief Low Power modes configuration functions
69 ===============================================================================
70 ##### Peripheral extended features functions #####
71 ===============================================================================
77 * @brief Enables the Fast WakeUp from Ultra Low Power mode.
78 * @note This bit works in conjunction with ULP bit.
79 * Means, when ULP = 1 and FWU = 1 :VREFINT startup time is ignored when
80 * exiting from low power mode.
83 void HAL_PWREx_EnableFastWakeUp(void)
85 /* Enable the fast wake up */
86 SET_BIT(PWR->CR, PWR_CR_FWU);
90 * @brief Disables the Fast WakeUp from Ultra Low Power mode.
93 void HAL_PWREx_DisableFastWakeUp(void)
95 /* Disable the fast wake up */
96 CLEAR_BIT(PWR->CR, PWR_CR_FWU);
100 * @brief Enables the Ultra Low Power mode
103 void HAL_PWREx_EnableUltraLowPower(void)
105 /* Enable the Ultra Low Power mode */
106 SET_BIT(PWR->CR, PWR_CR_ULP);
110 * @brief Disables the Ultra Low Power mode
113 void HAL_PWREx_DisableUltraLowPower(void)
115 /* Disable the Ultra Low Power mode */
116 CLEAR_BIT(PWR->CR, PWR_CR_ULP);
120 * @brief Enable the Low Power Run mode.
121 * @note Low power run mode can only be entered when VCORE is in range 2.
122 * In addition, the dynamic voltage scaling must not be used when Low
123 * power run mode is selected. Only Stop and Sleep modes with regulator
124 * configured in Low power mode is allowed when Low power run mode is
126 * @note The frequency of the system clock must be decreased to not exceed the
127 * frequency of RCC_MSIRANGE_1.
128 * @note In Low power run mode, all I/O pins keep the same state as in Run mode.
131 void HAL_PWREx_EnableLowPowerRunMode(void)
133 /* Enters the Low Power Run mode */
134 SET_BIT(PWR->CR, PWR_CR_LPSDSR);
135 SET_BIT(PWR->CR, PWR_CR_LPRUN);
139 * @brief Disable the Low Power Run mode.
140 * @note Before HAL_PWREx_DisableLowPowerRunMode() completion, the function checks that
141 * REGLPF has been properly reset (otherwise, HAL_PWREx_DisableLowPowerRunMode
142 * returns HAL_TIMEOUT status). The system clock frequency can then be
143 * increased above 2 MHz.
144 * @retval HAL_StatusTypeDef
146 HAL_StatusTypeDef HAL_PWREx_DisableLowPowerRunMode(void)
148 uint32_t wait_loop_index = 0;
150 /* Exit the Low Power Run mode */
151 CLEAR_BIT(PWR->CR, PWR_CR_LPRUN);
152 CLEAR_BIT(PWR->CR, PWR_CR_LPSDSR);
154 /* Wait until REGLPF is reset */
155 wait_loop_index = (PWR_FLAG_SETTING_DELAY_US * (SystemCoreClock / 1000000));
157 while ((wait_loop_index != 0) && (HAL_IS_BIT_SET(PWR->CSR, PWR_CSR_REGLPF)))
162 if (HAL_IS_BIT_SET(PWR->CSR, PWR_CSR_REGLPF))
181 #endif /* HAL_PWR_MODULE_ENABLED */
183 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/