stm32f0xx_hal_pwr_ex.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_hal_pwr_ex.c
  4. * @author MCD Application Team
  5. * @brief Extended PWR HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the Power Controller (PWR) peripheral:
  8. * + Extended Initialization and de-initialization functions
  9. * + Extended Peripheral Control functions
  10. *
  11. ******************************************************************************
  12. * @attention
  13. *
  14. * Copyright (c) 2016 STMicroelectronics.
  15. * All rights reserved.
  16. *
  17. * This software is licensed under terms that can be found in the LICENSE file
  18. * in the root directory of this software component.
  19. * If no LICENSE file comes with this software, it is provided AS-IS.
  20. *
  21. ******************************************************************************
  22. */
  23. /* Includes ------------------------------------------------------------------*/
  24. #include "stm32f0xx_hal.h"
  25. /** @addtogroup STM32F0xx_HAL_Driver
  26. * @{
  27. */
  28. /** @defgroup PWREx PWREx
  29. * @brief PWREx HAL module driver
  30. * @{
  31. */
  32. #ifdef HAL_PWR_MODULE_ENABLED
  33. /* Private typedef -----------------------------------------------------------*/
  34. /* Private define ------------------------------------------------------------*/
  35. /** @defgroup PWREx_Private_Constants PWREx Private Constants
  36. * @{
  37. */
  38. #define PVD_MODE_IT (0x00010000U)
  39. #define PVD_MODE_EVT (0x00020000U)
  40. #define PVD_RISING_EDGE (0x00000001U)
  41. #define PVD_FALLING_EDGE (0x00000002U)
  42. /**
  43. * @}
  44. */
  45. /* Private macro -------------------------------------------------------------*/
  46. /* Private variables ---------------------------------------------------------*/
  47. /* Private function prototypes -----------------------------------------------*/
  48. /* Exported functions ---------------------------------------------------------*/
  49. /** @defgroup PWREx_Exported_Functions PWREx Exported Functions
  50. * @{
  51. */
  52. /** @defgroup PWREx_Exported_Functions_Group1 Peripheral Extended Control Functions
  53. * @brief Extended Peripheral Control functions
  54. *
  55. @verbatim
  56. ===============================================================================
  57. ##### Peripheral extended control functions #####
  58. ===============================================================================
  59. *** PVD configuration ***
  60. =========================
  61. [..]
  62. (+) The PVD is used to monitor the VDD power supply by comparing it to a
  63. threshold selected by the PVD Level (PLS[2:0] bits in the PWR_CR).
  64. (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower
  65. than the PVD threshold. This event is internally connected to the EXTI
  66. line16 and can generate an interrupt if enabled. This is done through
  67. HAL_PWR_ConfigPVD(), HAL_PWR_EnablePVD() functions.
  68. (+) The PVD is stopped in Standby mode.
  69. -@- PVD is not available on STM32F030x4/x6/x8
  70. *** VDDIO2 Monitor Configuration ***
  71. ====================================
  72. [..]
  73. (+) VDDIO2 monitor is used to monitor the VDDIO2 power supply by comparing it
  74. to VREFInt Voltage
  75. (+) This monitor is internally connected to the EXTI line31
  76. and can generate an interrupt if enabled. This is done through
  77. HAL_PWREx_EnableVddio2Monitor() function.
  78. -@- VDDIO2 is available on STM32F07x/09x/04x
  79. @endverbatim
  80. * @{
  81. */
  82. #if defined (STM32F031x6) || defined (STM32F051x8) || \
  83. defined (STM32F071xB) || defined (STM32F091xC) || \
  84. defined (STM32F042x6) || defined (STM32F072xB)
  85. /**
  86. * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD).
  87. * @param sConfigPVD pointer to an PWR_PVDTypeDef structure that contains the configuration
  88. * information for the PVD.
  89. * @note Refer to the electrical characteristics of your device datasheet for
  90. * more details about the voltage threshold corresponding to each
  91. * detection level.
  92. * @retval None
  93. */
  94. void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD)
  95. {
  96. /* Check the parameters */
  97. assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel));
  98. assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode));
  99. /* Set PLS[7:5] bits according to PVDLevel value */
  100. MODIFY_REG(PWR->CR, PWR_CR_PLS, sConfigPVD->PVDLevel);
  101. /* Clear any previous config. Keep it clear if no event or IT mode is selected */
  102. __HAL_PWR_PVD_EXTI_DISABLE_EVENT();
  103. __HAL_PWR_PVD_EXTI_DISABLE_IT();
  104. __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();__HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE();
  105. /* Configure interrupt mode */
  106. if((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT)
  107. {
  108. __HAL_PWR_PVD_EXTI_ENABLE_IT();
  109. }
  110. /* Configure event mode */
  111. if((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT)
  112. {
  113. __HAL_PWR_PVD_EXTI_ENABLE_EVENT();
  114. }
  115. /* Configure the edge */
  116. if((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE)
  117. {
  118. __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();
  119. }
  120. if((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE)
  121. {
  122. __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();
  123. }
  124. }
  125. /**
  126. * @brief Enables the Power Voltage Detector(PVD).
  127. * @retval None
  128. */
  129. void HAL_PWR_EnablePVD(void)
  130. {
  131. PWR->CR |= (uint32_t)PWR_CR_PVDE;
  132. }
  133. /**
  134. * @brief Disables the Power Voltage Detector(PVD).
  135. * @retval None
  136. */
  137. void HAL_PWR_DisablePVD(void)
  138. {
  139. PWR->CR &= ~((uint32_t)PWR_CR_PVDE);
  140. }
  141. /**
  142. * @brief This function handles the PWR PVD interrupt request.
  143. * @note This API should be called under the PVD_IRQHandler() or PVD_VDDIO2_IRQHandler().
  144. * @retval None
  145. */
  146. void HAL_PWR_PVD_IRQHandler(void)
  147. {
  148. /* Check PWR exti flag */
  149. if(__HAL_PWR_PVD_EXTI_GET_FLAG() != RESET)
  150. {
  151. /* PWR PVD interrupt user callback */
  152. HAL_PWR_PVDCallback();
  153. /* Clear PWR Exti pending bit */
  154. __HAL_PWR_PVD_EXTI_CLEAR_FLAG();
  155. }
  156. }
  157. /**
  158. * @brief PWR PVD interrupt callback
  159. * @retval None
  160. */
  161. __weak void HAL_PWR_PVDCallback(void)
  162. {
  163. /* NOTE : This function Should not be modified, when the callback is needed,
  164. the HAL_PWR_PVDCallback could be implemented in the user file
  165. */
  166. }
  167. #endif /* defined (STM32F031x6) || defined (STM32F051x8) || */
  168. /* defined (STM32F071xB) || defined (STM32F091xC) || */
  169. /* defined (STM32F042x6) || defined (STM32F072xB) */
  170. #if defined (STM32F042x6) || defined (STM32F048xx) || \
  171. defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || \
  172. defined (STM32F091xC) || defined (STM32F098xx)
  173. /**
  174. * @brief Enable VDDIO2 monitor: enable Exti 31 and falling edge detection.
  175. * @note If Exti 31 is enable correlty and VDDIO2 voltage goes below Vrefint,
  176. an interrupt is generated Irq line 1.
  177. NVIS has to be enable by user.
  178. * @retval None
  179. */
  180. void HAL_PWREx_EnableVddio2Monitor(void)
  181. {
  182. __HAL_PWR_VDDIO2_EXTI_ENABLE_IT();
  183. __HAL_PWR_VDDIO2_EXTI_ENABLE_FALLING_EDGE();
  184. }
  185. /**
  186. * @brief Disable the Vddio2 Monitor.
  187. * @retval None
  188. */
  189. void HAL_PWREx_DisableVddio2Monitor(void)
  190. {
  191. __HAL_PWR_VDDIO2_EXTI_DISABLE_IT();
  192. __HAL_PWR_VDDIO2_EXTI_DISABLE_FALLING_EDGE();
  193. }
  194. /**
  195. * @brief This function handles the PWR Vddio2 monitor interrupt request.
  196. * @note This API should be called under the VDDIO2_IRQHandler() PVD_VDDIO2_IRQHandler().
  197. * @retval None
  198. */
  199. void HAL_PWREx_Vddio2Monitor_IRQHandler(void)
  200. {
  201. /* Check PWR exti flag */
  202. if(__HAL_PWR_VDDIO2_EXTI_GET_FLAG() != RESET)
  203. {
  204. /* PWR Vddio2 monitor interrupt user callback */
  205. HAL_PWREx_Vddio2MonitorCallback();
  206. /* Clear PWR Exti pending bit */
  207. __HAL_PWR_VDDIO2_EXTI_CLEAR_FLAG();
  208. }
  209. }
  210. /**
  211. * @brief PWR Vddio2 Monitor interrupt callback
  212. * @retval None
  213. */
  214. __weak void HAL_PWREx_Vddio2MonitorCallback(void)
  215. {
  216. /* NOTE : This function Should not be modified, when the callback is needed,
  217. the HAL_PWREx_Vddio2MonitorCallback could be implemented in the user file
  218. */
  219. }
  220. #endif /* defined (STM32F042x6) || defined (STM32F048xx) || \
  221. defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || \
  222. defined (STM32F091xC) || defined (STM32F098xx) */
  223. /**
  224. * @}
  225. */
  226. /**
  227. * @}
  228. */
  229. #endif /* HAL_PWR_MODULE_ENABLED */
  230. /**
  231. * @}
  232. */
  233. /**
  234. * @}
  235. */