1 /**
2   ******************************************************************************
3   * @file    stm32f7xx_hal_pwr_ex.h
4   * @author  MCD Application Team
5   * @version V1.0.1
6   * @date    25-June-2015
7   * @brief   Header file of PWR HAL Extension module.
8   ******************************************************************************
9   * @attention
10   *
11   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
12   *
13   * Redistribution and use in source and binary forms, with or without modification,
14   * are permitted provided that the following conditions are met:
15   *   1. Redistributions of source code must retain the above copyright notice,
16   *      this list of conditions and the following disclaimer.
17   *   2. Redistributions in binary form must reproduce the above copyright notice,
18   *      this list of conditions and the following disclaimer in the documentation
19   *      and/or other materials provided with the distribution.
20   *   3. Neither the name of STMicroelectronics nor the names of its contributors
21   *      may be used to endorse or promote products derived from this software
22   *      without specific prior written permission.
23   *
24   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34   *
35   ******************************************************************************
36   */
37 
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F7xx_HAL_PWR_EX_H
40 #define __STM32F7xx_HAL_PWR_EX_H
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f7xx_hal_def.h"
48 
49 /** @addtogroup STM32F7xx_HAL_Driver
50   * @{
51   */
52 
53 /** @addtogroup PWREx
54   * @{
55   */
56 
57 /* Exported types ------------------------------------------------------------*/
58 /* Exported constants --------------------------------------------------------*/
59 /** @defgroup PWREx_Exported_Constants PWREx Exported Constants
60   * @{
61   */
62 /** @defgroup PWREx_WakeUp_Pins PWREx Wake Up Pins
63   * @{
64   */
65 #define PWR_WAKEUP_PIN1                PWR_CSR2_EWUP1
66 #define PWR_WAKEUP_PIN2                PWR_CSR2_EWUP2
67 #define PWR_WAKEUP_PIN3                PWR_CSR2_EWUP3
68 #define PWR_WAKEUP_PIN4                PWR_CSR2_EWUP4
69 #define PWR_WAKEUP_PIN5                PWR_CSR2_EWUP5
70 #define PWR_WAKEUP_PIN6                PWR_CSR2_EWUP6
71 #define PWR_WAKEUP_PIN1_HIGH           PWR_CSR2_EWUP1
72 #define PWR_WAKEUP_PIN2_HIGH           PWR_CSR2_EWUP2
73 #define PWR_WAKEUP_PIN3_HIGH           PWR_CSR2_EWUP3
74 #define PWR_WAKEUP_PIN4_HIGH           PWR_CSR2_EWUP4
75 #define PWR_WAKEUP_PIN5_HIGH           PWR_CSR2_EWUP5
76 #define PWR_WAKEUP_PIN6_HIGH           PWR_CSR2_EWUP6
77 #define PWR_WAKEUP_PIN1_LOW            (uint32_t)((PWR_CR2_WUPP1<<6) | PWR_CSR2_EWUP1)
78 #define PWR_WAKEUP_PIN2_LOW            (uint32_t)((PWR_CR2_WUPP2<<6) | PWR_CSR2_EWUP2)
79 #define PWR_WAKEUP_PIN3_LOW            (uint32_t)((PWR_CR2_WUPP3<<6) | PWR_CSR2_EWUP3)
80 #define PWR_WAKEUP_PIN4_LOW            (uint32_t)((PWR_CR2_WUPP4<<6) | PWR_CSR2_EWUP4)
81 #define PWR_WAKEUP_PIN5_LOW            (uint32_t)((PWR_CR2_WUPP5<<6) | PWR_CSR2_EWUP5)
82 #define PWR_WAKEUP_PIN6_LOW            (uint32_t)((PWR_CR2_WUPP6<<6) | PWR_CSR2_EWUP6)
83 
84 /**
85   * @}
86   */
87 
88 /** @defgroup PWREx_Regulator_state_in_UnderDrive_mode PWREx Regulator state in UnderDrive mode
89   * @{
90   */
91 #define PWR_MAINREGULATOR_UNDERDRIVE_ON                       PWR_CR1_MRUDS
92 #define PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON                   ((uint32_t)(PWR_CR1_LPDS | PWR_CR1_LPUDS))
93 /**
94   * @}
95   */
96 
97 /** @defgroup PWREx_Over_Under_Drive_Flag PWREx Over Under Drive Flag
98   * @{
99   */
100 #define PWR_FLAG_ODRDY                  PWR_CSR1_ODRDY
101 #define PWR_FLAG_ODSWRDY                PWR_CSR1_ODSWRDY
102 #define PWR_FLAG_UDRDY                  PWR_CSR1_UDSWRDY
103 /**
104   * @}
105   */
106 
107 /** @defgroup PWREx_Wakeup_Pins_Flag PWREx Wake Up Pin Flags
108   * @{
109   */
110 #define PWR_WAKEUP_PIN_FLAG1            PWR_CSR2_WUPF1
111 #define PWR_WAKEUP_PIN_FLAG2            PWR_CSR2_WUPF2
112 #define PWR_WAKEUP_PIN_FLAG3            PWR_CSR2_WUPF3
113 #define PWR_WAKEUP_PIN_FLAG4            PWR_CSR2_WUPF4
114 #define PWR_WAKEUP_PIN_FLAG5            PWR_CSR2_WUPF5
115 #define PWR_WAKEUP_PIN_FLAG6            PWR_CSR2_WUPF6
116 /**
117   * @}
118   */
119 
120 /**
121   * @}
122   */
123 
124 /* Exported macro ------------------------------------------------------------*/
125 /** @defgroup PWREx_Exported_Macro PWREx Exported Macro
126   *  @{
127   */
128 /** @brief Macros to enable or disable the Over drive mode.
129   */
130 #define __HAL_PWR_OVERDRIVE_ENABLE() (PWR->CR1 |= (uint32_t)PWR_CR1_ODEN)
131 #define __HAL_PWR_OVERDRIVE_DISABLE() (PWR->CR1 &= (uint32_t)(~PWR_CR1_ODEN))
132 
133 /** @brief Macros to enable or disable the Over drive switching.
134   */
135 #define __HAL_PWR_OVERDRIVESWITCHING_ENABLE() (PWR->CR1 |= (uint32_t)PWR_CR1_ODSWEN)
136 #define __HAL_PWR_OVERDRIVESWITCHING_DISABLE() (PWR->CR1 &= (uint32_t)(~PWR_CR1_ODSWEN))
137 
138 /** @brief Macros to enable or disable the Under drive mode.
139   * @note  This mode is enabled only with STOP low power mode.
140   *        In this mode, the 1.2V domain is preserved in reduced leakage mode. This
141   *        mode is only available when the main regulator or the low power regulator
142   *        is in low voltage mode.
143   * @note  If the Under-drive mode was enabled, it is automatically disabled after
144   *        exiting Stop mode.
145   *        When the voltage regulator operates in Under-drive mode, an additional
146   *        startup delay is induced when waking up from Stop mode.
147   */
148 #define __HAL_PWR_UNDERDRIVE_ENABLE() (PWR->CR1 |= (uint32_t)PWR_CR1_UDEN)
149 #define __HAL_PWR_UNDERDRIVE_DISABLE() (PWR->CR1 &= (uint32_t)(~PWR_CR1_UDEN))
150 
151 /** @brief  Check PWR flag is set or not.
152   * @param  __FLAG__: specifies the flag to check.
153   *         This parameter can be one of the following values:
154   *            @arg PWR_FLAG_ODRDY: This flag indicates that the Over-drive mode
155   *                                 is ready
156   *            @arg PWR_FLAG_ODSWRDY: This flag indicates that the Over-drive mode
157   *                                   switching is ready
158   *            @arg PWR_FLAG_UDRDY: This flag indicates that the Under-drive mode
159   *                                 is enabled in Stop mode
160   * @retval The new state of __FLAG__ (TRUE or FALSE).
161   */
162 #define __HAL_PWR_GET_ODRUDR_FLAG(__FLAG__) ((PWR->CSR1 & (__FLAG__)) == (__FLAG__))
163 
164 /** @brief Clear the Under-Drive Ready flag.
165   */
166 #define __HAL_PWR_CLEAR_ODRUDR_FLAG() (PWR->CSR1 |= PWR_FLAG_UDRDY)
167 
168 /** @brief  Check Wake Up flag is set or not.
169   * @param  __WUFLAG__: specifies the Wake Up flag to check.
170   *          This parameter can be one of the following values:
171   *            @arg PWR_WAKEUP_PIN_FLAG1: Wakeup Pin Flag for PA0
172   *            @arg PWR_WAKEUP_PIN_FLAG2: Wakeup Pin Flag for PA2
173   *            @arg PWR_WAKEUP_PIN_FLAG3: Wakeup Pin Flag for PC1
174   *            @arg PWR_WAKEUP_PIN_FLAG4: Wakeup Pin Flag for PC13
175   *            @arg PWR_WAKEUP_PIN_FLAG5: Wakeup Pin Flag for PI8
176   *            @arg PWR_WAKEUP_PIN_FLAG6: Wakeup Pin Flag for PI11
177   */
178 #define __HAL_PWR_GET_WAKEUP_FLAG(__WUFLAG__) (PWR->CSR2 & (__WUFLAG__))
179 
180 /** @brief  Clear the WakeUp pins flags.
181   * @param  __WUFLAG__: specifies the Wake Up pin flag to clear.
182   *          This parameter can be one of the following values:
183   *            @arg PWR_WAKEUP_PIN_FLAG1: Wakeup Pin Flag for PA0
184   *            @arg PWR_WAKEUP_PIN_FLAG2: Wakeup Pin Flag for PA2
185   *            @arg PWR_WAKEUP_PIN_FLAG3: Wakeup Pin Flag for PC1
186   *            @arg PWR_WAKEUP_PIN_FLAG4: Wakeup Pin Flag for PC13
187   *            @arg PWR_WAKEUP_PIN_FLAG5: Wakeup Pin Flag for PI8
188   *            @arg PWR_WAKEUP_PIN_FLAG6: Wakeup Pin Flag for PI11
189   */
190 #define __HAL_PWR_CLEAR_WAKEUP_FLAG(__WUFLAG__) (PWR->CR2 |=  (__WUFLAG__))
191 /**
192   * @}
193   */
194 /* Exported functions --------------------------------------------------------*/
195 /** @addtogroup PWREx_Exported_Functions PWREx Exported Functions
196   *  @{
197   */
198 
199 /** @addtogroup PWREx_Exported_Functions_Group1
200   * @{
201   */
202 uint32_t HAL_PWREx_GetVoltageRange(void);
203 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling);
204 
205 void HAL_PWREx_EnableFlashPowerDown(void);
206 void HAL_PWREx_DisableFlashPowerDown(void);
207 HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg(void);
208 HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg(void);
209 
210 void HAL_PWREx_EnableMainRegulatorLowVoltage(void);
211 void HAL_PWREx_DisableMainRegulatorLowVoltage(void);
212 void HAL_PWREx_EnableLowRegulatorLowVoltage(void);
213 void HAL_PWREx_DisableLowRegulatorLowVoltage(void);
214 
215 HAL_StatusTypeDef HAL_PWREx_EnableOverDrive(void);
216 HAL_StatusTypeDef HAL_PWREx_DisableOverDrive(void);
217 HAL_StatusTypeDef HAL_PWREx_EnterUnderDriveSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
218 
219 /**
220   * @}
221   */
222 
223 /**
224   * @}
225   */
226 /* Private types -------------------------------------------------------------*/
227 /* Private variables ---------------------------------------------------------*/
228 /* Private constants ---------------------------------------------------------*/
229 /* Private macros ------------------------------------------------------------*/
230 /** @defgroup PWREx_Private_Macros PWREx Private Macros
231   * @{
232   */
233 
234 /** @defgroup PWREx_IS_PWR_Definitions PWREx Private macros to check input parameters
235   * @{
236   */
237 #define IS_PWR_REGULATOR_UNDERDRIVE(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_UNDERDRIVE_ON) || \
238                                                 ((REGULATOR) == PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON))
239 #define IS_PWR_WAKEUP_PIN(__PIN__)         (((__PIN__) == PWR_WAKEUP_PIN1)       || \
240                                             ((__PIN__) == PWR_WAKEUP_PIN2)       || \
241                                             ((__PIN__) == PWR_WAKEUP_PIN3)       || \
242                                             ((__PIN__) == PWR_WAKEUP_PIN4)       || \
243                                             ((__PIN__) == PWR_WAKEUP_PIN5)       || \
244                                             ((__PIN__) == PWR_WAKEUP_PIN6)           || \
245                                             ((__PIN__) == PWR_WAKEUP_PIN1_HIGH)  || \
246                                             ((__PIN__) == PWR_WAKEUP_PIN2_HIGH)  || \
247                                             ((__PIN__) == PWR_WAKEUP_PIN3_HIGH)  || \
248                                             ((__PIN__) == PWR_WAKEUP_PIN4_HIGH)  || \
249                                             ((__PIN__) == PWR_WAKEUP_PIN5_HIGH)  || \
250                                             ((__PIN__) == PWR_WAKEUP_PIN6_HIGH)  || \
251                                             ((__PIN__) == PWR_WAKEUP_PIN1_LOW)   || \
252                                             ((__PIN__) == PWR_WAKEUP_PIN2_LOW)   || \
253                                             ((__PIN__) == PWR_WAKEUP_PIN3_LOW)   || \
254                                             ((__PIN__) == PWR_WAKEUP_PIN4_LOW)   || \
255                                             ((__PIN__) == PWR_WAKEUP_PIN5_LOW)   || \
256                                             ((__PIN__) == PWR_WAKEUP_PIN6_LOW))
257 /**
258   * @}
259   */
260 
261 /**
262   * @}
263   */
264 
265 /**
266   * @}
267   */
268 
269 /**
270   * @}
271   */
272 
273 #ifdef __cplusplus
274 }
275 #endif
276 
277 
278 #endif /* __STM32F7xx_HAL_PWR_EX_H */
279 
280 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
281