stm32f0xx_hal_pwr_ex.c 8.3 KB

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