stm32l4xx_hal_pwr.h 15 KB

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