STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_hal_pwr.c
Go to the documentation of this file.
1 
25 /* Includes ------------------------------------------------------------------*/
26 #include "stm32l4xx_hal.h"
27 
37 #ifdef HAL_PWR_MODULE_ENABLED
38 
39 /* Private typedef -----------------------------------------------------------*/
40 /* Private define ------------------------------------------------------------*/
41 
49 #define PVD_MODE_IT ((uint32_t)0x00010000)
50 #define PVD_MODE_EVT ((uint32_t)0x00020000)
51 #define PVD_RISING_EDGE ((uint32_t)0x00000001)
52 #define PVD_FALLING_EDGE ((uint32_t)0x00000002)
61 /* Private macro -------------------------------------------------------------*/
62 /* Private variables ---------------------------------------------------------*/
63 /* Private function prototypes -----------------------------------------------*/
64 /* Exported functions --------------------------------------------------------*/
65 
87 void HAL_PWR_DeInit(void)
88 {
89  __HAL_RCC_PWR_FORCE_RESET();
90  __HAL_RCC_PWR_RELEASE_RESET();
91 }
92 
106 {
107  SET_BIT(PWR->CR1, PWR_CR1_DBP);
108 }
109 
116 {
117  CLEAR_BIT(PWR->CR1, PWR_CR1_DBP);
118 }
119 
120 
121 
122 
312 HAL_StatusTypeDef HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD)
313 {
314  /* Check the parameters */
315  assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel));
316  assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode));
317 
318  /* Set PLS bits according to PVDLevel value */
319  MODIFY_REG(PWR->CR2, PWR_CR2_PLS, sConfigPVD->PVDLevel);
320 
321  /* Clear any previous config. Keep it clear if no event or IT mode is selected */
322  __HAL_PWR_PVD_EXTI_DISABLE_EVENT();
323  __HAL_PWR_PVD_EXTI_DISABLE_IT();
324  __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE();
325  __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();
326 
327  /* Configure interrupt mode */
328  if((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT)
329  {
330  __HAL_PWR_PVD_EXTI_ENABLE_IT();
331  }
332 
333  /* Configure event mode */
334  if((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT)
335  {
336  __HAL_PWR_PVD_EXTI_ENABLE_EVENT();
337  }
338 
339  /* Configure the edge */
340  if((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE)
341  {
342  __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();
343  }
344 
345  if((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE)
346  {
347  __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();
348  }
349 
350  return HAL_OK;
351 }
352 
353 
359 {
360  SET_BIT(PWR->CR2, PWR_CR2_PVDE);
361 }
362 
368 {
369  CLEAR_BIT(PWR->CR2, PWR_CR2_PVDE);
370 }
371 
372 
373 
374 
392 void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity)
393 {
394  assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinPolarity));
395 
396  /* Specifies the Wake-Up pin polarity for the event detection
397  (rising or falling edge) */
398  MODIFY_REG(PWR->CR4, (PWR_CR3_EWUP & WakeUpPinPolarity), (WakeUpPinPolarity >> PWR_WUP_POLARITY_SHIFT));
399 
400  /* Enable wake-up pin */
401  SET_BIT(PWR->CR3, (PWR_CR3_EWUP & WakeUpPinPolarity));
402 
403 
404 }
405 
413 void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx)
414 {
415  assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
416 
417  CLEAR_BIT(PWR->CR3, (PWR_CR3_EWUP & WakeUpPinx));
418 }
419 
420 
445 void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)
446 {
447  /* Check the parameters */
448  assert_param(IS_PWR_REGULATOR(Regulator));
449  assert_param(IS_PWR_SLEEP_ENTRY(SLEEPEntry));
450 
451  /* Set Regulator parameter */
452  if (Regulator == PWR_MAINREGULATOR_ON)
453  {
454  /* If in low-power run mode at this point, exit it */
455  if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_REGLPF))
456  {
458  {
459  return ;
460  }
461  }
462  /* Regulator now in main mode. */
463  }
464  else
465  {
466  /* If in run mode, first move to low-power run mode.
467  The system clock frequency must be below 2 MHz at this point. */
468  if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_REGLPF) == RESET)
469  {
471  }
472  }
473 
474  /* Clear SLEEPDEEP bit of Cortex System Control Register */
475  CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
476 
477  /* Select SLEEP mode entry -------------------------------------------------*/
478  if(SLEEPEntry == PWR_SLEEPENTRY_WFI)
479  {
480  /* Request Wait For Interrupt */
481  __WFI();
482  }
483  else
484  {
485  /* Request Wait For Event */
486  __SEV();
487  __WFE();
488  __WFE();
489  }
490 
491 }
492 
493 
524 void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
525 {
526  /* Check the parameters */
527  assert_param(IS_PWR_REGULATOR(Regulator));
528 
529  if(Regulator == PWR_LOWPOWERREGULATOR_ON)
530  {
531  HAL_PWREx_EnterSTOP1Mode(STOPEntry);
532  }
533  else
534  {
535  HAL_PWREx_EnterSTOP0Mode(STOPEntry);
536  }
537 }
538 
558 {
559  /* Set Stand-by mode */
560  MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_STANDBY);
561 
562  /* Set SLEEPDEEP bit of Cortex System Control Register */
563  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
564 
565 /* This option is used to ensure that store operations are completed */
566 #if defined ( __CC_ARM)
567  __force_stores();
568 #endif
569  /* Request Wait For Interrupt */
570  __WFI();
571 }
572 
573 
574 
584 {
585  /* Set SLEEPONEXIT bit of Cortex System Control Register */
586  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
587 }
588 
589 
597 {
598  /* Clear SLEEPONEXIT bit of Cortex System Control Register */
599  CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
600 }
601 
602 
603 
611 {
612  /* Set SEVONPEND bit of Cortex System Control Register */
613  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
614 }
615 
616 
624 {
625  /* Clear SEVONPEND bit of Cortex System Control Register */
626  CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
627 }
628 
629 
630 
631 
632 
637 __weak void HAL_PWR_PVDCallback(void)
638 {
639  /* NOTE : This function should not be modified; when the callback is needed,
640  the HAL_PWR_PVDCallback can be implemented in the user file
641  */
642 }
643 
652 #endif /* HAL_PWR_MODULE_ENABLED */
653 
661 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
HAL_StatusTypeDef HAL_PWREx_DisableLowPowerRunMode(void)
Exit Low-power Run mode.
return(brrresult)
void HAL_PWR_EnablePVD(void)
Enable the Power Voltage Detector (PVD).
void HAL_PWR_EnterSTANDBYMode(void)
Enter Standby mode.
This file contains all the functions prototypes for the HAL module driver.
void HAL_PWR_DisableSEVOnPend(void)
Disable CORTEX M4 SEVONPEND bit.
void HAL_PWREx_EnterSTOP1Mode(uint8_t STOPEntry)
Enter Stop 1 mode.
void HAL_PWR_DisableBkUpAccess(void)
Disable access to the backup domain (RTC registers, RTC backup data registers).
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
void HAL_PWR_EnableSleepOnExit(void)
Indicate Sleep-On-Exit when returning from Handler mode to Thread mode.
void HAL_PWR_EnableBkUpAccess(void)
Enable access to the backup domain (RTC registers, RTC backup data registers).
return HAL_OK
HAL_StatusTypeDef HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD)
Configure the voltage threshold detected by the Power Voltage Detector (PVD).
void HAL_PWR_DeInit(void)
Deinitialize the HAL PWR peripheral registers to their default reset values.
void HAL_PWR_EnableSEVOnPend(void)
Enable CORTEX M4 SEVONPEND bit.
void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx)
Disable the WakeUp PINx functionality.
void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity)
Enable the WakeUp PINx functionality.
void HAL_PWREx_EnterSTOP0Mode(uint8_t STOPEntry)
Enter Stop 0 mode.
void HAL_PWR_DisablePVD(void)
Disable the Power Voltage Detector (PVD).
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
Enter Stop mode.
void HAL_PWR_DisableSleepOnExit(void)
Disable Sleep-On-Exit feature when returning from Handler mode to Thread mode.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)
Enter Sleep or Low-power Sleep mode.
void HAL_PWR_PVDCallback(void)
PWR PVD interrupt callback.
void HAL_PWREx_EnableLowPowerRunMode(void)
Enter Low-power Run mode.