You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

423 lines
15 KiB

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