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