]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_M4_AMP_STM32H745I_Discovery_IAR/ST_code/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr_ex.c
Add M7/M4 AMP demo.
[freertos] / FreeRTOS / Demo / CORTEX_M7_M4_AMP_STM32H745I_Discovery_IAR / ST_code / STM32H7xx_HAL_Driver / Src / stm32h7xx_hal_pwr_ex.c
1 /**\r
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
9   *\r
10   ******************************************************************************\r
11   * @attention\r
12   *\r
13   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics.\r
14   * All rights reserved.</center></h2>\r
15   *\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
20   *\r
21   ******************************************************************************\r
22   */\r
23 \r
24 /* Includes ------------------------------------------------------------------*/\r
25 #include "stm32h7xx_hal.h"\r
26 \r
27 /** @addtogroup STM32H7xx_HAL_Driver\r
28   * @{\r
29   */\r
30 \r
31 /** @defgroup PWREx PWREx\r
32   * @brief PWR Extended HAL module driver\r
33   * @{\r
34   */\r
35 \r
36 #ifdef HAL_PWR_MODULE_ENABLED\r
37 \r
38 /* Private typedef -----------------------------------------------------------*/\r
39 /* Private define ------------------------------------------------------------*/\r
40 /** @addtogroup PWREx_Private_Constants\r
41   * @{\r
42   */\r
43 \r
44 /** @defgroup PWREx_AVD_Mode_Mask PWR Extended AVD Mode Mask\r
45   * @{\r
46   */\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
52 /**\r
53   * @}\r
54   */\r
55 \r
56 /** @defgroup PWREx_REG_SET_TIMEOUT PWR Extended Flag Setting Time Out Value\r
57   * @{\r
58   */\r
59 #define PWR_FLAG_SETTING_DELAY_US  ((uint32_t)1000U)\r
60 /**\r
61   * @}\r
62   */\r
63 \r
64 /** @defgroup PWREx_WakeUp_Pins_Offsets PWREx Wake-Up Pins masks and offsets\r
65   * @{\r
66   */\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
71 \r
72 /* Wake-Up Pins PWR Pin Pull shift offsets */\r
73 #define PWR_WAKEUP_PINS_PULL_SHIFT_OFFSET      2U\r
74 /**\r
75   * @}\r
76   */\r
77 \r
78 \r
79 /**\r
80   * @}\r
81   */\r
82 \r
83 /* Private macro -------------------------------------------------------------*/\r
84 /* Private variables ---------------------------------------------------------*/\r
85 /* Private function prototypes -----------------------------------------------*/\r
86 /* Private functions ---------------------------------------------------------*/\r
87 /* Exported types ------------------------------------------------------------*/\r
88 \r
89 /* Exported functions --------------------------------------------------------*/\r
90 /** @defgroup PWREx_Exported_Functions PWREx Exported Functions\r
91   * @{\r
92   */\r
93 \r
94 /** @defgroup PWREx_Exported_Functions_Group1 Power supply control functions\r
95   * @brief    Power supply control functions\r
96   *\r
97 @verbatim\r
98 \r
99  ===============================================================================\r
100                  ##### Power supply control functions #####\r
101  ===============================================================================\r
102 \r
103     *** Power supply configuration ***\r
104     ==================================\r
105     [..]\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
108       configuration:\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
117        (++) SupplySource:\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
120                               modes.\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
128             not be changed.\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
131 \r
132 @endverbatim\r
133   * @{\r
134   */\r
135 \r
136 #if defined(SMPS)\r
137 /**\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
143   *\r
144   *            @arg PWR_DIRECT_SMPS_SUPPLY              The SMPS supplies the Vcore Power Domains.\r
145   *                                                     The LDO is Bypassed.\r
146   *\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
149   *\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
152   *\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
155   *\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
158   *\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
162   *\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
166   *\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
170   */\r
171 HAL_StatusTypeDef HAL_PWREx_ConfigSupply(uint32_t SupplySource)\r
172 {\r
173   uint32_t tickstart;\r
174 \r
175   /* Check the parameters */\r
176   assert_param(IS_PWR_SUPPLY(SupplySource));\r
177 \r
178   if((PWR->CR3 & (PWR_CR3_SMPSEN | PWR_CR3_LDOEN | PWR_CR3_BYPASS)) != (PWR_CR3_SMPSEN | PWR_CR3_LDOEN))\r
179   {\r
180     if((PWR->CR3 & PWR_SUPPLY_CONFIG_MASK) != SupplySource)\r
181     {\r
182       /* Supply configuration update locked, can't apply a new regulator config */\r
183       return HAL_ERROR;\r
184     }\r
185   }\r
186 \r
187   /* Set the power supply configuration */\r
188   MODIFY_REG(PWR->CR3, PWR_SUPPLY_CONFIG_MASK, SupplySource);\r
189 \r
190   /* Get tick */\r
191   tickstart = HAL_GetTick();\r
192 \r
193   /* Wait till voltage level flag is set */\r
194   while(!__HAL_PWR_GET_FLAG(PWR_FLAG_ACTVOSRDY))\r
195   {\r
196     if((HAL_GetTick() - tickstart ) > PWR_FLAG_SETTING_DELAY_US)\r
197     {\r
198       return HAL_TIMEOUT;\r
199     }\r
200   }\r
201 \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
207   {\r
208     /* Get tick */\r
209     tickstart = HAL_GetTick();\r
210 \r
211     /* Wait till SMPS external supply ready flag is set */\r
212     while(!__HAL_PWR_GET_FLAG(PWR_FLAG_SMPSEXTRDY))\r
213     {\r
214       if((HAL_GetTick() - tickstart ) > PWR_FLAG_SETTING_DELAY_US)\r
215       {\r
216         return HAL_TIMEOUT;\r
217       }\r
218     }\r
219   }\r
220 \r
221   return HAL_OK;\r
222 }\r
223 #else\r
224 /**\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
229   *\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
233   */\r
234 HAL_StatusTypeDef HAL_PWREx_ConfigSupply(uint32_t SupplySource)\r
235 {\r
236   uint32_t tickstart;\r
237 \r
238   /* Check the parameters */\r
239   assert_param(IS_PWR_SUPPLY(SupplySource));\r
240 \r
241   if(!__HAL_PWR_GET_FLAG(PWR_FLAG_SCUEN))\r
242   {\r
243     if((PWR->CR3 & PWR_SUPPLY_CONFIG_MASK) != SupplySource)\r
244     {\r
245       /* Supply configuration update locked, can't apply a new regulator config */\r
246       return HAL_ERROR;\r
247     }\r
248   }\r
249 \r
250   /* Set the power supply configuration */\r
251   MODIFY_REG(PWR->CR3, PWR_SUPPLY_CONFIG_MASK, SupplySource);\r
252 \r
253   /* Get tick */\r
254   tickstart = HAL_GetTick();\r
255 \r
256   /* Wait till voltage level flag is set */\r
257   while(!__HAL_PWR_GET_FLAG(PWR_FLAG_ACTVOSRDY))\r
258   {\r
259     if((HAL_GetTick() - tickstart ) > PWR_FLAG_SETTING_DELAY_US)\r
260     {\r
261       return HAL_TIMEOUT;\r
262     }\r
263   }\r
264 \r
265   return HAL_OK;\r
266 }\r
267 #endif /*SMPS*/\r
268 \r
269 \r
270 /**\r
271   * @brief  Get the power supply configuration.\r
272   * @retval The supply configuration.\r
273   */\r
274 uint32_t  HAL_PWREx_GetSupplyConfig(void)\r
275 {\r
276   return (PWR->CR3 & PWR_SUPPLY_CONFIG_MASK);\r
277 }\r
278 \r
279 /**\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
295   */\r
296 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling)\r
297 {\r
298   uint32_t tickstart;\r
299 \r
300   assert_param(IS_PWR_REGULATOR_VOLTAGE(VoltageScaling));\r
301 \r
302   /* Set the voltage range */\r
303   MODIFY_REG(PWR->D3CR, PWR_D3CR_VOS, VoltageScaling);\r
304 \r
305   /* Get tick */\r
306   tickstart = HAL_GetTick();\r
307 \r
308   /* Wait until the VOSRDY flag is set */\r
309   while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY))\r
310   {\r
311     if((HAL_GetTick() - tickstart ) > PWR_FLAG_SETTING_DELAY_US)\r
312     {\r
313       return HAL_TIMEOUT;\r
314     }\r
315   }\r
316 \r
317   return HAL_OK;\r
318 }\r
319 \r
320 /**\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
324   */\r
325 uint32_t  HAL_PWREx_GetVoltageRange(void)\r
326 {\r
327   return (PWR->CSR1 & PWR_CSR1_ACTVOS);\r
328 }\r
329 \r
330 /**\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
345   */\r
346 HAL_StatusTypeDef HAL_PWREx_ControlStopModeVoltageScaling(uint32_t VoltageScaling)\r
347 {\r
348   assert_param(IS_PWR_STOP_MODE_REGULATOR_VOLTAGE(VoltageScaling));\r
349 \r
350   /* Set the stop mode voltage range */\r
351   MODIFY_REG(PWR->CR1, PWR_CR1_SVOS, VoltageScaling);\r
352 \r
353   return HAL_OK;\r
354 }\r
355 \r
356 /**\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
359   */\r
360 uint32_t  HAL_PWREx_GetStopModeVoltageRange(void)\r
361 {\r
362   return (PWR->CR1 & PWR_CR1_SVOS);\r
363 }\r
364 \r
365 /**\r
366   * @}\r
367   */\r
368 \r
369 /** @defgroup PWREx_Exported_Functions_Group2 Low power control functions\r
370   * @brief    Low power control functions\r
371   *\r
372 @verbatim\r
373 \r
374  ===============================================================================\r
375                  ##### Low power control functions #####\r
376  ===============================================================================\r
377 \r
378     *** Domains Low Power modes configuration ***\r
379     =============================================\r
380     [..]\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
383 \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
400 \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
406 \r
407    *** DSTOP mode ***\r
408    ==================\r
409     [..]\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
413       power consumption.\r
414     [..]\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
417     [..]\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
420 \r
421       (+) Entry:\r
422          The DSTOP mode is entered using the HAL_PWREx_EnterSTOPMode(Regulator, STOPEntry, Domain)\r
423          function with:\r
424          (++) Regulator:\r
425           (+++) PWR_MAINREGULATOR_ON: Main regulator ON.\r
426           (+++) PWR_LOWPOWERREGULATOR_ON: Low Power regulator ON.\r
427          (++) STOPEntry:\r
428           (+++) PWR_STOPENTRY_WFI: enter STOP mode with WFI instruction\r
429           (+++) PWR_STOPENTRY_WFE: enter STOP mode with WFE instruction\r
430          (++) Domain:\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
434 \r
435       (+) Exit:\r
436         Any EXTI Line (Internal or External) configured in Interrupt/Event mode.\r
437 \r
438    *** DSTANDBY mode ***\r
439    ====================\r
440     [..]\r
441       In DStandby mode:\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
444     [..]\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
447 \r
448       (+) Entry:\r
449          The DSTANDBY mode is entered using the HAL_PWREx_EnterSTANDBYMode(Domain) function with:\r
450        (++) Domain:\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
454 \r
455       (+) Exit:\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
458 \r
459    *** Keep D3 in RUN mode ***\r
460    ===========================\r
461     [..]\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
464        (+) D3State:\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
467 \r
468     *** FLASH Power Down configuration ****\r
469     =======================================\r
470     [..]\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
475 \r
476     *** Wakeup Pins configuration ****\r
477     ===================================\r
478     [..]\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
485     [..]\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
489     [..]\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
494 \r
495 @endverbatim\r
496   * @{\r
497   */\r
498 \r
499 /**\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
506   *         DStandby mode.\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
525   * @retval None\r
526   */\r
527 void HAL_PWREx_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry, uint32_t Domain)\r
528 {\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
533 \r
534   /* Select the regulator state in Stop mode */\r
535   MODIFY_REG(PWR->CR1, PWR_CR1_LPDS, Regulator);\r
536 \r
537   /* Select the domain Power Down DeepSleep */\r
538   if (Domain == PWR_D1_DOMAIN)\r
539   {\r
540     /* Check Core */\r
541     assert_param(IS_PWR_D1_CPU(HAL_GetCurrentCPUID()));\r
542 \r
543     /* Keep DSTOP mode when D1 domain enters Deepsleep */\r
544     CLEAR_BIT(PWR->CPUCR, PWR_CPUCR_PDDS_D1);\r
545 \r
546 #if defined(DUAL_CORE)\r
547     CLEAR_BIT(PWR->CPU2CR, PWR_CPU2CR_PDDS_D1);\r
548 #endif /*DUAL_CORE*/\r
549 \r
550     /* Set SLEEPDEEP bit of Cortex System Control Register */\r
551     SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;\r
552 \r
553     /* Ensure that all instructions done before entering STOP mode */\r
554     __DSB();\r
555     __ISB();\r
556 \r
557     /* Select Stop mode entry */\r
558     if(STOPEntry == PWR_STOPENTRY_WFI)\r
559     {\r
560       /* Request Wait For Interrupt */\r
561       __WFI();\r
562     }\r
563     else\r
564     {\r
565       /* Request Wait For Event */\r
566       __WFE();\r
567     }\r
568 \r
569     /* Reset SLEEPDEEP bit of Cortex System Control Register */\r
570     SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);\r
571   }\r
572   else if (Domain == PWR_D2_DOMAIN)\r
573   {\r
574     /* Keep DSTOP mode when D2 domain enters Deepsleep */\r
575     CLEAR_BIT(PWR->CPUCR, PWR_CPUCR_PDDS_D2);\r
576 \r
577 #if defined(DUAL_CORE)\r
578     /* Check Core */\r
579     assert_param(IS_PWR_D2_CPU(HAL_GetCurrentCPUID()));\r
580 \r
581     CLEAR_BIT(PWR->CPU2CR, PWR_CPU2CR_PDDS_D2);\r
582 \r
583     /* Set SLEEPDEEP bit of Cortex System Control Register */\r
584     SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;\r
585 \r
586     /* Ensure that all instructions done before entering STOP mode */\r
587     __DSB();\r
588     __ISB();\r
589 \r
590     /* Select Stop mode entry */\r
591     if(STOPEntry == PWR_STOPENTRY_WFI)\r
592     {\r
593       /* Request Wait For Interrupt */\r
594       __WFI();\r
595     }\r
596     else\r
597     {\r
598       /* Request Wait For Event */\r
599       __WFE();\r
600     }\r
601 \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
605   }\r
606   else\r
607   {\r
608     /* Keep DSTOP mode when D3 domain enters Deepsleep */\r
609     CLEAR_BIT(PWR->CPUCR, PWR_CPUCR_PDDS_D3);\r
610 \r
611 #if defined(DUAL_CORE)\r
612     CLEAR_BIT(PWR->CPU2CR, PWR_CPU2CR_PDDS_D3);\r
613 #endif /*DUAL_CORE*/\r
614   }\r
615 }\r
616 \r
617 \r
618 /**\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
622   * @retval None\r
623   */\r
624 void HAL_PWREx_ClearPendingEvent(void)\r
625 {\r
626 #if defined(DUAL_CORE)\r
627   /* Check Core */\r
628   if(HAL_GetCurrentCPUID() == CM7_CPUID)\r
629   {\r
630     __WFE();\r
631   }\r
632   else\r
633   {\r
634     __SEV();\r
635     __WFE();\r
636   }\r
637 #else\r
638   __WFE();\r
639 #endif /*DUAL_CORE*/\r
640 \r
641 }\r
642 \r
643 /**\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
647   *         is disabled.\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
652   *         DStandby.\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
660   * @retval None\r
661   */\r
662 void HAL_PWREx_EnterSTANDBYMode(uint32_t Domain)\r
663 {\r
664   /* Check the parameters */\r
665   assert_param(IS_PWR_DOMAIN(Domain));\r
666 \r
667   /* Select the domain Power Down DeepSleep */\r
668   if (Domain == PWR_D1_DOMAIN)\r
669   {\r
670     /* Check Core */\r
671     assert_param(IS_PWR_D1_CPU(HAL_GetCurrentCPUID()));\r
672 \r
673     /* Allow DSTANDBY mode when D1 domain enters Deepsleep */\r
674     SET_BIT(PWR-> CPUCR, PWR_CPUCR_PDDS_D1);\r
675 \r
676 #if defined(DUAL_CORE)\r
677     SET_BIT(PWR-> CPU2CR, PWR_CPU2CR_PDDS_D1);\r
678 #endif /*DUAL_CORE*/\r
679 \r
680     /* Set SLEEPDEEP bit of Cortex System Control Register */\r
681     SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;\r
682 \r
683     /* This option is used to ensure that store operations are completed */\r
684 #if defined ( __CC_ARM)\r
685     __force_stores();\r
686 #endif\r
687 \r
688     /* Request Wait For Interrupt */\r
689     __WFI();\r
690   }\r
691   else if (Domain == PWR_D2_DOMAIN)\r
692   {\r
693     /* Allow DSTANDBY mode when D2 domain enters Deepsleep */\r
694     SET_BIT(PWR-> CPUCR, PWR_CPUCR_PDDS_D2);\r
695 \r
696 #if defined(DUAL_CORE)\r
697     /* Check Core */\r
698     assert_param(IS_PWR_D2_CPU(HAL_GetCurrentCPUID()));\r
699 \r
700     SET_BIT(PWR-> CPU2CR, PWR_CPU2CR_PDDS_D2);\r
701 \r
702     /* Set SLEEPDEEP bit of Cortex System Control Register */\r
703     SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;\r
704 \r
705     /* This option is used to ensure that store operations are completed */\r
706 #if defined ( __CC_ARM)\r
707     __force_stores();\r
708 #endif\r
709 \r
710     /* Request Wait For Interrupt */\r
711     __WFI();\r
712 #endif /*DUAL_CORE*/\r
713   }\r
714   else\r
715   {\r
716     /* Allow DSTANDBY mode when D3 domain enters Deepsleep */\r
717     SET_BIT(PWR-> CPUCR, PWR_CPUCR_PDDS_D3);\r
718 \r
719 #if defined(DUAL_CORE)\r
720     SET_BIT(PWR-> CPU2CR, PWR_CPU2CR_PDDS_D3);\r
721 #endif /*DUAL_CORE*/\r
722   }\r
723 }\r
724 \r
725 /**\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
732   * @retval None\r
733   */\r
734 void HAL_PWREx_ConfigD3Domain(uint32_t D3State)\r
735 {\r
736   /* Check the parameters */\r
737   assert_param(IS_D3_STATE(D3State));\r
738 \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
744 }\r
745 \r
746 #if defined(DUAL_CORE)\r
747 /**\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
753   * @retval None.\r
754   */\r
755 void HAL_PWREx_ClearDomainFlags(uint32_t DomainFlags)\r
756 {\r
757   /* Check the parameters */\r
758   assert_param(IS_PWR_DOMAIN_FLAG(DomainFlags));\r
759 \r
760   if (DomainFlags == PWR_D1_DOMAIN_FLAGS)\r
761   {\r
762     /* Clear D1 domain flags (HOLD2F, STOPF, SBF, SBF_D1, and SBF_D2) */\r
763     SET_BIT(PWR->CPUCR, PWR_CPUCR_CSSF);\r
764   }\r
765   else\r
766   {\r
767     /* Clear D2 domain flags (HOLD2F, STOPF, SBF, SBF_D1, and SBF_D2) */\r
768     SET_BIT(PWR->CPU2CR, PWR_CPU2CR_CSSF);\r
769   }\r
770 }\r
771 #endif /*DUAL_CORE*/\r
772 \r
773 #if defined(DUAL_CORE)\r
774 /**\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
781   */\r
782 HAL_StatusTypeDef HAL_PWREx_HoldCore(uint32_t CPU)\r
783 {\r
784   HAL_StatusTypeDef status = HAL_OK;\r
785 \r
786   /* Check the parameters */\r
787   assert_param(IS_PWR_CORE(CPU));\r
788 \r
789   if (PWR_CORE_CPU2 == CPU)\r
790   {\r
791     /* If CPU1 is not held */\r
792     if(PWR_CPU2CR_HOLD1 != (PWR->CPU2CR & PWR_CPU2CR_HOLD1))\r
793     {\r
794       /* Set HOLD2 bit */\r
795       SET_BIT(PWR->CPUCR, PWR_CPUCR_HOLD2);\r
796     }\r
797     else\r
798     {\r
799       status = HAL_ERROR;\r
800     }\r
801   }\r
802   else if (PWR_CORE_CPU1 == CPU)\r
803   {\r
804     /* If CPU2 is not held */\r
805     if(PWR_CPUCR_HOLD2 != (PWR->CPUCR & PWR_CPUCR_HOLD2))\r
806     {\r
807       /* Set HOLD1 bit */\r
808       SET_BIT(PWR->CPU2CR, PWR_CPU2CR_HOLD1);\r
809     }\r
810     else\r
811     {\r
812       status = HAL_ERROR;\r
813     }\r
814   }\r
815   else\r
816   {\r
817     status = HAL_ERROR;\r
818   }\r
819 \r
820   return status;\r
821 }\r
822 #endif /*DUAL_CORE*/\r
823 \r
824 \r
825 #if defined(DUAL_CORE)\r
826 /**\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
832   * @retval None\r
833   */\r
834 void HAL_PWREx_ReleaseCore(uint32_t CPU)\r
835 {\r
836   /* Check the parameters */\r
837   assert_param(IS_PWR_CORE(CPU));\r
838 \r
839   if (PWR_CORE_CPU2 == CPU)\r
840   {\r
841     /* Reset HOLD2 bit */\r
842     CLEAR_BIT(PWR->CPUCR, PWR_CPUCR_HOLD2);\r
843   }\r
844   else\r
845   {\r
846     /* Reset HOLD1 bit */\r
847     CLEAR_BIT(PWR->CPU2CR, PWR_CPU2CR_HOLD1);\r
848   }\r
849 }\r
850 #endif /*DUAL_CORE*/\r
851 \r
852 /**\r
853   * @brief  Enable the Flash Power Down in Stop mode.\r
854   * @retval None\r
855   */\r
856 void HAL_PWREx_EnableFlashPowerDown(void)\r
857 {\r
858   /* Enable the Flash Power Down */\r
859   SET_BIT(PWR->CR1, PWR_CR1_FLPS);\r
860 }\r
861 \r
862 /**\r
863   * @brief  Disable the Flash Power Down in Stop mode.\r
864   * @retval None\r
865   */\r
866 void HAL_PWREx_DisableFlashPowerDown(void)\r
867 {\r
868   /* Disable the Flash Power Down */\r
869   CLEAR_BIT(PWR->CR1, PWR_CR1_FLPS);\r
870 }\r
871 \r
872 /**\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
876   * @retval None\r
877   */\r
878 void HAL_PWREx_EnableWakeUpPin(PWREx_WakeupPinTypeDef *sPinParams)\r
879 {\r
880   uint32_t pinConfig;\r
881   uint32_t regMask;\r
882   const uint32_t pullMask = PWR_WKUPEPR_WKUPPUPD1;\r
883 \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
888 \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
892 \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
896 \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
900 #ifndef DUAL_CORE\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
903 #endif\r
904 }\r
905 \r
906 /**\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
916   * @retval None\r
917   */\r
918 void HAL_PWREx_DisableWakeUpPin(uint32_t WakeUpPin)\r
919 {\r
920   /* Check the parameters */\r
921   assert_param(IS_PWR_WAKEUP_PIN(WakeUpPin));\r
922 \r
923   /* Disable the WakeUpPin */\r
924   CLEAR_BIT(PWR->WKUPEPR, WakeUpPin);\r
925 }\r
926 \r
927 /**\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
938   */\r
939 uint32_t  HAL_PWREx_GetWakeupFlag(uint32_t WakeUpFlag)\r
940 {\r
941   /* Check the parameters */\r
942   assert_param(IS_PWR_WAKEUP_FLAG(WakeUpFlag));\r
943 \r
944   return (PWR->WKUPFR & WakeUpFlag);\r
945 }\r
946 \r
947 /**\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
958   */\r
959 HAL_StatusTypeDef HAL_PWREx_ClearWakeupFlag(uint32_t WakeUpFlag)\r
960 {\r
961   /* Check the parameters */\r
962   assert_param(IS_PWR_WAKEUP_FLAG(WakeUpFlag));\r
963 \r
964   SET_BIT(PWR->WKUPCR, WakeUpFlag);\r
965 \r
966   if((PWR->WKUPFR & WakeUpFlag) != 0U)\r
967   {\r
968     return HAL_ERROR;\r
969   }\r
970 \r
971   return HAL_OK;\r
972 }\r
973 \r
974 /**\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
977   * @retval None\r
978   */\r
979 void HAL_PWREx_WAKEUP_PIN_IRQHandler(void)\r
980 {\r
981   /* Wakeup pin EXTI line interrupt detected */\r
982   if(READ_BIT(PWR->WKUPFR, PWR_WKUPFR_WKUPF1) != 0U)\r
983   {\r
984     /* Clear PWR WKUPF1 flag */\r
985     SET_BIT(PWR->WKUPCR, PWR_WKUPCR_WKUPC1);\r
986 \r
987     /* PWR WKUP1 interrupt user callback */\r
988     HAL_PWREx_WKUP1_Callback();\r
989   }\r
990   else if(READ_BIT(PWR->WKUPFR, PWR_WKUPFR_WKUPF2) != 0U)\r
991   {\r
992     /* Clear PWR WKUPF2 flag */\r
993     SET_BIT(PWR->WKUPCR, PWR_WKUPCR_WKUPC2);\r
994 \r
995     /* PWR WKUP2 interrupt user callback */\r
996     HAL_PWREx_WKUP2_Callback();\r
997   }\r
998   else if(READ_BIT(PWR->WKUPFR, PWR_WKUPFR_WKUPF3) != 0U)\r
999   {\r
1000     /* Clear PWR WKUPF3 flag */\r
1001     SET_BIT(PWR->WKUPCR, PWR_WKUPCR_WKUPC3);\r
1002 \r
1003     /* PWR WKUP3 interrupt user callback */\r
1004     HAL_PWREx_WKUP3_Callback();\r
1005   }\r
1006   else if(READ_BIT(PWR->WKUPFR, PWR_WKUPFR_WKUPF4) != 0U)\r
1007   {\r
1008     /* Clear PWR WKUPF4 flag */\r
1009     SET_BIT(PWR->WKUPCR, PWR_WKUPCR_WKUPC4);\r
1010 \r
1011     /* PWR WKUP4 interrupt user callback */\r
1012     HAL_PWREx_WKUP4_Callback();\r
1013   }\r
1014   else if(READ_BIT(PWR->WKUPFR, PWR_WKUPFR_WKUPF5) != 0U)\r
1015   {\r
1016     /* Clear PWR WKUPF5 flag */\r
1017     SET_BIT(PWR->WKUPCR, PWR_WKUPCR_WKUPC5);\r
1018 \r
1019     /* PWR WKUP5 interrupt user callback */\r
1020     HAL_PWREx_WKUP5_Callback();\r
1021   }\r
1022   else\r
1023   {\r
1024     /* Clear PWR WKUPF6 flag */\r
1025     SET_BIT(PWR->WKUPCR, PWR_WKUPCR_WKUPC6);\r
1026 \r
1027     /* PWR WKUP6 interrupt user callback */\r
1028     HAL_PWREx_WKUP6_Callback();\r
1029   }\r
1030 }\r
1031 \r
1032 /**\r
1033   * @brief  PWR WKUP1 interrupt callback\r
1034   * @retval None\r
1035   */\r
1036 __weak void HAL_PWREx_WKUP1_Callback(void)\r
1037 {\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
1040   */\r
1041 }\r
1042 \r
1043 /**\r
1044   * @brief  PWR WKUP2 interrupt callback\r
1045   * @retval None\r
1046   */\r
1047 __weak void HAL_PWREx_WKUP2_Callback(void)\r
1048 {\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
1051   */\r
1052 }\r
1053 \r
1054 /**\r
1055   * @brief  PWR WKUP3 interrupt callback\r
1056   * @retval None\r
1057   */\r
1058 __weak void HAL_PWREx_WKUP3_Callback(void)\r
1059 {\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
1062   */\r
1063 }\r
1064 \r
1065 /**\r
1066   * @brief  PWR WKUP4 interrupt callback\r
1067   * @retval None\r
1068   */\r
1069 __weak void HAL_PWREx_WKUP4_Callback(void)\r
1070 {\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
1073   */\r
1074 }\r
1075 \r
1076 /**\r
1077   * @brief  PWR WKUP5 interrupt callback\r
1078   * @retval None\r
1079   */\r
1080 __weak void HAL_PWREx_WKUP5_Callback(void)\r
1081 {\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
1084   */\r
1085 }\r
1086 \r
1087 /**\r
1088   * @brief  PWR WKUP6 interrupt callback\r
1089   * @retval None\r
1090   */\r
1091 __weak void HAL_PWREx_WKUP6_Callback(void)\r
1092 {\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
1095   */\r
1096 }\r
1097 \r
1098 /**\r
1099   * @}\r
1100   */\r
1101 \r
1102 /** @defgroup PWREx_Exported_Functions_Group3 Peripherals control functions\r
1103   * @brief    Peripherals control functions\r
1104   *\r
1105 @verbatim\r
1106 \r
1107  ===============================================================================\r
1108                  ##### Peripherals control functions #####\r
1109  ===============================================================================\r
1110 \r
1111     *** Main and Backup Regulators configuration ***\r
1112     ================================================\r
1113     [..]\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
1139           system Stop mode.\r
1140     -@- Refer to the product datasheets for more details.\r
1141 \r
1142     *** USB Regulator configuration ***\r
1143     ===================================\r
1144     [..]\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
1154 \r
1155     *** VBAT battery charging ***\r
1156     =============================\r
1157     [..]\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
1162           with:\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
1167 \r
1168 @endverbatim\r
1169   * @{\r
1170   */\r
1171 \r
1172 /**\r
1173   * @brief  Enable the Backup Regulator.\r
1174   * @retval HAL status\r
1175   */\r
1176 HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg(void)\r
1177 {\r
1178   uint32_t tickstart;\r
1179 \r
1180   /* Enable the Backup regulator */\r
1181   SET_BIT(PWR->CR2, PWR_CR2_BREN);\r
1182 \r
1183   /* Get tick */\r
1184   tickstart = HAL_GetTick();\r
1185 \r
1186   /* Wait till Backup regulator ready flag is set */\r
1187   while(!__HAL_PWR_GET_FLAG(PWR_FLAG_BRR))\r
1188   {\r
1189     if((HAL_GetTick() - tickstart ) > PWR_FLAG_SETTING_DELAY_US)\r
1190     {\r
1191       return HAL_TIMEOUT;\r
1192     }\r
1193   }\r
1194   return HAL_OK;\r
1195 }\r
1196 \r
1197 /**\r
1198   * @brief  Disable the Backup Regulator.\r
1199   * @retval HAL status\r
1200   */\r
1201 HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg(void)\r
1202 {\r
1203   uint32_t tickstart;\r
1204 \r
1205   /* Disable the Backup regulator */\r
1206   CLEAR_BIT(PWR->CR2, PWR_CR2_BREN);\r
1207 \r
1208   /* Get tick */\r
1209   tickstart = HAL_GetTick();\r
1210 \r
1211   /* Wait till Backup regulator ready flag is reset */\r
1212   while(__HAL_PWR_GET_FLAG(PWR_FLAG_BRR) != RESET)\r
1213   {\r
1214     if((HAL_GetTick() - tickstart ) > PWR_FLAG_SETTING_DELAY_US)\r
1215     {\r
1216       return HAL_TIMEOUT;\r
1217     }\r
1218   }\r
1219   return HAL_OK;\r
1220 }\r
1221 \r
1222 /**\r
1223   * @brief  Enable the USB Regulator.\r
1224   * @retval HAL status\r
1225   */\r
1226 HAL_StatusTypeDef HAL_PWREx_EnableUSBReg(void)\r
1227 {\r
1228   uint32_t tickstart;\r
1229 \r
1230   /* Enable the USB regulator */\r
1231   SET_BIT(PWR->CR3, PWR_CR3_USBREGEN);\r
1232 \r
1233   /* Get tick */\r
1234   tickstart = HAL_GetTick();\r
1235 \r
1236   /* Wait till the USB regulator ready flag is set */\r
1237   while(READ_BIT(PWR->CR3, PWR_CR3_USB33RDY) == 0U)\r
1238   {\r
1239     if((HAL_GetTick() - tickstart ) > PWR_FLAG_SETTING_DELAY_US)\r
1240     {\r
1241       return HAL_TIMEOUT;\r
1242     }\r
1243   }\r
1244 \r
1245   return HAL_OK;\r
1246 }\r
1247 \r
1248 /**\r
1249   * @brief  Disable the USB Regulator.\r
1250   * @retval HAL status\r
1251   */\r
1252 HAL_StatusTypeDef HAL_PWREx_DisableUSBReg(void)\r
1253 {\r
1254   uint32_t tickstart;\r
1255 \r
1256   /* Disable the USB regulator */\r
1257   CLEAR_BIT(PWR->CR3, PWR_CR3_USBREGEN);\r
1258 \r
1259   /* Get tick */\r
1260   tickstart = HAL_GetTick();\r
1261 \r
1262   /* Wait till the USB regulator ready flag is reset */\r
1263   while(READ_BIT(PWR->CR3, PWR_CR3_USB33RDY) != 0U)\r
1264   {\r
1265     if((HAL_GetTick() - tickstart ) > PWR_FLAG_SETTING_DELAY_US)\r
1266     {\r
1267       return HAL_TIMEOUT;\r
1268     }\r
1269   }\r
1270   return HAL_OK;\r
1271 }\r
1272 \r
1273 /**\r
1274   * @brief  Enable the USB voltage level detector.\r
1275   * @retval None\r
1276   */\r
1277 void HAL_PWREx_EnableUSBVoltageDetector(void)\r
1278 {\r
1279   /* Enable the USB voltage detector */\r
1280   SET_BIT(PWR->CR3, PWR_CR3_USB33DEN);\r
1281 }\r
1282 \r
1283 /**\r
1284   * @brief  Disable the USB voltage level detector.\r
1285   * @retval None\r
1286   */\r
1287 void HAL_PWREx_DisableUSBVoltageDetector(void)\r
1288 {\r
1289   /* Disable the USB voltage detector */\r
1290   CLEAR_BIT(PWR->CR3, PWR_CR3_USB33DEN);\r
1291 }\r
1292 \r
1293 \r
1294 /**\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
1301   * @retval None\r
1302   */\r
1303 void HAL_PWREx_EnableBatteryCharging(uint32_t ResistorValue)\r
1304 {\r
1305   assert_param(IS_PWR_BATTERY_RESISTOR_SELECT(ResistorValue));\r
1306 \r
1307   /* Specify the charging resistor */\r
1308   MODIFY_REG(PWR->CR3, PWR_CR3_VBRS, ResistorValue);\r
1309 \r
1310   /* Enable the Battery charging */\r
1311   SET_BIT(PWR->CR3, PWR_CR3_VBE);\r
1312 }\r
1313 \r
1314 \r
1315 /**\r
1316   * @brief  Disable the Battery charging.\r
1317   * @retval None\r
1318   */\r
1319 void HAL_PWREx_DisableBatteryCharging(void)\r
1320 {\r
1321   /* Disable the Battery charging */\r
1322   CLEAR_BIT(PWR->CR3, PWR_CR3_VBE);\r
1323 }\r
1324 \r
1325 /**\r
1326   * @}\r
1327   */\r
1328 \r
1329 /** @defgroup PWREx_Exported_Functions_Group4 Power Monitoring functions\r
1330   * @brief    Power Monitoring functions\r
1331   *\r
1332 @verbatim\r
1333 \r
1334  ===============================================================================\r
1335                  ##### Power Monitoring functions #####\r
1336  ===============================================================================\r
1337 \r
1338     *** VBAT and Temperature supervision ***\r
1339     ========================================\r
1340     [..]\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
1355 \r
1356     *** AVD configuration ***\r
1357     =========================\r
1358     [..]\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
1366 \r
1367 @endverbatim\r
1368   * @{\r
1369   */\r
1370 \r
1371 /**\r
1372   * @brief  Enable the VBAT and temperature monitoring.\r
1373   * @retval HAL status\r
1374   */\r
1375 void HAL_PWREx_EnableMonitoring(void)\r
1376 {\r
1377   /* Enable the VBAT and Temperature monitoring */\r
1378   SET_BIT(PWR->CR2, PWR_CR2_MONEN);\r
1379 }\r
1380 \r
1381 /**\r
1382   * @brief  Disable the VBAT and temperature monitoring.\r
1383   * @retval HAL status\r
1384   */\r
1385 void HAL_PWREx_DisableMonitoring(void)\r
1386 {\r
1387   /* Disable the VBAT and Temperature monitoring */\r
1388   CLEAR_BIT(PWR->CR2, PWR_CR2_MONEN);\r
1389 }\r
1390 \r
1391 /**\r
1392   * @brief  Indicate whether the junction temperature is between, above or below the threshold.\r
1393   * @retval Temperature level.\r
1394   */\r
1395 uint32_t HAL_PWREx_GetTemperatureLevel(void)\r
1396 {\r
1397   uint32_t tempLevel;\r
1398   uint32_t regValue;\r
1399 \r
1400   /* Read the temperature flags */\r
1401   regValue = PWR->CR2 & (PWR_CR2_TEMPH | PWR_CR2_TEMPL);\r
1402 \r
1403   /* Compare the read value to the temperature threshold */\r
1404   if(regValue == PWR_CR2_TEMPL)\r
1405   {\r
1406     tempLevel = PWR_TEMP_BELOW_LOW_THRESHOLD;\r
1407   }\r
1408   else if(regValue == PWR_CR2_TEMPH)\r
1409   {\r
1410     tempLevel = PWR_TEMP_ABOVE_HIGH_THRESHOLD;\r
1411   }\r
1412   else\r
1413   {\r
1414     tempLevel = PWR_TEMP_BETWEEN_HIGH_LOW_THRESHOLD;\r
1415   }\r
1416 \r
1417   return tempLevel;\r
1418 }\r
1419 \r
1420 /**\r
1421   * @brief  Indicate whether the Battery voltage level is between, above or below the threshold.\r
1422   * @retval VBAT level.\r
1423   */\r
1424 uint32_t HAL_PWREx_GetVBATLevel(void)\r
1425 {\r
1426   uint32_t VBATLevel;\r
1427   uint32_t regValue;\r
1428 \r
1429   /* Read the VBAT flags */\r
1430   regValue = PWR->CR2 & (PWR_CR2_VBATH | PWR_CR2_VBATL);\r
1431 \r
1432   /* Compare the read value to the VBAT threshold */\r
1433   if(regValue == PWR_CR2_VBATL)\r
1434   {\r
1435     VBATLevel = PWR_VBAT_BELOW_LOW_THRESHOLD;\r
1436   }\r
1437   else if(regValue == PWR_CR2_VBATH)\r
1438   {\r
1439     VBATLevel = PWR_VBAT_ABOVE_HIGH_THRESHOLD;\r
1440   }\r
1441   else\r
1442   {\r
1443     VBATLevel = PWR_VBAT_BETWEEN_HIGH_LOW_THRESHOLD;\r
1444   }\r
1445 \r
1446   return VBATLevel;\r
1447 }\r
1448 \r
1449 /**\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
1455   * @retval None\r
1456   */\r
1457 void HAL_PWREx_ConfigAVD(PWREx_AVDTypeDef *sConfigAVD)\r
1458 {\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
1462 \r
1463   /* Set the ALS[18:17] bits according to AVDLevel value */\r
1464   MODIFY_REG(PWR->CR1, PWR_CR1_ALS, sConfigAVD->AVDLevel);\r
1465 \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
1470 #endif\r
1471   __HAL_PWR_AVD_EXTI_DISABLE_RISING_EDGE();\r
1472   __HAL_PWR_AVD_EXTI_DISABLE_FALLING_EDGE();\r
1473 \r
1474 #if !defined (DUAL_CORE)\r
1475   /* Configure the interrupt mode */\r
1476   if(AVD_MODE_IT == (sConfigAVD->Mode & AVD_MODE_IT))\r
1477   {\r
1478     __HAL_PWR_AVD_EXTI_ENABLE_IT();\r
1479   }\r
1480 \r
1481   /* Configure the event mode */\r
1482   if(AVD_MODE_EVT == (sConfigAVD->Mode & AVD_MODE_EVT))\r
1483   {\r
1484     __HAL_PWR_AVD_EXTI_ENABLE_EVENT();\r
1485   }\r
1486 #endif\r
1487   /* Configure the edge */\r
1488   if(AVD_RISING_EDGE == (sConfigAVD->Mode & AVD_RISING_EDGE))\r
1489   {\r
1490     __HAL_PWR_AVD_EXTI_ENABLE_RISING_EDGE();\r
1491   }\r
1492 \r
1493   if(AVD_FALLING_EDGE == (sConfigAVD->Mode & AVD_FALLING_EDGE))\r
1494   {\r
1495     __HAL_PWR_AVD_EXTI_ENABLE_FALLING_EDGE();\r
1496   }\r
1497 }\r
1498 \r
1499 /**\r
1500   * @brief  Enable the Analog Voltage Detector(AVD).\r
1501   * @retval None\r
1502   */\r
1503 void HAL_PWREx_EnableAVD(void)\r
1504 {\r
1505   /* Enable the Analog Voltage Detector */\r
1506   SET_BIT(PWR->CR1, PWR_CR1_AVDEN);\r
1507 }\r
1508 \r
1509 /**\r
1510   * @brief  Disable the Analog Voltage Detector(AVD).\r
1511   * @retval None\r
1512   */\r
1513 void HAL_PWREx_DisableAVD(void)\r
1514 {\r
1515   /* Disable the Analog Voltage Detector */\r
1516   CLEAR_BIT(PWR->CR1, PWR_CR1_AVDEN);\r
1517 }\r
1518 \r
1519 /**\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
1522   * @retval None\r
1523   */\r
1524 void HAL_PWREx_PVD_AVD_IRQHandler(void)\r
1525 {\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
1529   {\r
1530     if (HAL_GetCurrentCPUID() == CM7_CPUID)\r
1531     {\r
1532       /* Check PWR D1 EXTI flag */\r
1533       if(__HAL_PWR_PVD_EXTI_GET_FLAG() != RESET)\r
1534       {\r
1535         /* PWR PVD interrupt user callback */\r
1536         HAL_PWR_PVDCallback();\r
1537 \r
1538         /* Clear PWR EXTI D1 pending bit */\r
1539         __HAL_PWR_PVD_EXTI_CLEAR_FLAG();\r
1540       }\r
1541     }\r
1542     else\r
1543     {\r
1544       /* Check PWR EXTI D2 flag */\r
1545       if(__HAL_PWR_PVD_EXTID2_GET_FLAG() != RESET)\r
1546       {\r
1547         /* PWR PVD interrupt user callback */\r
1548         HAL_PWR_PVDCallback();\r
1549 \r
1550         /* Clear PWR EXTI D2 pending bit */\r
1551         __HAL_PWR_PVD_EXTID2_CLEAR_FLAG();\r
1552       }\r
1553     }\r
1554   }\r
1555 \r
1556   /* AVD EXTI line interrupt detected */\r
1557   if(READ_BIT(PWR->CR1, PWR_CR1_AVDEN) != 0U)\r
1558   {\r
1559     if (HAL_GetCurrentCPUID() == CM7_CPUID)\r
1560     {\r
1561       /* Check PWR EXTI D1 flag */\r
1562       if(__HAL_PWR_AVD_EXTI_GET_FLAG() != RESET)\r
1563       {\r
1564         /* PWR AVD interrupt user callback */\r
1565         HAL_PWREx_AVDCallback();\r
1566 \r
1567         /* Clear PWR EXTI D1 pending bit */\r
1568         __HAL_PWR_AVD_EXTI_CLEAR_FLAG();\r
1569       }\r
1570     }\r
1571     else\r
1572     {\r
1573       /* Check PWR EXTI D2 flag */\r
1574       if(__HAL_PWR_AVD_EXTID2_GET_FLAG() != RESET)\r
1575       {\r
1576         /* PWR AVD interrupt user callback */\r
1577         HAL_PWREx_AVDCallback();\r
1578 \r
1579         /* Clear PWR EXTI D2 pending bit */\r
1580         __HAL_PWR_AVD_EXTID2_CLEAR_FLAG();\r
1581       }\r
1582     }\r
1583   }\r
1584 #else\r
1585   /* PVD EXTI line interrupt detected */\r
1586   if(READ_BIT(PWR->CR1, PWR_CR1_PVDEN) != 0U)\r
1587   {\r
1588     /* Check PWR EXTI flag */\r
1589     if(__HAL_PWR_PVD_EXTI_GET_FLAG() != RESET)\r
1590     {\r
1591       /* PWR PVD interrupt user callback */\r
1592       HAL_PWR_PVDCallback();\r
1593 \r
1594       /* Clear PWR EXTI pending bit */\r
1595       __HAL_PWR_PVD_EXTI_CLEAR_FLAG();\r
1596     }\r
1597   }\r
1598 \r
1599   /* AVD EXTI line interrupt detected */\r
1600   if(READ_BIT(PWR->CR1, PWR_CR1_AVDEN) != 0U)\r
1601   {\r
1602     /* Check PWR EXTI flag */\r
1603     if(__HAL_PWR_AVD_EXTI_GET_FLAG() != RESET)\r
1604     {\r
1605       /* PWR AVD interrupt user callback */\r
1606       HAL_PWREx_AVDCallback();\r
1607 \r
1608       /* Clear PWR EXTI pending bit */\r
1609       __HAL_PWR_AVD_EXTI_CLEAR_FLAG();\r
1610     }\r
1611   }\r
1612 #endif /*DUAL_CORE*/\r
1613 }\r
1614 \r
1615 /**\r
1616   * @brief  PWR AVD interrupt callback\r
1617   * @retval None\r
1618   */\r
1619 __weak void HAL_PWREx_AVDCallback(void)\r
1620 {\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
1623    */\r
1624 }\r
1625 \r
1626 /**\r
1627   * @}\r
1628   */\r
1629 \r
1630 /**\r
1631   * @}\r
1632   */\r
1633 \r
1634 #endif /* HAL_PWR_MODULE_ENABLED */\r
1635 \r
1636 /**\r
1637   * @}\r
1638   */\r
1639 \r
1640 /**\r
1641   * @}\r
1642   */\r
1643 \r
1644 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r