stm32f2xx_hal_pwr.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. /**
  2. ******************************************************************************
  3. * @file stm32f2xx_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 __STM32F2xx_HAL_PWR_H
  21. #define __STM32F2xx_HAL_PWR_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32f2xx_hal_def.h"
  27. /** @addtogroup STM32F2xx_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.
  43. This parameter can be a value of @ref PWR_PVD_detection_level */
  44. uint32_t Mode; /*!< Mode: Specifies the operating mode for the selected pins.
  45. This parameter can be a value of @ref PWR_PVD_Mode */
  46. }PWR_PVDTypeDef;
  47. /**
  48. * @}
  49. */
  50. /* Exported constants --------------------------------------------------------*/
  51. /** @defgroup PWR_Exported_Constants PWR Exported Constants
  52. * @{
  53. */
  54. /** @defgroup PWR_WakeUp_Pins PWR WakeUp Pins
  55. * @{
  56. */
  57. #define PWR_WAKEUP_PIN1 0x00000100U
  58. /**
  59. * @}
  60. */
  61. /** @defgroup PWR_PVD_detection_level PWR PVD detection level
  62. * @{
  63. */
  64. #define PWR_PVDLEVEL_0 PWR_CR_PLS_LEV0
  65. #define PWR_PVDLEVEL_1 PWR_CR_PLS_LEV1
  66. #define PWR_PVDLEVEL_2 PWR_CR_PLS_LEV2
  67. #define PWR_PVDLEVEL_3 PWR_CR_PLS_LEV3
  68. #define PWR_PVDLEVEL_4 PWR_CR_PLS_LEV4
  69. #define PWR_PVDLEVEL_5 PWR_CR_PLS_LEV5
  70. #define PWR_PVDLEVEL_6 PWR_CR_PLS_LEV6
  71. #define PWR_PVDLEVEL_7 PWR_CR_PLS_LEV7/* External input analog voltage
  72. (Compare internally to VREFINT) */
  73. /**
  74. * @}
  75. */
  76. /** @defgroup PWR_PVD_Mode PWR PVD Mode
  77. * @{
  78. */
  79. #define PWR_PVD_MODE_NORMAL 0x00000000U /*!< basic mode is used */
  80. #define PWR_PVD_MODE_IT_RISING 0x00010001U /*!< External Interrupt Mode with Rising edge trigger detection */
  81. #define PWR_PVD_MODE_IT_FALLING 0x00010002U /*!< External Interrupt Mode with Falling edge trigger detection */
  82. #define PWR_PVD_MODE_IT_RISING_FALLING 0x00010003U /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
  83. #define PWR_PVD_MODE_EVENT_RISING 0x00020001U /*!< Event Mode with Rising edge trigger detection */
  84. #define PWR_PVD_MODE_EVENT_FALLING 0x00020002U /*!< Event Mode with Falling edge trigger detection */
  85. #define PWR_PVD_MODE_EVENT_RISING_FALLING 0x00020003U /*!< Event Mode with Rising/Falling edge trigger detection */
  86. /**
  87. * @}
  88. */
  89. /** @defgroup PWR_Regulator_state_in_STOP_mode PWR Regulator state in SLEEP/STOP mode
  90. * @{
  91. */
  92. #define PWR_MAINREGULATOR_ON 0x00000000U
  93. #define PWR_LOWPOWERREGULATOR_ON PWR_CR_LPDS
  94. /**
  95. * @}
  96. */
  97. /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry
  98. * @{
  99. */
  100. #define PWR_SLEEPENTRY_WFI ((uint8_t)0x01)
  101. #define PWR_SLEEPENTRY_WFE ((uint8_t)0x02)
  102. /**
  103. * @}
  104. */
  105. /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry
  106. * @{
  107. */
  108. #define PWR_STOPENTRY_WFI ((uint8_t)0x01)
  109. #define PWR_STOPENTRY_WFE ((uint8_t)0x02)
  110. /**
  111. * @}
  112. */
  113. /** @defgroup PWR_Flag PWR Flag
  114. * @{
  115. */
  116. #define PWR_FLAG_WU PWR_CSR_WUF
  117. #define PWR_FLAG_SB PWR_CSR_SBF
  118. #define PWR_FLAG_PVDO PWR_CSR_PVDO
  119. #define PWR_FLAG_BRR PWR_CSR_BRR
  120. /**
  121. * @}
  122. */
  123. /**
  124. * @}
  125. */
  126. /* Exported macro ------------------------------------------------------------*/
  127. /** @defgroup PWR_Exported_Macro PWR Exported Macro
  128. * @{
  129. */
  130. /** @brief Check PWR flag is set or not.
  131. * @param __FLAG__ specifies the flag to check.
  132. * This parameter can be one of the following values:
  133. * @arg PWR_FLAG_WU: Wake Up flag. This flag indicates that a wakeup event
  134. * was received from the WKUP pin or from the RTC alarm (Alarm A
  135. * or Alarm B), RTC Tamper event, RTC TimeStamp event or RTC Wakeup.
  136. * An additional wakeup event is detected if the WKUP pin is enabled
  137. * (by setting the EWUP bit) when the WKUP pin level is already high.
  138. * @arg PWR_FLAG_SB: StandBy flag. This flag indicates that the system was
  139. * resumed from StandBy mode.
  140. * @arg PWR_FLAG_PVDO: PVD Output. This flag is valid only if PVD is enabled
  141. * by the HAL_PWR_EnablePVD() function. The PVD is stopped by Standby mode
  142. * For this reason, this bit is equal to 0 after Standby or reset
  143. * until the PVDE bit is set.
  144. * @arg PWR_FLAG_BRR: Backup regulator ready flag. This bit is not reset
  145. * when the device wakes up from Standby mode or by a system reset
  146. * or power reset.
  147. * @retval The new state of __FLAG__ (TRUE or FALSE).
  148. */
  149. #define __HAL_PWR_GET_FLAG(__FLAG__) ((PWR->CSR & (__FLAG__)) == (__FLAG__))
  150. /** @brief Clear the PWR's pending flags.
  151. * @param __FLAG__ specifies the flag to clear.
  152. * This parameter can be one of the following values:
  153. * @arg PWR_FLAG_WU: Wake Up flag
  154. * @arg PWR_FLAG_SB: StandBy flag
  155. */
  156. #define __HAL_PWR_CLEAR_FLAG(__FLAG__) (PWR->CR |= (__FLAG__) << 2U)
  157. /**
  158. * @brief Enable the PVD Exti Line 16.
  159. * @retval None.
  160. */
  161. #define __HAL_PWR_PVD_EXTI_ENABLE_IT() (EXTI->IMR |= (PWR_EXTI_LINE_PVD))
  162. /**
  163. * @brief Disable the PVD EXTI Line 16.
  164. * @retval None.
  165. */
  166. #define __HAL_PWR_PVD_EXTI_DISABLE_IT() (EXTI->IMR &= ~(PWR_EXTI_LINE_PVD))
  167. /**
  168. * @brief Enable event on PVD Exti Line 16.
  169. * @retval None.
  170. */
  171. #define __HAL_PWR_PVD_EXTI_ENABLE_EVENT() (EXTI->EMR |= (PWR_EXTI_LINE_PVD))
  172. /**
  173. * @brief Disable event on PVD Exti Line 16.
  174. * @retval None.
  175. */
  176. #define __HAL_PWR_PVD_EXTI_DISABLE_EVENT() (EXTI->EMR &= ~(PWR_EXTI_LINE_PVD))
  177. /**
  178. * @brief Enable the PVD Extended Interrupt Rising Trigger.
  179. * @retval None.
  180. */
  181. #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR, PWR_EXTI_LINE_PVD)
  182. /**
  183. * @brief Disable the PVD Extended Interrupt Rising Trigger.
  184. * @retval None.
  185. */
  186. #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR, PWR_EXTI_LINE_PVD)
  187. /**
  188. * @brief Enable the PVD Extended Interrupt Falling Trigger.
  189. * @retval None.
  190. */
  191. #define __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR, PWR_EXTI_LINE_PVD)
  192. /**
  193. * @brief Disable the PVD Extended Interrupt Falling Trigger.
  194. * @retval None.
  195. */
  196. #define __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR, PWR_EXTI_LINE_PVD)
  197. /**
  198. * @brief PVD EXTI line configuration: set rising & falling edge trigger.
  199. * @retval None.
  200. */
  201. #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_FALLING_EDGE() do{ __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();\
  202. __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();\
  203. }while(0)
  204. /**
  205. * @brief Disable the PVD Extended Interrupt Rising & Falling Trigger.
  206. * This parameter can be:
  207. * @retval None.
  208. */
  209. #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_FALLING_EDGE() do{ __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();\
  210. __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE();\
  211. }while(0)
  212. /**
  213. * @brief checks whether the specified PVD Exti interrupt flag is set or not.
  214. * @retval EXTI PVD Line Status.
  215. */
  216. #define __HAL_PWR_PVD_EXTI_GET_FLAG() (EXTI->PR & (PWR_EXTI_LINE_PVD))
  217. /**
  218. * @brief Clear the PVD Exti flag.
  219. * @retval None.
  220. */
  221. #define __HAL_PWR_PVD_EXTI_CLEAR_FLAG() (EXTI->PR = (PWR_EXTI_LINE_PVD))
  222. /**
  223. * @brief Generates a Software interrupt on PVD EXTI line.
  224. * @retval None
  225. */
  226. #define __HAL_PWR_PVD_EXTI_GENERATE_SWIT() (EXTI->SWIER |= (PWR_EXTI_LINE_PVD))
  227. /**
  228. * @}
  229. */
  230. /* Include PWR HAL Extension module */
  231. #include "stm32f2xx_hal_pwr_ex.h"
  232. /* Exported functions --------------------------------------------------------*/
  233. /** @addtogroup PWR_Exported_Functions PWR Exported Functions
  234. * @{
  235. */
  236. /** @addtogroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions
  237. * @{
  238. */
  239. /* Initialization and de-initialization functions *****************************/
  240. void HAL_PWR_DeInit(void);
  241. void HAL_PWR_EnableBkUpAccess(void);
  242. void HAL_PWR_DisableBkUpAccess(void);
  243. /**
  244. * @}
  245. */
  246. /** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions
  247. * @{
  248. */
  249. /* Peripheral Control functions **********************************************/
  250. /* PVD configuration */
  251. void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD);
  252. void HAL_PWR_EnablePVD(void);
  253. void HAL_PWR_DisablePVD(void);
  254. /* WakeUp pins configuration */
  255. void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx);
  256. void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx);
  257. /* Low Power modes entry */
  258. void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
  259. void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry);
  260. void HAL_PWR_EnterSTANDBYMode(void);
  261. /* Power PVD IRQ Handler */
  262. void HAL_PWR_PVD_IRQHandler(void);
  263. void HAL_PWR_PVDCallback(void);
  264. /* Cortex System Control functions *******************************************/
  265. void HAL_PWR_EnableSleepOnExit(void);
  266. void HAL_PWR_DisableSleepOnExit(void);
  267. void HAL_PWR_EnableSEVOnPend(void);
  268. void HAL_PWR_DisableSEVOnPend(void);
  269. /**
  270. * @}
  271. */
  272. /**
  273. * @}
  274. */
  275. /* Private types -------------------------------------------------------------*/
  276. /* Private variables ---------------------------------------------------------*/
  277. /* Private constants ---------------------------------------------------------*/
  278. /** @defgroup PWR_Private_Constants PWR Private Constants
  279. * @{
  280. */
  281. /** @defgroup PWR_PVD_EXTI_Line PWR PVD EXTI Line
  282. * @{
  283. */
  284. #define PWR_EXTI_LINE_PVD ((uint32_t)EXTI_IMR_MR16) /*!< External interrupt line 16 Connected to the PVD EXTI Line */
  285. /**
  286. * @}
  287. */
  288. /** @defgroup PWR_register_alias_address PWR Register alias address
  289. * @{
  290. */
  291. /* ------------- PWR registers bit address in the alias region ---------------*/
  292. #define PWR_OFFSET (PWR_BASE - PERIPH_BASE)
  293. #define PWR_CR_OFFSET 0x00U
  294. #define PWR_CSR_OFFSET 0x04U
  295. #define PWR_CR_OFFSET_BB (PWR_OFFSET + PWR_CR_OFFSET)
  296. #define PWR_CSR_OFFSET_BB (PWR_OFFSET + PWR_CSR_OFFSET)
  297. /**
  298. * @}
  299. */
  300. /** @defgroup PWR_CR_register_alias PWR CR Register alias address
  301. * @{
  302. */
  303. /* --- CR Register ---*/
  304. /* Alias word address of DBP bit */
  305. #define DBP_BIT_NUMBER POSITION_VAL(PWR_CR_DBP)
  306. #define CR_DBP_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (DBP_BIT_NUMBER * 4U))
  307. /* Alias word address of PVDE bit */
  308. #define PVDE_BIT_NUMBER POSITION_VAL(PWR_CR_PVDE)
  309. #define CR_PVDE_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (PVDE_BIT_NUMBER * 4U))
  310. /**
  311. * @}
  312. */
  313. /** @defgroup PWR_CSR_register_alias PWR CSR Register alias address
  314. * @{
  315. */
  316. /* --- CSR Register ---*/
  317. /* Alias word address of EWUP bit */
  318. #define EWUP_BIT_NUMBER POSITION_VAL(PWR_CSR_EWUP)
  319. #define CSR_EWUP_BB (PERIPH_BB_BASE + (PWR_CSR_OFFSET_BB * 32U) + (EWUP_BIT_NUMBER * 4U))
  320. /**
  321. * @}
  322. */
  323. /**
  324. * @}
  325. */
  326. /* Private macros ------------------------------------------------------------*/
  327. /** @defgroup PWR_Private_Macros PWR Private Macros
  328. * @{
  329. */
  330. /** @defgroup PWR_IS_PWR_Definitions PWR Private macros to check input parameters
  331. * @{
  332. */
  333. #define IS_PWR_WAKEUP_PIN(PIN) ((PIN) == PWR_WAKEUP_PIN1)
  334. #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLEVEL_0) || ((LEVEL) == PWR_PVDLEVEL_1)|| \
  335. ((LEVEL) == PWR_PVDLEVEL_2) || ((LEVEL) == PWR_PVDLEVEL_3)|| \
  336. ((LEVEL) == PWR_PVDLEVEL_4) || ((LEVEL) == PWR_PVDLEVEL_5)|| \
  337. ((LEVEL) == PWR_PVDLEVEL_6) || ((LEVEL) == PWR_PVDLEVEL_7))
  338. #define IS_PWR_PVD_MODE(MODE) (((MODE) == PWR_PVD_MODE_IT_RISING)|| ((MODE) == PWR_PVD_MODE_IT_FALLING) || \
  339. ((MODE) == PWR_PVD_MODE_IT_RISING_FALLING) || ((MODE) == PWR_PVD_MODE_EVENT_RISING) || \
  340. ((MODE) == PWR_PVD_MODE_EVENT_FALLING) || ((MODE) == PWR_PVD_MODE_EVENT_RISING_FALLING) || \
  341. ((MODE) == PWR_PVD_MODE_NORMAL))
  342. #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \
  343. ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON))
  344. #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE))
  345. #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE))
  346. /**
  347. * @}
  348. */
  349. /**
  350. * @}
  351. */
  352. /**
  353. * @}
  354. */
  355. /**
  356. * @}
  357. */
  358. #ifdef __cplusplus
  359. }
  360. #endif
  361. #endif /* __STM32F2xx_HAL_PWR_H */
  362. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/