STM32F4xx HAL Documentation
Hardware Abstraction Layer for STM32F4 familiy
Loading...
Searching...
No Matches
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
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
276{
277 /* Check the parameters */
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 */
289
290 /* Configure interrupt mode */
291 if((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT)
292 {
294 }
295
296 /* Configure event mode */
297 if((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT)
298 {
300 }
301
302 /* Configure the edge */
303 if((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE)
304 {
306 }
307
308 if((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE)
309 {
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
341void 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
359void 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
391void 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
445void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
446{
447 /* Check the parameters */
448 assert_param(IS_PWR_REGULATOR(Regulator));
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 */
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 */
#define IS_PWR_WAKEUP_PIN(PIN)
#define CR_PVDE_BB
#define CR_DBP_BB
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.
#define __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE()
Disable the PVD Extended Interrupt Falling Trigger.
#define __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE()
Disable the PVD Extended Interrupt Rising Trigger.
#define __HAL_PWR_PVD_EXTI_ENABLE_IT()
Enable the PVD Exti Line 16.
#define __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE()
Enable the PVD Extended Interrupt Falling Trigger.
#define __HAL_PWR_PVD_EXTI_GET_FLAG()
checks whether the specified PVD Exti interrupt flag is set or not.
#define __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE()
Enable the PVD Extended Interrupt Rising Trigger.
#define __HAL_PWR_PVD_EXTI_DISABLE_EVENT()
Disable event on PVD Exti Line 16.
#define __HAL_PWR_PVD_EXTI_CLEAR_FLAG()
Clear the PVD Exti flag.
#define __HAL_PWR_PVD_EXTI_DISABLE_IT()
Disable the PVD EXTI Line 16.
#define __HAL_PWR_PVD_EXTI_ENABLE_EVENT()
Enable event on PVD Exti Line 16.
#define IS_PWR_REGULATOR(REGULATOR)
#define IS_PWR_STOP_ENTRY(ENTRY)
#define IS_PWR_PVD_MODE(MODE)
#define IS_PWR_SLEEP_ENTRY(ENTRY)
#define IS_PWR_PVD_LEVEL(LEVEL)
#define PVD_RISING_EDGE
#define PVD_MODE_EVT
#define PVD_FALLING_EDGE
#define PVD_MODE_IT
#define PWR_SLEEPENTRY_WFI
#define PWR_SLEEPENTRY_WFE_NO_EVT_CLEAR
#define PWR_STOPENTRY_WFI
#define PWR_STOPENTRY_WFE_NO_EVT_CLEAR
#define __HAL_RCC_PWR_RELEASE_RESET()
#define __HAL_RCC_PWR_FORCE_RESET()
#define assert_param(expr)
This file contains all the functions prototypes for the HAL module driver.
#define UNUSED(X)
PWR PVD configuration structure definition.