mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
<>
Date:
Mon Jan 16 15:03:32 2017 +0000
Revision:
156:95d6b41a828b
Parent:
149:156823d33999
Child:
180:96ed750bd169
This updates the lib to the mbed lib v134

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 144:ef7eb2e8f9f7 1 /**
<> 144:ef7eb2e8f9f7 2 ******************************************************************************
<> 144:ef7eb2e8f9f7 3 * @file stm32f0xx_hal_adc_ex.c
<> 144:ef7eb2e8f9f7 4 * @author MCD Application Team
<> 156:95d6b41a828b 5 * @version V1.5.0
<> 156:95d6b41a828b 6 * @date 04-November-2016
<> 144:ef7eb2e8f9f7 7 * @brief This file provides firmware functions to manage the following
<> 144:ef7eb2e8f9f7 8 * functionalities of the Analog to Digital Convertor (ADC)
<> 144:ef7eb2e8f9f7 9 * peripheral:
<> 144:ef7eb2e8f9f7 10 * + Operation functions
<> 144:ef7eb2e8f9f7 11 * ++ Calibration (ADC automatic self-calibration)
<> 144:ef7eb2e8f9f7 12 * Other functions (generic functions) are available in file
<> 144:ef7eb2e8f9f7 13 * "stm32l1xx_hal_adc.c".
<> 144:ef7eb2e8f9f7 14 *
<> 144:ef7eb2e8f9f7 15 @verbatim
<> 144:ef7eb2e8f9f7 16 [..]
<> 144:ef7eb2e8f9f7 17 (@) Sections "ADC peripheral features" and "How to use this driver" are
<> 144:ef7eb2e8f9f7 18 available in file of generic functions "stm32l1xx_hal_adc.c".
<> 144:ef7eb2e8f9f7 19 [..]
<> 144:ef7eb2e8f9f7 20 @endverbatim
<> 144:ef7eb2e8f9f7 21 ******************************************************************************
<> 144:ef7eb2e8f9f7 22 * @attention
<> 144:ef7eb2e8f9f7 23 *
<> 144:ef7eb2e8f9f7 24 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
<> 144:ef7eb2e8f9f7 25 *
<> 144:ef7eb2e8f9f7 26 * Redistribution and use in source and binary forms, with or without modification,
<> 144:ef7eb2e8f9f7 27 * are permitted provided that the following conditions are met:
<> 144:ef7eb2e8f9f7 28 * 1. Redistributions of source code must retain the above copyright notice,
<> 144:ef7eb2e8f9f7 29 * this list of conditions and the following disclaimer.
<> 144:ef7eb2e8f9f7 30 * 2. Redistributions in binary form must reproduce the above copyright notice,
<> 144:ef7eb2e8f9f7 31 * this list of conditions and the following disclaimer in the documentation
<> 144:ef7eb2e8f9f7 32 * and/or other materials provided with the distribution.
<> 144:ef7eb2e8f9f7 33 * 3. Neither the name of STMicroelectronics nor the names of its contributors
<> 144:ef7eb2e8f9f7 34 * may be used to endorse or promote products derived from this software
<> 144:ef7eb2e8f9f7 35 * without specific prior written permission.
<> 144:ef7eb2e8f9f7 36 *
<> 144:ef7eb2e8f9f7 37 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
<> 144:ef7eb2e8f9f7 38 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
<> 144:ef7eb2e8f9f7 39 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
<> 144:ef7eb2e8f9f7 40 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
<> 144:ef7eb2e8f9f7 41 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
<> 144:ef7eb2e8f9f7 42 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
<> 144:ef7eb2e8f9f7 43 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
<> 144:ef7eb2e8f9f7 44 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
<> 144:ef7eb2e8f9f7 45 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
<> 144:ef7eb2e8f9f7 46 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<> 144:ef7eb2e8f9f7 47 *
<> 144:ef7eb2e8f9f7 48 ******************************************************************************
<> 144:ef7eb2e8f9f7 49 */
<> 144:ef7eb2e8f9f7 50
<> 144:ef7eb2e8f9f7 51 /* Includes ------------------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 52 #include "stm32f0xx_hal.h"
<> 144:ef7eb2e8f9f7 53
<> 144:ef7eb2e8f9f7 54 /** @addtogroup STM32F0xx_HAL_Driver
<> 144:ef7eb2e8f9f7 55 * @{
<> 144:ef7eb2e8f9f7 56 */
<> 144:ef7eb2e8f9f7 57
<> 144:ef7eb2e8f9f7 58 /** @defgroup ADCEx ADCEx
<> 144:ef7eb2e8f9f7 59 * @brief ADC HAL module driver
<> 144:ef7eb2e8f9f7 60 * @{
<> 144:ef7eb2e8f9f7 61 */
<> 144:ef7eb2e8f9f7 62
<> 144:ef7eb2e8f9f7 63 #ifdef HAL_ADC_MODULE_ENABLED
<> 144:ef7eb2e8f9f7 64
<> 144:ef7eb2e8f9f7 65 /* Private typedef -----------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 66 /* Private define ------------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 67 /** @defgroup ADCEx_Private_Constants ADCEx Private Constants
<> 144:ef7eb2e8f9f7 68 * @{
<> 144:ef7eb2e8f9f7 69 */
<> 144:ef7eb2e8f9f7 70
<> 144:ef7eb2e8f9f7 71 /* Fixed timeout values for ADC calibration, enable settling time, disable */
<> 144:ef7eb2e8f9f7 72 /* settling time. */
<> 144:ef7eb2e8f9f7 73 /* Values defined to be higher than worst cases: low clock frequency, */
<> 144:ef7eb2e8f9f7 74 /* maximum prescaler. */
<> 144:ef7eb2e8f9f7 75 /* Ex of profile low frequency : Clock source at 0.1 MHz, ADC clock */
<> 144:ef7eb2e8f9f7 76 /* prescaler 4. */
<> 144:ef7eb2e8f9f7 77 /* Unit: ms */
<> 144:ef7eb2e8f9f7 78 #define ADC_DISABLE_TIMEOUT 2
<> 156:95d6b41a828b 79 #define ADC_CALIBRATION_TIMEOUT 2U
<> 144:ef7eb2e8f9f7 80 /**
<> 144:ef7eb2e8f9f7 81 * @}
<> 144:ef7eb2e8f9f7 82 */
<> 144:ef7eb2e8f9f7 83
<> 144:ef7eb2e8f9f7 84 /* Private macros -------------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 85 /* Private variables ---------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 86 /* Private function prototypes -----------------------------------------------*/
<> 144:ef7eb2e8f9f7 87 /* Private functions ---------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 88
<> 144:ef7eb2e8f9f7 89 /** @defgroup ADCEx_Exported_Functions ADCEx Exported Functions
<> 144:ef7eb2e8f9f7 90 * @{
<> 144:ef7eb2e8f9f7 91 */
<> 144:ef7eb2e8f9f7 92
<> 144:ef7eb2e8f9f7 93 /** @defgroup ADCEx_Exported_Functions_Group1 Extended Initialization/de-initialization functions
<> 144:ef7eb2e8f9f7 94 * @brief Extended Initialization and Configuration functions
<> 144:ef7eb2e8f9f7 95 *
<> 144:ef7eb2e8f9f7 96 @verbatim
<> 144:ef7eb2e8f9f7 97 ===============================================================================
<> 144:ef7eb2e8f9f7 98 ##### IO operation functions #####
<> 144:ef7eb2e8f9f7 99 ===============================================================================
<> 144:ef7eb2e8f9f7 100 [..] This section provides functions allowing to:
<> 144:ef7eb2e8f9f7 101 (+) Perform the ADC calibration.
<> 144:ef7eb2e8f9f7 102 @endverbatim
<> 144:ef7eb2e8f9f7 103 * @{
<> 144:ef7eb2e8f9f7 104 */
<> 144:ef7eb2e8f9f7 105
<> 144:ef7eb2e8f9f7 106 /**
<> 144:ef7eb2e8f9f7 107 * @brief Perform an ADC automatic self-calibration
<> 144:ef7eb2e8f9f7 108 * Calibration prerequisite: ADC must be disabled (execute this
<> 144:ef7eb2e8f9f7 109 * function before HAL_ADC_Start() or after HAL_ADC_Stop() ).
<> 144:ef7eb2e8f9f7 110 * @note Calibration factor can be read after calibration, using function
<> 144:ef7eb2e8f9f7 111 * HAL_ADC_GetValue() (value on 7 bits: from DR[6;0]).
<> 144:ef7eb2e8f9f7 112 * @param hadc: ADC handle
<> 144:ef7eb2e8f9f7 113 * @retval HAL status
<> 144:ef7eb2e8f9f7 114 */
<> 144:ef7eb2e8f9f7 115 HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc)
<> 144:ef7eb2e8f9f7 116 {
<> 144:ef7eb2e8f9f7 117 HAL_StatusTypeDef tmp_hal_status = HAL_OK;
<> 156:95d6b41a828b 118 uint32_t tickstart=0U;
<> 144:ef7eb2e8f9f7 119
<> 144:ef7eb2e8f9f7 120 /* Check the parameters */
<> 144:ef7eb2e8f9f7 121 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
<> 144:ef7eb2e8f9f7 122
<> 144:ef7eb2e8f9f7 123 /* Process locked */
<> 144:ef7eb2e8f9f7 124 __HAL_LOCK(hadc);
<> 144:ef7eb2e8f9f7 125
<> 144:ef7eb2e8f9f7 126 /* Calibration prerequisite: ADC must be disabled. */
<> 144:ef7eb2e8f9f7 127 if (ADC_IS_ENABLE(hadc) == RESET)
<> 144:ef7eb2e8f9f7 128 {
<> 144:ef7eb2e8f9f7 129 /* Set ADC state */
<> 144:ef7eb2e8f9f7 130 ADC_STATE_CLR_SET(hadc->State,
<> 144:ef7eb2e8f9f7 131 HAL_ADC_STATE_REG_BUSY,
<> 144:ef7eb2e8f9f7 132 HAL_ADC_STATE_BUSY_INTERNAL);
<> 144:ef7eb2e8f9f7 133
<> 144:ef7eb2e8f9f7 134 /* Start ADC calibration */
<> 144:ef7eb2e8f9f7 135 hadc->Instance->CR |= ADC_CR_ADCAL;
<> 144:ef7eb2e8f9f7 136
<> 144:ef7eb2e8f9f7 137 tickstart = HAL_GetTick();
<> 144:ef7eb2e8f9f7 138
<> 144:ef7eb2e8f9f7 139 /* Wait for calibration completion */
<> 144:ef7eb2e8f9f7 140 while(HAL_IS_BIT_SET(hadc->Instance->CR, ADC_CR_ADCAL))
<> 144:ef7eb2e8f9f7 141 {
<> 144:ef7eb2e8f9f7 142 if((HAL_GetTick() - tickstart) > ADC_CALIBRATION_TIMEOUT)
<> 144:ef7eb2e8f9f7 143 {
<> 144:ef7eb2e8f9f7 144 /* Update ADC state machine to error */
<> 144:ef7eb2e8f9f7 145 ADC_STATE_CLR_SET(hadc->State,
<> 144:ef7eb2e8f9f7 146 HAL_ADC_STATE_BUSY_INTERNAL,
<> 144:ef7eb2e8f9f7 147 HAL_ADC_STATE_ERROR_INTERNAL);
<> 144:ef7eb2e8f9f7 148
<> 144:ef7eb2e8f9f7 149 /* Process unlocked */
<> 144:ef7eb2e8f9f7 150 __HAL_UNLOCK(hadc);
<> 144:ef7eb2e8f9f7 151
<> 144:ef7eb2e8f9f7 152 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 153 }
<> 144:ef7eb2e8f9f7 154 }
<> 144:ef7eb2e8f9f7 155
<> 144:ef7eb2e8f9f7 156 /* Set ADC state */
<> 144:ef7eb2e8f9f7 157 ADC_STATE_CLR_SET(hadc->State,
<> 144:ef7eb2e8f9f7 158 HAL_ADC_STATE_BUSY_INTERNAL,
<> 144:ef7eb2e8f9f7 159 HAL_ADC_STATE_READY);
<> 144:ef7eb2e8f9f7 160 }
<> 144:ef7eb2e8f9f7 161 else
<> 144:ef7eb2e8f9f7 162 {
<> 144:ef7eb2e8f9f7 163 /* Update ADC state machine to error */
<> 144:ef7eb2e8f9f7 164 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
<> 144:ef7eb2e8f9f7 165
<> 144:ef7eb2e8f9f7 166 tmp_hal_status = HAL_ERROR;
<> 144:ef7eb2e8f9f7 167 }
<> 144:ef7eb2e8f9f7 168
<> 144:ef7eb2e8f9f7 169 /* Process unlocked */
<> 144:ef7eb2e8f9f7 170 __HAL_UNLOCK(hadc);
<> 144:ef7eb2e8f9f7 171
<> 144:ef7eb2e8f9f7 172 /* Return function status */
<> 144:ef7eb2e8f9f7 173 return tmp_hal_status;
<> 144:ef7eb2e8f9f7 174 }
<> 144:ef7eb2e8f9f7 175
<> 144:ef7eb2e8f9f7 176 /**
<> 144:ef7eb2e8f9f7 177 * @}
<> 144:ef7eb2e8f9f7 178 */
<> 144:ef7eb2e8f9f7 179
<> 144:ef7eb2e8f9f7 180 /**
<> 144:ef7eb2e8f9f7 181 * @}
<> 144:ef7eb2e8f9f7 182 */
<> 144:ef7eb2e8f9f7 183
<> 144:ef7eb2e8f9f7 184 #endif /* HAL_ADC_MODULE_ENABLED */
<> 144:ef7eb2e8f9f7 185 /**
<> 144:ef7eb2e8f9f7 186 * @}
<> 144:ef7eb2e8f9f7 187 */
<> 144:ef7eb2e8f9f7 188
<> 144:ef7eb2e8f9f7 189 /**
<> 144:ef7eb2e8f9f7 190 * @}
<> 144:ef7eb2e8f9f7 191 */
<> 144:ef7eb2e8f9f7 192
<> 144:ef7eb2e8f9f7 193 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/