stm32l0xx_ll_pwr.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_ll_pwr.h
  4. * @author MCD Application Team
  5. * @brief Header file of PWR LL 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_LL_PWR_H
  20. #define __STM32L0xx_LL_PWR_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32l0xx.h"
  26. /** @addtogroup STM32L0xx_LL_Driver
  27. * @{
  28. */
  29. #if defined(PWR)
  30. /** @defgroup PWR_LL PWR
  31. * @{
  32. */
  33. /* Private types -------------------------------------------------------------*/
  34. /* Private variables ---------------------------------------------------------*/
  35. /* Private constants ---------------------------------------------------------*/
  36. /* Private macros ------------------------------------------------------------*/
  37. /* Exported types ------------------------------------------------------------*/
  38. /* Exported constants --------------------------------------------------------*/
  39. /** @defgroup PWR_LL_Exported_Constants PWR Exported Constants
  40. * @{
  41. */
  42. /** @defgroup PWR_LL_EC_CLEAR_FLAG Clear Flags Defines
  43. * @brief Flags defines which can be used with LL_PWR_WriteReg function
  44. * @{
  45. */
  46. #define LL_PWR_CR_CSBF PWR_CR_CSBF /*!< Clear standby flag */
  47. #define LL_PWR_CR_CWUF PWR_CR_CWUF /*!< Clear wakeup flag */
  48. /**
  49. * @}
  50. */
  51. /** @defgroup PWR_LL_EC_GET_FLAG Get Flags Defines
  52. * @brief Flags defines which can be used with LL_PWR_ReadReg function
  53. * @{
  54. */
  55. #define LL_PWR_CSR_WUF PWR_CSR_WUF /*!< Wakeup flag */
  56. #define LL_PWR_CSR_SBF PWR_CSR_SBF /*!< Standby flag */
  57. #if defined(PWR_PVD_SUPPORT)
  58. #define LL_PWR_CSR_PVDO PWR_CSR_PVDO /*!< Power voltage detector output flag */
  59. #endif /* PWR_PVD_SUPPORT */
  60. #if defined(PWR_CSR_VREFINTRDYF)
  61. #define LL_PWR_CSR_VREFINTRDYF PWR_CSR_VREFINTRDYF /*!< VREFINT ready flag */
  62. #endif /* PWR_CSR_VREFINTRDYF */
  63. #define LL_PWR_CSR_VOS PWR_CSR_VOSF /*!< Voltage scaling select flag */
  64. #define LL_PWR_CSR_REGLPF PWR_CSR_REGLPF /*!< Regulator low power flag */
  65. #define LL_PWR_CSR_EWUP1 PWR_CSR_EWUP1 /*!< Enable WKUP pin 1 */
  66. #define LL_PWR_CSR_EWUP2 PWR_CSR_EWUP2 /*!< Enable WKUP pin 2 */
  67. #if defined(PWR_CSR_EWUP3)
  68. #define LL_PWR_CSR_EWUP3 PWR_CSR_EWUP3 /*!< Enable WKUP pin 3 */
  69. #endif /* PWR_CSR_EWUP3 */
  70. /**
  71. * @}
  72. */
  73. /** @defgroup PWR_LL_EC_REGU_VOLTAGE Regulator Voltage
  74. * @{
  75. */
  76. #define LL_PWR_REGU_VOLTAGE_SCALE1 (PWR_CR_VOS_0) /*!< 1.8V (range 1) */
  77. #define LL_PWR_REGU_VOLTAGE_SCALE2 (PWR_CR_VOS_1) /*!< 1.5V (range 2) */
  78. #define LL_PWR_REGU_VOLTAGE_SCALE3 (PWR_CR_VOS_0 | PWR_CR_VOS_1) /*!< 1.2V (range 3) */
  79. /**
  80. * @}
  81. */
  82. /** @defgroup PWR_LL_EC_MODE_PWR Mode Power
  83. * @{
  84. */
  85. #define LL_PWR_MODE_STOP 0x00000000U /*!< Enter Stop mode when the CPU enters deepsleep */
  86. #define LL_PWR_MODE_STANDBY (PWR_CR_PDDS) /*!< Enter Standby mode when the CPU enters deepsleep */
  87. /**
  88. * @}
  89. */
  90. /** @defgroup PWR_LL_EC_REGU_MODE_LP_MODES Regulator Mode In Low Power Modes
  91. * @{
  92. */
  93. #define LL_PWR_REGU_LPMODES_MAIN 0x00000000U /*!< Voltage regulator in main mode during deepsleep/sleep/low-power run mode */
  94. #define LL_PWR_REGU_LPMODES_LOW_POWER (PWR_CR_LPSDSR) /*!< Voltage regulator in low-power mode during deepsleep/sleep/low-power run mode */
  95. /**
  96. * @}
  97. */
  98. #if defined(PWR_CR_LPDS)
  99. /** @defgroup PWR_LL_EC_REGU_MODE_DS_MODE Regulator Mode In Deep Sleep Mode
  100. * @{
  101. */
  102. #define LL_PWR_REGU_DSMODE_MAIN 0x00000000U /*!< Voltage regulator in main mode during deepsleep mode when PWR_CR_LPSDSR = 0 */
  103. #define LL_PWR_REGU_DSMODE_LOW_POWER (PWR_CR_LPDS) /*!< Voltage regulator in low-power mode during deepsleep mode when PWR_CR_LPSDSR = 0 */
  104. /**
  105. * @}
  106. */
  107. #endif /* PWR_CR_LPDS */
  108. #if defined(PWR_PVD_SUPPORT)
  109. /** @defgroup PWR_LL_EC_PVDLEVEL Power Voltage Detector Level
  110. * @{
  111. */
  112. #define LL_PWR_PVDLEVEL_0 (PWR_CR_PLS_LEV0) /*!< Voltage threshold detected by PVD 1.9 V */
  113. #define LL_PWR_PVDLEVEL_1 (PWR_CR_PLS_LEV1) /*!< Voltage threshold detected by PVD 2.1 V */
  114. #define LL_PWR_PVDLEVEL_2 (PWR_CR_PLS_LEV2) /*!< Voltage threshold detected by PVD 2.3 V */
  115. #define LL_PWR_PVDLEVEL_3 (PWR_CR_PLS_LEV3) /*!< Voltage threshold detected by PVD 2.5 V */
  116. #define LL_PWR_PVDLEVEL_4 (PWR_CR_PLS_LEV4) /*!< Voltage threshold detected by PVD 2.7 V */
  117. #define LL_PWR_PVDLEVEL_5 (PWR_CR_PLS_LEV5) /*!< Voltage threshold detected by PVD 2.9 V */
  118. #define LL_PWR_PVDLEVEL_6 (PWR_CR_PLS_LEV6) /*!< Voltage threshold detected by PVD 3.1 V */
  119. #define LL_PWR_PVDLEVEL_7 (PWR_CR_PLS_LEV7) /*!< External input analog voltage (Compare internally to VREFINT) */
  120. /**
  121. * @}
  122. */
  123. #endif /* PWR_PVD_SUPPORT */
  124. /** @defgroup PWR_LL_EC_WAKEUP_PIN Wakeup Pins
  125. * @{
  126. */
  127. #define LL_PWR_WAKEUP_PIN1 (PWR_CSR_EWUP1) /*!< WKUP pin 1 : PA0 */
  128. #define LL_PWR_WAKEUP_PIN2 (PWR_CSR_EWUP2) /*!< WKUP pin 2 : PC13 */
  129. #if defined(PWR_CSR_EWUP3)
  130. #define LL_PWR_WAKEUP_PIN3 (PWR_CSR_EWUP3) /*!< WKUP pin 3 : PE6 or PA2 according to device */
  131. #endif /* PWR_CSR_EWUP3 */
  132. /**
  133. * @}
  134. */
  135. /**
  136. * @}
  137. */
  138. /* Exported macro ------------------------------------------------------------*/
  139. /** @defgroup PWR_LL_Exported_Macros PWR Exported Macros
  140. * @{
  141. */
  142. /** @defgroup PWR_LL_EM_WRITE_READ Common write and read registers Macros
  143. * @{
  144. */
  145. /**
  146. * @brief Write a value in PWR register
  147. * @param __REG__ Register to be written
  148. * @param __VALUE__ Value to be written in the register
  149. * @retval None
  150. */
  151. #define LL_PWR_WriteReg(__REG__, __VALUE__) WRITE_REG(PWR->__REG__, (__VALUE__))
  152. /**
  153. * @brief Read a value in PWR register
  154. * @param __REG__ Register to be read
  155. * @retval Register value
  156. */
  157. #define LL_PWR_ReadReg(__REG__) READ_REG(PWR->__REG__)
  158. /**
  159. * @}
  160. */
  161. /**
  162. * @}
  163. */
  164. /* Exported functions --------------------------------------------------------*/
  165. /** @defgroup PWR_LL_Exported_Functions PWR Exported Functions
  166. * @{
  167. */
  168. /** @defgroup PWR_LL_EF_Configuration Configuration
  169. * @{
  170. */
  171. /**
  172. * @brief Switch the regulator from main mode to low-power mode
  173. * @rmtoll CR LPRUN LL_PWR_EnableLowPowerRunMode
  174. * @note Remind to set the regulator to low power before enabling
  175. * LowPower run mode (bit @ref LL_PWR_REGU_LPMODES_LOW_POWER).
  176. * @retval None
  177. */
  178. __STATIC_INLINE void LL_PWR_EnableLowPowerRunMode(void)
  179. {
  180. SET_BIT(PWR->CR, PWR_CR_LPRUN);
  181. }
  182. /**
  183. * @brief Switch the regulator from low-power mode to main mode
  184. * @rmtoll CR LPRUN LL_PWR_DisableLowPowerRunMode
  185. * @retval None
  186. */
  187. __STATIC_INLINE void LL_PWR_DisableLowPowerRunMode(void)
  188. {
  189. CLEAR_BIT(PWR->CR, PWR_CR_LPRUN);
  190. }
  191. /**
  192. * @brief Check if the regulator is in low-power mode
  193. * @rmtoll CR LPRUN LL_PWR_IsEnabledLowPowerRunMode
  194. * @retval State of bit (1 or 0).
  195. */
  196. __STATIC_INLINE uint32_t LL_PWR_IsEnabledLowPowerRunMode(void)
  197. {
  198. return (READ_BIT(PWR->CR, PWR_CR_LPRUN) == (PWR_CR_LPRUN));
  199. }
  200. /**
  201. * @brief Set voltage regulator to low-power and switch from
  202. * run main mode to run low-power mode.
  203. * @rmtoll CR LPSDSR LL_PWR_EnterLowPowerRunMode\n
  204. * CR LPRUN LL_PWR_EnterLowPowerRunMode
  205. * @note This "high level" function is introduced to provide functional
  206. * compatibility with other families. Notice that the two registers
  207. * have to be written sequentially, so this function is not atomic.
  208. * To assure atomicity you can call separately the following functions:
  209. * - @ref LL_PWR_SetRegulModeLP(@ref LL_PWR_REGU_LPMODES_LOW_POWER);
  210. * - @ref LL_PWR_EnableLowPowerRunMode();
  211. * @retval None
  212. */
  213. __STATIC_INLINE void LL_PWR_EnterLowPowerRunMode(void)
  214. {
  215. SET_BIT(PWR->CR, PWR_CR_LPSDSR); /* => LL_PWR_SetRegulModeLP(LL_PWR_REGU_LPMODES_LOW_POWER) */
  216. SET_BIT(PWR->CR, PWR_CR_LPRUN); /* => LL_PWR_EnableLowPowerRunMode() */
  217. }
  218. /**
  219. * @brief Set voltage regulator to main and switch from
  220. * run main mode to low-power mode.
  221. * @rmtoll CR LPSDSR LL_PWR_ExitLowPowerRunMode\n
  222. * CR LPRUN LL_PWR_ExitLowPowerRunMode
  223. * @note This "high level" function is introduced to provide functional
  224. * compatibility with other families. Notice that the two registers
  225. * have to be written sequentially, so this function is not atomic.
  226. * To assure atomicity you can call separately the following functions:
  227. * - @ref LL_PWR_DisableLowPowerRunMode();
  228. * - @ref LL_PWR_SetRegulModeLP(@ref LL_PWR_REGU_LPMODES_MAIN);
  229. * @retval None
  230. */
  231. __STATIC_INLINE void LL_PWR_ExitLowPowerRunMode(void)
  232. {
  233. CLEAR_BIT(PWR->CR, PWR_CR_LPRUN); /* => LL_PWR_DisableLowPowerRunMode() */
  234. CLEAR_BIT(PWR->CR, PWR_CR_LPSDSR); /* => LL_PWR_SetRegulModeLP(LL_PWR_REGU_LPMODES_MAIN) */
  235. }
  236. /**
  237. * @brief Set the main internal regulator output voltage
  238. * @rmtoll CR VOS LL_PWR_SetRegulVoltageScaling
  239. * @param VoltageScaling This parameter can be one of the following values:
  240. * @arg @ref LL_PWR_REGU_VOLTAGE_SCALE1
  241. * @arg @ref LL_PWR_REGU_VOLTAGE_SCALE2
  242. * @arg @ref LL_PWR_REGU_VOLTAGE_SCALE3
  243. * @retval None
  244. */
  245. __STATIC_INLINE void LL_PWR_SetRegulVoltageScaling(uint32_t VoltageScaling)
  246. {
  247. MODIFY_REG(PWR->CR, PWR_CR_VOS, VoltageScaling);
  248. }
  249. /**
  250. * @brief Get the main internal regulator output voltage
  251. * @rmtoll CR VOS LL_PWR_GetRegulVoltageScaling
  252. * @retval Returned value can be one of the following values:
  253. * @arg @ref LL_PWR_REGU_VOLTAGE_SCALE1
  254. * @arg @ref LL_PWR_REGU_VOLTAGE_SCALE2
  255. * @arg @ref LL_PWR_REGU_VOLTAGE_SCALE3
  256. */
  257. __STATIC_INLINE uint32_t LL_PWR_GetRegulVoltageScaling(void)
  258. {
  259. return (uint32_t)(READ_BIT(PWR->CR, PWR_CR_VOS));
  260. }
  261. /**
  262. * @brief Enable access to the backup domain
  263. * @rmtoll CR DBP LL_PWR_EnableBkUpAccess
  264. * @retval None
  265. */
  266. __STATIC_INLINE void LL_PWR_EnableBkUpAccess(void)
  267. {
  268. SET_BIT(PWR->CR, PWR_CR_DBP);
  269. }
  270. /**
  271. * @brief Disable access to the backup domain
  272. * @rmtoll CR DBP LL_PWR_DisableBkUpAccess
  273. * @retval None
  274. */
  275. __STATIC_INLINE void LL_PWR_DisableBkUpAccess(void)
  276. {
  277. CLEAR_BIT(PWR->CR, PWR_CR_DBP);
  278. }
  279. /**
  280. * @brief Check if the backup domain is enabled
  281. * @rmtoll CR DBP LL_PWR_IsEnabledBkUpAccess
  282. * @retval State of bit (1 or 0).
  283. */
  284. __STATIC_INLINE uint32_t LL_PWR_IsEnabledBkUpAccess(void)
  285. {
  286. return (READ_BIT(PWR->CR, PWR_CR_DBP) == (PWR_CR_DBP));
  287. }
  288. /**
  289. * @brief Set voltage regulator mode during low power modes
  290. * @rmtoll CR LPSDSR LL_PWR_SetRegulModeLP
  291. * @param RegulMode This parameter can be one of the following values:
  292. * @arg @ref LL_PWR_REGU_LPMODES_MAIN
  293. * @arg @ref LL_PWR_REGU_LPMODES_LOW_POWER
  294. * @retval None
  295. */
  296. __STATIC_INLINE void LL_PWR_SetRegulModeLP(uint32_t RegulMode)
  297. {
  298. MODIFY_REG(PWR->CR, PWR_CR_LPSDSR, RegulMode);
  299. }
  300. /**
  301. * @brief Get voltage regulator mode during low power modes
  302. * @rmtoll CR LPSDSR LL_PWR_GetRegulModeLP
  303. * @retval Returned value can be one of the following values:
  304. * @arg @ref LL_PWR_REGU_LPMODES_MAIN
  305. * @arg @ref LL_PWR_REGU_LPMODES_LOW_POWER
  306. */
  307. __STATIC_INLINE uint32_t LL_PWR_GetRegulModeLP(void)
  308. {
  309. return (uint32_t)(READ_BIT(PWR->CR, PWR_CR_LPSDSR));
  310. }
  311. #if defined(PWR_CR_LPDS)
  312. /**
  313. * @brief Set voltage regulator mode during deep sleep mode
  314. * @rmtoll CR LPDS LL_PWR_SetRegulModeDS
  315. * @param RegulMode This parameter can be one of the following values:
  316. * @arg @ref LL_PWR_REGU_DSMODE_MAIN
  317. * @arg @ref LL_PWR_REGU_DSMODE_LOW_POWER
  318. * @retval None
  319. */
  320. __STATIC_INLINE void LL_PWR_SetRegulModeDS(uint32_t RegulMode)
  321. {
  322. MODIFY_REG(PWR->CR, PWR_CR_LPDS, RegulMode);
  323. }
  324. /**
  325. * @brief Get voltage regulator mode during deep sleep mode
  326. * @rmtoll CR LPDS LL_PWR_GetRegulModeDS
  327. * @retval Returned value can be one of the following values:
  328. * @arg @ref LL_PWR_REGU_DSMODE_MAIN
  329. * @arg @ref LL_PWR_REGU_DSMODE_LOW_POWER
  330. */
  331. __STATIC_INLINE uint32_t LL_PWR_GetRegulModeDS(void)
  332. {
  333. return (uint32_t)(READ_BIT(PWR->CR, PWR_CR_LPDS));
  334. }
  335. #endif /* PWR_CR_LPDS */
  336. /**
  337. * @brief Set power down mode when CPU enters deepsleep
  338. * @rmtoll CR PDDS LL_PWR_SetPowerMode
  339. * @param PDMode This parameter can be one of the following values:
  340. * @arg @ref LL_PWR_MODE_STOP
  341. * @arg @ref LL_PWR_MODE_STANDBY
  342. * @note Set the regulator to low power (bit @ref LL_PWR_REGU_LPMODES_LOW_POWER)
  343. * before setting MODE_STOP. If the regulator remains in "main mode",
  344. * it consumes more power without providing any additional feature.
  345. * In MODE_STANDBY the regulator is automatically off.
  346. * @note It is forbidden to configure both EN_VREFINT=1 and ULP=1 if the device is
  347. * in Stop mode or in Sleep/Low-power sleep mode. If the device is not in
  348. * low-power mode, VREFINT is always enabled whatever the state of EN_VREFINT and ULP
  349. * @retval None
  350. */
  351. __STATIC_INLINE void LL_PWR_SetPowerMode(uint32_t PDMode)
  352. {
  353. MODIFY_REG(PWR->CR, PWR_CR_PDDS, PDMode);
  354. }
  355. /**
  356. * @brief Get power down mode when CPU enters deepsleep
  357. * @rmtoll CR PDDS LL_PWR_GetPowerMode
  358. * @retval Returned value can be one of the following values:
  359. * @arg @ref LL_PWR_MODE_STOP
  360. * @arg @ref LL_PWR_MODE_STANDBY
  361. */
  362. __STATIC_INLINE uint32_t LL_PWR_GetPowerMode(void)
  363. {
  364. return (uint32_t)(READ_BIT(PWR->CR, PWR_CR_PDDS));
  365. }
  366. #if defined(PWR_PVD_SUPPORT)
  367. /**
  368. * @brief Configure the voltage threshold detected by the Power Voltage Detector
  369. * @rmtoll CR PLS LL_PWR_SetPVDLevel
  370. * @param PVDLevel This parameter can be one of the following values:
  371. * @arg @ref LL_PWR_PVDLEVEL_0
  372. * @arg @ref LL_PWR_PVDLEVEL_1
  373. * @arg @ref LL_PWR_PVDLEVEL_2
  374. * @arg @ref LL_PWR_PVDLEVEL_3
  375. * @arg @ref LL_PWR_PVDLEVEL_4
  376. * @arg @ref LL_PWR_PVDLEVEL_5
  377. * @arg @ref LL_PWR_PVDLEVEL_6
  378. * @arg @ref LL_PWR_PVDLEVEL_7
  379. * @retval None
  380. */
  381. __STATIC_INLINE void LL_PWR_SetPVDLevel(uint32_t PVDLevel)
  382. {
  383. MODIFY_REG(PWR->CR, PWR_CR_PLS, PVDLevel);
  384. }
  385. /**
  386. * @brief Get the voltage threshold detection
  387. * @rmtoll CR PLS LL_PWR_GetPVDLevel
  388. * @retval Returned value can be one of the following values:
  389. * @arg @ref LL_PWR_PVDLEVEL_0
  390. * @arg @ref LL_PWR_PVDLEVEL_1
  391. * @arg @ref LL_PWR_PVDLEVEL_2
  392. * @arg @ref LL_PWR_PVDLEVEL_3
  393. * @arg @ref LL_PWR_PVDLEVEL_4
  394. * @arg @ref LL_PWR_PVDLEVEL_5
  395. * @arg @ref LL_PWR_PVDLEVEL_6
  396. * @arg @ref LL_PWR_PVDLEVEL_7
  397. */
  398. __STATIC_INLINE uint32_t LL_PWR_GetPVDLevel(void)
  399. {
  400. return (uint32_t)(READ_BIT(PWR->CR, PWR_CR_PLS));
  401. }
  402. /**
  403. * @brief Enable Power Voltage Detector
  404. * @rmtoll CR PVDE LL_PWR_EnablePVD
  405. * @retval None
  406. */
  407. __STATIC_INLINE void LL_PWR_EnablePVD(void)
  408. {
  409. SET_BIT(PWR->CR, PWR_CR_PVDE);
  410. }
  411. /**
  412. * @brief Disable Power Voltage Detector
  413. * @rmtoll CR PVDE LL_PWR_DisablePVD
  414. * @retval None
  415. */
  416. __STATIC_INLINE void LL_PWR_DisablePVD(void)
  417. {
  418. CLEAR_BIT(PWR->CR, PWR_CR_PVDE);
  419. }
  420. /**
  421. * @brief Check if Power Voltage Detector is enabled
  422. * @rmtoll CR PVDE LL_PWR_IsEnabledPVD
  423. * @retval State of bit (1 or 0).
  424. */
  425. __STATIC_INLINE uint32_t LL_PWR_IsEnabledPVD(void)
  426. {
  427. return (READ_BIT(PWR->CR, PWR_CR_PVDE) == (PWR_CR_PVDE));
  428. }
  429. #endif /* PWR_PVD_SUPPORT */
  430. /**
  431. * @brief Enable the WakeUp PINx functionality
  432. * @rmtoll CSR EWUP1 LL_PWR_EnableWakeUpPin\n
  433. * @rmtoll CSR EWUP2 LL_PWR_EnableWakeUpPin\n
  434. * @rmtoll CSR EWUP3 LL_PWR_EnableWakeUpPin
  435. * @param WakeUpPin This parameter can be one of the following values:
  436. * @arg @ref LL_PWR_WAKEUP_PIN1
  437. * @arg @ref LL_PWR_WAKEUP_PIN2
  438. * @arg @ref LL_PWR_WAKEUP_PIN3 (*)
  439. *
  440. * (*) not available on all devices
  441. * @retval None
  442. */
  443. __STATIC_INLINE void LL_PWR_EnableWakeUpPin(uint32_t WakeUpPin)
  444. {
  445. SET_BIT(PWR->CSR, WakeUpPin);
  446. }
  447. /**
  448. * @brief Disable the WakeUp PINx functionality
  449. * @rmtoll CSR EWUP1 LL_PWR_DisableWakeUpPin\n
  450. * @rmtoll CSR EWUP2 LL_PWR_DisableWakeUpPin\n
  451. * @rmtoll CSR EWUP3 LL_PWR_DisableWakeUpPin
  452. * @param WakeUpPin This parameter can be one of the following values:
  453. * @arg @ref LL_PWR_WAKEUP_PIN1
  454. * @arg @ref LL_PWR_WAKEUP_PIN2
  455. * @arg @ref LL_PWR_WAKEUP_PIN3 (*)
  456. *
  457. * (*) not available on all devices
  458. * @retval None
  459. */
  460. __STATIC_INLINE void LL_PWR_DisableWakeUpPin(uint32_t WakeUpPin)
  461. {
  462. CLEAR_BIT(PWR->CSR, WakeUpPin);
  463. }
  464. /**
  465. * @brief Check if the WakeUp PINx functionality is enabled
  466. * @rmtoll CSR EWUP1 LL_PWR_IsEnabledWakeUpPin\n
  467. * @rmtoll CSR EWUP2 LL_PWR_IsEnabledWakeUpPin\n
  468. * @rmtoll CSR EWUP3 LL_PWR_IsEnabledWakeUpPin
  469. * @param WakeUpPin This parameter can be one of the following values:
  470. * @arg @ref LL_PWR_WAKEUP_PIN1
  471. * @arg @ref LL_PWR_WAKEUP_PIN2
  472. * @arg @ref LL_PWR_WAKEUP_PIN3 (*)
  473. *
  474. * (*) not available on all devices
  475. * @retval State of bit (1 or 0).
  476. */
  477. __STATIC_INLINE uint32_t LL_PWR_IsEnabledWakeUpPin(uint32_t WakeUpPin)
  478. {
  479. return (READ_BIT(PWR->CSR, WakeUpPin) == (WakeUpPin));
  480. }
  481. /**
  482. * @brief Enable ultra low-power mode by enabling VREFINT switch off in low-power modes
  483. * @rmtoll CR ULP LL_PWR_EnableUltraLowPower
  484. * @retval None
  485. */
  486. __STATIC_INLINE void LL_PWR_EnableUltraLowPower(void)
  487. {
  488. SET_BIT(PWR->CR, PWR_CR_ULP);
  489. }
  490. /**
  491. * @brief Disable ultra low-power mode by disabling VREFINT switch off in low-power modes
  492. * @rmtoll CR ULP LL_PWR_DisableUltraLowPower
  493. * @retval None
  494. */
  495. __STATIC_INLINE void LL_PWR_DisableUltraLowPower(void)
  496. {
  497. CLEAR_BIT(PWR->CR, PWR_CR_ULP);
  498. }
  499. /**
  500. * @brief Check if ultra low-power mode is enabled by checking if VREFINT switch off in low-power modes is enabled
  501. * @rmtoll CR ULP LL_PWR_IsEnabledUltraLowPower
  502. * @retval State of bit (1 or 0).
  503. */
  504. __STATIC_INLINE uint32_t LL_PWR_IsEnabledUltraLowPower(void)
  505. {
  506. return (READ_BIT(PWR->CR, PWR_CR_ULP) == (PWR_CR_ULP));
  507. }
  508. /**
  509. * @brief Enable fast wakeup by ignoring VREFINT startup time when exiting from low-power mode
  510. * @rmtoll CR FWU LL_PWR_EnableFastWakeUp
  511. * @note Works in conjunction with ultra low power mode.
  512. * @retval None
  513. */
  514. __STATIC_INLINE void LL_PWR_EnableFastWakeUp(void)
  515. {
  516. SET_BIT(PWR->CR, PWR_CR_FWU);
  517. }
  518. /**
  519. * @brief Disable fast wakeup by waiting VREFINT startup time when exiting from low-power mode
  520. * @rmtoll CR FWU LL_PWR_DisableFastWakeUp
  521. * @note Works in conjunction with ultra low power mode.
  522. * @retval None
  523. */
  524. __STATIC_INLINE void LL_PWR_DisableFastWakeUp(void)
  525. {
  526. CLEAR_BIT(PWR->CR, PWR_CR_FWU);
  527. }
  528. /**
  529. * @brief Check if fast wakeup is enabled by checking if VREFINT startup time when exiting from low-power mode is ignored
  530. * @rmtoll CR FWU LL_PWR_IsEnabledFastWakeUp
  531. * @retval State of bit (1 or 0).
  532. */
  533. __STATIC_INLINE uint32_t LL_PWR_IsEnabledFastWakeUp(void)
  534. {
  535. return (READ_BIT(PWR->CR, PWR_CR_FWU) == (PWR_CR_FWU));
  536. }
  537. /**
  538. * @brief Enable non-volatile memory (Flash and EEPROM) keeping off feature when exiting from low-power mode
  539. * @rmtoll CR DS_EE_KOFF LL_PWR_EnableNVMKeptOff
  540. * @note When enabled, after entering low-power mode (Stop or Standby only), if RUN_PD of FLASH_ACR register
  541. * is also set, the Flash memory will not be woken up when exiting from deepsleep mode.
  542. * When enabled, the EEPROM will not be woken up when exiting from low-power mode (if the bit RUN_PD is set)
  543. * @retval None
  544. */
  545. __STATIC_INLINE void LL_PWR_EnableNVMKeptOff(void)
  546. {
  547. SET_BIT(PWR->CR, PWR_CR_DSEEKOFF);
  548. }
  549. /**
  550. * @brief Disable non-volatile memory (Flash and EEPROM) keeping off feature when exiting from low-power mode
  551. * @rmtoll CR DS_EE_KOFF LL_PWR_DisableNVMKeptOff
  552. * @note When disabled, Flash memory is woken up when exiting from deepsleep mode even if the bit RUN_PD is set
  553. * @retval None
  554. */
  555. __STATIC_INLINE void LL_PWR_DisableNVMKeptOff(void)
  556. {
  557. CLEAR_BIT(PWR->CR, PWR_CR_DSEEKOFF);
  558. }
  559. /**
  560. * @brief Check if non-volatile memory (Flash and EEPROM) keeping off feature when exiting from low-power mode is enabled
  561. * @rmtoll CR DS_EE_KOFF LL_PWR_IsEnabledNVMKeptOff
  562. * @retval State of bit (1 or 0).
  563. */
  564. __STATIC_INLINE uint32_t LL_PWR_IsEnabledNVMKeptOff(void)
  565. {
  566. return (READ_BIT(PWR->CR, PWR_CR_DSEEKOFF) == (PWR_CR_DSEEKOFF));
  567. }
  568. /**
  569. * @}
  570. */
  571. /** @defgroup PWR_LL_EF_FLAG_Management FLAG_Management
  572. * @{
  573. */
  574. /**
  575. * @brief Get Wake-up Flag
  576. * @rmtoll CSR WUF LL_PWR_IsActiveFlag_WU
  577. * @retval State of bit (1 or 0).
  578. */
  579. __STATIC_INLINE uint32_t LL_PWR_IsActiveFlag_WU(void)
  580. {
  581. return (READ_BIT(PWR->CSR, PWR_CSR_WUF) == (PWR_CSR_WUF));
  582. }
  583. /**
  584. * @brief Get Standby Flag
  585. * @rmtoll CSR SBF LL_PWR_IsActiveFlag_SB
  586. * @retval State of bit (1 or 0).
  587. */
  588. __STATIC_INLINE uint32_t LL_PWR_IsActiveFlag_SB(void)
  589. {
  590. return (READ_BIT(PWR->CSR, PWR_CSR_SBF) == (PWR_CSR_SBF));
  591. }
  592. #if defined(PWR_PVD_SUPPORT)
  593. /**
  594. * @brief Indicate whether VDD voltage is below the selected PVD threshold
  595. * @rmtoll CSR PVDO LL_PWR_IsActiveFlag_PVDO
  596. * @retval State of bit (1 or 0).
  597. */
  598. __STATIC_INLINE uint32_t LL_PWR_IsActiveFlag_PVDO(void)
  599. {
  600. return (READ_BIT(PWR->CSR, PWR_CSR_PVDO) == (PWR_CSR_PVDO));
  601. }
  602. #endif /* PWR_PVD_SUPPORT */
  603. #if defined(PWR_CSR_VREFINTRDYF)
  604. /**
  605. * @brief Get Internal Reference VrefInt Flag
  606. * @rmtoll CSR VREFINTRDYF LL_PWR_IsActiveFlag_VREFINTRDY
  607. * @retval State of bit (1 or 0).
  608. */
  609. __STATIC_INLINE uint32_t LL_PWR_IsActiveFlag_VREFINTRDY(void)
  610. {
  611. return (READ_BIT(PWR->CSR, PWR_CSR_VREFINTRDYF) == (PWR_CSR_VREFINTRDYF));
  612. }
  613. #endif /* PWR_CSR_VREFINTRDYF */
  614. /**
  615. * @brief Indicate whether the regulator is ready in the selected voltage range or if its output voltage is still changing to the required voltage level
  616. * @rmtoll CSR VOSF LL_PWR_IsActiveFlag_VOS
  617. * @retval State of bit (1 or 0).
  618. */
  619. __STATIC_INLINE uint32_t LL_PWR_IsActiveFlag_VOS(void)
  620. {
  621. return (READ_BIT(PWR->CSR, LL_PWR_CSR_VOS) == (LL_PWR_CSR_VOS));
  622. }
  623. /**
  624. * @brief Indicate whether the regulator is ready in main mode or is in low-power mode
  625. * @rmtoll CSR REGLPF LL_PWR_IsActiveFlag_REGLPF
  626. * @note Take care, return value "0" means the regulator is ready. Return value "1" means the output voltage range is still changing.
  627. * @retval State of bit (1 or 0).
  628. */
  629. __STATIC_INLINE uint32_t LL_PWR_IsActiveFlag_REGLPF(void)
  630. {
  631. return (READ_BIT(PWR->CSR, PWR_CSR_REGLPF) == (PWR_CSR_REGLPF));
  632. }
  633. /**
  634. * @brief Clear Standby Flag
  635. * @rmtoll CR CSBF LL_PWR_ClearFlag_SB
  636. * @retval None
  637. */
  638. __STATIC_INLINE void LL_PWR_ClearFlag_SB(void)
  639. {
  640. SET_BIT(PWR->CR, PWR_CR_CSBF);
  641. }
  642. /**
  643. * @brief Clear Wake-up Flags
  644. * @rmtoll CR CWUF LL_PWR_ClearFlag_WU
  645. * @retval None
  646. */
  647. __STATIC_INLINE void LL_PWR_ClearFlag_WU(void)
  648. {
  649. SET_BIT(PWR->CR, PWR_CR_CWUF);
  650. }
  651. #if defined(USE_FULL_LL_DRIVER)
  652. /** @defgroup PWR_LL_EF_Init De-initialization function
  653. * @{
  654. */
  655. ErrorStatus LL_PWR_DeInit(void);
  656. /**
  657. * @}
  658. */
  659. #endif /* USE_FULL_LL_DRIVER */
  660. /**
  661. * @}
  662. */
  663. /**
  664. * @}
  665. */
  666. /**
  667. * @}
  668. */
  669. #endif /* defined(PWR) */
  670. /**
  671. * @}
  672. */
  673. #ifdef __cplusplus
  674. }
  675. #endif
  676. #endif /* __STM32L0xx_LL_PWR_H */