stm32f7xx_hal_pwr.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_pwr.h
  4. * @author MCD Application Team
  5. * @brief Header file of PWR HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32F7xx_HAL_PWR_H
  37. #define __STM32F7xx_HAL_PWR_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32f7xx_hal_def.h"
  43. /** @addtogroup STM32F7xx_HAL_Driver
  44. * @{
  45. */
  46. /** @addtogroup PWR
  47. * @{
  48. */
  49. /* Exported types ------------------------------------------------------------*/
  50. /** @defgroup PWR_Exported_Types PWR Exported Types
  51. * @{
  52. */
  53. /**
  54. * @brief PWR PVD configuration structure definition
  55. */
  56. typedef struct
  57. {
  58. uint32_t PVDLevel; /*!< PVDLevel: Specifies the PVD detection level.
  59. This parameter can be a value of @ref PWR_PVD_detection_level */
  60. uint32_t Mode; /*!< Mode: Specifies the operating mode for the selected pins.
  61. This parameter can be a value of @ref PWR_PVD_Mode */
  62. }PWR_PVDTypeDef;
  63. /**
  64. * @}
  65. */
  66. /* Exported constants --------------------------------------------------------*/
  67. /** @defgroup PWR_Exported_Constants PWR Exported Constants
  68. * @{
  69. */
  70. /** @defgroup PWR_PVD_detection_level PWR PVD detection level
  71. * @{
  72. */
  73. #define PWR_PVDLEVEL_0 PWR_CR1_PLS_LEV0
  74. #define PWR_PVDLEVEL_1 PWR_CR1_PLS_LEV1
  75. #define PWR_PVDLEVEL_2 PWR_CR1_PLS_LEV2
  76. #define PWR_PVDLEVEL_3 PWR_CR1_PLS_LEV3
  77. #define PWR_PVDLEVEL_4 PWR_CR1_PLS_LEV4
  78. #define PWR_PVDLEVEL_5 PWR_CR1_PLS_LEV5
  79. #define PWR_PVDLEVEL_6 PWR_CR1_PLS_LEV6
  80. #define PWR_PVDLEVEL_7 PWR_CR1_PLS_LEV7/* External input analog voltage
  81. (Compare internally to VREFINT) */
  82. /**
  83. * @}
  84. */
  85. /** @defgroup PWR_PVD_Mode PWR PVD Mode
  86. * @{
  87. */
  88. #define PWR_PVD_MODE_NORMAL ((uint32_t)0x00000000U) /*!< basic mode is used */
  89. #define PWR_PVD_MODE_IT_RISING ((uint32_t)0x00010001U) /*!< External Interrupt Mode with Rising edge trigger detection */
  90. #define PWR_PVD_MODE_IT_FALLING ((uint32_t)0x00010002U) /*!< External Interrupt Mode with Falling edge trigger detection */
  91. #define PWR_PVD_MODE_IT_RISING_FALLING ((uint32_t)0x00010003U) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
  92. #define PWR_PVD_MODE_EVENT_RISING ((uint32_t)0x00020001U) /*!< Event Mode with Rising edge trigger detection */
  93. #define PWR_PVD_MODE_EVENT_FALLING ((uint32_t)0x00020002U) /*!< Event Mode with Falling edge trigger detection */
  94. #define PWR_PVD_MODE_EVENT_RISING_FALLING ((uint32_t)0x00020003U) /*!< Event Mode with Rising/Falling edge trigger detection */
  95. /**
  96. * @}
  97. */
  98. /** @defgroup PWR_Regulator_state_in_STOP_mode PWR Regulator state in SLEEP/STOP mode
  99. * @{
  100. */
  101. #define PWR_MAINREGULATOR_ON ((uint32_t)0x00000000U)
  102. #define PWR_LOWPOWERREGULATOR_ON PWR_CR1_LPDS
  103. /**
  104. * @}
  105. */
  106. /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry
  107. * @{
  108. */
  109. #define PWR_SLEEPENTRY_WFI ((uint8_t)0x01U)
  110. #define PWR_SLEEPENTRY_WFE ((uint8_t)0x02U)
  111. /**
  112. * @}
  113. */
  114. /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry
  115. * @{
  116. */
  117. #define PWR_STOPENTRY_WFI ((uint8_t)0x01U)
  118. #define PWR_STOPENTRY_WFE ((uint8_t)0x02U)
  119. /**
  120. * @}
  121. */
  122. /** @defgroup PWR_Regulator_Voltage_Scale PWR Regulator Voltage Scale
  123. * @{
  124. */
  125. #define PWR_REGULATOR_VOLTAGE_SCALE1 PWR_CR1_VOS
  126. #define PWR_REGULATOR_VOLTAGE_SCALE2 PWR_CR1_VOS_1
  127. #define PWR_REGULATOR_VOLTAGE_SCALE3 PWR_CR1_VOS_0
  128. /**
  129. * @}
  130. */
  131. /** @defgroup PWR_Flag PWR Flag
  132. * @{
  133. */
  134. #define PWR_FLAG_WU PWR_CSR1_WUIF
  135. #define PWR_FLAG_SB PWR_CSR1_SBF
  136. #define PWR_FLAG_PVDO PWR_CSR1_PVDO
  137. #define PWR_FLAG_BRR PWR_CSR1_BRR
  138. #define PWR_FLAG_VOSRDY PWR_CSR1_VOSRDY
  139. /**
  140. * @}
  141. */
  142. /**
  143. * @}
  144. */
  145. /* Exported macro ------------------------------------------------------------*/
  146. /** @defgroup PWR_Exported_Macro PWR Exported Macro
  147. * @{
  148. */
  149. /** @brief macros configure the main internal regulator output voltage.
  150. * @param __REGULATOR__ specifies the regulator output voltage to achieve
  151. * a tradeoff between performance and power consumption when the device does
  152. * not operate at the maximum frequency (refer to the datasheets for more details).
  153. * This parameter can be one of the following values:
  154. * @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output Scale 1 mode
  155. * @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output Scale 2 mode
  156. * @arg PWR_REGULATOR_VOLTAGE_SCALE3: Regulator voltage output Scale 3 mode
  157. * @retval None
  158. */
  159. #define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__) do { \
  160. __IO uint32_t tmpreg; \
  161. MODIFY_REG(PWR->CR1, PWR_CR1_VOS, (__REGULATOR__)); \
  162. /* Delay after an RCC peripheral clock enabling */ \
  163. tmpreg = READ_BIT(PWR->CR1, PWR_CR1_VOS); \
  164. UNUSED(tmpreg); \
  165. } while(0)
  166. /** @brief Check PWR flag is set or not.
  167. * @param __FLAG__ specifies the flag to check.
  168. * This parameter can be one of the following values:
  169. * @arg PWR_FLAG_WU: Wake Up flag. This flag indicates that a wakeup event
  170. * was received on the internal wakeup line in standby mode (RTC alarm (Alarm A or Alarm B),
  171. * RTC Tamper event, RTC TimeStamp event or RTC Wakeup)).
  172. * @arg PWR_FLAG_SB: StandBy flag. This flag indicates that the system was
  173. * resumed from StandBy mode.
  174. * @arg PWR_FLAG_PVDO: PVD Output. This flag is valid only if PVD is enabled
  175. * by the HAL_PWR_EnablePVD() function. The PVD is stopped by Standby mode
  176. * For this reason, this bit is equal to 0 after Standby or reset
  177. * until the PVDE bit is set.
  178. * @arg PWR_FLAG_BRR: Backup regulator ready flag. This bit is not reset
  179. * when the device wakes up from Standby mode or by a system reset
  180. * or power reset.
  181. * @arg PWR_FLAG_VOSRDY: This flag indicates that the Regulator voltage
  182. * scaling output selection is ready.
  183. * @retval The new state of __FLAG__ (TRUE or FALSE).
  184. */
  185. #define __HAL_PWR_GET_FLAG(__FLAG__) ((PWR->CSR1 & (__FLAG__)) == (__FLAG__))
  186. /** @brief Clear the PWR's pending flags.
  187. * @param __FLAG__ specifies the flag to clear.
  188. * This parameter can be one of the following values:
  189. * @arg PWR_FLAG_SB: StandBy flag
  190. */
  191. #define __HAL_PWR_CLEAR_FLAG(__FLAG__) (PWR->CR1 |= (__FLAG__) << 2)
  192. /**
  193. * @brief Enable the PVD Exti Line 16.
  194. * @retval None.
  195. */
  196. #define __HAL_PWR_PVD_EXTI_ENABLE_IT() (EXTI->IMR |= (PWR_EXTI_LINE_PVD))
  197. /**
  198. * @brief Disable the PVD EXTI Line 16.
  199. * @retval None.
  200. */
  201. #define __HAL_PWR_PVD_EXTI_DISABLE_IT() (EXTI->IMR &= ~(PWR_EXTI_LINE_PVD))
  202. /**
  203. * @brief Enable event on PVD Exti Line 16.
  204. * @retval None.
  205. */
  206. #define __HAL_PWR_PVD_EXTI_ENABLE_EVENT() (EXTI->EMR |= (PWR_EXTI_LINE_PVD))
  207. /**
  208. * @brief Disable event on PVD Exti Line 16.
  209. * @retval None.
  210. */
  211. #define __HAL_PWR_PVD_EXTI_DISABLE_EVENT() (EXTI->EMR &= ~(PWR_EXTI_LINE_PVD))
  212. /**
  213. * @brief Enable the PVD Extended Interrupt Rising Trigger.
  214. * @retval None.
  215. */
  216. #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR, PWR_EXTI_LINE_PVD)
  217. /**
  218. * @brief Disable the PVD Extended Interrupt Rising Trigger.
  219. * @retval None.
  220. */
  221. #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR, PWR_EXTI_LINE_PVD)
  222. /**
  223. * @brief Enable the PVD Extended Interrupt Falling Trigger.
  224. * @retval None.
  225. */
  226. #define __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR, PWR_EXTI_LINE_PVD)
  227. /**
  228. * @brief Disable the PVD Extended Interrupt Falling Trigger.
  229. * @retval None.
  230. */
  231. #define __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR, PWR_EXTI_LINE_PVD)
  232. /**
  233. * @brief PVD EXTI line configuration: set rising & falling edge trigger.
  234. * @retval None.
  235. */
  236. #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_FALLING_EDGE() __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();__HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();
  237. /**
  238. * @brief Disable the PVD Extended Interrupt Rising & Falling Trigger.
  239. * @retval None.
  240. */
  241. #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_FALLING_EDGE() __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();__HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE();
  242. /**
  243. * @brief checks whether the specified PVD Exti interrupt flag is set or not.
  244. * @retval EXTI PVD Line Status.
  245. */
  246. #define __HAL_PWR_PVD_EXTI_GET_FLAG() (EXTI->PR & (PWR_EXTI_LINE_PVD))
  247. /**
  248. * @brief Clear the PVD Exti flag.
  249. * @retval None.
  250. */
  251. #define __HAL_PWR_PVD_EXTI_CLEAR_FLAG() (EXTI->PR = (PWR_EXTI_LINE_PVD))
  252. /**
  253. * @brief Generates a Software interrupt on PVD EXTI line.
  254. * @retval None
  255. */
  256. #define __HAL_PWR_PVD_EXTI_GENERATE_SWIT() (EXTI->SWIER |= (PWR_EXTI_LINE_PVD))
  257. /**
  258. * @}
  259. */
  260. /* Include PWR HAL Extension module */
  261. #include "stm32f7xx_hal_pwr_ex.h"
  262. /* Exported functions --------------------------------------------------------*/
  263. /** @addtogroup PWR_Exported_Functions PWR Exported Functions
  264. * @{
  265. */
  266. /** @addtogroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions
  267. * @{
  268. */
  269. /* Initialization and de-initialization functions *****************************/
  270. void HAL_PWR_DeInit(void);
  271. void HAL_PWR_EnableBkUpAccess(void);
  272. void HAL_PWR_DisableBkUpAccess(void);
  273. /**
  274. * @}
  275. */
  276. /** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions
  277. * @{
  278. */
  279. /* Peripheral Control functions **********************************************/
  280. /* PVD configuration */
  281. void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD);
  282. void HAL_PWR_EnablePVD(void);
  283. void HAL_PWR_DisablePVD(void);
  284. /* WakeUp pins configuration */
  285. void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity);
  286. void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx);
  287. /* Low Power modes entry */
  288. void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
  289. void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry);
  290. void HAL_PWR_EnterSTANDBYMode(void);
  291. /* Power PVD IRQ Handler */
  292. void HAL_PWR_PVD_IRQHandler(void);
  293. void HAL_PWR_PVDCallback(void);
  294. /* Cortex System Control functions *******************************************/
  295. void HAL_PWR_EnableSleepOnExit(void);
  296. void HAL_PWR_DisableSleepOnExit(void);
  297. void HAL_PWR_EnableSEVOnPend(void);
  298. void HAL_PWR_DisableSEVOnPend(void);
  299. /**
  300. * @}
  301. */
  302. /**
  303. * @}
  304. */
  305. /* Private types -------------------------------------------------------------*/
  306. /* Private variables ---------------------------------------------------------*/
  307. /* Private constants ---------------------------------------------------------*/
  308. /** @defgroup PWR_Private_Constants PWR Private Constants
  309. * @{
  310. */
  311. /** @defgroup PWR_PVD_EXTI_Line PWR PVD EXTI Line
  312. * @{
  313. */
  314. #define PWR_EXTI_LINE_PVD ((uint32_t)EXTI_IMR_IM16) /*!< External interrupt line 16 Connected to the PVD EXTI Line */
  315. /**
  316. * @}
  317. */
  318. /**
  319. * @}
  320. */
  321. /* Private macros ------------------------------------------------------------*/
  322. /** @defgroup PWR_Private_Macros PWR Private Macros
  323. * @{
  324. */
  325. /** @defgroup PWR_IS_PWR_Definitions PWR Private macros to check input parameters
  326. * @{
  327. */
  328. #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLEVEL_0) || ((LEVEL) == PWR_PVDLEVEL_1)|| \
  329. ((LEVEL) == PWR_PVDLEVEL_2) || ((LEVEL) == PWR_PVDLEVEL_3)|| \
  330. ((LEVEL) == PWR_PVDLEVEL_4) || ((LEVEL) == PWR_PVDLEVEL_5)|| \
  331. ((LEVEL) == PWR_PVDLEVEL_6) || ((LEVEL) == PWR_PVDLEVEL_7))
  332. #define IS_PWR_PVD_MODE(MODE) (((MODE) == PWR_PVD_MODE_IT_RISING)|| ((MODE) == PWR_PVD_MODE_IT_FALLING) || \
  333. ((MODE) == PWR_PVD_MODE_IT_RISING_FALLING) || ((MODE) == PWR_PVD_MODE_EVENT_RISING) || \
  334. ((MODE) == PWR_PVD_MODE_EVENT_FALLING) || ((MODE) == PWR_PVD_MODE_EVENT_RISING_FALLING) || \
  335. ((MODE) == PWR_PVD_MODE_NORMAL))
  336. #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \
  337. ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON))
  338. #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE))
  339. #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE))
  340. #define IS_PWR_REGULATOR_VOLTAGE(VOLTAGE) (((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE1) || \
  341. ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE2) || \
  342. ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE3))
  343. /**
  344. * @}
  345. */
  346. /**
  347. * @}
  348. */
  349. /**
  350. * @}
  351. */
  352. /**
  353. * @}
  354. */
  355. #ifdef __cplusplus
  356. }
  357. #endif
  358. #endif /* __STM32F7xx_HAL_PWR_H */
  359. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/