STM32F4xx_HAL_Driver  1.8.3
stm32f4xx_hal_pwr.c
Go to the documentation of this file.
1 
23 /* Includes ------------------------------------------------------------------*/
24 #include "stm32f4xx_hal.h"
25 
35 #ifdef HAL_PWR_MODULE_ENABLED
36 
37 /* Private typedef -----------------------------------------------------------*/
38 /* Private define ------------------------------------------------------------*/
46 #define PVD_MODE_IT 0x00010000U
47 #define PVD_MODE_EVT 0x00020000U
48 #define PVD_RISING_EDGE 0x00000001U
49 #define PVD_FALLING_EDGE 0x00000002U
57 /* Private macro -------------------------------------------------------------*/
58 /* Private variables ---------------------------------------------------------*/
59 /* Private function prototypes -----------------------------------------------*/
60 /* Private functions ---------------------------------------------------------*/
61 
90 void HAL_PWR_DeInit(void)
91 {
92  __HAL_RCC_PWR_FORCE_RESET();
93  __HAL_RCC_PWR_RELEASE_RESET();
94 }
95 
109 {
110  __IO uint32_t dummyread;
111  *(__IO uint32_t *) CR_DBP_BB = (uint32_t)ENABLE;
112  dummyread = PWR->CR;
113  UNUSED(dummyread);
114 }
115 
129 {
130  __IO uint32_t dummyread;
131  *(__IO uint32_t *) CR_DBP_BB = (uint32_t)DISABLE;
132  dummyread = PWR->CR;
133  UNUSED(dummyread);
134 }
135 
275 void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD)
276 {
277  /* Check the parameters */
278  assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel));
279  assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode));
280 
281  /* Set PLS[7:5] bits according to PVDLevel value */
282  MODIFY_REG(PWR->CR, PWR_CR_PLS, sConfigPVD->PVDLevel);
283 
284  /* Clear any previous config. Keep it clear if no event or IT mode is selected */
285  __HAL_PWR_PVD_EXTI_DISABLE_EVENT();
286  __HAL_PWR_PVD_EXTI_DISABLE_IT();
287  __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();
288  __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE();
289 
290  /* Configure interrupt mode */
291  if((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT)
292  {
293  __HAL_PWR_PVD_EXTI_ENABLE_IT();
294  }
295 
296  /* Configure event mode */
297  if((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT)
298  {
299  __HAL_PWR_PVD_EXTI_ENABLE_EVENT();
300  }
301 
302  /* Configure the edge */
303  if((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE)
304  {
305  __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();
306  }
307 
308  if((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE)
309  {
310  __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();
311  }
312 }
313 
319 {
320  *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)ENABLE;
321 }
322 
328 {
329  *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)DISABLE;
330 }
331 
341 void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx)
342 {
343  /* Check the parameter */
344  assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
345 
346  /* Enable the wake up pin */
347  SET_BIT(PWR->CSR, WakeUpPinx);
348 }
349 
359 void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx)
360 {
361  /* Check the parameter */
362  assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
363 
364  /* Disable the wake up pin */
365  CLEAR_BIT(PWR->CSR, WakeUpPinx);
366 }
367 
391 void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)
392 {
393  /* Prevent unused argument(s) compilation warning */
394  UNUSED(Regulator);
395 
396  /* Check the parameters */
397  assert_param(IS_PWR_REGULATOR(Regulator));
398  assert_param(IS_PWR_SLEEP_ENTRY(SLEEPEntry));
399 
400  /* Clear SLEEPDEEP bit of Cortex System Control Register */
401  CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
402 
403  /* Select SLEEP mode entry -------------------------------------------------*/
404  if(SLEEPEntry == PWR_SLEEPENTRY_WFI)
405  {
406  /* Request Wait For Interrupt */
407  __WFI();
408  }
409  else
410  {
411  if(SLEEPEntry != PWR_SLEEPENTRY_WFE_NO_EVT_CLEAR)
412  {
413  /* Clear all pending event */
414  __SEV();
415  __WFE();
416  }
417 
418  /* Request Wait For Event */
419  __WFE();
420  }
421 }
422 
445 void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
446 {
447  /* Check the parameters */
448  assert_param(IS_PWR_REGULATOR(Regulator));
449  assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
450 
451  /* Select the regulator state in Stop mode: Set PDDS and LPDS bits according to PWR_Regulator value */
452  MODIFY_REG(PWR->CR, (PWR_CR_PDDS | PWR_CR_LPDS), Regulator);
453 
454  /* Set SLEEPDEEP bit of Cortex System Control Register */
455  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
456 
457  /* Select Stop mode entry --------------------------------------------------*/
458  if(STOPEntry == PWR_STOPENTRY_WFI)
459  {
460  /* Request Wait For Interrupt */
461  __WFI();
462  }
463  else
464  {
465  if(STOPEntry != PWR_STOPENTRY_WFE_NO_EVT_CLEAR)
466  {
467  /* Clear all pending event */
468  __SEV();
469  __WFE();
470  }
471  /* Request Wait For Event */
472  __WFE();
473  }
474  /* Reset SLEEPDEEP bit of Cortex System Control Register */
475  CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
476 }
477 
489 {
490  /* Select Standby mode */
491  SET_BIT(PWR->CR, PWR_CR_PDDS);
492 
493  /* Set SLEEPDEEP bit of Cortex System Control Register */
494  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
495 
496  /* This option is used to ensure that store operations are completed */
497 #if defined ( __CC_ARM)
498  __force_stores();
499 #endif
500  /* Request Wait For Interrupt */
501  __WFI();
502 }
503 
510 {
511  /* Check PWR Exti flag */
512  if(__HAL_PWR_PVD_EXTI_GET_FLAG() != RESET)
513  {
514  /* PWR PVD interrupt user callback */
516 
517  /* Clear PWR Exti pending bit */
518  __HAL_PWR_PVD_EXTI_CLEAR_FLAG();
519  }
520 }
521 
526 __weak void HAL_PWR_PVDCallback(void)
527 {
528  /* NOTE : This function Should not be modified, when the callback is needed,
529  the HAL_PWR_PVDCallback could be implemented in the user file
530  */
531 }
532 
542 {
543  /* Set SLEEPONEXIT bit of Cortex System Control Register */
544  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
545 }
546 
554 {
555  /* Clear SLEEPONEXIT bit of Cortex System Control Register */
556  CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
557 }
558 
566 {
567  /* Set SEVONPEND bit of Cortex System Control Register */
568  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
569 }
570 
578 {
579  /* Clear SEVONPEND bit of Cortex System Control Register */
580  CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
581 }
582 
591 #endif /* HAL_PWR_MODULE_ENABLED */
void HAL_PWR_DisableBkUpAccess(void)
Disables access to the backup domain (RTC registers, RTC backup data registers and backup SRAM).
void HAL_PWR_EnableBkUpAccess(void)
Enables access to the backup domain (RTC registers, RTC backup data registers and backup SRAM).
void HAL_PWR_DeInit(void)
Deinitializes the HAL PWR peripheral registers to their default reset values.
void HAL_PWR_DisableSleepOnExit(void)
Disables Sleep-On-Exit feature when returning from Handler mode to Thread mode.
void HAL_PWR_DisablePVD(void)
Disables the Power Voltage Detector(PVD).
void HAL_PWR_EnterSTANDBYMode(void)
Enters Standby mode.
void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)
Enters Sleep mode.
void HAL_PWR_EnableSEVOnPend(void)
Enables CORTEX M4 SEVONPEND bit.
void HAL_PWR_EnablePVD(void)
Enables the Power Voltage Detector(PVD).
void HAL_PWR_PVDCallback(void)
PWR PVD interrupt callback.
void HAL_PWR_DisableSEVOnPend(void)
Disables CORTEX M4 SEVONPEND bit.
void HAL_PWR_EnableSleepOnExit(void)
Indicates Sleep-On-Exit when returning from Handler mode to Thread mode.
void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD)
Configures the voltage threshold detected by the Power Voltage Detector(PVD).
void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx)
Enables the Wake-up PINx functionality.
void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx)
Disables the Wake-up PINx functionality.
void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
Enters Stop mode.
void HAL_PWR_PVD_IRQHandler(void)
This function handles the PWR PVD interrupt request.
This file contains all the functions prototypes for the HAL module driver.