stm32l1xx_hal_pwr.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_hal_pwr.h
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 5-September-2014
  7. * @brief Header file of PWR HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2014 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 __STM32L1xx_HAL_PWR_H
  39. #define __STM32L1xx_HAL_PWR_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32l1xx_hal_def.h"
  45. /** @addtogroup STM32L1xx_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_register_alias_address PWR Register alias address
  73. * @{
  74. */
  75. /* ------------- PWR registers bit address in the alias region ---------------*/
  76. #define PWR_OFFSET (PWR_BASE - PERIPH_BASE)
  77. #define PWR_CR_OFFSET 0x00
  78. #define PWR_CSR_OFFSET 0x04
  79. #define PWR_CR_OFFSET_BB (PWR_OFFSET + PWR_CR_OFFSET)
  80. #define PWR_CSR_OFFSET_BB (PWR_OFFSET + PWR_CSR_OFFSET)
  81. /**
  82. * @}
  83. */
  84. /** @defgroup PWR_CR_register_alias PWR CR Register alias address
  85. * @{
  86. */
  87. /* --- CR Register ---*/
  88. /* Alias word address of LPSDSR bit */
  89. #define LPSDSR_BIT_NUMBER POSITION_VAL(PWR_CR_LPSDSR)
  90. #define CR_LPSDSR_BB ((uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32) + (LPSDSR_BIT_NUMBER * 4)))
  91. /* Alias word address of DBP bit */
  92. #define DBP_BIT_NUMBER POSITION_VAL(PWR_CR_DBP)
  93. #define CR_DBP_BB ((uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32) + (DBP_BIT_NUMBER * 4)))
  94. /* Alias word address of LPRUN bit */
  95. #define LPRUN_BIT_NUMBER POSITION_VAL(PWR_CR_LPRUN)
  96. #define CR_LPRUN_BB ((uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32) + (LPRUN_BIT_NUMBER * 4)))
  97. /* Alias word address of PVDE bit */
  98. #define PVDE_BIT_NUMBER POSITION_VAL(PWR_CR_PVDE)
  99. #define CR_PVDE_BB ((uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32) + (PVDE_BIT_NUMBER * 4)))
  100. /* Alias word address of FWU bit */
  101. #define FWU_BIT_NUMBER POSITION_VAL(PWR_CR_FWU)
  102. #define CR_FWU_BB ((uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32) + (FWU_BIT_NUMBER * 4)))
  103. /* Alias word address of ULP bit */
  104. #define ULP_BIT_NUMBER POSITION_VAL(PWR_CR_ULP)
  105. #define CR_ULP_BB ((uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32) + (ULP_BIT_NUMBER * 4)))
  106. /**
  107. * @}
  108. */
  109. /** @defgroup PWR_CSR_register_alias PWR CSR Register alias address
  110. * @{
  111. */
  112. /* --- CSR Register ---*/
  113. /* Alias word address of EWUP1, EWUP2 and EWUP3 bits */
  114. #define CSR_EWUP_BB(VAL) ((uint32_t)(PERIPH_BB_BASE + (PWR_CSR_OFFSET_BB * 32) + (POSITION_VAL(VAL) * 4)))
  115. /**
  116. * @}
  117. */
  118. /** @defgroup PWR_PVD_detection_level PWR PVD detection level
  119. * @{
  120. */
  121. #define PWR_PVDLEVEL_0 PWR_CR_PLS_LEV0
  122. #define PWR_PVDLEVEL_1 PWR_CR_PLS_LEV1
  123. #define PWR_PVDLEVEL_2 PWR_CR_PLS_LEV2
  124. #define PWR_PVDLEVEL_3 PWR_CR_PLS_LEV3
  125. #define PWR_PVDLEVEL_4 PWR_CR_PLS_LEV4
  126. #define PWR_PVDLEVEL_5 PWR_CR_PLS_LEV5
  127. #define PWR_PVDLEVEL_6 PWR_CR_PLS_LEV6
  128. #define PWR_PVDLEVEL_7 PWR_CR_PLS_LEV7 /* External input analog voltage
  129. (Compare internally to VREFINT) */
  130. #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLEVEL_0) || ((LEVEL) == PWR_PVDLEVEL_1)|| \
  131. ((LEVEL) == PWR_PVDLEVEL_2) || ((LEVEL) == PWR_PVDLEVEL_3)|| \
  132. ((LEVEL) == PWR_PVDLEVEL_4) || ((LEVEL) == PWR_PVDLEVEL_5)|| \
  133. ((LEVEL) == PWR_PVDLEVEL_6) || ((LEVEL) == PWR_PVDLEVEL_7))
  134. /**
  135. * @}
  136. */
  137. /** @defgroup PWR_PVD_Mode PWR PVD Mode
  138. * @{
  139. */
  140. #define PWR_PVD_MODE_NORMAL ((uint32_t)0x00000000) /*!< basic mode is used */
  141. #define PWR_PVD_MODE_IT_RISING ((uint32_t)0x00010001) /*!< External Interrupt Mode with Rising edge trigger detection */
  142. #define PWR_PVD_MODE_IT_FALLING ((uint32_t)0x00010002) /*!< External Interrupt Mode with Falling edge trigger detection */
  143. #define PWR_PVD_MODE_IT_RISING_FALLING ((uint32_t)0x00010003) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
  144. #define PWR_PVD_MODE_EVENT_RISING ((uint32_t)0x00020001) /*!< Event Mode with Rising edge trigger detection */
  145. #define PWR_PVD_MODE_EVENT_FALLING ((uint32_t)0x00020002) /*!< Event Mode with Falling edge trigger detection */
  146. #define PWR_PVD_MODE_EVENT_RISING_FALLING ((uint32_t)0x00020003) /*!< Event Mode with Rising/Falling edge trigger detection */
  147. #define IS_PWR_PVD_MODE(MODE) (((MODE) == PWR_PVD_MODE_IT_RISING)|| ((MODE) == PWR_PVD_MODE_IT_FALLING) || \
  148. ((MODE) == PWR_PVD_MODE_IT_RISING_FALLING) || ((MODE) == PWR_PVD_MODE_EVENT_RISING) || \
  149. ((MODE) == PWR_PVD_MODE_EVENT_FALLING) || ((MODE) == PWR_PVD_MODE_EVENT_RISING_FALLING) || \
  150. ((MODE) == PWR_PVD_MODE_NORMAL))
  151. /**
  152. * @}
  153. */
  154. /** @defgroup PWR_Regulator_state_in_SLEEP_STOP_mode PWR Regulator state in SLEEP/STOP mode
  155. * @{
  156. */
  157. #define PWR_MAINREGULATOR_ON ((uint32_t)0x00000000)
  158. #define PWR_LOWPOWERREGULATOR_ON PWR_CR_LPSDSR
  159. #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \
  160. ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON))
  161. /**
  162. * @}
  163. */
  164. /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry
  165. * @{
  166. */
  167. #define PWR_SLEEPENTRY_WFI ((uint8_t)0x01)
  168. #define PWR_SLEEPENTRY_WFE ((uint8_t)0x02)
  169. #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE))
  170. /**
  171. * @}
  172. */
  173. /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry
  174. * @{
  175. */
  176. #define PWR_STOPENTRY_WFI ((uint8_t)0x01)
  177. #define PWR_STOPENTRY_WFE ((uint8_t)0x02)
  178. #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE) )
  179. /**
  180. * @}
  181. */
  182. /** @defgroup PWR_Regulator_Voltage_Scale PWR Regulator Voltage Scale
  183. * @{
  184. */
  185. #define PWR_REGULATOR_VOLTAGE_SCALE1 PWR_CR_VOS_0
  186. #define PWR_REGULATOR_VOLTAGE_SCALE2 PWR_CR_VOS_1
  187. #define PWR_REGULATOR_VOLTAGE_SCALE3 PWR_CR_VOS
  188. #define IS_PWR_VOLTAGE_SCALING_RANGE(RANGE) (((RANGE) == PWR_REGULATOR_VOLTAGE_SCALE1) || \
  189. ((RANGE) == PWR_REGULATOR_VOLTAGE_SCALE2) || \
  190. ((RANGE) == PWR_REGULATOR_VOLTAGE_SCALE3))
  191. /**
  192. * @}
  193. */
  194. /** @defgroup PWR_Flag PWR Flag
  195. * @{
  196. */
  197. #define PWR_FLAG_WU PWR_CSR_WUF
  198. #define PWR_FLAG_SB PWR_CSR_SBF
  199. #define PWR_FLAG_PVDO PWR_CSR_PVDO
  200. #define PWR_FLAG_VREFINTRDY PWR_CSR_VREFINTRDYF
  201. #define PWR_FLAG_VOS PWR_CSR_VOSF
  202. #define PWR_FLAG_REGLP PWR_CSR_REGLPF
  203. /**
  204. * @}
  205. */
  206. /**
  207. * @}
  208. */
  209. /* Exported macro ------------------------------------------------------------*/
  210. /** @defgroup PWR_Exported_Macro PWR Exported Macro
  211. * @{
  212. */
  213. /** @brief macros configure the main internal regulator output voltage.
  214. * @param __REGULATOR__: specifies the regulator output voltage to achieve
  215. * a tradeoff between performance and power consumption when the device does
  216. * not operate at the maximum frequency (refer to the datasheets for more details).
  217. * This parameter can be one of the following values:
  218. * @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output Scale 1 mode,
  219. * System frequency up to 32 MHz.
  220. * @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output Scale 2 mode,
  221. * System frequency up to 16 MHz.
  222. * @arg PWR_REGULATOR_VOLTAGE_SCALE3: Regulator voltage output Scale 3 mode,
  223. * System frequency up to 4.2 MHz
  224. * @retval None
  225. */
  226. #define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__) (MODIFY_REG(PWR->CR, PWR_CR_VOS, (__REGULATOR__)))
  227. /** @brief Check PWR flag is set or not.
  228. * @param __FLAG__: specifies the flag to check.
  229. * This parameter can be one of the following values:
  230. * @arg PWR_FLAG_WU: Wake Up flag. This flag indicates that a wakeup event
  231. * was received from the WKUP pin or from the RTC alarm (Alarm B),
  232. * RTC Tamper event, RTC TimeStamp event or RTC Wakeup.
  233. * An additional wakeup event is detected if the WKUP pin is enabled
  234. * (by setting the EWUP bit) when the WKUP pin level is already high.
  235. * @arg PWR_FLAG_SB: StandBy flag. This flag indicates that the system was
  236. * resumed from StandBy mode.
  237. * @arg PWR_FLAG_PVDO: PVD Output. This flag is valid only if PVD is enabled
  238. * by the HAL_PWR_EnablePVD() function. The PVD is stopped by Standby mode
  239. * For this reason, this bit is equal to 0 after Standby or reset
  240. * until the PVDE bit is set.
  241. * @arg PWR_FLAG_VREFINTRDY: Internal voltage reference (VREFINT) ready flag.
  242. * This bit indicates the state of the internal voltage reference, VREFINT.
  243. * @arg PWR_FLAG_VOS: Voltage Scaling select flag. A delay is required for
  244. * the internal regulator to be ready after the voltage range is changed.
  245. * The VOSF bit indicates that the regulator has reached the voltage level
  246. * defined with bits VOS of PWR_CR register.
  247. * @arg PWR_FLAG_REGLP: Regulator LP flag. When the MCU exits from Low power run
  248. * mode, this bit stays at 1 until the regulator is ready in main mode.
  249. * A polling on this bit is recommended to wait for the regulator main mode.
  250. * This bit is reset by hardware when the regulator is ready.
  251. * @retval The new state of __FLAG__ (TRUE or FALSE).
  252. */
  253. #define __HAL_PWR_GET_FLAG(__FLAG__) ((PWR->CSR & (__FLAG__)) == (__FLAG__))
  254. /** @brief Clear the PWR's pending flags.
  255. * @param __FLAG__: specifies the flag to clear.
  256. * This parameter can be one of the following values:
  257. * @arg PWR_FLAG_WU: Wake Up flag
  258. * @arg PWR_FLAG_SB: StandBy flag
  259. */
  260. #define __HAL_PWR_CLEAR_FLAG(__FLAG__) (PWR->CR |= (__FLAG__) << 2)
  261. #define PWR_EXTI_LINE_PVD ((uint32_t)0x00010000) /*!< External interrupt line 16 Connected to the PVD EXTI Line */
  262. /**
  263. * @brief Enable interrupt on PVD Exti Line 16.
  264. * @retval None.
  265. */
  266. #define __HAL_PWR_PVD_EXTI_ENABLE_IT() (EXTI->IMR |= (PWR_EXTI_LINE_PVD))
  267. /**
  268. * @brief Disable interrupt on PVD Exti Line 16.
  269. * @retval None.
  270. */
  271. #define __HAL_PWR_PVD_EXTI_DISABLE_IT() (EXTI->IMR &= ~(PWR_EXTI_LINE_PVD))
  272. /**
  273. * @brief Enable event on PVD Exti Line 16.
  274. * @retval None.
  275. */
  276. #define __HAL_PWR_PVD_EXTI_ENABLE_EVENT() (EXTI->EMR |= (PWR_EXTI_LINE_PVD))
  277. /**
  278. * @brief Disable event on PVD Exti Line 16.
  279. * @retval None.
  280. */
  281. #define __HAL_PWR_PVD_EXTI_DISABLE_EVENT() (EXTI->EMR &= ~(PWR_EXTI_LINE_PVD))
  282. /**
  283. * @brief PVD EXTI line configuration: clear falling edge trigger and set rising edge.
  284. * @retval None.
  285. */
  286. #define __HAL_PWR_PVD_EXTI_CLEAR_EGDE_TRIGGER() EXTI->FTSR &= ~(PWR_EXTI_LINE_PVD); \
  287. EXTI->RTSR &= ~(PWR_EXTI_LINE_PVD)
  288. /**
  289. * @brief PVD EXTI line configuration: set falling edge trigger.
  290. * @retval None.
  291. */
  292. #define __HAL_PWR_PVD_EXTI_SET_FALLING_EGDE_TRIGGER() EXTI->FTSR |= (PWR_EXTI_LINE_PVD)
  293. /**
  294. * @brief PVD EXTI line configuration: set rising edge trigger.
  295. * @retval None.
  296. */
  297. #define __HAL_PWR_PVD_EXTI_SET_RISING_EDGE_TRIGGER() EXTI->RTSR |= (PWR_EXTI_LINE_PVD)
  298. /**
  299. * @brief Check whether the specified PVD EXTI interrupt flag is set or not.
  300. * @retval EXTI PVD Line Status.
  301. */
  302. #define __HAL_PWR_PVD_EXTI_GET_FLAG() (EXTI->PR & (PWR_EXTI_LINE_PVD))
  303. /**
  304. * @brief Clear the PVD EXTI flag.
  305. * @retval None.
  306. */
  307. #define __HAL_PWR_PVD_EXTI_CLEAR_FLAG() (EXTI->PR = (PWR_EXTI_LINE_PVD))
  308. /**
  309. * @brief Generate a Software interrupt on selected EXTI line.
  310. * @retval None.
  311. */
  312. #define __HAL_PWR_PVD_EXTI_GENERATE_SWIT() (EXTI->SWIER |= (PWR_EXTI_LINE_PVD))
  313. /**
  314. * @}
  315. */
  316. /* Include PWR HAL Extension module */
  317. #include "stm32l1xx_hal_pwr_ex.h"
  318. /* Exported functions --------------------------------------------------------*/
  319. /** @addtogroup PWR_Exported_Functions PWR Exported Functions
  320. * @{
  321. */
  322. /** @addtogroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions
  323. * @{
  324. */
  325. /* Initialization and de-initialization functions *******************************/
  326. void HAL_PWR_DeInit(void);
  327. void HAL_PWR_EnableBkUpAccess(void);
  328. void HAL_PWR_DisableBkUpAccess(void);
  329. /**
  330. * @}
  331. */
  332. /** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions
  333. * @{
  334. */
  335. /* Peripheral Control functions ************************************************/
  336. void HAL_PWR_PVDConfig(PWR_PVDTypeDef *sConfigPVD);
  337. void HAL_PWR_EnablePVD(void);
  338. void HAL_PWR_DisablePVD(void);
  339. /* WakeUp pins configuration functions ****************************************/
  340. void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx);
  341. void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx);
  342. /* Low Power modes configuration functions ************************************/
  343. void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
  344. void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry);
  345. void HAL_PWR_EnterSTANDBYMode(void);
  346. void HAL_PWR_PVD_IRQHandler(void);
  347. void HAL_PWR_PVDCallback(void);
  348. /**
  349. * @}
  350. */
  351. /**
  352. * @}
  353. */
  354. /**
  355. * @}
  356. */
  357. /**
  358. * @}
  359. */
  360. #ifdef __cplusplus
  361. }
  362. #endif
  363. #endif /* __STM32L1xx_HAL_PWR_H */
  364. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/