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.
 
 
 

291 lines
9.5 KiB

  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</center></h2>
  15. *
  16. * Redistribution and use in source and binary forms, with or without modification,
  17. * are permitted provided that the following conditions are met:
  18. * 1. Redistributions of source code must retain the above copyright notice,
  19. * this list of conditions and the following disclaimer.
  20. * 2. Redistributions in binary form must reproduce the above copyright notice,
  21. * this list of conditions and the following disclaimer in the documentation
  22. * and/or other materials provided with the distribution.
  23. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  24. * may be used to endorse or promote products derived from this software
  25. * without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  28. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  29. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  30. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  31. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  33. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  34. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  35. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  36. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. ******************************************************************************
  39. */
  40. /* Includes ------------------------------------------------------------------*/
  41. #include "stm32f0xx_hal.h"
  42. /** @addtogroup STM32F0xx_HAL_Driver
  43. * @{
  44. */
  45. /** @defgroup PWREx PWREx
  46. * @brief PWREx HAL module driver
  47. * @{
  48. */
  49. #ifdef HAL_PWR_MODULE_ENABLED
  50. /* Private typedef -----------------------------------------------------------*/
  51. /* Private define ------------------------------------------------------------*/
  52. /** @defgroup PWREx_Private_Constants PWREx Private Constants
  53. * @{
  54. */
  55. #define PVD_MODE_IT (0x00010000U)
  56. #define PVD_MODE_EVT (0x00020000U)
  57. #define PVD_RISING_EDGE (0x00000001U)
  58. #define PVD_FALLING_EDGE (0x00000002U)
  59. /**
  60. * @}
  61. */
  62. /* Private macro -------------------------------------------------------------*/
  63. /* Private variables ---------------------------------------------------------*/
  64. /* Private function prototypes -----------------------------------------------*/
  65. /* Exported functions ---------------------------------------------------------*/
  66. /** @defgroup PWREx_Exported_Functions PWREx Exported Functions
  67. * @{
  68. */
  69. /** @defgroup PWREx_Exported_Functions_Group1 Peripheral Extended Control Functions
  70. * @brief Extended Peripheral Control functions
  71. *
  72. @verbatim
  73. ===============================================================================
  74. ##### Peripheral extended control functions #####
  75. ===============================================================================
  76. *** PVD configuration ***
  77. =========================
  78. [..]
  79. (+) The PVD is used to monitor the VDD power supply by comparing it to a
  80. threshold selected by the PVD Level (PLS[2:0] bits in the PWR_CR).
  81. (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower
  82. than the PVD threshold. This event is internally connected to the EXTI
  83. line16 and can generate an interrupt if enabled. This is done through
  84. HAL_PWR_ConfigPVD(), HAL_PWR_EnablePVD() functions.
  85. (+) The PVD is stopped in Standby mode.
  86. -@- PVD is not available on STM32F030x4/x6/x8
  87. *** VDDIO2 Monitor Configuration ***
  88. ====================================
  89. [..]
  90. (+) VDDIO2 monitor is used to monitor the VDDIO2 power supply by comparing it
  91. to VREFInt Voltage
  92. (+) This monitor is internally connected to the EXTI line31
  93. and can generate an interrupt if enabled. This is done through
  94. HAL_PWREx_EnableVddio2Monitor() function.
  95. -@- VDDIO2 is available on STM32F07x/09x/04x
  96. @endverbatim
  97. * @{
  98. */
  99. #if defined (STM32F031x6) || defined (STM32F051x8) || \
  100. defined (STM32F071xB) || defined (STM32F091xC) || \
  101. defined (STM32F042x6) || defined (STM32F072xB)
  102. /**
  103. * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD).
  104. * @param sConfigPVD pointer to an PWR_PVDTypeDef structure that contains the configuration
  105. * information for the PVD.
  106. * @note Refer to the electrical characteristics of your device datasheet for
  107. * more details about the voltage threshold corresponding to each
  108. * detection level.
  109. * @retval None
  110. */
  111. void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD)
  112. {
  113. /* Check the parameters */
  114. assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel));
  115. assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode));
  116. /* Set PLS[7:5] bits according to PVDLevel value */
  117. MODIFY_REG(PWR->CR, PWR_CR_PLS, sConfigPVD->PVDLevel);
  118. /* Clear any previous config. Keep it clear if no event or IT mode is selected */
  119. __HAL_PWR_PVD_EXTI_DISABLE_EVENT();
  120. __HAL_PWR_PVD_EXTI_DISABLE_IT();
  121. __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();__HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE();
  122. /* Configure interrupt mode */
  123. if((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT)
  124. {
  125. __HAL_PWR_PVD_EXTI_ENABLE_IT();
  126. }
  127. /* Configure event mode */
  128. if((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT)
  129. {
  130. __HAL_PWR_PVD_EXTI_ENABLE_EVENT();
  131. }
  132. /* Configure the edge */
  133. if((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE)
  134. {
  135. __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();
  136. }
  137. if((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE)
  138. {
  139. __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();
  140. }
  141. }
  142. /**
  143. * @brief Enables the Power Voltage Detector(PVD).
  144. * @retval None
  145. */
  146. void HAL_PWR_EnablePVD(void)
  147. {
  148. PWR->CR |= (uint32_t)PWR_CR_PVDE;
  149. }
  150. /**
  151. * @brief Disables the Power Voltage Detector(PVD).
  152. * @retval None
  153. */
  154. void HAL_PWR_DisablePVD(void)
  155. {
  156. PWR->CR &= ~((uint32_t)PWR_CR_PVDE);
  157. }
  158. /**
  159. * @brief This function handles the PWR PVD interrupt request.
  160. * @note This API should be called under the PVD_IRQHandler() or PVD_VDDIO2_IRQHandler().
  161. * @retval None
  162. */
  163. void HAL_PWR_PVD_IRQHandler(void)
  164. {
  165. /* Check PWR exti flag */
  166. if(__HAL_PWR_PVD_EXTI_GET_FLAG() != RESET)
  167. {
  168. /* PWR PVD interrupt user callback */
  169. HAL_PWR_PVDCallback();
  170. /* Clear PWR Exti pending bit */
  171. __HAL_PWR_PVD_EXTI_CLEAR_FLAG();
  172. }
  173. }
  174. /**
  175. * @brief PWR PVD interrupt callback
  176. * @retval None
  177. */
  178. __weak void HAL_PWR_PVDCallback(void)
  179. {
  180. /* NOTE : This function Should not be modified, when the callback is needed,
  181. the HAL_PWR_PVDCallback could be implemented in the user file
  182. */
  183. }
  184. #endif /* defined (STM32F031x6) || defined (STM32F051x8) || */
  185. /* defined (STM32F071xB) || defined (STM32F091xC) || */
  186. /* defined (STM32F042x6) || defined (STM32F072xB) */
  187. #if defined (STM32F042x6) || defined (STM32F048xx) || \
  188. defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || \
  189. defined (STM32F091xC) || defined (STM32F098xx)
  190. /**
  191. * @brief Enable VDDIO2 monitor: enable Exti 31 and falling edge detection.
  192. * @note If Exti 31 is enable correlty and VDDIO2 voltage goes below Vrefint,
  193. an interrupt is generated Irq line 1.
  194. NVIS has to be enable by user.
  195. * @retval None
  196. */
  197. void HAL_PWREx_EnableVddio2Monitor(void)
  198. {
  199. __HAL_PWR_VDDIO2_EXTI_ENABLE_IT();
  200. __HAL_PWR_VDDIO2_EXTI_ENABLE_FALLING_EDGE();
  201. }
  202. /**
  203. * @brief Disable the Vddio2 Monitor.
  204. * @retval None
  205. */
  206. void HAL_PWREx_DisableVddio2Monitor(void)
  207. {
  208. __HAL_PWR_VDDIO2_EXTI_DISABLE_IT();
  209. __HAL_PWR_VDDIO2_EXTI_DISABLE_FALLING_EDGE();
  210. }
  211. /**
  212. * @brief This function handles the PWR Vddio2 monitor interrupt request.
  213. * @note This API should be called under the VDDIO2_IRQHandler() PVD_VDDIO2_IRQHandler().
  214. * @retval None
  215. */
  216. void HAL_PWREx_Vddio2Monitor_IRQHandler(void)
  217. {
  218. /* Check PWR exti flag */
  219. if(__HAL_PWR_VDDIO2_EXTI_GET_FLAG() != RESET)
  220. {
  221. /* PWR Vddio2 monitor interrupt user callback */
  222. HAL_PWREx_Vddio2MonitorCallback();
  223. /* Clear PWR Exti pending bit */
  224. __HAL_PWR_VDDIO2_EXTI_CLEAR_FLAG();
  225. }
  226. }
  227. /**
  228. * @brief PWR Vddio2 Monitor interrupt callback
  229. * @retval None
  230. */
  231. __weak void HAL_PWREx_Vddio2MonitorCallback(void)
  232. {
  233. /* NOTE : This function Should not be modified, when the callback is needed,
  234. the HAL_PWREx_Vddio2MonitorCallback could be implemented in the user file
  235. */
  236. }
  237. #endif /* defined (STM32F042x6) || defined (STM32F048xx) || \
  238. defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || \
  239. defined (STM32F091xC) || defined (STM32F098xx) */
  240. /**
  241. * @}
  242. */
  243. /**
  244. * @}
  245. */
  246. #endif /* HAL_PWR_MODULE_ENABLED */
  247. /**
  248. * @}
  249. */
  250. /**
  251. * @}
  252. */
  253. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/