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.
 
 
 

775 lines
35 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_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.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef STM32H7xx_HAL_PWR_H
  21. #define STM32H7xx_HAL_PWR_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif /* __cplusplus */
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32h7xx_hal_def.h"
  27. /** @addtogroup STM32H7xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup PWR
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup PWR_Exported_Types PWR Exported Types
  35. * @{
  36. */
  37. /**
  38. * @brief PWR PVD configuration structure definition
  39. */
  40. typedef struct
  41. {
  42. uint32_t PVDLevel; /*!< PVDLevel: Specifies the PVD detection level. This
  43. parameter can be a value of @ref
  44. PWR_PVD_detection_level.
  45. */
  46. uint32_t Mode; /*!< Mode: Specifies the EXTI operating mode for the PVD
  47. event. This parameter can be a value of @ref
  48. PWR_PVD_Mode.
  49. */
  50. }PWR_PVDTypeDef;
  51. /**
  52. * @}
  53. */
  54. /* Exported constants --------------------------------------------------------*/
  55. /** @defgroup PWR_Exported_Constants PWR Exported Constants
  56. * @{
  57. */
  58. /** @defgroup PWR_PVD_detection_level PWR PVD detection level
  59. * @{
  60. */
  61. #define PWR_PVDLEVEL_0 PWR_CR1_PLS_LEV0 /*!< Programmable voltage detector
  62. level 0 selection : 1V95 */
  63. #define PWR_PVDLEVEL_1 PWR_CR1_PLS_LEV1 /*!< Programmable voltage detector
  64. level 1 selection : 2V1 */
  65. #define PWR_PVDLEVEL_2 PWR_CR1_PLS_LEV2 /*!< Programmable voltage detector
  66. level 2 selection : 2V25 */
  67. #define PWR_PVDLEVEL_3 PWR_CR1_PLS_LEV3 /*!< Programmable voltage detector
  68. level 3 selection : 2V4 */
  69. #define PWR_PVDLEVEL_4 PWR_CR1_PLS_LEV4 /*!< Programmable voltage detector
  70. level 4 selection : 2V55 */
  71. #define PWR_PVDLEVEL_5 PWR_CR1_PLS_LEV5 /*!< Programmable voltage detector
  72. level 5 selection : 2V7 */
  73. #define PWR_PVDLEVEL_6 PWR_CR1_PLS_LEV6 /*!< Programmable voltage detector
  74. level 6 selection : 2V85 */
  75. #define PWR_PVDLEVEL_7 PWR_CR1_PLS_LEV7 /*!< External input analog voltage
  76. (Compare internally to VREF) */
  77. /**
  78. * @}
  79. */
  80. /** @defgroup PWR_PVD_Mode PWR PVD Mode
  81. * @{
  82. */
  83. #define PWR_PVD_MODE_NORMAL (0x00000000U) /*!< Basic mode is used */
  84. #define PWR_PVD_MODE_IT_RISING (0x00010001U) /*!< Interrupt Mode with Rising edge trigger detection */
  85. #define PWR_PVD_MODE_IT_FALLING (0x00010002U) /*!< Interrupt Mode with Falling edge trigger detection */
  86. #define PWR_PVD_MODE_IT_RISING_FALLING (0x00010003U) /*!< Interrupt Mode with Rising/Falling edge trigger detection */
  87. #define PWR_PVD_MODE_EVENT_RISING (0x00020001U) /*!< Event Mode with Rising edge trigger detection */
  88. #define PWR_PVD_MODE_EVENT_FALLING (0x00020002U) /*!< Event Mode with Falling edge trigger detection */
  89. #define PWR_PVD_MODE_EVENT_RISING_FALLING (0x00020003U) /*!< Event Mode with Rising/Falling edge trigger detection */
  90. /**
  91. * @}
  92. */
  93. /** @defgroup PWR_Regulator_state_in_STOP_mode PWR Regulator state in SLEEP/STOP mode
  94. * @{
  95. */
  96. #define PWR_MAINREGULATOR_ON (0U)
  97. #define PWR_LOWPOWERREGULATOR_ON PWR_CR1_LPDS
  98. /**
  99. * @}
  100. */
  101. /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry
  102. * @{
  103. */
  104. #define PWR_SLEEPENTRY_WFI (0x01U)
  105. #define PWR_SLEEPENTRY_WFE (0x02U)
  106. /**
  107. * @}
  108. */
  109. /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry
  110. * @{
  111. */
  112. #define PWR_STOPENTRY_WFI (0x01U)
  113. #define PWR_STOPENTRY_WFE (0x02U)
  114. /**
  115. * @}
  116. */
  117. /** @defgroup PWR_Regulator_Voltage_Scale PWR Regulator Voltage Scale
  118. * @{
  119. */
  120. #if defined(PWR_SRDCR_VOS)
  121. #define PWR_REGULATOR_VOLTAGE_SCALE0 (PWR_SRDCR_VOS_1 | PWR_SRDCR_VOS_0)
  122. #define PWR_REGULATOR_VOLTAGE_SCALE1 (PWR_SRDCR_VOS_1)
  123. #define PWR_REGULATOR_VOLTAGE_SCALE2 (PWR_SRDCR_VOS_0)
  124. #define PWR_REGULATOR_VOLTAGE_SCALE3 (0U)
  125. #else
  126. #define PWR_REGULATOR_VOLTAGE_SCALE0 (0U)
  127. #define PWR_REGULATOR_VOLTAGE_SCALE1 (PWR_D3CR_VOS_1 | PWR_D3CR_VOS_0)
  128. #define PWR_REGULATOR_VOLTAGE_SCALE2 (PWR_D3CR_VOS_1)
  129. #define PWR_REGULATOR_VOLTAGE_SCALE3 (PWR_D3CR_VOS_0)
  130. #endif /* PWR_SRDCR_VOS */
  131. /**
  132. * @}
  133. */
  134. /** @defgroup PWR_Flag PWR Flag
  135. * @{
  136. */
  137. /* PWR CPU flag */
  138. #define PWR_FLAG_STOP (0x01U)
  139. #if defined (PWR_CPUCR_SBF_D2)
  140. #define PWR_FLAG_SB_D1 (0x02U)
  141. #define PWR_FLAG_SB_D2 (0x03U)
  142. #endif /* defined (PWR_CPUCR_SBF_D2) */
  143. #define PWR_FLAG_SB (0x04U)
  144. #if defined (DUAL_CORE)
  145. #define PWR_FLAG_CPU_HOLD (0x05U)
  146. #define PWR_FLAG_CPU2_HOLD (0x06U)
  147. #define PWR_FLAG2_STOP (0x07U)
  148. #define PWR_FLAG2_SB_D1 (0x08U)
  149. #define PWR_FLAG2_SB_D2 (0x09U)
  150. #define PWR_FLAG2_SB (0x0AU)
  151. #endif /* defined (DUAL_CORE) */
  152. #define PWR_FLAG_PVDO (0x0BU)
  153. #define PWR_FLAG_AVDO (0x0CU)
  154. #define PWR_FLAG_ACTVOSRDY (0x0DU)
  155. #define PWR_FLAG_ACTVOS (0x0EU)
  156. #define PWR_FLAG_BRR (0x0FU)
  157. #define PWR_FLAG_VOSRDY (0x10U)
  158. #if defined (SMPS)
  159. #define PWR_FLAG_SMPSEXTRDY (0x11U)
  160. #else
  161. #define PWR_FLAG_SCUEN (0x11U)
  162. #endif /* defined (SMPS) */
  163. #if defined (PWR_CSR1_MMCVDO)
  164. #define PWR_FLAG_MMCVDO (0x12U)
  165. #endif /* defined (PWR_CSR1_MMCVDO) */
  166. #define PWR_FLAG_USB33RDY (0x13U)
  167. #define PWR_FLAG_TEMPH (0x14U)
  168. #define PWR_FLAG_TEMPL (0x15U)
  169. #define PWR_FLAG_VBATH (0x16U)
  170. #define PWR_FLAG_VBATL (0x17U)
  171. /* PWR Wake up flag */
  172. #define PWR_FLAG_WKUP1 PWR_WKUPCR_WKUPC1
  173. #define PWR_FLAG_WKUP2 PWR_WKUPCR_WKUPC2
  174. #define PWR_FLAG_WKUP3 PWR_WKUPCR_WKUPC3
  175. #define PWR_FLAG_WKUP4 PWR_WKUPCR_WKUPC4
  176. #define PWR_FLAG_WKUP5 PWR_WKUPCR_WKUPC5
  177. #define PWR_FLAG_WKUP6 PWR_WKUPCR_WKUPC6
  178. /**
  179. * @}
  180. */
  181. /** @defgroup PWR_ENABLE_WUP_Mask PWR Enable WUP Mask
  182. * @{
  183. */
  184. #define PWR_EWUP_MASK (0x0FFF3F3FU)
  185. /**
  186. * @}
  187. */
  188. /**
  189. * @}
  190. */
  191. /* Exported macro ------------------------------------------------------------*/
  192. /** @defgroup PWR_Exported_Macro PWR Exported Macro
  193. * @{
  194. */
  195. /** @brief Configure the main internal regulator output voltage.
  196. * @param __REGULATOR__ : Specifies the regulator output voltage to achieve a
  197. * trade-off between performance and power consumption
  198. * when the device does not operate at the maximum
  199. * frequency (refer to the datasheet for more details).
  200. * This parameter can be one of the following values:
  201. * @arg PWR_REGULATOR_VOLTAGE_SCALE0 : Regulator voltage output
  202. * Scale 0 mode.
  203. * @arg PWR_REGULATOR_VOLTAGE_SCALE1 : Regulator voltage output
  204. * Scale 1 mode.
  205. * @arg PWR_REGULATOR_VOLTAGE_SCALE2 : Regulator voltage output
  206. * Scale 2 mode.
  207. * @arg PWR_REGULATOR_VOLTAGE_SCALE3 : Regulator voltage output
  208. * Scale 3 mode.
  209. * @note For all H7 lines except STM32H7Axxx and STM32H7Bxxx lines,
  210. * configuring Voltage Scale 0 is only possible when Vcore is supplied
  211. * from LDO (Low DropOut). The SYSCFG Clock must be enabled through
  212. * __HAL_RCC_SYSCFG_CLK_ENABLE() macro before configuring Voltage Scale
  213. * 0 using __HAL_PWR_VOLTAGESCALING_CONFIG().
  214. * Transition to Voltage Scale 0 is only possible when the system is
  215. * already in Voltage Scale 1.
  216. * Transition from Voltage Scale 0 is only possible to Voltage Scale 1
  217. * then once in Voltage Scale 1 it is possible to switch to another
  218. * voltage scale.
  219. * After each regulator voltage setting, wait on VOSRDY flag to be set
  220. * using macro __HAL_PWR_GET_FLAG().
  221. * To enter low power mode , and if current regulator voltage is
  222. * Voltage Scale 0 then first switch to Voltage Scale 1 before entering
  223. * low power mode.
  224. * @retval None.
  225. */
  226. #if defined(PWR_SRDCR_VOS) /* STM32H7Axxx and STM32H7Bxxx lines */
  227. #define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__) \
  228. do { \
  229. __IO uint32_t tmpreg = 0x00; \
  230. MODIFY_REG(PWR->SRDCR, PWR_SRDCR_VOS, (__REGULATOR__)); \
  231. /* Delay after setting the voltage scaling */ \
  232. tmpreg = READ_BIT(PWR->SRDCR, PWR_SRDCR_VOS); \
  233. UNUSED(tmpreg); \
  234. } while(0)
  235. #else /* All H7 lines except STM32H7Axxx and STM32H7Bxxx lines */
  236. #define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__) \
  237. do { \
  238. __IO uint32_t tmpreg = 0x00; \
  239. /* Check the voltage scaling to be configured */ \
  240. if((__REGULATOR__) == PWR_REGULATOR_VOLTAGE_SCALE0) \
  241. { \
  242. /* Configure the Voltage Scaling 1 */ \
  243. MODIFY_REG(PWR->D3CR, PWR_D3CR_VOS, PWR_REGULATOR_VOLTAGE_SCALE1); \
  244. /* Delay after setting the voltage scaling */ \
  245. tmpreg = READ_BIT(PWR->D3CR, PWR_D3CR_VOS); \
  246. /* Enable the PWR overdrive */ \
  247. SET_BIT(SYSCFG->PWRCR, SYSCFG_PWRCR_ODEN); \
  248. /* Delay after setting the syscfg boost setting */ \
  249. tmpreg = READ_BIT(SYSCFG->PWRCR, SYSCFG_PWRCR_ODEN); \
  250. } \
  251. else \
  252. { \
  253. /* Disable the PWR overdrive */ \
  254. CLEAR_BIT(SYSCFG->PWRCR, SYSCFG_PWRCR_ODEN); \
  255. /* Delay after setting the syscfg boost setting */ \
  256. tmpreg = READ_BIT(SYSCFG->PWRCR, SYSCFG_PWRCR_ODEN); \
  257. /* Configure the Voltage Scaling x */ \
  258. MODIFY_REG(PWR->D3CR, PWR_D3CR_VOS, (__REGULATOR__)); \
  259. /* Delay after setting the voltage scaling */ \
  260. tmpreg = READ_BIT(PWR->D3CR, PWR_D3CR_VOS); \
  261. } \
  262. UNUSED(tmpreg); \
  263. } while(0)
  264. #endif /* PWR_SRDCR_VOS */
  265. /** @brief Check PWR flags are set or not.
  266. * @param __FLAG__ : Specifies the flag to check.
  267. * This parameter can be one of the following values:
  268. * @arg PWR_FLAG_PVDO : PVD Output. This flag is valid only if PVD
  269. * is enabled by the HAL_PWR_EnablePVD()
  270. * function.
  271. * The PVD is stopped by STANDBY mode. For this
  272. * reason, this bit is equal to 0 after STANDBY
  273. * or reset until the PVDE bit is set.
  274. * @arg PWR_FLAG_AVDO : AVD Output. This flag is valid only if AVD
  275. * is enabled by the HAL_PWREx_EnableAVD()
  276. * function. The AVD is stopped by STANDBY mode.
  277. * For this reason, this bit is equal to 0
  278. * after STANDBY or reset until the AVDE bit
  279. * is set.
  280. * @arg PWR_FLAG_ACTVOSRDY : This flag indicates that the Regulator
  281. * voltage scaling output selection is
  282. * ready.
  283. * @arg PWR_FLAG_BRR : Backup regulator ready flag. This bit is not
  284. * reset when the device wakes up from STANDBY
  285. * mode or by a system reset or power-on reset.
  286. * @arg PWR_FLAG_VOSRDY : This flag indicates that the Regulator
  287. * voltage scaling output selection is ready.
  288. * mode or by a system reset or power-on reset.
  289. * @arg PWR_FLAG_USB33RDY : This flag indicates that the USB supply
  290. * from regulator is ready.
  291. * @arg PWR_FLAG_TEMPH : This flag indicates that the temperature
  292. * equal or above high threshold level.
  293. * @arg PWR_FLAG_TEMPL : This flag indicates that the temperature
  294. * equal or below low threshold level.
  295. * @arg PWR_FLAG_VBATH : This flag indicates that VBAT level equal
  296. * or above high threshold level.
  297. * @arg PWR_FLAG_VBATL : This flag indicates that VBAT level equal
  298. * or below low threshold level.
  299. * @arg PWR_FLAG_STOP : This flag indicates that the system entered
  300. * in STOP mode.
  301. * @arg PWR_FLAG_SB : This flag indicates that the system entered in
  302. * STANDBY mode.
  303. * @arg PWR_FLAG_SB_D1 : This flag indicates that the D1 domain
  304. * entered in STANDBY mode.
  305. * @arg PWR_FLAG_SB_D2 : This flag indicates that the D2 domain
  306. * entered in STANDBY mode.
  307. * @arg PWR_FLAG2_STOP : This flag indicates that the system entered
  308. * in STOP mode.
  309. * @arg PWR_FLAG2_SB : This flag indicates that the system entered
  310. * in STANDBY mode.
  311. * @arg PWR_FLAG2_SB_D1 : This flag indicates that the D1 domain
  312. * entered in STANDBY mode.
  313. * @arg PWR_FLAG2_SB_D2 : This flag indicates that the D2 domain
  314. * entered in STANDBY mode.
  315. * @arg PWR_FLAG_CPU_HOLD : This flag indicates that the CPU1 wakes
  316. * up with hold.
  317. * @arg PWR_FLAG_CPU2_HOLD : This flag indicates that the CPU2 wakes
  318. * up with hold.
  319. * @arg PWR_FLAG_SMPSEXTRDY : This flag indicates that the SMPS
  320. * External supply is sready.
  321. * @arg PWR_FLAG_SCUEN : This flag indicates that the supply
  322. * configuration update is enabled.
  323. * @arg PWR_FLAG_MMCVDO : This flag indicates that the VDDMMC is
  324. * above or equal to 1.2 V.
  325. * @note The PWR_FLAG_PVDO, PWR_FLAG_AVDO, PWR_FLAG_ACTVOSRDY, PWR_FLAG_BRR,
  326. * PWR_FLAG_VOSRDY, PWR_FLAG_USB33RDY, PWR_FLAG_TEMPH, PWR_FLAG_TEMPL,
  327. * PWR_FLAG_VBATH, PWR_FLAG_VBATL, PWR_FLAG_STOP and PWR_FLAG_SB flags
  328. * are used for all H7 family lines.
  329. * The PWR_FLAG2_STOP, PWR_FLAG2_SB, PWR_FLAG2_SB_D1, PWR_FLAG2_SB_D2,
  330. * PWR_FLAG_CPU_HOLD and PWR_FLAG_CPU2_HOLD flags are used only for H7
  331. * dual core lines.
  332. * The PWR_FLAG_SB_D1 and PWR_FLAG_SB_D2 flags are used for all H7
  333. * family except STM32H7Axxx and STM32H7Bxxx lines.
  334. * The PWR_FLAG_MMCVDO flag is used only for STM32H7Axxx and
  335. * STM32H7Bxxx lines.
  336. * The PWR_FLAG_SCUEN flag is used for STM32H743, STM32H753, STM32H742,
  337. * STM32H750, STM32H7Axx and STM32H7Bxx lines.
  338. * The PWR_FLAG_SMPSEXTRDY flag is used for dual core and STM32H7AxxQ,
  339. * STM32H7BxxQ lines.
  340. * @retval The (__FLAG__) state (TRUE or FALSE).
  341. */
  342. #if defined (DUAL_CORE) /* Dual core lines */
  343. #define __HAL_PWR_GET_FLAG(__FLAG__) \
  344. (((__FLAG__) == PWR_FLAG_PVDO) ? ((PWR->CSR1 & PWR_CSR1_PVDO) == PWR_CSR1_PVDO) :\
  345. ((__FLAG__) == PWR_FLAG_AVDO) ? ((PWR->CSR1 & PWR_CSR1_AVDO) == PWR_CSR1_AVDO) :\
  346. ((__FLAG__) == PWR_FLAG_ACTVOSRDY) ? ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == PWR_CSR1_ACTVOSRDY) :\
  347. ((__FLAG__) == PWR_FLAG_VOSRDY) ? ((PWR->D3CR & PWR_D3CR_VOSRDY) == PWR_D3CR_VOSRDY) :\
  348. ((__FLAG__) == PWR_FLAG_SMPSEXTRDY) ? ((PWR->CR3 & PWR_CR3_SMPSEXTRDY) == PWR_CR3_SMPSEXTRDY) :\
  349. ((__FLAG__) == PWR_FLAG_BRR) ? ((PWR->CR2 & PWR_CR2_BRRDY) == PWR_CR2_BRRDY) :\
  350. ((__FLAG__) == PWR_FLAG_CPU_HOLD) ? ((PWR->CPU2CR & PWR_CPU2CR_HOLD1F) == PWR_CPU2CR_HOLD1F) :\
  351. ((__FLAG__) == PWR_FLAG_CPU2_HOLD) ? ((PWR->CPUCR & PWR_CPUCR_HOLD2F) == PWR_CPUCR_HOLD2F) :\
  352. ((__FLAG__) == PWR_FLAG_SB) ? ((PWR->CPUCR & PWR_CPUCR_SBF) == PWR_CPUCR_SBF) :\
  353. ((__FLAG__) == PWR_FLAG2_SB) ? ((PWR->CPU2CR & PWR_CPU2CR_SBF) == PWR_CPU2CR_SBF) :\
  354. ((__FLAG__) == PWR_FLAG_STOP) ? ((PWR->CPUCR & PWR_CPUCR_STOPF) == PWR_CPUCR_STOPF) :\
  355. ((__FLAG__) == PWR_FLAG2_STOP) ? ((PWR->CPU2CR & PWR_CPU2CR_STOPF) == PWR_CPU2CR_STOPF) :\
  356. ((__FLAG__) == PWR_FLAG_SB_D1) ? ((PWR->CPUCR & PWR_CPUCR_SBF_D1) == PWR_CPUCR_SBF_D1) :\
  357. ((__FLAG__) == PWR_FLAG2_SB_D1) ? ((PWR->CPU2CR & PWR_CPU2CR_SBF_D1) == PWR_CPU2CR_SBF_D1) :\
  358. ((__FLAG__) == PWR_FLAG_SB_D2) ? ((PWR->CPUCR & PWR_CPUCR_SBF_D2) == PWR_CPUCR_SBF_D2) :\
  359. ((__FLAG__) == PWR_FLAG2_SB_D2) ? ((PWR->CPU2CR & PWR_CPU2CR_SBF_D2) == PWR_CPU2CR_SBF_D2) :\
  360. ((__FLAG__) == PWR_FLAG_USB33RDY) ? ((PWR->CR3 & PWR_CR3_USB33RDY) == PWR_CR3_USB33RDY) :\
  361. ((__FLAG__) == PWR_FLAG_TEMPH) ? ((PWR->CR2 & PWR_CR2_TEMPH) == PWR_CR2_TEMPH) :\
  362. ((__FLAG__) == PWR_FLAG_TEMPL) ? ((PWR->CR2 & PWR_CR2_TEMPL) == PWR_CR2_TEMPL) :\
  363. ((__FLAG__) == PWR_FLAG_VBATH) ? ((PWR->CR2 & PWR_CR2_VBATH) == PWR_CR2_VBATH) :\
  364. ((PWR->CR2 & PWR_CR2_VBATL) == PWR_CR2_VBATL))
  365. #else /* Single core lines */
  366. #if defined (PWR_CPUCR_SBF_D2) /* STM32H743, STM32H753, STM32H742 and STM32H750 lines */
  367. #define __HAL_PWR_GET_FLAG(__FLAG__) \
  368. (((__FLAG__) == PWR_FLAG_PVDO) ? ((PWR->CSR1 & PWR_CSR1_PVDO) == PWR_CSR1_PVDO) :\
  369. ((__FLAG__) == PWR_FLAG_AVDO) ? ((PWR->CSR1 & PWR_CSR1_AVDO) == PWR_CSR1_AVDO) :\
  370. ((__FLAG__) == PWR_FLAG_ACTVOSRDY) ? ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == PWR_CSR1_ACTVOSRDY) :\
  371. ((__FLAG__) == PWR_FLAG_VOSRDY) ? ((PWR->D3CR & PWR_D3CR_VOSRDY) == PWR_D3CR_VOSRDY) :\
  372. ((__FLAG__) == PWR_FLAG_SCUEN) ? ((PWR->CR3 & PWR_CR3_SCUEN) == PWR_CR3_SCUEN) :\
  373. ((__FLAG__) == PWR_FLAG_BRR) ? ((PWR->CR2 & PWR_CR2_BRRDY) == PWR_CR2_BRRDY) :\
  374. ((__FLAG__) == PWR_FLAG_SB) ? ((PWR->CPUCR & PWR_CPUCR_SBF) == PWR_CPUCR_SBF) :\
  375. ((__FLAG__) == PWR_FLAG_STOP) ? ((PWR->CPUCR & PWR_CPUCR_STOPF) == PWR_CPUCR_STOPF) :\
  376. ((__FLAG__) == PWR_FLAG_SB_D1) ? ((PWR->CPUCR & PWR_CPUCR_SBF_D1) == PWR_CPUCR_SBF_D1) :\
  377. ((__FLAG__) == PWR_FLAG_SB_D2) ? ((PWR->CPUCR & PWR_CPUCR_SBF_D2) == PWR_CPUCR_SBF_D2) :\
  378. ((__FLAG__) == PWR_FLAG_USB33RDY) ? ((PWR->CR3 & PWR_CR3_USB33RDY) == PWR_CR3_USB33RDY) :\
  379. ((__FLAG__) == PWR_FLAG_TEMPH) ? ((PWR->CR2 & PWR_CR2_TEMPH) == PWR_CR2_TEMPH) :\
  380. ((__FLAG__) == PWR_FLAG_TEMPL) ? ((PWR->CR2 & PWR_CR2_TEMPL) == PWR_CR2_TEMPL) :\
  381. ((__FLAG__) == PWR_FLAG_VBATH) ? ((PWR->CR2 & PWR_CR2_VBATH) == PWR_CR2_VBATH) :\
  382. ((PWR->CR2 & PWR_CR2_VBATL) == PWR_CR2_VBATL))
  383. #else /* STM32H7Axxx and STM32H7Bxxx lines */
  384. #if defined (SMPS) /* STM32H7AxxQ and STM32H7BxxQ SMPS lines */
  385. #define __HAL_PWR_GET_FLAG(__FLAG__) \
  386. (((__FLAG__) == PWR_FLAG_PVDO) ? ((PWR->CSR1 & PWR_CSR1_PVDO) == PWR_CSR1_PVDO) :\
  387. ((__FLAG__) == PWR_FLAG_AVDO) ? ((PWR->CSR1 & PWR_CSR1_AVDO) == PWR_CSR1_AVDO) :\
  388. ((__FLAG__) == PWR_FLAG_ACTVOSRDY) ? ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == PWR_CSR1_ACTVOSRDY) :\
  389. ((__FLAG__) == PWR_FLAG_BRR) ? ((PWR->CR2 & PWR_CR2_BRRDY) == PWR_CR2_BRRDY) :\
  390. ((__FLAG__) == PWR_FLAG_VOSRDY) ? ((PWR->SRDCR & PWR_SRDCR_VOSRDY) == PWR_SRDCR_VOSRDY) :\
  391. ((__FLAG__) == PWR_FLAG_STOP) ? ((PWR->CPUCR & PWR_CPUCR_STOPF) == PWR_CPUCR_STOPF) :\
  392. ((__FLAG__) == PWR_FLAG_SB) ? ((PWR->CPUCR & PWR_CPUCR_SBF) == PWR_CPUCR_SBF) :\
  393. ((__FLAG__) == PWR_FLAG_MMCVDO) ? ((PWR->CSR1 & PWR_CSR1_MMCVDO) == PWR_CSR1_MMCVDO) :\
  394. ((__FLAG__) == PWR_FLAG_SMPSEXTRDY) ? ((PWR->CR3 & PWR_CR3_SMPSEXTRDY) == PWR_CR3_SMPSEXTRDY) :\
  395. ((__FLAG__) == PWR_FLAG_USB33RDY) ? ((PWR->CR3 & PWR_CR3_USB33RDY) == PWR_CR3_USB33RDY) :\
  396. ((__FLAG__) == PWR_FLAG_TEMPH) ? ((PWR->CR2 & PWR_CR2_TEMPH) == PWR_CR2_TEMPH) :\
  397. ((__FLAG__) == PWR_FLAG_TEMPL) ? ((PWR->CR2 & PWR_CR2_TEMPL) == PWR_CR2_TEMPL) :\
  398. ((__FLAG__) == PWR_FLAG_VBATH) ? ((PWR->CR2 & PWR_CR2_VBATH) == PWR_CR2_VBATH) :\
  399. ((PWR->CR2 & PWR_CR2_VBATL) == PWR_CR2_VBATL))
  400. #else /* STM32H7Axx and STM32H7Bxx LDO lines */
  401. #define __HAL_PWR_GET_FLAG(__FLAG__) \
  402. (((__FLAG__) == PWR_FLAG_PVDO) ? ((PWR->CSR1 & PWR_CSR1_PVDO) == PWR_CSR1_PVDO) :\
  403. ((__FLAG__) == PWR_FLAG_AVDO) ? ((PWR->CSR1 & PWR_CSR1_AVDO) == PWR_CSR1_AVDO) :\
  404. ((__FLAG__) == PWR_FLAG_ACTVOSRDY) ? ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == PWR_CSR1_ACTVOSRDY) :\
  405. ((__FLAG__) == PWR_FLAG_BRR) ? ((PWR->CR2 & PWR_CR2_BRRDY) == PWR_CR2_BRRDY) :\
  406. ((__FLAG__) == PWR_FLAG_VOSRDY) ? ((PWR->SRDCR & PWR_SRDCR_VOSRDY) == PWR_SRDCR_VOSRDY) :\
  407. ((__FLAG__) == PWR_FLAG_SCUEN) ? ((PWR->CR3 & PWR_CR3_SCUEN) == PWR_CR3_SCUEN) :\
  408. ((__FLAG__) == PWR_FLAG_STOP) ? ((PWR->CPUCR & PWR_CPUCR_STOPF) == PWR_CPUCR_STOPF) :\
  409. ((__FLAG__) == PWR_FLAG_SB) ? ((PWR->CPUCR & PWR_CPUCR_SBF) == PWR_CPUCR_SBF) :\
  410. ((__FLAG__) == PWR_FLAG_MMCVDO) ? ((PWR->CSR1 & PWR_CSR1_MMCVDO) == PWR_CSR1_MMCVDO) :\
  411. ((__FLAG__) == PWR_FLAG_USB33RDY) ? ((PWR->CR3 & PWR_CR3_USB33RDY) == PWR_CR3_USB33RDY) :\
  412. ((__FLAG__) == PWR_FLAG_TEMPH) ? ((PWR->CR2 & PWR_CR2_TEMPH) == PWR_CR2_TEMPH) :\
  413. ((__FLAG__) == PWR_FLAG_TEMPL) ? ((PWR->CR2 & PWR_CR2_TEMPL) == PWR_CR2_TEMPL) :\
  414. ((__FLAG__) == PWR_FLAG_VBATH) ? ((PWR->CR2 & PWR_CR2_VBATH) == PWR_CR2_VBATH) :\
  415. ((PWR->CR2 & PWR_CR2_VBATL) == PWR_CR2_VBATL))
  416. #endif /* SMPS */
  417. #endif /* PWR_CPUCR_SBF_D2 */
  418. #endif /* DUAL_CORE */
  419. /** @brief Check PWR wake up flags are set or not.
  420. * @param __FLAG__: specifies the wake up flag to check.
  421. * This parameter can be one of the following values:
  422. * @arg PWR_FLAG_WKUP1 : This parameter clear Wake up line 1 flag.
  423. * @arg PWR_FLAG_WKUP2 : This parameter clear Wake up line 2 flag.
  424. * @arg PWR_FLAG_WKUP3 : This parameter clear Wake up line 3 flag.
  425. * @arg PWR_FLAG_WKUP4 : This parameter clear Wake up line 4 flag.
  426. * @arg PWR_FLAG_WKUP5 : This parameter clear Wake up line 5 flag.
  427. * @arg PWR_FLAG_WKUP6 : This parameter clear Wake up line 6 flag.
  428. * @retval The (__FLAG__) state (TRUE or FALSE).
  429. */
  430. #define __HAL_PWR_GET_WAKEUPFLAG(__FLAG__) ((PWR->WKUPFR & (__FLAG__)) ? 0 : 1)
  431. #if defined (DUAL_CORE)
  432. /** @brief Clear CPU PWR flags.
  433. * @param __FLAG__ : Specifies the flag to clear.
  434. * @note This parameter is not used for the STM32H7 family and is kept as
  435. * parameter just to maintain compatibility with other families.
  436. * @note This macro clear all CPU flags STOPF, SBF, SBF_D1, and SBF_D2.
  437. * This parameter can be one of the following values :
  438. * @arg PWR_CPU_FLAGS : Clear HOLD2F, STOPF, SBF, SBF_D1, and SBF_D2
  439. * CPU flags.
  440. * @retval None.
  441. */
  442. #define __HAL_PWR_CLEAR_FLAG(__FLAG__) \
  443. do { \
  444. SET_BIT(PWR->CPUCR, PWR_CPUCR_CSSF); \
  445. SET_BIT(PWR->CPU2CR, PWR_CPU2CR_CSSF); \
  446. } while(0)
  447. #else
  448. /** @brief Clear CPU PWR flags.
  449. * @param __FLAG__ : Specifies the flag to clear.
  450. * @note This parameter is not used for the STM32H7 family and is kept as
  451. * parameter just to maintain compatibility with other families.
  452. * @note This macro clear all CPU flags.
  453. * For STM32H7Axxx and STM32H7Bxxx lines CPU flags are STOPF and SBF.
  454. * For dual core lines flags are HOLDxF, STOPF, SBF and SBF_Dx.
  455. * @retval None.
  456. */
  457. #define __HAL_PWR_CLEAR_FLAG(__FLAG__) SET_BIT(PWR->CPUCR, PWR_CPUCR_CSSF)
  458. #endif /* defined (DUAL_CORE) */
  459. /** @brief Clear PWR wake up flags.
  460. * @param __FLAG__ : Specifies the wake up flag to be cleared.
  461. * This parameter can be one of the following values :
  462. * @arg PWR_FLAG_WKUP1 : This parameter clear Wake up line 1 flag.
  463. * @arg PWR_FLAG_WKUP2 : This parameter clear Wake up line 2 flag.
  464. * @arg PWR_FLAG_WKUP3 : This parameter clear Wake up line 3 flag.
  465. * @arg PWR_FLAG_WKUP4 : This parameter clear Wake up line 4 flag.
  466. * @arg PWR_FLAG_WKUP5 : This parameter clear Wake up line 5 flag.
  467. * @arg PWR_FLAG_WKUP6 : This parameter clear Wake up line 6 flag.
  468. * @retval None.
  469. */
  470. #define __HAL_PWR_CLEAR_WAKEUPFLAG(__FLAG__) SET_BIT(PWR->WKUPCR, (__FLAG__))
  471. /**
  472. * @brief Enable the PVD EXTI Line 16.
  473. * @retval None.
  474. */
  475. #define __HAL_PWR_PVD_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR1, PWR_EXTI_LINE_PVD)
  476. #if defined (DUAL_CORE)
  477. /**
  478. * @brief Enable the PVD EXTI D2 Line 16.
  479. * @retval None.
  480. */
  481. #define __HAL_PWR_PVD_EXTID2_ENABLE_IT() SET_BIT(EXTI_D2->IMR1, PWR_EXTI_LINE_PVD)
  482. #endif /* defined (DUAL_CORE) */
  483. /**
  484. * @brief Disable the PVD EXTI Line 16.
  485. * @retval None.
  486. */
  487. #define __HAL_PWR_PVD_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR1, PWR_EXTI_LINE_PVD)
  488. #if defined (DUAL_CORE)
  489. /**
  490. * @brief Disable the PVD EXTI D2 Line 16.
  491. * @retval None.
  492. */
  493. #define __HAL_PWR_PVD_EXTID2_DISABLE_IT() CLEAR_BIT(EXTI_D2->IMR1, PWR_EXTI_LINE_PVD)
  494. #endif /* defined (DUAL_CORE) */
  495. /**
  496. * @brief Enable event on PVD EXTI Line 16.
  497. * @retval None.
  498. */
  499. #define __HAL_PWR_PVD_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR1, PWR_EXTI_LINE_PVD)
  500. #if defined (DUAL_CORE)
  501. /**
  502. * @brief Enable event on PVD EXTI D2 Line.
  503. * @retval None.
  504. */
  505. #define __HAL_PWR_PVD_EXTID2_ENABLE_EVENT() SET_BIT(EXTI_D2->EMR1, PWR_EXTI_LINE_PVD)
  506. #endif /* defined (DUAL_CORE) */
  507. /**
  508. * @brief Disable event on PVD EXTI Line 16.
  509. * @retval None.
  510. */
  511. #define __HAL_PWR_PVD_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR1, PWR_EXTI_LINE_PVD)
  512. #if defined (DUAL_CORE)
  513. /**
  514. * @brief Disable event on PVD EXTI D2 Line.
  515. * @retval None.
  516. */
  517. #define __HAL_PWR_PVD_EXTID2_DISABLE_EVENT() CLEAR_BIT(EXTI_D2->EMR1, PWR_EXTI_LINE_PVD)
  518. #endif /* defined (DUAL_CORE) */
  519. /**
  520. * @brief Enable the PVD Rising Interrupt Trigger.
  521. * @retval None.
  522. */
  523. #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR1, PWR_EXTI_LINE_PVD)
  524. /**
  525. * @brief Disable the PVD Rising Interrupt Trigger.
  526. * @retval None.
  527. */
  528. #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR1, PWR_EXTI_LINE_PVD)
  529. /**
  530. * @brief Enable the PVD Falling Interrupt Trigger.
  531. * @retval None.
  532. */
  533. #define __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR1, PWR_EXTI_LINE_PVD)
  534. /**
  535. * @brief Disable the PVD Falling Interrupt Trigger.
  536. * @retval None.
  537. */
  538. #define __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR1, PWR_EXTI_LINE_PVD)
  539. /**
  540. * @brief Enable the PVD Rising & Falling Interrupt Trigger.
  541. * @retval None.
  542. */
  543. #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_FALLING_EDGE() \
  544. do { \
  545. __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE(); \
  546. __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE(); \
  547. } while(0);
  548. /**
  549. * @brief Disable the PVD Rising & Falling Interrupt Trigger.
  550. * @retval None.
  551. */
  552. #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_FALLING_EDGE() \
  553. do { \
  554. __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE(); \
  555. __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE(); \
  556. } while(0);
  557. /**
  558. * @brief Check whether the specified PVD EXTI interrupt flag is set or not.
  559. * @retval EXTI PVD Line Status.
  560. */
  561. #define __HAL_PWR_PVD_EXTI_GET_FLAG() ((READ_BIT(EXTI->PR1, PWR_EXTI_LINE_PVD) == PWR_EXTI_LINE_PVD) ? 1UL : 0UL)
  562. #if defined (DUAL_CORE)
  563. /**
  564. * @brief Checks whether the specified PVD EXTI interrupt flag is set or not.
  565. * @retval EXTI D2 PVD Line Status.
  566. */
  567. #define __HAL_PWR_PVD_EXTID2_GET_FLAG() ((READ_BIT(EXTI_D2->PR1, PWR_EXTI_LINE_PVD) == PWR_EXTI_LINE_PVD) ? 1UL : 0UL)
  568. #endif /* defined (DUAL_CORE) */
  569. /**
  570. * @brief Clear the PVD EXTI flag.
  571. * @retval None.
  572. */
  573. #define __HAL_PWR_PVD_EXTI_CLEAR_FLAG() SET_BIT(EXTI->PR1, PWR_EXTI_LINE_PVD)
  574. #if defined (DUAL_CORE)
  575. /**
  576. * @brief Clear the PVD EXTI D2 flag.
  577. * @retval None.
  578. */
  579. #define __HAL_PWR_PVD_EXTID2_CLEAR_FLAG() SET_BIT(EXTI_D2->PR1, PWR_EXTI_LINE_PVD)
  580. #endif /* defined (DUAL_CORE) */
  581. /**
  582. * @brief Generates a Software interrupt on PVD EXTI line.
  583. * @retval None.
  584. */
  585. #define __HAL_PWR_PVD_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER1, PWR_EXTI_LINE_PVD)
  586. /**
  587. * @}
  588. */
  589. /* Include PWR HAL Extension module */
  590. #include "stm32h7xx_hal_pwr_ex.h"
  591. /* Exported functions --------------------------------------------------------*/
  592. /** @addtogroup PWR_Exported_Functions PWR Exported Functions
  593. * @{
  594. */
  595. /** @addtogroup PWR_Exported_Functions_Group1 Initialization and De-Initialization functions
  596. * @{
  597. */
  598. /* Initialization and de-initialization functions *****************************/
  599. void HAL_PWR_DeInit(void);
  600. void HAL_PWR_EnableBkUpAccess(void);
  601. void HAL_PWR_DisableBkUpAccess(void);
  602. /**
  603. * @}
  604. */
  605. /** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions
  606. * @{
  607. */
  608. /* Peripheral Control functions **********************************************/
  609. /* PVD configuration */
  610. void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD);
  611. void HAL_PWR_EnablePVD(void);
  612. void HAL_PWR_DisablePVD(void);
  613. /* WakeUp pins configuration */
  614. void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity);
  615. void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx);
  616. /* Low Power modes entry */
  617. void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
  618. void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry);
  619. void HAL_PWR_EnterSTANDBYMode(void);
  620. /* Power PVD IRQ Handler */
  621. void HAL_PWR_PVD_IRQHandler(void);
  622. void HAL_PWR_PVDCallback(void);
  623. /* Cortex System Control functions *******************************************/
  624. void HAL_PWR_EnableSleepOnExit(void);
  625. void HAL_PWR_DisableSleepOnExit(void);
  626. void HAL_PWR_EnableSEVOnPend(void);
  627. void HAL_PWR_DisableSEVOnPend(void);
  628. /**
  629. * @}
  630. */
  631. /**
  632. * @}
  633. */
  634. /* Private types -------------------------------------------------------------*/
  635. /* Private variables ---------------------------------------------------------*/
  636. /* Private constants ---------------------------------------------------------*/
  637. /** @defgroup PWR_Private_Constants PWR Private Constants
  638. * @{
  639. */
  640. /** @defgroup PWR_PVD_EXTI_Line PWR PVD EXTI Line
  641. * @{
  642. */
  643. #define PWR_EXTI_LINE_PVD EXTI_IMR1_IM16 /*!< External interrupt line 16
  644. Connected to the PVD EXTI Line */
  645. /**
  646. * @}
  647. */
  648. /**
  649. * @}
  650. */
  651. /* Private macros ------------------------------------------------------------*/
  652. /** @defgroup PWR_Private_Macros PWR Private Macros
  653. * @{
  654. */
  655. /** @defgroup PWR_IS_PWR_Definitions PWR Private macros to check input parameters
  656. * @{
  657. */
  658. /* Check PVD level parameter */
  659. #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLEVEL_0) ||\
  660. ((LEVEL) == PWR_PVDLEVEL_1) ||\
  661. ((LEVEL) == PWR_PVDLEVEL_2) ||\
  662. ((LEVEL) == PWR_PVDLEVEL_3) ||\
  663. ((LEVEL) == PWR_PVDLEVEL_4) ||\
  664. ((LEVEL) == PWR_PVDLEVEL_5) ||\
  665. ((LEVEL) == PWR_PVDLEVEL_6) ||\
  666. ((LEVEL) == PWR_PVDLEVEL_7))
  667. /* Check PVD mode parameter */
  668. #define IS_PWR_PVD_MODE(MODE) (((MODE) == PWR_PVD_MODE_IT_RISING) ||\
  669. ((MODE) == PWR_PVD_MODE_IT_FALLING) ||\
  670. ((MODE) == PWR_PVD_MODE_IT_RISING_FALLING) ||\
  671. ((MODE) == PWR_PVD_MODE_EVENT_RISING) ||\
  672. ((MODE) == PWR_PVD_MODE_EVENT_FALLING) ||\
  673. ((MODE) == PWR_PVD_MODE_EVENT_RISING_FALLING) ||\
  674. ((MODE) == PWR_PVD_MODE_NORMAL))
  675. /* Check low power regulator parameter */
  676. #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) ||\
  677. ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON))
  678. /* Check low power mode entry parameter */
  679. #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) ||\
  680. ((ENTRY) == PWR_SLEEPENTRY_WFE))
  681. /* Check low power mode entry parameter */
  682. #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) ||\
  683. ((ENTRY) == PWR_STOPENTRY_WFE))
  684. /* Check voltage scale level parameter */
  685. #define IS_PWR_REGULATOR_VOLTAGE(VOLTAGE) (((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE0) || \
  686. ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE1) || \
  687. ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE2) || \
  688. ((VOLTAGE) == PWR_REGULATOR_VOLTAGE_SCALE3))
  689. /**
  690. * @}
  691. */
  692. /**
  693. * @}
  694. */
  695. /**
  696. * @}
  697. */
  698. /**
  699. * @}
  700. */
  701. #ifdef __cplusplus
  702. }
  703. #endif /* __cplusplus */
  704. #endif /* STM32H7xx_HAL_PWR_H */
  705. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/