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