Subversion Repositories FuelGauge

Rev

Details | Last modification | View Log | RSS feed

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