stm32f1xx_ll_pwr.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_ll_pwr.h
  4. * @author MCD Application Team
  5. * @version V1.1.1
  6. * @date 12-May-2017
  7. * @brief Header file of PWR LL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2016 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 __STM32F1xx_LL_PWR_H
  39. #define __STM32F1xx_LL_PWR_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f1xx.h"
  45. /** @addtogroup STM32F1xx_LL_Driver
  46. * @{
  47. */
  48. #if defined(PWR)
  49. /** @defgroup PWR_LL PWR
  50. * @{
  51. */
  52. /* Private types -------------------------------------------------------------*/
  53. /* Private variables ---------------------------------------------------------*/
  54. /* Private constants ---------------------------------------------------------*/
  55. /* Private macros ------------------------------------------------------------*/
  56. /* Exported types ------------------------------------------------------------*/
  57. /* Exported constants --------------------------------------------------------*/
  58. /** @defgroup PWR_LL_Exported_Constants PWR Exported Constants
  59. * @{
  60. */
  61. /** @defgroup PWR_LL_EC_CLEAR_FLAG Clear Flags Defines
  62. * @brief Flags defines which can be used with LL_PWR_WriteReg function
  63. * @{
  64. */
  65. #define LL_PWR_CR_CSBF PWR_CR_CSBF /*!< Clear standby flag */
  66. #define LL_PWR_CR_CWUF PWR_CR_CWUF /*!< Clear wakeup flag */
  67. /**
  68. * @}
  69. */
  70. /** @defgroup PWR_LL_EC_GET_FLAG Get Flags Defines
  71. * @brief Flags defines which can be used with LL_PWR_ReadReg function
  72. * @{
  73. */
  74. #define LL_PWR_CSR_WUF PWR_CSR_WUF /*!< Wakeup flag */
  75. #define LL_PWR_CSR_SBF PWR_CSR_SBF /*!< Standby flag */
  76. #define LL_PWR_CSR_PVDO PWR_CSR_PVDO /*!< Power voltage detector output flag */
  77. #define LL_PWR_CSR_EWUP1 PWR_CSR_EWUP /*!< Enable WKUP pin 1 */
  78. /**
  79. * @}
  80. */
  81. /** @defgroup PWR_LL_EC_MODE_PWR Mode Power
  82. * @{
  83. */
  84. #define LL_PWR_MODE_STOP_MAINREGU 0x00000000U /*!< Enter Stop mode when the CPU enters deepsleep */
  85. #define LL_PWR_MODE_STOP_LPREGU (PWR_CR_LPDS) /*!< Enter Stop mode (with low power Regulator ON) 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_DS_MODE Regulator Mode In Deep Sleep Mode
  91. * @{
  92. */
  93. #define LL_PWR_REGU_DSMODE_MAIN 0x00000000U /*!< Voltage Regulator in main mode during deepsleep mode */
  94. #define LL_PWR_REGU_DSMODE_LOW_POWER (PWR_CR_LPDS) /*!< Voltage Regulator in low-power mode during deepsleep mode */
  95. /**
  96. * @}
  97. */
  98. /** @defgroup PWR_LL_EC_PVDLEVEL Power Voltage Detector Level
  99. * @{
  100. */
  101. #define LL_PWR_PVDLEVEL_0 (PWR_CR_PLS_LEV0) /*!< Voltage threshold detected by PVD 2.2 V */
  102. #define LL_PWR_PVDLEVEL_1 (PWR_CR_PLS_LEV1) /*!< Voltage threshold detected by PVD 2.3 V */
  103. #define LL_PWR_PVDLEVEL_2 (PWR_CR_PLS_LEV2) /*!< Voltage threshold detected by PVD 2.4 V */
  104. #define LL_PWR_PVDLEVEL_3 (PWR_CR_PLS_LEV3) /*!< Voltage threshold detected by PVD 2.5 V */
  105. #define LL_PWR_PVDLEVEL_4 (PWR_CR_PLS_LEV4) /*!< Voltage threshold detected by PVD 2.6 V */
  106. #define LL_PWR_PVDLEVEL_5 (PWR_CR_PLS_LEV5) /*!< Voltage threshold detected by PVD 2.7 V */
  107. #define LL_PWR_PVDLEVEL_6 (PWR_CR_PLS_LEV6) /*!< Voltage threshold detected by PVD 2.8 V */
  108. #define LL_PWR_PVDLEVEL_7 (PWR_CR_PLS_LEV7) /*!< Voltage threshold detected by PVD 2.9 V */
  109. /**
  110. * @}
  111. */
  112. /** @defgroup PWR_LL_EC_WAKEUP_PIN Wakeup Pins
  113. * @{
  114. */
  115. #define LL_PWR_WAKEUP_PIN1 (PWR_CSR_EWUP) /*!< WKUP pin 1 : PA0 */
  116. /**
  117. * @}
  118. */
  119. /**
  120. * @}
  121. */
  122. /* Exported macro ------------------------------------------------------------*/
  123. /** @defgroup PWR_LL_Exported_Macros PWR Exported Macros
  124. * @{
  125. */
  126. /** @defgroup PWR_LL_EM_WRITE_READ Common write and read registers Macros
  127. * @{
  128. */
  129. /**
  130. * @brief Write a value in PWR register
  131. * @param __REG__ Register to be written
  132. * @param __VALUE__ Value to be written in the register
  133. * @retval None
  134. */
  135. #define LL_PWR_WriteReg(__REG__, __VALUE__) WRITE_REG(PWR->__REG__, (__VALUE__))
  136. /**
  137. * @brief Read a value in PWR register
  138. * @param __REG__ Register to be read
  139. * @retval Register value
  140. */
  141. #define LL_PWR_ReadReg(__REG__) READ_REG(PWR->__REG__)
  142. /**
  143. * @}
  144. */
  145. /**
  146. * @}
  147. */
  148. /* Exported functions --------------------------------------------------------*/
  149. /** @defgroup PWR_LL_Exported_Functions PWR Exported Functions
  150. * @{
  151. */
  152. /** @defgroup PWR_LL_EF_Configuration Configuration
  153. * @{
  154. */
  155. /**
  156. * @brief Enable access to the backup domain
  157. * @rmtoll CR DBP LL_PWR_EnableBkUpAccess
  158. * @retval None
  159. */
  160. __STATIC_INLINE void LL_PWR_EnableBkUpAccess(void)
  161. {
  162. SET_BIT(PWR->CR, PWR_CR_DBP);
  163. }
  164. /**
  165. * @brief Disable access to the backup domain
  166. * @rmtoll CR DBP LL_PWR_DisableBkUpAccess
  167. * @retval None
  168. */
  169. __STATIC_INLINE void LL_PWR_DisableBkUpAccess(void)
  170. {
  171. CLEAR_BIT(PWR->CR, PWR_CR_DBP);
  172. }
  173. /**
  174. * @brief Check if the backup domain is enabled
  175. * @rmtoll CR DBP LL_PWR_IsEnabledBkUpAccess
  176. * @retval State of bit (1 or 0).
  177. */
  178. __STATIC_INLINE uint32_t LL_PWR_IsEnabledBkUpAccess(void)
  179. {
  180. return (READ_BIT(PWR->CR, PWR_CR_DBP) == (PWR_CR_DBP));
  181. }
  182. /**
  183. * @brief Set voltage Regulator mode during deep sleep mode
  184. * @rmtoll CR LPDS LL_PWR_SetRegulModeDS
  185. * @param RegulMode This parameter can be one of the following values:
  186. * @arg @ref LL_PWR_REGU_DSMODE_MAIN
  187. * @arg @ref LL_PWR_REGU_DSMODE_LOW_POWER
  188. * @retval None
  189. */
  190. __STATIC_INLINE void LL_PWR_SetRegulModeDS(uint32_t RegulMode)
  191. {
  192. MODIFY_REG(PWR->CR, PWR_CR_LPDS, RegulMode);
  193. }
  194. /**
  195. * @brief Get voltage Regulator mode during deep sleep mode
  196. * @rmtoll CR LPDS LL_PWR_GetRegulModeDS
  197. * @retval Returned value can be one of the following values:
  198. * @arg @ref LL_PWR_REGU_DSMODE_MAIN
  199. * @arg @ref LL_PWR_REGU_DSMODE_LOW_POWER
  200. */
  201. __STATIC_INLINE uint32_t LL_PWR_GetRegulModeDS(void)
  202. {
  203. return (uint32_t)(READ_BIT(PWR->CR, PWR_CR_LPDS));
  204. }
  205. /**
  206. * @brief Set Power Down mode when CPU enters deepsleep
  207. * @rmtoll CR PDDS LL_PWR_SetPowerMode\n
  208. * @rmtoll CR LPDS LL_PWR_SetPowerMode
  209. * @param PDMode This parameter can be one of the following values:
  210. * @arg @ref LL_PWR_MODE_STOP_MAINREGU
  211. * @arg @ref LL_PWR_MODE_STOP_LPREGU
  212. * @arg @ref LL_PWR_MODE_STANDBY
  213. * @retval None
  214. */
  215. __STATIC_INLINE void LL_PWR_SetPowerMode(uint32_t PDMode)
  216. {
  217. MODIFY_REG(PWR->CR, (PWR_CR_PDDS| PWR_CR_LPDS), PDMode);
  218. }
  219. /**
  220. * @brief Get Power Down mode when CPU enters deepsleep
  221. * @rmtoll CR PDDS LL_PWR_GetPowerMode\n
  222. * @rmtoll CR LPDS LL_PWR_GetPowerMode
  223. * @retval Returned value can be one of the following values:
  224. * @arg @ref LL_PWR_MODE_STOP_MAINREGU
  225. * @arg @ref LL_PWR_MODE_STOP_LPREGU
  226. * @arg @ref LL_PWR_MODE_STANDBY
  227. */
  228. __STATIC_INLINE uint32_t LL_PWR_GetPowerMode(void)
  229. {
  230. return (uint32_t)(READ_BIT(PWR->CR, (PWR_CR_PDDS| PWR_CR_LPDS)));
  231. }
  232. /**
  233. * @brief Configure the voltage threshold detected by the Power Voltage Detector
  234. * @rmtoll CR PLS LL_PWR_SetPVDLevel
  235. * @param PVDLevel This parameter can be one of the following values:
  236. * @arg @ref LL_PWR_PVDLEVEL_0
  237. * @arg @ref LL_PWR_PVDLEVEL_1
  238. * @arg @ref LL_PWR_PVDLEVEL_2
  239. * @arg @ref LL_PWR_PVDLEVEL_3
  240. * @arg @ref LL_PWR_PVDLEVEL_4
  241. * @arg @ref LL_PWR_PVDLEVEL_5
  242. * @arg @ref LL_PWR_PVDLEVEL_6
  243. * @arg @ref LL_PWR_PVDLEVEL_7
  244. * @retval None
  245. */
  246. __STATIC_INLINE void LL_PWR_SetPVDLevel(uint32_t PVDLevel)
  247. {
  248. MODIFY_REG(PWR->CR, PWR_CR_PLS, PVDLevel);
  249. }
  250. /**
  251. * @brief Get the voltage threshold detection
  252. * @rmtoll CR PLS LL_PWR_GetPVDLevel
  253. * @retval Returned value can be one of the following values:
  254. * @arg @ref LL_PWR_PVDLEVEL_0
  255. * @arg @ref LL_PWR_PVDLEVEL_1
  256. * @arg @ref LL_PWR_PVDLEVEL_2
  257. * @arg @ref LL_PWR_PVDLEVEL_3
  258. * @arg @ref LL_PWR_PVDLEVEL_4
  259. * @arg @ref LL_PWR_PVDLEVEL_5
  260. * @arg @ref LL_PWR_PVDLEVEL_6
  261. * @arg @ref LL_PWR_PVDLEVEL_7
  262. */
  263. __STATIC_INLINE uint32_t LL_PWR_GetPVDLevel(void)
  264. {
  265. return (uint32_t)(READ_BIT(PWR->CR, PWR_CR_PLS));
  266. }
  267. /**
  268. * @brief Enable Power Voltage Detector
  269. * @rmtoll CR PVDE LL_PWR_EnablePVD
  270. * @retval None
  271. */
  272. __STATIC_INLINE void LL_PWR_EnablePVD(void)
  273. {
  274. SET_BIT(PWR->CR, PWR_CR_PVDE);
  275. }
  276. /**
  277. * @brief Disable Power Voltage Detector
  278. * @rmtoll CR PVDE LL_PWR_DisablePVD
  279. * @retval None
  280. */
  281. __STATIC_INLINE void LL_PWR_DisablePVD(void)
  282. {
  283. CLEAR_BIT(PWR->CR, PWR_CR_PVDE);
  284. }
  285. /**
  286. * @brief Check if Power Voltage Detector is enabled
  287. * @rmtoll CR PVDE LL_PWR_IsEnabledPVD
  288. * @retval State of bit (1 or 0).
  289. */
  290. __STATIC_INLINE uint32_t LL_PWR_IsEnabledPVD(void)
  291. {
  292. return (READ_BIT(PWR->CR, PWR_CR_PVDE) == (PWR_CR_PVDE));
  293. }
  294. /**
  295. * @brief Enable the WakeUp PINx functionality
  296. * @rmtoll CSR EWUP LL_PWR_EnableWakeUpPin
  297. * @param WakeUpPin This parameter can be one of the following values:
  298. * @arg @ref LL_PWR_WAKEUP_PIN1
  299. * @retval None
  300. */
  301. __STATIC_INLINE void LL_PWR_EnableWakeUpPin(uint32_t WakeUpPin)
  302. {
  303. SET_BIT(PWR->CSR, WakeUpPin);
  304. }
  305. /**
  306. * @brief Disable the WakeUp PINx functionality
  307. * @rmtoll CSR EWUP LL_PWR_DisableWakeUpPin
  308. * @param WakeUpPin This parameter can be one of the following values:
  309. * @arg @ref LL_PWR_WAKEUP_PIN1
  310. * @retval None
  311. */
  312. __STATIC_INLINE void LL_PWR_DisableWakeUpPin(uint32_t WakeUpPin)
  313. {
  314. CLEAR_BIT(PWR->CSR, WakeUpPin);
  315. }
  316. /**
  317. * @brief Check if the WakeUp PINx functionality is enabled
  318. * @rmtoll CSR EWUP LL_PWR_IsEnabledWakeUpPin
  319. * @param WakeUpPin This parameter can be one of the following values:
  320. * @arg @ref LL_PWR_WAKEUP_PIN1
  321. * @retval State of bit (1 or 0).
  322. */
  323. __STATIC_INLINE uint32_t LL_PWR_IsEnabledWakeUpPin(uint32_t WakeUpPin)
  324. {
  325. return (READ_BIT(PWR->CSR, WakeUpPin) == (WakeUpPin));
  326. }
  327. /**
  328. * @}
  329. */
  330. /** @defgroup PWR_LL_EF_FLAG_Management FLAG_Management
  331. * @{
  332. */
  333. /**
  334. * @brief Get Wake-up Flag
  335. * @rmtoll CSR WUF LL_PWR_IsActiveFlag_WU
  336. * @retval State of bit (1 or 0).
  337. */
  338. __STATIC_INLINE uint32_t LL_PWR_IsActiveFlag_WU(void)
  339. {
  340. return (READ_BIT(PWR->CSR, PWR_CSR_WUF) == (PWR_CSR_WUF));
  341. }
  342. /**
  343. * @brief Get Standby Flag
  344. * @rmtoll CSR SBF LL_PWR_IsActiveFlag_SB
  345. * @retval State of bit (1 or 0).
  346. */
  347. __STATIC_INLINE uint32_t LL_PWR_IsActiveFlag_SB(void)
  348. {
  349. return (READ_BIT(PWR->CSR, PWR_CSR_SBF) == (PWR_CSR_SBF));
  350. }
  351. /**
  352. * @brief Indicate whether VDD voltage is below the selected PVD threshold
  353. * @rmtoll CSR PVDO LL_PWR_IsActiveFlag_PVDO
  354. * @retval State of bit (1 or 0).
  355. */
  356. __STATIC_INLINE uint32_t LL_PWR_IsActiveFlag_PVDO(void)
  357. {
  358. return (READ_BIT(PWR->CSR, PWR_CSR_PVDO) == (PWR_CSR_PVDO));
  359. }
  360. /**
  361. * @brief Clear Standby Flag
  362. * @rmtoll CR CSBF LL_PWR_ClearFlag_SB
  363. * @retval None
  364. */
  365. __STATIC_INLINE void LL_PWR_ClearFlag_SB(void)
  366. {
  367. SET_BIT(PWR->CR, PWR_CR_CSBF);
  368. }
  369. /**
  370. * @brief Clear Wake-up Flags
  371. * @rmtoll CR CWUF LL_PWR_ClearFlag_WU
  372. * @retval None
  373. */
  374. __STATIC_INLINE void LL_PWR_ClearFlag_WU(void)
  375. {
  376. SET_BIT(PWR->CR, PWR_CR_CWUF);
  377. }
  378. /**
  379. * @}
  380. */
  381. #if defined(USE_FULL_LL_DRIVER)
  382. /** @defgroup PWR_LL_EF_Init De-initialization function
  383. * @{
  384. */
  385. ErrorStatus LL_PWR_DeInit(void);
  386. /**
  387. * @}
  388. */
  389. #endif /* USE_FULL_LL_DRIVER */
  390. /**
  391. * @}
  392. */
  393. /**
  394. * @}
  395. */
  396. #endif /* defined(PWR) */
  397. /**
  398. * @}
  399. */
  400. #ifdef __cplusplus
  401. }
  402. #endif
  403. #endif /* __STM32F1xx_LL_PWR_H */
  404. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/