stm32f1xx_hal_pwr.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_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 __STM32F1xx_HAL_PWR_H
  20. #define __STM32F1xx_HAL_PWR_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32f1xx_hal_def.h"
  26. /** @addtogroup STM32F1xx_HAL_Driver
  27. * @{
  28. */
  29. /** @addtogroup PWR
  30. * @{
  31. */
  32. /* Exported types ------------------------------------------------------------*/
  33. /** @defgroup PWR_Exported_Types PWR Exported Types
  34. * @{
  35. */
  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. /**
  47. * @}
  48. */
  49. /* Internal constants --------------------------------------------------------*/
  50. /** @addtogroup PWR_Private_Constants
  51. * @{
  52. */
  53. #define PWR_EXTI_LINE_PVD ((uint32_t)0x00010000) /*!< External interrupt line 16 Connected to the PVD EXTI Line */
  54. /**
  55. * @}
  56. */
  57. /* Exported constants --------------------------------------------------------*/
  58. /** @defgroup PWR_Exported_Constants PWR Exported Constants
  59. * @{
  60. */
  61. /** @defgroup PWR_PVD_detection_level PWR PVD detection level
  62. * @{
  63. */
  64. #define PWR_PVDLEVEL_0 PWR_CR_PLS_2V2
  65. #define PWR_PVDLEVEL_1 PWR_CR_PLS_2V3
  66. #define PWR_PVDLEVEL_2 PWR_CR_PLS_2V4
  67. #define PWR_PVDLEVEL_3 PWR_CR_PLS_2V5
  68. #define PWR_PVDLEVEL_4 PWR_CR_PLS_2V6
  69. #define PWR_PVDLEVEL_5 PWR_CR_PLS_2V7
  70. #define PWR_PVDLEVEL_6 PWR_CR_PLS_2V8
  71. #define PWR_PVDLEVEL_7 PWR_CR_PLS_2V9
  72. /**
  73. * @}
  74. */
  75. /** @defgroup PWR_PVD_Mode PWR PVD Mode
  76. * @{
  77. */
  78. #define PWR_PVD_MODE_NORMAL 0x00000000U /*!< basic mode is used */
  79. #define PWR_PVD_MODE_IT_RISING 0x00010001U /*!< External Interrupt Mode with Rising edge trigger detection */
  80. #define PWR_PVD_MODE_IT_FALLING 0x00010002U /*!< External Interrupt Mode with Falling edge trigger detection */
  81. #define PWR_PVD_MODE_IT_RISING_FALLING 0x00010003U /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
  82. #define PWR_PVD_MODE_EVENT_RISING 0x00020001U /*!< Event Mode with Rising edge trigger detection */
  83. #define PWR_PVD_MODE_EVENT_FALLING 0x00020002U /*!< Event Mode with Falling edge trigger detection */
  84. #define PWR_PVD_MODE_EVENT_RISING_FALLING 0x00020003U /*!< Event Mode with Rising/Falling edge trigger detection */
  85. /**
  86. * @}
  87. */
  88. /** @defgroup PWR_WakeUp_Pins PWR WakeUp Pins
  89. * @{
  90. */
  91. #define PWR_WAKEUP_PIN1 PWR_CSR_EWUP
  92. /**
  93. * @}
  94. */
  95. /** @defgroup PWR_Regulator_state_in_SLEEP_STOP_mode PWR Regulator state in SLEEP/STOP mode
  96. * @{
  97. */
  98. #define PWR_MAINREGULATOR_ON 0x00000000U
  99. #define PWR_LOWPOWERREGULATOR_ON PWR_CR_LPDS
  100. /**
  101. * @}
  102. */
  103. /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry
  104. * @{
  105. */
  106. #define PWR_SLEEPENTRY_WFI ((uint8_t)0x01)
  107. #define PWR_SLEEPENTRY_WFE ((uint8_t)0x02)
  108. /**
  109. * @}
  110. */
  111. /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry
  112. * @{
  113. */
  114. #define PWR_STOPENTRY_WFI ((uint8_t)0x01)
  115. #define PWR_STOPENTRY_WFE ((uint8_t)0x02)
  116. /**
  117. * @}
  118. */
  119. /** @defgroup PWR_Flag PWR Flag
  120. * @{
  121. */
  122. #define PWR_FLAG_WU PWR_CSR_WUF
  123. #define PWR_FLAG_SB PWR_CSR_SBF
  124. #define PWR_FLAG_PVDO PWR_CSR_PVDO
  125. /**
  126. * @}
  127. */
  128. /**
  129. * @}
  130. */
  131. /* Exported macro ------------------------------------------------------------*/
  132. /** @defgroup PWR_Exported_Macros PWR Exported Macros
  133. * @{
  134. */
  135. /** @brief Check PWR flag is set or not.
  136. * @param __FLAG__: specifies the flag to check.
  137. * This parameter can be one of the following values:
  138. * @arg PWR_FLAG_WU: Wake Up flag. This flag indicates that a wakeup event
  139. * was received from the WKUP pin or from the RTC alarm
  140. * An additional wakeup event is detected if the WKUP pin is enabled
  141. * (by setting the EWUP bit) when the WKUP pin level is already high.
  142. * @arg PWR_FLAG_SB: StandBy flag. This flag indicates that the system was
  143. * resumed from StandBy mode.
  144. * @arg PWR_FLAG_PVDO: PVD Output. This flag is valid only if PVD is enabled
  145. * by the HAL_PWR_EnablePVD() function. The PVD is stopped by Standby mode
  146. * For this reason, this bit is equal to 0 after Standby or reset
  147. * until the PVDE bit is set.
  148. * @retval The new state of __FLAG__ (TRUE or FALSE).
  149. */
  150. #define __HAL_PWR_GET_FLAG(__FLAG__) ((PWR->CSR & (__FLAG__)) == (__FLAG__))
  151. /** @brief Clear the PWR's pending flags.
  152. * @param __FLAG__: specifies the flag to clear.
  153. * This parameter can be one of the following values:
  154. * @arg PWR_FLAG_WU: Wake Up flag
  155. * @arg PWR_FLAG_SB: StandBy flag
  156. */
  157. #define __HAL_PWR_CLEAR_FLAG(__FLAG__) SET_BIT(PWR->CR, ((__FLAG__) << 2))
  158. /**
  159. * @brief Enable interrupt on PVD Exti Line 16.
  160. * @retval None.
  161. */
  162. #define __HAL_PWR_PVD_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR, PWR_EXTI_LINE_PVD)
  163. /**
  164. * @brief Disable interrupt on PVD Exti Line 16.
  165. * @retval None.
  166. */
  167. #define __HAL_PWR_PVD_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR, PWR_EXTI_LINE_PVD)
  168. /**
  169. * @brief Enable event on PVD Exti Line 16.
  170. * @retval None.
  171. */
  172. #define __HAL_PWR_PVD_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR, PWR_EXTI_LINE_PVD)
  173. /**
  174. * @brief Disable event on PVD Exti Line 16.
  175. * @retval None.
  176. */
  177. #define __HAL_PWR_PVD_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR, PWR_EXTI_LINE_PVD)
  178. /**
  179. * @brief PVD EXTI line configuration: set falling edge trigger.
  180. * @retval None.
  181. */
  182. #define __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR, PWR_EXTI_LINE_PVD)
  183. /**
  184. * @brief Disable the PVD Extended Interrupt Falling Trigger.
  185. * @retval None.
  186. */
  187. #define __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR, PWR_EXTI_LINE_PVD)
  188. /**
  189. * @brief PVD EXTI line configuration: set rising edge trigger.
  190. * @retval None.
  191. */
  192. #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR, PWR_EXTI_LINE_PVD)
  193. /**
  194. * @brief Disable the PVD Extended Interrupt Rising Trigger.
  195. * This parameter can be:
  196. * @retval None.
  197. */
  198. #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR, PWR_EXTI_LINE_PVD)
  199. /**
  200. * @brief PVD EXTI line configuration: set rising & falling edge trigger.
  201. * @retval None.
  202. */
  203. #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_FALLING_EDGE() __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();__HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();
  204. /**
  205. * @brief Disable the PVD Extended Interrupt Rising & Falling Trigger.
  206. * This parameter can be:
  207. * @retval None.
  208. */
  209. #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_FALLING_EDGE() __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();__HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE();
  210. /**
  211. * @brief Check whether the specified PVD EXTI interrupt flag is set or not.
  212. * @retval EXTI PVD Line Status.
  213. */
  214. #define __HAL_PWR_PVD_EXTI_GET_FLAG() (EXTI->PR & (PWR_EXTI_LINE_PVD))
  215. /**
  216. * @brief Clear the PVD EXTI flag.
  217. * @retval None.
  218. */
  219. #define __HAL_PWR_PVD_EXTI_CLEAR_FLAG() (EXTI->PR = (PWR_EXTI_LINE_PVD))
  220. /**
  221. * @brief Generate a Software interrupt on selected EXTI line.
  222. * @retval None.
  223. */
  224. #define __HAL_PWR_PVD_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER, PWR_EXTI_LINE_PVD)
  225. /**
  226. * @}
  227. */
  228. /* Private macro -------------------------------------------------------------*/
  229. /** @defgroup PWR_Private_Macros PWR Private Macros
  230. * @{
  231. */
  232. #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLEVEL_0) || ((LEVEL) == PWR_PVDLEVEL_1)|| \
  233. ((LEVEL) == PWR_PVDLEVEL_2) || ((LEVEL) == PWR_PVDLEVEL_3)|| \
  234. ((LEVEL) == PWR_PVDLEVEL_4) || ((LEVEL) == PWR_PVDLEVEL_5)|| \
  235. ((LEVEL) == PWR_PVDLEVEL_6) || ((LEVEL) == PWR_PVDLEVEL_7))
  236. #define IS_PWR_PVD_MODE(MODE) (((MODE) == PWR_PVD_MODE_IT_RISING)|| ((MODE) == PWR_PVD_MODE_IT_FALLING) || \
  237. ((MODE) == PWR_PVD_MODE_IT_RISING_FALLING) || ((MODE) == PWR_PVD_MODE_EVENT_RISING) || \
  238. ((MODE) == PWR_PVD_MODE_EVENT_FALLING) || ((MODE) == PWR_PVD_MODE_EVENT_RISING_FALLING) || \
  239. ((MODE) == PWR_PVD_MODE_NORMAL))
  240. #define IS_PWR_WAKEUP_PIN(PIN) (((PIN) == PWR_WAKEUP_PIN1))
  241. #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \
  242. ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON))
  243. #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE))
  244. #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE))
  245. /**
  246. * @}
  247. */
  248. /* Exported functions --------------------------------------------------------*/
  249. /** @addtogroup PWR_Exported_Functions PWR Exported Functions
  250. * @{
  251. */
  252. /** @addtogroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions
  253. * @{
  254. */
  255. /* Initialization and de-initialization functions *******************************/
  256. void HAL_PWR_DeInit(void);
  257. void HAL_PWR_EnableBkUpAccess(void);
  258. void HAL_PWR_DisableBkUpAccess(void);
  259. /**
  260. * @}
  261. */
  262. /** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions
  263. * @{
  264. */
  265. /* Peripheral Control functions ************************************************/
  266. void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD);
  267. /* #define HAL_PWR_ConfigPVD 12*/
  268. void HAL_PWR_EnablePVD(void);
  269. void HAL_PWR_DisablePVD(void);
  270. /* WakeUp pins configuration functions ****************************************/
  271. void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx);
  272. void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx);
  273. /* Low Power modes configuration functions ************************************/
  274. void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
  275. void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry);
  276. void HAL_PWR_EnterSTANDBYMode(void);
  277. void HAL_PWR_EnableSleepOnExit(void);
  278. void HAL_PWR_DisableSleepOnExit(void);
  279. void HAL_PWR_EnableSEVOnPend(void);
  280. void HAL_PWR_DisableSEVOnPend(void);
  281. void HAL_PWR_PVD_IRQHandler(void);
  282. void HAL_PWR_PVDCallback(void);
  283. /**
  284. * @}
  285. */
  286. /**
  287. * @}
  288. */
  289. /**
  290. * @}
  291. */
  292. /**
  293. * @}
  294. */
  295. #ifdef __cplusplus
  296. }
  297. #endif
  298. #endif /* __STM32F1xx_HAL_PWR_H */