2 ******************************************************************************
\r
3 * @file stm32h7xx_hal_pwr_ex.c
\r
4 * @author MCD Application Team
\r
5 * @brief Extended PWR HAL module driver.
\r
6 * This file provides firmware functions to manage the following
\r
7 * functionalities of PWR extension peripheral:
\r
8 * + Peripheral Extended features functions
\r
10 ******************************************************************************
\r
13 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics.
\r
14 * All rights reserved.</center></h2>
\r
16 * This software component is licensed by ST under BSD 3-Clause license,
\r
17 * the "License"; You may not use this file except in compliance with the
\r
18 * License. You may obtain a copy of the License at:
\r
19 * opensource.org/licenses/BSD-3-Clause
\r
21 ******************************************************************************
\r
24 /* Includes ------------------------------------------------------------------*/
\r
25 #include "stm32h7xx_hal.h"
\r
27 /** @addtogroup STM32H7xx_HAL_Driver
\r
31 /** @defgroup PWREx PWREx
\r
32 * @brief PWR Extended HAL module driver
\r
36 #ifdef HAL_PWR_MODULE_ENABLED
\r
38 /* Private typedef -----------------------------------------------------------*/
\r
39 /* Private define ------------------------------------------------------------*/
\r
40 /** @addtogroup PWREx_Private_Constants
\r
44 /** @defgroup PWREx_AVD_Mode_Mask PWR Extended AVD Mode Mask
\r
47 #define AVD_MODE_IT ((uint32_t)0x00010000U)
\r
48 #define AVD_MODE_EVT ((uint32_t)0x00020000U)
\r
49 #define AVD_RISING_EDGE ((uint32_t)0x00000001U)
\r
50 #define AVD_FALLING_EDGE ((uint32_t)0x00000002U)
\r
51 #define AVD_RISING_FALLING_EDGE ((uint32_t)0x00000003U)
\r
56 /** @defgroup PWREx_REG_SET_TIMEOUT PWR Extended Flag Setting Time Out Value
\r
59 #define PWR_FLAG_SETTING_DELAY_US ((uint32_t)1000U)
\r
64 /** @defgroup PWREx_WakeUp_Pins_Offsets PWREx Wake-Up Pins masks and offsets
\r
67 /* Wake-Up Pins EXTI register mask */
\r
68 #define PWR_EXTI_WAKEUP_PINS_MASK (uint32_t)(EXTI_IMR2_IM55 | EXTI_IMR2_IM56 | \
\r
69 EXTI_IMR2_IM57 | EXTI_IMR2_IM58 | \
\r
70 EXTI_IMR2_IM59 | EXTI_IMR2_IM60)
\r
72 /* Wake-Up Pins PWR Pin Pull shift offsets */
\r
73 #define PWR_WAKEUP_PINS_PULL_SHIFT_OFFSET 2U
\r
83 /* Private macro -------------------------------------------------------------*/
\r
84 /* Private variables ---------------------------------------------------------*/
\r
85 /* Private function prototypes -----------------------------------------------*/
\r
86 /* Private functions ---------------------------------------------------------*/
\r
87 /* Exported types ------------------------------------------------------------*/
\r
89 /* Exported functions --------------------------------------------------------*/
\r
90 /** @defgroup PWREx_Exported_Functions PWREx Exported Functions
\r
94 /** @defgroup PWREx_Exported_Functions_Group1 Power supply control functions
\r
95 * @brief Power supply control functions
\r
99 ===============================================================================
\r
100 ##### Power supply control functions #####
\r
101 ===============================================================================
\r
103 *** Power supply configuration ***
\r
104 ==================================
\r
106 When the system is powered on, the POR monitors VDD supply. Once VDD is above the
\r
107 POR threshold level, the voltage regulator is enabled in the default supply
\r
109 (+) The Voltage converter output level is set at 1.0 V in accordance with the VOS3
\r
110 level configured in PWR D3 domain control register (PWR_D3CR).
\r
111 (+) The system is kept in reset mode as long as VCORE is not ok.
\r
112 (+) Once VCORE is ok, the system is taken out of reset and the HSI oscillator is enabled.
\r
113 (+) Once the oscillator is stable, the system is initialized: Flash memory and option
\r
114 bytes are loaded and the CPU starts in Run* mode.
\r
115 (+) The software shall then initialize the system including supply configuration
\r
116 programming using the HAL_PWREx_ConfigSupply(SupplySource) with:
\r
118 (+++) PWR_LDO_SUPPLY: VCORE Power Domains are supplied from the LDO according to
\r
119 VOS. LDO power mode (Main, LP, Off) will follow system low-power
\r
121 (+++) PWR_EXTERNAL_SOURCE_SUPPLY: VCORE supplied from external source and LDO bypassed,
\r
122 voltage monitoring still active.
\r
123 (+) Once the supply configuration has been configured, the HAL_PWREx_ConfigSupply
\r
124 function checks the ACTVOSRDY bit in PWR control status register 1 (PWR_CSR1)
\r
125 to guarantee a valid voltage levels:
\r
126 (++) As long as ACTVOSRDY indicates that voltage levels are invalid, the system is in
\r
127 limited Run* mode, write accesses to the RAMs are not permitted and VOS shall
\r
129 (++) Once ACTVOSRDY indicates that voltage levels are valid, the system is in normal
\r
130 Run mode, write accesses to RAMs are allowed and VOS can be changed.
\r
138 * @brief Configure the system Power Supply.
\r
139 * @param SupplySource: Specifies the Power Supply source to set after a system startup.
\r
140 * This parameter can be one of the following values:
\r
141 * @arg PWR_LDO_SUPPLY The LDO regulator supplies the Vcore Power Domains.
\r
142 * The SMPS regulator is Bypassed.
\r
144 * @arg PWR_DIRECT_SMPS_SUPPLY The SMPS supplies the Vcore Power Domains.
\r
145 * The LDO is Bypassed.
\r
147 * @arg PWR_SMPS_1V8_SUPPLIES_LDO The SMPS 1.8V output supplies the LDO.
\r
148 * The Vcore Power Domains are supplied from the LDO.
\r
150 * @arg PWR_SMPS_2V5_SUPPLIES_LDO The SMPS 2.5V output supplies the LDO.
\r
151 * The Vcore Power Domains are supplied from the LDO.
\r
153 * @arg PWR_SMPS_1V8_SUPPLIES_EXT_AND_LDO The SMPS 1.8V output supplies external circuits and the LDO.
\r
154 * The Vcore Power Domains are supplied from the LDO.
\r
156 * @arg PWR_SMPS_2V5_SUPPLIES_EXT_AND_LDO The SMPS 2.5V output supplies external circuits and the LDO.
\r
157 * The Vcore Power Domains are supplied from the LDO.
\r
159 * @arg PWR_SMPS_1V8_SUPPLIES_EXT The SMPS 1.8V output supplies external circuits.
\r
160 * The LDO is Bypassed.
\r
161 * The Vcore Power Domains are supplied from external source.
\r
163 * @arg PWR_SMPS_2V5_SUPPLIES_EXT The SMPS 2.5V output supplies external circuits.
\r
164 * The LDO is Bypassed.
\r
165 * The Vcore Power Domains are supplied from external source.
\r
167 * @arg PWR_EXTERNAL_SOURCE_SUPPLY The SMPS and the LDO are Bypassed.
\r
168 * The Vcore Power Domains are supplied from external source.
\r
169 * @retval HAL status.
\r
171 HAL_StatusTypeDef HAL_PWREx_ConfigSupply(uint32_t SupplySource)
\r
173 uint32_t tickstart;
\r
175 /* Check the parameters */
\r
176 assert_param(IS_PWR_SUPPLY(SupplySource));
\r
178 if((PWR->CR3 & (PWR_CR3_SMPSEN | PWR_CR3_LDOEN | PWR_CR3_BYPASS)) != (PWR_CR3_SMPSEN | PWR_CR3_LDOEN))
\r
180 if((PWR->CR3 & PWR_SUPPLY_CONFIG_MASK) != SupplySource)
\r
182 /* Supply configuration update locked, can't apply a new regulator config */
\r
187 /* Set the power supply configuration */
\r
188 MODIFY_REG(PWR->CR3, PWR_SUPPLY_CONFIG_MASK, SupplySource);
\r
191 tickstart = HAL_GetTick();
\r
193 /* Wait till voltage level flag is set */
\r
194 while(!__HAL_PWR_GET_FLAG(PWR_FLAG_ACTVOSRDY))
\r
196 if((HAL_GetTick() - tickstart ) > PWR_FLAG_SETTING_DELAY_US)
\r
198 return HAL_TIMEOUT;
\r
202 /* When the SMPS supplies external circuits verify that SDEXTRDY flag is set */
\r
203 if((SupplySource == PWR_SMPS_1V8_SUPPLIES_EXT_AND_LDO) ||
\r
204 (SupplySource == PWR_SMPS_2V5_SUPPLIES_EXT_AND_LDO) ||
\r
205 (SupplySource == PWR_SMPS_1V8_SUPPLIES_EXT) ||
\r
206 (SupplySource == PWR_SMPS_2V5_SUPPLIES_EXT))
\r
209 tickstart = HAL_GetTick();
\r
211 /* Wait till SMPS external supply ready flag is set */
\r
212 while(!__HAL_PWR_GET_FLAG(PWR_FLAG_SMPSEXTRDY))
\r
214 if((HAL_GetTick() - tickstart ) > PWR_FLAG_SETTING_DELAY_US)
\r
216 return HAL_TIMEOUT;
\r
225 * @brief Configure the system Power Supply.
\r
226 * @param SupplySource: Specifies the Power Supply source to set after a system startup.
\r
227 * This parameter can be one of the following values:
\r
228 * @arg PWR_LDO_SUPPLY The LDO regulator supplies the Vcore Power Domains.
\r
230 * @arg PWR_EXTERNAL_SOURCE_SUPPLY The LDO regulator is Bypassed.
\r
231 * The Vcore Power Domains are supplied from external source.
\r
232 * @retval HAL status.
\r
234 HAL_StatusTypeDef HAL_PWREx_ConfigSupply(uint32_t SupplySource)
\r
236 uint32_t tickstart;
\r
238 /* Check the parameters */
\r
239 assert_param(IS_PWR_SUPPLY(SupplySource));
\r
241 if(!__HAL_PWR_GET_FLAG(PWR_FLAG_SCUEN))
\r
243 if((PWR->CR3 & PWR_SUPPLY_CONFIG_MASK) != SupplySource)
\r
245 /* Supply configuration update locked, can't apply a new regulator config */
\r
250 /* Set the power supply configuration */
\r
251 MODIFY_REG(PWR->CR3, PWR_SUPPLY_CONFIG_MASK, SupplySource);
\r
254 tickstart = HAL_GetTick();
\r
256 /* Wait till voltage level flag is set */
\r
257 while(!__HAL_PWR_GET_FLAG(PWR_FLAG_ACTVOSRDY))
\r
259 if((HAL_GetTick() - tickstart ) > PWR_FLAG_SETTING_DELAY_US)
\r
261 return HAL_TIMEOUT;
\r
271 * @brief Get the power supply configuration.
\r
272 * @retval The supply configuration.
\r
274 uint32_t HAL_PWREx_GetSupplyConfig(void)
\r
276 return (PWR->CR3 & PWR_SUPPLY_CONFIG_MASK);
\r
280 * @brief Configure the main internal regulator output voltage.
\r
281 * @param VoltageScaling: Specifies the regulator output voltage to achieve
\r
282 * a tradeoff between performance and power consumption.
\r
283 * This parameter can be one of the following values:
\r
284 * @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output range 1 mode.
\r
285 * @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output range 2 mode.
\r
286 * @arg PWR_REGULATOR_VOLTAGE_SCALE3: Regulator voltage output range 3 mode.
\r
287 * @note When moving from Range 1 to Range 2, the system frequency must be decreased
\r
288 * before calling HAL_PWREx_ControlVoltageScaling() API.
\r
289 * When moving from Range 2 to Range 1, the system frequency can be increased
\r
290 * after calling HAL_PWREx_ControlVoltageScaling() API.
\r
291 * @note When moving from a Range to an other one, the API waits for VOSRDY flag to be
\r
292 * set before returning the status. If the flag is not set within 1000 microseconds,
\r
293 * HAL_TIMEOUT status is reported.
\r
294 * @retval HAL Status
\r
296 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)
\r
298 uint32_t tickstart;
\r
300 assert_param(IS_PWR_REGULATOR_VOLTAGE(VoltageScaling));
\r
302 /* Set the voltage range */
\r
303 MODIFY_REG(PWR->D3CR, PWR_D3CR_VOS, VoltageScaling);
\r
306 tickstart = HAL_GetTick();
\r
308 /* Wait until the VOSRDY flag is set */
\r
309 while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY))
\r
311 if((HAL_GetTick() - tickstart ) > PWR_FLAG_SETTING_DELAY_US)
\r
313 return HAL_TIMEOUT;
\r
321 * @brief Get the main internal regulator output voltage.
\r
322 * Reflecting the last VOS value applied to the PMU.
\r
323 * @retval The actual applied VOS for VDD11 Voltage Scaling selection.
\r
325 uint32_t HAL_PWREx_GetVoltageRange(void)
\r
327 return (PWR->CSR1 & PWR_CSR1_ACTVOS);
\r
331 * @brief Configure the main internal regulator output voltage in STOP mode.
\r
332 * @param VoltageScaling: Specifies the regulator output voltage when the system enters
\r
333 * Stop mode to achieve a tradeoff between performance and power consumption.
\r
334 * This parameter can be one of the following values:
\r
335 * @arg PWR_REGULATOR_SVOS_SCALE3: Regulator voltage output range 3 mode.
\r
336 * @arg PWR_REGULATOR_SVOS_SCALE4: Regulator voltage output range 4 mode.
\r
337 * @arg PWR_REGULATOR_SVOS_SCALE5: Regulator voltage output range 5 mode.
\r
338 * @note The Stop mode voltage scaling for SVOS4 and SVOS5 sets the voltage regulator
\r
339 * in Low-power (LP) mode to further reduce power consumption.
\r
340 * When preselecting SVOS3, the use of the voltage regulator low-power mode (LP)
\r
341 * can be selected by LPDS register bit.
\r
342 * @note The selected SVOS4 and SVOS5 levels add an additional startup delay when exiting
\r
343 * from system Stop mode.
\r
344 * @retval HAL Status
\r
346 HAL_StatusTypeDef HAL_PWREx_ControlStopModeVoltageScaling(uint32_t VoltageScaling)
\r
348 assert_param(IS_PWR_STOP_MODE_REGULATOR_VOLTAGE(VoltageScaling));
\r
350 /* Set the stop mode voltage range */
\r
351 MODIFY_REG(PWR->CR1, PWR_CR1_SVOS, VoltageScaling);
\r
357 * @brief Get the main internal regulator output voltage in STOP mode.
\r
358 * @retval The actual applied VOS for VDD11 Voltage Scaling selection.
\r
360 uint32_t HAL_PWREx_GetStopModeVoltageRange(void)
\r
362 return (PWR->CR1 & PWR_CR1_SVOS);
\r
369 /** @defgroup PWREx_Exported_Functions_Group2 Low power control functions
\r
370 * @brief Low power control functions
\r
374 ===============================================================================
\r
375 ##### Low power control functions #####
\r
376 ===============================================================================
\r
378 *** Domains Low Power modes configuration ***
\r
379 =============================================
\r
381 The system present 3 principles domains (D1, D2 and D3) that can be operated
\r
382 in low-power modes (DSTOP or DSTANDBY mode):
\r
384 (+) DSTOP mode to enters a domain to STOP mode:
\r
385 (++) D1 domain and/or D2 domain enters DSTOP mode only when the CPU
\r
386 subsystem is in CSTOP mode and has allocated peripheral in the domain.
\r
387 In DSTOP mode the domain bus matrix clock is stopped.
\r
388 (++) The system enters STOP mode using one of the following scenarios:
\r
389 (+++) D1 domain enters DSTANDBY mode (powered off) and D2, D3 domains enter DSTOP mode.
\r
390 (+++) D2 domain enters DSTANDBY mode (powered off) and D1, D3 domains enter DSTOP mode.
\r
391 (+++) D3 domain enters DSTANDBY mode (powered off) and D1, D2 domains enter DSTOP mode.
\r
392 (+++) D1 and D2 domains enter DSTANDBY mode (powered off) and D3 domain enters DSTOP mode.
\r
393 (+++) D1 and D3 domains enter DSTANDBY mode (powered off) and D2 domain enters DSTOP mode.
\r
394 (+++) D2 and D3 domains enter DSTANDBY mode (powered off) and D1 domain enters DSTOP mode.
\r
395 (+++) D1, D2 and D3 domains enter DSTOP mode.
\r
396 (++) When the system enters STOP mode, the clocks are stopped and the regulator is running
\r
397 in main or low power mode.
\r
398 (++) D3 domain can be kept in Run mode regardless of the CPU status when enter
\r
399 STOP mode by using HAL_PWREx_ConfigD3Domain(D3State) function.
\r
401 (+) DSTANDBY mode to enters a domain to STANDBY mode:
\r
402 (++) The DSTANDBY mode is entered when the PDDS_Dn bit in PWR CPU control register
\r
403 (PWR_CPUCR) for the Dn domain selects Standby mode.
\r
404 (++) The system enters STANDBY mode only when D1, D2 and D3 domains enter DSTANDBY mode.
\r
405 Consequently the VCORE supply regulator is powered off.
\r
410 In DStop mode the domain bus matrix clock is stopped.
\r
411 The Flash memory can enter low-power Stop mode when it is enabled through FLPS in
\r
412 PWR_CR1 register. This allows a trade-off between domain DStop restart time and low
\r
415 In DStop mode domain peripherals using the LSI or LSE clock and peripherals having a
\r
416 kernel clock request are still able to operate.
\r
418 Before entering DSTOP mode it is recommended to call SCB_CleanDCache function
\r
419 in order to clean the D-Cache and guarantee the data integrity for the SRAM memories.
\r
422 The DSTOP mode is entered using the HAL_PWREx_EnterSTOPMode(Regulator, STOPEntry, Domain)
\r
425 (+++) PWR_MAINREGULATOR_ON: Main regulator ON.
\r
426 (+++) PWR_LOWPOWERREGULATOR_ON: Low Power regulator ON.
\r
428 (+++) PWR_STOPENTRY_WFI: enter STOP mode with WFI instruction
\r
429 (+++) PWR_STOPENTRY_WFE: enter STOP mode with WFE instruction
\r
431 (+++) PWR_D1_DOMAIN: Enters D1 domain to DSTOP mode.
\r
432 (+++) PWR_D2_DOMAIN: Enters D2 domain to DSTOP mode.
\r
433 (+++) PWR_D3_DOMAIN: Enters D3 domain to DSTOP mode.
\r
436 Any EXTI Line (Internal or External) configured in Interrupt/Event mode.
\r
438 *** DSTANDBY mode ***
\r
439 ====================
\r
442 (+) The domain bus matrix clock is stopped.
\r
443 (+) The domain is powered down and the domain RAM and register contents are lost.
\r
445 Before entering DSTANDBY mode it is recommended to call SCB_CleanDCache function
\r
446 in order to clean the D-Cache and guarantee the data integrity for the SRAM memories.
\r
449 The DSTANDBY mode is entered using the HAL_PWREx_EnterSTANDBYMode(Domain) function with:
\r
451 (+++) PWR_D1_DOMAIN: Enters D1 domain to DSTANDBY mode.
\r
452 (+++) PWR_D2_DOMAIN: Enters D2 domain to DSTANDBY mode.
\r
453 (+++) PWR_D3_DOMAIN: Enters D3 domain to DSTANDBY mode.
\r
456 WKUP pin rising or falling edge, RTC alarm (Alarm A and Alarm B), RTC
\r
457 wakeup, tamper event, time stamp event, external reset in NRST pin, IWDG reset.
\r
459 *** Keep D3 in RUN mode ***
\r
460 ===========================
\r
462 D3 domain can be kept in Run mode regardless of the CPU status when enter
\r
463 STOP mode by using HAL_PWREx_ConfigD3Domain(D3State) function with:
\r
465 (++) PWR_D3_DOMAIN_STOP: D3 domain will follow the CPU sub-system mode.
\r
466 (++) PWR_D3_DOMAIN_RUN: D3 domain remains in Run mode regardless of CPU subsystem mode.
\r
468 *** FLASH Power Down configuration ****
\r
469 =======================================
\r
471 By setting the FLPS bit in the PWR_CR1 register using the HAL_PWREx_EnableFlashPowerDown()
\r
472 function, the Flash memory also enters power down mode when the device enters Stop mode.
\r
473 When the Flash memory is in power down mode, an additional startup delay is incurred when
\r
474 waking up from Stop mode.
\r
476 *** Wakeup Pins configuration ****
\r
477 ===================================
\r
479 Wakeup pins allow the system to exit from Standby mode. The configuration of
\r
480 wakeup pins is done with the HAL_PWREx_EnableWakeUpPin(sPinParams) function with:
\r
481 (+) sPinParams: structure to enable and configure a wakeup pin:
\r
482 (++) WakeUpPin: Wakeup pin to be enabled.
\r
483 (++) PinPolarity: Wakeup pin polarity (rising or falling edge).
\r
484 (++) PinPull: Wakeup pin pull (no pull, pull-up or pull-down).
\r
486 The wakeup pins are internally connected to the EXTI lines [55-60] to generate an interrupt
\r
487 if enabled. The EXTI lines configuration is done by the HAL_EXTI_Dx_EventInputConfig() functions
\r
488 defined in the stm32h7xxhal.c file.
\r
490 When a wakeup pin event is received the HAL_PWREx_WAKEUP_PIN_IRQHandler is called
\r
491 and the appropriate flag is set in the PWR_WKUPFR register. Then in the HAL_PWREx_WAKEUP_PIN_IRQHandler
\r
492 function the wakeup pin flag will be cleared and the appropriate user callback will be called.
\r
493 The user can add his own code by customization of function pointer HAL_PWREx_WKUPx_Callback.
\r
500 * @brief Enter a Domain to DSTOP mode.
\r
501 * @note In DStop mode the domain bus matrix clock is stopped.
\r
502 * @note The system D3 domain enters Stop mode only when the CPU subsystem is in CStop mode,
\r
503 * the EXTI wakeup sources are inactive and at least one PDDS_Dn bit in PWR CPU
\r
504 * control register (PWR_CPUCR) for any domain request Stop.
\r
505 * @note In system D3 domain Stop mode, D1 domain and D2 domain are either in DStop and/or
\r
507 * @note Before entering DSTOP mode it is recommended to call SCB_CleanDCache function
\r
508 * in order to clean the D-Cache and guarantee the data integrity for the SRAM memories.
\r
509 * @note In System Stop mode, the domain peripherals that use the LSI or LSE clock, and the
\r
510 * peripherals that have a kernel clock request to select HSI or CSI as source,
\r
511 * are still able to operate.
\r
512 * @param Regulator: Specifies the regulator state in Stop mode.
\r
513 * This parameter can be one of the following values:
\r
514 * @arg PWR_MAINREGULATOR_ON: Stop mode with regulator ON
\r
515 * @arg PWR_LOWPOWERREGULATOR_ON: Stop mode with low power regulator ON
\r
516 * @param STOPEntry: Specifies if Stop mode in entered with WFI or WFE instruction.
\r
517 * This parameter can be one of the following values:
\r
518 * @arg PWR_STOPENTRY_WFI: Enter DStop mode with WFI instruction
\r
519 * @arg PWR_STOPENTRY_WFE: Enter DStop mode with WFE instruction
\r
520 * @param Domain: Specifies the Domain to enter STOP mode.
\r
521 * This parameter can be one of the following values:
\r
522 * @arg PWR_D1_DOMAIN: Enter D1 Domain to DSTOP mode.
\r
523 * @arg PWR_D2_DOMAIN: Enter D2 Domain to DSTOP mode.
\r
524 * @arg PWR_D3_DOMAIN: Enter D3 Domain to DSTOP mode.
\r
527 void HAL_PWREx_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry, uint32_t Domain)
\r
529 /* Check the parameters */
\r
530 assert_param(IS_PWR_REGULATOR(Regulator));
\r
531 assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
\r
532 assert_param(IS_PWR_DOMAIN(Domain));
\r
534 /* Select the regulator state in Stop mode */
\r
535 MODIFY_REG(PWR->CR1, PWR_CR1_LPDS, Regulator);
\r
537 /* Select the domain Power Down DeepSleep */
\r
538 if (Domain == PWR_D1_DOMAIN)
\r
541 assert_param(IS_PWR_D1_CPU(HAL_GetCurrentCPUID()));
\r
543 /* Keep DSTOP mode when D1 domain enters Deepsleep */
\r
544 CLEAR_BIT(PWR->CPUCR, PWR_CPUCR_PDDS_D1);
\r
546 #if defined(DUAL_CORE)
\r
547 CLEAR_BIT(PWR->CPU2CR, PWR_CPU2CR_PDDS_D1);
\r
548 #endif /*DUAL_CORE*/
\r
550 /* Set SLEEPDEEP bit of Cortex System Control Register */
\r
551 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
\r
553 /* Ensure that all instructions done before entering STOP mode */
\r
557 /* Select Stop mode entry */
\r
558 if(STOPEntry == PWR_STOPENTRY_WFI)
\r
560 /* Request Wait For Interrupt */
\r
565 /* Request Wait For Event */
\r
569 /* Reset SLEEPDEEP bit of Cortex System Control Register */
\r
570 SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
\r
572 else if (Domain == PWR_D2_DOMAIN)
\r
574 /* Keep DSTOP mode when D2 domain enters Deepsleep */
\r
575 CLEAR_BIT(PWR->CPUCR, PWR_CPUCR_PDDS_D2);
\r
577 #if defined(DUAL_CORE)
\r
579 assert_param(IS_PWR_D2_CPU(HAL_GetCurrentCPUID()));
\r
581 CLEAR_BIT(PWR->CPU2CR, PWR_CPU2CR_PDDS_D2);
\r
583 /* Set SLEEPDEEP bit of Cortex System Control Register */
\r
584 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
\r
586 /* Ensure that all instructions done before entering STOP mode */
\r
590 /* Select Stop mode entry */
\r
591 if(STOPEntry == PWR_STOPENTRY_WFI)
\r
593 /* Request Wait For Interrupt */
\r
598 /* Request Wait For Event */
\r
602 /* Reset SLEEPDEEP bit of Cortex System Control Register */
\r
603 SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
\r
604 #endif /*DUAL_CORE*/
\r
608 /* Keep DSTOP mode when D3 domain enters Deepsleep */
\r
609 CLEAR_BIT(PWR->CPUCR, PWR_CPUCR_PDDS_D3);
\r
611 #if defined(DUAL_CORE)
\r
612 CLEAR_BIT(PWR->CPU2CR, PWR_CPU2CR_PDDS_D3);
\r
613 #endif /*DUAL_CORE*/
\r
619 * @brief Clear pending event.
\r
620 * @note This API clear the pending event in order to enter a given domain to DSTOP. It should
\r
621 * be called just before enter low power mode APIs using Wait For Event request.
\r
624 void HAL_PWREx_ClearPendingEvent(void)
\r
626 #if defined(DUAL_CORE)
\r
628 if(HAL_GetCurrentCPUID() == CM7_CPUID)
\r
639 #endif /*DUAL_CORE*/
\r
644 * @brief Enter a Domain to DSTANDBY mode.
\r
645 * @note The DStandby mode is entered when all PDDS_Dn bits in PWR_CPUCR for the Dn domain
\r
646 * select Standby mode. When the system enters Standby mode, the voltage regulator
\r
648 * @note When D2 or D3 domain is in DStandby mode and the CPU sets the domain PDDS_Dn
\r
649 * bit to select Stop mode, the domain remains in DStandby mode. The domain will only
\r
650 * exit DStandby when the CPU allocates a peripheral in the domain.
\r
651 * @note The system D3 domain enters Standby mode only when the D1 and D2 domain are in
\r
653 * @note Before entering DSTANDBY mode it is recommended to call SCB_CleanDCache function
\r
654 * in order to clean the D-Cache and guarantee the data integrity for the SRAM memories.
\r
655 * @param Domain: Specifies the Domain to enter to STANDBY mode.
\r
656 * This parameter can be one of the following values:
\r
657 * @arg PWR_D1_DOMAIN: Enter D1 Domain to DSTANDBY mode.
\r
658 * @arg PWR_D2_DOMAIN: Enter D2 Domain to DSTANDBY mode.
\r
659 * @arg PWR_D3_DOMAIN: Enter D3 Domain to DSTANDBY mode.
\r
662 void HAL_PWREx_EnterSTANDBYMode(uint32_t Domain)
\r
664 /* Check the parameters */
\r
665 assert_param(IS_PWR_DOMAIN(Domain));
\r
667 /* Select the domain Power Down DeepSleep */
\r
668 if (Domain == PWR_D1_DOMAIN)
\r
671 assert_param(IS_PWR_D1_CPU(HAL_GetCurrentCPUID()));
\r
673 /* Allow DSTANDBY mode when D1 domain enters Deepsleep */
\r
674 SET_BIT(PWR-> CPUCR, PWR_CPUCR_PDDS_D1);
\r
676 #if defined(DUAL_CORE)
\r
677 SET_BIT(PWR-> CPU2CR, PWR_CPU2CR_PDDS_D1);
\r
678 #endif /*DUAL_CORE*/
\r
680 /* Set SLEEPDEEP bit of Cortex System Control Register */
\r
681 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
\r
683 /* This option is used to ensure that store operations are completed */
\r
684 #if defined ( __CC_ARM)
\r
688 /* Request Wait For Interrupt */
\r
691 else if (Domain == PWR_D2_DOMAIN)
\r
693 /* Allow DSTANDBY mode when D2 domain enters Deepsleep */
\r
694 SET_BIT(PWR-> CPUCR, PWR_CPUCR_PDDS_D2);
\r
696 #if defined(DUAL_CORE)
\r
698 assert_param(IS_PWR_D2_CPU(HAL_GetCurrentCPUID()));
\r
700 SET_BIT(PWR-> CPU2CR, PWR_CPU2CR_PDDS_D2);
\r
702 /* Set SLEEPDEEP bit of Cortex System Control Register */
\r
703 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
\r
705 /* This option is used to ensure that store operations are completed */
\r
706 #if defined ( __CC_ARM)
\r
710 /* Request Wait For Interrupt */
\r
712 #endif /*DUAL_CORE*/
\r
716 /* Allow DSTANDBY mode when D3 domain enters Deepsleep */
\r
717 SET_BIT(PWR-> CPUCR, PWR_CPUCR_PDDS_D3);
\r
719 #if defined(DUAL_CORE)
\r
720 SET_BIT(PWR-> CPU2CR, PWR_CPU2CR_PDDS_D3);
\r
721 #endif /*DUAL_CORE*/
\r
726 * @brief Configure the D3 Domain state when the CPU is in low power mode.
\r
727 * @param D3State: Specifies the D3 state.
\r
728 * This parameter can be one of the following values:
\r
729 * @arg PWR_D3_DOMAIN_STOP: D3 domain will follow the CPU sub-system mode.
\r
730 * @arg PWR_D3_DOMAIN_RUN : D3 domain will stay in RUN mode regardless of the
\r
731 * CPU sub-system mode.
\r
734 void HAL_PWREx_ConfigD3Domain(uint32_t D3State)
\r
736 /* Check the parameters */
\r
737 assert_param(IS_D3_STATE(D3State));
\r
739 /* Keep D3 in run mode */
\r
740 MODIFY_REG(PWR->CPUCR, PWR_CPUCR_RUN_D3, D3State);
\r
741 #if defined(DUAL_CORE)
\r
742 MODIFY_REG(PWR->CPU2CR, PWR_CPU2CR_RUN_D3, D3State);
\r
743 #endif /*DUAL_CORE*/
\r
746 #if defined(DUAL_CORE)
\r
748 * @brief Clear HOLD2F, STOPF, SBF, SBF_D1, and SBF_D2 flags for a given domain.
\r
749 * @param DomainFlags: Specifies the Domain flags to be cleared.
\r
750 * This parameter can be one of the following values:
\r
751 * @arg PWR_D1_DOMAIN_FLAGS: Clear D1 Domain flags.
\r
752 * @arg PWR_D2_DOMAIN_FLAGS: Clear D2 Domain flags.
\r
755 void HAL_PWREx_ClearDomainFlags(uint32_t DomainFlags)
\r
757 /* Check the parameters */
\r
758 assert_param(IS_PWR_DOMAIN_FLAG(DomainFlags));
\r
760 if (DomainFlags == PWR_D1_DOMAIN_FLAGS)
\r
762 /* Clear D1 domain flags (HOLD2F, STOPF, SBF, SBF_D1, and SBF_D2) */
\r
763 SET_BIT(PWR->CPUCR, PWR_CPUCR_CSSF);
\r
767 /* Clear D2 domain flags (HOLD2F, STOPF, SBF, SBF_D1, and SBF_D2) */
\r
768 SET_BIT(PWR->CPU2CR, PWR_CPU2CR_CSSF);
\r
771 #endif /*DUAL_CORE*/
\r
773 #if defined(DUAL_CORE)
\r
775 * @brief Hold the CPU and their allocated peripherals when exiting from STOP mode.
\r
776 * @param CPU: Specifies the core to be held.
\r
777 * This parameter can be one of the following values:
\r
778 * @arg PWR_CORE_CPU1: Hold CPU1 and set CPU2 as master.
\r
779 * @arg PWR_CORE_CPU2: Hold CPU2 and set CPU1 as master.
\r
780 * @retval HAL status
\r
782 HAL_StatusTypeDef HAL_PWREx_HoldCore(uint32_t CPU)
\r
784 HAL_StatusTypeDef status = HAL_OK;
\r
786 /* Check the parameters */
\r
787 assert_param(IS_PWR_CORE(CPU));
\r
789 if (PWR_CORE_CPU2 == CPU)
\r
791 /* If CPU1 is not held */
\r
792 if(PWR_CPU2CR_HOLD1 != (PWR->CPU2CR & PWR_CPU2CR_HOLD1))
\r
794 /* Set HOLD2 bit */
\r
795 SET_BIT(PWR->CPUCR, PWR_CPUCR_HOLD2);
\r
799 status = HAL_ERROR;
\r
802 else if (PWR_CORE_CPU1 == CPU)
\r
804 /* If CPU2 is not held */
\r
805 if(PWR_CPUCR_HOLD2 != (PWR->CPUCR & PWR_CPUCR_HOLD2))
\r
807 /* Set HOLD1 bit */
\r
808 SET_BIT(PWR->CPU2CR, PWR_CPU2CR_HOLD1);
\r
812 status = HAL_ERROR;
\r
817 status = HAL_ERROR;
\r
822 #endif /*DUAL_CORE*/
\r
825 #if defined(DUAL_CORE)
\r
827 * @brief Release the CPU and their allocated peripherals after a wake-up from STOP mode.
\r
828 * @param CPU: Specifies the core to be released.
\r
829 * This parameter can be one of the following values:
\r
830 * @arg PWR_CORE_CPU1: Release the CPU1 and their allocated peripherals from holding.
\r
831 * @arg PWR_CORE_CPU2: Release the CPU2 and their allocated peripherals from holding.
\r
834 void HAL_PWREx_ReleaseCore(uint32_t CPU)
\r
836 /* Check the parameters */
\r
837 assert_param(IS_PWR_CORE(CPU));
\r
839 if (PWR_CORE_CPU2 == CPU)
\r
841 /* Reset HOLD2 bit */
\r
842 CLEAR_BIT(PWR->CPUCR, PWR_CPUCR_HOLD2);
\r
846 /* Reset HOLD1 bit */
\r
847 CLEAR_BIT(PWR->CPU2CR, PWR_CPU2CR_HOLD1);
\r
850 #endif /*DUAL_CORE*/
\r
853 * @brief Enable the Flash Power Down in Stop mode.
\r
856 void HAL_PWREx_EnableFlashPowerDown(void)
\r
858 /* Enable the Flash Power Down */
\r
859 SET_BIT(PWR->CR1, PWR_CR1_FLPS);
\r
863 * @brief Disable the Flash Power Down in Stop mode.
\r
866 void HAL_PWREx_DisableFlashPowerDown(void)
\r
868 /* Disable the Flash Power Down */
\r
869 CLEAR_BIT(PWR->CR1, PWR_CR1_FLPS);
\r
873 * @brief Enable the Wake-up PINx functionality.
\r
874 * @param sPinParams: pointer to an PWREx_WakeupPinTypeDef structure that contains
\r
875 * the configuration informations for the wake-up Pin.
\r
878 void HAL_PWREx_EnableWakeUpPin(PWREx_WakeupPinTypeDef *sPinParams)
\r
880 uint32_t pinConfig;
\r
882 const uint32_t pullMask = PWR_WKUPEPR_WKUPPUPD1;
\r
884 /* Check the parameters */
\r
885 assert_param(IS_PWR_WAKEUP_PIN(sPinParams->WakeUpPin));
\r
886 assert_param(IS_PWR_WAKEUP_PIN_POLARITY(sPinParams->PinPolarity));
\r
887 assert_param(IS_PWR_WAKEUP_PIN_PULL(sPinParams->PinPull));
\r
889 pinConfig = sPinParams->WakeUpPin | \
\r
890 (sPinParams->PinPolarity << ((POSITION_VAL(sPinParams->WakeUpPin) + PWR_WKUPEPR_WKUPP1_Pos) & 0x1FU)) | \
\r
891 (sPinParams->PinPull << (((POSITION_VAL(sPinParams->WakeUpPin) * PWR_WAKEUP_PINS_PULL_SHIFT_OFFSET) + PWR_WKUPEPR_WKUPPUPD1_Pos) & 0x1FU));
\r
893 regMask = sPinParams->WakeUpPin | \
\r
894 (PWR_WKUPEPR_WKUPP1 << (POSITION_VAL(sPinParams->WakeUpPin) & 0x1FU)) | \
\r
895 (pullMask << ((POSITION_VAL(sPinParams->WakeUpPin) * PWR_WAKEUP_PINS_PULL_SHIFT_OFFSET) & 0x1FU));
\r
897 /* Enable and Specify the Wake-Up pin polarity and the pull configuration
\r
898 for the event detection (rising or falling edge) */
\r
899 MODIFY_REG(PWR->WKUPEPR, regMask, pinConfig);
\r
901 /* Configure the Wakeup Pin EXTI Line */
\r
902 MODIFY_REG(EXTI->IMR2, PWR_EXTI_WAKEUP_PINS_MASK, (sPinParams->WakeUpPin << EXTI_IMR2_IM55_Pos));
\r
907 * @brief Disable the Wake-up PINx functionality.
\r
908 * @param WakeUpPin: Specifies the Wake-Up pin to be disabled.
\r
909 * This parameter can be one of the following values:
\r
910 * @arg PWR_WAKEUP_PIN1: Disable PA0 wake-up PIN.
\r
911 * @arg PWR_WAKEUP_PIN2: Disable PA2 wake-up PIN..
\r
912 * @arg PWR_WAKEUP_PIN3: Disable PI8 wake-up PIN..
\r
913 * @arg PWR_WAKEUP_PIN4: Disable PC13 wake-up PIN..
\r
914 * @arg PWR_WAKEUP_PIN5: Disable PI11 wake-up PIN..
\r
915 * @arg PWR_WAKEUP_PIN6: Disable PC1 wake-up PIN..
\r
918 void HAL_PWREx_DisableWakeUpPin(uint32_t WakeUpPin)
\r
920 /* Check the parameters */
\r
921 assert_param(IS_PWR_WAKEUP_PIN(WakeUpPin));
\r
923 /* Disable the WakeUpPin */
\r
924 CLEAR_BIT(PWR->WKUPEPR, WakeUpPin);
\r
928 * @brief Get the Wake-Up Pin flag.
\r
929 * @param WakeUpFlag: Specifies the Wake-Up PIN flag to check.
\r
930 * This parameter can be one of the following values:
\r
931 * @arg PWR_WAKEUP_FLAG1: A wakeup event was received from PA0.
\r
932 * @arg PWR_WAKEUP_FLAG2: A wakeup event was received from PA2.
\r
933 * @arg PWR_WAKEUP_FLAG3: A wakeup event was received from PC1.
\r
934 * @arg PWR_WAKEUP_FLAG4: A wakeup event was received from PC13.
\r
935 * @arg PWR_WAKEUP_FLAG5: A wakeup event was received from PI8.
\r
936 * @arg PWR_WAKEUP_FLAG6: A wakeup event was received from PI11.
\r
937 * @retval The Wake-Up pin flag.
\r
939 uint32_t HAL_PWREx_GetWakeupFlag(uint32_t WakeUpFlag)
\r
941 /* Check the parameters */
\r
942 assert_param(IS_PWR_WAKEUP_FLAG(WakeUpFlag));
\r
944 return (PWR->WKUPFR & WakeUpFlag);
\r
948 * @brief Clear the Wake-Up pin flag.
\r
949 * @param WakeUpFlag: Specifies the Wake-Up PIN flag to clear.
\r
950 * This parameter can be one of the following values:
\r
951 * @arg PWR_WAKEUP_FLAG1: Clear the wakeup event received from PA0.
\r
952 * @arg PWR_WAKEUP_FLAG2: Clear the wakeup event received from PA2.
\r
953 * @arg PWR_WAKEUP_FLAG3: Clear the wakeup event received from PC1.
\r
954 * @arg PWR_WAKEUP_FLAG4: Clear the wakeup event received from PC13.
\r
955 * @arg PWR_WAKEUP_FLAG5: Clear the wakeup event received from PI8.
\r
956 * @arg PWR_WAKEUP_FLAG6: Clear the wakeup event received from PI11.
\r
957 * @retval HAL status.
\r
959 HAL_StatusTypeDef HAL_PWREx_ClearWakeupFlag(uint32_t WakeUpFlag)
\r
961 /* Check the parameters */
\r
962 assert_param(IS_PWR_WAKEUP_FLAG(WakeUpFlag));
\r
964 SET_BIT(PWR->WKUPCR, WakeUpFlag);
\r
966 if((PWR->WKUPFR & WakeUpFlag) != 0U)
\r
975 * @brief This function handles the PWR WAKEUP PIN interrupt request.
\r
976 * @note This API should be called under the WAKEUP_PIN_IRQHandler().
\r
979 void HAL_PWREx_WAKEUP_PIN_IRQHandler(void)
\r
981 /* Wakeup pin EXTI line interrupt detected */
\r
982 if(READ_BIT(PWR->WKUPFR, PWR_WKUPFR_WKUPF1) != 0U)
\r
984 /* Clear PWR WKUPF1 flag */
\r
985 SET_BIT(PWR->WKUPCR, PWR_WKUPCR_WKUPC1);
\r
987 /* PWR WKUP1 interrupt user callback */
\r
988 HAL_PWREx_WKUP1_Callback();
\r
990 else if(READ_BIT(PWR->WKUPFR, PWR_WKUPFR_WKUPF2) != 0U)
\r
992 /* Clear PWR WKUPF2 flag */
\r
993 SET_BIT(PWR->WKUPCR, PWR_WKUPCR_WKUPC2);
\r
995 /* PWR WKUP2 interrupt user callback */
\r
996 HAL_PWREx_WKUP2_Callback();
\r
998 else if(READ_BIT(PWR->WKUPFR, PWR_WKUPFR_WKUPF3) != 0U)
\r
1000 /* Clear PWR WKUPF3 flag */
\r
1001 SET_BIT(PWR->WKUPCR, PWR_WKUPCR_WKUPC3);
\r
1003 /* PWR WKUP3 interrupt user callback */
\r
1004 HAL_PWREx_WKUP3_Callback();
\r
1006 else if(READ_BIT(PWR->WKUPFR, PWR_WKUPFR_WKUPF4) != 0U)
\r
1008 /* Clear PWR WKUPF4 flag */
\r
1009 SET_BIT(PWR->WKUPCR, PWR_WKUPCR_WKUPC4);
\r
1011 /* PWR WKUP4 interrupt user callback */
\r
1012 HAL_PWREx_WKUP4_Callback();
\r
1014 else if(READ_BIT(PWR->WKUPFR, PWR_WKUPFR_WKUPF5) != 0U)
\r
1016 /* Clear PWR WKUPF5 flag */
\r
1017 SET_BIT(PWR->WKUPCR, PWR_WKUPCR_WKUPC5);
\r
1019 /* PWR WKUP5 interrupt user callback */
\r
1020 HAL_PWREx_WKUP5_Callback();
\r
1024 /* Clear PWR WKUPF6 flag */
\r
1025 SET_BIT(PWR->WKUPCR, PWR_WKUPCR_WKUPC6);
\r
1027 /* PWR WKUP6 interrupt user callback */
\r
1028 HAL_PWREx_WKUP6_Callback();
\r
1033 * @brief PWR WKUP1 interrupt callback
\r
1036 __weak void HAL_PWREx_WKUP1_Callback(void)
\r
1038 /* NOTE : This function Should not be modified, when the callback is needed,
\r
1039 the HAL_PWREx_WKUP1Callback could be implemented in the user file
\r
1044 * @brief PWR WKUP2 interrupt callback
\r
1047 __weak void HAL_PWREx_WKUP2_Callback(void)
\r
1049 /* NOTE : This function Should not be modified, when the callback is needed,
\r
1050 the HAL_PWREx_WKUP2Callback could be implemented in the user file
\r
1055 * @brief PWR WKUP3 interrupt callback
\r
1058 __weak void HAL_PWREx_WKUP3_Callback(void)
\r
1060 /* NOTE : This function Should not be modified, when the callback is needed,
\r
1061 the HAL_PWREx_WKUP3Callback could be implemented in the user file
\r
1066 * @brief PWR WKUP4 interrupt callback
\r
1069 __weak void HAL_PWREx_WKUP4_Callback(void)
\r
1071 /* NOTE : This function Should not be modified, when the callback is needed,
\r
1072 the HAL_PWREx_WKUP4Callback could be implemented in the user file
\r
1077 * @brief PWR WKUP5 interrupt callback
\r
1080 __weak void HAL_PWREx_WKUP5_Callback(void)
\r
1082 /* NOTE : This function Should not be modified, when the callback is needed,
\r
1083 the HAL_PWREx_WKUP5Callback could be implemented in the user file
\r
1088 * @brief PWR WKUP6 interrupt callback
\r
1091 __weak void HAL_PWREx_WKUP6_Callback(void)
\r
1093 /* NOTE : This function Should not be modified, when the callback is needed,
\r
1094 the HAL_PWREx_WKUP6Callback could be implemented in the user file
\r
1102 /** @defgroup PWREx_Exported_Functions_Group3 Peripherals control functions
\r
1103 * @brief Peripherals control functions
\r
1107 ===============================================================================
\r
1108 ##### Peripherals control functions #####
\r
1109 ===============================================================================
\r
1111 *** Main and Backup Regulators configuration ***
\r
1112 ================================================
\r
1114 (+) The backup domain includes 4 Kbytes of backup SRAM accessible only from
\r
1115 the CPU, and address in 32-bit, 16-bit or 8-bit mode. Its content is
\r
1116 retained even in Standby or VBAT mode when the low power backup regulator
\r
1117 is enabled. It can be considered as an internal EEPROM when VBAT is
\r
1118 always present. You can use the HAL_PWREx_EnableBkUpReg() function to
\r
1119 enable the low power backup regulator.
\r
1120 (+) When the backup domain is supplied by VDD (analog switch connected to VDD)
\r
1121 the backup SRAM is powered from VDD which replaces the VBAT power supply to
\r
1122 save battery life.
\r
1123 (+) The backup SRAM is not mass erased by a tamper event. It is read
\r
1124 protected to prevent confidential data, such as cryptographic private
\r
1125 key, from being accessed. The backup SRAM can be erased only through
\r
1126 the Flash interface when a protection level change from level 1 to
\r
1127 level 0 is requested.
\r
1128 -@- Refer to the description of Read protection (RDP) in the Flash
\r
1129 programming manual.
\r
1130 (+) The main internal regulator can be configured to have a tradeoff between
\r
1131 performance and power consumption when the device does not operate at
\r
1132 the maximum frequency. This is done through HAL_PWREx_ControlVoltageScaling(VOS)
\r
1133 function which configure the VOS bit in PWR_D3CR register.
\r
1134 (+) The main internal regulator can be configured to operate in Low Power mode
\r
1135 when the system enter STOP mode to further reduce power consumption.
\r
1136 This is done through HAL_PWREx_ControlStopModeVoltageScaling(SVOS)
\r
1137 function which configure the SVOS bit in PWR_CR1 register.
\r
1138 The selected SVOS4 and SVOS5 levels add an additional startup delay when exiting from
\r
1140 -@- Refer to the product datasheets for more details.
\r
1142 *** USB Regulator configuration ***
\r
1143 ===================================
\r
1145 (+) The USB transceivers are supplied from a dedicated VDD33USB supply that can be
\r
1146 provided either by the integrated USB regulator, or by an external USB supply.
\r
1147 (+) The USB regulator is enabled by HAL_PWREx_EnableUSBReg() function, the VDD33USB
\r
1148 is then provided from the USB regulator.
\r
1149 (+) When the USB regulator is enabled, the VDD33USB supply level detector shall
\r
1150 be enabled through HAL_PWREx_EnableUSBVoltageDetector() function.
\r
1151 (+) The USB regulator is disabled through HAL_PWREx_DisableUSBReg() function and VDD33USB
\r
1152 can be provided from an external supply. In this case VDD33USB and VDD50USB shall
\r
1153 be connected together
\r
1155 *** VBAT battery charging ***
\r
1156 =============================
\r
1158 (+) When VDD is present, the external battery connected to VBAT can be charged through an
\r
1159 internal resistance. VBAT charging can be performed either through a 5 KOhm resistor
\r
1160 or through a 1.5 KOhm resistor.
\r
1161 (+) VBAT charging is enabled by HAL_PWREx_EnableBatteryCharging(ResistorValue) function
\r
1163 (++) ResistorValue:
\r
1164 (+++) PWR_BATTERY_CHARGING_RESISTOR_5: 5 KOhm resistor.
\r
1165 (+++) PWR_BATTERY_CHARGING_RESISTOR_1_5: 1.5 KOhm resistor.
\r
1166 (+) VBAT charging is disabled by HAL_PWREx_DisableBatteryCharging() function.
\r
1173 * @brief Enable the Backup Regulator.
\r
1174 * @retval HAL status
\r
1176 HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg(void)
\r
1178 uint32_t tickstart;
\r
1180 /* Enable the Backup regulator */
\r
1181 SET_BIT(PWR->CR2, PWR_CR2_BREN);
\r
1184 tickstart = HAL_GetTick();
\r
1186 /* Wait till Backup regulator ready flag is set */
\r
1187 while(!__HAL_PWR_GET_FLAG(PWR_FLAG_BRR))
\r
1189 if((HAL_GetTick() - tickstart ) > PWR_FLAG_SETTING_DELAY_US)
\r
1191 return HAL_TIMEOUT;
\r
1198 * @brief Disable the Backup Regulator.
\r
1199 * @retval HAL status
\r
1201 HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg(void)
\r
1203 uint32_t tickstart;
\r
1205 /* Disable the Backup regulator */
\r
1206 CLEAR_BIT(PWR->CR2, PWR_CR2_BREN);
\r
1209 tickstart = HAL_GetTick();
\r
1211 /* Wait till Backup regulator ready flag is reset */
\r
1212 while(__HAL_PWR_GET_FLAG(PWR_FLAG_BRR) != RESET)
\r
1214 if((HAL_GetTick() - tickstart ) > PWR_FLAG_SETTING_DELAY_US)
\r
1216 return HAL_TIMEOUT;
\r
1223 * @brief Enable the USB Regulator.
\r
1224 * @retval HAL status
\r
1226 HAL_StatusTypeDef HAL_PWREx_EnableUSBReg(void)
\r
1228 uint32_t tickstart;
\r
1230 /* Enable the USB regulator */
\r
1231 SET_BIT(PWR->CR3, PWR_CR3_USBREGEN);
\r
1234 tickstart = HAL_GetTick();
\r
1236 /* Wait till the USB regulator ready flag is set */
\r
1237 while(READ_BIT(PWR->CR3, PWR_CR3_USB33RDY) == 0U)
\r
1239 if((HAL_GetTick() - tickstart ) > PWR_FLAG_SETTING_DELAY_US)
\r
1241 return HAL_TIMEOUT;
\r
1249 * @brief Disable the USB Regulator.
\r
1250 * @retval HAL status
\r
1252 HAL_StatusTypeDef HAL_PWREx_DisableUSBReg(void)
\r
1254 uint32_t tickstart;
\r
1256 /* Disable the USB regulator */
\r
1257 CLEAR_BIT(PWR->CR3, PWR_CR3_USBREGEN);
\r
1260 tickstart = HAL_GetTick();
\r
1262 /* Wait till the USB regulator ready flag is reset */
\r
1263 while(READ_BIT(PWR->CR3, PWR_CR3_USB33RDY) != 0U)
\r
1265 if((HAL_GetTick() - tickstart ) > PWR_FLAG_SETTING_DELAY_US)
\r
1267 return HAL_TIMEOUT;
\r
1274 * @brief Enable the USB voltage level detector.
\r
1277 void HAL_PWREx_EnableUSBVoltageDetector(void)
\r
1279 /* Enable the USB voltage detector */
\r
1280 SET_BIT(PWR->CR3, PWR_CR3_USB33DEN);
\r
1284 * @brief Disable the USB voltage level detector.
\r
1287 void HAL_PWREx_DisableUSBVoltageDetector(void)
\r
1289 /* Disable the USB voltage detector */
\r
1290 CLEAR_BIT(PWR->CR3, PWR_CR3_USB33DEN);
\r
1295 * @brief Enable the Battery charging.
\r
1296 * When VDD is present, charge the external battery through an internal resistor.
\r
1297 * @param ResistorValue: Specifies the charging resistor.
\r
1298 * This parameter can be one of the following values:
\r
1299 * @arg PWR_BATTERY_CHARGING_RESISTOR_5: 5 KOhm resistor.
\r
1300 * @arg PWR_BATTERY_CHARGING_RESISTOR_1_5: 1.5 KOhm resistor.
\r
1303 void HAL_PWREx_EnableBatteryCharging(uint32_t ResistorValue)
\r
1305 assert_param(IS_PWR_BATTERY_RESISTOR_SELECT(ResistorValue));
\r
1307 /* Specify the charging resistor */
\r
1308 MODIFY_REG(PWR->CR3, PWR_CR3_VBRS, ResistorValue);
\r
1310 /* Enable the Battery charging */
\r
1311 SET_BIT(PWR->CR3, PWR_CR3_VBE);
\r
1316 * @brief Disable the Battery charging.
\r
1319 void HAL_PWREx_DisableBatteryCharging(void)
\r
1321 /* Disable the Battery charging */
\r
1322 CLEAR_BIT(PWR->CR3, PWR_CR3_VBE);
\r
1329 /** @defgroup PWREx_Exported_Functions_Group4 Power Monitoring functions
\r
1330 * @brief Power Monitoring functions
\r
1334 ===============================================================================
\r
1335 ##### Power Monitoring functions #####
\r
1336 ===============================================================================
\r
1338 *** VBAT and Temperature supervision ***
\r
1339 ========================================
\r
1341 (+) The VBAT battery voltage supply can be monitored by comparing it with two threshold
\r
1342 levels: VBAThigh and VBATlow. VBATH flag and VBATL flags in the PWR control register 2
\r
1343 (PWR_CR2), indicate if VBAT is higher or lower than the threshold.
\r
1344 (+) The temperature can be monitored by comparing it with two threshold levels, TEMPhigh
\r
1345 and TEMPlow. TEMPH and TEMPL flags, in the PWR control register 2 (PWR_CR2),
\r
1346 indicate whether the device temperature is higher or lower than the threshold.
\r
1347 (+) The VBAT and the temperature monitoring is enabled by HAL_PWREx_EnableMonitoring()
\r
1348 function and disabled by HAL_PWREx_DisableMonitoring() function.
\r
1349 (+) The HAL_PWREx_GetVBATLevel() function return the VBAT level which can be:
\r
1350 PWR_VBAT_BELOW_LOW_THRESHOLD or PWR_VBAT_ABOVE_HIGH_THRESHOLD or
\r
1351 PWR_VBAT_BETWEEN_HIGH_LOW_THRESHOLD.
\r
1352 (+) The HAL_PWREx_GetTemperatureLevel() function return the Temperature level which
\r
1353 can be: PWR_TEMP_BELOW_LOW_THRESHOLD or PWR_TEMP_ABOVE_HIGH_THRESHOLD or
\r
1354 PWR_TEMP_BETWEEN_HIGH_LOW_THRESHOLD.
\r
1356 *** AVD configuration ***
\r
1357 =========================
\r
1359 (+) The AVD is used to monitor the VDDA power supply by comparing it to a
\r
1360 threshold selected by the AVD Level (ALS[3:0] bits in the PWR_CR1 register).
\r
1361 (+) A AVDO flag is available to indicate if VDDA is higher or lower
\r
1362 than the AVD threshold. This event is internally connected to the EXTI
\r
1363 line 16 to generate an interrupt if enabled.
\r
1364 It is configurable through __HAL_PWR_AVD_EXTI_ENABLE_IT() macro.
\r
1365 (+) The AVD is stopped in System Standby mode.
\r
1372 * @brief Enable the VBAT and temperature monitoring.
\r
1373 * @retval HAL status
\r
1375 void HAL_PWREx_EnableMonitoring(void)
\r
1377 /* Enable the VBAT and Temperature monitoring */
\r
1378 SET_BIT(PWR->CR2, PWR_CR2_MONEN);
\r
1382 * @brief Disable the VBAT and temperature monitoring.
\r
1383 * @retval HAL status
\r
1385 void HAL_PWREx_DisableMonitoring(void)
\r
1387 /* Disable the VBAT and Temperature monitoring */
\r
1388 CLEAR_BIT(PWR->CR2, PWR_CR2_MONEN);
\r
1392 * @brief Indicate whether the junction temperature is between, above or below the threshold.
\r
1393 * @retval Temperature level.
\r
1395 uint32_t HAL_PWREx_GetTemperatureLevel(void)
\r
1397 uint32_t tempLevel;
\r
1398 uint32_t regValue;
\r
1400 /* Read the temperature flags */
\r
1401 regValue = PWR->CR2 & (PWR_CR2_TEMPH | PWR_CR2_TEMPL);
\r
1403 /* Compare the read value to the temperature threshold */
\r
1404 if(regValue == PWR_CR2_TEMPL)
\r
1406 tempLevel = PWR_TEMP_BELOW_LOW_THRESHOLD;
\r
1408 else if(regValue == PWR_CR2_TEMPH)
\r
1410 tempLevel = PWR_TEMP_ABOVE_HIGH_THRESHOLD;
\r
1414 tempLevel = PWR_TEMP_BETWEEN_HIGH_LOW_THRESHOLD;
\r
1421 * @brief Indicate whether the Battery voltage level is between, above or below the threshold.
\r
1422 * @retval VBAT level.
\r
1424 uint32_t HAL_PWREx_GetVBATLevel(void)
\r
1426 uint32_t VBATLevel;
\r
1427 uint32_t regValue;
\r
1429 /* Read the VBAT flags */
\r
1430 regValue = PWR->CR2 & (PWR_CR2_VBATH | PWR_CR2_VBATL);
\r
1432 /* Compare the read value to the VBAT threshold */
\r
1433 if(regValue == PWR_CR2_VBATL)
\r
1435 VBATLevel = PWR_VBAT_BELOW_LOW_THRESHOLD;
\r
1437 else if(regValue == PWR_CR2_VBATH)
\r
1439 VBATLevel = PWR_VBAT_ABOVE_HIGH_THRESHOLD;
\r
1443 VBATLevel = PWR_VBAT_BETWEEN_HIGH_LOW_THRESHOLD;
\r
1450 * @brief Configure the analog voltage threshold detected by the Analog Voltage Detector(AVD).
\r
1451 * @param sConfigAVD: pointer to an PWR_AVDTypeDef structure that contains the configuration
\r
1452 * information for the AVD.
\r
1453 * @note Refer to the electrical characteristics of your device datasheet for more details
\r
1454 * about the voltage threshold corresponding to each detection level.
\r
1457 void HAL_PWREx_ConfigAVD(PWREx_AVDTypeDef *sConfigAVD)
\r
1459 /* Check the parameters */
\r
1460 assert_param(IS_PWR_AVD_LEVEL(sConfigAVD->AVDLevel));
\r
1461 assert_param(IS_PWR_AVD_MODE(sConfigAVD->Mode));
\r
1463 /* Set the ALS[18:17] bits according to AVDLevel value */
\r
1464 MODIFY_REG(PWR->CR1, PWR_CR1_ALS, sConfigAVD->AVDLevel);
\r
1466 /* Clear any previous config */
\r
1467 #if !defined (DUAL_CORE)
\r
1468 __HAL_PWR_AVD_EXTI_DISABLE_EVENT();
\r
1469 __HAL_PWR_AVD_EXTI_DISABLE_IT();
\r
1471 __HAL_PWR_AVD_EXTI_DISABLE_RISING_EDGE();
\r
1472 __HAL_PWR_AVD_EXTI_DISABLE_FALLING_EDGE();
\r
1474 #if !defined (DUAL_CORE)
\r
1475 /* Configure the interrupt mode */
\r
1476 if(AVD_MODE_IT == (sConfigAVD->Mode & AVD_MODE_IT))
\r
1478 __HAL_PWR_AVD_EXTI_ENABLE_IT();
\r
1481 /* Configure the event mode */
\r
1482 if(AVD_MODE_EVT == (sConfigAVD->Mode & AVD_MODE_EVT))
\r
1484 __HAL_PWR_AVD_EXTI_ENABLE_EVENT();
\r
1487 /* Configure the edge */
\r
1488 if(AVD_RISING_EDGE == (sConfigAVD->Mode & AVD_RISING_EDGE))
\r
1490 __HAL_PWR_AVD_EXTI_ENABLE_RISING_EDGE();
\r
1493 if(AVD_FALLING_EDGE == (sConfigAVD->Mode & AVD_FALLING_EDGE))
\r
1495 __HAL_PWR_AVD_EXTI_ENABLE_FALLING_EDGE();
\r
1500 * @brief Enable the Analog Voltage Detector(AVD).
\r
1503 void HAL_PWREx_EnableAVD(void)
\r
1505 /* Enable the Analog Voltage Detector */
\r
1506 SET_BIT(PWR->CR1, PWR_CR1_AVDEN);
\r
1510 * @brief Disable the Analog Voltage Detector(AVD).
\r
1513 void HAL_PWREx_DisableAVD(void)
\r
1515 /* Disable the Analog Voltage Detector */
\r
1516 CLEAR_BIT(PWR->CR1, PWR_CR1_AVDEN);
\r
1520 * @brief This function handles the PWR PVD/AVD interrupt request.
\r
1521 * @note This API should be called under the PVD_AVD_IRQHandler().
\r
1524 void HAL_PWREx_PVD_AVD_IRQHandler(void)
\r
1526 #if defined(DUAL_CORE)
\r
1527 /* PVD EXTI line interrupt detected */
\r
1528 if(READ_BIT(PWR->CR1, PWR_CR1_PVDEN) != 0U)
\r
1530 if (HAL_GetCurrentCPUID() == CM7_CPUID)
\r
1532 /* Check PWR D1 EXTI flag */
\r
1533 if(__HAL_PWR_PVD_EXTI_GET_FLAG() != RESET)
\r
1535 /* PWR PVD interrupt user callback */
\r
1536 HAL_PWR_PVDCallback();
\r
1538 /* Clear PWR EXTI D1 pending bit */
\r
1539 __HAL_PWR_PVD_EXTI_CLEAR_FLAG();
\r
1544 /* Check PWR EXTI D2 flag */
\r
1545 if(__HAL_PWR_PVD_EXTID2_GET_FLAG() != RESET)
\r
1547 /* PWR PVD interrupt user callback */
\r
1548 HAL_PWR_PVDCallback();
\r
1550 /* Clear PWR EXTI D2 pending bit */
\r
1551 __HAL_PWR_PVD_EXTID2_CLEAR_FLAG();
\r
1556 /* AVD EXTI line interrupt detected */
\r
1557 if(READ_BIT(PWR->CR1, PWR_CR1_AVDEN) != 0U)
\r
1559 if (HAL_GetCurrentCPUID() == CM7_CPUID)
\r
1561 /* Check PWR EXTI D1 flag */
\r
1562 if(__HAL_PWR_AVD_EXTI_GET_FLAG() != RESET)
\r
1564 /* PWR AVD interrupt user callback */
\r
1565 HAL_PWREx_AVDCallback();
\r
1567 /* Clear PWR EXTI D1 pending bit */
\r
1568 __HAL_PWR_AVD_EXTI_CLEAR_FLAG();
\r
1573 /* Check PWR EXTI D2 flag */
\r
1574 if(__HAL_PWR_AVD_EXTID2_GET_FLAG() != RESET)
\r
1576 /* PWR AVD interrupt user callback */
\r
1577 HAL_PWREx_AVDCallback();
\r
1579 /* Clear PWR EXTI D2 pending bit */
\r
1580 __HAL_PWR_AVD_EXTID2_CLEAR_FLAG();
\r
1585 /* PVD EXTI line interrupt detected */
\r
1586 if(READ_BIT(PWR->CR1, PWR_CR1_PVDEN) != 0U)
\r
1588 /* Check PWR EXTI flag */
\r
1589 if(__HAL_PWR_PVD_EXTI_GET_FLAG() != RESET)
\r
1591 /* PWR PVD interrupt user callback */
\r
1592 HAL_PWR_PVDCallback();
\r
1594 /* Clear PWR EXTI pending bit */
\r
1595 __HAL_PWR_PVD_EXTI_CLEAR_FLAG();
\r
1599 /* AVD EXTI line interrupt detected */
\r
1600 if(READ_BIT(PWR->CR1, PWR_CR1_AVDEN) != 0U)
\r
1602 /* Check PWR EXTI flag */
\r
1603 if(__HAL_PWR_AVD_EXTI_GET_FLAG() != RESET)
\r
1605 /* PWR AVD interrupt user callback */
\r
1606 HAL_PWREx_AVDCallback();
\r
1608 /* Clear PWR EXTI pending bit */
\r
1609 __HAL_PWR_AVD_EXTI_CLEAR_FLAG();
\r
1612 #endif /*DUAL_CORE*/
\r
1616 * @brief PWR AVD interrupt callback
\r
1619 __weak void HAL_PWREx_AVDCallback(void)
\r
1621 /* NOTE : This function Should not be modified, when the callback is needed,
\r
1622 the HAL_PWR_AVDCallback could be implemented in the user file
\r
1634 #endif /* HAL_PWR_MODULE_ENABLED */
\r
1644 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r