Rev 49 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 49 | Rev 50 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | /** |
1 | /** |
| 2 | ****************************************************************************** |
2 | ****************************************************************************** |
| 3 | * @file stm32l1xx_hal_pwr.c |
3 | * @file stm32l1xx_hal_pwr.c |
| 4 | * @author MCD Application Team |
4 | * @author MCD Application Team |
| 5 | * @version V1.2.0 |
- | |
| 6 | * @date 01-July-2016 |
- | |
| 7 | * @brief PWR HAL module driver. |
5 | * @brief PWR HAL module driver. |
| 8 | * |
6 | * |
| 9 | * This file provides firmware functions to manage the following |
7 | * This file provides firmware functions to manage the following |
| 10 | * functionalities of the Power Controller (PWR) peripheral: |
8 | * functionalities of the Power Controller (PWR) peripheral: |
| 11 | * + Initialization/de-initialization functions |
9 | * + Initialization/de-initialization functions |
| 12 | * + Peripheral Control functions |
10 | * + Peripheral Control functions |
| 13 | * |
11 | * |
| 14 | ****************************************************************************** |
12 | ****************************************************************************** |
| 15 | * @attention |
13 | * @attention |
| 16 | * |
14 | * |
| 17 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
15 | * <h2><center>© Copyright (c) 2017 STMicroelectronics. |
| - | 16 | * All rights reserved.</center></h2> |
|
| 18 | * |
17 | * |
| 19 | * Redistribution and use in source and binary forms, with or without modification, |
18 | * This software component is licensed by ST under BSD 3-Clause license, |
| 20 | * are permitted provided that the following conditions are met: |
19 | * the "License"; You may not use this file except in compliance with the |
| 21 | * 1. Redistributions of source code must retain the above copyright notice, |
- | |
| 22 | * this list of conditions and the following disclaimer. |
- | |
| 23 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
- | |
| 24 | * this list of conditions and the following disclaimer in the documentation |
- | |
| 25 | * and/or other materials provided with the distribution. |
20 | * License. You may obtain a copy of the License at: |
| 26 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
- | |
| 27 | * may be used to endorse or promote products derived from this software |
21 | * opensource.org/licenses/BSD-3-Clause |
| 28 | * without specific prior written permission. |
- | |
| 29 | * |
- | |
| 30 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
- | |
| 31 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
- | |
| 32 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
- | |
| 33 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
- | |
| 34 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
- | |
| 35 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
- | |
| 36 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
- | |
| 37 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
- | |
| 38 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
- | |
| 39 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
- | |
| 40 | * |
22 | * |
| 41 | ****************************************************************************** |
23 | ****************************************************************************** |
| 42 | */ |
24 | */ |
| 43 | 25 | ||
| 44 | /* Includes ------------------------------------------------------------------*/ |
26 | /* Includes ------------------------------------------------------------------*/ |
| Line 55... | Line 37... | ||
| 55 | 37 | ||
| 56 | #ifdef HAL_PWR_MODULE_ENABLED |
38 | #ifdef HAL_PWR_MODULE_ENABLED |
| 57 | 39 | ||
| 58 | /* Private typedef -----------------------------------------------------------*/ |
40 | /* Private typedef -----------------------------------------------------------*/ |
| 59 | /* Private define ------------------------------------------------------------*/ |
41 | /* Private define ------------------------------------------------------------*/ |
| 60 | #define PVD_MODE_IT ((uint32_t)0x00010000) |
42 | #define PVD_MODE_IT (0x00010000U) |
| 61 | #define PVD_MODE_EVT ((uint32_t)0x00020000) |
43 | #define PVD_MODE_EVT (0x00020000U) |
| 62 | #define PVD_RISING_EDGE ((uint32_t)0x00000001) |
44 | #define PVD_RISING_EDGE (0x00000001U) |
| 63 | #define PVD_FALLING_EDGE ((uint32_t)0x00000002) |
45 | #define PVD_FALLING_EDGE (0x00000002U) |
| 64 | 46 | ||
| 65 | /* Private macro -------------------------------------------------------------*/ |
47 | /* Private macro -------------------------------------------------------------*/ |
| 66 | /* Private variables ---------------------------------------------------------*/ |
48 | /* Private variables ---------------------------------------------------------*/ |
| 67 | /* Private function prototypes -----------------------------------------------*/ |
49 | /* Private function prototypes -----------------------------------------------*/ |
| 68 | /* Private functions ---------------------------------------------------------*/ |
50 | /* Private functions ---------------------------------------------------------*/ |
| 69 | 51 | ||
| 70 | /** @defgroup PWR_Exported_Functions PWR Exported Functions |
52 | /** @defgroup PWR_Exported_Functions PWR Exported Functions |
| 71 | * @{ |
53 | * @{ |
| 72 | */ |
54 | */ |
| 73 | 55 | ||
| 74 | /** @defgroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions |
56 | /** @defgroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions |
| 75 | * @brief Initialization and de-initialization functions |
57 | * @brief Initialization and de-initialization functions |
| 76 | * |
58 | * |
| 77 | @verbatim |
59 | @verbatim |
| 78 | =============================================================================== |
60 | =============================================================================== |
| 79 | ##### Initialization and de-initialization functions ##### |
61 | ##### Initialization and de-initialization functions ##### |
| Line 91... | Line 73... | ||
| 91 | * @{ |
73 | * @{ |
| 92 | */ |
74 | */ |
| 93 | 75 | ||
| 94 | /** |
76 | /** |
| 95 | * @brief Deinitializes the PWR peripheral registers to their default reset values. |
77 | * @brief Deinitializes the PWR peripheral registers to their default reset values. |
| 96 | * @note Before calling this function, the VOS[1:0] bits should be configured |
78 | * @note Before calling this function, the VOS[1:0] bits should be configured |
| 97 | * to "10" and the system frequency has to be configured accordingly. |
79 | * to "10" and the system frequency has to be configured accordingly. |
| 98 | * To configure the VOS[1:0] bits, use the PWR_VoltageScalingConfig() |
80 | * To configure the VOS[1:0] bits, use the PWR_VoltageScalingConfig() |
| 99 | * function. |
81 | * function. |
| 100 | * @note ULP and FWU bits are not reset by this function. |
82 | * @note ULP and FWU bits are not reset by this function. |
| 101 | * @retval None |
83 | * @retval None |
| 102 | */ |
84 | */ |
| 103 | void HAL_PWR_DeInit(void) |
85 | void HAL_PWR_DeInit(void) |
| 104 | { |
86 | { |
| 105 | __HAL_RCC_PWR_FORCE_RESET(); |
87 | __HAL_RCC_PWR_FORCE_RESET(); |
| Line 134... | Line 116... | ||
| 134 | 116 | ||
| 135 | /** |
117 | /** |
| 136 | * @} |
118 | * @} |
| 137 | */ |
119 | */ |
| 138 | 120 | ||
| 139 | /** @defgroup PWR_Exported_Functions_Group2 Peripheral Control functions |
121 | /** @defgroup PWR_Exported_Functions_Group2 Peripheral Control functions |
| 140 | * @brief Low Power modes configuration functions |
122 | * @brief Low Power modes configuration functions |
| 141 | * |
123 | * |
| 142 | @verbatim |
124 | @verbatim |
| 143 | 125 | ||
| 144 | =============================================================================== |
126 | =============================================================================== |
| 145 | ##### Peripheral Control functions ##### |
127 | ##### Peripheral Control functions ##### |
| 146 | =============================================================================== |
128 | =============================================================================== |
| 147 | |
129 | |
| 148 | *** PVD configuration *** |
130 | *** PVD configuration *** |
| 149 | ========================= |
131 | ========================= |
| 150 | [..] |
132 | [..] |
| 151 | (+) The PVD is used to monitor the VDD power supply by comparing it to a |
133 | (+) The PVD is used to monitor the VDD power supply by comparing it to a |
| 152 | threshold selected by the PVD Level (PLS[2:0] bits in the PWR_CR). |
134 | threshold selected by the PVD Level (PLS[2:0] bits in the PWR_CR). |
| 153 | (+) The PVD can use an external input analog voltage (PVD_IN) which is compared |
135 | (+) The PVD can use an external input analog voltage (PVD_IN) which is compared |
| 154 | internally to VREFINT. The PVD_IN (PB7) has to be configured in Analog mode |
136 | internally to VREFINT. The PVD_IN (PB7) has to be configured in Analog mode |
| 155 | when PWR_PVDLevel_7 is selected (PLS[2:0] = 111). |
137 | when PWR_PVDLevel_7 is selected (PLS[2:0] = 111). |
| 156 | 138 | ||
| 157 | (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower |
139 | (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower |
| 158 | than the PVD threshold. This event is internally connected to the EXTI |
140 | than the PVD threshold. This event is internally connected to the EXTI |
| 159 | line16 and can generate an interrupt if enabled. This is done through |
141 | line16 and can generate an interrupt if enabled. This is done through |
| Line 166... | Line 148... | ||
| 166 | (+) WakeUp pin is used to wake up the system from Standby mode. This pin is |
148 | (+) WakeUp pin is used to wake up the system from Standby mode. This pin is |
| 167 | forced in input pull-down configuration and is active on rising edges. |
149 | forced in input pull-down configuration and is active on rising edges. |
| 168 | (+) There are two or three WakeUp pins: |
150 | (+) There are two or three WakeUp pins: |
| 169 | WakeUp Pin 1 on PA.00. |
151 | WakeUp Pin 1 on PA.00. |
| 170 | WakeUp Pin 2 on PC.13. |
152 | WakeUp Pin 2 on PC.13. |
| 171 | WakeUp Pin 3 on PE.06. : Only on product with GPIOE available |
153 | WakeUp Pin 3 on PE.06. : Only on product with GPIOE available |
| 172 | 154 | ||
| 173 | [..] |
155 | [..] |
| 174 | *** Main and Backup Regulators configuration *** |
156 | *** Main and Backup Regulators configuration *** |
| 175 | ================================================ |
157 | ================================================ |
| 176 | 158 | ||
| Line 182... | Line 164... | ||
| 182 | the System frequency can go up to 32 MHz. |
164 | the System frequency can go up to 32 MHz. |
| 183 | (++) When this bit is reset (Regulator voltage output Scale 2 mode selected) |
165 | (++) When this bit is reset (Regulator voltage output Scale 2 mode selected) |
| 184 | the System frequency can go up to 16 MHz. |
166 | the System frequency can go up to 16 MHz. |
| 185 | (++) When this bit is reset (Regulator voltage output Scale 3 mode selected) |
167 | (++) When this bit is reset (Regulator voltage output Scale 3 mode selected) |
| 186 | the System frequency can go up to 4.2 MHz. |
168 | the System frequency can go up to 4.2 MHz. |
| 187 | |
169 | |
| 188 | Refer to the datasheets for more details. |
170 | Refer to the datasheets for more details. |
| 189 | 171 | ||
| 190 | *** Low Power modes configuration *** |
172 | *** Low Power modes configuration *** |
| 191 | ===================================== |
173 | ===================================== |
| 192 | [..] |
174 | [..] |
| 193 | The device features 5 low-power modes: |
175 | The device features 5 low-power modes: |
| 194 | (+) Low power run mode: regulator in low power mode, limited clock frequency, |
176 | (+) Low power run mode: regulator in low power mode, limited clock frequency, |
| 195 | limited number of peripherals running. |
177 | limited number of peripherals running. |
| 196 | (+) Sleep mode: Cortex-M3 core stopped, peripherals kept running. |
178 | (+) Sleep mode: Cortex-M3 core stopped, peripherals kept running. |
| 197 | (+) Low power sleep mode: Cortex-M3 core stopped, limited clock frequency, |
179 | (+) Low power sleep mode: Cortex-M3 core stopped, limited clock frequency, |
| 198 | limited number of peripherals running, regulator in low power mode. |
180 | limited number of peripherals running, regulator in low power mode. |
| 199 | (+) Stop mode: All clocks are stopped, regulator running, regulator in low power mode. |
181 | (+) Stop mode: All clocks are stopped, regulator running, regulator in low power mode. |
| 200 | (+) Standby mode: VCORE domain powered off |
182 | (+) Standby mode: VCORE domain powered off |
| 201 | |
183 | |
| 202 | *** Low power run mode *** |
184 | *** Low power run mode *** |
| 203 | ========================= |
185 | ========================= |
| 204 | [..] |
186 | [..] |
| 205 | To further reduce the consumption when the system is in Run mode, the regulator can be |
187 | To further reduce the consumption when the system is in Run mode, the regulator can be |
| 206 | configured in low power mode. In this mode, the system frequency should not exceed |
188 | configured in low power mode. In this mode, the system frequency should not exceed |
| 207 | MSI frequency range1. |
189 | MSI frequency range1. |
| 208 | In Low power run mode, all I/O pins keep the same state as in Run mode. |
190 | In Low power run mode, all I/O pins keep the same state as in Run mode. |
| 209 | |
191 | |
| 210 | (+) Entry: |
192 | (+) Entry: |
| 211 | (++) VCORE in range2 |
193 | (++) VCORE in range2 |
| 212 | (++) Decrease the system frequency tonot exceed the frequency of MSI frequency range1. |
194 | (++) Decrease the system frequency tonot exceed the frequency of MSI frequency range1. |
| 213 | (++) The regulator is forced in low power mode using the HAL_PWREx_EnableLowPowerRunMode() |
195 | (++) The regulator is forced in low power mode using the HAL_PWREx_EnableLowPowerRunMode() |
| 214 | function. |
196 | function. |
| 215 | (+) Exit: |
197 | (+) Exit: |
| 216 | (++) The regulator is forced in Main regulator mode using the HAL_PWREx_DisableLowPowerRunMode() |
198 | (++) The regulator is forced in Main regulator mode using the HAL_PWREx_DisableLowPowerRunMode() |
| 217 | function. |
199 | function. |
| 218 | (++) Increase the system frequency if needed. |
200 | (++) Increase the system frequency if needed. |
| 219 | |
201 | |
| 220 | *** Sleep mode *** |
202 | *** Sleep mode *** |
| 221 | ================== |
203 | ================== |
| 222 | [..] |
204 | [..] |
| 223 | (+) Entry: |
205 | (+) Entry: |
| 224 | The Sleep mode is entered by using the HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFx) |
206 | The Sleep mode is entered by using the HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFx) |
| 225 | functions with |
207 | functions with |
| 226 | (++) PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction |
208 | (++) PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction |
| 227 | (++) PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction |
209 | (++) PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction |
| 228 | |
210 | |
| 229 | (+) Exit: |
211 | (+) Exit: |
| 230 | (++) Any peripheral interrupt acknowledged by the nested vectored interrupt |
212 | (++) Any peripheral interrupt acknowledged by the nested vectored interrupt |
| 231 | controller (NVIC) can wake up the device from Sleep mode. |
213 | controller (NVIC) can wake up the device from Sleep mode. |
| 232 | 214 | ||
| 233 | *** Low power sleep mode *** |
215 | *** Low power sleep mode *** |
| Line 236... | Line 218... | ||
| 236 | (+) Entry: |
218 | (+) Entry: |
| 237 | The Low power sleep mode is entered by using the HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFx) |
219 | The Low power sleep mode is entered by using the HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFx) |
| 238 | functions with |
220 | functions with |
| 239 | (++) PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction |
221 | (++) PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction |
| 240 | (++) PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction |
222 | (++) PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction |
| 241 | (+) The Flash memory can be switched off by using the control bits (SLEEP_PD in the FLASH_ACR register. |
223 | (+) The Flash memory can be switched off by using the control bits (SLEEP_PD in the FLASH_ACR register. |
| 242 | This reduces power consumption but increases the wake-up time. |
224 | This reduces power consumption but increases the wake-up time. |
| 243 | |
225 | |
| 244 | (+) Exit: |
226 | (+) Exit: |
| 245 | (++) If the WFI instruction was used to enter Low power sleep mode, any peripheral interrupt |
227 | (++) If the WFI instruction was used to enter Low power sleep mode, any peripheral interrupt |
| 246 | acknowledged by the nested vectored interrupt controller (NVIC) can wake up the device |
228 | acknowledged by the nested vectored interrupt controller (NVIC) can wake up the device |
| 247 | from Low power sleep mode. If the WFE instruction was used to enter Low power sleep mode, |
229 | from Low power sleep mode. If the WFE instruction was used to enter Low power sleep mode, |
| 248 | the MCU exits Sleep mode as soon as an event occurs. |
230 | the MCU exits Sleep mode as soon as an event occurs. |
| 249 | |
- | |
| - | 231 | ||
| 250 | *** Stop mode *** |
232 | *** Stop mode *** |
| 251 | ================= |
233 | ================= |
| 252 | [..] |
234 | [..] |
| 253 | The Stop mode is based on the Cortex-M3 deepsleep mode combined with peripheral |
235 | The Stop mode is based on the Cortex-M3 deepsleep mode combined with peripheral |
| 254 | clock gating. The voltage regulator can be configured either in normal or low-power mode. |
236 | clock gating. The voltage regulator can be configured either in normal or low-power mode. |
| Line 278... | Line 260... | ||
| 278 | The Standby mode allows to achieve the lowest power consumption. It is based on the |
260 | The Standby mode allows to achieve the lowest power consumption. It is based on the |
| 279 | Cortex-M3 deepsleep mode, with the voltage regulator disabled. The VCORE domain is |
261 | Cortex-M3 deepsleep mode, with the voltage regulator disabled. The VCORE domain is |
| 280 | consequently powered off. The PLL, the MSI, the HSI oscillator and the HSE oscillator are |
262 | consequently powered off. The PLL, the MSI, the HSI oscillator and the HSE oscillator are |
| 281 | also switched off. SRAM and register contents are lost except for the RTC registers, RTC |
263 | also switched off. SRAM and register contents are lost except for the RTC registers, RTC |
| 282 | backup registers and Standby circuitry. |
264 | backup registers and Standby circuitry. |
| 283 | |
265 | |
| 284 | To minimize the consumption In Standby mode, VREFINT, the BOR, PVD, and temperature |
266 | To minimize the consumption In Standby mode, VREFINT, the BOR, PVD, and temperature |
| 285 | sensor can be switched off before entering the Standby mode. They can be switched |
267 | sensor can be switched off before entering the Standby mode. They can be switched |
| 286 | on again by software after exiting the Standby mode. |
268 | on again by software after exiting the Standby mode. |
| 287 | function. |
269 | function. |
| 288 | |
270 | |
| 289 | (+) Entry: |
271 | (+) Entry: |
| 290 | (++) The Standby mode is entered using the HAL_PWR_EnterSTANDBYMode() function. |
272 | (++) The Standby mode is entered using the HAL_PWR_EnterSTANDBYMode() function. |
| 291 | (+) Exit: |
273 | (+) Exit: |
| 292 | (++) WKUP pin rising edge, RTC alarm (Alarm A and Alarm B), RTC wakeup, |
274 | (++) WKUP pin rising edge, RTC alarm (Alarm A and Alarm B), RTC wakeup, |
| 293 | tamper event, time-stamp event, external reset in NRST pin, IWDG reset. |
275 | tamper event, time-stamp event, external reset in NRST pin, IWDG reset. |
| 294 | 276 | ||
| 295 | *** Auto-wakeup (AWU) from low-power mode *** |
277 | *** Auto-wakeup (AWU) from low-power mode *** |
| 296 | ============================================= |
278 | ============================================= |
| 297 | [..] |
279 | [..] |
| 298 | The MCU can be woken up from low-power mode by an RTC Alarm event, an RTC |
280 | The MCU can be woken up from low-power mode by an RTC Alarm event, an RTC |
| 299 | Wakeup event, a tamper event, a time-stamp event, or a comparator event, |
281 | Wakeup event, a tamper event, a time-stamp event, or a comparator event, |
| 300 | without depending on an external interrupt (Auto-wakeup mode). |
282 | without depending on an external interrupt (Auto-wakeup mode). |
| 301 | 283 | ||
| 302 | (+) RTC auto-wakeup (AWU) from the Stop mode |
284 | (+) RTC auto-wakeup (AWU) from the Stop mode |
| 303 | (++) To wake up from the Stop mode with an RTC alarm event, it is necessary to: |
285 | (++) To wake up from the Stop mode with an RTC alarm event, it is necessary to: |
| 304 | (+++) Configure the EXTI Line 17 to be sensitive to rising edges (Interrupt |
286 | (+++) Configure the EXTI Line 17 to be sensitive to rising edges (Interrupt |
| 305 | or Event modes) and Enable the RTC Alarm Interrupt using the HAL_RTC_SetAlarm_IT() |
287 | or Event modes) and Enable the RTC Alarm Interrupt using the HAL_RTC_SetAlarm_IT() |
| 306 | function |
288 | function |
| 307 | (+++) Configure the RTC to generate the RTC alarm using the HAL_RTC_Init() |
289 | (+++) Configure the RTC to generate the RTC alarm using the HAL_RTC_Init() |
| 308 | and HAL_RTC_SetTime() functions. |
290 | and HAL_RTC_SetTime() functions. |
| 309 | (++) To wake up from the Stop mode with an RTC Tamper or time stamp event, it |
291 | (++) To wake up from the Stop mode with an RTC Tamper or time stamp event, it |
| 310 | is necessary to: |
292 | is necessary to: |
| 311 | (+++) Configure the EXTI Line 19 to be sensitive to rising edges (Interrupt or Event modes) and |
293 | (+++) Configure the EXTI Line 19 to be sensitive to rising edges (Interrupt or Event modes) and |
| 312 | Enable the RTC Tamper or time stamp Interrupt using the HAL_RTCEx_SetTamper_IT() |
294 | Enable the RTC Tamper or time stamp Interrupt using the HAL_RTCEx_SetTamper_IT() |
| 313 | or HAL_RTCEx_SetTimeStamp_IT() functions. |
295 | or HAL_RTCEx_SetTimeStamp_IT() functions. |
| 314 | (++) To wake up from the Stop mode with an RTC WakeUp event, it is necessary to: |
296 | (++) To wake up from the Stop mode with an RTC WakeUp event, it is necessary to: |
| 315 | (+++) Configure the EXTI Line 20 to be sensitive to rising edges (Interrupt or Event modes) and |
297 | (+++) Configure the EXTI Line 20 to be sensitive to rising edges (Interrupt or Event modes) and |
| 316 | Enable the RTC WakeUp Interrupt using the HAL_RTCEx_SetWakeUpTimer_IT() function. |
298 | Enable the RTC WakeUp Interrupt using the HAL_RTCEx_SetWakeUpTimer_IT() function. |
| 317 | (+++) Configure the RTC to generate the RTC WakeUp event using the HAL_RTCEx_SetWakeUpTimer() |
299 | (+++) Configure the RTC to generate the RTC WakeUp event using the HAL_RTCEx_SetWakeUpTimer() |
| 318 | function. |
300 | function. |
| 319 | 301 | ||
| 320 | (+) RTC auto-wakeup (AWU) from the Standby mode |
302 | (+) RTC auto-wakeup (AWU) from the Standby mode |
| 321 | (++) To wake up from the Standby mode with an RTC alarm event, it is necessary to: |
303 | (++) To wake up from the Standby mode with an RTC alarm event, it is necessary to: |
| 322 | (+++) Enable the RTC Alarm Interrupt using the HAL_RTC_SetAlarm_IT() function. |
304 | (+++) Enable the RTC Alarm Interrupt using the HAL_RTC_SetAlarm_IT() function. |
| 323 | (+++) Configure the RTC to generate the RTC alarm using the HAL_RTC_Init() |
305 | (+++) Configure the RTC to generate the RTC alarm using the HAL_RTC_Init() |
| 324 | and HAL_RTC_SetTime() functions. |
306 | and HAL_RTC_SetTime() functions. |
| 325 | (++) To wake up from the Standby mode with an RTC Tamper or time stamp event, it |
307 | (++) To wake up from the Standby mode with an RTC Tamper or time stamp event, it |
| 326 | is necessary to: |
308 | is necessary to: |
| 327 | (+++) Enable the RTC Tamper or time stamp Interrupt and Configure the RTC to |
309 | (+++) Enable the RTC Tamper or time stamp Interrupt and Configure the RTC to |
| 328 | detect the tamper or time stamp event using the HAL_RTCEx_SetTimeStamp_IT() |
310 | detect the tamper or time stamp event using the HAL_RTCEx_SetTimeStamp_IT() |
| 329 | or HAL_RTCEx_SetTamper_IT()functions. |
311 | or HAL_RTCEx_SetTamper_IT()functions. |
| 330 | (++) To wake up from the Standby mode with an RTC WakeUp event, it is necessary to: |
312 | (++) To wake up from the Standby mode with an RTC WakeUp event, it is necessary to: |
| 331 | (+++) Enable the RTC WakeUp Interrupt and Configure the RTC to generate the RTC WakeUp event |
313 | (+++) Enable the RTC WakeUp Interrupt and Configure the RTC to generate the RTC WakeUp event |
| 332 | using the HAL_RTCEx_SetWakeUpTimer_IT() and HAL_RTCEx_SetWakeUpTimer() functions. |
314 | using the HAL_RTCEx_SetWakeUpTimer_IT() and HAL_RTCEx_SetWakeUpTimer() functions. |
| 333 | 315 | ||
| 334 | (+) Comparator auto-wakeup (AWU) from the Stop mode |
316 | (+) Comparator auto-wakeup (AWU) from the Stop mode |
| 335 | (++) To wake up from the Stop mode with an comparator 1 or comparator 2 wakeup |
317 | (++) To wake up from the Stop mode with an comparator 1 or comparator 2 wakeup |
| 336 | event, it is necessary to: |
318 | event, it is necessary to: |
| 337 | (+++) Configure the EXTI Line 21 or EXTI Line 22 for comparator to be sensitive to to the |
319 | (+++) Configure the EXTI Line 21 or EXTI Line 22 for comparator to be sensitive to to the |
| 338 | selected edges (falling, rising or falling and rising) (Interrupt or Event modes) using |
320 | selected edges (falling, rising or falling and rising) (Interrupt or Event modes) using |
| 339 | the COMP functions. |
321 | the COMP functions. |
| 340 | (+++) Configure the comparator to generate the event. |
322 | (+++) Configure the comparator to generate the event. |
| 341 | |
323 | |
| 342 | |
324 | |
| 343 | |
325 | |
| 344 | @endverbatim |
326 | @endverbatim |
| 345 | * @{ |
327 | * @{ |
| 346 | */ |
328 | */ |
| 347 | 329 | ||
| 348 | /** |
330 | /** |
| 349 | * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD). |
331 | * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD). |
| 350 | * @param sConfigPVD: pointer to an PWR_PVDTypeDef structure that contains the configuration |
332 | * @param sConfigPVD pointer to an PWR_PVDTypeDef structure that contains the configuration |
| 351 | * information for the PVD. |
333 | * information for the PVD. |
| 352 | * @note Refer to the electrical characteristics of your device datasheet for |
334 | * @note Refer to the electrical characteristics of your device datasheet for |
| 353 | * more details about the voltage threshold corresponding to each |
335 | * more details about the voltage threshold corresponding to each |
| 354 | * detection level. |
336 | * detection level. |
| 355 | * @retval None |
337 | * @retval None |
| Line 360... | Line 342... | ||
| 360 | assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel)); |
342 | assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel)); |
| 361 | assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode)); |
343 | assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode)); |
| 362 | 344 | ||
| 363 | /* Set PLS[7:5] bits according to PVDLevel value */ |
345 | /* Set PLS[7:5] bits according to PVDLevel value */ |
| 364 | MODIFY_REG(PWR->CR, PWR_CR_PLS, sConfigPVD->PVDLevel); |
346 | MODIFY_REG(PWR->CR, PWR_CR_PLS, sConfigPVD->PVDLevel); |
| 365 | 347 | ||
| 366 | /* Clear any previous config. Keep it clear if no event or IT mode is selected */ |
348 | /* Clear any previous config. Keep it clear if no event or IT mode is selected */ |
| 367 | __HAL_PWR_PVD_EXTI_DISABLE_EVENT(); |
349 | __HAL_PWR_PVD_EXTI_DISABLE_EVENT(); |
| 368 | __HAL_PWR_PVD_EXTI_DISABLE_IT(); |
350 | __HAL_PWR_PVD_EXTI_DISABLE_IT(); |
| 369 | __HAL_PWR_PVD_EXTI_DISABLE_RISING_FALLING_EDGE(); |
351 | __HAL_PWR_PVD_EXTI_DISABLE_RISING_FALLING_EDGE(); |
| 370 | 352 | ||
| 371 | /* Configure interrupt mode */ |
353 | /* Configure interrupt mode */ |
| 372 | if((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT) |
354 | if((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT) |
| 373 | { |
355 | { |
| 374 | __HAL_PWR_PVD_EXTI_ENABLE_IT(); |
356 | __HAL_PWR_PVD_EXTI_ENABLE_IT(); |
| 375 | } |
357 | } |
| 376 | 358 | ||
| 377 | /* Configure event mode */ |
359 | /* Configure event mode */ |
| 378 | if((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT) |
360 | if((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT) |
| 379 | { |
361 | { |
| 380 | __HAL_PWR_PVD_EXTI_ENABLE_EVENT(); |
362 | __HAL_PWR_PVD_EXTI_ENABLE_EVENT(); |
| 381 | } |
363 | } |
| 382 | 364 | ||
| 383 | /* Configure the edge */ |
365 | /* Configure the edge */ |
| 384 | if((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE) |
366 | if((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE) |
| 385 | { |
367 | { |
| 386 | __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE(); |
368 | __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE(); |
| 387 | } |
369 | } |
| 388 | 370 | ||
| 389 | if((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE) |
371 | if((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE) |
| 390 | { |
372 | { |
| 391 | __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE(); |
373 | __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE(); |
| 392 | } |
374 | } |
| 393 | } |
375 | } |
| Line 416... | Line 398... | ||
| 416 | * @brief Enables the WakeUp PINx functionality. |
398 | * @brief Enables the WakeUp PINx functionality. |
| 417 | * @param WakeUpPinx: Specifies the Power Wake-Up pin to enable. |
399 | * @param WakeUpPinx: Specifies the Power Wake-Up pin to enable. |
| 418 | * This parameter can be one of the following values: |
400 | * This parameter can be one of the following values: |
| 419 | * @arg PWR_WAKEUP_PIN1 |
401 | * @arg PWR_WAKEUP_PIN1 |
| 420 | * @arg PWR_WAKEUP_PIN2 |
402 | * @arg PWR_WAKEUP_PIN2 |
| 421 | * @arg PWR_WAKEUP_PIN3: Only on product with GPIOE available |
403 | * @arg PWR_WAKEUP_PIN3: Only on product with GPIOE available |
| 422 | * @retval None |
404 | * @retval None |
| 423 | */ |
405 | */ |
| 424 | void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx) |
406 | void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx) |
| 425 | { |
407 | { |
| 426 | /* Check the parameter */ |
408 | /* Check the parameter */ |
| Line 432... | Line 414... | ||
| 432 | /** |
414 | /** |
| 433 | * @brief Disables the WakeUp PINx functionality. |
415 | * @brief Disables the WakeUp PINx functionality. |
| 434 | * @param WakeUpPinx: Specifies the Power Wake-Up pin to disable. |
416 | * @param WakeUpPinx: Specifies the Power Wake-Up pin to disable. |
| 435 | * This parameter can be one of the following values: |
417 | * This parameter can be one of the following values: |
| 436 | * @arg PWR_WAKEUP_PIN1 |
418 | * @arg PWR_WAKEUP_PIN1 |
| 437 | * @arg PWR_WAKEUP_PIN2 |
419 | * @arg PWR_WAKEUP_PIN2 |
| 438 | * @arg PWR_WAKEUP_PIN3: Only on product with GPIOE available |
420 | * @arg PWR_WAKEUP_PIN3: Only on product with GPIOE available |
| 439 | * @retval None |
421 | * @retval None |
| 440 | */ |
422 | */ |
| 441 | void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx) |
423 | void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx) |
| 442 | { |
424 | { |
| 443 | /* Check the parameter */ |
425 | /* Check the parameter */ |
| Line 452... | Line 434... | ||
| 452 | * @param Regulator: Specifies the regulator state in SLEEP mode. |
434 | * @param Regulator: Specifies the regulator state in SLEEP mode. |
| 453 | * This parameter can be one of the following values: |
435 | * This parameter can be one of the following values: |
| 454 | * @arg PWR_MAINREGULATOR_ON: SLEEP mode with regulator ON |
436 | * @arg PWR_MAINREGULATOR_ON: SLEEP mode with regulator ON |
| 455 | * @arg PWR_LOWPOWERREGULATOR_ON: SLEEP mode with low power regulator ON |
437 | * @arg PWR_LOWPOWERREGULATOR_ON: SLEEP mode with low power regulator ON |
| 456 | * @param SLEEPEntry: Specifies if SLEEP mode is entered with WFI or WFE instruction. |
438 | * @param SLEEPEntry: Specifies if SLEEP mode is entered with WFI or WFE instruction. |
| 457 | * When WFI entry is used, tick interrupt have to be disabled if not desired as |
439 | * When WFI entry is used, tick interrupt have to be disabled if not desired as |
| 458 | * the interrupt wake up source. |
440 | * the interrupt wake up source. |
| 459 | * This parameter can be one of the following values: |
441 | * This parameter can be one of the following values: |
| 460 | * @arg PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction |
442 | * @arg PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction |
| 461 | * @arg PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction |
443 | * @arg PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction |
| 462 | * @retval None |
444 | * @retval None |
| Line 487... | Line 469... | ||
| 487 | __WFE(); |
469 | __WFE(); |
| 488 | } |
470 | } |
| 489 | } |
471 | } |
| 490 | 472 | ||
| 491 | /** |
473 | /** |
| 492 | * @brief Enters Stop mode. |
474 | * @brief Enters Stop mode. |
| 493 | * @note In Stop mode, all I/O pins keep the same state as in Run mode. |
475 | * @note In Stop mode, all I/O pins keep the same state as in Run mode. |
| 494 | * @note When exiting Stop mode by using an interrupt or a wakeup event, |
476 | * @note When exiting Stop mode by using an interrupt or a wakeup event, |
| 495 | * MSI RC oscillator is selected as system clock. |
477 | * MSI RC oscillator is selected as system clock. |
| 496 | * @note When the voltage regulator operates in low power mode, an additional |
478 | * @note When the voltage regulator operates in low power mode, an additional |
| 497 | * startup delay is incurred when waking up from Stop mode. |
479 | * startup delay is incurred when waking up from Stop mode. |
| 498 | * By keeping the internal regulator ON during Stop mode, the consumption |
480 | * By keeping the internal regulator ON during Stop mode, the consumption |
| 499 | * is higher although the startup time is reduced. |
481 | * is higher although the startup time is reduced. |
| 500 | * @param Regulator: Specifies the regulator state in Stop mode. |
482 | * @param Regulator: Specifies the regulator state in Stop mode. |
| 501 | * This parameter can be one of the following values: |
483 | * This parameter can be one of the following values: |
| 502 | * @arg PWR_MAINREGULATOR_ON: Stop mode with regulator ON |
484 | * @arg PWR_MAINREGULATOR_ON: Stop mode with regulator ON |
| 503 | * @arg PWR_LOWPOWERREGULATOR_ON: Stop mode with low power regulator ON |
485 | * @arg PWR_LOWPOWERREGULATOR_ON: Stop mode with low power regulator ON |
| 504 | * @param STOPEntry: Specifies if Stop mode in entered with WFI or WFE instruction. |
486 | * @param STOPEntry: Specifies if Stop mode in entered with WFI or WFE instruction. |
| 505 | * This parameter can be one of the following values: |
487 | * This parameter can be one of the following values: |
| 506 | * @arg PWR_STOPENTRY_WFI: Enter Stop mode with WFI instruction |
488 | * @arg PWR_STOPENTRY_WFI: Enter Stop mode with WFI instruction |
| 507 | * @arg PWR_STOPENTRY_WFE: Enter Stop mode with WFE instruction |
489 | * @arg PWR_STOPENTRY_WFE: Enter Stop mode with WFE instruction |
| 508 | * @retval None |
490 | * @retval None |
| 509 | */ |
491 | */ |
| 510 | void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry) |
492 | void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry) |
| 511 | { |
493 | { |
| 512 | /* Check the parameters */ |
494 | /* Check the parameters */ |
| Line 537... | Line 519... | ||
| 537 | } |
519 | } |
| 538 | 520 | ||
| 539 | /** |
521 | /** |
| 540 | * @brief Enters Standby mode. |
522 | * @brief Enters Standby mode. |
| 541 | * @note In Standby mode, all I/O pins are high impedance except for: |
523 | * @note In Standby mode, all I/O pins are high impedance except for: |
| 542 | * - Reset pad (still available) |
524 | * - Reset pad (still available) |
| 543 | * - RTC_AF1 pin (PC13) if configured for tamper, time-stamp, RTC |
525 | * - RTC_AF1 pin (PC13) if configured for tamper, time-stamp, RTC |
| 544 | * Alarm out, or RTC clock calibration out. |
526 | * Alarm out, or RTC clock calibration out. |
| 545 | * - WKUP pin 1 (PA0) if enabled. |
527 | * - WKUP pin 1 (PA0) if enabled. |
| 546 | * - WKUP pin 2 (PC13) if enabled. |
528 | * - WKUP pin 2 (PC13) if enabled. |
| 547 | * - WKUP pin 3 (PE6) if enabled. |
529 | * - WKUP pin 3 (PE6) if enabled. |
| Line 563... | Line 545... | ||
| 563 | __WFI(); |
545 | __WFI(); |
| 564 | } |
546 | } |
| 565 | 547 | ||
| 566 | 548 | ||
| 567 | /** |
549 | /** |
| 568 | * @brief Indicates Sleep-On-Exit when returning from Handler mode to Thread mode. |
550 | * @brief Indicates Sleep-On-Exit when returning from Handler mode to Thread mode. |
| 569 | * @note Set SLEEPONEXIT bit of SCR register. When this bit is set, the processor |
551 | * @note Set SLEEPONEXIT bit of SCR register. When this bit is set, the processor |
| 570 | * re-enters SLEEP mode when an interruption handling is over. |
552 | * re-enters SLEEP mode when an interruption handling is over. |
| 571 | * Setting this bit is useful when the processor is expected to run only on |
553 | * Setting this bit is useful when the processor is expected to run only on |
| 572 | * interruptions handling. |
554 | * interruptions handling. |
| 573 | * @retval None |
555 | * @retval None |
| 574 | */ |
556 | */ |
| 575 | void HAL_PWR_EnableSleepOnExit(void) |
557 | void HAL_PWR_EnableSleepOnExit(void) |
| 576 | { |
558 | { |
| 577 | /* Set SLEEPONEXIT bit of Cortex System Control Register */ |
559 | /* Set SLEEPONEXIT bit of Cortex System Control Register */ |
| 578 | SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk)); |
560 | SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk)); |
| 579 | } |
561 | } |
| 580 | 562 | ||
| 581 | 563 | ||
| 582 | /** |
564 | /** |
| 583 | * @brief Disables Sleep-On-Exit feature when returning from Handler mode to Thread mode. |
565 | * @brief Disables Sleep-On-Exit feature when returning from Handler mode to Thread mode. |
| 584 | * @note Clears SLEEPONEXIT bit of SCR register. When this bit is set, the processor |
566 | * @note Clears SLEEPONEXIT bit of SCR register. When this bit is set, the processor |
| 585 | * re-enters SLEEP mode when an interruption handling is over. |
567 | * re-enters SLEEP mode when an interruption handling is over. |
| 586 | * @retval None |
568 | * @retval None |
| 587 | */ |
569 | */ |
| 588 | void HAL_PWR_DisableSleepOnExit(void) |
570 | void HAL_PWR_DisableSleepOnExit(void) |
| 589 | { |
571 | { |
| 590 | /* Clear SLEEPONEXIT bit of Cortex System Control Register */ |
572 | /* Clear SLEEPONEXIT bit of Cortex System Control Register */ |
| 591 | CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk)); |
573 | CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk)); |
| 592 | } |
574 | } |
| 593 | 575 | ||
| 594 | 576 | ||
| 595 | /** |
577 | /** |
| 596 | * @brief Enables CORTEX M3 SEVONPEND bit. |
578 | * @brief Enables CORTEX M3 SEVONPEND bit. |
| 597 | * @note Sets SEVONPEND bit of SCR register. When this bit is set, this causes |
579 | * @note Sets SEVONPEND bit of SCR register. When this bit is set, this causes |
| 598 | * WFE to wake up when an interrupt moves from inactive to pended. |
580 | * WFE to wake up when an interrupt moves from inactive to pended. |
| 599 | * @retval None |
581 | * @retval None |
| 600 | */ |
582 | */ |
| 601 | void HAL_PWR_EnableSEVOnPend(void) |
583 | void HAL_PWR_EnableSEVOnPend(void) |
| 602 | { |
584 | { |
| Line 604... | Line 586... | ||
| 604 | SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk)); |
586 | SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk)); |
| 605 | } |
587 | } |
| 606 | 588 | ||
| 607 | 589 | ||
| 608 | /** |
590 | /** |
| 609 | * @brief Disables CORTEX M3 SEVONPEND bit. |
591 | * @brief Disables CORTEX M3 SEVONPEND bit. |
| 610 | * @note Clears SEVONPEND bit of SCR register. When this bit is set, this causes |
592 | * @note Clears SEVONPEND bit of SCR register. When this bit is set, this causes |
| 611 | * WFE to wake up when an interrupt moves from inactive to pended. |
593 | * WFE to wake up when an interrupt moves from inactive to pended. |
| 612 | * @retval None |
594 | * @retval None |
| 613 | */ |
595 | */ |
| 614 | void HAL_PWR_DisableSEVOnPend(void) |
596 | void HAL_PWR_DisableSEVOnPend(void) |
| 615 | { |
597 | { |
| 616 | /* Clear SEVONPEND bit of Cortex System Control Register */ |
598 | /* Clear SEVONPEND bit of Cortex System Control Register */ |
| Line 643... | Line 625... | ||
| 643 | */ |
625 | */ |
| 644 | __weak void HAL_PWR_PVDCallback(void) |
626 | __weak void HAL_PWR_PVDCallback(void) |
| 645 | { |
627 | { |
| 646 | /* NOTE : This function Should not be modified, when the callback is needed, |
628 | /* NOTE : This function Should not be modified, when the callback is needed, |
| 647 | the HAL_PWR_PVDCallback could be implemented in the user file |
629 | the HAL_PWR_PVDCallback could be implemented in the user file |
| 648 | */ |
630 | */ |
| 649 | } |
631 | } |
| 650 | 632 | ||
| 651 | /** |
633 | /** |
| 652 | * @} |
634 | * @} |
| 653 | */ |
635 | */ |