mbed library sources

Dependents:   Marvino mbot

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Sep 28 14:00:11 2015 +0100
Revision:
632:7687fb9c4f91
Parent:
385:be64abf45658
Child:
634:ac7d6880524d
Synchronized with git revision f7ce4ed029cc611121464252ff28d5e8beb895b0

Full URL: https://github.com/mbedmicro/mbed/commit/f7ce4ed029cc611121464252ff28d5e8beb895b0/

NUCLEO_F303K8 - add support of the STM32F303K8

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 237:f3da66175598 1 /**
mbed_official 237:f3da66175598 2 ******************************************************************************
mbed_official 237:f3da66175598 3 * @file stm32f3xx_hal_pwr_ex.c
mbed_official 237:f3da66175598 4 * @author MCD Application Team
mbed_official 632:7687fb9c4f91 5 * @version V1.1.1
mbed_official 632:7687fb9c4f91 6 * @date 19-June-2015
mbed_official 237:f3da66175598 7 * @brief Extended PWR HAL module driver.
mbed_official 237:f3da66175598 8 *
mbed_official 237:f3da66175598 9 * This file provides firmware functions to manage the following
mbed_official 237:f3da66175598 10 * functionalities of the Power Controller (PWR) peripheral:
mbed_official 237:f3da66175598 11 * + Extended Initialization and de-initialization functions
mbed_official 237:f3da66175598 12 * + Extended Peripheral Control functions
mbed_official 237:f3da66175598 13 *
mbed_official 237:f3da66175598 14 ******************************************************************************
mbed_official 237:f3da66175598 15 * @attention
mbed_official 237:f3da66175598 16 *
mbed_official 632:7687fb9c4f91 17 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
mbed_official 237:f3da66175598 18 *
mbed_official 237:f3da66175598 19 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 237:f3da66175598 20 * are permitted provided that the following conditions are met:
mbed_official 237:f3da66175598 21 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 237:f3da66175598 22 * this list of conditions and the following disclaimer.
mbed_official 237:f3da66175598 23 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 237:f3da66175598 24 * this list of conditions and the following disclaimer in the documentation
mbed_official 237:f3da66175598 25 * and/or other materials provided with the distribution.
mbed_official 237:f3da66175598 26 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 237:f3da66175598 27 * may be used to endorse or promote products derived from this software
mbed_official 237:f3da66175598 28 * without specific prior written permission.
mbed_official 237:f3da66175598 29 *
mbed_official 237:f3da66175598 30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 237:f3da66175598 31 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 237:f3da66175598 32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 237:f3da66175598 33 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 237:f3da66175598 34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 237:f3da66175598 35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 237:f3da66175598 36 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 237:f3da66175598 37 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 237:f3da66175598 38 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 237:f3da66175598 39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 237:f3da66175598 40 *
mbed_official 237:f3da66175598 41 ******************************************************************************
mbed_official 237:f3da66175598 42 */
mbed_official 237:f3da66175598 43
mbed_official 237:f3da66175598 44 /* Includes ------------------------------------------------------------------*/
mbed_official 237:f3da66175598 45 #include "stm32f3xx_hal.h"
mbed_official 237:f3da66175598 46
mbed_official 237:f3da66175598 47 /** @addtogroup STM32F3xx_HAL_Driver
mbed_official 237:f3da66175598 48 * @{
mbed_official 237:f3da66175598 49 */
mbed_official 237:f3da66175598 50
mbed_official 375:3d36234a1087 51 /** @defgroup PWREx PWR Extended HAL module driver
mbed_official 375:3d36234a1087 52 * @brief PWREx HAL module driver
mbed_official 237:f3da66175598 53 * @{
mbed_official 237:f3da66175598 54 */
mbed_official 237:f3da66175598 55
mbed_official 237:f3da66175598 56 #ifdef HAL_PWR_MODULE_ENABLED
mbed_official 237:f3da66175598 57
mbed_official 237:f3da66175598 58 /* Private typedef -----------------------------------------------------------*/
mbed_official 237:f3da66175598 59 /* Private define ------------------------------------------------------------*/
mbed_official 375:3d36234a1087 60 /** @defgroup PWREx_Private_Constants PWR Extended Private Constants
mbed_official 375:3d36234a1087 61 * @{
mbed_official 375:3d36234a1087 62 */
mbed_official 375:3d36234a1087 63 #define PVD_MODE_IT ((uint32_t)0x00010000)
mbed_official 375:3d36234a1087 64 #define PVD_MODE_EVT ((uint32_t)0x00020000)
mbed_official 375:3d36234a1087 65 #define PVD_RISING_EDGE ((uint32_t)0x00000001)
mbed_official 375:3d36234a1087 66 #define PVD_FALLING_EDGE ((uint32_t)0x00000002)
mbed_official 375:3d36234a1087 67 /**
mbed_official 375:3d36234a1087 68 * @}
mbed_official 375:3d36234a1087 69 */
mbed_official 375:3d36234a1087 70
mbed_official 237:f3da66175598 71 /* Private macro -------------------------------------------------------------*/
mbed_official 237:f3da66175598 72 /* Private variables ---------------------------------------------------------*/
mbed_official 237:f3da66175598 73 /* Private function prototypes -----------------------------------------------*/
mbed_official 375:3d36234a1087 74 /* Exported functions ---------------------------------------------------------*/
mbed_official 237:f3da66175598 75
mbed_official 375:3d36234a1087 76 /** @defgroup PWREx_Exported_Functions PWR Extended Exported Functions
mbed_official 237:f3da66175598 77 * @{
mbed_official 237:f3da66175598 78 */
mbed_official 237:f3da66175598 79
mbed_official 375:3d36234a1087 80 /** @defgroup PWREx_Exported_Functions_Group1 Peripheral Extended Control Functions
mbed_official 237:f3da66175598 81 * @brief Extended Peripheral Control functions
mbed_official 237:f3da66175598 82 *
mbed_official 237:f3da66175598 83 @verbatim
mbed_official 237:f3da66175598 84
mbed_official 237:f3da66175598 85 ===============================================================================
mbed_official 375:3d36234a1087 86 ##### Peripheral Extended control functions #####
mbed_official 237:f3da66175598 87 ===============================================================================
mbed_official 237:f3da66175598 88 *** PVD configuration (present on all other devices than STM32F3x8 devices) ***
mbed_official 237:f3da66175598 89 =========================
mbed_official 375:3d36234a1087 90 [..]
mbed_official 237:f3da66175598 91 (+) The PVD is used to monitor the VDD power supply by comparing it to a
mbed_official 237:f3da66175598 92 threshold selected by the PVD Level (PLS[2:0] bits in the PWR_CR).
mbed_official 237:f3da66175598 93 (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower
mbed_official 237:f3da66175598 94 than the PVD threshold. This event is internally connected to the EXTI
mbed_official 237:f3da66175598 95 line16 and can generate an interrupt if enabled. This is done through
mbed_official 237:f3da66175598 96 __HAL_PVD_EXTI_ENABLE_IT() macro
mbed_official 237:f3da66175598 97 (+) The PVD is stopped in Standby mode.
mbed_official 237:f3da66175598 98 (+) Note: PVD is not available on STM32F3x8 Product Line
mbed_official 237:f3da66175598 99
mbed_official 237:f3da66175598 100
mbed_official 237:f3da66175598 101 *** Voltage regulator ***
mbed_official 237:f3da66175598 102 =========================
mbed_official 237:f3da66175598 103 (+) The voltage regulator is always enabled after Reset. It works in three different
mbed_official 237:f3da66175598 104 modes:
mbed_official 237:f3da66175598 105 In Run mode, the regulator supplies full power to the 1.8V domain (core, memories
mbed_official 237:f3da66175598 106 and digital peripherals).
mbed_official 237:f3da66175598 107 In Stop mode, the regulator supplies low power to the 1.8V domain, preserving
mbed_official 237:f3da66175598 108 contents of registers and SRAM.
mbed_official 237:f3da66175598 109 In Stop mode, the regulator is powered off. The contents of the registers and SRAM
mbed_official 237:f3da66175598 110 are lost except for the Standby circuitry and the Backup Domain.
mbed_official 237:f3da66175598 111 Note: In the STM32F3x8xx devices, the voltage regulator is bypassed and the
mbed_official 237:f3da66175598 112 microcontroller must be powered from a nominal VDD = 1.8V +/-8% voltage.
mbed_official 237:f3da66175598 113
mbed_official 237:f3da66175598 114
mbed_official 237:f3da66175598 115 (+) A PVDO flag is available to indicate if VDD/VDDA is higher or lower
mbed_official 237:f3da66175598 116 than the PVD threshold. This event is internally connected to the EXTI
mbed_official 237:f3da66175598 117 line16 and can generate an interrupt if enabled. This is done through
mbed_official 237:f3da66175598 118 __HAL_PVD_EXTI_ENABLE_IT() macro
mbed_official 237:f3da66175598 119 (+) The PVD is stopped in Standby mode.
mbed_official 237:f3da66175598 120
mbed_official 237:f3da66175598 121
mbed_official 237:f3da66175598 122 *** SDADC power configuration ***
mbed_official 237:f3da66175598 123 ================================
mbed_official 237:f3da66175598 124 (+) On STM32F373xC/STM32F378xx devices, there are up to
mbed_official 237:f3da66175598 125 3 SDADC instances that can be enabled/disabled.
mbed_official 237:f3da66175598 126
mbed_official 237:f3da66175598 127 @endverbatim
mbed_official 237:f3da66175598 128 * @{
mbed_official 237:f3da66175598 129 */
mbed_official 237:f3da66175598 130
mbed_official 375:3d36234a1087 131 #if defined(STM32F302xE) || defined(STM32F303xE) || \
mbed_official 375:3d36234a1087 132 defined(STM32F302xC) || defined(STM32F303xC) || \
mbed_official 375:3d36234a1087 133 defined(STM32F303x8) || defined(STM32F334x8) || \
mbed_official 375:3d36234a1087 134 defined(STM32F301x8) || defined(STM32F302x8) || \
mbed_official 375:3d36234a1087 135 defined(STM32F373xC)
mbed_official 237:f3da66175598 136
mbed_official 237:f3da66175598 137 /**
mbed_official 237:f3da66175598 138 * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD).
mbed_official 237:f3da66175598 139 * @param sConfigPVD: pointer to an PWR_PVDTypeDef structure that contains the configuration
mbed_official 237:f3da66175598 140 * information for the PVD.
mbed_official 237:f3da66175598 141 * @note Refer to the electrical characteristics of your device datasheet for
mbed_official 237:f3da66175598 142 * more details about the voltage threshold corresponding to each
mbed_official 237:f3da66175598 143 * detection level.
mbed_official 237:f3da66175598 144 * @retval None
mbed_official 237:f3da66175598 145 */
mbed_official 237:f3da66175598 146 void HAL_PWR_PVDConfig(PWR_PVDTypeDef *sConfigPVD)
mbed_official 237:f3da66175598 147 {
mbed_official 237:f3da66175598 148 /* Check the parameters */
mbed_official 237:f3da66175598 149 assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel));
mbed_official 237:f3da66175598 150 assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode));
mbed_official 237:f3da66175598 151
mbed_official 237:f3da66175598 152 /* Set PLS[7:5] bits according to PVDLevel value */
mbed_official 237:f3da66175598 153 MODIFY_REG(PWR->CR, PWR_CR_PLS, sConfigPVD->PVDLevel);
mbed_official 375:3d36234a1087 154
mbed_official 375:3d36234a1087 155 /* Clear any previous config. Keep it clear if no event or IT mode is selected */
mbed_official 375:3d36234a1087 156 __HAL_PWR_PVD_EXTI_DISABLE_EVENT();
mbed_official 375:3d36234a1087 157 __HAL_PWR_PVD_EXTI_DISABLE_IT();
mbed_official 375:3d36234a1087 158 __HAL_PWR_PVD_EXTI_CLEAR_EGDE_TRIGGER();
mbed_official 237:f3da66175598 159
mbed_official 375:3d36234a1087 160 /* Configure interrupt mode */
mbed_official 375:3d36234a1087 161 if((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT)
mbed_official 237:f3da66175598 162 {
mbed_official 375:3d36234a1087 163 __HAL_PWR_PVD_EXTI_ENABLE_IT();
mbed_official 237:f3da66175598 164 }
mbed_official 375:3d36234a1087 165
mbed_official 375:3d36234a1087 166 /* Configure event mode */
mbed_official 375:3d36234a1087 167 if((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT)
mbed_official 237:f3da66175598 168 {
mbed_official 375:3d36234a1087 169 __HAL_PWR_PVD_EXTI_ENABLE_EVENT();
mbed_official 237:f3da66175598 170 }
mbed_official 375:3d36234a1087 171
mbed_official 375:3d36234a1087 172 /* Configure the edge */
mbed_official 375:3d36234a1087 173 if((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE)
mbed_official 237:f3da66175598 174 {
mbed_official 375:3d36234a1087 175 __HAL_PWR_PVD_EXTI_SET_RISING_EDGE_TRIGGER();
mbed_official 375:3d36234a1087 176 }
mbed_official 375:3d36234a1087 177
mbed_official 375:3d36234a1087 178 if((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE)
mbed_official 375:3d36234a1087 179 {
mbed_official 375:3d36234a1087 180 __HAL_PWR_PVD_EXTI_SET_FALLING_EGDE_TRIGGER();
mbed_official 237:f3da66175598 181 }
mbed_official 237:f3da66175598 182 }
mbed_official 237:f3da66175598 183
mbed_official 237:f3da66175598 184 /**
mbed_official 237:f3da66175598 185 * @brief Enables the Power Voltage Detector(PVD).
mbed_official 237:f3da66175598 186 * @retval None
mbed_official 237:f3da66175598 187 */
mbed_official 237:f3da66175598 188 void HAL_PWR_EnablePVD(void)
mbed_official 237:f3da66175598 189 {
mbed_official 237:f3da66175598 190 *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)ENABLE;
mbed_official 237:f3da66175598 191 }
mbed_official 237:f3da66175598 192
mbed_official 237:f3da66175598 193 /**
mbed_official 237:f3da66175598 194 * @brief Disables the Power Voltage Detector(PVD).
mbed_official 237:f3da66175598 195 * @retval None
mbed_official 237:f3da66175598 196 */
mbed_official 237:f3da66175598 197 void HAL_PWR_DisablePVD(void)
mbed_official 237:f3da66175598 198 {
mbed_official 237:f3da66175598 199 *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)DISABLE;
mbed_official 237:f3da66175598 200 }
mbed_official 237:f3da66175598 201
mbed_official 237:f3da66175598 202 /**
mbed_official 237:f3da66175598 203 * @brief This function handles the PWR PVD interrupt request.
mbed_official 237:f3da66175598 204 * @note This API should be called under the PVD_IRQHandler().
mbed_official 237:f3da66175598 205 * @retval None
mbed_official 237:f3da66175598 206 */
mbed_official 237:f3da66175598 207 void HAL_PWR_PVD_IRQHandler(void)
mbed_official 237:f3da66175598 208 {
mbed_official 237:f3da66175598 209 /* Check PWR exti flag */
mbed_official 375:3d36234a1087 210 if(__HAL_PWR_PVD_EXTI_GET_FLAG() != RESET)
mbed_official 237:f3da66175598 211 {
mbed_official 237:f3da66175598 212 /* PWR PVD interrupt user callback */
mbed_official 237:f3da66175598 213 HAL_PWR_PVDCallback();
mbed_official 237:f3da66175598 214
mbed_official 237:f3da66175598 215 /* Clear PWR Exti pending bit */
mbed_official 375:3d36234a1087 216 __HAL_PWR_PVD_EXTI_CLEAR_FLAG();
mbed_official 237:f3da66175598 217 }
mbed_official 237:f3da66175598 218 }
mbed_official 237:f3da66175598 219
mbed_official 237:f3da66175598 220 /**
mbed_official 237:f3da66175598 221 * @brief PWR PVD interrupt callback
mbed_official 237:f3da66175598 222 * @retval None
mbed_official 237:f3da66175598 223 */
mbed_official 237:f3da66175598 224 __weak void HAL_PWR_PVDCallback(void)
mbed_official 237:f3da66175598 225 {
mbed_official 237:f3da66175598 226 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 237:f3da66175598 227 the HAL_PWR_PVDCallback could be implemented in the user file
mbed_official 237:f3da66175598 228 */
mbed_official 237:f3da66175598 229 }
mbed_official 237:f3da66175598 230
mbed_official 375:3d36234a1087 231 #endif /* STM32F302xE || STM32F303xE || */
mbed_official 375:3d36234a1087 232 /* STM32F302xC || STM32F303xC || */
mbed_official 375:3d36234a1087 233 /* STM32F303x8 || STM32F334x8 || */
mbed_official 375:3d36234a1087 234 /* STM32F301x8 || STM32F302x8 || */
mbed_official 375:3d36234a1087 235 /* STM32F373xC */
mbed_official 237:f3da66175598 236
mbed_official 237:f3da66175598 237 #if defined(STM32F373xC) || defined(STM32F378xx)
mbed_official 237:f3da66175598 238
mbed_official 237:f3da66175598 239 /**
mbed_official 237:f3da66175598 240 * @brief Enables the SDADC peripheral functionaliy
mbed_official 237:f3da66175598 241 * @param Analogx: specifies the SDADC peripheral instance.
mbed_official 237:f3da66175598 242 * This parameter can be: PWR_SDADC_ANALOG1, PWR_SDADC_ANALOG2 or PWR_SDADC_ANALOG3.
mbed_official 237:f3da66175598 243 * @retval None
mbed_official 237:f3da66175598 244 */
mbed_official 237:f3da66175598 245 void HAL_PWREx_EnableSDADCAnalog(uint32_t Analogx)
mbed_official 237:f3da66175598 246 {
mbed_official 237:f3da66175598 247 /* Check the parameters */
mbed_official 237:f3da66175598 248 assert_param(IS_PWR_SDADC_ANALOG(Analogx));
mbed_official 237:f3da66175598 249
mbed_official 237:f3da66175598 250 /* Enable PWR clock interface for SDADC use */
mbed_official 237:f3da66175598 251 __PWR_CLK_ENABLE();
mbed_official 237:f3da66175598 252
mbed_official 237:f3da66175598 253 PWR->CR |= Analogx;
mbed_official 237:f3da66175598 254 }
mbed_official 237:f3da66175598 255
mbed_official 237:f3da66175598 256 /**
mbed_official 237:f3da66175598 257 * @brief Disables the SDADC peripheral functionaliy
mbed_official 237:f3da66175598 258 * @param Analogx: specifies the SDADC peripheral instance.
mbed_official 237:f3da66175598 259 * This parameter can be: PWR_SDADC_ANALOG1, PWR_SDADC_ANALOG2 or PWR_SDADC_ANALOG3.
mbed_official 237:f3da66175598 260 * @retval None
mbed_official 237:f3da66175598 261 */
mbed_official 237:f3da66175598 262 void HAL_PWREx_DisableSDADCAnalog(uint32_t Analogx)
mbed_official 237:f3da66175598 263 {
mbed_official 237:f3da66175598 264 /* Check the parameters */
mbed_official 237:f3da66175598 265 assert_param(IS_PWR_SDADC_ANALOG(Analogx));
mbed_official 237:f3da66175598 266
mbed_official 237:f3da66175598 267 PWR->CR &= ~Analogx;
mbed_official 237:f3da66175598 268 }
mbed_official 237:f3da66175598 269
mbed_official 237:f3da66175598 270 #endif /* STM32F373xC || STM32F378xx */
mbed_official 237:f3da66175598 271
mbed_official 237:f3da66175598 272 /**
mbed_official 237:f3da66175598 273 * @}
mbed_official 237:f3da66175598 274 */
mbed_official 237:f3da66175598 275
mbed_official 237:f3da66175598 276 /**
mbed_official 237:f3da66175598 277 * @}
mbed_official 237:f3da66175598 278 */
mbed_official 237:f3da66175598 279
mbed_official 237:f3da66175598 280 #endif /* HAL_PWR_MODULE_ENABLED */
mbed_official 237:f3da66175598 281 /**
mbed_official 237:f3da66175598 282 * @}
mbed_official 237:f3da66175598 283 */
mbed_official 237:f3da66175598 284
mbed_official 237:f3da66175598 285 /**
mbed_official 237:f3da66175598 286 * @}
mbed_official 237:f3da66175598 287 */
mbed_official 237:f3da66175598 288
mbed_official 237:f3da66175598 289 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/