]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_STM32L4_Discovery_Keil_STM32Cube/ST_Code/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr.c
Make vSetupTimerInterrupt weak in the RVDS M4 MPU port to give the
[freertos] / FreeRTOS / Demo / CORTEX_MPU_STM32L4_Discovery_Keil_STM32Cube / ST_Code / Drivers / STM32L4xx_HAL_Driver / Src / stm32l4xx_hal_pwr.c
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32l4xx_hal_pwr.c\r
4   * @author  MCD Application Team\r
5   * @brief   PWR HAL module driver.\r
6   *          This file provides firmware functions to manage the following\r
7   *          functionalities of the Power Controller (PWR) peripheral:\r
8   *           + Initialization/de-initialization functions\r
9   *           + Peripheral Control functions\r
10   *\r
11   ******************************************************************************\r
12   * @attention\r
13   *\r
14   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.\r
15   * All rights reserved.</center></h2>\r
16   *\r
17   * This software component is licensed by ST under BSD 3-Clause license,\r
18   * the "License"; You may not use this file except in compliance with the\r
19   * License. You may obtain a copy of the License at:\r
20   *                        opensource.org/licenses/BSD-3-Clause\r
21   *\r
22   ******************************************************************************\r
23   */\r
24 \r
25 /* Includes ------------------------------------------------------------------*/\r
26 #include "stm32l4xx_hal.h"\r
27 \r
28 /** @addtogroup STM32L4xx_HAL_Driver\r
29   * @{\r
30   */\r
31 \r
32 /** @defgroup PWR PWR\r
33   * @brief PWR HAL module driver\r
34   * @{\r
35   */\r
36 \r
37 #ifdef HAL_PWR_MODULE_ENABLED\r
38 \r
39 /* Private typedef -----------------------------------------------------------*/\r
40 /* Private define ------------------------------------------------------------*/\r
41 \r
42 /** @defgroup PWR_Private_Defines PWR Private Defines\r
43   * @{\r
44   */\r
45 \r
46 /** @defgroup PWR_PVD_Mode_Mask PWR PVD Mode Mask\r
47   * @{\r
48   */\r
49 #define PVD_MODE_IT               ((uint32_t)0x00010000)  /*!< Mask for interruption yielded by PVD threshold crossing */\r
50 #define PVD_MODE_EVT              ((uint32_t)0x00020000)  /*!< Mask for event yielded by PVD threshold crossing        */\r
51 #define PVD_RISING_EDGE           ((uint32_t)0x00000001)  /*!< Mask for rising edge set as PVD trigger                 */\r
52 #define PVD_FALLING_EDGE          ((uint32_t)0x00000002)  /*!< Mask for falling edge set as PVD trigger                */\r
53 /**\r
54   * @}\r
55   */\r
56 \r
57 /**\r
58   * @}\r
59   */\r
60 \r
61 /* Private macro -------------------------------------------------------------*/\r
62 /* Private variables ---------------------------------------------------------*/\r
63 /* Private function prototypes -----------------------------------------------*/\r
64 /* Exported functions --------------------------------------------------------*/\r
65 \r
66 /** @defgroup PWR_Exported_Functions PWR Exported Functions\r
67   * @{\r
68   */\r
69 \r
70 /** @defgroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions\r
71   *  @brief    Initialization and de-initialization functions\r
72   *\r
73 @verbatim\r
74  ===============================================================================\r
75               ##### Initialization and de-initialization functions #####\r
76  ===============================================================================\r
77     [..]\r
78 \r
79 @endverbatim\r
80   * @{\r
81   */\r
82 \r
83 /**\r
84   * @brief Deinitialize the HAL PWR peripheral registers to their default reset values.\r
85   * @retval None\r
86   */\r
87 void HAL_PWR_DeInit(void)\r
88 {\r
89   __HAL_RCC_PWR_FORCE_RESET();\r
90   __HAL_RCC_PWR_RELEASE_RESET();\r
91 }\r
92 \r
93 /**\r
94   * @brief Enable access to the backup domain\r
95   *        (RTC registers, RTC backup data registers).\r
96   * @note  After reset, the backup domain is protected against\r
97   *        possible unwanted write accesses.\r
98   * @note  RTCSEL that sets the RTC clock source selection is in the RTC back-up domain.\r
99   *        In order to set or modify the RTC clock, the backup domain access must be\r
100   *        disabled.\r
101   * @note  LSEON bit that switches on and off the LSE crystal belongs as well to the\r
102   *        back-up domain.\r
103   * @retval None\r
104   */\r
105 void HAL_PWR_EnableBkUpAccess(void)\r
106 {\r
107   SET_BIT(PWR->CR1, PWR_CR1_DBP);\r
108 }\r
109 \r
110 /**\r
111   * @brief Disable access to the backup domain\r
112   *        (RTC registers, RTC backup data registers).\r
113   * @retval None\r
114   */\r
115 void HAL_PWR_DisableBkUpAccess(void)\r
116 {\r
117   CLEAR_BIT(PWR->CR1, PWR_CR1_DBP);\r
118 }\r
119 \r
120 \r
121 \r
122 \r
123 /**\r
124   * @}\r
125   */\r
126 \r
127 \r
128 \r
129 /** @defgroup PWR_Exported_Functions_Group2 Peripheral Control functions\r
130   *  @brief Low Power modes configuration functions\r
131   *\r
132 @verbatim\r
133 \r
134  ===============================================================================\r
135                  ##### Peripheral Control functions #####\r
136  ===============================================================================\r
137 \r
138      [..]\r
139      *** PVD configuration ***\r
140     =========================\r
141     [..]\r
142       (+) The PVD is used to monitor the VDD power supply by comparing it to a\r
143           threshold selected by the PVD Level (PLS[2:0] bits in PWR_CR2 register).\r
144 \r
145       (+) PVDO flag is available to indicate if VDD/VDDA is higher or lower\r
146           than the PVD threshold. This event is internally connected to the EXTI\r
147           line16 and can generate an interrupt if enabled. This is done through\r
148           __HAL_PVD_EXTI_ENABLE_IT() macro.\r
149       (+) The PVD is stopped in Standby mode.\r
150 \r
151 \r
152     *** WakeUp pin configuration ***\r
153     ================================\r
154     [..]\r
155       (+) WakeUp pins are used to wakeup the system from Standby mode or Shutdown mode.\r
156           The polarity of these pins can be set to configure event detection on high\r
157           level (rising edge) or low level (falling edge).\r
158 \r
159 \r
160 \r
161     *** Low Power modes configuration ***\r
162     =====================================\r
163     [..]\r
164       The devices feature 8 low-power modes:\r
165       (+) Low-power Run mode: core and peripherals are running, main regulator off, low power regulator on.\r
166       (+) Sleep mode: Cortex-M4 core stopped, peripherals kept running, main and low power regulators on.\r
167       (+) Low-power Sleep mode: Cortex-M4 core stopped, peripherals kept running, main regulator off, low power regulator on.\r
168       (+) Stop 0 mode: all clocks are stopped except LSI and LSE, main and low power regulators on.\r
169       (+) Stop 1 mode: all clocks are stopped except LSI and LSE, main regulator off, low power regulator on.\r
170       (+) Stop 2 mode: all clocks are stopped except LSI and LSE, main regulator off, low power regulator on, reduced set of waking up IPs compared to Stop 1 mode.\r
171       (+) Standby mode with SRAM2: all clocks are stopped except LSI and LSE, SRAM2 content preserved, main regulator off, low power regulator on.\r
172       (+) Standby mode without SRAM2: all clocks are stopped except LSI and LSE, main and low power regulators off.\r
173       (+) Shutdown mode: all clocks are stopped except LSE, main and low power regulators off.\r
174 \r
175 \r
176    *** Low-power run mode ***\r
177    ==========================\r
178     [..]\r
179       (+) Entry: (from main run mode)\r
180         (++) set LPR bit with HAL_PWREx_EnableLowPowerRunMode() API after having decreased the system clock below 2 MHz.\r
181 \r
182       (+) Exit:\r
183         (++) clear LPR bit then wait for REGLP bit to be reset with HAL_PWREx_DisableLowPowerRunMode() API. Only\r
184              then can the system clock frequency be increased above 2 MHz.\r
185 \r
186 \r
187    *** Sleep mode / Low-power sleep mode ***\r
188    =========================================\r
189     [..]\r
190       (+) Entry:\r
191           The Sleep mode / Low-power Sleep mode is entered thru HAL_PWR_EnterSLEEPMode() API\r
192           in specifying whether or not the regulator is forced to low-power mode and if exit is interrupt or event-triggered.\r
193           (++) PWR_MAINREGULATOR_ON: Sleep mode (regulator in main mode).\r
194           (++) PWR_LOWPOWERREGULATOR_ON: Low-power sleep (regulator in low power mode).\r
195           In the latter case, the system clock frequency must have been decreased below 2 MHz beforehand.\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       (+) WFI Exit:\r
200         (++) Any peripheral interrupt acknowledged by the nested vectored interrupt\r
201              controller (NVIC) or any wake-up event.\r
202 \r
203       (+) WFE Exit:\r
204         (++) Any wake-up event such as an EXTI line configured in event mode.\r
205 \r
206          [..] When exiting the Low-power sleep mode by issuing an interrupt or a wakeup event,\r
207              the MCU is in Low-power Run mode.\r
208 \r
209    *** Stop 0, Stop 1 and Stop 2 modes ***\r
210    ===============================\r
211     [..]\r
212       (+) Entry:\r
213           The Stop 0, Stop 1 or Stop 2 modes are entered thru the following API's:\r
214           (++) HAL_PWREx_EnterSTOP0Mode() for mode 0 or HAL_PWREx_EnterSTOP1Mode() for mode 1 or for porting reasons HAL_PWR_EnterSTOPMode().\r
215           (++) HAL_PWREx_EnterSTOP2Mode() for mode 2.\r
216       (+) Regulator setting (applicable to HAL_PWR_EnterSTOPMode() only):\r
217           (++) PWR_MAINREGULATOR_ON\r
218           (++) PWR_LOWPOWERREGULATOR_ON\r
219       (+) Exit (interrupt or event-triggered, specified when entering STOP mode):\r
220           (++) PWR_STOPENTRY_WFI: enter Stop mode with WFI instruction\r
221           (++) PWR_STOPENTRY_WFE: enter Stop mode with WFE instruction\r
222 \r
223       (+) WFI Exit:\r
224           (++) Any EXTI Line (Internal or External) configured in Interrupt mode.\r
225           (++) Some specific communication peripherals (USART, LPUART, I2C) interrupts\r
226                when programmed in wakeup mode.\r
227       (+) WFE Exit:\r
228           (++) Any EXTI Line (Internal or External) configured in Event mode.\r
229 \r
230        [..]\r
231           When exiting Stop 0 and Stop 1 modes, the MCU is either in Run mode or in Low-power Run mode\r
232           depending on the LPR bit setting.\r
233           When exiting Stop 2 mode, the MCU is in Run mode.\r
234 \r
235    *** Standby mode ***\r
236    ====================\r
237      [..]\r
238       The Standby mode offers two options:\r
239       (+) option a) all clocks off except LSI and LSE, RRS bit set (keeps voltage regulator in low power mode).\r
240         SRAM and registers contents are lost except for the SRAM2 content, the RTC registers, RTC backup registers\r
241         and Standby circuitry.\r
242       (+) option b) all clocks off except LSI and LSE, RRS bit cleared (voltage regulator then disabled).\r
243         SRAM and register contents are lost except for the RTC registers, RTC backup registers\r
244         and Standby circuitry.\r
245 \r
246       (++) Entry:\r
247           (+++) The Standby mode is entered thru HAL_PWR_EnterSTANDBYMode() API.\r
248                 SRAM1 and register contents are lost except for registers in the Backup domain and\r
249                 Standby circuitry. SRAM2 content can be preserved if the bit RRS is set in PWR_CR3 register.\r
250                 To enable this feature, the user can resort to HAL_PWREx_EnableSRAM2ContentRetention() API\r
251                 to set RRS bit.\r
252 \r
253       (++) Exit:\r
254           (+++) WKUP pin rising edge, RTC alarm or wakeup, tamper event, time-stamp event,\r
255                 external reset in NRST pin, IWDG reset.\r
256 \r
257       [..]    After waking up from Standby mode, program execution restarts in the same way as after a Reset.\r
258 \r
259 \r
260     *** Shutdown mode ***\r
261    ======================\r
262      [..]\r
263       In Shutdown mode,\r
264         voltage regulator is disabled, all clocks are off except LSE, RRS bit is cleared.\r
265         SRAM and registers contents are lost except for backup domain registers.\r
266 \r
267       (+) Entry:\r
268           The Shutdown mode is entered thru HAL_PWREx_EnterSHUTDOWNMode() API.\r
269 \r
270       (+) Exit:\r
271           (++) WKUP pin rising edge, RTC alarm or wakeup, tamper event, time-stamp event,\r
272                external reset in NRST pin.\r
273 \r
274          [..] After waking up from Shutdown mode, program execution restarts in the same way as after a Reset.\r
275 \r
276 \r
277    *** Auto-wakeup (AWU) from low-power mode ***\r
278    =============================================\r
279     [..]\r
280       The MCU can be woken up from low-power mode by an RTC Alarm event, an RTC\r
281       Wakeup event, a tamper event or a time-stamp event, without depending on\r
282       an external interrupt (Auto-wakeup mode).\r
283 \r
284       (+) RTC auto-wakeup (AWU) from the Stop, Standby and Shutdown modes\r
285 \r
286 \r
287         (++) To wake up from the Stop mode with an RTC alarm event, it is necessary to\r
288              configure the RTC to generate the RTC alarm using the HAL_RTC_SetAlarm_IT() function.\r
289 \r
290         (++) To wake up from the Stop mode with an RTC Tamper or time stamp event, it\r
291              is necessary to configure the RTC to detect the tamper or time stamp event using the\r
292              HAL_RTCEx_SetTimeStamp_IT() or HAL_RTCEx_SetTamper_IT() functions.\r
293 \r
294         (++) To wake up from the Stop mode with an RTC WakeUp event, it is necessary to\r
295               configure the RTC to generate the RTC WakeUp event using the HAL_RTCEx_SetWakeUpTimer_IT() function.\r
296 \r
297 @endverbatim\r
298   * @{\r
299   */\r
300 \r
301 \r
302 \r
303 /**\r
304   * @brief Configure the voltage threshold detected by the Power Voltage Detector (PVD).\r
305   * @param sConfigPVD: pointer to a PWR_PVDTypeDef structure that contains the PVD\r
306   *        configuration information.\r
307   * @note Refer to the electrical characteristics of your device datasheet for\r
308   *         more details about the voltage thresholds corresponding to each\r
309   *         detection level.\r
310   * @retval None\r
311   */\r
312 HAL_StatusTypeDef HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD)\r
313 {\r
314   /* Check the parameters */\r
315   assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel));\r
316   assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode));\r
317 \r
318   /* Set PLS bits according to PVDLevel value */\r
319   MODIFY_REG(PWR->CR2, PWR_CR2_PLS, sConfigPVD->PVDLevel);\r
320 \r
321   /* Clear any previous config. Keep it clear if no event or IT mode is selected */\r
322   __HAL_PWR_PVD_EXTI_DISABLE_EVENT();\r
323   __HAL_PWR_PVD_EXTI_DISABLE_IT();\r
324   __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE();\r
325   __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();\r
326 \r
327   /* Configure interrupt mode */\r
328   if((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT)\r
329   {\r
330     __HAL_PWR_PVD_EXTI_ENABLE_IT();\r
331   }\r
332 \r
333   /* Configure event mode */\r
334   if((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT)\r
335   {\r
336     __HAL_PWR_PVD_EXTI_ENABLE_EVENT();\r
337   }\r
338 \r
339   /* Configure the edge */\r
340   if((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE)\r
341   {\r
342     __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();\r
343   }\r
344 \r
345   if((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE)\r
346   {\r
347     __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();\r
348   }\r
349 \r
350   return HAL_OK;\r
351 }\r
352 \r
353 \r
354 /**\r
355   * @brief Enable the Power Voltage Detector (PVD).\r
356   * @retval None\r
357   */\r
358 void HAL_PWR_EnablePVD(void)\r
359 {\r
360   SET_BIT(PWR->CR2, PWR_CR2_PVDE);\r
361 }\r
362 \r
363 /**\r
364   * @brief Disable the Power Voltage Detector (PVD).\r
365   * @retval None\r
366   */\r
367 void HAL_PWR_DisablePVD(void)\r
368 {\r
369   CLEAR_BIT(PWR->CR2, PWR_CR2_PVDE);\r
370 }\r
371 \r
372 \r
373 \r
374 \r
375 /**\r
376   * @brief Enable the WakeUp PINx functionality.\r
377   * @param WakeUpPinPolarity: Specifies which Wake-Up pin to enable.\r
378   *         This parameter can be one of the following legacy values which set the default polarity\r
379   *         i.e. detection on high level (rising edge):\r
380   *           @arg @ref PWR_WAKEUP_PIN1, PWR_WAKEUP_PIN2, PWR_WAKEUP_PIN3, PWR_WAKEUP_PIN4, PWR_WAKEUP_PIN5\r
381   *\r
382   *         or one of the following value where the user can explicitly specify the enabled pin and\r
383   *         the chosen polarity:\r
384   *           @arg @ref PWR_WAKEUP_PIN1_HIGH or PWR_WAKEUP_PIN1_LOW\r
385   *           @arg @ref PWR_WAKEUP_PIN2_HIGH or PWR_WAKEUP_PIN2_LOW\r
386   *           @arg @ref PWR_WAKEUP_PIN3_HIGH or PWR_WAKEUP_PIN3_LOW\r
387   *           @arg @ref PWR_WAKEUP_PIN4_HIGH or PWR_WAKEUP_PIN4_LOW\r
388   *           @arg @ref PWR_WAKEUP_PIN5_HIGH or PWR_WAKEUP_PIN5_LOW\r
389   * @note  PWR_WAKEUP_PINx and PWR_WAKEUP_PINx_HIGH are equivalent.\r
390   * @retval None\r
391   */\r
392 void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity)\r
393 {\r
394   assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinPolarity));\r
395 \r
396   /* Specifies the Wake-Up pin polarity for the event detection\r
397     (rising or falling edge) */\r
398   MODIFY_REG(PWR->CR4, (PWR_CR3_EWUP & WakeUpPinPolarity), (WakeUpPinPolarity >> PWR_WUP_POLARITY_SHIFT));\r
399 \r
400   /* Enable wake-up pin */\r
401   SET_BIT(PWR->CR3, (PWR_CR3_EWUP & WakeUpPinPolarity));\r
402 \r
403 \r
404 }\r
405 \r
406 /**\r
407   * @brief Disable the WakeUp PINx functionality.\r
408   * @param WakeUpPinx: Specifies the Power Wake-Up pin to disable.\r
409   *         This parameter can be one of the following values:\r
410   *           @arg @ref PWR_WAKEUP_PIN1, PWR_WAKEUP_PIN2, PWR_WAKEUP_PIN3, PWR_WAKEUP_PIN4, PWR_WAKEUP_PIN5\r
411   * @retval None\r
412   */\r
413 void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx)\r
414 {\r
415   assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));\r
416 \r
417   CLEAR_BIT(PWR->CR3, (PWR_CR3_EWUP & WakeUpPinx));\r
418 }\r
419 \r
420 \r
421 /**\r
422   * @brief Enter Sleep or Low-power Sleep mode.\r
423   * @note  In Sleep/Low-power Sleep mode, all I/O pins keep the same state as in Run mode.\r
424   * @param Regulator: Specifies the regulator state in Sleep/Low-power Sleep mode.\r
425   *          This parameter can be one of the following values:\r
426   *            @arg @ref PWR_MAINREGULATOR_ON Sleep mode (regulator in main mode)\r
427   *            @arg @ref PWR_LOWPOWERREGULATOR_ON Low-power Sleep mode (regulator in low-power mode)\r
428   * @note  Low-power Sleep mode is entered from Low-power Run mode. Therefore, if not yet\r
429   *        in Low-power Run mode before calling HAL_PWR_EnterSLEEPMode() with Regulator set\r
430   *        to PWR_LOWPOWERREGULATOR_ON, the user can optionally configure the\r
431   *        Flash in power-down monde in setting the SLEEP_PD bit in FLASH_ACR register.\r
432   *        Additionally, the clock frequency must be reduced below 2 MHz.\r
433   *        Setting SLEEP_PD in FLASH_ACR then appropriately reducing the clock frequency must\r
434   *        be done before calling HAL_PWR_EnterSLEEPMode() API.\r
435   * @note  When exiting Low-power Sleep mode, the MCU is in Low-power Run mode. To move in\r
436   *        Run mode, the user must resort to HAL_PWREx_DisableLowPowerRunMode() API.\r
437   * @param SLEEPEntry: Specifies if Sleep mode is entered with WFI or WFE instruction.\r
438   *           This parameter can be one of the following values:\r
439   *            @arg @ref PWR_SLEEPENTRY_WFI enter Sleep or Low-power Sleep mode with WFI instruction\r
440   *            @arg @ref PWR_SLEEPENTRY_WFE enter Sleep or Low-power Sleep mode with WFE instruction\r
441   * @note  When WFI entry is used, tick interrupt have to be disabled if not desired as\r
442   *        the interrupt wake up source.\r
443   * @retval None\r
444   */\r
445 void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)\r
446 {\r
447   /* Check the parameters */\r
448   assert_param(IS_PWR_REGULATOR(Regulator));\r
449   assert_param(IS_PWR_SLEEP_ENTRY(SLEEPEntry));\r
450 \r
451   /* Set Regulator parameter */\r
452   if (Regulator == PWR_MAINREGULATOR_ON)\r
453   {\r
454     /* If in low-power run mode at this point, exit it */\r
455     if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_REGLPF))\r
456     {\r
457       if (HAL_PWREx_DisableLowPowerRunMode() != HAL_OK)\r
458       {\r
459         return ;\r
460       }\r
461     }\r
462     /* Regulator now in main mode. */\r
463   }\r
464   else\r
465   {\r
466     /* If in run mode, first move to low-power run mode.\r
467        The system clock frequency must be below 2 MHz at this point. */\r
468     if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_REGLPF) == RESET)\r
469     {\r
470       HAL_PWREx_EnableLowPowerRunMode();\r
471     }\r
472   }\r
473 \r
474   /* Clear SLEEPDEEP bit of Cortex System Control Register */\r
475   CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));\r
476 \r
477   /* Select SLEEP mode entry -------------------------------------------------*/\r
478   if(SLEEPEntry == PWR_SLEEPENTRY_WFI)\r
479   {\r
480     /* Request Wait For Interrupt */\r
481     __WFI();\r
482   }\r
483   else\r
484   {\r
485     /* Request Wait For Event */\r
486     __SEV();\r
487     __WFE();\r
488     __WFE();\r
489   }\r
490 \r
491 }\r
492 \r
493 \r
494 /**\r
495   * @brief Enter Stop mode\r
496   * @note  This API is named HAL_PWR_EnterSTOPMode to ensure compatibility with legacy code running\r
497   *        on devices where only "Stop mode" is mentioned with main or low power regulator ON.\r
498   * @note  In Stop mode, all I/O pins keep the same state as in Run mode.\r
499   * @note  All clocks in the VCORE domain are stopped; the PLL, the MSI,\r
500   *        the HSI and the HSE oscillators are disabled. Some peripherals with the wakeup capability\r
501   *        (I2Cx, USARTx and LPUART) can switch on the HSI to receive a frame, and switch off the HSI\r
502   *        after receiving the frame if it is not a wakeup frame. In this case, the HSI clock is propagated\r
503   *        only to the peripheral requesting it.\r
504   *        SRAM1, SRAM2 and register contents are preserved.\r
505   *        The BOR is available.\r
506   *        The voltage regulator can be configured either in normal (Stop 0) or low-power mode (Stop 1).\r
507   * @note  When exiting Stop 0 or Stop 1 mode by issuing an interrupt or a wakeup event,\r
508   *         the HSI RC oscillator is selected as system clock if STOPWUCK bit in RCC_CFGR register\r
509   *         is set; the MSI oscillator is selected if STOPWUCK is cleared.\r
510   * @note  When the voltage regulator operates in low power mode (Stop 1), an additional\r
511   *         startup delay is incurred when waking up.\r
512   *         By keeping the internal regulator ON during Stop mode (Stop 0), the consumption\r
513   *         is higher although the startup time is reduced.\r
514   * @param Regulator: Specifies the regulator state in Stop mode.\r
515   *          This parameter can be one of the following values:\r
516   *            @arg @ref PWR_MAINREGULATOR_ON  Stop 0 mode (main regulator ON)\r
517   *            @arg @ref PWR_LOWPOWERREGULATOR_ON  Stop 1 mode (low power regulator ON)\r
518   * @param STOPEntry: Specifies Stop 0 or Stop 1 mode is entered with WFI or WFE instruction.\r
519   *          This parameter can be one of the following values:\r
520   *            @arg @ref PWR_STOPENTRY_WFI  Enter Stop 0 or Stop 1 mode with WFI instruction.\r
521   *            @arg @ref PWR_STOPENTRY_WFE  Enter Stop 0 or Stop 1 mode with WFE instruction.\r
522   * @retval None\r
523   */\r
524 void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)\r
525 {\r
526   /* Check the parameters */\r
527   assert_param(IS_PWR_REGULATOR(Regulator));\r
528 \r
529   if(Regulator == PWR_LOWPOWERREGULATOR_ON)\r
530   {\r
531     HAL_PWREx_EnterSTOP1Mode(STOPEntry);\r
532   }\r
533   else\r
534   {\r
535     HAL_PWREx_EnterSTOP0Mode(STOPEntry);\r
536   }\r
537 }\r
538 \r
539 /**\r
540   * @brief Enter Standby mode.\r
541   * @note  In Standby mode, the PLL, the HSI, the MSI and the HSE oscillators are switched\r
542   *        off. The voltage regulator is disabled, except when SRAM2 content is preserved\r
543   *        in which case the regulator is in low-power mode.\r
544   *        SRAM1 and register contents are lost except for registers in the Backup domain and\r
545   *        Standby circuitry. SRAM2 content can be preserved if the bit RRS is set in PWR_CR3 register.\r
546   *        To enable this feature, the user can resort to HAL_PWREx_EnableSRAM2ContentRetention() API\r
547   *        to set RRS bit.\r
548   *        The BOR is available.\r
549   * @note  The I/Os can be configured either with a pull-up or pull-down or can be kept in analog state.\r
550   *        HAL_PWREx_EnableGPIOPullUp() and HAL_PWREx_EnableGPIOPullDown() respectively enable Pull Up and\r
551   *        Pull Down state, HAL_PWREx_DisableGPIOPullUp() and HAL_PWREx_DisableGPIOPullDown() disable the\r
552   *        same.\r
553   *        These states are effective in Standby mode only if APC bit is set through\r
554   *        HAL_PWREx_EnablePullUpPullDownConfig() API.\r
555   * @retval None\r
556   */\r
557 void HAL_PWR_EnterSTANDBYMode(void)\r
558 {\r
559   /* Set Stand-by mode */\r
560   MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_STANDBY);\r
561 \r
562   /* Set SLEEPDEEP bit of Cortex System Control Register */\r
563   SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));\r
564 \r
565 /* This option is used to ensure that store operations are completed */\r
566 #if defined ( __CC_ARM)\r
567   __force_stores();\r
568 #endif\r
569   /* Request Wait For Interrupt */\r
570   __WFI();\r
571 }\r
572 \r
573 \r
574 \r
575 /**\r
576   * @brief Indicate Sleep-On-Exit when returning from Handler mode to Thread mode.\r
577   * @note Set SLEEPONEXIT bit of SCR register. When this bit is set, the processor\r
578   *       re-enters SLEEP mode when an interruption handling is over.\r
579   *       Setting this bit is useful when the processor is expected to run only on\r
580   *       interruptions handling.\r
581   * @retval None\r
582   */\r
583 void HAL_PWR_EnableSleepOnExit(void)\r
584 {\r
585   /* Set SLEEPONEXIT bit of Cortex System Control Register */\r
586   SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));\r
587 }\r
588 \r
589 \r
590 /**\r
591   * @brief Disable Sleep-On-Exit feature when returning from Handler mode to Thread mode.\r
592   * @note Clear SLEEPONEXIT bit of SCR register. When this bit is set, the processor\r
593   *       re-enters SLEEP mode when an interruption handling is over.\r
594   * @retval None\r
595   */\r
596 void HAL_PWR_DisableSleepOnExit(void)\r
597 {\r
598   /* Clear SLEEPONEXIT bit of Cortex System Control Register */\r
599   CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));\r
600 }\r
601 \r
602 \r
603 \r
604 /**\r
605   * @brief Enable CORTEX M4 SEVONPEND bit.\r
606   * @note Set SEVONPEND bit of SCR register. When this bit is set, this causes\r
607   *       WFE to wake up when an interrupt moves from inactive to pended.\r
608   * @retval None\r
609   */\r
610 void HAL_PWR_EnableSEVOnPend(void)\r
611 {\r
612   /* Set SEVONPEND bit of Cortex System Control Register */\r
613   SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));\r
614 }\r
615 \r
616 \r
617 /**\r
618   * @brief Disable CORTEX M4 SEVONPEND bit.\r
619   * @note Clear SEVONPEND bit of SCR register. When this bit is set, this causes\r
620   *       WFE to wake up when an interrupt moves from inactive to pended.\r
621   * @retval None\r
622   */\r
623 void HAL_PWR_DisableSEVOnPend(void)\r
624 {\r
625   /* Clear SEVONPEND bit of Cortex System Control Register */\r
626   CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));\r
627 }\r
628 \r
629 \r
630 \r
631 \r
632 \r
633 /**\r
634   * @brief PWR PVD interrupt callback\r
635   * @retval None\r
636   */\r
637 __weak void HAL_PWR_PVDCallback(void)\r
638 {\r
639   /* NOTE : This function should not be modified; when the callback is needed,\r
640             the HAL_PWR_PVDCallback can be implemented in the user file\r
641    */\r
642 }\r
643 \r
644 /**\r
645   * @}\r
646   */\r
647 \r
648 /**\r
649   * @}\r
650   */\r
651 \r
652 #endif /* HAL_PWR_MODULE_ENABLED */\r
653 /**\r
654   * @}\r
655   */\r
656 \r
657 /**\r
658   * @}\r
659   */\r
660 \r
661 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r