stm32f3xx_hal_pwr_ex.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /**
  2. ******************************************************************************
  3. * @file stm32f3xx_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 "stm32f3xx_hal.h"
  25. /** @addtogroup STM32F3xx_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 PWR Extended 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 PWR Extended 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 (present on all other devices than STM32F3x8 devices) ***
  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_PVD_EXTI_ENABLE_IT() macro
  68. (+) The PVD is stopped in Standby mode.
  69. -@- PVD is not available on STM32F3x8 Product Line
  70. *** Voltage regulator ***
  71. =========================
  72. [..]
  73. (+) The voltage regulator is always enabled after Reset. It works in three different
  74. modes.
  75. In Run mode, the regulator supplies full power to the 1.8V domain (core, memories
  76. and digital peripherals).
  77. In Stop mode, the regulator supplies low power to the 1.8V domain, preserving
  78. contents of registers and SRAM.
  79. In Stop mode, the regulator is powered off. The contents of the registers and SRAM
  80. are lost except for the Standby circuitry and the Backup Domain.
  81. Note: in the STM32F3x8xx devices, the voltage regulator is bypassed and the
  82. microcontroller must be powered from a nominal VDD = 1.8V +/-8U% voltage.
  83. (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower
  84. than the PVD threshold. This event is internally connected to the EXTI
  85. line16 and can generate an interrupt if enabled. This is done through
  86. __HAL_PWR_PVD_EXTI_ENABLE_IT() macro
  87. (+) The PVD is stopped in Standby mode.
  88. *** SDADC power configuration ***
  89. ================================
  90. [..]
  91. (+) On STM32F373xC/STM32F378xx devices, there are up to
  92. 3 SDADC instances that can be enabled/disabled.
  93. @endverbatim
  94. * @{
  95. */
  96. #if defined(STM32F302xE) || defined(STM32F303xE) || \
  97. defined(STM32F302xC) || defined(STM32F303xC) || \
  98. defined(STM32F303x8) || defined(STM32F334x8) || \
  99. defined(STM32F301x8) || defined(STM32F302x8) || \
  100. defined(STM32F373xC)
  101. /**
  102. * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD).
  103. * @param sConfigPVD pointer to an PWR_PVDTypeDef structure that contains the configuration
  104. * information for the PVD.
  105. * @note Refer to the electrical characteristics of your device datasheet for
  106. * more details about the voltage threshold corresponding to each
  107. * detection level.
  108. * @retval None
  109. */
  110. void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD)
  111. {
  112. /* Check the parameters */
  113. assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel));
  114. assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode));
  115. /* Set PLS[7:5] bits according to PVDLevel value */
  116. MODIFY_REG(PWR->CR, PWR_CR_PLS, sConfigPVD->PVDLevel);
  117. /* Clear any previous config. Keep it clear if no event or IT mode is selected */
  118. __HAL_PWR_PVD_EXTI_DISABLE_EVENT();
  119. __HAL_PWR_PVD_EXTI_DISABLE_IT();
  120. __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();__HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE();
  121. /* Configure interrupt mode */
  122. if((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT)
  123. {
  124. __HAL_PWR_PVD_EXTI_ENABLE_IT();
  125. }
  126. /* Configure event mode */
  127. if((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT)
  128. {
  129. __HAL_PWR_PVD_EXTI_ENABLE_EVENT();
  130. }
  131. /* Configure the edge */
  132. if((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE)
  133. {
  134. __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();
  135. }
  136. if((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE)
  137. {
  138. __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();
  139. }
  140. }
  141. /**
  142. * @brief Enables the Power Voltage Detector(PVD).
  143. * @retval None
  144. */
  145. void HAL_PWR_EnablePVD(void)
  146. {
  147. SET_BIT(PWR->CR, PWR_CR_PVDE);
  148. }
  149. /**
  150. * @brief Disables the Power Voltage Detector(PVD).
  151. * @retval None
  152. */
  153. void HAL_PWR_DisablePVD(void)
  154. {
  155. CLEAR_BIT(PWR->CR, PWR_CR_PVDE);
  156. }
  157. /**
  158. * @brief This function handles the PWR PVD interrupt request.
  159. * @note This API should be called under the PVD_IRQHandler().
  160. * @retval None
  161. */
  162. void HAL_PWR_PVD_IRQHandler(void)
  163. {
  164. /* Check PWR exti flag */
  165. if(__HAL_PWR_PVD_EXTI_GET_FLAG() != RESET)
  166. {
  167. /* PWR PVD interrupt user callback */
  168. HAL_PWR_PVDCallback();
  169. /* Clear PWR Exti pending bit */
  170. __HAL_PWR_PVD_EXTI_CLEAR_FLAG();
  171. }
  172. }
  173. /**
  174. * @brief PWR PVD interrupt callback
  175. * @retval None
  176. */
  177. __weak void HAL_PWR_PVDCallback(void)
  178. {
  179. /* NOTE : This function Should not be modified, when the callback is needed,
  180. the HAL_PWR_PVDCallback could be implemented in the user file
  181. */
  182. }
  183. #endif /* STM32F302xE || STM32F303xE || */
  184. /* STM32F302xC || STM32F303xC || */
  185. /* STM32F303x8 || STM32F334x8 || */
  186. /* STM32F301x8 || STM32F302x8 || */
  187. /* STM32F373xC */
  188. #if defined(STM32F373xC) || defined(STM32F378xx)
  189. /**
  190. * @brief Enables the SDADC peripheral functionaliy
  191. * @param Analogx specifies the SDADC peripheral instance.
  192. * This parameter can be: PWR_SDADC_ANALOG1, PWR_SDADC_ANALOG2 or PWR_SDADC_ANALOG3.
  193. * @retval None
  194. */
  195. void HAL_PWREx_EnableSDADC(uint32_t Analogx)
  196. {
  197. /* Check the parameters */
  198. assert_param(IS_PWR_SDADC_ANALOG(Analogx));
  199. /* Enable PWR clock interface for SDADC use */
  200. __HAL_RCC_PWR_CLK_ENABLE();
  201. PWR->CR |= Analogx;
  202. }
  203. /**
  204. * @brief Disables the SDADC peripheral functionaliy
  205. * @param Analogx specifies the SDADC peripheral instance.
  206. * This parameter can be: PWR_SDADC_ANALOG1, PWR_SDADC_ANALOG2 or PWR_SDADC_ANALOG3.
  207. * @retval None
  208. */
  209. void HAL_PWREx_DisableSDADC(uint32_t Analogx)
  210. {
  211. /* Check the parameters */
  212. assert_param(IS_PWR_SDADC_ANALOG(Analogx));
  213. PWR->CR &= ~Analogx;
  214. }
  215. #endif /* STM32F373xC || STM32F378xx */
  216. /**
  217. * @}
  218. */
  219. /**
  220. * @}
  221. */
  222. #endif /* HAL_PWR_MODULE_ENABLED */
  223. /**
  224. * @}
  225. */
  226. /**
  227. * @}
  228. */