1 /**
2   ******************************************************************************
3   * @file    stm32l1xx_hal_pwr_ex.c
4   * @author  MCD Application Team
5   * @brief   Extended PWR HAL module driver.
6   *          This file provides firmware functions to manage the following
7   *          functionalities of the Power Controller (PWR) peripheral:
8   *           + Extended Initialization and de-initialization functions
9   *           + Extended Peripheral Control functions
10   *
11   ******************************************************************************
12   * @attention
13   *
14   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
15   *
16   * Redistribution and use in source and binary forms, with or without modification,
17   * are permitted provided that the following conditions are met:
18   *   1. Redistributions of source code must retain the above copyright notice,
19   *      this list of conditions and the following disclaimer.
20   *   2. Redistributions in binary form must reproduce the above copyright notice,
21   *      this list of conditions and the following disclaimer in the documentation
22   *      and/or other materials provided with the distribution.
23   *   3. Neither the name of STMicroelectronics nor the names of its contributors
24   *      may be used to endorse or promote products derived from this software
25   *      without specific prior written permission.
26   *
27   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
31   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37   *
38   ******************************************************************************
39   */
40 
41 /* Includes ------------------------------------------------------------------*/
42 #include "stm32l1xx_hal.h"
43 
44 /** @addtogroup STM32L1xx_HAL_Driver
45   * @{
46   */
47 
48 /** @defgroup PWREx PWREx
49   * @brief    PWR HAL module driver
50   * @{
51   */
52 
53 #ifdef HAL_PWR_MODULE_ENABLED
54 
55 /* Private typedef -----------------------------------------------------------*/
56 /* Private define ------------------------------------------------------------*/
57 /* Private macro -------------------------------------------------------------*/
58 /* Private variables ---------------------------------------------------------*/
59 /* Private function prototypes -----------------------------------------------*/
60 /* Private functions ---------------------------------------------------------*/
61 
62 /** @defgroup PWREx_Exported_Functions PWREx Exported Functions
63   * @{
64   */
65 
66 /** @defgroup PWREx_Exported_Functions_Group1 Peripheral Extended Features Functions
67   * @brief    Low Power modes configuration functions
68   *
69 @verbatim
70 
71  ===============================================================================
72                  ##### Peripheral extended features functions #####
73  ===============================================================================
74 @endverbatim
75   * @{
76   */
77 
78 /**
79   * @brief Return Voltage Scaling Range.
80   * @retval VOS bit field (PWR_REGULATOR_VOLTAGE_SCALE1, PWR_REGULATOR_VOLTAGE_SCALE2 or PWR_REGULATOR_VOLTAGE_SCALE3)
81   */
HAL_PWREx_GetVoltageRange(void)82 uint32_t HAL_PWREx_GetVoltageRange(void)
83 {
84   return  (PWR->CR & PWR_CR_VOS);
85 }
86 
87 
88 /**
89   * @brief  Enables the Fast WakeUp from Ultra Low Power mode.
90   * @note   This bit works in conjunction with ULP bit.
91   *         Means, when ULP = 1 and FWU = 1 :VREFINT startup time is ignored when
92   *         exiting from low power mode.
93   * @retval None
94   */
HAL_PWREx_EnableFastWakeUp(void)95 void HAL_PWREx_EnableFastWakeUp(void)
96 {
97   /* Enable the fast wake up */
98   *(__IO uint32_t *) CR_FWU_BB = (uint32_t)ENABLE;
99 }
100 
101 /**
102   * @brief  Disables the Fast WakeUp from Ultra Low Power mode.
103   * @retval None
104   */
HAL_PWREx_DisableFastWakeUp(void)105 void HAL_PWREx_DisableFastWakeUp(void)
106 {
107   /* Disable the fast wake up */
108   *(__IO uint32_t *) CR_FWU_BB = (uint32_t)DISABLE;
109 }
110 
111 /**
112   * @brief  Enables the Ultra Low Power mode
113   * @retval None
114   */
HAL_PWREx_EnableUltraLowPower(void)115 void HAL_PWREx_EnableUltraLowPower(void)
116 {
117   /* Enable the Ultra Low Power mode */
118   *(__IO uint32_t *) CR_ULP_BB = (uint32_t)ENABLE;
119 }
120 
121 /**
122   * @brief  Disables the Ultra Low Power mode
123   * @retval None
124   */
HAL_PWREx_DisableUltraLowPower(void)125 void HAL_PWREx_DisableUltraLowPower(void)
126 {
127   /* Disable the Ultra Low Power mode */
128   *(__IO uint32_t *) CR_ULP_BB = (uint32_t)DISABLE;
129 }
130 
131 /**
132   * @brief  Enters the Low Power Run mode.
133   * @note   Low power run mode can only be entered when VCORE is in range 2.
134   *         In addition, the dynamic voltage scaling must not be used when Low
135   *         power run mode is selected. Only Stop and Sleep modes with regulator
136   *         configured in Low power mode is allowed when Low power run mode is
137   *         selected.
138   * @note   In Low power run mode, all I/O pins keep the same state as in Run mode.
139   * @retval None
140   */
HAL_PWREx_EnableLowPowerRunMode(void)141 void HAL_PWREx_EnableLowPowerRunMode(void)
142 {
143   /* Enters the Low Power Run mode */
144   *(__IO uint32_t *) CR_LPSDSR_BB = (uint32_t)ENABLE;
145   *(__IO uint32_t *) CR_LPRUN_BB  = (uint32_t)ENABLE;
146 }
147 
148 /**
149   * @brief  Exits the Low Power Run mode.
150   * @retval None
151   */
HAL_PWREx_DisableLowPowerRunMode(void)152 HAL_StatusTypeDef HAL_PWREx_DisableLowPowerRunMode(void)
153 {
154   /* Exits the Low Power Run mode */
155   *(__IO uint32_t *) CR_LPRUN_BB  = (uint32_t)DISABLE;
156   *(__IO uint32_t *) CR_LPSDSR_BB = (uint32_t)DISABLE;
157   return HAL_OK;
158 }
159 
160 /**
161   * @}
162   */
163 
164 /**
165   * @}
166   */
167 
168 #endif /* HAL_PWR_MODULE_ENABLED */
169 /**
170   * @}
171   */
172 
173 /**
174   * @}
175   */
176 
177 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
178