stm32l4xx_hal_pwr.h 16 KB

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