1 /**
2   ******************************************************************************
3   * @file    stm32f3xx_hal_pwr.h
4   * @author  MCD Application Team
5   * @brief   Header file of PWR HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2016 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef __STM32F3xx_HAL_PWR_H
21 #define __STM32F3xx_HAL_PWR_H
22 
23 #ifdef __cplusplus
24  extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32f3xx_hal_def.h"
29 
30 /** @addtogroup STM32F3xx_HAL_Driver
31   * @{
32   */
33 
34 /** @addtogroup PWR PWR
35   * @{
36   */
37 
38 /* Exported types ------------------------------------------------------------*/
39 /* Exported constants --------------------------------------------------------*/
40 /** @defgroup PWR_Exported_Constants PWR Exported Constants
41   * @{
42   */
43 
44 /** @defgroup PWR_WakeUp_Pins PWR WakeUp Pins
45   * @{
46   */
47 
48 #define PWR_WAKEUP_PIN1                 ((uint32_t)PWR_CSR_EWUP1)   /*!< Wakeup pin 1U */
49 #define PWR_WAKEUP_PIN2                 ((uint32_t)PWR_CSR_EWUP2)   /*!< Wakeup pin 2U */
50 #define PWR_WAKEUP_PIN3                 ((uint32_t)PWR_CSR_EWUP3)   /*!< Wakeup pin 3U */
51 /**
52   * @}
53   */
54 
55 /** @defgroup PWR_Regulator_state_in_STOP_mode PWR Regulator state in STOP mode
56   * @{
57   */
58 #define PWR_MAINREGULATOR_ON         (0x00000000U) /*!< Voltage regulator on during STOP mode                */
59 #define PWR_LOWPOWERREGULATOR_ON     PWR_CR_LPDS            /*!< Voltage regulator in low-power mode during STOP mode */
60 /**
61   * @}
62   */
63 
64 /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry
65   * @{
66   */
67 #define PWR_SLEEPENTRY_WFI              ((uint8_t)0x01U)   /*!< Wait For Interruption instruction to enter SLEEP mode */
68 #define PWR_SLEEPENTRY_WFE              ((uint8_t)0x02U)   /*!< Wait For Event instruction to enter SLEEP mode        */
69 /**
70   * @}
71   */
72 
73 /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry
74   * @{
75   */
76 #define PWR_STOPENTRY_WFI               ((uint8_t)0x01U)   /*!< Wait For Interruption instruction to enter STOP mode */
77 #define PWR_STOPENTRY_WFE               ((uint8_t)0x02U)   /*!< Wait For Event instruction to enter STOP mode        */
78 /**
79   * @}
80   */
81 
82 /** @defgroup PWR_Flag PWR Flag
83   * @{
84   */
85 #define PWR_FLAG_WU                     PWR_CSR_WUF             /*!< Wakeup event from wakeup pin or RTC alarm */
86 #define PWR_FLAG_SB                     PWR_CSR_SBF             /*!< Standby flag                              */
87 #define PWR_FLAG_PVDO                   PWR_CSR_PVDO            /*!< Power Voltage Detector output flag        */
88 #define PWR_FLAG_VREFINTRDY             PWR_CSR_VREFINTRDYF     /*!< VREFINT reference voltage ready           */
89 /**
90   * @}
91   */
92 
93 /**
94   * @}
95   */
96 
97 /* Exported macro ------------------------------------------------------------*/
98 /** @defgroup PWR_Exported_Macro PWR Exported Macro
99   * @{
100   */
101 
102 /** @brief  Check PWR flag is set or not.
103   * @param  __FLAG__ specifies the flag to check.
104   *           This parameter can be one of the following values:
105   *            @arg PWR_FLAG_WU: Wake Up flag. This flag indicates that a wakeup event
106   *                  was received from the WKUP pin or from the RTC alarm (Alarm A
107   *                  or Alarm B), RTC Tamper event, RTC TimeStamp event or RTC Wakeup.
108   *                  An additional wakeup event is detected if the WKUP pin is enabled
109   *                  (by setting the EWUP bit) when the WKUP pin level is already high.
110   *            @arg PWR_FLAG_SB: StandBy flag. This flag indicates that the system was
111   *                  resumed from StandBy mode.
112   *            @arg PWR_FLAG_PVDO: PVD Output. This flag is valid only if PVD is enabled
113   *                  by the HAL_PWR_EnablePVD() function. The PVD is stopped by Standby mode
114   *                  For this reason, this bit is equal to 0 after Standby or reset
115   *                  until the PVDE bit is set.
116   *            @arg PWR_FLAG_VREFINTRDY: This flag indicates that the internal reference
117   *                  voltage VREFINT is ready.
118   * @retval The new state of __FLAG__ (TRUE or FALSE).
119   */
120 #define __HAL_PWR_GET_FLAG(__FLAG__) ((PWR->CSR & (__FLAG__)) == (__FLAG__))
121 
122 /** @brief  Clear the PWR's pending flags.
123   * @param  __FLAG__ specifies the flag to clear.
124   *          This parameter can be one of the following values:
125   *            @arg PWR_FLAG_WU: Wake Up flag
126   *            @arg PWR_FLAG_SB: StandBy flag
127   */
128 #define __HAL_PWR_CLEAR_FLAG(__FLAG__) (PWR->CR |=  (__FLAG__) << 2U)
129 
130 /**
131   * @}
132   */
133 
134 /* Private macros --------------------------------------------------------*/
135 /** @addtogroup  PWR_Private_Macros   PWR Private Macros
136   * @{
137   */
138 
139 #define IS_PWR_WAKEUP_PIN(PIN) (((PIN) == PWR_WAKEUP_PIN1) || \
140                                 ((PIN) == PWR_WAKEUP_PIN2) || \
141                                 ((PIN) == PWR_WAKEUP_PIN3))
142 
143 #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \
144                                      ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON))
145 
146 #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE))
147 
148 #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE))
149 
150 /**
151   * @}
152   */
153 
154 /* Include PWR HAL Extended module */
155 #include "stm32f3xx_hal_pwr_ex.h"
156 
157 /* Exported functions --------------------------------------------------------*/
158 
159 /** @addtogroup PWR_Exported_Functions PWR Exported Functions
160   * @{
161   */
162 
163 /** @addtogroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions
164   * @{
165   */
166 
167 /* Initialization and de-initialization functions *****************************/
168 void HAL_PWR_DeInit(void);
169 
170 /**
171   * @}
172   */
173 
174 /** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions
175   * @{
176   */
177 
178 /* Peripheral Control functions  **********************************************/
179 void HAL_PWR_EnableBkUpAccess(void);
180 void HAL_PWR_DisableBkUpAccess(void);
181 
182 /* WakeUp pins configuration functions ****************************************/
183 void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx);
184 void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx);
185 
186 /* Low Power modes configuration functions ************************************/
187 void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
188 void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry);
189 void HAL_PWR_EnterSTANDBYMode(void);
190 
191 void HAL_PWR_EnableSleepOnExit(void);
192 void HAL_PWR_DisableSleepOnExit(void);
193 void HAL_PWR_EnableSEVOnPend(void);
194 void HAL_PWR_DisableSEVOnPend(void);
195 /**
196   * @}
197   */
198 
199 /**
200   * @}
201   */
202 
203 /**
204   * @}
205   */
206 
207 /**
208   * @}
209   */
210 
211 #ifdef __cplusplus
212 }
213 #endif
214 
215 
216 #endif /* __STM32F3xx_HAL_PWR_H */
217