amiro-blt / Target / Modules / PowerManagement_1-1 / Boot / lib / stdperiphlib / STM32F4xx_StdPeriph_Driver / src / stm32f4xx_pwr.c @ 367c0652
History | View | Annotate | Download (25.8 KB)
1 | 69661903 | Thomas Schöpping | /**
|
---|---|---|---|
2 | ******************************************************************************
|
||
3 | * @file stm32f4xx_pwr.c
|
||
4 | * @author MCD Application Team
|
||
5 | * @version V1.1.0
|
||
6 | * @date 11-January-2013
|
||
7 | * @brief This file provides firmware functions to manage the following
|
||
8 | * functionalities of the Power Controller (PWR) peripheral:
|
||
9 | * + Backup Domain Access
|
||
10 | * + PVD configuration
|
||
11 | * + WakeUp pin configuration
|
||
12 | * + Main and Backup Regulators configuration
|
||
13 | * + FLASH Power Down configuration
|
||
14 | * + Low Power modes configuration
|
||
15 | * + Flags management
|
||
16 | *
|
||
17 | ******************************************************************************
|
||
18 | * @attention
|
||
19 | *
|
||
20 | * <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
|
||
21 | *
|
||
22 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||
23 | * You may not use this file except in compliance with the License.
|
||
24 | * You may obtain a copy of the License at:
|
||
25 | *
|
||
26 | * http://www.st.com/software_license_agreement_liberty_v2
|
||
27 | *
|
||
28 | * Unless required by applicable law or agreed to in writing, software
|
||
29 | * distributed under the License is distributed on an "AS IS" BASIS,
|
||
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
31 | * See the License for the specific language governing permissions and
|
||
32 | * limitations under the License.
|
||
33 | *
|
||
34 | ******************************************************************************
|
||
35 | */
|
||
36 | |||
37 | /* Includes ------------------------------------------------------------------*/
|
||
38 | #include "stm32f4xx_pwr.h" |
||
39 | #include "stm32f4xx_rcc.h" |
||
40 | |||
41 | /** @addtogroup STM32F4xx_StdPeriph_Driver
|
||
42 | * @{
|
||
43 | */
|
||
44 | |||
45 | /** @defgroup PWR
|
||
46 | * @brief PWR driver modules
|
||
47 | * @{
|
||
48 | */
|
||
49 | |||
50 | /* Private typedef -----------------------------------------------------------*/
|
||
51 | /* Private define ------------------------------------------------------------*/
|
||
52 | /* --------- PWR registers bit address in the alias region ---------- */
|
||
53 | #define PWR_OFFSET (PWR_BASE - PERIPH_BASE)
|
||
54 | |||
55 | /* --- CR Register ---*/
|
||
56 | |||
57 | /* Alias word address of DBP bit */
|
||
58 | #define CR_OFFSET (PWR_OFFSET + 0x00) |
||
59 | #define DBP_BitNumber 0x08 |
||
60 | #define CR_DBP_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (DBP_BitNumber * 4)) |
||
61 | |||
62 | /* Alias word address of PVDE bit */
|
||
63 | #define PVDE_BitNumber 0x04 |
||
64 | #define CR_PVDE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PVDE_BitNumber * 4)) |
||
65 | |||
66 | /* Alias word address of FPDS bit */
|
||
67 | #define FPDS_BitNumber 0x09 |
||
68 | #define CR_FPDS_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (FPDS_BitNumber * 4)) |
||
69 | |||
70 | /* Alias word address of PMODE bit */
|
||
71 | #define PMODE_BitNumber 0x0E |
||
72 | #define CR_PMODE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PMODE_BitNumber * 4)) |
||
73 | |||
74 | |||
75 | /* --- CSR Register ---*/
|
||
76 | |||
77 | /* Alias word address of EWUP bit */
|
||
78 | #define CSR_OFFSET (PWR_OFFSET + 0x04) |
||
79 | #define EWUP_BitNumber 0x08 |
||
80 | #define CSR_EWUP_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (EWUP_BitNumber * 4)) |
||
81 | |||
82 | /* Alias word address of BRE bit */
|
||
83 | #define BRE_BitNumber 0x09 |
||
84 | #define CSR_BRE_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (BRE_BitNumber * 4)) |
||
85 | |||
86 | /* ------------------ PWR registers bit mask ------------------------ */
|
||
87 | |||
88 | /* CR register bit mask */
|
||
89 | #define CR_DS_MASK ((uint32_t)0xFFFFFFFC) |
||
90 | #define CR_PLS_MASK ((uint32_t)0xFFFFFF1F) |
||
91 | #define CR_VOS_MASK ((uint32_t)0xFFFF3FFF) |
||
92 | |||
93 | /* Private macro -------------------------------------------------------------*/
|
||
94 | /* Private variables ---------------------------------------------------------*/
|
||
95 | /* Private function prototypes -----------------------------------------------*/
|
||
96 | /* Private functions ---------------------------------------------------------*/
|
||
97 | |||
98 | /** @defgroup PWR_Private_Functions
|
||
99 | * @{
|
||
100 | */
|
||
101 | |||
102 | /** @defgroup PWR_Group1 Backup Domain Access function
|
||
103 | * @brief Backup Domain Access function
|
||
104 | *
|
||
105 | @verbatim
|
||
106 | ===============================================================================
|
||
107 | ##### Backup Domain Access function #####
|
||
108 | ===============================================================================
|
||
109 | [..]
|
||
110 | After reset, the backup domain (RTC registers, RTC backup data
|
||
111 | registers and backup SRAM) is protected against possible unwanted
|
||
112 | write accesses.
|
||
113 | To enable access to the RTC Domain and RTC registers, proceed as follows:
|
||
114 | (+) Enable the Power Controller (PWR) APB1 interface clock using the
|
||
115 | RCC_APB1PeriphClockCmd() function.
|
||
116 | (+) Enable access to RTC domain using the PWR_BackupAccessCmd() function.
|
||
117 | |||
118 | @endverbatim
|
||
119 | * @{
|
||
120 | */
|
||
121 | |||
122 | /**
|
||
123 | * @brief Deinitializes the PWR peripheral registers to their default reset values.
|
||
124 | * @param None
|
||
125 | * @retval None
|
||
126 | */
|
||
127 | void PWR_DeInit(void) |
||
128 | { |
||
129 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE); |
||
130 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, DISABLE); |
||
131 | } |
||
132 | |||
133 | /**
|
||
134 | * @brief Enables or disables access to the backup domain (RTC registers, RTC
|
||
135 | * backup data registers and backup SRAM).
|
||
136 | * @note If the HSE divided by 2, 3, ..31 is used as the RTC clock, the
|
||
137 | * Backup Domain Access should be kept enabled.
|
||
138 | * @param NewState: new state of the access to the backup domain.
|
||
139 | * This parameter can be: ENABLE or DISABLE.
|
||
140 | * @retval None
|
||
141 | */
|
||
142 | void PWR_BackupAccessCmd(FunctionalState NewState)
|
||
143 | { |
||
144 | /* Check the parameters */
|
||
145 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
||
146 | |||
147 | *(__IO uint32_t *) CR_DBP_BB = (uint32_t)NewState; |
||
148 | } |
||
149 | |||
150 | /**
|
||
151 | * @}
|
||
152 | */
|
||
153 | |||
154 | /** @defgroup PWR_Group2 PVD configuration functions
|
||
155 | * @brief PVD configuration functions
|
||
156 | *
|
||
157 | @verbatim
|
||
158 | ===============================================================================
|
||
159 | ##### PVD configuration functions #####
|
||
160 | ===============================================================================
|
||
161 | [..]
|
||
162 | (+) The PVD is used to monitor the VDD power supply by comparing it to a
|
||
163 | threshold selected by the PVD Level (PLS[2:0] bits in the PWR_CR).
|
||
164 | (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower
|
||
165 | than the PVD threshold. This event is internally connected to the EXTI
|
||
166 | line16 and can generate an interrupt if enabled through the EXTI registers.
|
||
167 | (+) The PVD is stopped in Standby mode.
|
||
168 | |||
169 | @endverbatim
|
||
170 | * @{
|
||
171 | */
|
||
172 | |||
173 | /**
|
||
174 | * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD).
|
||
175 | * @param PWR_PVDLevel: specifies the PVD detection level
|
||
176 | * This parameter can be one of the following values:
|
||
177 | * @arg PWR_PVDLevel_0
|
||
178 | * @arg PWR_PVDLevel_1
|
||
179 | * @arg PWR_PVDLevel_2
|
||
180 | * @arg PWR_PVDLevel_3
|
||
181 | * @arg PWR_PVDLevel_4
|
||
182 | * @arg PWR_PVDLevel_5
|
||
183 | * @arg PWR_PVDLevel_6
|
||
184 | * @arg PWR_PVDLevel_7
|
||
185 | * @note Refer to the electrical characteristics of your device datasheet for
|
||
186 | * more details about the voltage threshold corresponding to each
|
||
187 | * detection level.
|
||
188 | * @retval None
|
||
189 | */
|
||
190 | void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel)
|
||
191 | { |
||
192 | uint32_t tmpreg = 0;
|
||
193 | |||
194 | /* Check the parameters */
|
||
195 | assert_param(IS_PWR_PVD_LEVEL(PWR_PVDLevel)); |
||
196 | |||
197 | tmpreg = PWR->CR; |
||
198 | |||
199 | /* Clear PLS[7:5] bits */
|
||
200 | tmpreg &= CR_PLS_MASK; |
||
201 | |||
202 | /* Set PLS[7:5] bits according to PWR_PVDLevel value */
|
||
203 | tmpreg |= PWR_PVDLevel; |
||
204 | |||
205 | /* Store the new value */
|
||
206 | PWR->CR = tmpreg; |
||
207 | } |
||
208 | |||
209 | /**
|
||
210 | * @brief Enables or disables the Power Voltage Detector(PVD).
|
||
211 | * @param NewState: new state of the PVD.
|
||
212 | * This parameter can be: ENABLE or DISABLE.
|
||
213 | * @retval None
|
||
214 | */
|
||
215 | void PWR_PVDCmd(FunctionalState NewState)
|
||
216 | { |
||
217 | /* Check the parameters */
|
||
218 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
||
219 | |||
220 | *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)NewState; |
||
221 | } |
||
222 | |||
223 | /**
|
||
224 | * @}
|
||
225 | */
|
||
226 | |||
227 | /** @defgroup PWR_Group3 WakeUp pin configuration functions
|
||
228 | * @brief WakeUp pin configuration functions
|
||
229 | *
|
||
230 | @verbatim
|
||
231 | ===============================================================================
|
||
232 | ##### WakeUp pin configuration functions #####
|
||
233 | ===============================================================================
|
||
234 | [..]
|
||
235 | (+) WakeUp pin is used to wakeup the system from Standby mode. This pin is
|
||
236 | forced in input pull down configuration and is active on rising edges.
|
||
237 | (+) There is only one WakeUp pin: WakeUp Pin 1 on PA.00.
|
||
238 | |||
239 | @endverbatim
|
||
240 | * @{
|
||
241 | */
|
||
242 | |||
243 | /**
|
||
244 | * @brief Enables or disables the WakeUp Pin functionality.
|
||
245 | * @param NewState: new state of the WakeUp Pin functionality.
|
||
246 | * This parameter can be: ENABLE or DISABLE.
|
||
247 | * @retval None
|
||
248 | */
|
||
249 | void PWR_WakeUpPinCmd(FunctionalState NewState)
|
||
250 | { |
||
251 | /* Check the parameters */
|
||
252 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
||
253 | |||
254 | *(__IO uint32_t *) CSR_EWUP_BB = (uint32_t)NewState; |
||
255 | } |
||
256 | |||
257 | /**
|
||
258 | * @}
|
||
259 | */
|
||
260 | |||
261 | /** @defgroup PWR_Group4 Main and Backup Regulators configuration functions
|
||
262 | * @brief Main and Backup Regulators configuration functions
|
||
263 | *
|
||
264 | @verbatim
|
||
265 | ===============================================================================
|
||
266 | ##### Main and Backup Regulators configuration functions #####
|
||
267 | ===============================================================================
|
||
268 | [..]
|
||
269 | (+) The backup domain includes 4 Kbytes of backup SRAM accessible only from
|
||
270 | the CPU, and address in 32-bit, 16-bit or 8-bit mode. Its content is
|
||
271 | retained even in Standby or VBAT mode when the low power backup regulator
|
||
272 | is enabled. It can be considered as an internal EEPROM when VBAT is
|
||
273 | always present. You can use the PWR_BackupRegulatorCmd() function to
|
||
274 | enable the low power backup regulator and use the PWR_GetFlagStatus
|
||
275 | (PWR_FLAG_BRR) to check if it is ready or not.
|
||
276 | |||
277 | (+) When the backup domain is supplied by VDD (analog switch connected to VDD)
|
||
278 | the backup SRAM is powered from VDD which replaces the VBAT power supply to
|
||
279 | save battery life.
|
||
280 | |||
281 | (+) The backup SRAM is not mass erased by an tamper event. It is read
|
||
282 | protected to prevent confidential data, such as cryptographic private
|
||
283 | key, from being accessed. The backup SRAM can be erased only through
|
||
284 | the Flash interface when a protection level change from level 1 to
|
||
285 | level 0 is requested.
|
||
286 | -@- Refer to the description of Read protection (RDP) in the Flash
|
||
287 | programming manual.
|
||
288 | |||
289 | (+) The main internal regulator can be configured to have a tradeoff between
|
||
290 | performance and power consumption when the device does not operate at
|
||
291 | the maximum frequency. This is done through PWR_MainRegulatorModeConfig()
|
||
292 | function which configure VOS bit in PWR_CR register:
|
||
293 | (++) When this bit is set (Regulator voltage output Scale 1 mode selected)
|
||
294 | the System frequency can go up to 168 MHz.
|
||
295 | (++) When this bit is reset (Regulator voltage output Scale 2 mode selected)
|
||
296 | the System frequency can go up to 144 MHz.
|
||
297 |
|
||
298 | Refer to the datasheets for more details.
|
||
299 |
|
||
300 | @endverbatim
|
||
301 | * @{
|
||
302 | */
|
||
303 | |||
304 | /**
|
||
305 | * @brief Enables or disables the Backup Regulator.
|
||
306 | * @param NewState: new state of the Backup Regulator.
|
||
307 | * This parameter can be: ENABLE or DISABLE.
|
||
308 | * @retval None
|
||
309 | */
|
||
310 | void PWR_BackupRegulatorCmd(FunctionalState NewState)
|
||
311 | { |
||
312 | /* Check the parameters */
|
||
313 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
||
314 | |||
315 | *(__IO uint32_t *) CSR_BRE_BB = (uint32_t)NewState; |
||
316 | } |
||
317 | |||
318 | /**
|
||
319 | * @brief Configures the main internal regulator output voltage.
|
||
320 | * @param PWR_Regulator_Voltage: specifies the regulator output voltage to achieve
|
||
321 | * a tradeoff between performance and power consumption when the device does
|
||
322 | * not operate at the maximum frequency (refer to the datasheets for more details).
|
||
323 | * This parameter can be one of the following values:
|
||
324 | * @arg PWR_Regulator_Voltage_Scale1: Regulator voltage output Scale 1 mode,
|
||
325 | * System frequency up to 168 MHz.
|
||
326 | * @arg PWR_Regulator_Voltage_Scale2: Regulator voltage output Scale 2 mode,
|
||
327 | * System frequency up to 144 MHz.
|
||
328 | * @arg PWR_Regulator_Voltage_Scale3: Regulator voltage output Scale 3 mode,
|
||
329 | * System frequency up to 120 MHz
|
||
330 | * @retval None
|
||
331 | */
|
||
332 | void PWR_MainRegulatorModeConfig(uint32_t PWR_Regulator_Voltage)
|
||
333 | { |
||
334 | uint32_t tmpreg = 0;
|
||
335 | |||
336 | /* Check the parameters */
|
||
337 | assert_param(IS_PWR_REGULATOR_VOLTAGE(PWR_Regulator_Voltage)); |
||
338 | |||
339 | tmpreg = PWR->CR; |
||
340 | |||
341 | /* Clear VOS[15:14] bits */
|
||
342 | tmpreg &= CR_VOS_MASK; |
||
343 | |||
344 | /* Set VOS[15:14] bits according to PWR_Regulator_Voltage value */
|
||
345 | tmpreg |= PWR_Regulator_Voltage; |
||
346 | |||
347 | /* Store the new value */
|
||
348 | PWR->CR = tmpreg; |
||
349 | } |
||
350 | |||
351 | /**
|
||
352 | * @}
|
||
353 | */
|
||
354 | |||
355 | /** @defgroup PWR_Group5 FLASH Power Down configuration functions
|
||
356 | * @brief FLASH Power Down configuration functions
|
||
357 | *
|
||
358 | @verbatim
|
||
359 | ===============================================================================
|
||
360 | ##### FLASH Power Down configuration functions #####
|
||
361 | ===============================================================================
|
||
362 | [..]
|
||
363 | (+) By setting the FPDS bit in the PWR_CR register by using the
|
||
364 | PWR_FlashPowerDownCmd() function, the Flash memory also enters power
|
||
365 | down mode when the device enters Stop mode. When the Flash memory
|
||
366 | is in power down mode, an additional startup delay is incurred when
|
||
367 | waking up from Stop mode.
|
||
368 | @endverbatim
|
||
369 | * @{
|
||
370 | */
|
||
371 | |||
372 | /**
|
||
373 | * @brief Enables or disables the Flash Power Down in STOP mode.
|
||
374 | * @param NewState: new state of the Flash power mode.
|
||
375 | * This parameter can be: ENABLE or DISABLE.
|
||
376 | * @retval None
|
||
377 | */
|
||
378 | void PWR_FlashPowerDownCmd(FunctionalState NewState)
|
||
379 | { |
||
380 | /* Check the parameters */
|
||
381 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
||
382 | |||
383 | *(__IO uint32_t *) CR_FPDS_BB = (uint32_t)NewState; |
||
384 | } |
||
385 | |||
386 | /**
|
||
387 | * @}
|
||
388 | */
|
||
389 | |||
390 | /** @defgroup PWR_Group6 Low Power modes configuration functions
|
||
391 | * @brief Low Power modes configuration functions
|
||
392 | *
|
||
393 | @verbatim
|
||
394 | ===============================================================================
|
||
395 | ##### Low Power modes configuration functions #####
|
||
396 | ===============================================================================
|
||
397 | [..]
|
||
398 | The devices feature 3 low-power modes:
|
||
399 | (+) Sleep mode: Cortex-M4 core stopped, peripherals kept running.
|
||
400 | (+) Stop mode: all clocks are stopped, regulator running, regulator
|
||
401 | in low power mode
|
||
402 | (+) Standby mode: 1.2V domain powered off.
|
||
403 |
|
||
404 | *** Sleep mode ***
|
||
405 | ==================
|
||
406 | [..]
|
||
407 | (+) Entry:
|
||
408 | (++) The Sleep mode is entered by using the __WFI() or __WFE() functions.
|
||
409 | (+) Exit:
|
||
410 | (++) Any peripheral interrupt acknowledged by the nested vectored interrupt
|
||
411 | controller (NVIC) can wake up the device from Sleep mode.
|
||
412 | |||
413 | *** Stop mode ***
|
||
414 | =================
|
||
415 | [..]
|
||
416 | In Stop mode, all clocks in the 1.2V domain are stopped, the PLL, the HSI,
|
||
417 | and the HSE RC oscillators are disabled. Internal SRAM and register contents
|
||
418 | are preserved.
|
||
419 | The voltage regulator can be configured either in normal or low-power mode.
|
||
420 | To minimize the consumption In Stop mode, FLASH can be powered off before
|
||
421 | entering the Stop mode. It can be switched on again by software after exiting
|
||
422 | the Stop mode using the PWR_FlashPowerDownCmd() function.
|
||
423 |
|
||
424 | (+) Entry:
|
||
425 | (++) The Stop mode is entered using the PWR_EnterSTOPMode(PWR_Regulator_LowPower,)
|
||
426 | function with regulator in LowPower or with Regulator ON.
|
||
427 | (+) Exit:
|
||
428 | (++) Any EXTI Line (Internal or External) configured in Interrupt/Event mode.
|
||
429 |
|
||
430 | *** Standby mode ***
|
||
431 | ====================
|
||
432 | [..]
|
||
433 | The Standby mode allows to achieve the lowest power consumption. It is based
|
||
434 | on the Cortex-M4 deepsleep mode, with the voltage regulator disabled.
|
||
435 | The 1.2V domain is consequently powered off. The PLL, the HSI oscillator and
|
||
436 | the HSE oscillator are also switched off. SRAM and register contents are lost
|
||
437 | except for the RTC registers, RTC backup registers, backup SRAM and Standby
|
||
438 | circuitry.
|
||
439 |
|
||
440 | The voltage regulator is OFF.
|
||
441 |
|
||
442 | (+) Entry:
|
||
443 | (++) The Standby mode is entered using the PWR_EnterSTANDBYMode() function.
|
||
444 | (+) Exit:
|
||
445 | (++) WKUP pin rising edge, RTC alarm (Alarm A and Alarm B), RTC wakeup,
|
||
446 | tamper event, time-stamp event, external reset in NRST pin, IWDG reset.
|
||
447 | |||
448 | *** Auto-wakeup (AWU) from low-power mode ***
|
||
449 | =============================================
|
||
450 | [..]
|
||
451 | The MCU can be woken up from low-power mode by an RTC Alarm event, an RTC
|
||
452 | Wakeup event, a tamper event, a time-stamp event, or a comparator event,
|
||
453 | without depending on an external interrupt (Auto-wakeup mode).
|
||
454 | |||
455 | (#) RTC auto-wakeup (AWU) from the Stop mode
|
||
456 |
|
||
457 | (++) To wake up from the Stop mode with an RTC alarm event, it is necessary to:
|
||
458 | (+++) Configure the EXTI Line 17 to be sensitive to rising edges (Interrupt
|
||
459 | or Event modes) using the EXTI_Init() function.
|
||
460 | (+++) Enable the RTC Alarm Interrupt using the RTC_ITConfig() function
|
||
461 | (+++) Configure the RTC to generate the RTC alarm using the RTC_SetAlarm()
|
||
462 | and RTC_AlarmCmd() functions.
|
||
463 | (++) To wake up from the Stop mode with an RTC Tamper or time stamp event, it
|
||
464 | is necessary to:
|
||
465 | (+++) Configure the EXTI Line 21 to be sensitive to rising edges (Interrupt
|
||
466 | or Event modes) using the EXTI_Init() function.
|
||
467 | (+++) Enable the RTC Tamper or time stamp Interrupt using the RTC_ITConfig()
|
||
468 | function
|
||
469 | (+++) Configure the RTC to detect the tamper or time stamp event using the
|
||
470 | RTC_TimeStampConfig(), RTC_TamperTriggerConfig() and RTC_TamperCmd()
|
||
471 | functions.
|
||
472 | (++) To wake up from the Stop mode with an RTC WakeUp event, it is necessary to:
|
||
473 | (+++) Configure the EXTI Line 22 to be sensitive to rising edges (Interrupt
|
||
474 | or Event modes) using the EXTI_Init() function.
|
||
475 | (+++) Enable the RTC WakeUp Interrupt using the RTC_ITConfig() function
|
||
476 | (+++) Configure the RTC to generate the RTC WakeUp event using the RTC_WakeUpClockConfig(),
|
||
477 | RTC_SetWakeUpCounter() and RTC_WakeUpCmd() functions.
|
||
478 | |||
479 | (#) RTC auto-wakeup (AWU) from the Standby mode
|
||
480 |
|
||
481 | (++) To wake up from the Standby mode with an RTC alarm event, it is necessary to:
|
||
482 | (+++) Enable the RTC Alarm Interrupt using the RTC_ITConfig() function
|
||
483 | (+++) Configure the RTC to generate the RTC alarm using the RTC_SetAlarm()
|
||
484 | and RTC_AlarmCmd() functions.
|
||
485 | (++) To wake up from the Standby mode with an RTC Tamper or time stamp event, it
|
||
486 | is necessary to:
|
||
487 | (+++) Enable the RTC Tamper or time stamp Interrupt using the RTC_ITConfig()
|
||
488 | function
|
||
489 | (+++) Configure the RTC to detect the tamper or time stamp event using the
|
||
490 | RTC_TimeStampConfig(), RTC_TamperTriggerConfig() and RTC_TamperCmd()
|
||
491 | functions.
|
||
492 | (++) To wake up from the Standby mode with an RTC WakeUp event, it is necessary to:
|
||
493 | (+++) Enable the RTC WakeUp Interrupt using the RTC_ITConfig() function
|
||
494 | (+++) Configure the RTC to generate the RTC WakeUp event using the RTC_WakeUpClockConfig(),
|
||
495 | RTC_SetWakeUpCounter() and RTC_WakeUpCmd() functions.
|
||
496 | |||
497 | @endverbatim
|
||
498 | * @{
|
||
499 | */
|
||
500 | |||
501 | /**
|
||
502 | * @brief Enters STOP mode.
|
||
503 | *
|
||
504 | * @note In Stop mode, all I/O pins keep the same state as in Run mode.
|
||
505 | * @note When exiting Stop mode by issuing an interrupt or a wakeup event,
|
||
506 | * the HSI RC oscillator is selected as system clock.
|
||
507 | * @note When the voltage regulator operates in low power mode, an additional
|
||
508 | * startup delay is incurred when waking up from Stop mode.
|
||
509 | * By keeping the internal regulator ON during Stop mode, the consumption
|
||
510 | * is higher although the startup time is reduced.
|
||
511 | *
|
||
512 | * @param PWR_Regulator: specifies the regulator state in STOP mode.
|
||
513 | * This parameter can be one of the following values:
|
||
514 | * @arg PWR_Regulator_ON: STOP mode with regulator ON
|
||
515 | * @arg PWR_Regulator_LowPower: STOP mode with regulator in low power mode
|
||
516 | * @param PWR_STOPEntry: specifies if STOP mode in entered with WFI or WFE instruction.
|
||
517 | * This parameter can be one of the following values:
|
||
518 | * @arg PWR_STOPEntry_WFI: enter STOP mode with WFI instruction
|
||
519 | * @arg PWR_STOPEntry_WFE: enter STOP mode with WFE instruction
|
||
520 | * @retval None
|
||
521 | */
|
||
522 | void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry)
|
||
523 | { |
||
524 | uint32_t tmpreg = 0;
|
||
525 | |||
526 | /* Check the parameters */
|
||
527 | assert_param(IS_PWR_REGULATOR(PWR_Regulator)); |
||
528 | assert_param(IS_PWR_STOP_ENTRY(PWR_STOPEntry)); |
||
529 | |||
530 | /* Select the regulator state in STOP mode ---------------------------------*/
|
||
531 | tmpreg = PWR->CR; |
||
532 | /* Clear PDDS and LPDSR bits */
|
||
533 | tmpreg &= CR_DS_MASK; |
||
534 | |||
535 | /* Set LPDSR bit according to PWR_Regulator value */
|
||
536 | tmpreg |= PWR_Regulator; |
||
537 | |||
538 | /* Store the new value */
|
||
539 | PWR->CR = tmpreg; |
||
540 | |||
541 | /* Set SLEEPDEEP bit of Cortex System Control Register */
|
||
542 | SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; |
||
543 | |||
544 | /* Select STOP mode entry --------------------------------------------------*/
|
||
545 | if(PWR_STOPEntry == PWR_STOPEntry_WFI)
|
||
546 | { |
||
547 | /* Request Wait For Interrupt */
|
||
548 | __WFI(); |
||
549 | } |
||
550 | else
|
||
551 | { |
||
552 | /* Request Wait For Event */
|
||
553 | __WFE(); |
||
554 | } |
||
555 | /* Reset SLEEPDEEP bit of Cortex System Control Register */
|
||
556 | SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk); |
||
557 | } |
||
558 | |||
559 | /**
|
||
560 | * @brief Enters STANDBY mode.
|
||
561 | * @note In Standby mode, all I/O pins are high impedance except for:
|
||
562 | * - Reset pad (still available)
|
||
563 | * - RTC_AF1 pin (PC13) if configured for tamper, time-stamp, RTC
|
||
564 | * Alarm out, or RTC clock calibration out.
|
||
565 | * - RTC_AF2 pin (PI8) if configured for tamper or time-stamp.
|
||
566 | * - WKUP pin 1 (PA0) if enabled.
|
||
567 | * @param None
|
||
568 | * @retval None
|
||
569 | */
|
||
570 | void PWR_EnterSTANDBYMode(void) |
||
571 | { |
||
572 | /* Clear Wakeup flag */
|
||
573 | PWR->CR |= PWR_CR_CWUF; |
||
574 | |||
575 | /* Select STANDBY mode */
|
||
576 | PWR->CR |= PWR_CR_PDDS; |
||
577 | |||
578 | /* Set SLEEPDEEP bit of Cortex System Control Register */
|
||
579 | SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; |
||
580 | |||
581 | /* This option is used to ensure that store operations are completed */
|
||
582 | #if defined ( __CC_ARM )
|
||
583 | __force_stores(); |
||
584 | #endif
|
||
585 | /* Request Wait For Interrupt */
|
||
586 | __WFI(); |
||
587 | } |
||
588 | |||
589 | /**
|
||
590 | * @}
|
||
591 | */
|
||
592 | |||
593 | /** @defgroup PWR_Group7 Flags management functions
|
||
594 | * @brief Flags management functions
|
||
595 | *
|
||
596 | @verbatim
|
||
597 | ===============================================================================
|
||
598 | ##### Flags management functions #####
|
||
599 | ===============================================================================
|
||
600 | |||
601 | @endverbatim
|
||
602 | * @{
|
||
603 | */
|
||
604 | |||
605 | /**
|
||
606 | * @brief Checks whether the specified PWR flag is set or not.
|
||
607 | * @param PWR_FLAG: specifies the flag to check.
|
||
608 | * This parameter can be one of the following values:
|
||
609 | * @arg PWR_FLAG_WU: Wake Up flag. This flag indicates that a wakeup event
|
||
610 | * was received from the WKUP pin or from the RTC alarm (Alarm A
|
||
611 | * or Alarm B), RTC Tamper event, RTC TimeStamp event or RTC Wakeup.
|
||
612 | * An additional wakeup event is detected if the WKUP pin is enabled
|
||
613 | * (by setting the EWUP bit) when the WKUP pin level is already high.
|
||
614 | * @arg PWR_FLAG_SB: StandBy flag. This flag indicates that the system was
|
||
615 | * resumed from StandBy mode.
|
||
616 | * @arg PWR_FLAG_PVDO: PVD Output. This flag is valid only if PVD is enabled
|
||
617 | * by the PWR_PVDCmd() function. The PVD is stopped by Standby mode
|
||
618 | * For this reason, this bit is equal to 0 after Standby or reset
|
||
619 | * until the PVDE bit is set.
|
||
620 | * @arg PWR_FLAG_BRR: Backup regulator ready flag. This bit is not reset
|
||
621 | * when the device wakes up from Standby mode or by a system reset
|
||
622 | * or power reset.
|
||
623 | * @arg PWR_FLAG_VOSRDY: This flag indicates that the Regulator voltage
|
||
624 | * scaling output selection is ready.
|
||
625 | * @retval The new state of PWR_FLAG (SET or RESET).
|
||
626 | */
|
||
627 | FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG) |
||
628 | { |
||
629 | FlagStatus bitstatus = RESET; |
||
630 | |||
631 | /* Check the parameters */
|
||
632 | assert_param(IS_PWR_GET_FLAG(PWR_FLAG)); |
||
633 | |||
634 | if ((PWR->CSR & PWR_FLAG) != (uint32_t)RESET)
|
||
635 | { |
||
636 | bitstatus = SET; |
||
637 | } |
||
638 | else
|
||
639 | { |
||
640 | bitstatus = RESET; |
||
641 | } |
||
642 | /* Return the flag status */
|
||
643 | return bitstatus;
|
||
644 | } |
||
645 | |||
646 | /**
|
||
647 | * @brief Clears the PWR's pending flags.
|
||
648 | * @param PWR_FLAG: specifies the flag to clear.
|
||
649 | * This parameter can be one of the following values:
|
||
650 | * @arg PWR_FLAG_WU: Wake Up flag
|
||
651 | * @arg PWR_FLAG_SB: StandBy flag
|
||
652 | * @retval None
|
||
653 | */
|
||
654 | void PWR_ClearFlag(uint32_t PWR_FLAG)
|
||
655 | { |
||
656 | /* Check the parameters */
|
||
657 | assert_param(IS_PWR_CLEAR_FLAG(PWR_FLAG)); |
||
658 | |||
659 | PWR->CR |= PWR_FLAG << 2;
|
||
660 | } |
||
661 | |||
662 | /**
|
||
663 | * @}
|
||
664 | */
|
||
665 | |||
666 | /**
|
||
667 | * @}
|
||
668 | */
|
||
669 | |||
670 | /**
|
||
671 | * @}
|
||
672 | */
|
||
673 | |||
674 | /**
|
||
675 | * @}
|
||
676 | */
|
||
677 | |||
678 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|