mbed library sources. Supersedes mbed-src.

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

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
186:707f6e361f3e
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 144:ef7eb2e8f9f7 1 /**
<> 144:ef7eb2e8f9f7 2 ******************************************************************************
<> 144:ef7eb2e8f9f7 3 * @file stm32l0xx_hal_adc_ex.c
<> 144:ef7eb2e8f9f7 4 * @author MCD Application Team
<> 144:ef7eb2e8f9f7 5 * @brief This file provides firmware functions to manage the following
<> 144:ef7eb2e8f9f7 6 * functionalities of the Analog to Digital Convertor (ADC)
<> 144:ef7eb2e8f9f7 7 * peripheral:
Anna Bridge 186:707f6e361f3e 8 * + Operation functions
Anna Bridge 186:707f6e361f3e 9 * ++ Calibration
Anna Bridge 186:707f6e361f3e 10 * +++ ADC automatic self-calibration
Anna Bridge 186:707f6e361f3e 11 * +++ Calibration factors get or set
Anna Bridge 186:707f6e361f3e 12 * Other functions (generic functions) are available in file
Anna Bridge 186:707f6e361f3e 13 * "stm32l0xx_hal_adc.c".
Anna Bridge 186:707f6e361f3e 14 *
<> 144:ef7eb2e8f9f7 15 @verbatim
<> 144:ef7eb2e8f9f7 16 [..]
Anna Bridge 186:707f6e361f3e 17 (@) Sections "ADC peripheral features" and "How to use this driver" are
Anna Bridge 186:707f6e361f3e 18 available in file of generic functions "stm32l0xx_hal_adc.c".
Anna Bridge 186:707f6e361f3e 19 [..]
Anna Bridge 186:707f6e361f3e 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 *
Anna Bridge 186:707f6e361f3e 48 ******************************************************************************
<> 144:ef7eb2e8f9f7 49 */
<> 144:ef7eb2e8f9f7 50
<> 144:ef7eb2e8f9f7 51 /* Includes ------------------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 52 #include "stm32l0xx_hal.h"
<> 144:ef7eb2e8f9f7 53
<> 144:ef7eb2e8f9f7 54 /** @addtogroup STM32L0xx_HAL_Driver
<> 144:ef7eb2e8f9f7 55 * @{
<> 144:ef7eb2e8f9f7 56 */
<> 144:ef7eb2e8f9f7 57
Anna Bridge 186:707f6e361f3e 58 /** @defgroup ADCEx ADCEx
Anna Bridge 186:707f6e361f3e 59 * @brief ADC Extended HAL module driver
Anna Bridge 186:707f6e361f3e 60 * @{
Anna Bridge 186:707f6e361f3e 61 */
Anna Bridge 186:707f6e361f3e 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
Anna Bridge 186:707f6e361f3e 68 /** @defgroup ADCEx_Private_Constants ADC Extended Private Constants
Anna Bridge 186:707f6e361f3e 69 * @{
Anna Bridge 186:707f6e361f3e 70 */
Anna Bridge 186:707f6e361f3e 71
Anna Bridge 186:707f6e361f3e 72 /* Fixed timeout values for ADC calibration, enable settling time, disable */
<> 144:ef7eb2e8f9f7 73 /* settling time. */
<> 144:ef7eb2e8f9f7 74 /* Values defined to be higher than worst cases: low clock frequency, */
<> 144:ef7eb2e8f9f7 75 /* maximum prescaler. */
<> 144:ef7eb2e8f9f7 76 /* Unit: ms */
<> 151:5eaa88a5bcc7 77 #define ADC_CALIBRATION_TIMEOUT 10U
<> 144:ef7eb2e8f9f7 78
<> 144:ef7eb2e8f9f7 79 /* Delay for VREFINT stabilization time. */
<> 144:ef7eb2e8f9f7 80 /* Internal reference startup time max value is 3ms (refer to device datasheet, parameter TVREFINT). */
<> 144:ef7eb2e8f9f7 81 /* Unit: ms */
<> 151:5eaa88a5bcc7 82 #define SYSCFG_BUF_VREFINT_ENABLE_TIMEOUT ((uint32_t) 3U)
<> 144:ef7eb2e8f9f7 83
<> 144:ef7eb2e8f9f7 84 /* Delay for TEMPSENSOR stabilization time. */
<> 151:5eaa88a5bcc7 85 /* Temperature sensor startup time max value is 10us (refer to device datasheet, parameter tSTART). */
<> 144:ef7eb2e8f9f7 86 /* Unit: ms */
<> 151:5eaa88a5bcc7 87 #define SYSCFG_BUF_TEMPSENSOR_ENABLE_TIMEOUT ((uint32_t) 1U)
<> 144:ef7eb2e8f9f7 88
<> 144:ef7eb2e8f9f7 89 /* Private macro -------------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 90 /* Private variables ---------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 91 /* Private function prototypes -----------------------------------------------*/
Anna Bridge 186:707f6e361f3e 92 /* Exported functions --------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 93
Anna Bridge 186:707f6e361f3e 94 /** @defgroup ADCEx_Exported_Functions ADC Extended Exported Functions
Anna Bridge 186:707f6e361f3e 95 * @{
Anna Bridge 186:707f6e361f3e 96 */
Anna Bridge 186:707f6e361f3e 97
Anna Bridge 186:707f6e361f3e 98 /** @defgroup ADCEx_Exported_Functions_Group1 Extended Input and Output operation functions
Anna Bridge 186:707f6e361f3e 99 * @brief Extended IO operation functions
Anna Bridge 186:707f6e361f3e 100 *
Anna Bridge 186:707f6e361f3e 101 @verbatim
<> 144:ef7eb2e8f9f7 102 ===============================================================================
Anna Bridge 186:707f6e361f3e 103 ##### IO operation functions #####
Anna Bridge 186:707f6e361f3e 104 ===============================================================================
Anna Bridge 186:707f6e361f3e 105 [..] This section provides functions allowing to:
Anna Bridge 186:707f6e361f3e 106 (+) Perform the ADC calibration.
<> 144:ef7eb2e8f9f7 107 @endverbatim
<> 144:ef7eb2e8f9f7 108 * @{
<> 144:ef7eb2e8f9f7 109 */
<> 144:ef7eb2e8f9f7 110
<> 144:ef7eb2e8f9f7 111 /**
Anna Bridge 186:707f6e361f3e 112 * @brief Perform an ADC automatic self-calibration
Anna Bridge 186:707f6e361f3e 113 * Calibration prerequisite: ADC must be disabled (execute this
Anna Bridge 186:707f6e361f3e 114 * function before HAL_ADC_Start() or after HAL_ADC_Stop() ).
Anna Bridge 186:707f6e361f3e 115 * @note Calibration factor can be read after calibration, using function
Anna Bridge 186:707f6e361f3e 116 * HAL_ADC_GetValue() (value on 7 bits: from DR[6;0]).
Anna Bridge 186:707f6e361f3e 117 * @param hadc ADC handle
<> 144:ef7eb2e8f9f7 118 * @param SingleDiff: Selection of single-ended or differential input
<> 144:ef7eb2e8f9f7 119 * This parameter can be only of the following values:
<> 144:ef7eb2e8f9f7 120 * @arg ADC_SINGLE_ENDED: Channel in mode input single ended
<> 144:ef7eb2e8f9f7 121 * @retval HAL status
<> 144:ef7eb2e8f9f7 122 */
<> 144:ef7eb2e8f9f7 123 HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc, uint32_t SingleDiff)
<> 144:ef7eb2e8f9f7 124 {
<> 144:ef7eb2e8f9f7 125 HAL_StatusTypeDef tmp_hal_status = HAL_OK;
Anna Bridge 186:707f6e361f3e 126 uint32_t tickstart = 0U;
Anna Bridge 186:707f6e361f3e 127 uint32_t backup_setting_adc_dma_transfer = 0U; /* Note: Variable not declared as volatile because register read is already declared as volatile */
<> 144:ef7eb2e8f9f7 128
<> 144:ef7eb2e8f9f7 129 /* Check the parameters */
<> 144:ef7eb2e8f9f7 130 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
<> 144:ef7eb2e8f9f7 131
<> 144:ef7eb2e8f9f7 132 /* Process locked */
<> 144:ef7eb2e8f9f7 133 __HAL_LOCK(hadc);
<> 144:ef7eb2e8f9f7 134
<> 144:ef7eb2e8f9f7 135 /* Calibration prerequisite: ADC must be disabled. */
<> 144:ef7eb2e8f9f7 136 if (ADC_IS_ENABLE(hadc) == RESET)
<> 144:ef7eb2e8f9f7 137 {
<> 144:ef7eb2e8f9f7 138 /* Set ADC state */
<> 144:ef7eb2e8f9f7 139 ADC_STATE_CLR_SET(hadc->State,
<> 144:ef7eb2e8f9f7 140 HAL_ADC_STATE_REG_BUSY,
<> 144:ef7eb2e8f9f7 141 HAL_ADC_STATE_BUSY_INTERNAL);
<> 144:ef7eb2e8f9f7 142
Anna Bridge 186:707f6e361f3e 143 /* Disable ADC DMA transfer request during calibration */
Anna Bridge 186:707f6e361f3e 144 /* Note: Specificity of this STM32 serie: Calibration factor is */
Anna Bridge 186:707f6e361f3e 145 /* available in data register and also transfered by DMA. */
Anna Bridge 186:707f6e361f3e 146 /* To not insert ADC calibration factor among ADC conversion data */
Anna Bridge 186:707f6e361f3e 147 /* in array variable, DMA transfer must be disabled during */
Anna Bridge 186:707f6e361f3e 148 /* calibration. */
Anna Bridge 186:707f6e361f3e 149 backup_setting_adc_dma_transfer = READ_BIT(hadc->Instance->CFGR1, ADC_CFGR1_DMAEN | ADC_CFGR1_DMACFG);
Anna Bridge 186:707f6e361f3e 150 CLEAR_BIT(hadc->Instance->CFGR1, ADC_CFGR1_DMAEN | ADC_CFGR1_DMACFG);
Anna Bridge 186:707f6e361f3e 151
<> 144:ef7eb2e8f9f7 152 /* Start ADC calibration */
<> 144:ef7eb2e8f9f7 153 hadc->Instance->CR |= ADC_CR_ADCAL;
Anna Bridge 186:707f6e361f3e 154
<> 144:ef7eb2e8f9f7 155 tickstart = HAL_GetTick();
Anna Bridge 186:707f6e361f3e 156
<> 144:ef7eb2e8f9f7 157 /* Wait for calibration completion */
<> 144:ef7eb2e8f9f7 158 while(HAL_IS_BIT_SET(hadc->Instance->CR, ADC_CR_ADCAL))
<> 144:ef7eb2e8f9f7 159 {
<> 144:ef7eb2e8f9f7 160 if((HAL_GetTick() - tickstart) > ADC_CALIBRATION_TIMEOUT)
<> 144:ef7eb2e8f9f7 161 {
<> 144:ef7eb2e8f9f7 162 /* Update ADC state machine to error */
<> 144:ef7eb2e8f9f7 163 ADC_STATE_CLR_SET(hadc->State,
<> 144:ef7eb2e8f9f7 164 HAL_ADC_STATE_BUSY_INTERNAL,
<> 144:ef7eb2e8f9f7 165 HAL_ADC_STATE_ERROR_INTERNAL);
<> 144:ef7eb2e8f9f7 166
<> 144:ef7eb2e8f9f7 167 /* Process unlocked */
<> 144:ef7eb2e8f9f7 168 __HAL_UNLOCK(hadc);
<> 144:ef7eb2e8f9f7 169
<> 144:ef7eb2e8f9f7 170 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 171 }
<> 144:ef7eb2e8f9f7 172 }
<> 144:ef7eb2e8f9f7 173
Anna Bridge 186:707f6e361f3e 174 /* Restore ADC DMA transfer request after calibration */
Anna Bridge 186:707f6e361f3e 175 SET_BIT(hadc->Instance->CFGR1, backup_setting_adc_dma_transfer);
Anna Bridge 186:707f6e361f3e 176
<> 144:ef7eb2e8f9f7 177 /* Set ADC state */
<> 144:ef7eb2e8f9f7 178 ADC_STATE_CLR_SET(hadc->State,
<> 144:ef7eb2e8f9f7 179 HAL_ADC_STATE_BUSY_INTERNAL,
<> 144:ef7eb2e8f9f7 180 HAL_ADC_STATE_READY);
<> 144:ef7eb2e8f9f7 181 }
<> 144:ef7eb2e8f9f7 182 else
<> 144:ef7eb2e8f9f7 183 {
<> 144:ef7eb2e8f9f7 184 /* Update ADC state machine to error */
<> 144:ef7eb2e8f9f7 185 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
<> 144:ef7eb2e8f9f7 186
<> 144:ef7eb2e8f9f7 187 tmp_hal_status = HAL_ERROR;
<> 144:ef7eb2e8f9f7 188 }
<> 144:ef7eb2e8f9f7 189
<> 144:ef7eb2e8f9f7 190 /* Process unlocked */
<> 144:ef7eb2e8f9f7 191 __HAL_UNLOCK(hadc);
<> 144:ef7eb2e8f9f7 192
<> 144:ef7eb2e8f9f7 193 /* Return function status */
<> 144:ef7eb2e8f9f7 194 return tmp_hal_status;
<> 144:ef7eb2e8f9f7 195 }
<> 144:ef7eb2e8f9f7 196
<> 144:ef7eb2e8f9f7 197 /**
<> 144:ef7eb2e8f9f7 198 * @brief Get the calibration factor.
<> 144:ef7eb2e8f9f7 199 * @param hadc: ADC handle.
<> 144:ef7eb2e8f9f7 200 * @param SingleDiff: This parameter can be only:
<> 144:ef7eb2e8f9f7 201 * @arg ADC_SINGLE_ENDED: Channel in mode input single ended.
<> 144:ef7eb2e8f9f7 202 * @retval Calibration value.
<> 144:ef7eb2e8f9f7 203 */
<> 144:ef7eb2e8f9f7 204 uint32_t HAL_ADCEx_Calibration_GetValue(ADC_HandleTypeDef* hadc, uint32_t SingleDiff)
<> 144:ef7eb2e8f9f7 205 {
<> 144:ef7eb2e8f9f7 206 /* Check the parameters */
<> 144:ef7eb2e8f9f7 207 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
<> 144:ef7eb2e8f9f7 208 assert_param(IS_ADC_SINGLE_DIFFERENTIAL(SingleDiff));
<> 144:ef7eb2e8f9f7 209
<> 144:ef7eb2e8f9f7 210 /* Return the ADC calibration value */
<> 151:5eaa88a5bcc7 211 return ((hadc->Instance->CALFACT) & 0x0000007FU);
<> 144:ef7eb2e8f9f7 212 }
<> 144:ef7eb2e8f9f7 213
<> 144:ef7eb2e8f9f7 214 /**
<> 144:ef7eb2e8f9f7 215 * @brief Set the calibration factor to overwrite automatic conversion result.
<> 144:ef7eb2e8f9f7 216 * ADC must be enabled and no conversion is ongoing.
<> 144:ef7eb2e8f9f7 217 * @param hadc: ADC handle
<> 144:ef7eb2e8f9f7 218 * @param SingleDiff: This parameter can be only:
<> 144:ef7eb2e8f9f7 219 * @arg ADC_SINGLE_ENDED: Channel in mode input single ended.
<> 144:ef7eb2e8f9f7 220 * @param CalibrationFactor: Calibration factor (coded on 7 bits maximum)
<> 144:ef7eb2e8f9f7 221 * @retval HAL state
<> 144:ef7eb2e8f9f7 222 */
<> 144:ef7eb2e8f9f7 223 HAL_StatusTypeDef HAL_ADCEx_Calibration_SetValue(ADC_HandleTypeDef* hadc, uint32_t SingleDiff, uint32_t CalibrationFactor)
<> 144:ef7eb2e8f9f7 224 {
<> 144:ef7eb2e8f9f7 225 HAL_StatusTypeDef tmp_hal_status = HAL_OK;
<> 144:ef7eb2e8f9f7 226
<> 144:ef7eb2e8f9f7 227 /* Check the parameters */
<> 144:ef7eb2e8f9f7 228 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
<> 144:ef7eb2e8f9f7 229 assert_param(IS_ADC_SINGLE_DIFFERENTIAL(SingleDiff));
<> 144:ef7eb2e8f9f7 230 assert_param(IS_ADC_CALFACT(CalibrationFactor));
<> 144:ef7eb2e8f9f7 231
<> 144:ef7eb2e8f9f7 232 /* Process locked */
<> 144:ef7eb2e8f9f7 233 __HAL_LOCK(hadc);
<> 144:ef7eb2e8f9f7 234
<> 144:ef7eb2e8f9f7 235 /* Verification of hardware constraints before modifying the calibration */
<> 144:ef7eb2e8f9f7 236 /* factors register: ADC must be enabled, no conversion on going. */
<> 144:ef7eb2e8f9f7 237 if ( (ADC_IS_ENABLE(hadc) != RESET) &&
<> 144:ef7eb2e8f9f7 238 (ADC_IS_CONVERSION_ONGOING_REGULAR(hadc) == RESET) )
<> 144:ef7eb2e8f9f7 239 {
<> 144:ef7eb2e8f9f7 240 /* Set the selected ADC calibration value */
<> 144:ef7eb2e8f9f7 241 hadc->Instance->CALFACT &= ~ADC_CALFACT_CALFACT;
<> 144:ef7eb2e8f9f7 242 hadc->Instance->CALFACT |= CalibrationFactor;
<> 144:ef7eb2e8f9f7 243 }
<> 144:ef7eb2e8f9f7 244 else
<> 144:ef7eb2e8f9f7 245 {
<> 144:ef7eb2e8f9f7 246 /* Update ADC state machine to error */
<> 144:ef7eb2e8f9f7 247 SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
<> 144:ef7eb2e8f9f7 248 /* Update ADC state machine to error */
<> 144:ef7eb2e8f9f7 249 SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL);
<> 144:ef7eb2e8f9f7 250
<> 144:ef7eb2e8f9f7 251 /* Update ADC state machine to error */
<> 144:ef7eb2e8f9f7 252 tmp_hal_status = HAL_ERROR;
<> 144:ef7eb2e8f9f7 253 }
<> 144:ef7eb2e8f9f7 254
<> 144:ef7eb2e8f9f7 255 /* Process unlocked */
<> 144:ef7eb2e8f9f7 256 __HAL_UNLOCK(hadc);
<> 144:ef7eb2e8f9f7 257
<> 144:ef7eb2e8f9f7 258 /* Return function status */
<> 144:ef7eb2e8f9f7 259 return tmp_hal_status;
<> 144:ef7eb2e8f9f7 260 }
<> 144:ef7eb2e8f9f7 261
<> 144:ef7eb2e8f9f7 262 /**
<> 144:ef7eb2e8f9f7 263 * @brief Enables the buffer of Vrefint for the ADC, required when device is in mode low-power (low-power run, low-power sleep or stop mode)
<> 144:ef7eb2e8f9f7 264 * This function must be called before function HAL_ADC_Init()
<> 144:ef7eb2e8f9f7 265 * (in case of previous ADC operations: function HAL_ADC_DeInit() must be called first)
<> 144:ef7eb2e8f9f7 266 * For more details on procedure and buffer current consumption, refer to device reference manual.
<> 144:ef7eb2e8f9f7 267 * @note This is functional only if the LOCK is not set.
<> 144:ef7eb2e8f9f7 268 * @retval None
<> 144:ef7eb2e8f9f7 269 */
<> 144:ef7eb2e8f9f7 270 HAL_StatusTypeDef HAL_ADCEx_EnableVREFINT(void)
<> 144:ef7eb2e8f9f7 271 {
<> 151:5eaa88a5bcc7 272 uint32_t tickstart = 0U;
<> 144:ef7eb2e8f9f7 273
<> 151:5eaa88a5bcc7 274 /* Enable the Buffer for the ADC by setting ENBUF_SENSOR_ADC bit in the CFGR3 register */
<> 151:5eaa88a5bcc7 275 SET_BIT(SYSCFG->CFGR3, SYSCFG_CFGR3_ENBUF_VREFINT_ADC);
<> 144:ef7eb2e8f9f7 276
<> 144:ef7eb2e8f9f7 277 /* Wait for Vrefint buffer effectively enabled */
<> 144:ef7eb2e8f9f7 278 /* Get tick count */
<> 144:ef7eb2e8f9f7 279 tickstart = HAL_GetTick();
<> 144:ef7eb2e8f9f7 280
<> 151:5eaa88a5bcc7 281 while(HAL_IS_BIT_CLR(SYSCFG->CFGR3, SYSCFG_CFGR3_VREFINT_RDYF))
<> 144:ef7eb2e8f9f7 282 {
<> 144:ef7eb2e8f9f7 283 if((HAL_GetTick() - tickstart) > SYSCFG_BUF_VREFINT_ENABLE_TIMEOUT)
<> 144:ef7eb2e8f9f7 284 {
<> 144:ef7eb2e8f9f7 285 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 286 }
<> 144:ef7eb2e8f9f7 287 }
<> 144:ef7eb2e8f9f7 288
<> 144:ef7eb2e8f9f7 289 return HAL_OK;
<> 144:ef7eb2e8f9f7 290 }
<> 144:ef7eb2e8f9f7 291
<> 144:ef7eb2e8f9f7 292 /**
<> 144:ef7eb2e8f9f7 293 * @brief Disables the Buffer Vrefint for the ADC.
<> 144:ef7eb2e8f9f7 294 * @note This is functional only if the LOCK is not set.
<> 144:ef7eb2e8f9f7 295 * @retval None
<> 144:ef7eb2e8f9f7 296 */
<> 144:ef7eb2e8f9f7 297 void HAL_ADCEx_DisableVREFINT(void)
<> 144:ef7eb2e8f9f7 298 {
<> 151:5eaa88a5bcc7 299 /* Disable the Vrefint by resetting ENBUF_SENSOR_ADC bit in the CFGR3 register */
<> 151:5eaa88a5bcc7 300 CLEAR_BIT(SYSCFG->CFGR3, SYSCFG_CFGR3_ENBUF_VREFINT_ADC);
<> 144:ef7eb2e8f9f7 301 }
<> 144:ef7eb2e8f9f7 302
<> 144:ef7eb2e8f9f7 303 /**
<> 144:ef7eb2e8f9f7 304 * @brief Enables the buffer of temperature sensor for the ADC, required when device is in mode low-power (low-power run, low-power sleep or stop mode)
<> 144:ef7eb2e8f9f7 305 * This function must be called before function HAL_ADC_Init()
<> 144:ef7eb2e8f9f7 306 * (in case of previous ADC operations: function HAL_ADC_DeInit() must be called first)
<> 144:ef7eb2e8f9f7 307 * For more details on procedure and buffer current consumption, refer to device reference manual.
<> 144:ef7eb2e8f9f7 308 * @note This is functional only if the LOCK is not set.
<> 144:ef7eb2e8f9f7 309 * @retval None
<> 144:ef7eb2e8f9f7 310 */
<> 144:ef7eb2e8f9f7 311 HAL_StatusTypeDef HAL_ADCEx_EnableVREFINTTempSensor(void)
<> 144:ef7eb2e8f9f7 312 {
<> 151:5eaa88a5bcc7 313 uint32_t tickstart = 0U;
<> 144:ef7eb2e8f9f7 314
<> 151:5eaa88a5bcc7 315 /* Enable the Buffer for the ADC by setting ENBUF_SENSOR_ADC bit in the CFGR3 register */
<> 151:5eaa88a5bcc7 316 SET_BIT(SYSCFG->CFGR3, SYSCFG_CFGR3_ENBUF_SENSOR_ADC);
<> 144:ef7eb2e8f9f7 317
<> 144:ef7eb2e8f9f7 318 /* Wait for Vrefint buffer effectively enabled */
<> 144:ef7eb2e8f9f7 319 /* Get tick count */
<> 144:ef7eb2e8f9f7 320 tickstart = HAL_GetTick();
<> 144:ef7eb2e8f9f7 321
<> 151:5eaa88a5bcc7 322 while(HAL_IS_BIT_CLR(SYSCFG->CFGR3, SYSCFG_CFGR3_VREFINT_RDYF))
<> 144:ef7eb2e8f9f7 323 {
<> 144:ef7eb2e8f9f7 324 if((HAL_GetTick() - tickstart) > SYSCFG_BUF_TEMPSENSOR_ENABLE_TIMEOUT)
<> 144:ef7eb2e8f9f7 325 {
<> 144:ef7eb2e8f9f7 326 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 327 }
<> 144:ef7eb2e8f9f7 328 }
<> 144:ef7eb2e8f9f7 329
<> 144:ef7eb2e8f9f7 330 return HAL_OK;
<> 144:ef7eb2e8f9f7 331 }
<> 144:ef7eb2e8f9f7 332
<> 144:ef7eb2e8f9f7 333 /**
<> 151:5eaa88a5bcc7 334 * @brief Disables the VREFINT and Sensor for the ADC.
<> 144:ef7eb2e8f9f7 335 * @note This is functional only if the LOCK is not set.
<> 144:ef7eb2e8f9f7 336 * @retval None
<> 144:ef7eb2e8f9f7 337 */
<> 144:ef7eb2e8f9f7 338 void HAL_ADCEx_DisableVREFINTTempSensor(void)
<> 144:ef7eb2e8f9f7 339 {
<> 151:5eaa88a5bcc7 340 /* Disable the Vrefint by resetting ENBUF_SENSOR_ADC bit in the CFGR3 register */
<> 151:5eaa88a5bcc7 341 CLEAR_BIT(SYSCFG->CFGR3, SYSCFG_CFGR3_ENBUF_SENSOR_ADC);
<> 144:ef7eb2e8f9f7 342 }
<> 144:ef7eb2e8f9f7 343
<> 144:ef7eb2e8f9f7 344 /**
<> 144:ef7eb2e8f9f7 345 * @}
<> 144:ef7eb2e8f9f7 346 */
<> 144:ef7eb2e8f9f7 347
<> 144:ef7eb2e8f9f7 348 /**
<> 144:ef7eb2e8f9f7 349 * @}
<> 144:ef7eb2e8f9f7 350 */
<> 144:ef7eb2e8f9f7 351
Anna Bridge 186:707f6e361f3e 352 #endif /* HAL_ADC_MODULE_ENABLED */
<> 144:ef7eb2e8f9f7 353 /**
<> 144:ef7eb2e8f9f7 354 * @}
<> 144:ef7eb2e8f9f7 355 */
<> 144:ef7eb2e8f9f7 356
<> 144:ef7eb2e8f9f7 357 /**
<> 144:ef7eb2e8f9f7 358 * @}
Anna Bridge 186:707f6e361f3e 359 */
<> 144:ef7eb2e8f9f7 360
<> 144:ef7eb2e8f9f7 361 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/