stm32g0xx_hal_pwr.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /**
  2. ******************************************************************************
  3. * @file stm32g0xx_hal_pwr.h
  4. * @author MCD Application Team
  5. * @brief Header file of PWR HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2018 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 STM32G0xx_HAL_PWR_H
  20. #define STM32G0xx_HAL_PWR_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32g0xx_hal_def.h"
  26. /** @addtogroup STM32G0xx_HAL_Driver
  27. * @{
  28. */
  29. /** @defgroup PWR PWR
  30. * @brief PWR HAL module driver
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup PWR_Exported_Types PWR Exported Types
  35. * @{
  36. */
  37. /**
  38. * @}
  39. */
  40. /* Exported constants --------------------------------------------------------*/
  41. /** @defgroup PWR_Exported_Constants PWR Exported Constants
  42. * @{
  43. */
  44. /** @defgroup PWR_WakeUp_Pins PWR WakeUp pins
  45. * @{
  46. */
  47. #define PWR_WAKEUP_PIN1 PWR_CR3_EWUP1 /*!< Wakeup pin 1 (with high level detection) */
  48. #define PWR_WAKEUP_PIN2 PWR_CR3_EWUP2 /*!< Wakeup pin 2 (with high level detection) */
  49. #if defined(PWR_CR3_EWUP3)
  50. #define PWR_WAKEUP_PIN3 PWR_CR3_EWUP3 /*!< Wakeup pin 3 (with high level detection) */
  51. #endif /* PWR_CR3_EWUP3 */
  52. #define PWR_WAKEUP_PIN4 PWR_CR3_EWUP4 /*!< Wakeup pin 4 (with high level detection) */
  53. #if defined(PWR_CR3_EWUP5)
  54. #define PWR_WAKEUP_PIN5 PWR_CR3_EWUP5 /*!< Wakeup pin 5 (with high level detection) */
  55. #endif /* PWR_CR3_EWUP5 */
  56. #define PWR_WAKEUP_PIN6 PWR_CR3_EWUP6 /*!< Wakeup pin 6 (with high level detection) */
  57. #define PWR_WAKEUP_PIN1_HIGH PWR_CR3_EWUP1 /*!< Wakeup pin 1 (with high level detection) */
  58. #define PWR_WAKEUP_PIN2_HIGH PWR_CR3_EWUP2 /*!< Wakeup pin 2 (with high level detection) */
  59. #if defined(PWR_CR3_EWUP3)
  60. #define PWR_WAKEUP_PIN3_HIGH PWR_CR3_EWUP3 /*!< Wakeup pin 3 (with high level detection) */
  61. #endif /* PWR_CR3_EWUP3 */
  62. #define PWR_WAKEUP_PIN4_HIGH PWR_CR3_EWUP4 /*!< Wakeup pin 4 (with high level detection) */
  63. #if defined(PWR_CR3_EWUP5)
  64. #define PWR_WAKEUP_PIN5_HIGH PWR_CR3_EWUP5 /*!< Wakeup pin 5 (with high level detection) */
  65. #endif /* PWR_CR3_EWUP5*/
  66. #define PWR_WAKEUP_PIN6_HIGH PWR_CR3_EWUP6 /*!< Wakeup pin 6 (with high level detection) */
  67. #define PWR_WAKEUP_PIN1_LOW ((PWR_CR4_WP1 << PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP1) /*!< Wakeup pin 1 (with low level detection) */
  68. #define PWR_WAKEUP_PIN2_LOW ((PWR_CR4_WP2 << PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP2) /*!< Wakeup pin 2 (with low level detection) */
  69. #if defined(PWR_CR3_EWUP3)
  70. #define PWR_WAKEUP_PIN3_LOW ((PWR_CR4_WP3 << PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP3) /*!< Wakeup pin 3 (with low level detection) */
  71. #endif /* PWR_CR3_EWUP3 */
  72. #define PWR_WAKEUP_PIN4_LOW ((PWR_CR4_WP4 << PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP4) /*!< Wakeup pin 4 (with low level detection) */
  73. #if defined(PWR_CR3_EWUP5)
  74. #define PWR_WAKEUP_PIN5_LOW ((PWR_CR4_WP5 << PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP5) /*!< Wakeup pin 5 (with low level detection) */
  75. #endif /* PWR_CR3_EWUP5 */
  76. #define PWR_WAKEUP_PIN6_LOW ((PWR_CR4_WP6 << PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP6) /*!< Wakeup pin 6 (with low level detection) */
  77. /**
  78. * @}
  79. */
  80. /** @defgroup PWR_Low_Power_Mode_Selection PWR Low Power Mode Selection
  81. * @{
  82. */
  83. #define PWR_LOWPOWERMODE_STOP0 (0x00000000u) /*!< Stop 0: stop mode with main regulator */
  84. #define PWR_LOWPOWERMODE_STOP1 (PWR_CR1_LPMS_0) /*!< Stop 1: stop mode with low power regulator */
  85. #define PWR_LOWPOWERMODE_STANDBY (PWR_CR1_LPMS_0 | PWR_CR1_LPMS_1) /*!< Standby mode */
  86. #if defined(PWR_SHDW_SUPPORT)
  87. #define PWR_LOWPOWERMODE_SHUTDOWN (PWR_CR1_LPMS_2) /*!< Shutdown mode */
  88. #endif /* PWR_SHDW_SUPPORT */
  89. /**
  90. * @}
  91. */
  92. /** @defgroup PWR_Regulator_state_in_SLEEP_STOP_mode PWR regulator mode
  93. * @{
  94. */
  95. #define PWR_MAINREGULATOR_ON (0x00000000u) /*!< Regulator in main mode */
  96. #define PWR_LOWPOWERREGULATOR_ON PWR_CR1_LPR /*!< Regulator in low-power mode */
  97. /**
  98. * @}
  99. */
  100. /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry
  101. * @{
  102. */
  103. #define PWR_SLEEPENTRY_WFI ((uint8_t)0x01u) /*!< Wait For Interruption instruction to enter Sleep mode */
  104. #define PWR_SLEEPENTRY_WFE ((uint8_t)0x02u) /*!< Wait For Event instruction to enter Sleep mode */
  105. /**
  106. * @}
  107. */
  108. /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry
  109. * @{
  110. */
  111. #define PWR_STOPENTRY_WFI ((uint8_t)0x01u) /*!< Wait For Interruption instruction to enter Stop mode */
  112. #define PWR_STOPENTRY_WFE ((uint8_t)0x02u) /*!< Wait For Event instruction to enter Stop mode */
  113. /**
  114. * @}
  115. */
  116. /** @defgroup PWR_Flag PWR Status Flags
  117. * @brief Elements values convention: 0000 00XX 000Y YYYYb
  118. * - Y YYYY : Flag position in the XX register (5 bits)
  119. * - XX : Status register (2 bits)
  120. * - 01: SR1 register
  121. * - 10: SR2 register
  122. * The only exception is PWR_FLAG_WU, encompassing all
  123. * wake-up flags and set to PWR_SR1_WUF.
  124. * @{
  125. */
  126. #define PWR_FLAG_WUF1 (0x00010000u | PWR_SR1_WUF1) /*!< Wakeup event on wakeup pin 1 */
  127. #define PWR_FLAG_WUF2 (0x00010000u | PWR_SR1_WUF2) /*!< Wakeup event on wakeup pin 2 */
  128. #if defined(PWR_CR3_EWUP3)
  129. #define PWR_FLAG_WUF3 (0x00010000u | PWR_SR1_WUF3) /*!< Wakeup event on wakeup pin 3 */
  130. #endif /* PWR_CR3_EWUP3 */
  131. #define PWR_FLAG_WUF4 (0x00010000u | PWR_SR1_WUF4) /*!< Wakeup event on wakeup pin 4 */
  132. #if defined(PWR_CR3_EWUP5)
  133. #define PWR_FLAG_WUF5 (0x00010000u | PWR_SR1_WUF5) /*!< Wakeup event on wakeup pin 5 */
  134. #endif /* PWR_CR3_EWUP5 */
  135. #define PWR_FLAG_WUF6 (0x00010000u | PWR_SR1_WUF6) /*!< Wakeup event on wakeup pin 6 */
  136. #define PWR_FLAG_WUF (0x00010000u | PWR_SR1_WUF) /*!< Wakeup event on all wakeup pin */
  137. #define PWR_FLAG_SB (0x00010000u | PWR_SR1_SBF) /*!< Standby flag */
  138. #define PWR_FLAG_WUFI (0x00010000u | PWR_SR1_WUFI) /*!< Wakeup on internal wakeup line */
  139. #define PWR_FLAG_FLASH_READY (0x00020000u | PWR_SR2_FLASH_RDY) /*!< Flash ready */
  140. #define PWR_FLAG_REGLPS (0x00020000u | PWR_SR2_REGLPS) /*!< Regulator Low Power started */
  141. #define PWR_FLAG_REGLPF (0x00020000u | PWR_SR2_REGLPF) /*!< Regulator Low Power flag */
  142. #if defined(PWR_PVD_SUPPORT)
  143. #define PWR_FLAG_PVDO (0x00020000u | PWR_SR2_PVDO) /*!< Power Voltage Detector output */
  144. #endif /* PWR_PVD_SUPPORT */
  145. #if defined(PWR_PVM_SUPPORT)
  146. #define PWR_FLAG_PVMO_USB (0x00020000u | PWR_SR2_PVMO_USB) /*!< Power Voltage Monitoring output */
  147. #endif /* PWR_PVM_SUPPORT */
  148. /**
  149. * @}
  150. */
  151. /**
  152. * @}
  153. */
  154. /* Exported macros -----------------------------------------------------------*/
  155. /** @defgroup PWR_Exported_Macros PWR Exported Macros
  156. * @{
  157. */
  158. /** @brief Check whether or not a specific PWR flag is set.
  159. * @param __FLAG__ specifies the flag to check.
  160. * This parameter can be one a combination of following values:
  161. * @arg PWR_FLAG_WUF1: Wake Up Flag 1. Indicates that a wakeup event
  162. * was received from the WKUP pin 1.
  163. * @arg PWR_FLAG_WUF2: Wake Up Flag 2. Indicates that a wakeup event
  164. * was received from the WKUP pin 2.
  165. * @arg PWR_FLAG_WUF3: Wake Up Flag 3. Indicates that a wakeup event
  166. * was received from the WKUP pin 3. (*)
  167. * @arg PWR_FLAG_WUF4: Wake Up Flag 4. Indicates that a wakeup event
  168. * was received from the WKUP pin 4.
  169. * @arg PWR_FLAG_WUF5: Wake Up Flag 5. Indicates that a wakeup event
  170. * was received from the WKUP pin 5. (*)
  171. * @arg PWR_FLAG_WUF6: Wake Up Flag 6. Indicates that a wakeup event
  172. * was received from the WKUP pin 6.
  173. * @arg PWR_FLAG_SB: StandBy Flag. Indicates that the system
  174. * entered StandBy mode.
  175. * @arg PWR_FLAG_WUFI: Wake-Up Flag Internal. Set when a wakeup is
  176. * detected on the internal wakeup line.
  177. * OR a combination of following values:
  178. * @arg PWR_FLAG_FLASH_READY: Flash is ready. Indicates whether flash
  179. * can be used or not
  180. * @arg PWR_FLAG_REGLPS: Low Power Regulator Started. Indicates whether
  181. * or not the low-power regulator is ready.
  182. * @arg PWR_FLAG_REGLPF: Low Power Regulator Flag. Indicates whether the
  183. * regulator is ready in main mode or is in low-power mode.
  184. * @if defined(STM32G081xx)
  185. * @arg PWR_FLAG_PVDO: Power Voltage Detector Output. Indicates whether
  186. * VDD voltage is below or above the selected PVD threshold.
  187. * @endif
  188. * @retval The new state of __FLAG__ (TRUE or FALSE).
  189. */
  190. #define __HAL_PWR_GET_FLAG(__FLAG__) (((__FLAG__) & 0x00010000u) ?\
  191. ((PWR->SR1 & ((__FLAG__) & ~0x00030000u)) == ((__FLAG__) & ~0x00030000u)) :\
  192. ((PWR->SR2 & ((__FLAG__) & ~0x00030000u)) == ((__FLAG__) & ~0x00030000u)))
  193. /** @brief Clear a specific PWR flag.
  194. * @param __FLAG__ specifies the flag to clear.
  195. * This parameter can be a combination of following values:
  196. * @arg PWR_FLAG_WUF1: Wake Up Flag 1. Indicates that a wakeup event
  197. * was received from the WKUP pin 1.
  198. * @arg PWR_FLAG_WUF2: Wake Up Flag 2. Indicates that a wakeup event
  199. * was received from the WKUP pin 2.
  200. * @arg PWR_FLAG_WUF3: Wake Up Flag 3. Indicates that a wakeup event
  201. * was received from the WKUP pin 3. (*)
  202. * @arg PWR_FLAG_WUF4: Wake Up Flag 4. Indicates that a wakeup event
  203. * was received from the WKUP pin 4.
  204. * @arg PWR_FLAG_WUF5: Wake Up Flag 5. Indicates that a wakeup event
  205. * was received from the WKUP pin 5. (*)
  206. * @arg PWR_FLAG_WUF6: Wake Up Flag 6. Indicates that a wakeup event
  207. * was received from the WKUP pin 6.
  208. * @arg PWR_FLAG_WUF: Encompasses all Wake Up Flags.
  209. * @arg PWR_FLAG_SB: Standby Flag. Indicates that the system
  210. * entered Standby mode.
  211. * @retval None
  212. */
  213. #define __HAL_PWR_CLEAR_FLAG(__FLAG__) (PWR->SCR = (__FLAG__))
  214. /**
  215. * @}
  216. */
  217. /* Private constants-------------------------------------------------------*/
  218. /** @defgroup PWR_WUP_Polarity Shift to apply to retrieve polarity information from PWR_WAKEUP_PINy_xxx constants
  219. * @{
  220. */
  221. #define PWR_WUP_POLARITY_SHIFT 0x08u /*!< Internal constant used to retrieve wakeup pin polariry */
  222. /**
  223. * @}
  224. */
  225. /* Private macros --------------------------------------------------------*/
  226. /** @defgroup PWR_Private_Macros PWR Private Macros
  227. * @{
  228. */
  229. #define IS_PWR_WAKEUP_PIN(PIN) ((((PIN) & ((PWR_CR4_WP << 8U) | (PWR_CR3_EWUP))) != 0x00000000u) && \
  230. (((PIN) & ~((PWR_CR4_WP << 8U) | (PWR_CR3_EWUP))) == 0x00000000u))
  231. #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \
  232. ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON))
  233. #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || \
  234. ((ENTRY) == PWR_SLEEPENTRY_WFE))
  235. #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || \
  236. ((ENTRY) == PWR_STOPENTRY_WFE))
  237. /**
  238. * @}
  239. */
  240. /* Include PWR HAL Extended module */
  241. #include "stm32g0xx_hal_pwr_ex.h"
  242. /* Exported functions --------------------------------------------------------*/
  243. /** @defgroup PWR_Exported_Functions PWR Exported Functions
  244. * @{
  245. */
  246. /** @defgroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions
  247. * @{
  248. */
  249. /* Initialization and de-initialization functions *******************************/
  250. void HAL_PWR_DeInit(void);
  251. /**
  252. * @}
  253. */
  254. /** @defgroup PWR_Exported_Functions_Group2 Peripheral Control functions
  255. * @{
  256. */
  257. /* Peripheral Control functions ************************************************/
  258. void HAL_PWR_EnableBkUpAccess(void);
  259. void HAL_PWR_DisableBkUpAccess(void);
  260. /* WakeUp pins configuration functions ****************************************/
  261. void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity);
  262. void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx);
  263. /* Low Power modes configuration functions ************************************/
  264. void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry);
  265. void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
  266. void HAL_PWR_EnterSTANDBYMode(void);
  267. void HAL_PWR_EnableSleepOnExit(void);
  268. void HAL_PWR_DisableSleepOnExit(void);
  269. void HAL_PWR_EnableSEVOnPend(void);
  270. void HAL_PWR_DisableSEVOnPend(void);
  271. /**
  272. * @}
  273. */
  274. /**
  275. * @}
  276. */
  277. /**
  278. * @}
  279. */
  280. /**
  281. * @}
  282. */
  283. #ifdef __cplusplus
  284. }
  285. #endif
  286. #endif /* STM32G0xx_HAL_PWR_H */