mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Jul 02 16:30:08 2015 +0100
Revision:
581:39197bcd20f2
Parent:
489:119543c9f674
Synchronized with git revision ae2d3cdffe70184eb8736d94f76c45c93f4b7724

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

Make it possible to build the core mbed library with yotta

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 489:119543c9f674 1 /**
mbed_official 489:119543c9f674 2 ******************************************************************************
mbed_official 489:119543c9f674 3 * @file stm32f1xx_hal_adc_ex.c
mbed_official 489:119543c9f674 4 * @author MCD Application Team
mbed_official 489:119543c9f674 5 * @version V1.0.0
mbed_official 489:119543c9f674 6 * @date 15-December-2014
mbed_official 489:119543c9f674 7 * @brief This file provides firmware functions to manage the following
mbed_official 489:119543c9f674 8 * functionalities of the Analog to Digital Convertor (ADC)
mbed_official 489:119543c9f674 9 * peripheral:
mbed_official 489:119543c9f674 10 * + Operation functions
mbed_official 489:119543c9f674 11 * ++ Start, stop, get result of conversions of injected
mbed_official 489:119543c9f674 12 * group, using 2 possible modes: polling, interruption.
mbed_official 489:119543c9f674 13 * ++ Multimode feature (available on devices with 2 ADCs or more)
mbed_official 489:119543c9f674 14 * ++ Calibration (ADC automatic self-calibration)
mbed_official 489:119543c9f674 15 * + Control functions
mbed_official 489:119543c9f674 16 * ++ Channels configuration on injected group
mbed_official 489:119543c9f674 17 * Other functions (generic functions) are available in file
mbed_official 489:119543c9f674 18 * "stm32f1xx_hal_adc.c".
mbed_official 489:119543c9f674 19 *
mbed_official 489:119543c9f674 20 @verbatim
mbed_official 489:119543c9f674 21 [..]
mbed_official 489:119543c9f674 22 (@) Sections "ADC peripheral features" and "How to use this driver" are
mbed_official 489:119543c9f674 23 available in file of generic functions "stm32f1xx_hal_adc.c".
mbed_official 489:119543c9f674 24 [..]
mbed_official 489:119543c9f674 25 @endverbatim
mbed_official 489:119543c9f674 26 ******************************************************************************
mbed_official 489:119543c9f674 27 * @attention
mbed_official 489:119543c9f674 28 *
mbed_official 489:119543c9f674 29 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 489:119543c9f674 30 *
mbed_official 489:119543c9f674 31 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 489:119543c9f674 32 * are permitted provided that the following conditions are met:
mbed_official 489:119543c9f674 33 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 489:119543c9f674 34 * this list of conditions and the following disclaimer.
mbed_official 489:119543c9f674 35 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 489:119543c9f674 36 * this list of conditions and the following disclaimer in the documentation
mbed_official 489:119543c9f674 37 * and/or other materials provided with the distribution.
mbed_official 489:119543c9f674 38 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 489:119543c9f674 39 * may be used to endorse or promote products derived from this software
mbed_official 489:119543c9f674 40 * without specific prior written permission.
mbed_official 489:119543c9f674 41 *
mbed_official 489:119543c9f674 42 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 489:119543c9f674 43 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 489:119543c9f674 44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 489:119543c9f674 45 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 489:119543c9f674 46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 489:119543c9f674 47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 489:119543c9f674 48 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 489:119543c9f674 49 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 489:119543c9f674 50 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 489:119543c9f674 51 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 489:119543c9f674 52 *
mbed_official 489:119543c9f674 53 ******************************************************************************
mbed_official 489:119543c9f674 54 */
mbed_official 489:119543c9f674 55
mbed_official 489:119543c9f674 56 /* Includes ------------------------------------------------------------------*/
mbed_official 489:119543c9f674 57 #include "stm32f1xx_hal.h"
mbed_official 489:119543c9f674 58
mbed_official 489:119543c9f674 59 /** @addtogroup STM32F1xx_HAL_Driver
mbed_official 489:119543c9f674 60 * @{
mbed_official 489:119543c9f674 61 */
mbed_official 489:119543c9f674 62
mbed_official 489:119543c9f674 63 /** @defgroup ADCEx ADCEx
mbed_official 489:119543c9f674 64 * @brief ADC Extension HAL module driver
mbed_official 489:119543c9f674 65 * @{
mbed_official 489:119543c9f674 66 */
mbed_official 489:119543c9f674 67
mbed_official 489:119543c9f674 68 #ifdef HAL_ADC_MODULE_ENABLED
mbed_official 489:119543c9f674 69
mbed_official 489:119543c9f674 70 /* Private typedef -----------------------------------------------------------*/
mbed_official 489:119543c9f674 71 /* Private define ------------------------------------------------------------*/
mbed_official 489:119543c9f674 72 /** @defgroup ADCEx_Private_Constants ADCEx Private Constants
mbed_official 489:119543c9f674 73 * @{
mbed_official 489:119543c9f674 74 */
mbed_official 489:119543c9f674 75
mbed_official 489:119543c9f674 76 /* Delay for ADC calibration: */
mbed_official 489:119543c9f674 77 /* Hardware prerequisite before starting a calibration: the ADC must have */
mbed_official 489:119543c9f674 78 /* been in power-on state for at least two ADC clock cycles. */
mbed_official 489:119543c9f674 79 /* Unit: ADC clock cycles */
mbed_official 489:119543c9f674 80 #define ADC_PRECALIBRATION_DELAY_ADCCLOCKCYCLES ((uint32_t) 2)
mbed_official 489:119543c9f674 81
mbed_official 489:119543c9f674 82 /* Timeout value for ADC calibration */
mbed_official 489:119543c9f674 83 /* Value defined to be higher than worst cases: low clocks freq, */
mbed_official 489:119543c9f674 84 /* maximum prescaler. */
mbed_official 489:119543c9f674 85 /* Ex of profile low frequency : Clock source at 0.1 MHz, ADC clock */
mbed_official 489:119543c9f674 86 /* prescaler 4, sampling time 12.5 ADC clock cycles, resolution 12 bits. */
mbed_official 489:119543c9f674 87 /* Unit: ms */
mbed_official 489:119543c9f674 88 #define ADC_CALIBRATION_TIMEOUT ((uint32_t) 10)
mbed_official 489:119543c9f674 89
mbed_official 489:119543c9f674 90 /* Delay for temperature sensor stabilization time. */
mbed_official 489:119543c9f674 91 /* Maximum delay is 10us (refer to device datasheet, parameter tSTART). */
mbed_official 489:119543c9f674 92 /* Unit: us */
mbed_official 489:119543c9f674 93 #define ADC_TEMPSENSOR_DELAY_US ((uint32_t) 10)
mbed_official 489:119543c9f674 94
mbed_official 489:119543c9f674 95 /**
mbed_official 489:119543c9f674 96 * @}
mbed_official 489:119543c9f674 97 */
mbed_official 489:119543c9f674 98
mbed_official 489:119543c9f674 99 /* Private macro -------------------------------------------------------------*/
mbed_official 489:119543c9f674 100 /* Private variables ---------------------------------------------------------*/
mbed_official 489:119543c9f674 101 /* Private function prototypes -----------------------------------------------*/
mbed_official 489:119543c9f674 102 /* Private functions ---------------------------------------------------------*/
mbed_official 489:119543c9f674 103
mbed_official 489:119543c9f674 104 /** @defgroup ADCEx_Exported_Functions ADCEx Exported Functions
mbed_official 489:119543c9f674 105 * @{
mbed_official 489:119543c9f674 106 */
mbed_official 489:119543c9f674 107
mbed_official 489:119543c9f674 108 /** @defgroup ADCEx_Exported_Functions_Group1 Extended Extended IO operation functions
mbed_official 489:119543c9f674 109 * @brief Extended Extended Input and Output operation functions
mbed_official 489:119543c9f674 110 *
mbed_official 489:119543c9f674 111 @verbatim
mbed_official 489:119543c9f674 112 ===============================================================================
mbed_official 489:119543c9f674 113 ##### IO operation functions #####
mbed_official 489:119543c9f674 114 ===============================================================================
mbed_official 489:119543c9f674 115 [..] This section provides functions allowing to:
mbed_official 489:119543c9f674 116 (+) Start conversion of injected group.
mbed_official 489:119543c9f674 117 (+) Stop conversion of injected group.
mbed_official 489:119543c9f674 118 (+) Poll for conversion complete on injected group.
mbed_official 489:119543c9f674 119 (+) Get result of injected channel conversion.
mbed_official 489:119543c9f674 120 (+) Start conversion of injected group and enable interruptions.
mbed_official 489:119543c9f674 121 (+) Stop conversion of injected group and disable interruptions.
mbed_official 489:119543c9f674 122
mbed_official 489:119543c9f674 123 (+) Start multimode and enable DMA transfer.
mbed_official 489:119543c9f674 124 (+) Stop multimode and disable ADC DMA transfer.
mbed_official 489:119543c9f674 125 (+) Get result of multimode conversion.
mbed_official 489:119543c9f674 126
mbed_official 489:119543c9f674 127 (+) Perform the ADC self-calibration for single or differential ending.
mbed_official 489:119543c9f674 128 (+) Get calibration factors for single or differential ending.
mbed_official 489:119543c9f674 129 (+) Set calibration factors for single or differential ending.
mbed_official 489:119543c9f674 130
mbed_official 489:119543c9f674 131 @endverbatim
mbed_official 489:119543c9f674 132 * @{
mbed_official 489:119543c9f674 133 */
mbed_official 489:119543c9f674 134
mbed_official 489:119543c9f674 135 /**
mbed_official 489:119543c9f674 136 * @brief Perform an ADC automatic self-calibration
mbed_official 489:119543c9f674 137 * Calibration prerequisite: ADC must be disabled (execute this
mbed_official 489:119543c9f674 138 * function before HAL_ADC_Start() or after HAL_ADC_Stop() ).
mbed_official 489:119543c9f674 139 * During calibration process, ADC is enabled. ADC is let enabled at
mbed_official 489:119543c9f674 140 * the completion of this function.
mbed_official 489:119543c9f674 141 * @param hadc: ADC handle
mbed_official 489:119543c9f674 142 * @retval HAL status
mbed_official 489:119543c9f674 143 */
mbed_official 489:119543c9f674 144 HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc)
mbed_official 489:119543c9f674 145 {
mbed_official 489:119543c9f674 146 HAL_StatusTypeDef tmp_hal_status = HAL_OK;
mbed_official 489:119543c9f674 147 uint32_t tickstart;
mbed_official 489:119543c9f674 148 __IO uint32_t wait_loop_index = 0;
mbed_official 489:119543c9f674 149
mbed_official 489:119543c9f674 150 /* Check the parameters */
mbed_official 489:119543c9f674 151 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
mbed_official 489:119543c9f674 152
mbed_official 489:119543c9f674 153 /* Process locked */
mbed_official 489:119543c9f674 154 __HAL_LOCK(hadc);
mbed_official 489:119543c9f674 155
mbed_official 489:119543c9f674 156 /* 1. Calibration prerequisite: */
mbed_official 489:119543c9f674 157 /* - ADC must be disabled for at least two ADC clock cycles in disable */
mbed_official 489:119543c9f674 158 /* mode before ADC enable */
mbed_official 489:119543c9f674 159 /* Stop potential conversion on going, on regular and injected groups */
mbed_official 489:119543c9f674 160 /* Disable ADC peripheral */
mbed_official 489:119543c9f674 161 tmp_hal_status = ADC_ConversionStop_Disable(hadc);
mbed_official 489:119543c9f674 162
mbed_official 489:119543c9f674 163 /* Check if ADC is effectively disabled */
mbed_official 489:119543c9f674 164 if (tmp_hal_status != HAL_ERROR)
mbed_official 489:119543c9f674 165 {
mbed_official 489:119543c9f674 166 /* Hardware prerequisite: delay before starting the calibration. */
mbed_official 489:119543c9f674 167 /* - Computation of CPU clock cycles corresponding to ADC clock cycles. */
mbed_official 489:119543c9f674 168 /* - Wait for the expected ADC clock cycles delay */
mbed_official 489:119543c9f674 169 wait_loop_index = ((SystemCoreClock
mbed_official 489:119543c9f674 170 / HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_ADC))
mbed_official 489:119543c9f674 171 * ADC_PRECALIBRATION_DELAY_ADCCLOCKCYCLES );
mbed_official 489:119543c9f674 172
mbed_official 489:119543c9f674 173 while(wait_loop_index != 0)
mbed_official 489:119543c9f674 174 {
mbed_official 489:119543c9f674 175 wait_loop_index--;
mbed_official 489:119543c9f674 176 }
mbed_official 489:119543c9f674 177
mbed_official 489:119543c9f674 178 /* 2. Enable the ADC peripheral */
mbed_official 489:119543c9f674 179 ADC_Enable(hadc);
mbed_official 489:119543c9f674 180
mbed_official 489:119543c9f674 181
mbed_official 489:119543c9f674 182 /* 3. Resets ADC calibration registers */
mbed_official 489:119543c9f674 183 SET_BIT(hadc->Instance->CR2, ADC_CR2_RSTCAL);
mbed_official 489:119543c9f674 184
mbed_official 489:119543c9f674 185 tickstart = HAL_GetTick();
mbed_official 489:119543c9f674 186
mbed_official 489:119543c9f674 187 /* Wait for calibration reset completion */
mbed_official 489:119543c9f674 188 while(HAL_IS_BIT_SET(hadc->Instance->CR2, ADC_CR2_RSTCAL))
mbed_official 489:119543c9f674 189 {
mbed_official 489:119543c9f674 190 if((HAL_GetTick() - tickstart) > ADC_CALIBRATION_TIMEOUT)
mbed_official 489:119543c9f674 191 {
mbed_official 489:119543c9f674 192 /* Update ADC state machine to error */
mbed_official 489:119543c9f674 193 hadc->State = HAL_ADC_STATE_ERROR;
mbed_official 489:119543c9f674 194
mbed_official 489:119543c9f674 195 /* Process unlocked */
mbed_official 489:119543c9f674 196 __HAL_UNLOCK(hadc);
mbed_official 489:119543c9f674 197
mbed_official 489:119543c9f674 198 return HAL_ERROR;
mbed_official 489:119543c9f674 199 }
mbed_official 489:119543c9f674 200 }
mbed_official 489:119543c9f674 201
mbed_official 489:119543c9f674 202
mbed_official 489:119543c9f674 203 /* 4. Start ADC calibration */
mbed_official 489:119543c9f674 204 SET_BIT(hadc->Instance->CR2, ADC_CR2_CAL);
mbed_official 489:119543c9f674 205
mbed_official 489:119543c9f674 206 tickstart = HAL_GetTick();
mbed_official 489:119543c9f674 207
mbed_official 489:119543c9f674 208 /* Wait for calibration completion */
mbed_official 489:119543c9f674 209 while(HAL_IS_BIT_SET(hadc->Instance->CR2, ADC_CR2_CAL))
mbed_official 489:119543c9f674 210 {
mbed_official 489:119543c9f674 211 if((HAL_GetTick() - tickstart) > ADC_CALIBRATION_TIMEOUT)
mbed_official 489:119543c9f674 212 {
mbed_official 489:119543c9f674 213 /* Update ADC state machine to error */
mbed_official 489:119543c9f674 214 hadc->State = HAL_ADC_STATE_ERROR;
mbed_official 489:119543c9f674 215
mbed_official 489:119543c9f674 216 /* Process unlocked */
mbed_official 489:119543c9f674 217 __HAL_UNLOCK(hadc);
mbed_official 489:119543c9f674 218
mbed_official 489:119543c9f674 219 return HAL_ERROR;
mbed_official 489:119543c9f674 220 }
mbed_official 489:119543c9f674 221 }
mbed_official 489:119543c9f674 222
mbed_official 489:119543c9f674 223 }
mbed_official 489:119543c9f674 224
mbed_official 489:119543c9f674 225 /* Process unlocked */
mbed_official 489:119543c9f674 226 __HAL_UNLOCK(hadc);
mbed_official 489:119543c9f674 227
mbed_official 489:119543c9f674 228 /* Return function status */
mbed_official 489:119543c9f674 229 return tmp_hal_status;
mbed_official 489:119543c9f674 230 }
mbed_official 489:119543c9f674 231
mbed_official 489:119543c9f674 232 /**
mbed_official 489:119543c9f674 233 * @brief Enables ADC, starts conversion of injected group.
mbed_official 489:119543c9f674 234 * Interruptions enabled in this function: None.
mbed_official 489:119543c9f674 235 * @param hadc: ADC handle
mbed_official 489:119543c9f674 236 * @retval HAL status
mbed_official 489:119543c9f674 237 */
mbed_official 489:119543c9f674 238 HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
mbed_official 489:119543c9f674 239 {
mbed_official 489:119543c9f674 240 HAL_StatusTypeDef tmp_hal_status = HAL_OK;
mbed_official 489:119543c9f674 241
mbed_official 489:119543c9f674 242 /* Check the parameters */
mbed_official 489:119543c9f674 243 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
mbed_official 489:119543c9f674 244
mbed_official 489:119543c9f674 245 /* Process locked */
mbed_official 489:119543c9f674 246 __HAL_LOCK(hadc);
mbed_official 489:119543c9f674 247
mbed_official 489:119543c9f674 248 /* Enable the ADC peripheral */
mbed_official 489:119543c9f674 249 tmp_hal_status = ADC_Enable(hadc);
mbed_official 489:119543c9f674 250
mbed_official 489:119543c9f674 251 /* Start conversion if ADC is effectively enabled */
mbed_official 489:119543c9f674 252 if (tmp_hal_status != HAL_ERROR)
mbed_official 489:119543c9f674 253 {
mbed_official 489:119543c9f674 254 /* Check if a regular conversion is ongoing */
mbed_official 489:119543c9f674 255 if(hadc->State == HAL_ADC_STATE_BUSY_REG)
mbed_official 489:119543c9f674 256 {
mbed_official 489:119543c9f674 257 /* Change ADC state */
mbed_official 489:119543c9f674 258 hadc->State = HAL_ADC_STATE_BUSY_INJ_REG;
mbed_official 489:119543c9f674 259 }
mbed_official 489:119543c9f674 260 else
mbed_official 489:119543c9f674 261 {
mbed_official 489:119543c9f674 262 /* Change ADC state */
mbed_official 489:119543c9f674 263 hadc->State = HAL_ADC_STATE_BUSY_INJ;
mbed_official 489:119543c9f674 264 }
mbed_official 489:119543c9f674 265
mbed_official 489:119543c9f674 266 /* Process unlocked */
mbed_official 489:119543c9f674 267 /* Unlock before starting ADC conversions: in case of potential */
mbed_official 489:119543c9f674 268 /* interruption, to let the process to ADC IRQ Handler. */
mbed_official 489:119543c9f674 269 __HAL_UNLOCK(hadc);
mbed_official 489:119543c9f674 270
mbed_official 489:119543c9f674 271 /* Set ADC error code to none */
mbed_official 489:119543c9f674 272 ADC_CLEAR_ERRORCODE(hadc);
mbed_official 489:119543c9f674 273
mbed_official 489:119543c9f674 274 /* Clear injected group conversion flag */
mbed_official 489:119543c9f674 275 /* (To ensure of no unknown state from potential previous ADC operations) */
mbed_official 489:119543c9f674 276 __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_JEOC);
mbed_official 489:119543c9f674 277
mbed_official 489:119543c9f674 278 /* Enable conversion of injected group. */
mbed_official 489:119543c9f674 279 /* If software start has been selected, conversion starts immediately. */
mbed_official 489:119543c9f674 280 /* If external trigger has been selected, conversion will start at next */
mbed_official 489:119543c9f674 281 /* trigger event. */
mbed_official 489:119543c9f674 282 /* If automatic injected conversion is enabled, conversion will start */
mbed_official 489:119543c9f674 283 /* after next regular group conversion. */
mbed_official 489:119543c9f674 284 /* Case of multimode enabled (for devices with several ADCs): if ADC is */
mbed_official 489:119543c9f674 285 /* slave, ADC is enabled only (conversion is not started). If ADC is */
mbed_official 489:119543c9f674 286 /* master, ADC is enabled and conversion is started. */
mbed_official 489:119543c9f674 287 if (HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO))
mbed_official 489:119543c9f674 288 {
mbed_official 489:119543c9f674 289 if (ADC_IS_SOFTWARE_START_INJECTED(hadc) &&
mbed_official 489:119543c9f674 290 ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc) )
mbed_official 489:119543c9f674 291 {
mbed_official 489:119543c9f674 292 /* Start ADC conversion on injected group with SW start */
mbed_official 489:119543c9f674 293 SET_BIT(hadc->Instance->CR2, (ADC_CR2_JSWSTART | ADC_CR2_JEXTTRIG));
mbed_official 489:119543c9f674 294 }
mbed_official 489:119543c9f674 295 else
mbed_official 489:119543c9f674 296 {
mbed_official 489:119543c9f674 297 /* Start ADC conversion on injected group with external trigger */
mbed_official 489:119543c9f674 298 SET_BIT(hadc->Instance->CR2, ADC_CR2_JEXTTRIG);
mbed_official 489:119543c9f674 299 }
mbed_official 489:119543c9f674 300 }
mbed_official 489:119543c9f674 301 }
mbed_official 489:119543c9f674 302 else
mbed_official 489:119543c9f674 303 {
mbed_official 489:119543c9f674 304 /* Process unlocked */
mbed_official 489:119543c9f674 305 __HAL_UNLOCK(hadc);
mbed_official 489:119543c9f674 306 }
mbed_official 489:119543c9f674 307
mbed_official 489:119543c9f674 308 /* Return function status */
mbed_official 489:119543c9f674 309 return tmp_hal_status;
mbed_official 489:119543c9f674 310 }
mbed_official 489:119543c9f674 311
mbed_official 489:119543c9f674 312 /**
mbed_official 489:119543c9f674 313 * @brief Stop conversion of injected channels. Disable ADC peripheral if
mbed_official 489:119543c9f674 314 * no regular conversion is on going.
mbed_official 489:119543c9f674 315 * @note If ADC must be disabled and if conversion is on going on
mbed_official 489:119543c9f674 316 * regular group, function HAL_ADC_Stop must be used to stop both
mbed_official 489:119543c9f674 317 * injected and regular groups, and disable the ADC.
mbed_official 489:119543c9f674 318 * @note In case of auto-injection mode, HAL_ADC_Stop must be used.
mbed_official 489:119543c9f674 319 * @param hadc: ADC handle
mbed_official 489:119543c9f674 320 * @retval None
mbed_official 489:119543c9f674 321 */
mbed_official 489:119543c9f674 322 HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc)
mbed_official 489:119543c9f674 323 {
mbed_official 489:119543c9f674 324 HAL_StatusTypeDef tmp_hal_status = HAL_OK;
mbed_official 489:119543c9f674 325
mbed_official 489:119543c9f674 326 /* Check the parameters */
mbed_official 489:119543c9f674 327 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
mbed_official 489:119543c9f674 328
mbed_official 489:119543c9f674 329 /* Process locked */
mbed_official 489:119543c9f674 330 __HAL_LOCK(hadc);
mbed_official 489:119543c9f674 331
mbed_official 489:119543c9f674 332 /* Stop potential conversion and disable ADC peripheral */
mbed_official 489:119543c9f674 333 /* Conditioned to: */
mbed_official 489:119543c9f674 334 /* - No conversion on the other group (regular group) is intended to */
mbed_official 489:119543c9f674 335 /* continue (injected and regular groups stop conversion and ADC disable */
mbed_official 489:119543c9f674 336 /* are common) */
mbed_official 489:119543c9f674 337 /* - In case of auto-injection mode, HAL_ADC_Stop must be used. */
mbed_official 489:119543c9f674 338 if((hadc->State != HAL_ADC_STATE_BUSY_REG) &&
mbed_official 489:119543c9f674 339 (hadc->State != HAL_ADC_STATE_BUSY_INJ_REG) &&
mbed_official 489:119543c9f674 340 HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO) )
mbed_official 489:119543c9f674 341 {
mbed_official 489:119543c9f674 342 /* Stop potential conversion on going, on regular and injected groups */
mbed_official 489:119543c9f674 343 /* Disable ADC peripheral */
mbed_official 489:119543c9f674 344 tmp_hal_status = ADC_ConversionStop_Disable(hadc);
mbed_official 489:119543c9f674 345
mbed_official 489:119543c9f674 346 /* Check if ADC is effectively disabled */
mbed_official 489:119543c9f674 347 if (tmp_hal_status != HAL_ERROR)
mbed_official 489:119543c9f674 348 {
mbed_official 489:119543c9f674 349 /* Change ADC state */
mbed_official 489:119543c9f674 350 hadc->State = HAL_ADC_STATE_READY;
mbed_official 489:119543c9f674 351 }
mbed_official 489:119543c9f674 352 }
mbed_official 489:119543c9f674 353 else
mbed_official 489:119543c9f674 354 {
mbed_official 489:119543c9f674 355 /* Update ADC state machine to error */
mbed_official 489:119543c9f674 356 hadc->State = HAL_ADC_STATE_ERROR;
mbed_official 489:119543c9f674 357
mbed_official 489:119543c9f674 358 tmp_hal_status = HAL_ERROR;
mbed_official 489:119543c9f674 359 }
mbed_official 489:119543c9f674 360
mbed_official 489:119543c9f674 361 /* Process unlocked */
mbed_official 489:119543c9f674 362 __HAL_UNLOCK(hadc);
mbed_official 489:119543c9f674 363
mbed_official 489:119543c9f674 364 /* Return function status */
mbed_official 489:119543c9f674 365 return tmp_hal_status;
mbed_official 489:119543c9f674 366 }
mbed_official 489:119543c9f674 367
mbed_official 489:119543c9f674 368 /**
mbed_official 489:119543c9f674 369 * @brief Wait for injected group conversion to be completed.
mbed_official 489:119543c9f674 370 * @param hadc: ADC handle
mbed_official 489:119543c9f674 371 * @param Timeout: Timeout value in millisecond.
mbed_official 489:119543c9f674 372 * @retval HAL status
mbed_official 489:119543c9f674 373 */
mbed_official 489:119543c9f674 374 HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout)
mbed_official 489:119543c9f674 375 {
mbed_official 489:119543c9f674 376 uint32_t tickstart;
mbed_official 489:119543c9f674 377
mbed_official 489:119543c9f674 378 /* Variables for polling in case of scan mode enabled and polling for each */
mbed_official 489:119543c9f674 379 /* conversion. */
mbed_official 489:119543c9f674 380 __IO uint32_t Conversion_Timeout_CPU_cycles = 0;
mbed_official 489:119543c9f674 381 uint32_t Conversion_Timeout_CPU_cycles_max = 0;
mbed_official 489:119543c9f674 382
mbed_official 489:119543c9f674 383 /* Check the parameters */
mbed_official 489:119543c9f674 384 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
mbed_official 489:119543c9f674 385
mbed_official 489:119543c9f674 386 /* Get timeout */
mbed_official 489:119543c9f674 387 tickstart = HAL_GetTick();
mbed_official 489:119543c9f674 388
mbed_official 489:119543c9f674 389 /* Polling for end of conversion: differentiation if single/sequence */
mbed_official 489:119543c9f674 390 /* conversion. */
mbed_official 489:119543c9f674 391 /* For injected group, flag JEOC is set only at the end of the sequence, */
mbed_official 489:119543c9f674 392 /* not for each conversion within the sequence. */
mbed_official 489:119543c9f674 393 /* - If single conversion for injected group (scan mode disabled or */
mbed_official 489:119543c9f674 394 /* InjectedNbrOfConversion ==1), flag jEOC is used to determine the */
mbed_official 489:119543c9f674 395 /* conversion completion. */
mbed_official 489:119543c9f674 396 /* - If sequence conversion for injected group (scan mode enabled and */
mbed_official 489:119543c9f674 397 /* InjectedNbrOfConversion >=2), flag JEOC is set only at the end of the */
mbed_official 489:119543c9f674 398 /* sequence. */
mbed_official 489:119543c9f674 399 /* To poll for each conversion, the maximum conversion time is computed */
mbed_official 489:119543c9f674 400 /* from ADC conversion time (selected sampling time + conversion time of */
mbed_official 489:119543c9f674 401 /* 12.5 ADC clock cycles) and APB2/ADC clock prescalers (depending on */
mbed_official 489:119543c9f674 402 /* settings, conversion time range can be from 28 to 32256 CPU cycles). */
mbed_official 489:119543c9f674 403 if ((hadc->Instance->JSQR & ADC_JSQR_JL) == RESET)
mbed_official 489:119543c9f674 404 {
mbed_official 489:119543c9f674 405 /* Wait until End of Conversion flag is raised */
mbed_official 489:119543c9f674 406 while(HAL_IS_BIT_CLR(hadc->Instance->SR, ADC_FLAG_JEOC))
mbed_official 489:119543c9f674 407 {
mbed_official 489:119543c9f674 408 /* Check if timeout is disabled (set to infinite wait) */
mbed_official 489:119543c9f674 409 if(Timeout != HAL_MAX_DELAY)
mbed_official 489:119543c9f674 410 {
mbed_official 489:119543c9f674 411 if((Timeout == 0) || ((HAL_GetTick() - tickstart ) > Timeout))
mbed_official 489:119543c9f674 412 {
mbed_official 489:119543c9f674 413 /* Update ADC state machine to timeout */
mbed_official 489:119543c9f674 414 hadc->State = HAL_ADC_STATE_TIMEOUT;
mbed_official 489:119543c9f674 415
mbed_official 489:119543c9f674 416 /* Process unlocked */
mbed_official 489:119543c9f674 417 __HAL_UNLOCK(hadc);
mbed_official 489:119543c9f674 418
mbed_official 489:119543c9f674 419 return HAL_ERROR;
mbed_official 489:119543c9f674 420 }
mbed_official 489:119543c9f674 421 }
mbed_official 489:119543c9f674 422 }
mbed_official 489:119543c9f674 423 }
mbed_official 489:119543c9f674 424 else
mbed_official 489:119543c9f674 425 {
mbed_official 489:119543c9f674 426 /* Poll with maximum conversion time */
mbed_official 489:119543c9f674 427 /* - Computation of CPU clock cycles corresponding to ADC clock cycles */
mbed_official 489:119543c9f674 428 /* and ADC maximum conversion cycles on all channels. */
mbed_official 489:119543c9f674 429 /* - Wait for the expected ADC clock cycles delay */
mbed_official 489:119543c9f674 430 Conversion_Timeout_CPU_cycles_max = ((SystemCoreClock
mbed_official 489:119543c9f674 431 / HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_ADC))
mbed_official 489:119543c9f674 432 * ADC_CONVCYCLES_MAX_RANGE(hadc) );
mbed_official 489:119543c9f674 433
mbed_official 489:119543c9f674 434 while(Conversion_Timeout_CPU_cycles < Conversion_Timeout_CPU_cycles_max)
mbed_official 489:119543c9f674 435 {
mbed_official 489:119543c9f674 436 /* Check if timeout is disabled (set to infinite wait) */
mbed_official 489:119543c9f674 437 if(Timeout != HAL_MAX_DELAY)
mbed_official 489:119543c9f674 438 {
mbed_official 489:119543c9f674 439 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
mbed_official 489:119543c9f674 440 {
mbed_official 489:119543c9f674 441 /* Update ADC state machine to timeout */
mbed_official 489:119543c9f674 442 hadc->State = HAL_ADC_STATE_TIMEOUT;
mbed_official 489:119543c9f674 443
mbed_official 489:119543c9f674 444 /* Process unlocked */
mbed_official 489:119543c9f674 445 __HAL_UNLOCK(hadc);
mbed_official 489:119543c9f674 446
mbed_official 489:119543c9f674 447 return HAL_ERROR;
mbed_official 489:119543c9f674 448 }
mbed_official 489:119543c9f674 449 }
mbed_official 489:119543c9f674 450 Conversion_Timeout_CPU_cycles ++;
mbed_official 489:119543c9f674 451 }
mbed_official 489:119543c9f674 452 }
mbed_official 489:119543c9f674 453
mbed_official 489:119543c9f674 454 /* Clear injected group conversion flag (and regular conversion flag raised */
mbed_official 489:119543c9f674 455 /* simultaneously) */
mbed_official 489:119543c9f674 456 __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_JSTRT | ADC_FLAG_JEOC | ADC_FLAG_EOC);
mbed_official 489:119543c9f674 457
mbed_official 489:119543c9f674 458 /* Update state machine on conversion status if not in error state */
mbed_official 489:119543c9f674 459 if(hadc->State != HAL_ADC_STATE_ERROR)
mbed_official 489:119543c9f674 460 {
mbed_official 489:119543c9f674 461 /* Update ADC state machine */
mbed_official 489:119543c9f674 462 if(hadc->State != HAL_ADC_STATE_EOC_INJ_REG)
mbed_official 489:119543c9f674 463 {
mbed_official 489:119543c9f674 464
mbed_official 489:119543c9f674 465 if(hadc->State == HAL_ADC_STATE_EOC_REG)
mbed_official 489:119543c9f674 466 {
mbed_official 489:119543c9f674 467 /* Change ADC state */
mbed_official 489:119543c9f674 468 hadc->State = HAL_ADC_STATE_EOC_INJ_REG;
mbed_official 489:119543c9f674 469 }
mbed_official 489:119543c9f674 470 else
mbed_official 489:119543c9f674 471 {
mbed_official 489:119543c9f674 472 /* Change ADC state */
mbed_official 489:119543c9f674 473 hadc->State = HAL_ADC_STATE_EOC_INJ;
mbed_official 489:119543c9f674 474 }
mbed_official 489:119543c9f674 475 }
mbed_official 489:119543c9f674 476 }
mbed_official 489:119543c9f674 477
mbed_official 489:119543c9f674 478 /* Return ADC state */
mbed_official 489:119543c9f674 479 return HAL_OK;
mbed_official 489:119543c9f674 480 }
mbed_official 489:119543c9f674 481
mbed_official 489:119543c9f674 482 /**
mbed_official 489:119543c9f674 483 * @brief Enables ADC, starts conversion of injected group with interruption.
mbed_official 489:119543c9f674 484 * - JEOC (end of conversion of injected group)
mbed_official 489:119543c9f674 485 * Each of these interruptions has its dedicated callback function.
mbed_official 489:119543c9f674 486 * @param hadc: ADC handle
mbed_official 489:119543c9f674 487 * @retval HAL status.
mbed_official 489:119543c9f674 488 */
mbed_official 489:119543c9f674 489 HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
mbed_official 489:119543c9f674 490 {
mbed_official 489:119543c9f674 491 HAL_StatusTypeDef tmp_hal_status = HAL_OK;
mbed_official 489:119543c9f674 492
mbed_official 489:119543c9f674 493 /* Check the parameters */
mbed_official 489:119543c9f674 494 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
mbed_official 489:119543c9f674 495
mbed_official 489:119543c9f674 496 /* Process locked */
mbed_official 489:119543c9f674 497 __HAL_LOCK(hadc);
mbed_official 489:119543c9f674 498
mbed_official 489:119543c9f674 499 /* Enable the ADC peripheral */
mbed_official 489:119543c9f674 500 tmp_hal_status = ADC_Enable(hadc);
mbed_official 489:119543c9f674 501
mbed_official 489:119543c9f674 502 /* Start conversion if ADC is effectively enabled */
mbed_official 489:119543c9f674 503 if (tmp_hal_status != HAL_ERROR)
mbed_official 489:119543c9f674 504 {
mbed_official 489:119543c9f674 505 /* Check if a regular conversion is ongoing */
mbed_official 489:119543c9f674 506 if(hadc->State == HAL_ADC_STATE_BUSY_REG)
mbed_official 489:119543c9f674 507 {
mbed_official 489:119543c9f674 508 /* Change ADC state */
mbed_official 489:119543c9f674 509 hadc->State = HAL_ADC_STATE_BUSY_INJ_REG;
mbed_official 489:119543c9f674 510 }
mbed_official 489:119543c9f674 511 else
mbed_official 489:119543c9f674 512 {
mbed_official 489:119543c9f674 513 /* Change ADC state */
mbed_official 489:119543c9f674 514 hadc->State = HAL_ADC_STATE_BUSY_INJ;
mbed_official 489:119543c9f674 515 }
mbed_official 489:119543c9f674 516
mbed_official 489:119543c9f674 517 /* Process unlocked */
mbed_official 489:119543c9f674 518 /* Unlock before starting ADC conversions: in case of potential */
mbed_official 489:119543c9f674 519 /* interruption, to let the process to ADC IRQ Handler. */
mbed_official 489:119543c9f674 520 __HAL_UNLOCK(hadc);
mbed_official 489:119543c9f674 521
mbed_official 489:119543c9f674 522 /* Set ADC error code to none */
mbed_official 489:119543c9f674 523 ADC_CLEAR_ERRORCODE(hadc);
mbed_official 489:119543c9f674 524
mbed_official 489:119543c9f674 525 /* Clear injected group conversion flag */
mbed_official 489:119543c9f674 526 /* (To ensure of no unknown state from potential previous ADC operations) */
mbed_official 489:119543c9f674 527 __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_JEOC);
mbed_official 489:119543c9f674 528
mbed_official 489:119543c9f674 529 /* Enable end of conversion interrupt for injected channels */
mbed_official 489:119543c9f674 530 __HAL_ADC_ENABLE_IT(hadc, ADC_IT_JEOC);
mbed_official 489:119543c9f674 531
mbed_official 489:119543c9f674 532 /* Start conversion of injected group if software start has been selected */
mbed_official 489:119543c9f674 533 /* and if automatic injected conversion is disabled. */
mbed_official 489:119543c9f674 534 /* If external trigger has been selected, conversion will start at next */
mbed_official 489:119543c9f674 535 /* trigger event. */
mbed_official 489:119543c9f674 536 /* If automatic injected conversion is enabled, conversion will start */
mbed_official 489:119543c9f674 537 /* after next regular group conversion. */
mbed_official 489:119543c9f674 538 if (HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO))
mbed_official 489:119543c9f674 539 {
mbed_official 489:119543c9f674 540 if (ADC_IS_SOFTWARE_START_INJECTED(hadc) &&
mbed_official 489:119543c9f674 541 ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc) )
mbed_official 489:119543c9f674 542 {
mbed_official 489:119543c9f674 543 /* Start ADC conversion on injected group with SW start */
mbed_official 489:119543c9f674 544 SET_BIT(hadc->Instance->CR2, (ADC_CR2_JSWSTART | ADC_CR2_JEXTTRIG));
mbed_official 489:119543c9f674 545 }
mbed_official 489:119543c9f674 546 else
mbed_official 489:119543c9f674 547 {
mbed_official 489:119543c9f674 548 /* Start ADC conversion on injected group with external trigger */
mbed_official 489:119543c9f674 549 SET_BIT(hadc->Instance->CR2, ADC_CR2_JEXTTRIG);
mbed_official 489:119543c9f674 550 }
mbed_official 489:119543c9f674 551 }
mbed_official 489:119543c9f674 552 }
mbed_official 489:119543c9f674 553 else
mbed_official 489:119543c9f674 554 {
mbed_official 489:119543c9f674 555 /* Process unlocked */
mbed_official 489:119543c9f674 556 __HAL_UNLOCK(hadc);
mbed_official 489:119543c9f674 557 }
mbed_official 489:119543c9f674 558
mbed_official 489:119543c9f674 559 /* Return function status */
mbed_official 489:119543c9f674 560 return tmp_hal_status;
mbed_official 489:119543c9f674 561 }
mbed_official 489:119543c9f674 562
mbed_official 489:119543c9f674 563 /**
mbed_official 489:119543c9f674 564 * @brief Stop conversion of injected channels, disable interruption of
mbed_official 489:119543c9f674 565 * end-of-conversion. Disable ADC peripheral if no regular conversion
mbed_official 489:119543c9f674 566 * is on going.
mbed_official 489:119543c9f674 567 * @note If ADC must be disabled and if conversion is on going on
mbed_official 489:119543c9f674 568 * regular group, function HAL_ADC_Stop must be used to stop both
mbed_official 489:119543c9f674 569 * injected and regular groups, and disable the ADC.
mbed_official 489:119543c9f674 570 * @param hadc: ADC handle
mbed_official 489:119543c9f674 571 * @retval None
mbed_official 489:119543c9f674 572 */
mbed_official 489:119543c9f674 573 HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc)
mbed_official 489:119543c9f674 574 {
mbed_official 489:119543c9f674 575 HAL_StatusTypeDef tmp_hal_status = HAL_OK;
mbed_official 489:119543c9f674 576
mbed_official 489:119543c9f674 577 /* Check the parameters */
mbed_official 489:119543c9f674 578 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
mbed_official 489:119543c9f674 579
mbed_official 489:119543c9f674 580 /* Process locked */
mbed_official 489:119543c9f674 581 __HAL_LOCK(hadc);
mbed_official 489:119543c9f674 582
mbed_official 489:119543c9f674 583 /* Stop potential conversion and disable ADC peripheral */
mbed_official 489:119543c9f674 584 /* Conditioned to: */
mbed_official 489:119543c9f674 585 /* - No conversion on the other group (regular group) is intended to */
mbed_official 489:119543c9f674 586 /* continue (injected and regular groups stop conversion and ADC disable */
mbed_official 489:119543c9f674 587 /* are common) */
mbed_official 489:119543c9f674 588 /* - In case of auto-injection mode, HAL_ADC_Stop must be used. */
mbed_official 489:119543c9f674 589 if((hadc->State != HAL_ADC_STATE_BUSY_REG) &&
mbed_official 489:119543c9f674 590 (hadc->State != HAL_ADC_STATE_BUSY_INJ_REG) &&
mbed_official 489:119543c9f674 591 HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO) )
mbed_official 489:119543c9f674 592 {
mbed_official 489:119543c9f674 593 /* Stop potential conversion on going, on regular and injected groups */
mbed_official 489:119543c9f674 594 /* Disable ADC peripheral */
mbed_official 489:119543c9f674 595 tmp_hal_status = ADC_ConversionStop_Disable(hadc);
mbed_official 489:119543c9f674 596
mbed_official 489:119543c9f674 597 /* Check if ADC is effectively disabled */
mbed_official 489:119543c9f674 598 if (tmp_hal_status != HAL_ERROR)
mbed_official 489:119543c9f674 599 {
mbed_official 489:119543c9f674 600 /* Disable ADC end of conversion interrupt for injected channels */
mbed_official 489:119543c9f674 601 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOC);
mbed_official 489:119543c9f674 602
mbed_official 489:119543c9f674 603 /* Change ADC state */
mbed_official 489:119543c9f674 604 hadc->State = HAL_ADC_STATE_READY;
mbed_official 489:119543c9f674 605 }
mbed_official 489:119543c9f674 606 }
mbed_official 489:119543c9f674 607 else
mbed_official 489:119543c9f674 608 {
mbed_official 489:119543c9f674 609 /* Update ADC state machine to error */
mbed_official 489:119543c9f674 610 hadc->State = HAL_ADC_STATE_ERROR;
mbed_official 489:119543c9f674 611
mbed_official 489:119543c9f674 612 tmp_hal_status = HAL_ERROR;
mbed_official 489:119543c9f674 613 }
mbed_official 489:119543c9f674 614
mbed_official 489:119543c9f674 615 /* Process unlocked */
mbed_official 489:119543c9f674 616 __HAL_UNLOCK(hadc);
mbed_official 489:119543c9f674 617
mbed_official 489:119543c9f674 618 /* Return function status */
mbed_official 489:119543c9f674 619 return tmp_hal_status;
mbed_official 489:119543c9f674 620 }
mbed_official 489:119543c9f674 621
mbed_official 489:119543c9f674 622 #if defined (STM32F101xG) || defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
mbed_official 489:119543c9f674 623 /**
mbed_official 489:119543c9f674 624 * @brief Enables ADC, starts conversion of regular group and transfers result
mbed_official 489:119543c9f674 625 * through DMA.
mbed_official 489:119543c9f674 626 * Multimode must have been previously configured using
mbed_official 489:119543c9f674 627 * HAL_ADCEx_MultiModeConfigChannel() function.
mbed_official 489:119543c9f674 628 * Interruptions enabled in this function:
mbed_official 489:119543c9f674 629 * - DMA transfer complete
mbed_official 489:119543c9f674 630 * - DMA half transfer
mbed_official 489:119543c9f674 631 * Each of these interruptions has its dedicated callback function.
mbed_official 489:119543c9f674 632 * @note: On STM32F1 devices, ADC slave regular group must be configured
mbed_official 489:119543c9f674 633 * with conversion trigger ADC_SOFTWARE_START.
mbed_official 489:119543c9f674 634 * @note: ADC slave can be enabled preliminarily using single-mode
mbed_official 489:119543c9f674 635 * HAL_ADC_Start() function.
mbed_official 489:119543c9f674 636 * @param hadc: ADC handle of ADC master (handle of ADC slave must not be used)
mbed_official 489:119543c9f674 637 * @param pData: The destination Buffer address.
mbed_official 489:119543c9f674 638 * @param Length: The length of data to be transferred from ADC peripheral to memory.
mbed_official 489:119543c9f674 639 * @retval None
mbed_official 489:119543c9f674 640 */
mbed_official 489:119543c9f674 641 HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length)
mbed_official 489:119543c9f674 642 {
mbed_official 489:119543c9f674 643 HAL_StatusTypeDef tmp_hal_status = HAL_OK;
mbed_official 489:119543c9f674 644 ADC_HandleTypeDef tmphadcSlave;
mbed_official 489:119543c9f674 645
mbed_official 489:119543c9f674 646 /* Check the parameters */
mbed_official 489:119543c9f674 647 assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance));
mbed_official 489:119543c9f674 648 assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ContinuousConvMode));
mbed_official 489:119543c9f674 649
mbed_official 489:119543c9f674 650 /* Process locked */
mbed_official 489:119543c9f674 651 __HAL_LOCK(hadc);
mbed_official 489:119543c9f674 652
mbed_official 489:119543c9f674 653 /* Set a temporary handle of the ADC slave associated to the ADC master */
mbed_official 489:119543c9f674 654 ADC_MULTI_SLAVE(hadc, &tmphadcSlave);
mbed_official 489:119543c9f674 655
mbed_official 489:119543c9f674 656 /* On STM32F1 devices, ADC slave regular group must be configured with */
mbed_official 489:119543c9f674 657 /* conversion trigger ADC_SOFTWARE_START. */
mbed_official 489:119543c9f674 658 /* Note: External trigger of ADC slave must be enabled, it is already done */
mbed_official 489:119543c9f674 659 /* into function "HAL_ADC_Init()". */
mbed_official 489:119543c9f674 660 if ((tmphadcSlave.Instance == NULL) ||
mbed_official 489:119543c9f674 661 (! ADC_IS_SOFTWARE_START_REGULAR(&tmphadcSlave)) )
mbed_official 489:119543c9f674 662 {
mbed_official 489:119543c9f674 663 /* Update ADC state machine to error */
mbed_official 489:119543c9f674 664 hadc->State = HAL_ADC_STATE_ERROR;
mbed_official 489:119543c9f674 665
mbed_official 489:119543c9f674 666 /* Process unlocked */
mbed_official 489:119543c9f674 667 __HAL_UNLOCK(hadc);
mbed_official 489:119543c9f674 668
mbed_official 489:119543c9f674 669 return HAL_ERROR;
mbed_official 489:119543c9f674 670 }
mbed_official 489:119543c9f674 671
mbed_official 489:119543c9f674 672 /* Enable the ADC peripherals: master and slave (in case if not already */
mbed_official 489:119543c9f674 673 /* enabled previously) */
mbed_official 489:119543c9f674 674 tmp_hal_status = ADC_Enable(hadc);
mbed_official 489:119543c9f674 675 if (tmp_hal_status != HAL_ERROR)
mbed_official 489:119543c9f674 676 {
mbed_official 489:119543c9f674 677 tmp_hal_status = ADC_Enable(&tmphadcSlave);
mbed_official 489:119543c9f674 678 }
mbed_official 489:119543c9f674 679
mbed_official 489:119543c9f674 680 /* Start conversion all ADCs of multimode are effectively enabled */
mbed_official 489:119543c9f674 681 if (tmp_hal_status != HAL_ERROR)
mbed_official 489:119543c9f674 682 {
mbed_official 489:119543c9f674 683 /* State machine update (ADC master): Check if an injected conversion is */
mbed_official 489:119543c9f674 684 /* ongoing. */
mbed_official 489:119543c9f674 685 if(hadc->State == HAL_ADC_STATE_BUSY_INJ)
mbed_official 489:119543c9f674 686 {
mbed_official 489:119543c9f674 687 /* Change ADC state */
mbed_official 489:119543c9f674 688 hadc->State = HAL_ADC_STATE_BUSY_INJ_REG;
mbed_official 489:119543c9f674 689 }
mbed_official 489:119543c9f674 690 else
mbed_official 489:119543c9f674 691 {
mbed_official 489:119543c9f674 692 /* Change ADC state */
mbed_official 489:119543c9f674 693 hadc->State = HAL_ADC_STATE_BUSY_REG;
mbed_official 489:119543c9f674 694 }
mbed_official 489:119543c9f674 695
mbed_official 489:119543c9f674 696 /* Process unlocked */
mbed_official 489:119543c9f674 697 /* Unlock before starting ADC conversions: in case of potential */
mbed_official 489:119543c9f674 698 /* interruption, to let the process to ADC IRQ Handler. */
mbed_official 489:119543c9f674 699 __HAL_UNLOCK(hadc);
mbed_official 489:119543c9f674 700
mbed_official 489:119543c9f674 701 /* Set ADC error code to none */
mbed_official 489:119543c9f674 702 ADC_CLEAR_ERRORCODE(hadc);
mbed_official 489:119543c9f674 703
mbed_official 489:119543c9f674 704
mbed_official 489:119543c9f674 705 /* Set the DMA transfer complete callback */
mbed_official 489:119543c9f674 706 hadc->DMA_Handle->XferCpltCallback = ADC_DMAConvCplt;
mbed_official 489:119543c9f674 707
mbed_official 489:119543c9f674 708 /* Set the DMA half transfer complete callback */
mbed_official 489:119543c9f674 709 hadc->DMA_Handle->XferHalfCpltCallback = ADC_DMAHalfConvCplt;
mbed_official 489:119543c9f674 710
mbed_official 489:119543c9f674 711 /* Set the DMA error callback */
mbed_official 489:119543c9f674 712 hadc->DMA_Handle->XferErrorCallback = ADC_DMAError;
mbed_official 489:119543c9f674 713
mbed_official 489:119543c9f674 714
mbed_official 489:119543c9f674 715 /* Manage ADC and DMA start: ADC overrun interruption, DMA start, ADC */
mbed_official 489:119543c9f674 716 /* start (in case of SW start): */
mbed_official 489:119543c9f674 717
mbed_official 489:119543c9f674 718 /* Clear regular group conversion flag and overrun flag */
mbed_official 489:119543c9f674 719 /* (To ensure of no unknown state from potential previous ADC operations) */
mbed_official 489:119543c9f674 720 __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_EOC);
mbed_official 489:119543c9f674 721
mbed_official 489:119543c9f674 722 /* Enable ADC DMA mode of ADC master */
mbed_official 489:119543c9f674 723 SET_BIT(hadc->Instance->CR2, ADC_CR2_DMA);
mbed_official 489:119543c9f674 724
mbed_official 489:119543c9f674 725 /* Start the DMA channel */
mbed_official 489:119543c9f674 726 HAL_DMA_Start_IT(hadc->DMA_Handle, (uint32_t)&hadc->Instance->DR, (uint32_t)pData, Length);
mbed_official 489:119543c9f674 727
mbed_official 489:119543c9f674 728 /* Start conversion of regular group if software start has been selected. */
mbed_official 489:119543c9f674 729 /* If external trigger has been selected, conversion will start at next */
mbed_official 489:119543c9f674 730 /* trigger event. */
mbed_official 489:119543c9f674 731 /* Note: Alternate trigger for single conversion could be to force an */
mbed_official 489:119543c9f674 732 /* additional set of bit ADON "hadc->Instance->CR2 |= ADC_CR2_ADON;"*/
mbed_official 489:119543c9f674 733 if (ADC_IS_SOFTWARE_START_REGULAR(hadc))
mbed_official 489:119543c9f674 734 {
mbed_official 489:119543c9f674 735 /* Start ADC conversion on regular group with SW start */
mbed_official 489:119543c9f674 736 SET_BIT(hadc->Instance->CR2, (ADC_CR2_SWSTART | ADC_CR2_EXTTRIG));
mbed_official 489:119543c9f674 737 }
mbed_official 489:119543c9f674 738 else
mbed_official 489:119543c9f674 739 {
mbed_official 489:119543c9f674 740 /* Start ADC conversion on regular group with external trigger */
mbed_official 489:119543c9f674 741 SET_BIT(hadc->Instance->CR2, ADC_CR2_EXTTRIG);
mbed_official 489:119543c9f674 742 }
mbed_official 489:119543c9f674 743 }
mbed_official 489:119543c9f674 744 else
mbed_official 489:119543c9f674 745 {
mbed_official 489:119543c9f674 746 /* Process unlocked */
mbed_official 489:119543c9f674 747 __HAL_UNLOCK(hadc);
mbed_official 489:119543c9f674 748 }
mbed_official 489:119543c9f674 749
mbed_official 489:119543c9f674 750 /* Return function status */
mbed_official 489:119543c9f674 751 return tmp_hal_status;
mbed_official 489:119543c9f674 752 }
mbed_official 489:119543c9f674 753
mbed_official 489:119543c9f674 754 /**
mbed_official 489:119543c9f674 755 * @brief Stop ADC conversion of regular group (and injected channels in
mbed_official 489:119543c9f674 756 * case of auto_injection mode), disable ADC DMA transfer, disable
mbed_official 489:119543c9f674 757 * ADC peripheral.
mbed_official 489:119543c9f674 758 * @note Multimode is kept enabled after this function. To disable multimode
mbed_official 489:119543c9f674 759 * (set with HAL_ADCEx_MultiModeConfigChannel(), ADC must be
mbed_official 489:119543c9f674 760 * reinitialized using HAL_ADC_Init() or HAL_ADC_ReInit().
mbed_official 489:119543c9f674 761 * @note In case of DMA configured in circular mode, function
mbed_official 489:119543c9f674 762 * HAL_ADC_Stop_DMA must be called after this function with handle of
mbed_official 489:119543c9f674 763 * ADC slave, to properly disable the DMA channel.
mbed_official 489:119543c9f674 764 * @param hadc: ADC handle of ADC master (handle of ADC slave must not be used)
mbed_official 489:119543c9f674 765 * @retval None
mbed_official 489:119543c9f674 766 */
mbed_official 489:119543c9f674 767 HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc)
mbed_official 489:119543c9f674 768 {
mbed_official 489:119543c9f674 769 HAL_StatusTypeDef tmp_hal_status = HAL_OK;
mbed_official 489:119543c9f674 770 ADC_HandleTypeDef tmphadcSlave;
mbed_official 489:119543c9f674 771
mbed_official 489:119543c9f674 772 /* Check the parameters */
mbed_official 489:119543c9f674 773 assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance));
mbed_official 489:119543c9f674 774
mbed_official 489:119543c9f674 775 /* Process locked */
mbed_official 489:119543c9f674 776 __HAL_LOCK(hadc);
mbed_official 489:119543c9f674 777
mbed_official 489:119543c9f674 778
mbed_official 489:119543c9f674 779 /* Stop potential conversion on going, on regular and injected groups */
mbed_official 489:119543c9f674 780 /* Disable ADC master peripheral */
mbed_official 489:119543c9f674 781 tmp_hal_status = ADC_ConversionStop_Disable(hadc);
mbed_official 489:119543c9f674 782
mbed_official 489:119543c9f674 783 /* Check if ADC is effectively disabled */
mbed_official 489:119543c9f674 784 if (tmp_hal_status != HAL_ERROR)
mbed_official 489:119543c9f674 785 {
mbed_official 489:119543c9f674 786 /* Set a temporary handle of the ADC slave associated to the ADC master */
mbed_official 489:119543c9f674 787 ADC_MULTI_SLAVE(hadc, &tmphadcSlave);
mbed_official 489:119543c9f674 788
mbed_official 489:119543c9f674 789 if (tmphadcSlave.Instance == NULL)
mbed_official 489:119543c9f674 790 {
mbed_official 489:119543c9f674 791 /* Update ADC state machine to error */
mbed_official 489:119543c9f674 792 hadc->State = HAL_ADC_STATE_ERROR;
mbed_official 489:119543c9f674 793
mbed_official 489:119543c9f674 794 /* Process unlocked */
mbed_official 489:119543c9f674 795 __HAL_UNLOCK(hadc);
mbed_official 489:119543c9f674 796
mbed_official 489:119543c9f674 797 return HAL_ERROR;
mbed_official 489:119543c9f674 798 }
mbed_official 489:119543c9f674 799 else
mbed_official 489:119543c9f674 800 {
mbed_official 489:119543c9f674 801 /* Disable ADC slave peripheral */
mbed_official 489:119543c9f674 802 tmp_hal_status = ADC_ConversionStop_Disable(&tmphadcSlave);
mbed_official 489:119543c9f674 803
mbed_official 489:119543c9f674 804 /* Check if ADC is effectively disabled */
mbed_official 489:119543c9f674 805 if (tmp_hal_status != HAL_OK)
mbed_official 489:119543c9f674 806 {
mbed_official 489:119543c9f674 807 /* Update ADC state machine to error */
mbed_official 489:119543c9f674 808 hadc->State = HAL_ADC_STATE_ERROR;
mbed_official 489:119543c9f674 809
mbed_official 489:119543c9f674 810 /* Process unlocked */
mbed_official 489:119543c9f674 811 __HAL_UNLOCK(hadc);
mbed_official 489:119543c9f674 812
mbed_official 489:119543c9f674 813 return HAL_ERROR;
mbed_official 489:119543c9f674 814 }
mbed_official 489:119543c9f674 815 }
mbed_official 489:119543c9f674 816
mbed_official 489:119543c9f674 817 /* Disable ADC DMA mode */
mbed_official 489:119543c9f674 818 CLEAR_BIT(hadc->Instance->CR2, ADC_CR2_DMA);
mbed_official 489:119543c9f674 819
mbed_official 489:119543c9f674 820 /* Reset configuration of ADC DMA continuous request for dual mode */
mbed_official 489:119543c9f674 821 CLEAR_BIT(hadc->Instance->CR1, ADC_CR1_DUALMOD);
mbed_official 489:119543c9f674 822
mbed_official 489:119543c9f674 823 /* Disable the DMA channel (in case of DMA in circular mode or stop while */
mbed_official 489:119543c9f674 824 /* while DMA transfer is on going) */
mbed_official 489:119543c9f674 825 tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle);
mbed_official 489:119543c9f674 826
mbed_official 489:119543c9f674 827
mbed_official 489:119543c9f674 828 /* Check if DMA channel effectively disabled */
mbed_official 489:119543c9f674 829 if (tmp_hal_status != HAL_ERROR)
mbed_official 489:119543c9f674 830 {
mbed_official 489:119543c9f674 831 /* Change ADC state (ADC master) */
mbed_official 489:119543c9f674 832 hadc->State = HAL_ADC_STATE_READY;
mbed_official 489:119543c9f674 833 }
mbed_official 489:119543c9f674 834 else
mbed_official 489:119543c9f674 835 {
mbed_official 489:119543c9f674 836 /* Update ADC state machine to error */
mbed_official 489:119543c9f674 837 hadc->State = HAL_ADC_STATE_ERROR;
mbed_official 489:119543c9f674 838 }
mbed_official 489:119543c9f674 839 }
mbed_official 489:119543c9f674 840
mbed_official 489:119543c9f674 841 /* Process unlocked */
mbed_official 489:119543c9f674 842 __HAL_UNLOCK(hadc);
mbed_official 489:119543c9f674 843
mbed_official 489:119543c9f674 844 /* Return function status */
mbed_official 489:119543c9f674 845 return tmp_hal_status;
mbed_official 489:119543c9f674 846 }
mbed_official 489:119543c9f674 847 #endif /* STM32F101xG || defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
mbed_official 489:119543c9f674 848
mbed_official 489:119543c9f674 849 /**
mbed_official 489:119543c9f674 850 * @brief Get ADC injected group conversion result.
mbed_official 489:119543c9f674 851 * @param hadc: ADC handle
mbed_official 489:119543c9f674 852 * @param InjectedRank: the converted ADC injected rank.
mbed_official 489:119543c9f674 853 * This parameter can be one of the following values:
mbed_official 489:119543c9f674 854 * @arg ADC_INJECTED_RANK_1: Injected Channel1 selected
mbed_official 489:119543c9f674 855 * @arg ADC_INJECTED_RANK_2: Injected Channel2 selected
mbed_official 489:119543c9f674 856 * @arg ADC_INJECTED_RANK_3: Injected Channel3 selected
mbed_official 489:119543c9f674 857 * @arg ADC_INJECTED_RANK_4: Injected Channel4 selected
mbed_official 489:119543c9f674 858 * @retval None
mbed_official 489:119543c9f674 859 */
mbed_official 489:119543c9f674 860 uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef* hadc, uint32_t InjectedRank)
mbed_official 489:119543c9f674 861 {
mbed_official 489:119543c9f674 862 uint32_t tmp_jdr = 0;
mbed_official 489:119543c9f674 863
mbed_official 489:119543c9f674 864 /* Check the parameters */
mbed_official 489:119543c9f674 865 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
mbed_official 489:119543c9f674 866 assert_param(IS_ADC_INJECTED_RANK(InjectedRank));
mbed_official 489:119543c9f674 867
mbed_official 489:119543c9f674 868 /* Clear injected group conversion flag to have similar behaviour as */
mbed_official 489:119543c9f674 869 /* regular group: reading data register also clears end of conversion flag. */
mbed_official 489:119543c9f674 870 __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_JEOC);
mbed_official 489:119543c9f674 871
mbed_official 489:119543c9f674 872 /* Get ADC converted value */
mbed_official 489:119543c9f674 873 switch(InjectedRank)
mbed_official 489:119543c9f674 874 {
mbed_official 489:119543c9f674 875 case ADC_INJECTED_RANK_4:
mbed_official 489:119543c9f674 876 tmp_jdr = hadc->Instance->JDR4;
mbed_official 489:119543c9f674 877 break;
mbed_official 489:119543c9f674 878 case ADC_INJECTED_RANK_3:
mbed_official 489:119543c9f674 879 tmp_jdr = hadc->Instance->JDR3;
mbed_official 489:119543c9f674 880 break;
mbed_official 489:119543c9f674 881 case ADC_INJECTED_RANK_2:
mbed_official 489:119543c9f674 882 tmp_jdr = hadc->Instance->JDR2;
mbed_official 489:119543c9f674 883 break;
mbed_official 489:119543c9f674 884 case ADC_INJECTED_RANK_1:
mbed_official 489:119543c9f674 885 default:
mbed_official 489:119543c9f674 886 tmp_jdr = hadc->Instance->JDR1;
mbed_official 489:119543c9f674 887 break;
mbed_official 489:119543c9f674 888 }
mbed_official 489:119543c9f674 889
mbed_official 489:119543c9f674 890 /* Return ADC converted value */
mbed_official 489:119543c9f674 891 return tmp_jdr;
mbed_official 489:119543c9f674 892 }
mbed_official 489:119543c9f674 893
mbed_official 489:119543c9f674 894 #if defined (STM32F101xG) || defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
mbed_official 489:119543c9f674 895 /**
mbed_official 489:119543c9f674 896 * @brief Returns the last ADC Master&Slave regular conversions results data
mbed_official 489:119543c9f674 897 * in the selected multi mode.
mbed_official 489:119543c9f674 898 * @param hadc: ADC handle of ADC master (handle of ADC slave must not be used)
mbed_official 489:119543c9f674 899 * @retval The converted data value.
mbed_official 489:119543c9f674 900 */
mbed_official 489:119543c9f674 901 uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef* hadc)
mbed_official 489:119543c9f674 902 {
mbed_official 489:119543c9f674 903 uint32_t tmpDR = 0;
mbed_official 489:119543c9f674 904
mbed_official 489:119543c9f674 905 /* Check the parameters */
mbed_official 489:119543c9f674 906 assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance));
mbed_official 489:119543c9f674 907
mbed_official 489:119543c9f674 908 /* Check the parameters */
mbed_official 489:119543c9f674 909 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
mbed_official 489:119543c9f674 910
mbed_official 489:119543c9f674 911 /* Note: EOC flag is not cleared here by software because automatically */
mbed_official 489:119543c9f674 912 /* cleared by hardware when reading register DR. */
mbed_official 489:119543c9f674 913
mbed_official 489:119543c9f674 914 /* On STM32F1 devices, ADC1 data register DR contains ADC2 conversions */
mbed_official 489:119543c9f674 915 /* only if ADC1 DMA mode is enabled. */
mbed_official 489:119543c9f674 916 tmpDR = hadc->Instance->DR;
mbed_official 489:119543c9f674 917
mbed_official 489:119543c9f674 918 if (HAL_IS_BIT_CLR(ADC1->CR2, ADC_CR2_DMA))
mbed_official 489:119543c9f674 919 {
mbed_official 489:119543c9f674 920 tmpDR |= (ADC2->DR << 16);
mbed_official 489:119543c9f674 921 }
mbed_official 489:119543c9f674 922
mbed_official 489:119543c9f674 923 /* Return ADC converted value */
mbed_official 489:119543c9f674 924 return tmpDR;
mbed_official 489:119543c9f674 925 }
mbed_official 489:119543c9f674 926 #endif /* STM32F101xG || defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
mbed_official 489:119543c9f674 927
mbed_official 489:119543c9f674 928 /**
mbed_official 489:119543c9f674 929 * @brief Injected conversion complete callback in non blocking mode
mbed_official 489:119543c9f674 930 * @param hadc: ADC handle
mbed_official 489:119543c9f674 931 * @retval None
mbed_official 489:119543c9f674 932 */
mbed_official 489:119543c9f674 933 __weak void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc)
mbed_official 489:119543c9f674 934 {
mbed_official 489:119543c9f674 935 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 489:119543c9f674 936 the HAL_ADCEx_InjectedConvCpltCallback could be implemented in the user file
mbed_official 489:119543c9f674 937 */
mbed_official 489:119543c9f674 938 }
mbed_official 489:119543c9f674 939
mbed_official 489:119543c9f674 940 /**
mbed_official 489:119543c9f674 941 * @}
mbed_official 489:119543c9f674 942 */
mbed_official 489:119543c9f674 943
mbed_official 489:119543c9f674 944 /** @defgroup ADCEx_Exported_Functions_Group2 Extended Peripheral Control functions
mbed_official 489:119543c9f674 945 * @brief Extended Peripheral Control functions
mbed_official 489:119543c9f674 946 *
mbed_official 489:119543c9f674 947 @verbatim
mbed_official 489:119543c9f674 948 ===============================================================================
mbed_official 489:119543c9f674 949 ##### Peripheral Control functions #####
mbed_official 489:119543c9f674 950 ===============================================================================
mbed_official 489:119543c9f674 951 [..] This section provides functions allowing to:
mbed_official 489:119543c9f674 952 (+) Configure channels on injected group
mbed_official 489:119543c9f674 953 (+) Configure multimode
mbed_official 489:119543c9f674 954
mbed_official 489:119543c9f674 955 @endverbatim
mbed_official 489:119543c9f674 956 * @{
mbed_official 489:119543c9f674 957 */
mbed_official 489:119543c9f674 958
mbed_official 489:119543c9f674 959 /**
mbed_official 489:119543c9f674 960 * @brief Configures the ADC injected group and the selected channel to be
mbed_official 489:119543c9f674 961 * linked to the injected group.
mbed_official 489:119543c9f674 962 * @note Possibility to update parameters on the fly:
mbed_official 489:119543c9f674 963 * This function initializes injected group, following calls to this
mbed_official 489:119543c9f674 964 * function can be used to reconfigure some parameters of structure
mbed_official 489:119543c9f674 965 * "ADC_InjectionConfTypeDef" on the fly, without reseting the ADC.
mbed_official 489:119543c9f674 966 * The setting of these parameters is conditioned to ADC state:
mbed_official 489:119543c9f674 967 * this function must be called when ADC is not under conversion.
mbed_official 489:119543c9f674 968 * @param hadc: ADC handle
mbed_official 489:119543c9f674 969 * @param sConfigInjected: Structure of ADC injected group and ADC channel for
mbed_official 489:119543c9f674 970 * injected group.
mbed_official 489:119543c9f674 971 * @retval None
mbed_official 489:119543c9f674 972 */
mbed_official 489:119543c9f674 973 HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_InjectionConfTypeDef* sConfigInjected)
mbed_official 489:119543c9f674 974 {
mbed_official 489:119543c9f674 975 HAL_StatusTypeDef tmp_hal_status = HAL_OK;
mbed_official 489:119543c9f674 976 __IO uint32_t wait_loop_index = 0;
mbed_official 489:119543c9f674 977
mbed_official 489:119543c9f674 978 /* Check the parameters */
mbed_official 489:119543c9f674 979 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
mbed_official 489:119543c9f674 980 assert_param(IS_ADC_CHANNEL(sConfigInjected->InjectedChannel));
mbed_official 489:119543c9f674 981 assert_param(IS_ADC_SAMPLE_TIME(sConfigInjected->InjectedSamplingTime));
mbed_official 489:119543c9f674 982 assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->AutoInjectedConv));
mbed_official 489:119543c9f674 983 assert_param(IS_ADC_EXTTRIGINJEC(sConfigInjected->ExternalTrigInjecConv));
mbed_official 489:119543c9f674 984 assert_param(IS_ADC_RANGE(sConfigInjected->InjectedOffset));
mbed_official 489:119543c9f674 985
mbed_official 489:119543c9f674 986 if(hadc->Init.ScanConvMode != ADC_SCAN_DISABLE)
mbed_official 489:119543c9f674 987 {
mbed_official 489:119543c9f674 988 assert_param(IS_ADC_INJECTED_RANK(sConfigInjected->InjectedRank));
mbed_official 489:119543c9f674 989 assert_param(IS_ADC_INJECTED_NB_CONV(sConfigInjected->InjectedNbrOfConversion));
mbed_official 489:119543c9f674 990 assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->InjectedDiscontinuousConvMode));
mbed_official 489:119543c9f674 991 }
mbed_official 489:119543c9f674 992
mbed_official 489:119543c9f674 993 /* Process locked */
mbed_official 489:119543c9f674 994 __HAL_LOCK(hadc);
mbed_official 489:119543c9f674 995
mbed_official 489:119543c9f674 996 /* Configuration of injected group sequencer: */
mbed_official 489:119543c9f674 997 /* - if scan mode is disabled, injected channels sequence length is set to */
mbed_official 489:119543c9f674 998 /* 0x00: 1 channel converted (channel on regular rank 1) */
mbed_official 489:119543c9f674 999 /* Parameter "InjectedNbrOfConversion" is discarded. */
mbed_official 489:119543c9f674 1000 /* Note: Scan mode is present by hardware on this device and, if */
mbed_official 489:119543c9f674 1001 /* disabled, discards automatically nb of conversions. Anyway, nb of */
mbed_official 489:119543c9f674 1002 /* conversions is forced to 0x00 for alignment over all STM32 devices. */
mbed_official 489:119543c9f674 1003 /* - if scan mode is enabled, injected channels sequence length is set to */
mbed_official 489:119543c9f674 1004 /* parameter "InjectedNbrOfConversion". */
mbed_official 489:119543c9f674 1005 if (hadc->Init.ScanConvMode == ADC_SCAN_DISABLE)
mbed_official 489:119543c9f674 1006 {
mbed_official 489:119543c9f674 1007 if (sConfigInjected->InjectedRank == ADC_INJECTED_RANK_1)
mbed_official 489:119543c9f674 1008 {
mbed_official 489:119543c9f674 1009 /* Clear the old SQx bits for all injected ranks */
mbed_official 489:119543c9f674 1010 MODIFY_REG(hadc->Instance->JSQR ,
mbed_official 489:119543c9f674 1011 ADC_JSQR_JL |
mbed_official 489:119543c9f674 1012 ADC_JSQR_JSQ4 |
mbed_official 489:119543c9f674 1013 ADC_JSQR_JSQ3 |
mbed_official 489:119543c9f674 1014 ADC_JSQR_JSQ2 |
mbed_official 489:119543c9f674 1015 ADC_JSQR_JSQ1 ,
mbed_official 489:119543c9f674 1016 ADC_JSQR_RK_JL(sConfigInjected->InjectedChannel,
mbed_official 489:119543c9f674 1017 ADC_INJECTED_RANK_1,
mbed_official 489:119543c9f674 1018 0x01) );
mbed_official 489:119543c9f674 1019 }
mbed_official 489:119543c9f674 1020 /* If another injected rank than rank1 was intended to be set, and could */
mbed_official 489:119543c9f674 1021 /* not due to ScanConvMode disabled, error is reported. */
mbed_official 489:119543c9f674 1022 else
mbed_official 489:119543c9f674 1023 {
mbed_official 489:119543c9f674 1024 /* Update ADC state machine to error */
mbed_official 489:119543c9f674 1025 hadc->State = HAL_ADC_STATE_ERROR;
mbed_official 489:119543c9f674 1026
mbed_official 489:119543c9f674 1027 tmp_hal_status = HAL_ERROR;
mbed_official 489:119543c9f674 1028 }
mbed_official 489:119543c9f674 1029 }
mbed_official 489:119543c9f674 1030 else
mbed_official 489:119543c9f674 1031 {
mbed_official 489:119543c9f674 1032 /* Since injected channels rank conv. order depends on total number of */
mbed_official 489:119543c9f674 1033 /* injected conversions, selected rank must be below or equal to total */
mbed_official 489:119543c9f674 1034 /* number of injected conversions to be updated. */
mbed_official 489:119543c9f674 1035 if (sConfigInjected->InjectedRank <= sConfigInjected->InjectedNbrOfConversion)
mbed_official 489:119543c9f674 1036 {
mbed_official 489:119543c9f674 1037 /* Clear the old SQx bits for the selected rank */
mbed_official 489:119543c9f674 1038 /* Set the SQx bits for the selected rank */
mbed_official 489:119543c9f674 1039 MODIFY_REG(hadc->Instance->JSQR ,
mbed_official 489:119543c9f674 1040
mbed_official 489:119543c9f674 1041 ADC_JSQR_JL |
mbed_official 489:119543c9f674 1042 ADC_JSQR_RK_JL(ADC_JSQR_JSQ1,
mbed_official 489:119543c9f674 1043 sConfigInjected->InjectedRank,
mbed_official 489:119543c9f674 1044 sConfigInjected->InjectedNbrOfConversion) ,
mbed_official 489:119543c9f674 1045
mbed_official 489:119543c9f674 1046 ADC_JSQR_JL_SHIFT(sConfigInjected->InjectedNbrOfConversion) |
mbed_official 489:119543c9f674 1047 ADC_JSQR_RK_JL(sConfigInjected->InjectedChannel,
mbed_official 489:119543c9f674 1048 sConfigInjected->InjectedRank,
mbed_official 489:119543c9f674 1049 sConfigInjected->InjectedNbrOfConversion) );
mbed_official 489:119543c9f674 1050 }
mbed_official 489:119543c9f674 1051 else
mbed_official 489:119543c9f674 1052 {
mbed_official 489:119543c9f674 1053 /* Clear the old SQx bits for the selected rank */
mbed_official 489:119543c9f674 1054 MODIFY_REG(hadc->Instance->JSQR ,
mbed_official 489:119543c9f674 1055
mbed_official 489:119543c9f674 1056 ADC_JSQR_JL |
mbed_official 489:119543c9f674 1057 ADC_JSQR_RK_JL(ADC_JSQR_JSQ1,
mbed_official 489:119543c9f674 1058 sConfigInjected->InjectedRank,
mbed_official 489:119543c9f674 1059 sConfigInjected->InjectedNbrOfConversion) ,
mbed_official 489:119543c9f674 1060
mbed_official 489:119543c9f674 1061 0x00000000 );
mbed_official 489:119543c9f674 1062 }
mbed_official 489:119543c9f674 1063 }
mbed_official 489:119543c9f674 1064
mbed_official 489:119543c9f674 1065 /* Configuration of injected group */
mbed_official 489:119543c9f674 1066 /* Parameters update conditioned to ADC state: */
mbed_official 489:119543c9f674 1067 /* Parameters that can be updated only when ADC is disabled: */
mbed_official 489:119543c9f674 1068 /* - external trigger to start conversion */
mbed_official 489:119543c9f674 1069 /* Parameters update not conditioned to ADC state: */
mbed_official 489:119543c9f674 1070 /* - Automatic injected conversion */
mbed_official 489:119543c9f674 1071 /* - Injected discontinuous mode */
mbed_official 489:119543c9f674 1072 /* Note: In case of ADC already enabled, caution to not launch an unwanted */
mbed_official 489:119543c9f674 1073 /* conversion while modifying register CR2 by writing 1 to bit ADON. */
mbed_official 489:119543c9f674 1074 if (ADC_IS_ENABLE(hadc) == RESET)
mbed_official 489:119543c9f674 1075 {
mbed_official 489:119543c9f674 1076 MODIFY_REG(hadc->Instance->CR2 ,
mbed_official 489:119543c9f674 1077 ADC_CR2_JEXTSEL |
mbed_official 489:119543c9f674 1078 ADC_CR2_ADON ,
mbed_official 489:119543c9f674 1079 ADC_CFGR_JEXTSEL(hadc, sConfigInjected->ExternalTrigInjecConv) );
mbed_official 489:119543c9f674 1080 }
mbed_official 489:119543c9f674 1081
mbed_official 489:119543c9f674 1082
mbed_official 489:119543c9f674 1083 /* Configuration of injected group */
mbed_official 489:119543c9f674 1084 /* - Automatic injected conversion */
mbed_official 489:119543c9f674 1085 /* - Injected discontinuous mode */
mbed_official 489:119543c9f674 1086
mbed_official 489:119543c9f674 1087 /* Automatic injected conversion can be enabled if injected group */
mbed_official 489:119543c9f674 1088 /* external triggers are disabled. */
mbed_official 489:119543c9f674 1089 if (sConfigInjected->AutoInjectedConv == ENABLE)
mbed_official 489:119543c9f674 1090 {
mbed_official 489:119543c9f674 1091 if (sConfigInjected->ExternalTrigInjecConv == ADC_INJECTED_SOFTWARE_START)
mbed_official 489:119543c9f674 1092 {
mbed_official 489:119543c9f674 1093 SET_BIT(hadc->Instance->CR1, ADC_CR1_JAUTO);
mbed_official 489:119543c9f674 1094 }
mbed_official 489:119543c9f674 1095 else
mbed_official 489:119543c9f674 1096 {
mbed_official 489:119543c9f674 1097 /* Update ADC state machine to error */
mbed_official 489:119543c9f674 1098 hadc->State = HAL_ADC_STATE_ERROR;
mbed_official 489:119543c9f674 1099
mbed_official 489:119543c9f674 1100 tmp_hal_status = HAL_ERROR;
mbed_official 489:119543c9f674 1101 }
mbed_official 489:119543c9f674 1102 }
mbed_official 489:119543c9f674 1103
mbed_official 489:119543c9f674 1104 /* Injected discontinuous can be enabled only if auto-injected mode is */
mbed_official 489:119543c9f674 1105 /* disabled. */
mbed_official 489:119543c9f674 1106 if (sConfigInjected->InjectedDiscontinuousConvMode == ENABLE)
mbed_official 489:119543c9f674 1107 {
mbed_official 489:119543c9f674 1108 if (sConfigInjected->AutoInjectedConv == DISABLE)
mbed_official 489:119543c9f674 1109 {
mbed_official 489:119543c9f674 1110 SET_BIT(hadc->Instance->CR1, ADC_CR1_JDISCEN);
mbed_official 489:119543c9f674 1111 }
mbed_official 489:119543c9f674 1112 else
mbed_official 489:119543c9f674 1113 {
mbed_official 489:119543c9f674 1114 /* Update ADC state machine to error */
mbed_official 489:119543c9f674 1115 hadc->State = HAL_ADC_STATE_ERROR;
mbed_official 489:119543c9f674 1116
mbed_official 489:119543c9f674 1117 tmp_hal_status = HAL_ERROR;
mbed_official 489:119543c9f674 1118 }
mbed_official 489:119543c9f674 1119 }
mbed_official 489:119543c9f674 1120
mbed_official 489:119543c9f674 1121
mbed_official 489:119543c9f674 1122 /* InjectedChannel sampling time configuration */
mbed_official 489:119543c9f674 1123 /* For channels 10 to 17 */
mbed_official 489:119543c9f674 1124 if (sConfigInjected->InjectedChannel >= ADC_CHANNEL_10)
mbed_official 489:119543c9f674 1125 {
mbed_official 489:119543c9f674 1126 MODIFY_REG(hadc->Instance->SMPR1 ,
mbed_official 489:119543c9f674 1127 ADC_SMPR1(ADC_SMPR1_SMP10, sConfigInjected->InjectedChannel) ,
mbed_official 489:119543c9f674 1128 ADC_SMPR1(sConfigInjected->InjectedSamplingTime, sConfigInjected->InjectedChannel) );
mbed_official 489:119543c9f674 1129 }
mbed_official 489:119543c9f674 1130 else /* For channels 0 to 9 */
mbed_official 489:119543c9f674 1131 {
mbed_official 489:119543c9f674 1132 MODIFY_REG(hadc->Instance->SMPR2 ,
mbed_official 489:119543c9f674 1133 ADC_SMPR2(ADC_SMPR2_SMP0, sConfigInjected->InjectedChannel) ,
mbed_official 489:119543c9f674 1134 ADC_SMPR2(sConfigInjected->InjectedSamplingTime, sConfigInjected->InjectedChannel) );
mbed_official 489:119543c9f674 1135 }
mbed_official 489:119543c9f674 1136
mbed_official 489:119543c9f674 1137 /* If ADC1 InjectedChannel_16 or InjectedChannel_17 is selected, enable Temperature sensor */
mbed_official 489:119543c9f674 1138 /* and VREFINT measurement path. */
mbed_official 489:119543c9f674 1139 if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR) ||
mbed_official 489:119543c9f674 1140 (sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT) )
mbed_official 489:119543c9f674 1141 {
mbed_official 489:119543c9f674 1142 SET_BIT(hadc->Instance->CR2, ADC_CR2_TSVREFE);
mbed_official 489:119543c9f674 1143 }
mbed_official 489:119543c9f674 1144
mbed_official 489:119543c9f674 1145
mbed_official 489:119543c9f674 1146 /* Configure the offset: offset enable/disable, InjectedChannel, offset value */
mbed_official 489:119543c9f674 1147 switch(sConfigInjected->InjectedRank)
mbed_official 489:119543c9f674 1148 {
mbed_official 489:119543c9f674 1149 case 1:
mbed_official 489:119543c9f674 1150 /* Set injected channel 1 offset */
mbed_official 489:119543c9f674 1151 MODIFY_REG(hadc->Instance->JOFR1,
mbed_official 489:119543c9f674 1152 ADC_JOFR1_JOFFSET1,
mbed_official 489:119543c9f674 1153 sConfigInjected->InjectedOffset);
mbed_official 489:119543c9f674 1154 break;
mbed_official 489:119543c9f674 1155 case 2:
mbed_official 489:119543c9f674 1156 /* Set injected channel 2 offset */
mbed_official 489:119543c9f674 1157 MODIFY_REG(hadc->Instance->JOFR2,
mbed_official 489:119543c9f674 1158 ADC_JOFR2_JOFFSET2,
mbed_official 489:119543c9f674 1159 sConfigInjected->InjectedOffset);
mbed_official 489:119543c9f674 1160 break;
mbed_official 489:119543c9f674 1161 case 3:
mbed_official 489:119543c9f674 1162 /* Set injected channel 3 offset */
mbed_official 489:119543c9f674 1163 MODIFY_REG(hadc->Instance->JOFR3,
mbed_official 489:119543c9f674 1164 ADC_JOFR3_JOFFSET3,
mbed_official 489:119543c9f674 1165 sConfigInjected->InjectedOffset);
mbed_official 489:119543c9f674 1166 break;
mbed_official 489:119543c9f674 1167 case 4:
mbed_official 489:119543c9f674 1168 default:
mbed_official 489:119543c9f674 1169 MODIFY_REG(hadc->Instance->JOFR4,
mbed_official 489:119543c9f674 1170 ADC_JOFR4_JOFFSET4,
mbed_official 489:119543c9f674 1171 sConfigInjected->InjectedOffset);
mbed_official 489:119543c9f674 1172 break;
mbed_official 489:119543c9f674 1173 }
mbed_official 489:119543c9f674 1174
mbed_official 489:119543c9f674 1175 /* If ADC1 Channel_16 or Channel_17 is selected, enable Temperature sensor */
mbed_official 489:119543c9f674 1176 /* and VREFINT measurement path. */
mbed_official 489:119543c9f674 1177 if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR) ||
mbed_official 489:119543c9f674 1178 (sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT) )
mbed_official 489:119543c9f674 1179 {
mbed_official 489:119543c9f674 1180 /* For STM32F1 devices with several ADC: Only ADC1 can access internal */
mbed_official 489:119543c9f674 1181 /* measurement channels (VrefInt/TempSensor). If these channels are */
mbed_official 489:119543c9f674 1182 /* intended to be set on other ADC instances, an error is reported. */
mbed_official 489:119543c9f674 1183 if (hadc->Instance == ADC1)
mbed_official 489:119543c9f674 1184 {
mbed_official 489:119543c9f674 1185 if (READ_BIT(hadc->Instance->CR2, ADC_CR2_TSVREFE) == RESET)
mbed_official 489:119543c9f674 1186 {
mbed_official 489:119543c9f674 1187 SET_BIT(hadc->Instance->CR2, ADC_CR2_TSVREFE);
mbed_official 489:119543c9f674 1188
mbed_official 489:119543c9f674 1189 if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR))
mbed_official 489:119543c9f674 1190 {
mbed_official 489:119543c9f674 1191 /* Delay for temperature sensor stabilization time */
mbed_official 489:119543c9f674 1192 /* Compute number of CPU cycles to wait for */
mbed_official 489:119543c9f674 1193 wait_loop_index = (ADC_TEMPSENSOR_DELAY_US * (SystemCoreClock / 1000000));
mbed_official 489:119543c9f674 1194 while(wait_loop_index != 0)
mbed_official 489:119543c9f674 1195 {
mbed_official 489:119543c9f674 1196 wait_loop_index--;
mbed_official 489:119543c9f674 1197 }
mbed_official 489:119543c9f674 1198 }
mbed_official 489:119543c9f674 1199 }
mbed_official 489:119543c9f674 1200 }
mbed_official 489:119543c9f674 1201 else
mbed_official 489:119543c9f674 1202 {
mbed_official 489:119543c9f674 1203 /* Update ADC state machine to error */
mbed_official 489:119543c9f674 1204 hadc->State = HAL_ADC_STATE_ERROR;
mbed_official 489:119543c9f674 1205
mbed_official 489:119543c9f674 1206 tmp_hal_status = HAL_ERROR;
mbed_official 489:119543c9f674 1207 }
mbed_official 489:119543c9f674 1208 }
mbed_official 489:119543c9f674 1209
mbed_official 489:119543c9f674 1210 /* Process unlocked */
mbed_official 489:119543c9f674 1211 __HAL_UNLOCK(hadc);
mbed_official 489:119543c9f674 1212
mbed_official 489:119543c9f674 1213 /* Return function status */
mbed_official 489:119543c9f674 1214 return tmp_hal_status;
mbed_official 489:119543c9f674 1215 }
mbed_official 489:119543c9f674 1216
mbed_official 489:119543c9f674 1217 #if defined (STM32F101xG) || defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
mbed_official 489:119543c9f674 1218 /**
mbed_official 489:119543c9f674 1219 * @brief Enable ADC multimode and configure multimode parameters
mbed_official 489:119543c9f674 1220 * @note Possibility to update parameters on the fly:
mbed_official 489:119543c9f674 1221 * This function initializes multimode parameters, following
mbed_official 489:119543c9f674 1222 * calls to this function can be used to reconfigure some parameters
mbed_official 489:119543c9f674 1223 * of structure "ADC_MultiModeTypeDef" on the fly, without reseting
mbed_official 489:119543c9f674 1224 * the ADCs (both ADCs of the common group).
mbed_official 489:119543c9f674 1225 * The setting of these parameters is conditioned to ADC state.
mbed_official 489:119543c9f674 1226 * For parameters constraints, see comments of structure
mbed_official 489:119543c9f674 1227 * "ADC_MultiModeTypeDef".
mbed_official 489:119543c9f674 1228 * @note To change back configuration from multimode to single mode, ADC must
mbed_official 489:119543c9f674 1229 * be reset (using function HAL_ADC_Init() ).
mbed_official 489:119543c9f674 1230 * @param hadc: ADC handle
mbed_official 489:119543c9f674 1231 * @param multimode: Structure of ADC multimode configuration
mbed_official 489:119543c9f674 1232 * @retval HAL status
mbed_official 489:119543c9f674 1233 */
mbed_official 489:119543c9f674 1234 HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef* hadc, ADC_MultiModeTypeDef* multimode)
mbed_official 489:119543c9f674 1235 {
mbed_official 489:119543c9f674 1236 HAL_StatusTypeDef tmp_hal_status = HAL_OK;
mbed_official 489:119543c9f674 1237 ADC_HandleTypeDef tmphadcSlave;
mbed_official 489:119543c9f674 1238
mbed_official 489:119543c9f674 1239 /* Check the parameters */
mbed_official 489:119543c9f674 1240 assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance));
mbed_official 489:119543c9f674 1241 assert_param(IS_ADC_MODE(multimode->Mode));
mbed_official 489:119543c9f674 1242
mbed_official 489:119543c9f674 1243 /* Process locked */
mbed_official 489:119543c9f674 1244 __HAL_LOCK(hadc);
mbed_official 489:119543c9f674 1245
mbed_official 489:119543c9f674 1246 /* Set a temporary handle of the ADC slave associated to the ADC master */
mbed_official 489:119543c9f674 1247 ADC_MULTI_SLAVE(hadc, &tmphadcSlave);
mbed_official 489:119543c9f674 1248
mbed_official 489:119543c9f674 1249 /* Parameters update conditioned to ADC state: */
mbed_official 489:119543c9f674 1250 /* Parameters that can be updated when ADC is disabled or enabled without */
mbed_official 489:119543c9f674 1251 /* conversion on going on regular group: */
mbed_official 489:119543c9f674 1252 /* - ADC master and ADC slave DMA configuration */
mbed_official 489:119543c9f674 1253 /* Parameters that can be updated only when ADC is disabled: */
mbed_official 489:119543c9f674 1254 /* - Multimode mode selection */
mbed_official 489:119543c9f674 1255 /* To optimize code, all multimode settings can be set when both ADCs of */
mbed_official 489:119543c9f674 1256 /* the common group are in state: disabled. */
mbed_official 489:119543c9f674 1257 if ((ADC_IS_ENABLE(hadc) == RESET) &&
mbed_official 489:119543c9f674 1258 (ADC_IS_ENABLE(&tmphadcSlave) == RESET) &&
mbed_official 489:119543c9f674 1259 (IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance)) )
mbed_official 489:119543c9f674 1260 {
mbed_official 489:119543c9f674 1261 MODIFY_REG(hadc->Instance->CR1,
mbed_official 489:119543c9f674 1262 ADC_CR1_DUALMOD ,
mbed_official 489:119543c9f674 1263 multimode->Mode );
mbed_official 489:119543c9f674 1264 }
mbed_official 489:119543c9f674 1265 /* If one of the ADC sharing the same common group is enabled, no update */
mbed_official 489:119543c9f674 1266 /* could be done on neither of the multimode structure parameters. */
mbed_official 489:119543c9f674 1267 else
mbed_official 489:119543c9f674 1268 {
mbed_official 489:119543c9f674 1269 /* Update ADC state machine to error */
mbed_official 489:119543c9f674 1270 hadc->State = HAL_ADC_STATE_ERROR;
mbed_official 489:119543c9f674 1271
mbed_official 489:119543c9f674 1272 tmp_hal_status = HAL_ERROR;
mbed_official 489:119543c9f674 1273 }
mbed_official 489:119543c9f674 1274
mbed_official 489:119543c9f674 1275
mbed_official 489:119543c9f674 1276 /* Process unlocked */
mbed_official 489:119543c9f674 1277 __HAL_UNLOCK(hadc);
mbed_official 489:119543c9f674 1278
mbed_official 489:119543c9f674 1279 /* Return function status */
mbed_official 489:119543c9f674 1280 return tmp_hal_status;
mbed_official 489:119543c9f674 1281 }
mbed_official 489:119543c9f674 1282 #endif /* STM32F101xG || defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
mbed_official 489:119543c9f674 1283 /**
mbed_official 489:119543c9f674 1284 * @}
mbed_official 489:119543c9f674 1285 */
mbed_official 489:119543c9f674 1286
mbed_official 489:119543c9f674 1287 /**
mbed_official 489:119543c9f674 1288 * @}
mbed_official 489:119543c9f674 1289 */
mbed_official 489:119543c9f674 1290
mbed_official 489:119543c9f674 1291 #endif /* HAL_ADC_MODULE_ENABLED */
mbed_official 489:119543c9f674 1292 /**
mbed_official 489:119543c9f674 1293 * @}
mbed_official 489:119543c9f674 1294 */
mbed_official 489:119543c9f674 1295
mbed_official 489:119543c9f674 1296 /**
mbed_official 489:119543c9f674 1297 * @}
mbed_official 489:119543c9f674 1298 */
mbed_official 489:119543c9f674 1299
mbed_official 489:119543c9f674 1300 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/