2 ******************************************************************************
3 * @file stm32f3xx_hal_pwr_ex.c
4 * @author MCD Application Team
7 * @brief Extended PWR HAL module driver.
9 * This file provides firmware functions to manage the following
10 * functionalities of the Power Controller (PWR) peripheral:
11 * + Extended Initialization and de-initialization functions
12 * + Extended Peripheral Control functions
14 ******************************************************************************
17 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
19 * Redistribution and use in source and binary forms, with or without modification,
20 * are permitted provided that the following conditions are met:
21 * 1. Redistributions of source code must retain the above copyright notice,
22 * this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright notice,
24 * this list of conditions and the following disclaimer in the documentation
25 * and/or other materials provided with the distribution.
26 * 3. Neither the name of STMicroelectronics nor the names of its contributors
27 * may be used to endorse or promote products derived from this software
28 * without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
33 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
36 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
37 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
38 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 ******************************************************************************
44 /* Includes ------------------------------------------------------------------*/
45 #include "stm32f3xx_hal.h"
47 /** @addtogroup STM32F3xx_HAL_Driver
51 /** @defgroup PWREx PWR Extended HAL module driver
52 * @brief PWREx HAL module driver
56 #ifdef HAL_PWR_MODULE_ENABLED
58 /* Private typedef -----------------------------------------------------------*/
59 /* Private define ------------------------------------------------------------*/
60 /** @defgroup PWREx_Private_Constants PWR Extended Private Constants
63 #define PVD_MODE_IT ((uint32_t)0x00010000)
64 #define PVD_MODE_EVT ((uint32_t)0x00020000)
65 #define PVD_RISING_EDGE ((uint32_t)0x00000001)
66 #define PVD_FALLING_EDGE ((uint32_t)0x00000002)
71 /* Private macro -------------------------------------------------------------*/
72 /* Private variables ---------------------------------------------------------*/
73 /* Private function prototypes -----------------------------------------------*/
74 /* Exported functions ---------------------------------------------------------*/
76 /** @defgroup PWREx_Exported_Functions PWR Extended Exported Functions
80 /** @defgroup PWREx_Exported_Functions_Group1 Peripheral Extended Control Functions
81 * @brief Extended Peripheral Control functions
85 ===============================================================================
86 ##### Peripheral Extended control functions #####
87 ===============================================================================
88 *** PVD configuration (present on all other devices than STM32F3x8 devices) ***
89 =========================
91 (+) The PVD is used to monitor the VDD power supply by comparing it to a
92 threshold selected by the PVD Level (PLS[2:0] bits in the PWR_CR).
93 (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower
94 than the PVD threshold. This event is internally connected to the EXTI
95 line16 and can generate an interrupt if enabled. This is done through
96 __HAL_PVD_EXTI_ENABLE_IT() macro
97 (+) The PVD is stopped in Standby mode.
98 (+) Note: PVD is not available on STM32F3x8 Product Line
101 *** Voltage regulator ***
102 =========================
103 (+) The voltage regulator is always enabled after Reset. It works in three different
105 In Run mode, the regulator supplies full power to the 1.8V domain (core, memories
106 and digital peripherals).
107 In Stop mode, the regulator supplies low power to the 1.8V domain, preserving
108 contents of registers and SRAM.
109 In Stop mode, the regulator is powered off. The contents of the registers and SRAM
110 are lost except for the Standby circuitry and the Backup Domain.
111 Note: In the STM32F3x8xx devices, the voltage regulator is bypassed and the
112 microcontroller must be powered from a nominal VDD = 1.8V +/-8% voltage.
115 (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower
116 than the PVD threshold. This event is internally connected to the EXTI
117 line16 and can generate an interrupt if enabled. This is done through
118 __HAL_PVD_EXTI_ENABLE_IT() macro
119 (+) The PVD is stopped in Standby mode.
122 *** SDADC power configuration ***
123 ================================
124 (+) On STM32F373xC/STM32F378xx devices, there are up to
125 3 SDADC instances that can be enabled/disabled.
131 #if defined(STM32F302xE) || defined(STM32F303xE) || \
132 defined(STM32F302xC) || defined(STM32F303xC) || \
133 defined(STM32F303x8) || defined(STM32F334x8) || \
134 defined(STM32F301x8) || defined(STM32F302x8) || \
138 * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD).
139 * @param sConfigPVD: pointer to an PWR_PVDTypeDef structure that contains the configuration
140 * information for the PVD.
141 * @note Refer to the electrical characteristics of your device datasheet for
142 * more details about the voltage threshold corresponding to each
146 void HAL_PWR_PVDConfig(PWR_PVDTypeDef *sConfigPVD)
148 /* Check the parameters */
149 assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel));
150 assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode));
152 /* Set PLS[7:5] bits according to PVDLevel value */
153 MODIFY_REG(PWR->CR, PWR_CR_PLS, sConfigPVD->PVDLevel);
155 /* Clear any previous config. Keep it clear if no event or IT mode is selected */
156 __HAL_PWR_PVD_EXTI_DISABLE_EVENT();
157 __HAL_PWR_PVD_EXTI_DISABLE_IT();
158 __HAL_PWR_PVD_EXTI_CLEAR_EGDE_TRIGGER();
160 /* Configure interrupt mode */
161 if((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT)
163 __HAL_PWR_PVD_EXTI_ENABLE_IT();
166 /* Configure event mode */
167 if((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT)
169 __HAL_PWR_PVD_EXTI_ENABLE_EVENT();
172 /* Configure the edge */
173 if((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE)
175 __HAL_PWR_PVD_EXTI_SET_RISING_EDGE_TRIGGER();
178 if((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE)
180 __HAL_PWR_PVD_EXTI_SET_FALLING_EGDE_TRIGGER();
185 * @brief Enables the Power Voltage Detector(PVD).
188 void HAL_PWR_EnablePVD(void)
190 *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)ENABLE;
194 * @brief Disables the Power Voltage Detector(PVD).
197 void HAL_PWR_DisablePVD(void)
199 *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)DISABLE;
203 * @brief This function handles the PWR PVD interrupt request.
204 * @note This API should be called under the PVD_IRQHandler().
207 void HAL_PWR_PVD_IRQHandler(void)
209 /* Check PWR exti flag */
210 if(__HAL_PWR_PVD_EXTI_GET_FLAG() != RESET)
212 /* PWR PVD interrupt user callback */
213 HAL_PWR_PVDCallback();
215 /* Clear PWR Exti pending bit */
216 __HAL_PWR_PVD_EXTI_CLEAR_FLAG();
221 * @brief PWR PVD interrupt callback
224 __weak void HAL_PWR_PVDCallback(void)
226 /* NOTE : This function Should not be modified, when the callback is needed,
227 the HAL_PWR_PVDCallback could be implemented in the user file
231 #endif /* STM32F302xE || STM32F303xE || */
232 /* STM32F302xC || STM32F303xC || */
233 /* STM32F303x8 || STM32F334x8 || */
234 /* STM32F301x8 || STM32F302x8 || */
237 #if defined(STM32F373xC) || defined(STM32F378xx)
240 * @brief Enables the SDADC peripheral functionaliy
241 * @param Analogx: specifies the SDADC peripheral instance.
242 * This parameter can be: PWR_SDADC_ANALOG1, PWR_SDADC_ANALOG2 or PWR_SDADC_ANALOG3.
245 void HAL_PWREx_EnableSDADCAnalog(uint32_t Analogx)
247 /* Check the parameters */
248 assert_param(IS_PWR_SDADC_ANALOG(Analogx));
250 /* Enable PWR clock interface for SDADC use */
257 * @brief Disables the SDADC peripheral functionaliy
258 * @param Analogx: specifies the SDADC peripheral instance.
259 * This parameter can be: PWR_SDADC_ANALOG1, PWR_SDADC_ANALOG2 or PWR_SDADC_ANALOG3.
262 void HAL_PWREx_DisableSDADCAnalog(uint32_t Analogx)
264 /* Check the parameters */
265 assert_param(IS_PWR_SDADC_ANALOG(Analogx));
270 #endif /* STM32F373xC || STM32F378xx */
280 #endif /* HAL_PWR_MODULE_ENABLED */
289 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/