stm32g0xx_hal_pwr_ex.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /**
  2. ******************************************************************************
  3. * @file stm32g0xx_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) 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_EX_H
  20. #define STM32G0xx_HAL_PWR_EX_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 PWREx PWREx
  30. * @brief PWR Extended HAL module driver
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup PWREx_Exported_Types PWR Extended Exported Types
  35. * @{
  36. */
  37. #if defined(PWR_PVM_SUPPORT)
  38. /**
  39. * @brief PWR PVM configuration structure definition
  40. */
  41. typedef struct
  42. {
  43. uint32_t PVMType; /*!< PVMType: Specifies which voltage is monitored and against which threshold.
  44. This parameter can be a value of @ref PWREx_PVM_Type.
  45. @arg @ref PWR_PVM_USB Peripheral Voltage Monitoring USB enable */
  46. uint32_t Mode; /*!< Mode: Specifies the operating mode for the selected pins.
  47. This parameter can be a value of @ref PWREx_PVM_Mode. */
  48. } PWR_PVMTypeDef;
  49. #endif /* PWR_PVM_SUPPORT */
  50. #if defined(PWR_PVD_SUPPORT)
  51. /**
  52. * @brief PWR PVD configuration structure definition
  53. */
  54. typedef struct
  55. {
  56. uint32_t PVDLevel; /*!< PVDLevel: Specifies the PVD detection level.
  57. This parameter can be a value or a combination of
  58. @ref PWR_PVD_detection_level. */
  59. uint32_t Mode; /*!< Mode: Specifies the operating mode for the selected pins.
  60. This parameter can be a value of @ref PWR_PVD_Mode. */
  61. } PWR_PVDTypeDef;
  62. #endif /* PWR_PVD_SUPPORT */
  63. /**
  64. * @}
  65. */
  66. /* Exported constants --------------------------------------------------------*/
  67. /** @defgroup PWREx_Exported_Constants PWR Extended Exported Constants
  68. * @{
  69. */
  70. #if defined(PWR_PVD_SUPPORT)
  71. /** @defgroup PWR_PVD_detection_level Programmable Voltage Detection levels
  72. * @note see datasheet for selection voltage value
  73. * @{
  74. */
  75. #define PWR_PVDLEVEL_RISING_0 (0x00000000u) /*!< PVD threshold level 0 for rising detection */
  76. #define PWR_PVDLEVEL_RISING_1 (PWR_CR2_PVDRT_0) /*!< PVD threshold level 1 for rising detection */
  77. #define PWR_PVDLEVEL_RISING_2 (PWR_CR2_PVDRT_1) /*!< PVD threshold level 2 for rising detection */
  78. #define PWR_PVDLEVEL_RISING_3 (PWR_CR2_PVDRT_0 | PWR_CR2_PVDRT_1) /*!< PVD threshold level 3 for rising detection */
  79. #define PWR_PVDLEVEL_RISING_4 (PWR_CR2_PVDRT_2) /*!< PVD threshold level 4 for rising detection */
  80. #define PWR_PVDLEVEL_RISING_5 (PWR_CR2_PVDRT_2 | PWR_CR2_PVDRT_0) /*!< PVD threshold level 5 for rising detection */
  81. #define PWR_PVDLEVEL_RISING_6 (PWR_CR2_PVDRT_2 | PWR_CR2_PVDRT_1) /*!< PVD threshold level 6 for rising detection */
  82. #define PWR_PVDLEVEL_FALLING_0 (0x00000000u) /*!< PVD threshold level 0 for falling detection */
  83. #define PWR_PVDLEVEL_FALLING_1 (PWR_CR2_PVDFT_0) /*!< PVD threshold level 1 for falling detection */
  84. #define PWR_PVDLEVEL_FALLING_2 (PWR_CR2_PVDFT_1) /*!< PVD threshold level 2 for falling detection */
  85. #define PWR_PVDLEVEL_FALLING_3 (PWR_CR2_PVDFT_0 | PWR_CR2_PVDFT_1) /*!< PVD threshold level 3 for falling detection */
  86. #define PWR_PVDLEVEL_FALLING_4 (PWR_CR2_PVDFT_2) /*!< PVD threshold level 4 for falling detection */
  87. #define PWR_PVDLEVEL_FALLING_5 (PWR_CR2_PVDFT_2 | PWR_CR2_PVDFT_0) /*!< PVD threshold level 5 for falling detection */
  88. #define PWR_PVDLEVEL_FALLING_6 (PWR_CR2_PVDFT_2 | PWR_CR2_PVDFT_1) /*!< PVD threshold level 6 for falling detection */
  89. #define PWR_PVDLEVEL_0 (PWR_PVDLEVEL_RISING_0 | PWR_PVDLEVEL_FALLING_0) /*!< same PVD threshold level 0 on rising & falling */
  90. #define PWR_PVDLEVEL_1 (PWR_PVDLEVEL_RISING_1 | PWR_PVDLEVEL_FALLING_1) /*!< same PVD threshold level 1 on rising & falling */
  91. #define PWR_PVDLEVEL_2 (PWR_PVDLEVEL_RISING_2 | PWR_PVDLEVEL_FALLING_2) /*!< same PVD threshold level 2 on rising & falling */
  92. #define PWR_PVDLEVEL_3 (PWR_PVDLEVEL_RISING_3 | PWR_PVDLEVEL_FALLING_3) /*!< same PVD threshold level 3 on rising & falling */
  93. #define PWR_PVDLEVEL_4 (PWR_PVDLEVEL_RISING_4 | PWR_PVDLEVEL_FALLING_4) /*!< same PVD threshold level 4 on rising & falling */
  94. #define PWR_PVDLEVEL_5 (PWR_PVDLEVEL_RISING_5 | PWR_PVDLEVEL_FALLING_5) /*!< same PVD threshold level 5 on rising & falling */
  95. #define PWR_PVDLEVEL_6 (PWR_PVDLEVEL_RISING_6 | PWR_PVDLEVEL_FALLING_6) /*!< same PVD threshold level 6 on rising & falling */
  96. #define PWR_PVDLEVEL_7 (PWR_CR2_PVDRT_2 | PWR_CR2_PVDRT_1 | PWR_CR2_PVDRT_0) /*!< External input analog voltage (compared internally to VREFINT) */
  97. /**
  98. * @}
  99. */
  100. /** @defgroup PWR_PVD_Mode PWR PVD interrupt and event mode
  101. * @{
  102. */
  103. #define PWR_PVD_MODE_NORMAL (0x00000000u) /*!< basic mode is used */
  104. #define PWR_PVD_MODE_IT_RISING (0x00010001u) /*!< External Interrupt Mode with Rising edge trigger detection */
  105. #define PWR_PVD_MODE_IT_FALLING (0x00010002u) /*!< External Interrupt Mode with Falling edge trigger detection */
  106. #define PWR_PVD_MODE_IT_RISING_FALLING (0x00010003u) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
  107. #define PWR_PVD_MODE_EVENT_RISING (0x00020001u) /*!< Event Mode with Rising edge trigger detection */
  108. #define PWR_PVD_MODE_EVENT_FALLING (0x00020002u) /*!< Event Mode with Falling edge trigger detection */
  109. #define PWR_PVD_MODE_EVENT_RISING_FALLING (0x00020003u) /*!< Event Mode with Rising/Falling edge trigger detection */
  110. /**
  111. * @}
  112. */
  113. /** @defgroup PWR_PVD_EXTI_LINE PWR PVD external interrupt line
  114. * @{
  115. */
  116. #define PWR_EXTI_LINE_PVD (EXTI_IMR1_IM16) /*!< External interrupt line 16 connected to PVD */
  117. /**
  118. * @}
  119. */
  120. /** @defgroup PWR_PVD_EVENT_LINE PWR PVD event line
  121. * @{
  122. */
  123. #define PWR_EVENT_LINE_PVD (EXTI_EMR1_EM16) /*!< Event line 16 connected to PVD */
  124. /**
  125. * @}
  126. */
  127. #endif /* PWR_PVD_SUPPORT */
  128. #if defined(PWR_PVM_SUPPORT)
  129. /** @defgroup PWREx_PVM_Type Peripheral Voltage Monitoring type
  130. * @{
  131. */
  132. #define PWR_PVM_USB PWR_CR2_PVMEN_USB /*!< Peripheral Voltage Monitoring enable for USB peripheral: Enable to keep the USB peripheral voltage monitoring under control (power domain Vddio2) */
  133. /**
  134. * @}
  135. */
  136. /** @defgroup PWREx_PVM_Mode PWR PVM interrupt and event mode
  137. * @{
  138. */
  139. #define PWR_PVM_MODE_NORMAL ((uint32_t)0x00000000) /*!< basic mode is used */
  140. #define PWR_PVM_MODE_IT_RISING ((uint32_t)0x00010001) /*!< External Interrupt Mode with Rising edge trigger detection */
  141. #define PWR_PVM_MODE_IT_FALLING ((uint32_t)0x00010002) /*!< External Interrupt Mode with Falling edge trigger detection */
  142. #define PWR_PVM_MODE_IT_RISING_FALLING ((uint32_t)0x00010003) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
  143. #define PWR_PVM_MODE_EVENT_RISING ((uint32_t)0x00020001) /*!< Event Mode with Rising edge trigger detection */
  144. #define PWR_PVM_MODE_EVENT_FALLING ((uint32_t)0x00020002) /*!< Event Mode with Falling edge trigger detection */
  145. #define PWR_PVM_MODE_EVENT_RISING_FALLING ((uint32_t)0x00020003) /*!< Event Mode with Rising/Falling edge trigger detection */
  146. /**
  147. * @}
  148. */
  149. /** @defgroup PWR_PVM_EXTI_LINE PWR PVM external interrupt line
  150. * @{
  151. */
  152. #define PWR_EXTI_LINE_PVM (EXTI_IMR2_IM34) /*!< External interrupt line 34 connected to PVM */
  153. /**
  154. * @}
  155. */
  156. /** @defgroup PWR_PVM_EVENT_LINE PWR PVM event line
  157. * @{
  158. */
  159. #define PWR_EVENT_LINE_PVM (EXTI_EMR2_EM34) /*!< Event line 34 connected to PVM */
  160. /**
  161. * @}
  162. */
  163. #endif /* PWR_PVM_SUPPORT */
  164. /** @defgroup PWREx_VBAT_Battery_Charging_Selection PWR battery charging resistor selection
  165. * @{
  166. */
  167. #define PWR_BATTERY_CHARGING_RESISTOR_5 (0x00000000u) /*!< VBAT charging through a 5 kOhms resistor */
  168. #define PWR_BATTERY_CHARGING_RESISTOR_1_5 PWR_CR4_VBRS /*!< VBAT charging through a 1.5 kOhms resistor */
  169. /**
  170. * @}
  171. */
  172. /** @defgroup PWREx_GPIO_Bit_Number GPIO bit position
  173. * @brief for I/O pull up/down setting in standby/shutdown mode
  174. * @{
  175. */
  176. #define PWR_GPIO_BIT_0 PWR_PUCRB_PU0 /*!< GPIO port I/O pin 0 */
  177. #define PWR_GPIO_BIT_1 PWR_PUCRB_PU1 /*!< GPIO port I/O pin 1 */
  178. #define PWR_GPIO_BIT_2 PWR_PUCRB_PU2 /*!< GPIO port I/O pin 2 */
  179. #define PWR_GPIO_BIT_3 PWR_PUCRB_PU3 /*!< GPIO port I/O pin 3 */
  180. #define PWR_GPIO_BIT_4 PWR_PUCRB_PU4 /*!< GPIO port I/O pin 4 */
  181. #define PWR_GPIO_BIT_5 PWR_PUCRB_PU5 /*!< GPIO port I/O pin 5 */
  182. #define PWR_GPIO_BIT_6 PWR_PUCRB_PU6 /*!< GPIO port I/O pin 6 */
  183. #define PWR_GPIO_BIT_7 PWR_PUCRB_PU7 /*!< GPIO port I/O pin 7 */
  184. #define PWR_GPIO_BIT_8 PWR_PUCRB_PU8 /*!< GPIO port I/O pin 8 */
  185. #define PWR_GPIO_BIT_9 PWR_PUCRB_PU9 /*!< GPIO port I/O pin 9 */
  186. #define PWR_GPIO_BIT_10 PWR_PUCRB_PU10 /*!< GPIO port I/O pin 10 */
  187. #define PWR_GPIO_BIT_11 PWR_PUCRB_PU11 /*!< GPIO port I/O pin 11 */
  188. #define PWR_GPIO_BIT_12 PWR_PUCRB_PU12 /*!< GPIO port I/O pin 12 */
  189. #define PWR_GPIO_BIT_13 PWR_PUCRB_PU13 /*!< GPIO port I/O pin 13 */
  190. #define PWR_GPIO_BIT_14 PWR_PUCRB_PU14 /*!< GPIO port I/O pin 14 */
  191. #define PWR_GPIO_BIT_15 PWR_PUCRB_PU15 /*!< GPIO port I/O pin 15 */
  192. /**
  193. * @}
  194. */
  195. /** @defgroup PWREx_GPIO_Port GPIO Port
  196. * @{
  197. */
  198. #define PWR_GPIO_A (0x00000000u) /*!< GPIO port A */
  199. #define PWR_GPIO_B (0x00000001u) /*!< GPIO port B */
  200. #define PWR_GPIO_C (0x00000002u) /*!< GPIO port C */
  201. #define PWR_GPIO_D (0x00000003u) /*!< GPIO port D */
  202. #if defined (GPIOE)
  203. #define PWR_GPIO_E (0x00000004u) /*!< GPIO port E */
  204. #endif /* GPIOE */
  205. #define PWR_GPIO_F (0x00000005u) /*!< GPIO port F */
  206. /**
  207. * @}
  208. */
  209. /** @defgroup PWREx_Flash_PowerDown Flash Power Down modes
  210. * @{
  211. */
  212. #define PWR_FLASHPD_LPRUN PWR_CR1_FPD_LPRUN /*!< Enable Flash power down in low power run mode */
  213. #define PWR_FLASHPD_LPSLEEP PWR_CR1_FPD_LPSLP /*!< Enable Flash power down in low power sleep mode */
  214. #define PWR_FLASHPD_STOP PWR_CR1_FPD_STOP /*!< Enable Flash power down in stop mode */
  215. /**
  216. * @}
  217. */
  218. /** @defgroup PWREx_Regulator_Voltage_Scale PWR Regulator voltage scale
  219. * @{
  220. */
  221. #define PWR_REGULATOR_VOLTAGE_SCALE1 PWR_CR1_VOS_0 /*!< Voltage scaling range 1 */
  222. #define PWR_REGULATOR_VOLTAGE_SCALE2 PWR_CR1_VOS_1 /*!< Voltage scaling range 2 */
  223. /**
  224. * @}
  225. */
  226. /** @addtogroup PWR_Flag PWR Status Flags
  227. * @brief Elements values convention: 0000 00XX 000Y YYYYb
  228. * - Y YYYY : Flag position in the XX register (5 bits)
  229. * - XX : Status register (2 bits)
  230. * - 01: SR1 register
  231. * - 10: SR2 register
  232. * The only exception is PWR_FLAG_WU, encompassing all
  233. * wake-up flags and set to PWR_SR1_WUF.
  234. * @{
  235. */
  236. #if defined(PWR_PVM_SUPPORT)
  237. #define PWR_FLAG_PVMOUSB (0x00020000u | PWR_SR2_PVMO_USB) /*!< USB Peripheral Voltage Monitoring output */
  238. #endif /* PWR_PVM_SUPPORT */
  239. /**
  240. * @}
  241. */
  242. /**
  243. * @}
  244. */
  245. /* Exported macros -----------------------------------------------------------*/
  246. /** @addtogroup PWREx_Exported_Macros PWR Extended Exported Macros
  247. * @{
  248. */
  249. #if defined(PWR_PVD_SUPPORT)
  250. /**
  251. * @brief Enable the PVD Extended Interrupt Line.
  252. * @retval None
  253. */
  254. #define __HAL_PWR_PVD_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR1, PWR_EXTI_LINE_PVD)
  255. /**
  256. * @brief Disable the PVD Extended Interrupt Line.
  257. * @retval None
  258. */
  259. #define __HAL_PWR_PVD_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR1, PWR_EXTI_LINE_PVD)
  260. /**
  261. * @brief Enable the PVD Event Line.
  262. * @retval None
  263. */
  264. #define __HAL_PWR_PVD_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR1, PWR_EVENT_LINE_PVD)
  265. /**
  266. * @brief Disable the PVD Event Line.
  267. * @retval None
  268. */
  269. #define __HAL_PWR_PVD_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR1, PWR_EVENT_LINE_PVD)
  270. /**
  271. * @brief Enable the PVD Extended Interrupt Rising Trigger.
  272. * @retval None
  273. */
  274. #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR1, PWR_EXTI_LINE_PVD)
  275. /**
  276. * @brief Disable the PVD Extended Interrupt Rising Trigger.
  277. * @retval None
  278. */
  279. #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR1, PWR_EXTI_LINE_PVD)
  280. /**
  281. * @brief Enable the PVD Extended Interrupt Falling Trigger.
  282. * @retval None
  283. */
  284. #define __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR1, PWR_EXTI_LINE_PVD)
  285. /**
  286. * @brief Disable the PVD Extended Interrupt Falling Trigger.
  287. * @retval None
  288. */
  289. #define __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR1, PWR_EXTI_LINE_PVD)
  290. /**
  291. * @brief Enable the PVD Extended Interrupt Rising & Falling Trigger.
  292. * @retval None
  293. */
  294. #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_FALLING_EDGE() \
  295. do { \
  296. __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE(); \
  297. __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE(); \
  298. } while(0U)
  299. /**
  300. * @brief Disable the PVD Extended Interrupt Rising & Falling Trigger.
  301. * @retval None
  302. */
  303. #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_FALLING_EDGE() \
  304. do { \
  305. __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE(); \
  306. __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE(); \
  307. } while(0U)
  308. /**
  309. * @brief Generate a Software interrupt on selected EXTI line.
  310. * @retval None
  311. */
  312. #define __HAL_PWR_PVD_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER1, PWR_EXTI_LINE_PVD)
  313. /**
  314. * @brief Check whether or not the PVD EXTI interrupt Rising flag is set.
  315. * @retval EXTI PVD Line Status.
  316. */
  317. #define __HAL_PWR_PVD_EXTI_GET_RISING_FLAG() (EXTI->RPR1 & PWR_EXTI_LINE_PVD)
  318. /**
  319. * @brief Check whether or not the PVD EXTI interrupt Falling flag is set.
  320. * @retval EXTI PVD Line Status.
  321. */
  322. #define __HAL_PWR_PVD_EXTI_GET_FALLING_FLAG() (EXTI->FPR1 & PWR_EXTI_LINE_PVD)
  323. /**
  324. * @brief Clear the PVD EXTI interrupt Rising flag.
  325. * @retval None
  326. */
  327. #define __HAL_PWR_PVD_EXTI_CLEAR_RISING_FLAG() WRITE_REG(EXTI->RPR1, PWR_EXTI_LINE_PVD)
  328. /**
  329. * @brief Clear the PVD EXTI interrupt Falling flag.
  330. * @retval None
  331. */
  332. #define __HAL_PWR_PVD_EXTI_CLEAR_FALLING_FLAG() WRITE_REG(EXTI->FPR1, PWR_EXTI_LINE_PVD)
  333. #endif /* PWR_PVD_SUPPORT */
  334. #if defined(PWR_PVM_SUPPORT)
  335. /**
  336. * @brief Enable the PVM Extended Interrupt Line.
  337. * @retval None
  338. */
  339. #define __HAL_PWR_PVM_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR2, PWR_EXTI_LINE_PVM)
  340. /**
  341. * @brief Disable the PVM Extended Interrupt Line.
  342. * @retval None
  343. */
  344. #define __HAL_PWR_PVM_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR2, PWR_EXTI_LINE_PVM)
  345. /**
  346. * @brief Enable the PVM Event Line.
  347. * @retval None
  348. */
  349. #define __HAL_PWR_PVM_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR2, PWR_EVENT_LINE_PVM)
  350. /**
  351. * @brief Disable the PVM Event Line.
  352. * @retval None
  353. */
  354. #define __HAL_PWR_PVM_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR2, PWR_EVENT_LINE_PVM)
  355. /**
  356. * @brief Enable the PVM Extended Interrupt Rising Trigger.
  357. * @retval None
  358. */
  359. #define __HAL_PWR_PVM_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR2, PWR_EXTI_LINE_PVM)
  360. /**
  361. * @brief Disable the PVM Extended Interrupt Rising Trigger.
  362. * @retval None
  363. */
  364. #define __HAL_PWR_PVM_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR2, PWR_EXTI_LINE_PVM)
  365. /**
  366. * @brief Enable the PVM Extended Interrupt Falling Trigger.
  367. * @retval None
  368. */
  369. #define __HAL_PWR_PVM_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR2, PWR_EXTI_LINE_PVM)
  370. /**
  371. * @brief Disable the PVM Extended Interrupt Falling Trigger.
  372. * @retval None
  373. */
  374. #define __HAL_PWR_PVM_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR2, PWR_EXTI_LINE_PVM)
  375. /**
  376. * @brief Enable the PVM Extended Interrupt Rising & Falling Trigger.
  377. * @retval None
  378. */
  379. #define __HAL_PWR_PVM_EXTI_ENABLE_RISING_FALLING_EDGE() \
  380. do { \
  381. __HAL_PWR_PVM_EXTI_ENABLE_RISING_EDGE(); \
  382. __HAL_PWR_PVM_EXTI_ENABLE_FALLING_EDGE(); \
  383. } while(0U)
  384. /**
  385. * @brief Disable the PVM Extended Interrupt Rising & Falling Trigger.
  386. * @retval None
  387. */
  388. #define __HAL_PWR_PVM_EXTI_DISABLE_RISING_FALLING_EDGE() \
  389. do { \
  390. __HAL_PWR_PVM_EXTI_DISABLE_RISING_EDGE(); \
  391. __HAL_PWR_PVM_EXTI_DISABLE_FALLING_EDGE(); \
  392. } while(0U)
  393. /**
  394. * @brief Generate a Software interrupt on selected EXTI line.
  395. * @retval None
  396. */
  397. #define __HAL_PWR_PVM_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER2, PWR_EXTI_LINE_PVM)
  398. /**
  399. * @brief Check whether or not the PVM EXTI interrupt Rising flag is set.
  400. * @retval EXTI PVM Line Status.
  401. */
  402. #define __HAL_PWR_PVM_EXTI_GET_RISING_FLAG() (EXTI->RPR2 & PWR_EXTI_LINE_PVM)
  403. /**
  404. * @brief Check whether or not the PVM EXTI interrupt Falling flag is set.
  405. * @retval EXTI PVM Line Status.
  406. */
  407. #define __HAL_PWR_PVM_EXTI_GET_FALLING_FLAG() (EXTI->FPR2 & PWR_EXTI_LINE_PVM)
  408. /**
  409. * @brief Clear the PVM EXTI interrupt Rising flag.
  410. * @retval None
  411. */
  412. #define __HAL_PWR_PVM_EXTI_CLEAR_RISING_FLAG() WRITE_REG(EXTI->RPR2, PWR_EXTI_LINE_PVM)
  413. /**
  414. * @brief Clear the PVM EXTI interrupt Falling flag.
  415. * @retval None
  416. */
  417. #define __HAL_PWR_PVM_EXTI_CLEAR_FALLING_FLAG() WRITE_REG(EXTI->FPR2, PWR_EXTI_LINE_PVM)
  418. #endif /* PWR_PVM_SUPPORT */
  419. /**
  420. * @}
  421. */
  422. /* Private define ------------------------------------------------------------*/
  423. /** @defgroup PWR_Extended_Private_Defines PWR Extended Private Defines
  424. * @{
  425. */
  426. /** @defgroup PWREx_PVM_Mode_Mask PWR PVM Mode Mask
  427. * @{
  428. */
  429. #define PVM_MODE_IT ((uint32_t)0x00010000) /*!< Mask for interruption yielded by PVM threshold crossing */
  430. #define PVM_MODE_EVT ((uint32_t)0x00020000) /*!< Mask for event yielded by PVM threshold crossing */
  431. #define PVM_RISING_EDGE ((uint32_t)0x00000001) /*!< Mask for rising edge set as PVM trigger */
  432. #define PVM_FALLING_EDGE ((uint32_t)0x00000002) /*!< Mask for falling edge set as PVM trigger */
  433. /**
  434. * @}
  435. */
  436. /**
  437. * @}
  438. */
  439. /* Private macros ------------------------------------------------------------*/
  440. /** @addtogroup PWREx_Private_Macros PWR Extended Private Macros
  441. * @{
  442. */
  443. #define IS_PWR_BATTERY_RESISTOR_SELECT(__RESISTOR__) (((__RESISTOR__) == PWR_BATTERY_CHARGING_RESISTOR_5) || \
  444. ((__RESISTOR__) == PWR_BATTERY_CHARGING_RESISTOR_1_5))
  445. #define IS_PWR_GPIO_BIT_NUMBER(__BIT_NUMBER__) ((((__BIT_NUMBER__) & 0x0000FFFFu) != 0x00u) && \
  446. (((__BIT_NUMBER__) & 0xFFFF0000u) == 0x00u))
  447. #if defined (GPIOE)
  448. #define IS_PWR_GPIO(__GPIO__) (((__GPIO__) == PWR_GPIO_A) || \
  449. ((__GPIO__) == PWR_GPIO_B) || \
  450. ((__GPIO__) == PWR_GPIO_C) || \
  451. ((__GPIO__) == PWR_GPIO_D) || \
  452. ((__GPIO__) == PWR_GPIO_E) || \
  453. ((__GPIO__) == PWR_GPIO_F))
  454. #else
  455. #define IS_PWR_GPIO(__GPIO__) (((__GPIO__) == PWR_GPIO_A) || \
  456. ((__GPIO__) == PWR_GPIO_B) || \
  457. ((__GPIO__) == PWR_GPIO_C) || \
  458. ((__GPIO__) == PWR_GPIO_D) || \
  459. ((__GPIO__) == PWR_GPIO_F))
  460. #endif /* GPIOE */
  461. #define IS_PWR_FLASH_POWERDOWN(__MODE__) ((((__MODE__) & (PWR_FLASHPD_LPRUN | PWR_FLASHPD_LPSLEEP | PWR_FLASHPD_STOP)) != 0x00u) && \
  462. (((__MODE__) & ~(PWR_FLASHPD_LPRUN | PWR_FLASHPD_LPSLEEP | PWR_FLASHPD_STOP)) == 0x00u))
  463. #define IS_PWR_VOLTAGE_SCALING_RANGE(RANGE) (((RANGE) == PWR_REGULATOR_VOLTAGE_SCALE1) || \
  464. ((RANGE) == PWR_REGULATOR_VOLTAGE_SCALE2))
  465. #if defined(PWR_PVD_SUPPORT)
  466. #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) & ~(PWR_CR2_PVDRT | PWR_CR2_PVDFT)) == 0x00000000u)
  467. #define IS_PWR_PVD_MODE(MODE) (((MODE) == PWR_PVD_MODE_NORMAL) || \
  468. ((MODE) == PWR_PVD_MODE_IT_RISING) || \
  469. ((MODE) == PWR_PVD_MODE_IT_FALLING) || \
  470. ((MODE) == PWR_PVD_MODE_IT_RISING_FALLING) || \
  471. ((MODE) == PWR_PVD_MODE_EVENT_RISING) || \
  472. ((MODE) == PWR_PVD_MODE_EVENT_FALLING) || \
  473. ((MODE) == PWR_PVD_MODE_EVENT_RISING_FALLING))
  474. #endif /* PWR_PVD_SUPPORT */
  475. #if defined(PWR_PVM_SUPPORT)
  476. #define IS_PWR_PVM_TYPE(TYPE) ((TYPE) == PWR_PVM_USB)
  477. #define IS_PWR_PVM_MODE(MODE) (((MODE) == PWR_PVM_MODE_NORMAL) ||\
  478. ((MODE) == PWR_PVM_MODE_IT_RISING) ||\
  479. ((MODE) == PWR_PVM_MODE_IT_FALLING) ||\
  480. ((MODE) == PWR_PVM_MODE_IT_RISING_FALLING) ||\
  481. ((MODE) == PWR_PVM_MODE_EVENT_RISING) ||\
  482. ((MODE) == PWR_PVM_MODE_EVENT_FALLING) ||\
  483. ((MODE) == PWR_PVM_MODE_EVENT_RISING_FALLING))
  484. #endif /* PWR_PVM_SUPPORT */
  485. /**
  486. * @}
  487. */
  488. /* Exported functions --------------------------------------------------------*/
  489. /** @defgroup PWREx_Exported_Functions PWR Extended Exported Functions
  490. * @{
  491. */
  492. /** @defgroup PWREx_Exported_Functions_Group1 Extended Peripheral Control functions
  493. * @{
  494. */
  495. /* Peripheral Control functions **********************************************/
  496. void HAL_PWREx_EnableBatteryCharging(uint32_t ResistorSelection);
  497. void HAL_PWREx_DisableBatteryCharging(void);
  498. #if defined(PWR_CR3_ENB_ULP)
  499. void HAL_PWREx_EnablePORMonitorSampling(void);
  500. void HAL_PWREx_DisablePORMonitorSampling(void);
  501. #endif /* PWR_CR3_ENB_ULP */
  502. void HAL_PWREx_EnableInternalWakeUpLine(void);
  503. void HAL_PWREx_DisableInternalWakeUpLine(void);
  504. HAL_StatusTypeDef HAL_PWREx_EnableGPIOPullUp(uint32_t GPIO, uint32_t GPIONumber);
  505. HAL_StatusTypeDef HAL_PWREx_DisableGPIOPullUp(uint32_t GPIO, uint32_t GPIONumber);
  506. HAL_StatusTypeDef HAL_PWREx_EnableGPIOPullDown(uint32_t GPIO, uint32_t GPIONumber);
  507. HAL_StatusTypeDef HAL_PWREx_DisableGPIOPullDown(uint32_t GPIO, uint32_t GPIONumber);
  508. void HAL_PWREx_EnablePullUpPullDownConfig(void);
  509. void HAL_PWREx_DisablePullUpPullDownConfig(void);
  510. #if defined(PWR_CR3_RRS)
  511. void HAL_PWREx_EnableSRAMRetention(void);
  512. void HAL_PWREx_DisableSRAMRetention(void);
  513. #endif /* PWR_CR3_RRS */
  514. void HAL_PWREx_EnableFlashPowerDown(uint32_t PowerMode);
  515. void HAL_PWREx_DisableFlashPowerDown(uint32_t PowerMode);
  516. uint32_t HAL_PWREx_GetVoltageRange(void);
  517. HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling);
  518. #if defined(PWR_PVD_SUPPORT)
  519. /* Power voltage detection configuration functions ****************************/
  520. HAL_StatusTypeDef HAL_PWREx_ConfigPVD(PWR_PVDTypeDef *sConfigPVD);
  521. void HAL_PWREx_EnablePVD(void);
  522. void HAL_PWREx_DisablePVD(void);
  523. #endif /* PWR_PVD_SUPPORT */
  524. #if defined(PWR_PVM_SUPPORT)
  525. /* Power voltage monitoring configuration functions ***************************/
  526. void HAL_PWREx_EnableVddIO2(void);
  527. void HAL_PWREx_DisableVddIO2(void);
  528. void HAL_PWREx_EnablePVMUSB(void);
  529. void HAL_PWREx_DisablePVMUSB(void);
  530. HAL_StatusTypeDef HAL_PWREx_ConfigPVM(PWR_PVMTypeDef *sConfigPVM);
  531. #endif /* PWR_PVM_SUPPORT */
  532. #if defined(PWR_CR2_USV)
  533. void HAL_PWREx_EnableVddUSB(void);
  534. void HAL_PWREx_DisableVddUSB(void);
  535. #endif /* PWR_CR2_USV */
  536. /* Low Power modes configuration functions ************************************/
  537. void HAL_PWREx_EnableLowPowerRunMode(void);
  538. HAL_StatusTypeDef HAL_PWREx_DisableLowPowerRunMode(void);
  539. #if defined(PWR_SHDW_SUPPORT)
  540. void HAL_PWREx_EnterSHUTDOWNMode(void);
  541. #endif /* PWR_SHDW_SUPPORT */
  542. #if defined(PWR_PVD_SUPPORT) && defined(PWR_PVM_SUPPORT)
  543. void HAL_PWREx_PVD_PVM_IRQHandler(void);
  544. void HAL_PWREx_PVD_PVM_Rising_Callback(void);
  545. void HAL_PWREx_PVD_PVM_Falling_Callback(void);
  546. #elif defined(PWR_PVD_SUPPORT)
  547. void HAL_PWREx_PVD_IRQHandler(void);
  548. void HAL_PWREx_PVD_Rising_Callback(void);
  549. void HAL_PWREx_PVD_Falling_Callback(void);
  550. #endif /* PWR_PVD_SUPPORT && PWR_PVM_SUPPORT */
  551. /**
  552. * @}
  553. */
  554. /**
  555. * @}
  556. */
  557. /**
  558. * @}
  559. */
  560. /**
  561. * @}
  562. */
  563. #ifdef __cplusplus
  564. }
  565. #endif
  566. #endif /* STM32G0xx_HAL_PWR_EX_H */