]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_STM32F7_STM32756G-EVAL_IAR_Keil/ST_Library/stm32f7xx_hal_pwr.c
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M7_STM32F7_STM32756G-EVAL_IAR_Keil / ST_Library / stm32f7xx_hal_pwr.c
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32f7xx_hal_pwr.c\r
4   * @author  MCD Application Team\r
5   * @version V1.0.0RC1\r
6   * @date    24-March-2015\r
7   * @brief   PWR HAL module driver.\r
8   *          This file provides firmware functions to manage the following \r
9   *          functionalities of the Power Controller (PWR) peripheral:\r
10   *           + Initialization and de-initialization functions\r
11   *           + Peripheral Control functions \r
12   *         \r
13   ******************************************************************************\r
14   * @attention\r
15   *\r
16   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>\r
17   *\r
18   * Redistribution and use in source and binary forms, with or without modification,\r
19   * are permitted provided that the following conditions are met:\r
20   *   1. Redistributions of source code must retain the above copyright notice,\r
21   *      this list of conditions and the following disclaimer.\r
22   *   2. Redistributions in binary form must reproduce the above copyright notice,\r
23   *      this list of conditions and the following disclaimer in the documentation\r
24   *      and/or other materials provided with the distribution.\r
25   *   3. Neither the name of STMicroelectronics nor the names of its contributors\r
26   *      may be used to endorse or promote products derived from this software\r
27   *      without specific prior written permission.\r
28   *\r
29   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
30   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
31   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
32   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\r
33   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
34   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
35   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
36   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r
37   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
38   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
39   *\r
40   ******************************************************************************\r
41   */ \r
42 \r
43 /* Includes ------------------------------------------------------------------*/\r
44 #include "stm32f7xx_hal.h"\r
45 \r
46 /** @addtogroup STM32F7xx_HAL_Driver\r
47   * @{\r
48   */\r
49 \r
50 /** @defgroup PWR PWR\r
51   * @brief PWR HAL module driver\r
52   * @{\r
53   */\r
54 \r
55 #ifdef HAL_PWR_MODULE_ENABLED\r
56 \r
57 /* Private typedef -----------------------------------------------------------*/\r
58 /* Private define ------------------------------------------------------------*/\r
59 /** @addtogroup PWR_Private_Constants\r
60   * @{\r
61   */\r
62         \r
63 /** @defgroup PWR_PVD_Mode_Mask PWR PVD Mode Mask\r
64   * @{\r
65   */     \r
66 #define PVD_MODE_IT               ((uint32_t)0x00010000)\r
67 #define PVD_MODE_EVT              ((uint32_t)0x00020000)\r
68 #define PVD_RISING_EDGE           ((uint32_t)0x00000001)\r
69 #define PVD_FALLING_EDGE          ((uint32_t)0x00000002)\r
70 /**\r
71   * @}\r
72   */\r
73 \r
74 /** @defgroup PWR_ENABLE_WUP_Mask PWR Enable WUP Mask\r
75   * @{\r
76   */  \r
77 #define  PWR_EWUP_MASK                          ((uint32_t)0x00003F00)\r
78 /**\r
79   * @}\r
80   */\r
81 \r
82 /**\r
83   * @}\r
84   */\r
85 /* Private macro -------------------------------------------------------------*/\r
86 /* Private variables ---------------------------------------------------------*/\r
87 /* Private function prototypes -----------------------------------------------*/\r
88 /* Private functions ---------------------------------------------------------*/\r
89 \r
90 /** @defgroup PWR_Exported_Functions PWR Exported Functions\r
91   * @{\r
92   */\r
93 \r
94 /** @defgroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions \r
95   *  @brief    Initialization and de-initialization functions\r
96   *\r
97 @verbatim\r
98  ===============================================================================\r
99               ##### Initialization and de-initialization functions #####\r
100  ===============================================================================\r
101     [..]\r
102       After reset, the backup domain (RTC registers, RTC backup data \r
103       registers and backup SRAM) is protected against possible unwanted \r
104       write accesses. \r
105       To enable access to the RTC Domain and RTC registers, proceed as follows:\r
106         (+) Enable the Power Controller (PWR) APB1 interface clock using the\r
107             __HAL_RCC_PWR_CLK_ENABLE() macro.\r
108         (+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function.\r
109  \r
110 @endverbatim\r
111   * @{\r
112   */\r
113 \r
114 /**\r
115   * @brief Deinitializes the HAL PWR peripheral registers to their default reset values.\r
116   * @retval None\r
117   */\r
118 void HAL_PWR_DeInit(void)\r
119 {\r
120   __HAL_RCC_PWR_FORCE_RESET();\r
121   __HAL_RCC_PWR_RELEASE_RESET();\r
122 }\r
123 \r
124 /**\r
125   * @brief Enables access to the backup domain (RTC registers, RTC \r
126   *         backup data registers and backup SRAM).\r
127   * @note If the HSE divided by 2, 3, ..31 is used as the RTC clock, the \r
128   *         Backup Domain Access should be kept enabled.\r
129   * @retval None\r
130   */\r
131 void HAL_PWR_EnableBkUpAccess(void)\r
132 {\r
133   /* Enable access to RTC and backup registers */\r
134   SET_BIT(PWR->CR1, PWR_CR1_DBP);\r
135 }\r
136 \r
137 /**\r
138   * @brief Disables access to the backup domain (RTC registers, RTC \r
139   *         backup data registers and backup SRAM).\r
140   * @note If the HSE divided by 2, 3, ..31 is used as the RTC clock, the \r
141   *         Backup Domain Access should be kept enabled.\r
142   * @retval None\r
143   */\r
144 void HAL_PWR_DisableBkUpAccess(void)\r
145 {\r
146   /* Disable access to RTC and backup registers */\r
147         CLEAR_BIT(PWR->CR1, PWR_CR1_DBP);\r
148 }\r
149 \r
150 /**\r
151   * @}\r
152   */\r
153 \r
154 /** @defgroup PWR_Exported_Functions_Group2 Peripheral Control functions \r
155   *  @brief Low Power modes configuration functions \r
156   *\r
157 @verbatim\r
158 \r
159  ===============================================================================\r
160                  ##### Peripheral Control functions #####\r
161  ===============================================================================\r
162      \r
163     *** PVD configuration ***\r
164     =========================\r
165     [..]\r
166       (+) The PVD is used to monitor the VDD power supply by comparing it to a \r
167           threshold selected by the PVD Level (PLS[2:0] bits in the PWR_CR).\r
168       (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower \r
169           than the PVD threshold. This event is internally connected to the EXTI \r
170           line16 and can generate an interrupt if enabled. This is done through\r
171           __HAL_PWR_PVD_EXTI_ENABLE_IT() macro.\r
172       (+) The PVD is stopped in Standby mode.\r
173 \r
174     *** Wake-up pin configuration ***\r
175     ================================\r
176     [..]\r
177       (+) Wake-up pin is used to wake up the system from Standby mode. This pin is \r
178           forced in input pull-down configuration and is active on rising edges.\r
179       (+) There are to 6 Wake-up pin in the STM32F7 devices family\r
180 \r
181     *** Low Power modes configuration ***\r
182     =====================================\r
183     [..]\r
184       The devices feature 3 low-power modes:\r
185       (+) Sleep mode: Cortex-M7 core stopped, peripherals kept running.\r
186       (+) Stop mode: all clocks are stopped, regulator running, regulator \r
187           in low power mode\r
188       (+) Standby mode: 1.2V domain powered off.\r
189    \r
190    *** Sleep mode ***\r
191    ==================\r
192     [..]\r
193       (+) Entry:\r
194         The Sleep mode is entered by using the HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI)\r
195               functions with\r
196           (++) PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction\r
197           (++) PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction\r
198       \r
199       -@@- The Regulator parameter is not used for the STM32F7 family \r
200               and is kept as parameter just to maintain compatibility with the \r
201               lower power families (STM32L).\r
202       (+) Exit:\r
203         Any peripheral interrupt acknowledged by the nested vectored interrupt \r
204               controller (NVIC) can wake up the device from Sleep mode.\r
205 \r
206    *** Stop mode ***\r
207    =================\r
208     [..]\r
209       In Stop mode, all clocks in the 1.2V domain are stopped, the PLL, the HSI,\r
210       and the HSE RC oscillators are disabled. Internal SRAM and register contents \r
211       are preserved.\r
212       The voltage regulator can be configured either in normal or low-power mode.\r
213       To minimize the consumption In Stop mode, FLASH can be powered off before \r
214       entering the Stop mode using the HAL_PWREx_EnableFlashPowerDown() function.\r
215       It can be switched on again by software after exiting the Stop mode using\r
216       the HAL_PWREx_DisableFlashPowerDown() function. \r
217 \r
218       (+) Entry:\r
219          The Stop mode is entered using the HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON) \r
220              function with:\r
221           (++) Main regulator ON.\r
222           (++) Low Power regulator ON.\r
223       (+) Exit:\r
224         Any EXTI Line (Internal or External) configured in Interrupt/Event mode.\r
225 \r
226    *** Standby mode ***\r
227    ====================\r
228     [..]\r
229     (+)\r
230       The Standby mode allows to achieve the lowest power consumption. It is based \r
231       on the Cortex-M7 deep sleep mode, with the voltage regulator disabled. \r
232       The 1.2V domain is consequently powered off. The PLL, the HSI oscillator and \r
233       the HSE oscillator are also switched off. SRAM and register contents are lost \r
234       except for the RTC registers, RTC backup registers, backup SRAM and Standby \r
235       circuitry.\r
236    \r
237       The voltage regulator is OFF.\r
238       \r
239       (++) Entry:\r
240         (+++) The Standby mode is entered using the HAL_PWR_EnterSTANDBYMode() function.\r
241       (++) Exit:\r
242         (+++) WKUP pin rising or falling edge, RTC alarm (Alarm A and Alarm B), RTC\r
243              wakeup, tamper event, time stamp event, external reset in NRST pin, IWDG reset.\r
244 \r
245    *** Auto-wakeup (AWU) from low-power mode ***\r
246    =============================================\r
247     [..]\r
248     \r
249      (+) The MCU can be woken up from low-power mode by an RTC Alarm event, an RTC \r
250       Wakeup event, a tamper event or a time-stamp event, without depending on \r
251       an external interrupt (Auto-wakeup mode).\r
252 \r
253       (+) RTC auto-wakeup (AWU) from the Stop and Standby modes\r
254        \r
255         (++) To wake up from the Stop mode with an RTC alarm event, it is necessary to \r
256               configure the RTC to generate the RTC alarm using the HAL_RTC_SetAlarm_IT() function.\r
257 \r
258         (++) To wake up from the Stop mode with an RTC Tamper or time stamp event, it \r
259              is necessary to configure the RTC to detect the tamper or time stamp event using the\r
260                 HAL_RTCEx_SetTimeStamp_IT() or HAL_RTCEx_SetTamper_IT() functions.\r
261                   \r
262         (++) To wake up from the Stop mode with an RTC WakeUp event, it is necessary to\r
263               configure the RTC to generate the RTC WakeUp event using the HAL_RTCEx_SetWakeUpTimer_IT() function.\r
264 \r
265 @endverbatim\r
266   * @{\r
267   */\r
268 \r
269 /**\r
270   * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD).\r
271   * @param sConfigPVD: pointer to an PWR_PVDTypeDef structure that contains the configuration\r
272   *        information for the PVD.\r
273   * @note Refer to the electrical characteristics of your device datasheet for\r
274   *         more details about the voltage threshold corresponding to each \r
275   *         detection level.\r
276   * @retval None\r
277   */\r
278 void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD)\r
279 {\r
280   /* Check the parameters */\r
281   assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel));\r
282   assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode));\r
283   \r
284   /* Set PLS[7:5] bits according to PVDLevel value */\r
285   MODIFY_REG(PWR->CR1, PWR_CR1_PLS, sConfigPVD->PVDLevel);\r
286   \r
287   /* Clear any previous config. Keep it clear if no event or IT mode is selected */\r
288   __HAL_PWR_PVD_EXTI_DISABLE_EVENT();\r
289   __HAL_PWR_PVD_EXTI_DISABLE_IT();\r
290   __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();\r
291   __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE(); \r
292 \r
293   /* Configure interrupt mode */\r
294   if((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT)\r
295   {\r
296     __HAL_PWR_PVD_EXTI_ENABLE_IT();\r
297   }\r
298   \r
299   /* Configure event mode */\r
300   if((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT)\r
301   {\r
302     __HAL_PWR_PVD_EXTI_ENABLE_EVENT();\r
303   }\r
304   \r
305   /* Configure the edge */\r
306   if((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE)\r
307   {\r
308     __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();\r
309   }\r
310   \r
311   if((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE)\r
312   {\r
313     __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();\r
314   }\r
315 }\r
316 \r
317 /**\r
318   * @brief Enables the Power Voltage Detector(PVD).\r
319   * @retval None\r
320   */\r
321 void HAL_PWR_EnablePVD(void)\r
322 {\r
323   /* Enable the power voltage detector */\r
324         SET_BIT(PWR->CR1, PWR_CR1_PVDE);\r
325 }\r
326 \r
327 /**\r
328   * @brief Disables the Power Voltage Detector(PVD).\r
329   * @retval None\r
330   */\r
331 void HAL_PWR_DisablePVD(void)\r
332 {\r
333   /* Disable the power voltage detector */\r
334         CLEAR_BIT(PWR->CR1, PWR_CR1_PVDE);\r
335 }\r
336 \r
337 /**\r
338   * @brief Enable the WakeUp PINx functionality.\r
339   * @param WakeUpPinPolarity: Specifies which Wake-Up pin to enable.\r
340   *         This parameter can be one of the following legacy values, which sets the default polarity: \r
341   *         detection on high level (rising edge):\r
342   *           @arg PWR_WAKEUP_PIN1, PWR_WAKEUP_PIN2, PWR_WAKEUP_PIN3, PWR_WAKEUP_PIN4, PWR_WAKEUP_PIN5, PWR_WAKEUP_PIN6 \r
343   *         or one of the following value where the user can explicitly states the enabled pin and\r
344   *         the chosen polarity  \r
345   *           @arg PWR_WAKEUP_PIN1_HIGH or PWR_WAKEUP_PIN1_LOW \r
346   *           @arg PWR_WAKEUP_PIN2_HIGH or PWR_WAKEUP_PIN2_LOW \r
347   *           @arg PWR_WAKEUP_PIN3_HIGH or PWR_WAKEUP_PIN3_LOW \r
348   *           @arg PWR_WAKEUP_PIN4_HIGH or PWR_WAKEUP_PIN4_LOW\r
349   *           @arg PWR_WAKEUP_PIN5_HIGH or PWR_WAKEUP_PIN5_LOW \r
350   *           @arg PWR_WAKEUP_PIN6_HIGH or PWR_WAKEUP_PIN6_LOW \r
351   * @note  PWR_WAKEUP_PINx and PWR_WAKEUP_PINx_HIGH are equivalent.               \r
352   * @retval None\r
353   */\r
354 void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity)\r
355 {\r
356   assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinPolarity));\r
357   \r
358   /* Enable wake-up pin */\r
359   SET_BIT(PWR->CSR2, (PWR_EWUP_MASK & WakeUpPinPolarity));\r
360         \r
361   /* Specifies the Wake-Up pin polarity for the event detection\r
362     (rising or falling edge) */\r
363   MODIFY_REG(PWR->CR2, (PWR_EWUP_MASK & WakeUpPinPolarity), (WakeUpPinPolarity >> 0x06));\r
364 }\r
365 \r
366 /**\r
367   * @brief Disables the WakeUp PINx functionality.\r
368   * @param WakeUpPinx: Specifies the Power Wake-Up pin to disable.\r
369   *         This parameter can be one of the following values:\r
370   *           @arg PWR_WAKEUP_PIN1\r
371   *           @arg PWR_WAKEUP_PIN2\r
372   *           @arg PWR_WAKEUP_PIN3\r
373   *           @arg PWR_WAKEUP_PIN4\r
374   *           @arg PWR_WAKEUP_PIN5\r
375   *           @arg PWR_WAKEUP_PIN6 \r
376   * @retval None\r
377   */\r
378 void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx)\r
379 {\r
380   assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));\r
381 \r
382   CLEAR_BIT(PWR->CSR2, WakeUpPinx);\r
383 }\r
384   \r
385 /**\r
386   * @brief Enters Sleep mode.\r
387   *   \r
388   * @note In Sleep mode, all I/O pins keep the same state as in Run mode.\r
389   * \r
390   * @note In Sleep mode, the systick is stopped to avoid exit from this mode with\r
391   *       systick interrupt when used as time base for Timeout \r
392   *                \r
393   * @param Regulator: Specifies the regulator state in SLEEP mode.\r
394   *            This parameter can be one of the following values:\r
395   *            @arg PWR_MAINREGULATOR_ON: SLEEP mode with regulator ON\r
396   *            @arg PWR_LOWPOWERREGULATOR_ON: SLEEP mode with low power regulator ON\r
397   * @note This parameter is not used for the STM32F7 family and is kept as parameter\r
398   *       just to maintain compatibility with the lower power families.\r
399   * @param SLEEPEntry: Specifies if SLEEP mode in entered with WFI or WFE instruction.\r
400   *          This parameter can be one of the following values:\r
401   *            @arg PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction\r
402   *            @arg PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction\r
403   * @retval None\r
404   */\r
405 void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)\r
406 {\r
407   /* Check the parameters */\r
408   assert_param(IS_PWR_REGULATOR(Regulator));\r
409   assert_param(IS_PWR_SLEEP_ENTRY(SLEEPEntry));\r
410 \r
411   /* Clear SLEEPDEEP bit of Cortex System Control Register */\r
412   CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));\r
413 \r
414   /* Select SLEEP mode entry -------------------------------------------------*/\r
415   if(SLEEPEntry == PWR_SLEEPENTRY_WFI)\r
416   {   \r
417     /* Request Wait For Interrupt */\r
418     __WFI();\r
419   }\r
420   else\r
421   {\r
422     /* Request Wait For Event */\r
423     __SEV();\r
424     __WFE();\r
425     __WFE();\r
426   }\r
427 }\r
428 \r
429 /**\r
430   * @brief Enters Stop mode. \r
431   * @note In Stop mode, all I/O pins keep the same state as in Run mode.\r
432   * @note When exiting Stop mode by issuing an interrupt or a wakeup event, \r
433   *         the HSI RC oscillator is selected as system clock.\r
434   * @note When the voltage regulator operates in low power mode, an additional \r
435   *         startup delay is incurred when waking up from Stop mode. \r
436   *         By keeping the internal regulator ON during Stop mode, the consumption \r
437   *         is higher although the startup time is reduced.    \r
438   * @param Regulator: Specifies the regulator state in Stop mode.\r
439   *          This parameter can be one of the following values:\r
440   *            @arg PWR_MAINREGULATOR_ON: Stop mode with regulator ON\r
441   *            @arg PWR_LOWPOWERREGULATOR_ON: Stop mode with low power regulator ON\r
442   * @param STOPEntry: Specifies if Stop mode in entered with WFI or WFE instruction.\r
443   *          This parameter can be one of the following values:\r
444   *            @arg PWR_STOPENTRY_WFI: Enter Stop mode with WFI instruction\r
445   *            @arg PWR_STOPENTRY_WFE: Enter Stop mode with WFE instruction\r
446   * @retval None\r
447   */\r
448 void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)\r
449 {\r
450   uint32_t tmpreg = 0;\r
451   \r
452   /* Check the parameters */\r
453   assert_param(IS_PWR_REGULATOR(Regulator));\r
454   assert_param(IS_PWR_STOP_ENTRY(STOPEntry));\r
455   \r
456   /* Select the regulator state in Stop mode ---------------------------------*/\r
457   tmpreg = PWR->CR1;\r
458   /* Clear PDDS and LPDS bits */\r
459   tmpreg &= (uint32_t)~(PWR_CR1_PDDS | PWR_CR1_LPDS);\r
460   \r
461   /* Set LPDS, MRLVDS and LPLVDS bits according to Regulator value */\r
462   tmpreg |= Regulator;\r
463   \r
464   /* Store the new value */\r
465   PWR->CR1 = tmpreg;\r
466   \r
467   /* Set SLEEPDEEP bit of Cortex System Control Register */\r
468   SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;\r
469   \r
470   /* Select Stop mode entry --------------------------------------------------*/\r
471   if(STOPEntry == PWR_STOPENTRY_WFI)\r
472   {   \r
473     /* Request Wait For Interrupt */\r
474     __WFI();\r
475   }\r
476   else\r
477   {\r
478     /* Request Wait For Event */\r
479     __SEV();\r
480     __WFE();\r
481     __WFE();\r
482   }\r
483   /* Reset SLEEPDEEP bit of Cortex System Control Register */\r
484   SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);  \r
485 }\r
486 \r
487 /**\r
488   * @brief Enters Standby mode.\r
489   * @note In Standby mode, all I/O pins are high impedance except for:\r
490   *          - Reset pad (still available) \r
491   *          - RTC_AF1 pin (PC13) if configured for tamper, time-stamp, RTC \r
492   *            Alarm out, or RTC clock calibration out.\r
493   *          - RTC_AF2 pin (PI8) if configured for tamper or time-stamp.  \r
494   *          - WKUP pins if enabled.       \r
495   * @retval None\r
496   */\r
497 void HAL_PWR_EnterSTANDBYMode(void)\r
498 {\r
499   /* Select Standby mode */\r
500   PWR->CR1 |= PWR_CR1_PDDS;\r
501   \r
502   /* Set SLEEPDEEP bit of Cortex System Control Register */\r
503   SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;\r
504   \r
505   /* This option is used to ensure that store operations are completed */\r
506 #if defined ( __CC_ARM)\r
507   __force_stores();\r
508 #endif\r
509   /* Request Wait For Interrupt */\r
510   __WFI();\r
511 }\r
512 \r
513 /**\r
514   * @brief This function handles the PWR PVD interrupt request.\r
515   * @note This API should be called under the PVD_IRQHandler().\r
516   * @retval None\r
517   */\r
518 void HAL_PWR_PVD_IRQHandler(void)\r
519 {\r
520   /* Check PWR Exti flag */\r
521   if(__HAL_PWR_PVD_EXTI_GET_FLAG() != RESET)\r
522   {\r
523     /* PWR PVD interrupt user callback */\r
524     HAL_PWR_PVDCallback();\r
525     \r
526     /* Clear PWR Exti pending bit */\r
527     __HAL_PWR_PVD_EXTI_CLEAR_FLAG();\r
528   }\r
529 }\r
530 \r
531 /**\r
532   * @brief  PWR PVD interrupt callback\r
533   * @retval None\r
534   */\r
535 __weak void HAL_PWR_PVDCallback(void)\r
536 {\r
537   /* NOTE : This function Should not be modified, when the callback is needed,\r
538             the HAL_PWR_PVDCallback could be implemented in the user file\r
539    */ \r
540 }\r
541 \r
542 /**\r
543   * @brief Indicates Sleep-On-Exit when returning from Handler mode to Thread mode. \r
544   * @note Set SLEEPONEXIT bit of SCR register. When this bit is set, the processor \r
545   *       re-enters SLEEP mode when an interruption handling is over.\r
546   *       Setting this bit is useful when the processor is expected to run only on\r
547   *       interruptions handling.         \r
548   * @retval None\r
549   */\r
550 void HAL_PWR_EnableSleepOnExit(void)\r
551 {\r
552   /* Set SLEEPONEXIT bit of Cortex System Control Register */\r
553   SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));\r
554 }\r
555 \r
556 /**\r
557   * @brief Disables Sleep-On-Exit feature when returning from Handler mode to Thread mode. \r
558   * @note Clears SLEEPONEXIT bit of SCR register. When this bit is set, the processor \r
559   *       re-enters SLEEP mode when an interruption handling is over.          \r
560   * @retval None\r
561   */\r
562 void HAL_PWR_DisableSleepOnExit(void)\r
563 {\r
564   /* Clear SLEEPONEXIT bit of Cortex System Control Register */\r
565   CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));\r
566 }\r
567 \r
568 /**\r
569   * @brief Enables CORTEX M4 SEVONPEND bit. \r
570   * @note Sets SEVONPEND bit of SCR register. When this bit is set, this causes \r
571   *       WFE to wake up when an interrupt moves from inactive to pended.\r
572   * @retval None\r
573   */\r
574 void HAL_PWR_EnableSEVOnPend(void)\r
575 {\r
576   /* Set SEVONPEND bit of Cortex System Control Register */\r
577   SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));\r
578 }\r
579 \r
580 /**\r
581   * @brief Disables CORTEX M4 SEVONPEND bit. \r
582   * @note Clears SEVONPEND bit of SCR register. When this bit is set, this causes \r
583   *       WFE to wake up when an interrupt moves from inactive to pended.         \r
584   * @retval None\r
585   */\r
586 void HAL_PWR_DisableSEVOnPend(void)\r
587 {\r
588   /* Clear SEVONPEND bit of Cortex System Control Register */\r
589   CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));\r
590 }\r
591 \r
592 /**\r
593   * @}\r
594   */\r
595   \r
596 /**\r
597   * @}\r
598   */\r
599 \r
600 #endif /* HAL_PWR_MODULE_ENABLED */\r
601 /**\r
602   * @}\r
603   */\r
604 \r
605 /**\r
606   * @}\r
607   */\r
608 \r
609 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r