stm32g4xx_hal_pwr_ex.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. /**
  2. ******************************************************************************
  3. * @file stm32g4xx_hal_pwr_ex.h
  4. * @author MCD Application Team
  5. * @brief Header file of PWR HAL Extended module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2019 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 STM32G4xx_HAL_PWR_EX_H
  20. #define STM32G4xx_HAL_PWR_EX_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32g4xx_hal_def.h"
  26. /** @addtogroup STM32G4xx_HAL_Driver
  27. * @{
  28. */
  29. /** @addtogroup PWREx
  30. * @{
  31. */
  32. /* Exported types ------------------------------------------------------------*/
  33. /** @defgroup PWREx_Exported_Types PWR Extended Exported Types
  34. * @{
  35. */
  36. /**
  37. * @brief PWR PVM configuration structure definition
  38. */
  39. typedef struct
  40. {
  41. uint32_t PVMType; /*!< PVMType: Specifies which voltage is monitored and against which threshold.
  42. This parameter can be a value of @ref PWREx_PVM_Type. */
  43. uint32_t Mode; /*!< Mode: Specifies the operating mode for the selected pins.
  44. This parameter can be a value of @ref PWREx_PVM_Mode. */
  45. }PWR_PVMTypeDef;
  46. /**
  47. * @}
  48. */
  49. /* Exported constants --------------------------------------------------------*/
  50. /** @defgroup PWREx_Exported_Constants PWR Extended Exported Constants
  51. * @{
  52. */
  53. /** @defgroup PWREx_WUP_Polarity Shift to apply to retrieve polarity information from PWR_WAKEUP_PINy_xxx constants
  54. * @{
  55. */
  56. #define PWR_WUP_POLARITY_SHIFT 0x05U /*!< Internal constant used to retrieve wakeup pin polariry */
  57. /**
  58. * @}
  59. */
  60. /** @defgroup PWREx_WakeUp_Pins PWR wake-up pins
  61. * @{
  62. */
  63. #define PWR_WAKEUP_PIN1 PWR_CR3_EWUP1 /*!< Wakeup pin 1 (with high level polarity) */
  64. #define PWR_WAKEUP_PIN2 PWR_CR3_EWUP2 /*!< Wakeup pin 2 (with high level polarity) */
  65. #define PWR_WAKEUP_PIN3 PWR_CR3_EWUP3 /*!< Wakeup pin 3 (with high level polarity) */
  66. #define PWR_WAKEUP_PIN4 PWR_CR3_EWUP4 /*!< Wakeup pin 4 (with high level polarity) */
  67. #define PWR_WAKEUP_PIN5 PWR_CR3_EWUP5 /*!< Wakeup pin 5 (with high level polarity) */
  68. #define PWR_WAKEUP_PIN1_HIGH PWR_CR3_EWUP1 /*!< Wakeup pin 1 (with high level polarity) */
  69. #define PWR_WAKEUP_PIN2_HIGH PWR_CR3_EWUP2 /*!< Wakeup pin 2 (with high level polarity) */
  70. #define PWR_WAKEUP_PIN3_HIGH PWR_CR3_EWUP3 /*!< Wakeup pin 3 (with high level polarity) */
  71. #define PWR_WAKEUP_PIN4_HIGH PWR_CR3_EWUP4 /*!< Wakeup pin 4 (with high level polarity) */
  72. #define PWR_WAKEUP_PIN5_HIGH PWR_CR3_EWUP5 /*!< Wakeup pin 5 (with high level polarity) */
  73. #define PWR_WAKEUP_PIN1_LOW (uint32_t)((PWR_CR4_WP1<<PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP1) /*!< Wakeup pin 1 (with low level polarity) */
  74. #define PWR_WAKEUP_PIN2_LOW (uint32_t)((PWR_CR4_WP2<<PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP2) /*!< Wakeup pin 2 (with low level polarity) */
  75. #define PWR_WAKEUP_PIN3_LOW (uint32_t)((PWR_CR4_WP3<<PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP3) /*!< Wakeup pin 3 (with low level polarity) */
  76. #define PWR_WAKEUP_PIN4_LOW (uint32_t)((PWR_CR4_WP4<<PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP4) /*!< Wakeup pin 4 (with low level polarity) */
  77. #define PWR_WAKEUP_PIN5_LOW (uint32_t)((PWR_CR4_WP5<<PWR_WUP_POLARITY_SHIFT) | PWR_CR3_EWUP5) /*!< Wakeup pin 5 (with low level polarity) */
  78. /**
  79. * @}
  80. */
  81. /** @defgroup PWREx_PVM_Type Peripheral Voltage Monitoring type
  82. * @{
  83. */
  84. #if defined(PWR_CR2_PVME1)
  85. #define PWR_PVM_1 PWR_CR2_PVME1 /*!< Peripheral Voltage Monitoring 1 enable: VDDUSB versus 1.2 V (applicable when USB feature is supported) */
  86. #endif /* PWR_CR2_PVME1 */
  87. #if defined(PWR_CR2_PVME2)
  88. #define PWR_PVM_2 PWR_CR2_PVME2 /*!< Peripheral Voltage Monitoring 2 enable: VDDIO2 versus 0.9 V (applicable when VDDIO2 is present on device) */
  89. #endif /* PWR_CR2_PVME2 */
  90. #define PWR_PVM_3 PWR_CR2_PVME3 /*!< Peripheral Voltage Monitoring 3 enable: VDDA versus 1.62 V */
  91. #define PWR_PVM_4 PWR_CR2_PVME4 /*!< Peripheral Voltage Monitoring 4 enable: VDDA versus 2.2 V */
  92. /**
  93. * @}
  94. */
  95. /** @defgroup PWREx_PVM_Mode PWR PVM interrupt and event mode
  96. * @{
  97. */
  98. #define PWR_PVM_MODE_NORMAL 0x00000000U /*!< basic mode is used */
  99. #define PWR_PVM_MODE_IT_RISING 0x00010001U /*!< External Interrupt Mode with Rising edge trigger detection */
  100. #define PWR_PVM_MODE_IT_FALLING 0x00010002U /*!< External Interrupt Mode with Falling edge trigger detection */
  101. #define PWR_PVM_MODE_IT_RISING_FALLING 0x00010003U /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
  102. #define PWR_PVM_MODE_EVENT_RISING 0x00020001U /*!< Event Mode with Rising edge trigger detection */
  103. #define PWR_PVM_MODE_EVENT_FALLING 0x00020002U /*!< Event Mode with Falling edge trigger detection */
  104. #define PWR_PVM_MODE_EVENT_RISING_FALLING 0x00020003U /*!< Event Mode with Rising/Falling edge trigger detection */
  105. /**
  106. * @}
  107. */
  108. /** @defgroup PWREx_Regulator_Voltage_Scale PWR Regulator voltage scale
  109. * @{
  110. */
  111. #if defined(PWR_CR5_R1MODE)
  112. #define PWR_REGULATOR_VOLTAGE_SCALE1_BOOST ((uint32_t)0x00000000) /*!< Voltage scaling range 1 boost mode */
  113. #endif /*PWR_CR5_R1MODE */
  114. #define PWR_REGULATOR_VOLTAGE_SCALE1 PWR_CR1_VOS_0 /*!< Voltage scaling range 1 normal mode */
  115. #define PWR_REGULATOR_VOLTAGE_SCALE2 PWR_CR1_VOS_1 /*!< Voltage scaling range 2 */
  116. /**
  117. * @}
  118. */
  119. /** @defgroup PWREx_VBAT_Battery_Charging_Selection PWR battery charging resistor selection
  120. * @{
  121. */
  122. #define PWR_BATTERY_CHARGING_RESISTOR_5 0x00000000U /*!< VBAT charging through a 5 kOhms resistor */
  123. #define PWR_BATTERY_CHARGING_RESISTOR_1_5 PWR_CR4_VBRS /*!< VBAT charging through a 1.5 kOhms resistor */
  124. /**
  125. * @}
  126. */
  127. /** @defgroup PWREx_VBAT_Battery_Charging PWR battery charging
  128. * @{
  129. */
  130. #define PWR_BATTERY_CHARGING_DISABLE 0x00000000U
  131. #define PWR_BATTERY_CHARGING_ENABLE PWR_CR4_VBE
  132. /**
  133. * @}
  134. */
  135. /** @defgroup PWREx_GPIO_Bit_Number GPIO bit number for I/O setting in standby/shutdown mode
  136. * @{
  137. */
  138. #define PWR_GPIO_BIT_0 PWR_PUCRA_PA0 /*!< GPIO port I/O pin 0 */
  139. #define PWR_GPIO_BIT_1 PWR_PUCRA_PA1 /*!< GPIO port I/O pin 1 */
  140. #define PWR_GPIO_BIT_2 PWR_PUCRA_PA2 /*!< GPIO port I/O pin 2 */
  141. #define PWR_GPIO_BIT_3 PWR_PUCRA_PA3 /*!< GPIO port I/O pin 3 */
  142. #define PWR_GPIO_BIT_4 PWR_PUCRA_PA4 /*!< GPIO port I/O pin 4 */
  143. #define PWR_GPIO_BIT_5 PWR_PUCRA_PA5 /*!< GPIO port I/O pin 5 */
  144. #define PWR_GPIO_BIT_6 PWR_PUCRA_PA6 /*!< GPIO port I/O pin 6 */
  145. #define PWR_GPIO_BIT_7 PWR_PUCRA_PA7 /*!< GPIO port I/O pin 7 */
  146. #define PWR_GPIO_BIT_8 PWR_PUCRA_PA8 /*!< GPIO port I/O pin 8 */
  147. #define PWR_GPIO_BIT_9 PWR_PUCRA_PA9 /*!< GPIO port I/O pin 9 */
  148. #define PWR_GPIO_BIT_10 PWR_PUCRA_PA10 /*!< GPIO port I/O pin 10 */
  149. #define PWR_GPIO_BIT_11 PWR_PUCRA_PA11 /*!< GPIO port I/O pin 11 */
  150. #define PWR_GPIO_BIT_12 PWR_PUCRA_PA12 /*!< GPIO port I/O pin 12 */
  151. #define PWR_GPIO_BIT_13 PWR_PUCRA_PA13 /*!< GPIO port I/O pin 13 */
  152. #define PWR_GPIO_BIT_14 PWR_PDCRA_PA14 /*!< GPIO port I/O pin 14 */
  153. #define PWR_GPIO_BIT_15 PWR_PUCRA_PA15 /*!< GPIO port I/O pin 15 */
  154. /**
  155. * @}
  156. */
  157. /** @defgroup PWREx_GPIO GPIO port
  158. * @{
  159. */
  160. #define PWR_GPIO_A 0x00000000U /*!< GPIO port A */
  161. #define PWR_GPIO_B 0x00000001U /*!< GPIO port B */
  162. #define PWR_GPIO_C 0x00000002U /*!< GPIO port C */
  163. #define PWR_GPIO_D 0x00000003U /*!< GPIO port D */
  164. #define PWR_GPIO_E 0x00000004U /*!< GPIO port E */
  165. #define PWR_GPIO_F 0x00000005U /*!< GPIO port F */
  166. #define PWR_GPIO_G 0x00000006U /*!< GPIO port G */
  167. /**
  168. * @}
  169. */
  170. /** @defgroup PWREx_PVM_EXTI_LINE PWR PVM external interrupts lines
  171. * @{
  172. */
  173. #if defined(PWR_CR2_PVME1)
  174. #define PWR_EXTI_LINE_PVM1 0x00000008U /*!< External interrupt line 35 Connected to the PVM1 EXTI Line */
  175. #endif /* PWR_CR2_PVME1 */
  176. #if defined(PWR_CR2_PVME2)
  177. #define PWR_EXTI_LINE_PVM2 0x00000010U /*!< External interrupt line 36 Connected to the PVM2 EXTI Line */
  178. #endif /* PWR_CR2_PVME2 */
  179. #define PWR_EXTI_LINE_PVM3 0x00000020U /*!< External interrupt line 37 Connected to the PVM3 EXTI Line */
  180. #define PWR_EXTI_LINE_PVM4 0x00000040U /*!< External interrupt line 38 Connected to the PVM4 EXTI Line */
  181. /**
  182. * @}
  183. */
  184. /** @defgroup PWREx_PVM_EVENT_LINE PWR PVM event lines
  185. * @{
  186. */
  187. #if defined(PWR_CR2_PVME1)
  188. #define PWR_EVENT_LINE_PVM1 0x00000008U /*!< Event line 35 Connected to the PVM1 EXTI Line */
  189. #endif /* PWR_CR2_PVME1 */
  190. #if defined(PWR_CR2_PVME2)
  191. #define PWR_EVENT_LINE_PVM2 0x00000010U /*!< Event line 36 Connected to the PVM2 EXTI Line */
  192. #endif /* PWR_CR2_PVME2 */
  193. #define PWR_EVENT_LINE_PVM3 0x00000020U /*!< Event line 37 Connected to the PVM3 EXTI Line */
  194. #define PWR_EVENT_LINE_PVM4 0x00000040U /*!< Event line 38 Connected to the PVM4 EXTI Line */
  195. /**
  196. * @}
  197. */
  198. /** @defgroup PWREx_Flag PWR Status Flags
  199. * Elements values convention: 0000 0000 0XXY YYYYb
  200. * - Y YYYY : Flag position in the XX register (5 bits)
  201. * - XX : Status register (2 bits)
  202. * - 01: SR1 register
  203. * - 10: SR2 register
  204. * The only exception is PWR_FLAG_WU, encompassing all
  205. * wake-up flags and set to PWR_SR1_WUF.
  206. * @{
  207. */
  208. #define PWR_FLAG_WUF1 0x0020U /*!< Wakeup event on wakeup pin 1 */
  209. #define PWR_FLAG_WUF2 0x0021U /*!< Wakeup event on wakeup pin 2 */
  210. #define PWR_FLAG_WUF3 0x0022U /*!< Wakeup event on wakeup pin 3 */
  211. #define PWR_FLAG_WUF4 0x0023U /*!< Wakeup event on wakeup pin 4 */
  212. #define PWR_FLAG_WUF5 0x0024U /*!< Wakeup event on wakeup pin 5 */
  213. #define PWR_FLAG_WU PWR_SR1_WUF /*!< Encompass wakeup event on all wakeup pins */
  214. #define PWR_FLAG_SB 0x0028U /*!< Standby flag */
  215. #define PWR_FLAG_WUFI 0x002FU /*!< Wakeup on internal wakeup line */
  216. #define PWR_FLAG_REGLPS 0x0048U /*!< Low-power regulator start flag */
  217. #define PWR_FLAG_REGLPF 0x0049U /*!< Low-power regulator flag */
  218. #define PWR_FLAG_VOSF 0x004AU /*!< Voltage scaling flag */
  219. #define PWR_FLAG_PVDO 0x004BU /*!< Power Voltage Detector output flag */
  220. #if defined(PWR_CR2_PVME1)
  221. #define PWR_FLAG_PVMO1 0x004CU /*!< Power Voltage Monitoring 1 output flag */
  222. #endif /* PWR_CR2_PVME1 */
  223. #if defined(PWR_CR2_PVME2)
  224. #define PWR_FLAG_PVMO2 0x004DU /*!< Power Voltage Monitoring 2 output flag */
  225. #endif /* PWR_CR2_PVME2 */
  226. #define PWR_FLAG_PVMO3 0x004EU /*!< Power Voltage Monitoring 3 output flag */
  227. #define PWR_FLAG_PVMO4 0x004FU /*!< Power Voltage Monitoring 4 output flag */
  228. /**
  229. * @}
  230. */
  231. /**
  232. * @}
  233. */
  234. /* Exported macros -----------------------------------------------------------*/
  235. /** @defgroup PWREx_Exported_Macros PWR Extended Exported Macros
  236. * @{
  237. */
  238. #if defined(PWR_CR2_PVME1)
  239. /**
  240. * @brief Enable the PVM1 Extended Interrupt Line.
  241. * @retval None
  242. */
  243. #define __HAL_PWR_PVM1_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR2, PWR_EXTI_LINE_PVM1)
  244. /**
  245. * @brief Disable the PVM1 Extended Interrupt Line.
  246. * @retval None
  247. */
  248. #define __HAL_PWR_PVM1_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR2, PWR_EXTI_LINE_PVM1)
  249. /**
  250. * @brief Enable the PVM1 Event Line.
  251. * @retval None
  252. */
  253. #define __HAL_PWR_PVM1_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR2, PWR_EVENT_LINE_PVM1)
  254. /**
  255. * @brief Disable the PVM1 Event Line.
  256. * @retval None
  257. */
  258. #define __HAL_PWR_PVM1_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR2, PWR_EVENT_LINE_PVM1)
  259. /**
  260. * @brief Enable the PVM1 Extended Interrupt Rising Trigger.
  261. * @retval None
  262. */
  263. #define __HAL_PWR_PVM1_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR2, PWR_EXTI_LINE_PVM1)
  264. /**
  265. * @brief Disable the PVM1 Extended Interrupt Rising Trigger.
  266. * @retval None
  267. */
  268. #define __HAL_PWR_PVM1_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR2, PWR_EXTI_LINE_PVM1)
  269. /**
  270. * @brief Enable the PVM1 Extended Interrupt Falling Trigger.
  271. * @retval None
  272. */
  273. #define __HAL_PWR_PVM1_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR2, PWR_EXTI_LINE_PVM1)
  274. /**
  275. * @brief Disable the PVM1 Extended Interrupt Falling Trigger.
  276. * @retval None
  277. */
  278. #define __HAL_PWR_PVM1_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR2, PWR_EXTI_LINE_PVM1)
  279. /**
  280. * @brief PVM1 EXTI line configuration: set rising & falling edge trigger.
  281. * @retval None
  282. */
  283. #define __HAL_PWR_PVM1_EXTI_ENABLE_RISING_FALLING_EDGE() \
  284. do { \
  285. __HAL_PWR_PVM1_EXTI_ENABLE_RISING_EDGE(); \
  286. __HAL_PWR_PVM1_EXTI_ENABLE_FALLING_EDGE(); \
  287. } while(0)
  288. /**
  289. * @brief Disable the PVM1 Extended Interrupt Rising & Falling Trigger.
  290. * @retval None
  291. */
  292. #define __HAL_PWR_PVM1_EXTI_DISABLE_RISING_FALLING_EDGE() \
  293. do { \
  294. __HAL_PWR_PVM1_EXTI_DISABLE_RISING_EDGE(); \
  295. __HAL_PWR_PVM1_EXTI_DISABLE_FALLING_EDGE(); \
  296. } while(0)
  297. /**
  298. * @brief Generate a Software interrupt on selected EXTI line.
  299. * @retval None
  300. */
  301. #define __HAL_PWR_PVM1_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER2, PWR_EXTI_LINE_PVM1)
  302. /**
  303. * @brief Check whether the specified PVM1 EXTI interrupt flag is set or not.
  304. * @retval EXTI PVM1 Line Status.
  305. */
  306. #define __HAL_PWR_PVM1_EXTI_GET_FLAG() (EXTI->PR2 & PWR_EXTI_LINE_PVM1)
  307. /**
  308. * @brief Clear the PVM1 EXTI flag.
  309. * @retval None
  310. */
  311. #define __HAL_PWR_PVM1_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR2, PWR_EXTI_LINE_PVM1)
  312. #endif /* PWR_CR2_PVME1 */
  313. #if defined(PWR_CR2_PVME2)
  314. /**
  315. * @brief Enable the PVM2 Extended Interrupt Line.
  316. * @retval None
  317. */
  318. #define __HAL_PWR_PVM2_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR2, PWR_EXTI_LINE_PVM2)
  319. /**
  320. * @brief Disable the PVM2 Extended Interrupt Line.
  321. * @retval None
  322. */
  323. #define __HAL_PWR_PVM2_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR2, PWR_EXTI_LINE_PVM2)
  324. /**
  325. * @brief Enable the PVM2 Event Line.
  326. * @retval None
  327. */
  328. #define __HAL_PWR_PVM2_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR2, PWR_EVENT_LINE_PVM2)
  329. /**
  330. * @brief Disable the PVM2 Event Line.
  331. * @retval None
  332. */
  333. #define __HAL_PWR_PVM2_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR2, PWR_EVENT_LINE_PVM2)
  334. /**
  335. * @brief Enable the PVM2 Extended Interrupt Rising Trigger.
  336. * @retval None
  337. */
  338. #define __HAL_PWR_PVM2_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR2, PWR_EXTI_LINE_PVM2)
  339. /**
  340. * @brief Disable the PVM2 Extended Interrupt Rising Trigger.
  341. * @retval None
  342. */
  343. #define __HAL_PWR_PVM2_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR2, PWR_EXTI_LINE_PVM2)
  344. /**
  345. * @brief Enable the PVM2 Extended Interrupt Falling Trigger.
  346. * @retval None
  347. */
  348. #define __HAL_PWR_PVM2_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR2, PWR_EXTI_LINE_PVM2)
  349. /**
  350. * @brief Disable the PVM2 Extended Interrupt Falling Trigger.
  351. * @retval None
  352. */
  353. #define __HAL_PWR_PVM2_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR2, PWR_EXTI_LINE_PVM2)
  354. /**
  355. * @brief PVM2 EXTI line configuration: set rising & falling edge trigger.
  356. * @retval None
  357. */
  358. #define __HAL_PWR_PVM2_EXTI_ENABLE_RISING_FALLING_EDGE() \
  359. do { \
  360. __HAL_PWR_PVM2_EXTI_ENABLE_RISING_EDGE(); \
  361. __HAL_PWR_PVM2_EXTI_ENABLE_FALLING_EDGE(); \
  362. } while(0)
  363. /**
  364. * @brief Disable the PVM2 Extended Interrupt Rising & Falling Trigger.
  365. * @retval None
  366. */
  367. #define __HAL_PWR_PVM2_EXTI_DISABLE_RISING_FALLING_EDGE() \
  368. do { \
  369. __HAL_PWR_PVM2_EXTI_DISABLE_RISING_EDGE(); \
  370. __HAL_PWR_PVM2_EXTI_DISABLE_FALLING_EDGE(); \
  371. } while(0)
  372. /**
  373. * @brief Generate a Software interrupt on selected EXTI line.
  374. * @retval None
  375. */
  376. #define __HAL_PWR_PVM2_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER2, PWR_EXTI_LINE_PVM2)
  377. /**
  378. * @brief Check whether the specified PVM2 EXTI interrupt flag is set or not.
  379. * @retval EXTI PVM2 Line Status.
  380. */
  381. #define __HAL_PWR_PVM2_EXTI_GET_FLAG() (EXTI->PR2 & PWR_EXTI_LINE_PVM2)
  382. /**
  383. * @brief Clear the PVM2 EXTI flag.
  384. * @retval None
  385. */
  386. #define __HAL_PWR_PVM2_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR2, PWR_EXTI_LINE_PVM2)
  387. #endif /* PWR_CR2_PVME2 */
  388. /**
  389. * @brief Enable the PVM3 Extended Interrupt Line.
  390. * @retval None
  391. */
  392. #define __HAL_PWR_PVM3_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR2, PWR_EXTI_LINE_PVM3)
  393. /**
  394. * @brief Disable the PVM3 Extended Interrupt Line.
  395. * @retval None
  396. */
  397. #define __HAL_PWR_PVM3_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR2, PWR_EXTI_LINE_PVM3)
  398. /**
  399. * @brief Enable the PVM3 Event Line.
  400. * @retval None
  401. */
  402. #define __HAL_PWR_PVM3_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR2, PWR_EVENT_LINE_PVM3)
  403. /**
  404. * @brief Disable the PVM3 Event Line.
  405. * @retval None
  406. */
  407. #define __HAL_PWR_PVM3_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR2, PWR_EVENT_LINE_PVM3)
  408. /**
  409. * @brief Enable the PVM3 Extended Interrupt Rising Trigger.
  410. * @retval None
  411. */
  412. #define __HAL_PWR_PVM3_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR2, PWR_EXTI_LINE_PVM3)
  413. /**
  414. * @brief Disable the PVM3 Extended Interrupt Rising Trigger.
  415. * @retval None
  416. */
  417. #define __HAL_PWR_PVM3_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR2, PWR_EXTI_LINE_PVM3)
  418. /**
  419. * @brief Enable the PVM3 Extended Interrupt Falling Trigger.
  420. * @retval None
  421. */
  422. #define __HAL_PWR_PVM3_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR2, PWR_EXTI_LINE_PVM3)
  423. /**
  424. * @brief Disable the PVM3 Extended Interrupt Falling Trigger.
  425. * @retval None
  426. */
  427. #define __HAL_PWR_PVM3_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR2, PWR_EXTI_LINE_PVM3)
  428. /**
  429. * @brief PVM3 EXTI line configuration: set rising & falling edge trigger.
  430. * @retval None
  431. */
  432. #define __HAL_PWR_PVM3_EXTI_ENABLE_RISING_FALLING_EDGE() \
  433. do { \
  434. __HAL_PWR_PVM3_EXTI_ENABLE_RISING_EDGE(); \
  435. __HAL_PWR_PVM3_EXTI_ENABLE_FALLING_EDGE(); \
  436. } while(0)
  437. /**
  438. * @brief Disable the PVM3 Extended Interrupt Rising & Falling Trigger.
  439. * @retval None
  440. */
  441. #define __HAL_PWR_PVM3_EXTI_DISABLE_RISING_FALLING_EDGE() \
  442. do { \
  443. __HAL_PWR_PVM3_EXTI_DISABLE_RISING_EDGE(); \
  444. __HAL_PWR_PVM3_EXTI_DISABLE_FALLING_EDGE(); \
  445. } while(0)
  446. /**
  447. * @brief Generate a Software interrupt on selected EXTI line.
  448. * @retval None
  449. */
  450. #define __HAL_PWR_PVM3_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER2, PWR_EXTI_LINE_PVM3)
  451. /**
  452. * @brief Check whether the specified PVM3 EXTI interrupt flag is set or not.
  453. * @retval EXTI PVM3 Line Status.
  454. */
  455. #define __HAL_PWR_PVM3_EXTI_GET_FLAG() (EXTI->PR2 & PWR_EXTI_LINE_PVM3)
  456. /**
  457. * @brief Clear the PVM3 EXTI flag.
  458. * @retval None
  459. */
  460. #define __HAL_PWR_PVM3_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR2, PWR_EXTI_LINE_PVM3)
  461. /**
  462. * @brief Enable the PVM4 Extended Interrupt Line.
  463. * @retval None
  464. */
  465. #define __HAL_PWR_PVM4_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR2, PWR_EXTI_LINE_PVM4)
  466. /**
  467. * @brief Disable the PVM4 Extended Interrupt Line.
  468. * @retval None
  469. */
  470. #define __HAL_PWR_PVM4_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR2, PWR_EXTI_LINE_PVM4)
  471. /**
  472. * @brief Enable the PVM4 Event Line.
  473. * @retval None
  474. */
  475. #define __HAL_PWR_PVM4_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR2, PWR_EVENT_LINE_PVM4)
  476. /**
  477. * @brief Disable the PVM4 Event Line.
  478. * @retval None
  479. */
  480. #define __HAL_PWR_PVM4_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR2, PWR_EVENT_LINE_PVM4)
  481. /**
  482. * @brief Enable the PVM4 Extended Interrupt Rising Trigger.
  483. * @retval None
  484. */
  485. #define __HAL_PWR_PVM4_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR2, PWR_EXTI_LINE_PVM4)
  486. /**
  487. * @brief Disable the PVM4 Extended Interrupt Rising Trigger.
  488. * @retval None
  489. */
  490. #define __HAL_PWR_PVM4_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR2, PWR_EXTI_LINE_PVM4)
  491. /**
  492. * @brief Enable the PVM4 Extended Interrupt Falling Trigger.
  493. * @retval None
  494. */
  495. #define __HAL_PWR_PVM4_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR2, PWR_EXTI_LINE_PVM4)
  496. /**
  497. * @brief Disable the PVM4 Extended Interrupt Falling Trigger.
  498. * @retval None
  499. */
  500. #define __HAL_PWR_PVM4_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR2, PWR_EXTI_LINE_PVM4)
  501. /**
  502. * @brief PVM4 EXTI line configuration: set rising & falling edge trigger.
  503. * @retval None
  504. */
  505. #define __HAL_PWR_PVM4_EXTI_ENABLE_RISING_FALLING_EDGE() \
  506. do { \
  507. __HAL_PWR_PVM4_EXTI_ENABLE_RISING_EDGE(); \
  508. __HAL_PWR_PVM4_EXTI_ENABLE_FALLING_EDGE(); \
  509. } while(0)
  510. /**
  511. * @brief Disable the PVM4 Extended Interrupt Rising & Falling Trigger.
  512. * @retval None
  513. */
  514. #define __HAL_PWR_PVM4_EXTI_DISABLE_RISING_FALLING_EDGE() \
  515. do { \
  516. __HAL_PWR_PVM4_EXTI_DISABLE_RISING_EDGE(); \
  517. __HAL_PWR_PVM4_EXTI_DISABLE_FALLING_EDGE(); \
  518. } while(0)
  519. /**
  520. * @brief Generate a Software interrupt on selected EXTI line.
  521. * @retval None
  522. */
  523. #define __HAL_PWR_PVM4_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER2, PWR_EXTI_LINE_PVM4)
  524. /**
  525. * @brief Check whether or not the specified PVM4 EXTI interrupt flag is set.
  526. * @retval EXTI PVM4 Line Status.
  527. */
  528. #define __HAL_PWR_PVM4_EXTI_GET_FLAG() (EXTI->PR2 & PWR_EXTI_LINE_PVM4)
  529. /**
  530. * @brief Clear the PVM4 EXTI flag.
  531. * @retval None
  532. */
  533. #define __HAL_PWR_PVM4_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR2, PWR_EXTI_LINE_PVM4)
  534. /**
  535. * @brief Configure the main internal regulator output voltage.
  536. * @param __REGULATOR__: specifies the regulator output voltage to achieve
  537. * a tradeoff between performance and power consumption.
  538. * This parameter can be one of the following values:
  539. * @arg @ref PWR_REGULATOR_VOLTAGE_SCALE1_BOOST Regulator voltage output range 1 mode,
  540. * typical output voltage at 1.28 V,
  541. * system frequency up to 170 MHz.
  542. * @arg @ref PWR_REGULATOR_VOLTAGE_SCALE1 Regulator voltage output range 1 mode,
  543. * typical output voltage at 1.2 V,
  544. * system frequency up to 150 MHz.
  545. * @arg @ref PWR_REGULATOR_VOLTAGE_SCALE2 Regulator voltage output range 2 mode,
  546. * typical output voltage at 1.0 V,
  547. * system frequency up to 26 MHz.
  548. * @note This macro is similar to HAL_PWREx_ControlVoltageScaling() API but doesn't check
  549. * whether or not VOSF flag is cleared when moving from range 2 to range 1. User
  550. * may resort to __HAL_PWR_GET_FLAG() macro to check VOSF bit resetting.
  551. * @retval None
  552. */
  553. #define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__) do { \
  554. __IO uint32_t tmpreg; \
  555. MODIFY_REG(PWR->CR1, PWR_CR1_VOS, (__REGULATOR__)); \
  556. /* Delay after an RCC peripheral clock enabling */ \
  557. tmpreg = READ_BIT(PWR->CR1, PWR_CR1_VOS); \
  558. UNUSED(tmpreg); \
  559. } while(0)
  560. /**
  561. * @}
  562. */
  563. /* Private macros --------------------------------------------------------*/
  564. /** @addtogroup PWREx_Private_Macros PWR Extended Private Macros
  565. * @{
  566. */
  567. #define IS_PWR_WAKEUP_PIN(PIN) (((PIN) == PWR_WAKEUP_PIN1) || \
  568. ((PIN) == PWR_WAKEUP_PIN2) || \
  569. ((PIN) == PWR_WAKEUP_PIN3) || \
  570. ((PIN) == PWR_WAKEUP_PIN4) || \
  571. ((PIN) == PWR_WAKEUP_PIN5) || \
  572. ((PIN) == PWR_WAKEUP_PIN1_HIGH) || \
  573. ((PIN) == PWR_WAKEUP_PIN2_HIGH) || \
  574. ((PIN) == PWR_WAKEUP_PIN3_HIGH) || \
  575. ((PIN) == PWR_WAKEUP_PIN4_HIGH) || \
  576. ((PIN) == PWR_WAKEUP_PIN5_HIGH) || \
  577. ((PIN) == PWR_WAKEUP_PIN1_LOW) || \
  578. ((PIN) == PWR_WAKEUP_PIN2_LOW) || \
  579. ((PIN) == PWR_WAKEUP_PIN3_LOW) || \
  580. ((PIN) == PWR_WAKEUP_PIN4_LOW) || \
  581. ((PIN) == PWR_WAKEUP_PIN5_LOW))
  582. #define IS_PWR_PVM_TYPE(TYPE) (((TYPE) == PWR_PVM_1) ||\
  583. ((TYPE) == PWR_PVM_2) ||\
  584. ((TYPE) == PWR_PVM_3) ||\
  585. ((TYPE) == PWR_PVM_4))
  586. #define IS_PWR_PVM_MODE(MODE) (((MODE) == PWR_PVM_MODE_NORMAL) ||\
  587. ((MODE) == PWR_PVM_MODE_IT_RISING) ||\
  588. ((MODE) == PWR_PVM_MODE_IT_FALLING) ||\
  589. ((MODE) == PWR_PVM_MODE_IT_RISING_FALLING) ||\
  590. ((MODE) == PWR_PVM_MODE_EVENT_RISING) ||\
  591. ((MODE) == PWR_PVM_MODE_EVENT_FALLING) ||\
  592. ((MODE) == PWR_PVM_MODE_EVENT_RISING_FALLING))
  593. #if defined(PWR_CR5_R1MODE)
  594. #define IS_PWR_VOLTAGE_SCALING_RANGE(RANGE) (((RANGE) == PWR_REGULATOR_VOLTAGE_SCALE1_BOOST) || \
  595. ((RANGE) == PWR_REGULATOR_VOLTAGE_SCALE1) || \
  596. ((RANGE) == PWR_REGULATOR_VOLTAGE_SCALE2))
  597. #else
  598. #define IS_PWR_VOLTAGE_SCALING_RANGE(RANGE) (((RANGE) == PWR_REGULATOR_VOLTAGE_SCALE1) || \
  599. ((RANGE) == PWR_REGULATOR_VOLTAGE_SCALE2))
  600. #endif
  601. #define IS_PWR_BATTERY_RESISTOR_SELECT(RESISTOR) (((RESISTOR) == PWR_BATTERY_CHARGING_RESISTOR_5) ||\
  602. ((RESISTOR) == PWR_BATTERY_CHARGING_RESISTOR_1_5))
  603. #define IS_PWR_BATTERY_CHARGING(CHARGING) (((CHARGING) == PWR_BATTERY_CHARGING_DISABLE) ||\
  604. ((CHARGING) == PWR_BATTERY_CHARGING_ENABLE))
  605. #define IS_PWR_GPIO_BIT_NUMBER(BIT_NUMBER) (((BIT_NUMBER) & GPIO_PIN_MASK) != (uint32_t)0x00U)
  606. #define IS_PWR_GPIO(GPIO) (((GPIO) == PWR_GPIO_A) ||\
  607. ((GPIO) == PWR_GPIO_B) ||\
  608. ((GPIO) == PWR_GPIO_C) ||\
  609. ((GPIO) == PWR_GPIO_D) ||\
  610. ((GPIO) == PWR_GPIO_E) ||\
  611. ((GPIO) == PWR_GPIO_F) ||\
  612. ((GPIO) == PWR_GPIO_G))
  613. /**
  614. * @}
  615. */
  616. /** @addtogroup PWREx_Exported_Functions PWR Extended Exported Functions
  617. * @{
  618. */
  619. /** @addtogroup PWREx_Exported_Functions_Group1 Extended Peripheral Control functions
  620. * @{
  621. */
  622. /* Peripheral Control functions **********************************************/
  623. uint32_t HAL_PWREx_GetVoltageRange(void);
  624. HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling);
  625. void HAL_PWREx_EnableBatteryCharging(uint32_t ResistorSelection);
  626. void HAL_PWREx_DisableBatteryCharging(void);
  627. void HAL_PWREx_EnableInternalWakeUpLine(void);
  628. void HAL_PWREx_DisableInternalWakeUpLine(void);
  629. HAL_StatusTypeDef HAL_PWREx_EnableGPIOPullUp(uint32_t GPIO, uint32_t GPIONumber);
  630. HAL_StatusTypeDef HAL_PWREx_DisableGPIOPullUp(uint32_t GPIO, uint32_t GPIONumber);
  631. HAL_StatusTypeDef HAL_PWREx_EnableGPIOPullDown(uint32_t GPIO, uint32_t GPIONumber);
  632. HAL_StatusTypeDef HAL_PWREx_DisableGPIOPullDown(uint32_t GPIO, uint32_t GPIONumber);
  633. void HAL_PWREx_EnablePullUpPullDownConfig(void);
  634. void HAL_PWREx_DisablePullUpPullDownConfig(void);
  635. void HAL_PWREx_EnableSRAM2ContentRetention(void);
  636. void HAL_PWREx_DisableSRAM2ContentRetention(void);
  637. #if defined(PWR_CR2_PVME1)
  638. void HAL_PWREx_EnablePVM1(void);
  639. void HAL_PWREx_DisablePVM1(void);
  640. #endif /* PWR_CR2_PVME1 */
  641. #if defined(PWR_CR2_PVME2)
  642. void HAL_PWREx_EnablePVM2(void);
  643. void HAL_PWREx_DisablePVM2(void);
  644. #endif /* PWR_CR2_PVME2 */
  645. void HAL_PWREx_EnablePVM3(void);
  646. void HAL_PWREx_DisablePVM3(void);
  647. void HAL_PWREx_EnablePVM4(void);
  648. void HAL_PWREx_DisablePVM4(void);
  649. HAL_StatusTypeDef HAL_PWREx_ConfigPVM(PWR_PVMTypeDef *sConfigPVM);
  650. /* Low Power modes configuration functions ************************************/
  651. void HAL_PWREx_EnableLowPowerRunMode(void);
  652. HAL_StatusTypeDef HAL_PWREx_DisableLowPowerRunMode(void);
  653. void HAL_PWREx_EnterSTOP0Mode(uint8_t STOPEntry);
  654. void HAL_PWREx_EnterSTOP1Mode(uint8_t STOPEntry);
  655. void HAL_PWREx_EnterSHUTDOWNMode(void);
  656. void HAL_PWREx_PVD_PVM_IRQHandler(void);
  657. #if defined(PWR_CR2_PVME1)
  658. void HAL_PWREx_PVM1Callback(void);
  659. #endif /* PWR_CR2_PVME1 */
  660. #if defined(PWR_CR2_PVME2)
  661. void HAL_PWREx_PVM2Callback(void);
  662. #endif /* PWR_CR2_PVME2 */
  663. void HAL_PWREx_PVM3Callback(void);
  664. void HAL_PWREx_PVM4Callback(void);
  665. #if defined(PWR_CR3_UCPD_STDBY)
  666. void HAL_PWREx_EnableUCPDStandbyMode(void);
  667. void HAL_PWREx_DisableUCPDStandbyMode(void);
  668. #endif /* PWR_CR3_UCPD_STDBY */
  669. #if defined(PWR_CR3_UCPD_DBDIS)
  670. void HAL_PWREx_EnableUCPDDeadBattery(void);
  671. void HAL_PWREx_DisableUCPDDeadBattery(void);
  672. #endif /* PWR_CR3_UCPD_DBDIS */
  673. /**
  674. * @}
  675. */
  676. /**
  677. * @}
  678. */
  679. /**
  680. * @}
  681. */
  682. /**
  683. * @}
  684. */
  685. #ifdef __cplusplus
  686. }
  687. #endif
  688. #endif /* STM32G4xx_HAL_PWR_EX_H */