You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

826 lines
33 KiB

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