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