stm32l0xx_hal_pwr.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_hal_pwr.h
  4. * @author MCD Application Team
  5. * @brief Header file of PWR HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2016 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 __STM32L0xx_HAL_PWR_H
  20. #define __STM32L0xx_HAL_PWR_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32l0xx_hal_def.h"
  26. /** @addtogroup STM32L0xx_HAL_Driver
  27. * @{
  28. */
  29. /** @defgroup PWR PWR
  30. * @{
  31. */
  32. /** @defgroup PWR_Exported_Types PWR Exported Types
  33. * @{
  34. */
  35. #if defined(PWR_PVD_SUPPORT)
  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. #endif
  47. /**
  48. * @}
  49. */
  50. /** @addtogroup PWR_Private
  51. * @{
  52. */
  53. #if defined(PWR_PVD_SUPPORT)
  54. #define PWR_EXTI_LINE_PVD EXTI_FTSR_TR16 /*!< External interrupt line 16 Connected to the PVD EXTI Line */
  55. #endif
  56. /**
  57. * @}
  58. */
  59. /** @defgroup PWR_Exported_Constants PWR Exported Constants
  60. * @{
  61. */
  62. /** @defgroup PWR_register_alias_address PWR Register alias address
  63. * @{
  64. */
  65. #define PWR_WAKEUP_PIN1 PWR_CSR_EWUP1
  66. #if defined (STM32L010x4) || defined (STM32L011xx) || defined (STM32L021xx)
  67. #else
  68. #define PWR_WAKEUP_PIN2 PWR_CSR_EWUP2
  69. #endif
  70. #if defined (STM32L010x4) || defined (STM32L010x6) || defined (STM32L011xx) || defined (STM32L021xx) || \
  71. defined (STM32L031xx) || defined (STM32L041xx) || defined (STM32L071xx) || defined (STM32L072xx) || \
  72. defined (STM32L073xx) || defined (STM32L081xx) || defined (STM32L082xx) || defined (STM32L083xx)
  73. #define PWR_WAKEUP_PIN3 PWR_CSR_EWUP3
  74. #endif
  75. /**
  76. * @}
  77. */
  78. #if defined(PWR_PVD_SUPPORT)
  79. /** @defgroup PWR_PVD_detection_level PVD detection level
  80. * @{
  81. */
  82. #define PWR_PVDLEVEL_0 PWR_CR_PLS_LEV0
  83. #define PWR_PVDLEVEL_1 PWR_CR_PLS_LEV1
  84. #define PWR_PVDLEVEL_2 PWR_CR_PLS_LEV2
  85. #define PWR_PVDLEVEL_3 PWR_CR_PLS_LEV3
  86. #define PWR_PVDLEVEL_4 PWR_CR_PLS_LEV4
  87. #define PWR_PVDLEVEL_5 PWR_CR_PLS_LEV5
  88. #define PWR_PVDLEVEL_6 PWR_CR_PLS_LEV6
  89. #define PWR_PVDLEVEL_7 PWR_CR_PLS_LEV7 /* External input analog voltage
  90. (Compare internally to VREFINT) */
  91. /**
  92. * @}
  93. */
  94. /** @defgroup PWR_PVD_Mode PWR PVD Mode
  95. * @{
  96. */
  97. #define PWR_PVD_MODE_NORMAL (0x00000000U) /*!< basic mode is used */
  98. #define PWR_PVD_MODE_IT_RISING (0x00010001U) /*!< External Interrupt Mode with Rising edge trigger detection */
  99. #define PWR_PVD_MODE_IT_FALLING (0x00010002U) /*!< External Interrupt Mode with Falling edge trigger detection */
  100. #define PWR_PVD_MODE_IT_RISING_FALLING (0x00010003U) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
  101. #define PWR_PVD_MODE_EVENT_RISING (0x00020001U) /*!< Event Mode with Rising edge trigger detection */
  102. #define PWR_PVD_MODE_EVENT_FALLING (0x00020002U) /*!< Event Mode with Falling edge trigger detection */
  103. #define PWR_PVD_MODE_EVENT_RISING_FALLING (0x00020003U) /*!< Event Mode with Rising/Falling edge trigger detection */
  104. /**
  105. * @}
  106. */
  107. #endif /* PWR_PVD_SUPPORT */
  108. /** @defgroup PWR_Regulator_state_in_SLEEP_STOP_mode PWR Regulator state in SLEEP/STOP mode
  109. * @{
  110. */
  111. #define PWR_MAINREGULATOR_ON (0x00000000U)
  112. #define PWR_LOWPOWERREGULATOR_ON PWR_CR_LPSDSR
  113. /**
  114. * @}
  115. */
  116. /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry
  117. * @{
  118. */
  119. #define PWR_SLEEPENTRY_WFI (0x01U)
  120. #define PWR_SLEEPENTRY_WFE (0x02U)
  121. /**
  122. * @}
  123. */
  124. /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry
  125. * @{
  126. */
  127. #define PWR_STOPENTRY_WFI (0x01U)
  128. #define PWR_STOPENTRY_WFE (0x02U)
  129. /**
  130. * @}
  131. */
  132. /** @defgroup PWR_Regulator_Voltage_Scale PWR Regulator Voltage Scale
  133. * @{
  134. */
  135. #define PWR_REGULATOR_VOLTAGE_SCALE1 PWR_CR_VOS_0
  136. #define PWR_REGULATOR_VOLTAGE_SCALE2 PWR_CR_VOS_1
  137. #define PWR_REGULATOR_VOLTAGE_SCALE3 PWR_CR_VOS
  138. #define IS_PWR_VOLTAGE_SCALING_RANGE(RANGE) (((RANGE) == PWR_REGULATOR_VOLTAGE_SCALE1) || \
  139. ((RANGE) == PWR_REGULATOR_VOLTAGE_SCALE2) || \
  140. ((RANGE) == PWR_REGULATOR_VOLTAGE_SCALE3))
  141. /**
  142. * @}
  143. */
  144. /** @defgroup PWR_Flag PWR Flag
  145. * @{
  146. */
  147. #define PWR_FLAG_WU PWR_CSR_WUF
  148. #define PWR_FLAG_SB PWR_CSR_SBF
  149. #if defined(PWR_PVD_SUPPORT)
  150. #define PWR_FLAG_PVDO PWR_CSR_PVDO
  151. #endif
  152. #define PWR_FLAG_VREFINTRDY PWR_CSR_VREFINTRDYF
  153. #define PWR_FLAG_VOS PWR_CSR_VOSF
  154. #define PWR_FLAG_REGLP PWR_CSR_REGLPF
  155. /**
  156. * @}
  157. */
  158. /**
  159. * @}
  160. */
  161. /** @defgroup PWR_Exported_Macro PWR Exported Macros
  162. * @{
  163. */
  164. /** @brief macros configure the main internal regulator output voltage.
  165. * When exiting Low Power Run Mode or during dynamic voltage scaling configuration,
  166. * the reference manual recommends to poll PWR_FLAG_REGLP bit to wait for the regulator
  167. * to reach main mode (resp. to get stabilized) for a transition from 0 to 1.
  168. * Only then the clock can be increased.
  169. *
  170. * @param __REGULATOR__ specifies the regulator output voltage to achieve
  171. * a tradeoff between performance and power consumption when the device does
  172. * not operate at the maximum frequency (refer to the datasheets for more details).
  173. * This parameter can be one of the following values:
  174. * @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output Scale 1 mode,
  175. * System frequency up to 32 MHz.
  176. * @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output Scale 2 mode,
  177. * System frequency up to 16 MHz.
  178. * @arg PWR_REGULATOR_VOLTAGE_SCALE3: Regulator voltage output Scale 3 mode,
  179. * System frequency up to 4.2 MHz
  180. * @retval None
  181. */
  182. #define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__) (MODIFY_REG(PWR->CR, PWR_CR_VOS, (__REGULATOR__)))
  183. /** @brief Check PWR flag is set or not.
  184. * @param __FLAG__ specifies the flag to check.
  185. * This parameter can be one of the following values:
  186. * @arg PWR_FLAG_WU: Wake Up flag. This flag indicates that a wakeup event
  187. * was received from the WKUP pin or from the RTC alarm (Alarm B),
  188. * RTC Tamper event, RTC TimeStamp event or RTC Wakeup.
  189. * An additional wakeup event is detected if the WKUP pin is enabled
  190. * (by setting the EWUP bit) when the WKUP pin level is already high.
  191. * @arg PWR_FLAG_SB: StandBy flag. This flag indicates that the system was
  192. * resumed from StandBy mode.
  193. * @arg PWR_FLAG_PVDO: PVD Output. This flag is valid only if PVD is enabled
  194. * by the HAL_PWR_EnablePVD() function. The PVD is stopped by Standby mode.
  195. * For this reason, this bit is equal to 0 after Standby or reset
  196. * until the PVDE bit is set. Not available on L0 Value line.
  197. * @arg PWR_FLAG_VREFINTRDY: Internal voltage reference (VREFINT) ready flag.
  198. * This bit indicates the state of the internal voltage reference, VREFINT.
  199. * @arg PWR_FLAG_VOS: Voltage Scaling select flag. A delay is required for
  200. * the internal regulator to be ready after the voltage range is changed.
  201. * The VOSF bit indicates that the regulator has reached the voltage level
  202. * defined with bits VOS of PWR_CR register.
  203. * @arg PWR_FLAG_REGLP: Regulator LP flag. When the MCU exits from Low power run
  204. * mode, this bit stays at 1 until the regulator is ready in main mode.
  205. * A polling on this bit is recommended to wait for the regulator main mode.
  206. * This bit is reset by hardware when the regulator is ready.
  207. * @retval The new state of __FLAG__ (TRUE or FALSE).
  208. */
  209. #define __HAL_PWR_GET_FLAG(__FLAG__) ((PWR->CSR & (__FLAG__)) == (__FLAG__))
  210. /** @brief Clear the PWR pending flags.
  211. * @param __FLAG__ specifies the flag to clear.
  212. * This parameter can be one of the following values:
  213. * @arg PWR_FLAG_WU: Wake Up flag
  214. * @arg PWR_FLAG_SB: StandBy flag
  215. */
  216. #define __HAL_PWR_CLEAR_FLAG(__FLAG__) SET_BIT(PWR->CR, (__FLAG__) << 2U)
  217. #if defined(PWR_PVD_SUPPORT)
  218. /**
  219. * @brief Enable interrupt on PVD Exti Line 16.
  220. * @retval None.
  221. */
  222. #define __HAL_PWR_PVD_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR, PWR_EXTI_LINE_PVD)
  223. /**
  224. * @brief Disable interrupt on PVD Exti Line 16.
  225. * @retval None.
  226. */
  227. #define __HAL_PWR_PVD_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR, PWR_EXTI_LINE_PVD)
  228. /**
  229. * @brief Enable event on PVD Exti Line 16.
  230. * @retval None.
  231. */
  232. #define __HAL_PWR_PVD_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR, PWR_EXTI_LINE_PVD)
  233. /**
  234. * @brief Disable event on PVD Exti Line 16.
  235. * @retval None.
  236. */
  237. #define __HAL_PWR_PVD_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR, PWR_EXTI_LINE_PVD)
  238. /**
  239. * @brief PVD EXTI line configuration: set falling edge trigger.
  240. * @retval None.
  241. */
  242. #define __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR, PWR_EXTI_LINE_PVD)
  243. /**
  244. * @brief Disable the PVD Extended Interrupt Falling Trigger.
  245. * @retval None.
  246. */
  247. #define __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR, PWR_EXTI_LINE_PVD)
  248. /**
  249. * @brief PVD EXTI line configuration: set rising edge trigger.
  250. * @retval None.
  251. */
  252. #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR, PWR_EXTI_LINE_PVD)
  253. /**
  254. * @brief Disable the PVD Extended Interrupt Rising Trigger.
  255. * This parameter can be:
  256. * @retval None.
  257. */
  258. #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR, PWR_EXTI_LINE_PVD)
  259. /**
  260. * @brief PVD EXTI line configuration: set rising & falling edge trigger.
  261. * @retval None.
  262. */
  263. #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_FALLING_EDGE() do { __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();__HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE(); } while(0);
  264. /**
  265. * @brief Disable the PVD Extended Interrupt Rising & Falling Trigger.
  266. * This parameter can be:
  267. * @retval None.
  268. */
  269. #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_FALLING_EDGE() do { __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();__HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE(); } while(0);
  270. /**
  271. * @brief Check whether the specified PVD EXTI interrupt flag is set or not.
  272. * @retval EXTI PVD Line Status.
  273. */
  274. #define __HAL_PWR_PVD_EXTI_GET_FLAG() (EXTI->PR & (PWR_EXTI_LINE_PVD))
  275. /**
  276. * @brief Clear the PVD EXTI flag.
  277. * @retval None.
  278. */
  279. #define __HAL_PWR_PVD_EXTI_CLEAR_FLAG() (EXTI->PR = (PWR_EXTI_LINE_PVD))
  280. /**
  281. * @brief Generate a Software interrupt on selected EXTI line.
  282. * @retval None.
  283. */
  284. #define __HAL_PWR_PVD_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER, PWR_EXTI_LINE_PVD)
  285. #endif /* PWR_PVD_SUPPORT */
  286. /**
  287. * @}
  288. */
  289. /** @addtogroup PWR_Private
  290. * @{
  291. */
  292. #if defined(PWR_PVD_SUPPORT)
  293. #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLEVEL_0) || ((LEVEL) == PWR_PVDLEVEL_1)|| \
  294. ((LEVEL) == PWR_PVDLEVEL_2) || ((LEVEL) == PWR_PVDLEVEL_3)|| \
  295. ((LEVEL) == PWR_PVDLEVEL_4) || ((LEVEL) == PWR_PVDLEVEL_5)|| \
  296. ((LEVEL) == PWR_PVDLEVEL_6) || ((LEVEL) == PWR_PVDLEVEL_7))
  297. #define IS_PWR_PVD_MODE(MODE) (((MODE) == PWR_PVD_MODE_IT_RISING)|| ((MODE) == PWR_PVD_MODE_IT_FALLING) || \
  298. ((MODE) == PWR_PVD_MODE_IT_RISING_FALLING) || ((MODE) == PWR_PVD_MODE_EVENT_RISING) || \
  299. ((MODE) == PWR_PVD_MODE_EVENT_FALLING) || ((MODE) == PWR_PVD_MODE_EVENT_RISING_FALLING) || \
  300. ((MODE) == PWR_PVD_MODE_NORMAL))
  301. #endif /* PWR_PVD_SUPPORT */
  302. #if defined (STM32L010x6) || defined (STM32L071xx) || defined (STM32L072xx) || defined (STM32L073xx) || defined (STM32L081xx) || defined (STM32L082xx) || defined (STM32L083xx)
  303. #define IS_PWR_WAKEUP_PIN(PIN) (((PIN) == PWR_WAKEUP_PIN1) || \
  304. ((PIN) == PWR_WAKEUP_PIN2) || \
  305. ((PIN) == PWR_WAKEUP_PIN3))
  306. #elif defined (STM32L010xB) || defined (STM32L051xx) || defined (STM32L052xx) || defined (STM32L053xx) || defined (STM32L062xx) || defined (STM32L063xx)
  307. #define IS_PWR_WAKEUP_PIN(PIN) (((PIN) == PWR_WAKEUP_PIN1) || \
  308. ((PIN) == PWR_WAKEUP_PIN2))
  309. #elif defined (STM32L010x8) || defined (STM32L031xx) || defined (STM32L041xx)
  310. #define IS_PWR_WAKEUP_PIN(PIN) (((PIN) == PWR_WAKEUP_PIN1) || \
  311. ((PIN) == PWR_WAKEUP_PIN2))
  312. #elif defined (STM32L010x4) || defined (STM32L011xx) || defined (STM32L021xx)
  313. #define IS_PWR_WAKEUP_PIN(PIN) (((PIN) == PWR_WAKEUP_PIN1) || \
  314. ((PIN) == PWR_WAKEUP_PIN3))
  315. #endif
  316. #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \
  317. ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON))
  318. #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE))
  319. #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE))
  320. /**
  321. * @}
  322. */
  323. /* Include PWR HAL Extension module */
  324. #include "stm32l0xx_hal_pwr_ex.h"
  325. /** @defgroup PWR_Exported_Functions PWR Exported Functions
  326. * @{
  327. */
  328. /** @defgroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions
  329. * @{
  330. */
  331. void HAL_PWR_DeInit(void);
  332. void HAL_PWR_EnableBkUpAccess(void);
  333. void HAL_PWR_DisableBkUpAccess(void);
  334. /**
  335. * @}
  336. */
  337. /** @defgroup PWR_Exported_Functions_Group2 Low Power modes configuration functions
  338. * @{
  339. */
  340. #if defined(PWR_PVD_SUPPORT)
  341. /* PVD control functions ************************************************/
  342. void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD);
  343. void HAL_PWR_EnablePVD(void);
  344. void HAL_PWR_DisablePVD(void);
  345. void HAL_PWR_PVD_IRQHandler(void);
  346. void HAL_PWR_PVDCallback(void);
  347. #endif
  348. /* WakeUp pins configuration functions ****************************************/
  349. void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx);
  350. void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx);
  351. /* Low Power modes configuration functions ************************************/
  352. void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
  353. void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry);
  354. void HAL_PWR_EnterSTANDBYMode(void);
  355. void HAL_PWR_EnableSleepOnExit(void);
  356. void HAL_PWR_DisableSleepOnExit(void);
  357. void HAL_PWR_EnableSEVOnPend(void);
  358. void HAL_PWR_DisableSEVOnPend(void);
  359. /**
  360. * @}
  361. */
  362. /**
  363. * @}
  364. */
  365. /* Define the private group ***********************************/
  366. /**************************************************************/
  367. /** @defgroup PWR_Private PWR Private
  368. * @{
  369. */
  370. /**
  371. * @}
  372. */
  373. /**************************************************************/
  374. /**
  375. * @}
  376. */
  377. /**
  378. * @}
  379. */
  380. #ifdef __cplusplus
  381. }
  382. #endif
  383. #endif /* __STM32L0xx_HAL_PWR_H */