You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

461 lines
16 KiB

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