stm32l4xx_hal_pwr.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_pwr.h
  4. * @author MCD Application Team
  5. * @brief Header file of PWR HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef STM32L4xx_HAL_PWR_H
  20. #define STM32L4xx_HAL_PWR_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32l4xx_hal_def.h"
  26. /** @addtogroup STM32L4xx_HAL_Driver
  27. * @{
  28. */
  29. /** @addtogroup PWR
  30. * @{
  31. */
  32. /* Exported types ------------------------------------------------------------*/
  33. /** @defgroup PWR_Exported_Types PWR Exported Types
  34. * @{
  35. */
  36. /**
  37. * @brief PWR PVD configuration structure definition
  38. */
  39. typedef struct
  40. {
  41. uint32_t PVDLevel; /*!< PVDLevel: Specifies the PVD detection level.
  42. This parameter can be a value of @ref PWR_PVD_detection_level. */
  43. uint32_t Mode; /*!< Mode: Specifies the operating mode for the selected pins.
  44. This parameter can be a value of @ref PWR_PVD_Mode. */
  45. }PWR_PVDTypeDef;
  46. /**
  47. * @}
  48. */
  49. /* Exported constants --------------------------------------------------------*/
  50. /** @defgroup PWR_Exported_Constants PWR Exported Constants
  51. * @{
  52. */
  53. /** @defgroup PWR_PVD_detection_level Programmable Voltage Detection levels
  54. * @{
  55. */
  56. #define PWR_PVDLEVEL_0 PWR_CR2_PLS_LEV0 /*!< PVD threshold around 2.0 V */
  57. #define PWR_PVDLEVEL_1 PWR_CR2_PLS_LEV1 /*!< PVD threshold around 2.2 V */
  58. #define PWR_PVDLEVEL_2 PWR_CR2_PLS_LEV2 /*!< PVD threshold around 2.4 V */
  59. #define PWR_PVDLEVEL_3 PWR_CR2_PLS_LEV3 /*!< PVD threshold around 2.5 V */
  60. #define PWR_PVDLEVEL_4 PWR_CR2_PLS_LEV4 /*!< PVD threshold around 2.6 V */
  61. #define PWR_PVDLEVEL_5 PWR_CR2_PLS_LEV5 /*!< PVD threshold around 2.8 V */
  62. #define PWR_PVDLEVEL_6 PWR_CR2_PLS_LEV6 /*!< PVD threshold around 2.9 V */
  63. #define PWR_PVDLEVEL_7 PWR_CR2_PLS_LEV7 /*!< External input analog voltage (compared internally to VREFINT) */
  64. /**
  65. * @}
  66. */
  67. /** @defgroup PWR_PVD_Mode PWR PVD interrupt and event mode
  68. * @{
  69. */
  70. #define PWR_PVD_MODE_NORMAL ((uint32_t)0x00000000) /*!< Basic mode is used */
  71. #define PWR_PVD_MODE_IT_RISING ((uint32_t)0x00010001) /*!< External Interrupt Mode with Rising edge trigger detection */
  72. #define PWR_PVD_MODE_IT_FALLING ((uint32_t)0x00010002) /*!< External Interrupt Mode with Falling edge trigger detection */
  73. #define PWR_PVD_MODE_IT_RISING_FALLING ((uint32_t)0x00010003) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
  74. #define PWR_PVD_MODE_EVENT_RISING ((uint32_t)0x00020001) /*!< Event Mode with Rising edge trigger detection */
  75. #define PWR_PVD_MODE_EVENT_FALLING ((uint32_t)0x00020002) /*!< Event Mode with Falling edge trigger detection */
  76. #define PWR_PVD_MODE_EVENT_RISING_FALLING ((uint32_t)0x00020003) /*!< Event Mode with Rising/Falling edge trigger detection */
  77. /**
  78. * @}
  79. */
  80. /** @defgroup PWR_Regulator_state_in_SLEEP_STOP_mode PWR regulator mode
  81. * @{
  82. */
  83. #define PWR_MAINREGULATOR_ON ((uint32_t)0x00000000) /*!< Regulator in main mode */
  84. #define PWR_LOWPOWERREGULATOR_ON PWR_CR1_LPR /*!< Regulator in low-power mode */
  85. /**
  86. * @}
  87. */
  88. /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry
  89. * @{
  90. */
  91. #define PWR_SLEEPENTRY_WFI ((uint8_t)0x01) /*!< Wait For Interruption instruction to enter Sleep mode */
  92. #define PWR_SLEEPENTRY_WFE ((uint8_t)0x02) /*!< Wait For Event instruction to enter Sleep mode */
  93. /**
  94. * @}
  95. */
  96. /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry
  97. * @{
  98. */
  99. #define PWR_STOPENTRY_WFI ((uint8_t)0x01) /*!< Wait For Interruption instruction to enter Stop mode */
  100. #define PWR_STOPENTRY_WFE ((uint8_t)0x02) /*!< Wait For Event instruction to enter Stop mode */
  101. /**
  102. * @}
  103. */
  104. /** @defgroup PWR_PVD_EXTI_LINE PWR PVD external interrupt line
  105. * @{
  106. */
  107. #define PWR_EXTI_LINE_PVD ((uint32_t)0x00010000) /*!< External interrupt line 16 Connected to the PVD EXTI Line */
  108. /**
  109. * @}
  110. */
  111. /** @defgroup PWR_PVD_EVENT_LINE PWR PVD event line
  112. * @{
  113. */
  114. #define PWR_EVENT_LINE_PVD ((uint32_t)0x00010000) /*!< Event line 16 Connected to the PVD Event Line */
  115. /**
  116. * @}
  117. */
  118. /**
  119. * @}
  120. */
  121. /* Exported macros -----------------------------------------------------------*/
  122. /** @defgroup PWR_Exported_Macros PWR Exported Macros
  123. * @{
  124. */
  125. /** @brief Check whether or not a specific PWR flag is set.
  126. * @param __FLAG__ specifies the flag to check.
  127. * This parameter can be one of the following values:
  128. * @arg @ref PWR_FLAG_WUF1 Wake Up Flag 1. Indicates that a wakeup event
  129. * was received from the WKUP pin 1.
  130. * @arg @ref PWR_FLAG_WUF2 Wake Up Flag 2. Indicates that a wakeup event
  131. * was received from the WKUP pin 2.
  132. * @arg @ref PWR_FLAG_WUF3 Wake Up Flag 3. Indicates that a wakeup event
  133. * was received from the WKUP pin 3.
  134. * @arg @ref PWR_FLAG_WUF4 Wake Up Flag 4. Indicates that a wakeup event
  135. * was received from the WKUP pin 4.
  136. * @arg @ref PWR_FLAG_WUF5 Wake Up Flag 5. Indicates that a wakeup event
  137. * was received from the WKUP pin 5.
  138. * @arg @ref PWR_FLAG_SB StandBy Flag. Indicates that the system
  139. * entered StandBy mode.
  140. * @arg @ref PWR_FLAG_EXT_SMPS External SMPS Ready Flag. When available on device, indicates
  141. * that external switch can be closed to connect to the external SMPS, when the Range 2
  142. * of internal regulator is ready.
  143. * @arg @ref PWR_FLAG_WUFI Wake-Up Flag Internal. Set when a wakeup is detected on
  144. * the internal wakeup line.
  145. * @arg @ref PWR_FLAG_REGLPS Low Power Regulator Started. Indicates whether or not the
  146. * low-power regulator is ready.
  147. * @arg @ref PWR_FLAG_REGLPF Low Power Regulator Flag. Indicates whether the
  148. * regulator is ready in main mode or is in low-power mode.
  149. * @arg @ref PWR_FLAG_VOSF Voltage Scaling Flag. Indicates whether the regulator is ready
  150. * in the selected voltage range or is still changing to the required voltage level.
  151. * @arg @ref PWR_FLAG_PVDO Power Voltage Detector Output. Indicates whether VDD voltage is
  152. * below or above the selected PVD threshold.
  153. * @arg @ref PWR_FLAG_PVMO1 Peripheral Voltage Monitoring Output 1. Indicates whether VDDUSB voltage is
  154. * is below or above PVM1 threshold (applicable when USB feature is supported).
  155. @if STM32L486xx
  156. * @arg @ref PWR_FLAG_PVMO2 Peripheral Voltage Monitoring Output 2. Indicates whether VDDIO2 voltage is
  157. * is below or above PVM2 threshold (applicable when VDDIO2 is present on device).
  158. @endif
  159. * @arg @ref PWR_FLAG_PVMO3 Peripheral Voltage Monitoring Output 3. Indicates whether VDDA voltage is
  160. * is below or above PVM3 threshold.
  161. * @arg @ref PWR_FLAG_PVMO4 Peripheral Voltage Monitoring Output 4. Indicates whether VDDA voltage is
  162. * is below or above PVM4 threshold.
  163. *
  164. * @retval The new state of __FLAG__ (TRUE or FALSE).
  165. */
  166. #define __HAL_PWR_GET_FLAG(__FLAG__) ( ((((uint8_t)(__FLAG__)) >> 5U) == 1) ?\
  167. (PWR->SR1 & (1U << ((__FLAG__) & 31U))) :\
  168. (PWR->SR2 & (1U << ((__FLAG__) & 31U))) )
  169. /** @brief Clear a specific PWR flag.
  170. * @param __FLAG__ specifies the flag to clear.
  171. * This parameter can be one of the following values:
  172. * @arg @ref PWR_FLAG_WUF1 Wake Up Flag 1. Indicates that a wakeup event
  173. * was received from the WKUP pin 1.
  174. * @arg @ref PWR_FLAG_WUF2 Wake Up Flag 2. Indicates that a wakeup event
  175. * was received from the WKUP pin 2.
  176. * @arg @ref PWR_FLAG_WUF3 Wake Up Flag 3. Indicates that a wakeup event
  177. * was received from the WKUP pin 3.
  178. * @arg @ref PWR_FLAG_WUF4 Wake Up Flag 4. Indicates that a wakeup event
  179. * was received from the WKUP pin 4.
  180. * @arg @ref PWR_FLAG_WUF5 Wake Up Flag 5. Indicates that a wakeup event
  181. * was received from the WKUP pin 5.
  182. * @arg @ref PWR_FLAG_WU Encompasses all five Wake Up Flags.
  183. * @arg @ref PWR_FLAG_SB Standby Flag. Indicates that the system
  184. * entered Standby mode.
  185. * @retval None
  186. */
  187. #define __HAL_PWR_CLEAR_FLAG(__FLAG__) ( (((uint8_t)(__FLAG__)) == PWR_FLAG_WU) ?\
  188. (PWR->SCR = (__FLAG__)) :\
  189. (PWR->SCR = (1U << ((__FLAG__) & 31U))) )
  190. /**
  191. * @brief Enable the PVD Extended Interrupt Line.
  192. * @retval None
  193. */
  194. #define __HAL_PWR_PVD_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR1, PWR_EXTI_LINE_PVD)
  195. /**
  196. * @brief Disable the PVD Extended Interrupt Line.
  197. * @retval None
  198. */
  199. #define __HAL_PWR_PVD_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR1, PWR_EXTI_LINE_PVD)
  200. /**
  201. * @brief Enable the PVD Event Line.
  202. * @retval None
  203. */
  204. #define __HAL_PWR_PVD_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR1, PWR_EVENT_LINE_PVD)
  205. /**
  206. * @brief Disable the PVD Event Line.
  207. * @retval None
  208. */
  209. #define __HAL_PWR_PVD_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR1, PWR_EVENT_LINE_PVD)
  210. /**
  211. * @brief Enable the PVD Extended Interrupt Rising Trigger.
  212. * @retval None
  213. */
  214. #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR1, PWR_EXTI_LINE_PVD)
  215. /**
  216. * @brief Disable the PVD Extended Interrupt Rising Trigger.
  217. * @retval None
  218. */
  219. #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR1, PWR_EXTI_LINE_PVD)
  220. /**
  221. * @brief Enable the PVD Extended Interrupt Falling Trigger.
  222. * @retval None
  223. */
  224. #define __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR1, PWR_EXTI_LINE_PVD)
  225. /**
  226. * @brief Disable the PVD Extended Interrupt Falling Trigger.
  227. * @retval None
  228. */
  229. #define __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR1, PWR_EXTI_LINE_PVD)
  230. /**
  231. * @brief Enable the PVD Extended Interrupt Rising & Falling Trigger.
  232. * @retval None
  233. */
  234. #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_FALLING_EDGE() \
  235. do { \
  236. __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE(); \
  237. __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE(); \
  238. } while(0)
  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() \
  244. do { \
  245. __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE(); \
  246. __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE(); \
  247. } while(0)
  248. /**
  249. * @brief Generate a Software interrupt on selected EXTI line.
  250. * @retval None
  251. */
  252. #define __HAL_PWR_PVD_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER1, PWR_EXTI_LINE_PVD)
  253. /**
  254. * @brief Check whether or not the PVD EXTI interrupt flag is set.
  255. * @retval EXTI PVD Line Status.
  256. */
  257. #define __HAL_PWR_PVD_EXTI_GET_FLAG() (EXTI->PR1 & PWR_EXTI_LINE_PVD)
  258. /**
  259. * @brief Clear the PVD EXTI interrupt flag.
  260. * @retval None
  261. */
  262. #define __HAL_PWR_PVD_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR1, PWR_EXTI_LINE_PVD)
  263. /**
  264. * @}
  265. */
  266. /* Private macros --------------------------------------------------------*/
  267. /** @addtogroup PWR_Private_Macros PWR Private Macros
  268. * @{
  269. */
  270. #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLEVEL_0) || ((LEVEL) == PWR_PVDLEVEL_1)|| \
  271. ((LEVEL) == PWR_PVDLEVEL_2) || ((LEVEL) == PWR_PVDLEVEL_3)|| \
  272. ((LEVEL) == PWR_PVDLEVEL_4) || ((LEVEL) == PWR_PVDLEVEL_5)|| \
  273. ((LEVEL) == PWR_PVDLEVEL_6) || ((LEVEL) == PWR_PVDLEVEL_7))
  274. #define IS_PWR_PVD_MODE(MODE) (((MODE) == PWR_PVD_MODE_NORMAL) ||\
  275. ((MODE) == PWR_PVD_MODE_IT_RISING) ||\
  276. ((MODE) == PWR_PVD_MODE_IT_FALLING) ||\
  277. ((MODE) == PWR_PVD_MODE_IT_RISING_FALLING) ||\
  278. ((MODE) == PWR_PVD_MODE_EVENT_RISING) ||\
  279. ((MODE) == PWR_PVD_MODE_EVENT_FALLING) ||\
  280. ((MODE) == PWR_PVD_MODE_EVENT_RISING_FALLING))
  281. #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \
  282. ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON))
  283. #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE))
  284. #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE) )
  285. /**
  286. * @}
  287. */
  288. /* Include PWR HAL Extended module */
  289. #include "stm32l4xx_hal_pwr_ex.h"
  290. /* Exported functions --------------------------------------------------------*/
  291. /** @addtogroup PWR_Exported_Functions PWR Exported Functions
  292. * @{
  293. */
  294. /** @addtogroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions
  295. * @{
  296. */
  297. /* Initialization and de-initialization functions *******************************/
  298. void HAL_PWR_DeInit(void);
  299. void HAL_PWR_EnableBkUpAccess(void);
  300. void HAL_PWR_DisableBkUpAccess(void);
  301. /**
  302. * @}
  303. */
  304. /** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions
  305. * @{
  306. */
  307. /* Peripheral Control functions ************************************************/
  308. HAL_StatusTypeDef HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD);
  309. void HAL_PWR_EnablePVD(void);
  310. void HAL_PWR_DisablePVD(void);
  311. /* WakeUp pins configuration functions ****************************************/
  312. void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity);
  313. void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx);
  314. /* Low Power modes configuration functions ************************************/
  315. void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry);
  316. void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
  317. void HAL_PWR_EnterSTANDBYMode(void);
  318. void HAL_PWR_EnableSleepOnExit(void);
  319. void HAL_PWR_DisableSleepOnExit(void);
  320. void HAL_PWR_EnableSEVOnPend(void);
  321. void HAL_PWR_DisableSEVOnPend(void);
  322. void HAL_PWR_PVDCallback(void);
  323. /**
  324. * @}
  325. */
  326. /**
  327. * @}
  328. */
  329. /**
  330. * @}
  331. */
  332. /**
  333. * @}
  334. */
  335. #ifdef __cplusplus
  336. }
  337. #endif
  338. #endif /* STM32L4xx_HAL_PWR_H */