]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F3/stm32f3xx_hal_pwr_ex.c
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F3 / stm32f3xx_hal_pwr_ex.c
1 /**
2   ******************************************************************************
3   * @file    stm32f3xx_hal_pwr_ex.c
4   * @author  MCD Application Team
5   * @version V1.1.0
6   * @date    12-Sept-2014
7   * @brief   Extended PWR HAL module driver.
8   *
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
13   *         
14   ******************************************************************************
15   * @attention
16   *
17   * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
18   *
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.
29   *
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.
40   *
41   ******************************************************************************
42   */
43
44 /* Includes ------------------------------------------------------------------*/
45 #include "stm32f3xx_hal.h"
46
47 /** @addtogroup STM32F3xx_HAL_Driver
48   * @{
49   */
50
51 /** @defgroup PWREx PWR Extended HAL module driver
52   * @brief    PWREx HAL module driver
53   * @{
54   */
55
56 #ifdef HAL_PWR_MODULE_ENABLED
57
58 /* Private typedef -----------------------------------------------------------*/
59 /* Private define ------------------------------------------------------------*/
60 /** @defgroup PWREx_Private_Constants PWR Extended Private Constants
61   * @{
62   */
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)
67 /**
68   * @}
69   */
70  
71 /* Private macro -------------------------------------------------------------*/
72 /* Private variables ---------------------------------------------------------*/
73 /* Private function prototypes -----------------------------------------------*/
74 /* Exported functions ---------------------------------------------------------*/
75
76 /** @defgroup PWREx_Exported_Functions PWR Extended Exported Functions
77   * @{
78   */
79
80 /** @defgroup PWREx_Exported_Functions_Group1 Peripheral Extended Control Functions
81   *  @brief   Extended Peripheral Control functions
82   *
83 @verbatim
84
85  ===============================================================================
86                  ##### Peripheral Extended control functions #####
87  ===============================================================================
88     *** PVD configuration (present on all other devices than STM32F3x8 devices) ***
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_PVD_EXTI_ENABLE_IT() macro
97       (+) The PVD is stopped in Standby mode.
98       (+) Note: PVD is not available on STM32F3x8 Product Line
99
100
101     *** Voltage regulator ***
102     =========================
103       (+) The voltage regulator is always enabled after Reset. It works in three different
104           modes:
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.
113
114
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.
120
121
122     *** SDADC power configuration ***
123     ================================
124       (+) On STM32F373xC/STM32F378xx devices, there are up to 
125           3 SDADC instances that can be enabled/disabled.
126
127 @endverbatim
128   * @{
129   */
130
131 #if defined(STM32F302xE) || defined(STM32F303xE) || \
132     defined(STM32F302xC) || defined(STM32F303xC) || \
133     defined(STM32F303x8) || defined(STM32F334x8) || \
134     defined(STM32F301x8) || defined(STM32F302x8) || \
135     defined(STM32F373xC)
136
137 /**
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
143   *         detection level.
144   * @retval None
145   */
146 void HAL_PWR_PVDConfig(PWR_PVDTypeDef *sConfigPVD)
147 {
148   /* Check the parameters */
149   assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel));
150   assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode));
151
152   /* Set PLS[7:5] bits according to PVDLevel value */
153   MODIFY_REG(PWR->CR, PWR_CR_PLS, sConfigPVD->PVDLevel);
154   
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();
159
160   /* Configure interrupt mode */
161   if((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT)
162   {
163     __HAL_PWR_PVD_EXTI_ENABLE_IT();
164   }
165   
166   /* Configure event mode */
167   if((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT)
168   {
169     __HAL_PWR_PVD_EXTI_ENABLE_EVENT();
170   }
171   
172   /* Configure the edge */
173   if((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE)
174   {
175     __HAL_PWR_PVD_EXTI_SET_RISING_EDGE_TRIGGER();
176   }
177   
178   if((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE)
179   {
180     __HAL_PWR_PVD_EXTI_SET_FALLING_EGDE_TRIGGER();
181   }
182 }
183
184 /**
185   * @brief Enables the Power Voltage Detector(PVD).
186   * @retval None
187   */
188 void HAL_PWR_EnablePVD(void)
189 {
190   *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)ENABLE;
191 }
192
193 /**
194   * @brief Disables the Power Voltage Detector(PVD).
195   * @retval None
196   */
197 void HAL_PWR_DisablePVD(void)
198 {
199   *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)DISABLE;
200 }
201
202 /**
203   * @brief This function handles the PWR PVD interrupt request.
204   * @note This API should be called under the PVD_IRQHandler().
205   * @retval None
206   */
207 void HAL_PWR_PVD_IRQHandler(void)
208 {
209   /* Check PWR exti flag */
210   if(__HAL_PWR_PVD_EXTI_GET_FLAG() != RESET)
211   {
212     /* PWR PVD interrupt user callback */
213     HAL_PWR_PVDCallback();
214
215     /* Clear PWR Exti pending bit */
216     __HAL_PWR_PVD_EXTI_CLEAR_FLAG();
217   }
218 }
219
220 /**
221   * @brief PWR PVD interrupt callback
222   * @retval None
223   */
224 __weak void HAL_PWR_PVDCallback(void)
225 {
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
228    */
229 }
230
231 #endif /* STM32F302xE || STM32F303xE || */
232        /* STM32F302xC || STM32F303xC || */
233        /* STM32F303x8 || STM32F334x8 || */
234        /* STM32F301x8 || STM32F302x8 || */
235        /* STM32F373xC                   */
236
237 #if defined(STM32F373xC) || defined(STM32F378xx)
238
239 /**
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.
243   * @retval None
244   */
245 void HAL_PWREx_EnableSDADCAnalog(uint32_t Analogx)
246 {
247   /* Check the parameters */
248   assert_param(IS_PWR_SDADC_ANALOG(Analogx));
249
250   /* Enable PWR clock interface for SDADC use */
251   __PWR_CLK_ENABLE();
252     
253   PWR->CR |= Analogx;
254 }
255
256 /**
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.
260   * @retval None
261   */
262 void HAL_PWREx_DisableSDADCAnalog(uint32_t Analogx)
263 {
264   /* Check the parameters */
265   assert_param(IS_PWR_SDADC_ANALOG(Analogx));
266   
267   PWR->CR &= ~Analogx;
268 }
269
270 #endif /* STM32F373xC || STM32F378xx */
271
272 /**
273   * @}
274   */
275
276 /**
277   * @}
278   */
279
280 #endif /* HAL_PWR_MODULE_ENABLED */
281 /**
282   * @}
283   */
284
285 /**
286   * @}
287   */
288
289 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/