STM32F479xx HAL User Manual
stm32f4xx_hal_adc_ex.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4xx_hal_adc_ex.c
00004   * @author  MCD Application Team
00005   * @brief   This file provides firmware functions to manage the following
00006   *          functionalities of the ADC extension peripheral:
00007   *           + Extended features functions
00008   *
00009   @verbatim
00010   ==============================================================================
00011                     ##### How to use this driver #####
00012   ==============================================================================
00013     [..]
00014     (#)Initialize the ADC low level resources by implementing the HAL_ADC_MspInit():
00015        (##) Enable the ADC interface clock using __HAL_RCC_ADC_CLK_ENABLE()
00016        (##) ADC pins configuration
00017              (+++) Enable the clock for the ADC GPIOs using the following function:
00018                    __HAL_RCC_GPIOx_CLK_ENABLE()
00019              (+++) Configure these ADC pins in analog mode using HAL_GPIO_Init()
00020        (##) In case of using interrupts (e.g. HAL_ADC_Start_IT())
00021              (+++) Configure the ADC interrupt priority using HAL_NVIC_SetPriority()
00022              (+++) Enable the ADC IRQ handler using HAL_NVIC_EnableIRQ()
00023              (+++) In ADC IRQ handler, call HAL_ADC_IRQHandler()
00024       (##) In case of using DMA to control data transfer (e.g. HAL_ADC_Start_DMA())
00025              (+++) Enable the DMAx interface clock using __HAL_RCC_DMAx_CLK_ENABLE()
00026              (+++) Configure and enable two DMA streams stream for managing data
00027                  transfer from peripheral to memory (output stream)
00028              (+++) Associate the initialized DMA handle to the ADC DMA handle
00029                  using  __HAL_LINKDMA()
00030              (+++) Configure the priority and enable the NVIC for the transfer complete
00031                  interrupt on the two DMA Streams. The output stream should have higher
00032                  priority than the input stream.
00033      (#) Configure the ADC Prescaler, conversion resolution and data alignment
00034          using the HAL_ADC_Init() function.
00035 
00036      (#) Configure the ADC Injected channels group features, use HAL_ADC_Init()
00037          and HAL_ADC_ConfigChannel() functions.
00038 
00039      (#) Three operation modes are available within this driver:
00040 
00041      *** Polling mode IO operation ***
00042      =================================
00043      [..]
00044        (+) Start the ADC peripheral using HAL_ADCEx_InjectedStart()
00045        (+) Wait for end of conversion using HAL_ADC_PollForConversion(), at this stage
00046            user can specify the value of timeout according to his end application
00047        (+) To read the ADC converted values, use the HAL_ADCEx_InjectedGetValue() function.
00048        (+) Stop the ADC peripheral using HAL_ADCEx_InjectedStop()
00049 
00050      *** Interrupt mode IO operation ***
00051      ===================================
00052      [..]
00053        (+) Start the ADC peripheral using HAL_ADCEx_InjectedStart_IT()
00054        (+) Use HAL_ADC_IRQHandler() called under ADC_IRQHandler() Interrupt subroutine
00055        (+) At ADC end of conversion HAL_ADCEx_InjectedConvCpltCallback() function is executed and user can
00056             add his own code by customization of function pointer HAL_ADCEx_InjectedConvCpltCallback 
00057        (+) In case of ADC Error, HAL_ADCEx_InjectedErrorCallback() function is executed and user can 
00058             add his own code by customization of function pointer HAL_ADCEx_InjectedErrorCallback
00059        (+) Stop the ADC peripheral using HAL_ADCEx_InjectedStop_IT()
00060 
00061      *** Multi mode ADCs Regular channels configuration ***
00062      ======================================================
00063      [..]
00064        (+) Select the Multi mode ADC regular channels features (dual or triple mode)
00065           and configure the DMA mode using HAL_ADCEx_MultiModeConfigChannel() functions.
00066        (+) Start the ADC peripheral using HAL_ADCEx_MultiModeStart_DMA(), at this stage the user specify the length
00067            of data to be transferred at each end of conversion
00068        (+) Read the ADCs converted values using the HAL_ADCEx_MultiModeGetValue() function.
00069 
00070 
00071     @endverbatim
00072   ******************************************************************************
00073   * @attention
00074   *
00075   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
00076   * All rights reserved.</center></h2>
00077   *
00078   * This software component is licensed by ST under BSD 3-Clause license,
00079   * the "License"; You may not use this file except in compliance with the
00080   * License. You may obtain a copy of the License at:
00081   *                        opensource.org/licenses/BSD-3-Clause
00082   *
00083   ******************************************************************************
00084   */
00085 
00086 /* Includes ------------------------------------------------------------------*/
00087 #include "stm32f4xx_hal.h"
00088 
00089 /** @addtogroup STM32F4xx_HAL_Driver
00090   * @{
00091   */
00092 
00093 /** @defgroup ADCEx ADCEx
00094   * @brief ADC Extended driver modules
00095   * @{
00096   */ 
00097 
00098 #ifdef HAL_ADC_MODULE_ENABLED
00099     
00100 /* Private typedef -----------------------------------------------------------*/
00101 /* Private define ------------------------------------------------------------*/ 
00102 /* Private macro -------------------------------------------------------------*/
00103 /* Private variables ---------------------------------------------------------*/
00104 /** @addtogroup ADCEx_Private_Functions
00105   * @{
00106   */
00107 /* Private function prototypes -----------------------------------------------*/
00108 static void ADC_MultiModeDMAConvCplt(DMA_HandleTypeDef *hdma);
00109 static void ADC_MultiModeDMAError(DMA_HandleTypeDef *hdma);
00110 static void ADC_MultiModeDMAHalfConvCplt(DMA_HandleTypeDef *hdma); 
00111 /**
00112   * @}
00113   */
00114 
00115 /* Exported functions --------------------------------------------------------*/
00116 /** @defgroup ADCEx_Exported_Functions ADC Exported Functions
00117   * @{
00118   */
00119 
00120 /** @defgroup ADCEx_Exported_Functions_Group1  Extended features functions 
00121   *  @brief    Extended features functions  
00122   *
00123 @verbatim   
00124  ===============================================================================
00125                  ##### Extended features functions #####
00126  ===============================================================================  
00127     [..]  This section provides functions allowing to:
00128       (+) Start conversion of injected channel.
00129       (+) Stop conversion of injected channel.
00130       (+) Start multimode and enable DMA transfer.
00131       (+) Stop multimode and disable DMA transfer.
00132       (+) Get result of injected channel conversion.
00133       (+) Get result of multimode conversion.
00134       (+) Configure injected channels.
00135       (+) Configure multimode.
00136                
00137 @endverbatim
00138   * @{
00139   */
00140 
00141 /**
00142   * @brief  Enables the selected ADC software start conversion of the injected channels.
00143   * @param  hadc pointer to a ADC_HandleTypeDef structure that contains
00144   *         the configuration information for the specified ADC.
00145   * @retval HAL status
00146   */
00147 HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
00148 {
00149   __IO uint32_t counter = 0U;
00150   uint32_t tmp1 = 0U, tmp2 = 0U;
00151   ADC_Common_TypeDef *tmpADC_Common;
00152   
00153   /* Process locked */
00154   __HAL_LOCK(hadc);
00155   
00156   /* Enable the ADC peripheral */
00157   
00158   /* Check if ADC peripheral is disabled in order to enable it and wait during 
00159      Tstab time the ADC's stabilization */
00160   if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON)
00161   {  
00162     /* Enable the Peripheral */
00163     __HAL_ADC_ENABLE(hadc);
00164     
00165     /* Delay for ADC stabilization time */
00166     /* Compute number of CPU cycles to wait for */
00167     counter = (ADC_STAB_DELAY_US * (SystemCoreClock / 1000000U));
00168     while(counter != 0U)
00169     {
00170       counter--;
00171     }
00172   }
00173   
00174   /* Start conversion if ADC is effectively enabled */
00175   if(HAL_IS_BIT_SET(hadc->Instance->CR2, ADC_CR2_ADON))
00176   {
00177     /* Set ADC state                                                          */
00178     /* - Clear state bitfield related to injected group conversion results    */
00179     /* - Set state bitfield related to injected operation                     */
00180     ADC_STATE_CLR_SET(hadc->State,
00181                       HAL_ADC_STATE_READY | HAL_ADC_STATE_INJ_EOC,
00182                       HAL_ADC_STATE_INJ_BUSY);
00183     
00184     /* Check if a regular conversion is ongoing */
00185     /* Note: On this device, there is no ADC error code fields related to     */
00186     /*       conversions on group injected only. In case of conversion on     */
00187     /*       going on group regular, no error code is reset.                  */
00188     if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_REG_BUSY))
00189     {
00190       /* Reset ADC all error code fields */
00191       ADC_CLEAR_ERRORCODE(hadc);
00192     }
00193     
00194     /* Process unlocked */
00195     /* Unlock before starting ADC conversions: in case of potential           */
00196     /* interruption, to let the process to ADC IRQ Handler.                   */
00197     __HAL_UNLOCK(hadc);
00198     
00199     /* Clear injected group conversion flag */
00200     /* (To ensure of no unknown state from potential previous ADC operations) */
00201     __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_JEOC);
00202 
00203     /* Pointer to the common control register to which is belonging hadc    */
00204     /* (Depending on STM32F4 product, there may be up to 3 ADC and 1 common */
00205     /* control register)                                                    */
00206     tmpADC_Common = ADC_COMMON_REGISTER(hadc);
00207 
00208     /* Check if Multimode enabled */
00209     if(HAL_IS_BIT_CLR(tmpADC_Common->CCR, ADC_CCR_MULTI))
00210     {
00211       tmp1 = HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_JEXTEN);
00212       tmp2 = HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO);
00213       if(tmp1 && tmp2)
00214       {
00215         /* Enable the selected ADC software conversion for injected group */
00216         hadc->Instance->CR2 |= ADC_CR2_JSWSTART;
00217       }
00218     }
00219     else
00220     {
00221       tmp1 = HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_JEXTEN);
00222       tmp2 = HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO);
00223       if((hadc->Instance == ADC1) && tmp1 && tmp2)  
00224       {
00225         /* Enable the selected ADC software conversion for injected group */
00226         hadc->Instance->CR2 |= ADC_CR2_JSWSTART;
00227       }
00228     }
00229   }
00230   else
00231   {
00232     /* Update ADC state machine to error */
00233     SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
00234 
00235     /* Set ADC error code to ADC IP internal error */
00236     SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL);
00237   }
00238   
00239   /* Return function status */
00240   return HAL_OK;
00241 }
00242 
00243 /**
00244   * @brief  Enables the interrupt and starts ADC conversion of injected channels.
00245   * @param  hadc pointer to a ADC_HandleTypeDef structure that contains
00246   *         the configuration information for the specified ADC.
00247   *
00248   * @retval HAL status.
00249   */
00250 HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
00251 {
00252   __IO uint32_t counter = 0U;
00253   uint32_t tmp1 = 0U, tmp2 = 0U;
00254   ADC_Common_TypeDef *tmpADC_Common;
00255   
00256   /* Process locked */
00257   __HAL_LOCK(hadc);
00258   
00259   /* Enable the ADC peripheral */
00260   
00261   /* Check if ADC peripheral is disabled in order to enable it and wait during 
00262      Tstab time the ADC's stabilization */
00263   if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON)
00264   {  
00265     /* Enable the Peripheral */
00266     __HAL_ADC_ENABLE(hadc);
00267     
00268     /* Delay for ADC stabilization time */
00269     /* Compute number of CPU cycles to wait for */
00270     counter = (ADC_STAB_DELAY_US * (SystemCoreClock / 1000000U));
00271     while(counter != 0U)
00272     {
00273       counter--;
00274     }
00275   }
00276   
00277   /* Start conversion if ADC is effectively enabled */
00278   if(HAL_IS_BIT_SET(hadc->Instance->CR2, ADC_CR2_ADON))
00279   {
00280     /* Set ADC state                                                          */
00281     /* - Clear state bitfield related to injected group conversion results    */
00282     /* - Set state bitfield related to injected operation                     */
00283     ADC_STATE_CLR_SET(hadc->State,
00284                       HAL_ADC_STATE_READY | HAL_ADC_STATE_INJ_EOC,
00285                       HAL_ADC_STATE_INJ_BUSY);
00286     
00287     /* Check if a regular conversion is ongoing */
00288     /* Note: On this device, there is no ADC error code fields related to     */
00289     /*       conversions on group injected only. In case of conversion on     */
00290     /*       going on group regular, no error code is reset.                  */
00291     if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_REG_BUSY))
00292     {
00293       /* Reset ADC all error code fields */
00294       ADC_CLEAR_ERRORCODE(hadc);
00295     }
00296     
00297     /* Process unlocked */
00298     /* Unlock before starting ADC conversions: in case of potential           */
00299     /* interruption, to let the process to ADC IRQ Handler.                   */
00300     __HAL_UNLOCK(hadc);
00301     
00302     /* Clear injected group conversion flag */
00303     /* (To ensure of no unknown state from potential previous ADC operations) */
00304     __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_JEOC);
00305     
00306     /* Enable end of conversion interrupt for injected channels */
00307     __HAL_ADC_ENABLE_IT(hadc, ADC_IT_JEOC);
00308 
00309     /* Pointer to the common control register to which is belonging hadc    */
00310     /* (Depending on STM32F4 product, there may be up to 3 ADC and 1 common */
00311     /* control register)                                                    */
00312     tmpADC_Common = ADC_COMMON_REGISTER(hadc);
00313     
00314     /* Check if Multimode enabled */
00315     if(HAL_IS_BIT_CLR(tmpADC_Common->CCR, ADC_CCR_MULTI))
00316     {
00317       tmp1 = HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_JEXTEN);
00318       tmp2 = HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO);
00319       if(tmp1 && tmp2)
00320       {
00321         /* Enable the selected ADC software conversion for injected group */
00322         hadc->Instance->CR2 |= ADC_CR2_JSWSTART;
00323       }
00324     }
00325     else
00326     {
00327       tmp1 = HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_JEXTEN);
00328       tmp2 = HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO);
00329       if((hadc->Instance == ADC1) && tmp1 && tmp2)  
00330       {
00331         /* Enable the selected ADC software conversion for injected group */
00332         hadc->Instance->CR2 |= ADC_CR2_JSWSTART;
00333       }
00334     }
00335   }
00336   else
00337   {
00338     /* Update ADC state machine to error */
00339     SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
00340 
00341     /* Set ADC error code to ADC IP internal error */
00342     SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL);
00343   }
00344   
00345   /* Return function status */
00346   return HAL_OK;
00347 }
00348 
00349 /**
00350   * @brief  Stop conversion of injected channels. Disable ADC peripheral if
00351   *         no regular conversion is on going.
00352   * @note   If ADC must be disabled and if conversion is on going on 
00353   *         regular group, function HAL_ADC_Stop must be used to stop both
00354   *         injected and regular groups, and disable the ADC.
00355   * @note   If injected group mode auto-injection is enabled,
00356   *         function HAL_ADC_Stop must be used.
00357   * @note   In case of auto-injection mode, HAL_ADC_Stop must be used.
00358   * @param  hadc ADC handle
00359   * @retval None
00360   */
00361 HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc)
00362 {
00363   HAL_StatusTypeDef tmp_hal_status = HAL_OK;
00364   
00365   /* Check the parameters */
00366   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
00367 
00368   /* Process locked */
00369   __HAL_LOCK(hadc);
00370     
00371   /* Stop potential conversion and disable ADC peripheral                     */
00372   /* Conditioned to:                                                          */
00373   /* - No conversion on the other group (regular group) is intended to        */
00374   /*   continue (injected and regular groups stop conversion and ADC disable  */
00375   /*   are common)                                                            */
00376   /* - In case of auto-injection mode, HAL_ADC_Stop must be used.             */
00377   if(((hadc->State & HAL_ADC_STATE_REG_BUSY) == RESET)  &&
00378      HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO)   )
00379   {
00380     /* Stop potential conversion on going, on regular and injected groups */
00381     /* Disable ADC peripheral */
00382     __HAL_ADC_DISABLE(hadc);
00383     
00384     /* Check if ADC is effectively disabled */
00385     if(HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_ADON))
00386     {
00387       /* Set ADC state */
00388       ADC_STATE_CLR_SET(hadc->State,
00389                         HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
00390                         HAL_ADC_STATE_READY);
00391     }
00392   }
00393   else
00394   {
00395     /* Update ADC state machine to error */
00396     SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
00397       
00398     tmp_hal_status = HAL_ERROR;
00399   }
00400   
00401   /* Process unlocked */
00402   __HAL_UNLOCK(hadc);
00403   
00404   /* Return function status */
00405   return tmp_hal_status;
00406 }
00407 
00408 /**
00409   * @brief  Poll for injected conversion complete
00410   * @param  hadc pointer to a ADC_HandleTypeDef structure that contains
00411   *         the configuration information for the specified ADC.
00412   * @param  Timeout Timeout value in millisecond.  
00413   * @retval HAL status
00414   */
00415 HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout)
00416 {
00417   uint32_t tickstart = 0U;
00418 
00419   /* Get tick */ 
00420   tickstart = HAL_GetTick();
00421 
00422   /* Check End of conversion flag */
00423   while(!(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_JEOC)))
00424   {
00425     /* Check for the Timeout */
00426     if(Timeout != HAL_MAX_DELAY)
00427     {
00428       if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
00429       {
00430         /* New check to avoid false timeout detection in case of preemption */
00431         if(!(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_JEOC)))
00432         {
00433           hadc->State= HAL_ADC_STATE_TIMEOUT;
00434           /* Process unlocked */
00435           __HAL_UNLOCK(hadc);
00436           return HAL_TIMEOUT;
00437         }
00438       }
00439     }
00440   }
00441   
00442   /* Clear injected group conversion flag */
00443   __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_JSTRT | ADC_FLAG_JEOC);
00444     
00445   /* Update ADC state machine */
00446   SET_BIT(hadc->State, HAL_ADC_STATE_INJ_EOC);
00447   
00448   /* Determine whether any further conversion upcoming on group injected      */
00449   /* by external trigger, continuous mode or scan sequence on going.          */
00450   /* Note: On STM32F4, there is no independent flag of end of sequence.       */
00451   /*       The test of scan sequence on going is done either with scan        */
00452   /*       sequence disabled or with end of conversion flag set to            */
00453   /*       of end of sequence.                                                */
00454   if(ADC_IS_SOFTWARE_START_INJECTED(hadc)                    &&
00455      (HAL_IS_BIT_CLR(hadc->Instance->JSQR, ADC_JSQR_JL)  ||
00456       HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_EOCS)    ) &&
00457      (HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO) &&
00458       (ADC_IS_SOFTWARE_START_REGULAR(hadc)       &&
00459       (hadc->Init.ContinuousConvMode == DISABLE)   )       )   )
00460   {
00461     /* Set ADC state */
00462     CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
00463     
00464     if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_REG_BUSY))
00465     { 
00466       SET_BIT(hadc->State, HAL_ADC_STATE_READY);
00467     }
00468   }
00469   
00470   /* Return ADC state */
00471   return HAL_OK;
00472 }      
00473   
00474 /**
00475   * @brief  Stop conversion of injected channels, disable interruption of 
00476   *         end-of-conversion. Disable ADC peripheral if no regular conversion
00477   *         is on going.
00478   * @note   If ADC must be disabled and if conversion is on going on 
00479   *         regular group, function HAL_ADC_Stop must be used to stop both
00480   *         injected and regular groups, and disable the ADC.
00481   * @note   If injected group mode auto-injection is enabled,
00482   *         function HAL_ADC_Stop must be used.
00483   * @param  hadc ADC handle
00484   * @retval None
00485   */
00486 HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc)
00487 {
00488   HAL_StatusTypeDef tmp_hal_status = HAL_OK;
00489   
00490   /* Check the parameters */
00491   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
00492 
00493   /* Process locked */
00494   __HAL_LOCK(hadc);
00495     
00496   /* Stop potential conversion and disable ADC peripheral                     */
00497   /* Conditioned to:                                                          */
00498   /* - No conversion on the other group (regular group) is intended to        */
00499   /*   continue (injected and regular groups stop conversion and ADC disable  */
00500   /*   are common)                                                            */
00501   /* - In case of auto-injection mode, HAL_ADC_Stop must be used.             */ 
00502   if(((hadc->State & HAL_ADC_STATE_REG_BUSY) == RESET)  &&
00503      HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO)   )
00504   {
00505     /* Stop potential conversion on going, on regular and injected groups */
00506     /* Disable ADC peripheral */
00507     __HAL_ADC_DISABLE(hadc);
00508     
00509     /* Check if ADC is effectively disabled */
00510     if(HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_ADON))
00511     {
00512       /* Disable ADC end of conversion interrupt for injected channels */
00513       __HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOC);
00514       
00515       /* Set ADC state */
00516       ADC_STATE_CLR_SET(hadc->State,
00517                         HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
00518                         HAL_ADC_STATE_READY);
00519     }
00520   }
00521   else
00522   {
00523     /* Update ADC state machine to error */
00524     SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
00525       
00526     tmp_hal_status = HAL_ERROR;
00527   }
00528   
00529   /* Process unlocked */
00530   __HAL_UNLOCK(hadc);
00531   
00532   /* Return function status */
00533   return tmp_hal_status;
00534 }
00535 
00536 /**
00537   * @brief  Gets the converted value from data register of injected channel.
00538   * @param  hadc pointer to a ADC_HandleTypeDef structure that contains
00539   *         the configuration information for the specified ADC.
00540   * @param  InjectedRank the ADC injected rank.
00541   *          This parameter can be one of the following values:
00542   *            @arg ADC_INJECTED_RANK_1: Injected Channel1 selected
00543   *            @arg ADC_INJECTED_RANK_2: Injected Channel2 selected
00544   *            @arg ADC_INJECTED_RANK_3: Injected Channel3 selected
00545   *            @arg ADC_INJECTED_RANK_4: Injected Channel4 selected
00546   * @retval None
00547   */
00548 uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef* hadc, uint32_t InjectedRank)
00549 {
00550   __IO uint32_t tmp = 0U;
00551   
00552   /* Check the parameters */
00553   assert_param(IS_ADC_INJECTED_RANK(InjectedRank));
00554   
00555   /* Clear injected group conversion flag to have similar behaviour as        */
00556   /* regular group: reading data register also clears end of conversion flag. */
00557   __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_JEOC);
00558   
00559   /* Return the selected ADC converted value */ 
00560   switch(InjectedRank)
00561   {  
00562     case ADC_INJECTED_RANK_4:
00563     {
00564       tmp =  hadc->Instance->JDR4;
00565     }  
00566     break;
00567     case ADC_INJECTED_RANK_3: 
00568     {  
00569       tmp =  hadc->Instance->JDR3;
00570     }  
00571     break;
00572     case ADC_INJECTED_RANK_2: 
00573     {  
00574       tmp =  hadc->Instance->JDR2;
00575     }
00576     break;
00577     case ADC_INJECTED_RANK_1:
00578     {
00579       tmp =  hadc->Instance->JDR1;
00580     }
00581     break;
00582     default:
00583     break;  
00584   }
00585   return tmp;
00586 }
00587 
00588 /**
00589   * @brief  Enables ADC DMA request after last transfer (Multi-ADC mode) and enables ADC peripheral
00590   * 
00591   * @note   Caution: This function must be used only with the ADC master.  
00592   *
00593   * @param  hadc pointer to a ADC_HandleTypeDef structure that contains
00594   *         the configuration information for the specified ADC.
00595   * @param  pData   Pointer to buffer in which transferred from ADC peripheral to memory will be stored. 
00596   * @param  Length  The length of data to be transferred from ADC peripheral to memory.  
00597   * @retval HAL status
00598   */
00599 HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length)
00600 {
00601   __IO uint32_t counter = 0U;
00602   ADC_Common_TypeDef *tmpADC_Common;
00603   
00604   /* Check the parameters */
00605   assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ContinuousConvMode));
00606   assert_param(IS_ADC_EXT_TRIG_EDGE(hadc->Init.ExternalTrigConvEdge));
00607   assert_param(IS_FUNCTIONAL_STATE(hadc->Init.DMAContinuousRequests));
00608   
00609   /* Process locked */
00610   __HAL_LOCK(hadc);
00611   
00612   /* Check if ADC peripheral is disabled in order to enable it and wait during 
00613      Tstab time the ADC's stabilization */
00614   if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON)
00615   {  
00616     /* Enable the Peripheral */
00617     __HAL_ADC_ENABLE(hadc);
00618     
00619     /* Delay for temperature sensor stabilization time */
00620     /* Compute number of CPU cycles to wait for */
00621     counter = (ADC_STAB_DELAY_US * (SystemCoreClock / 1000000U));
00622     while(counter != 0U)
00623     {
00624       counter--;
00625     }
00626   }
00627   
00628   /* Start conversion if ADC is effectively enabled */
00629   if(HAL_IS_BIT_SET(hadc->Instance->CR2, ADC_CR2_ADON))
00630   {
00631     /* Set ADC state                                                          */
00632     /* - Clear state bitfield related to regular group conversion results     */
00633     /* - Set state bitfield related to regular group operation                */
00634     ADC_STATE_CLR_SET(hadc->State,
00635                       HAL_ADC_STATE_READY | HAL_ADC_STATE_REG_EOC | HAL_ADC_STATE_REG_OVR,
00636                       HAL_ADC_STATE_REG_BUSY);
00637     
00638     /* If conversions on group regular are also triggering group injected,    */
00639     /* update ADC state.                                                      */
00640     if (READ_BIT(hadc->Instance->CR1, ADC_CR1_JAUTO) != RESET)
00641     {
00642       ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY);  
00643     }
00644     
00645     /* State machine update: Check if an injected conversion is ongoing */
00646     if (HAL_IS_BIT_SET(hadc->State, HAL_ADC_STATE_INJ_BUSY))
00647     {
00648       /* Reset ADC error code fields related to conversions on group regular */
00649       CLEAR_BIT(hadc->ErrorCode, (HAL_ADC_ERROR_OVR | HAL_ADC_ERROR_DMA));         
00650     }
00651     else
00652     {
00653       /* Reset ADC all error code fields */
00654       ADC_CLEAR_ERRORCODE(hadc);
00655     }
00656     
00657     /* Process unlocked */
00658     /* Unlock before starting ADC conversions: in case of potential           */
00659     /* interruption, to let the process to ADC IRQ Handler.                   */
00660     __HAL_UNLOCK(hadc);
00661     
00662     /* Set the DMA transfer complete callback */
00663     hadc->DMA_Handle->XferCpltCallback = ADC_MultiModeDMAConvCplt;
00664     
00665     /* Set the DMA half transfer complete callback */
00666     hadc->DMA_Handle->XferHalfCpltCallback = ADC_MultiModeDMAHalfConvCplt;
00667     
00668     /* Set the DMA error callback */
00669     hadc->DMA_Handle->XferErrorCallback = ADC_MultiModeDMAError ;
00670     
00671     /* Manage ADC and DMA start: ADC overrun interruption, DMA start, ADC     */
00672     /* start (in case of SW start):                                           */
00673     
00674     /* Clear regular group conversion flag and overrun flag */
00675     /* (To ensure of no unknown state from potential previous ADC operations) */
00676     __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_EOC);
00677 
00678     /* Enable ADC overrun interrupt */
00679     __HAL_ADC_ENABLE_IT(hadc, ADC_IT_OVR);
00680 
00681     /* Pointer to the common control register to which is belonging hadc    */
00682     /* (Depending on STM32F4 product, there may be up to 3 ADC and 1 common */
00683     /* control register)                                                    */
00684     tmpADC_Common = ADC_COMMON_REGISTER(hadc);
00685 
00686     if (hadc->Init.DMAContinuousRequests != DISABLE)
00687     {
00688       /* Enable the selected ADC DMA request after last transfer */
00689       tmpADC_Common->CCR |= ADC_CCR_DDS;
00690     }
00691     else
00692     {
00693       /* Disable the selected ADC EOC rising on each regular channel conversion */
00694       tmpADC_Common->CCR &= ~ADC_CCR_DDS;
00695     }
00696     
00697     /* Enable the DMA Stream */
00698     HAL_DMA_Start_IT(hadc->DMA_Handle, (uint32_t)&tmpADC_Common->CDR, (uint32_t)pData, Length);
00699     
00700     /* if no external trigger present enable software conversion of regular channels */
00701     if((hadc->Instance->CR2 & ADC_CR2_EXTEN) == RESET) 
00702     {
00703       /* Enable the selected ADC software conversion for regular group */
00704       hadc->Instance->CR2 |= (uint32_t)ADC_CR2_SWSTART;
00705     }
00706   }
00707   else
00708   {
00709     /* Update ADC state machine to error */
00710     SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
00711 
00712     /* Set ADC error code to ADC IP internal error */
00713     SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL);
00714   }
00715   
00716   /* Return function status */
00717   return HAL_OK;
00718 }
00719 
00720 /**
00721   * @brief  Disables ADC DMA (multi-ADC mode) and disables ADC peripheral    
00722   * @param  hadc pointer to a ADC_HandleTypeDef structure that contains
00723   *         the configuration information for the specified ADC.
00724   * @retval HAL status
00725   */
00726 HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc)
00727 {
00728   HAL_StatusTypeDef tmp_hal_status = HAL_OK;
00729   ADC_Common_TypeDef *tmpADC_Common;
00730   
00731   /* Check the parameters */
00732   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
00733   
00734   /* Process locked */
00735   __HAL_LOCK(hadc);
00736   
00737   /* Stop potential conversion on going, on regular and injected groups */
00738   /* Disable ADC peripheral */
00739   __HAL_ADC_DISABLE(hadc);
00740 
00741   /* Pointer to the common control register to which is belonging hadc    */
00742   /* (Depending on STM32F4 product, there may be up to 3 ADC and 1 common */
00743   /* control register)                                                    */
00744   tmpADC_Common = ADC_COMMON_REGISTER(hadc);
00745 
00746   /* Check if ADC is effectively disabled */
00747   if(HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_ADON))
00748   {
00749     /* Disable the selected ADC DMA mode for multimode */
00750     tmpADC_Common->CCR &= ~ADC_CCR_DDS;
00751     
00752     /* Disable the DMA channel (in case of DMA in circular mode or stop while */
00753     /* DMA transfer is on going)                                              */
00754     tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle);
00755     
00756     /* Disable ADC overrun interrupt */
00757     __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR);
00758     
00759     /* Set ADC state */
00760     ADC_STATE_CLR_SET(hadc->State,
00761                       HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
00762                       HAL_ADC_STATE_READY);
00763   }
00764   
00765   /* Process unlocked */
00766   __HAL_UNLOCK(hadc);
00767   
00768   /* Return function status */
00769   return tmp_hal_status;
00770 }
00771 
00772 /**
00773   * @brief  Returns the last ADC1, ADC2 and ADC3 regular conversions results 
00774   *         data in the selected multi mode.
00775   * @param  hadc pointer to a ADC_HandleTypeDef structure that contains
00776   *         the configuration information for the specified ADC.
00777   * @retval The converted data value.
00778   */
00779 uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef* hadc)
00780 {
00781   ADC_Common_TypeDef *tmpADC_Common;
00782 
00783   /* Pointer to the common control register to which is belonging hadc    */
00784   /* (Depending on STM32F4 product, there may be up to 3 ADC and 1 common */
00785   /* control register)                                                    */
00786   tmpADC_Common = ADC_COMMON_REGISTER(hadc);
00787 
00788   /* Return the multi mode conversion value */
00789   return tmpADC_Common->CDR;
00790 }
00791 
00792 /**
00793   * @brief  Injected conversion complete callback in non blocking mode 
00794   * @param  hadc pointer to a ADC_HandleTypeDef structure that contains
00795   *         the configuration information for the specified ADC.
00796   * @retval None
00797   */
00798 __weak void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc)
00799 {
00800   /* Prevent unused argument(s) compilation warning */
00801   UNUSED(hadc);
00802   /* NOTE : This function Should not be modified, when the callback is needed,
00803             the HAL_ADC_InjectedConvCpltCallback could be implemented in the user file
00804    */
00805 }
00806 
00807 /**
00808   * @brief  Configures for the selected ADC injected channel its corresponding
00809   *         rank in the sequencer and its sample time.
00810   * @param  hadc pointer to a ADC_HandleTypeDef structure that contains
00811   *         the configuration information for the specified ADC.
00812   * @param  sConfigInjected ADC configuration structure for injected channel. 
00813   * @retval None
00814   */
00815 HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_InjectionConfTypeDef* sConfigInjected)
00816 {
00817   
00818 #ifdef USE_FULL_ASSERT  
00819   uint32_t tmp = 0U;
00820   
00821 #endif /* USE_FULL_ASSERT  */
00822 
00823   ADC_Common_TypeDef *tmpADC_Common;
00824 
00825   /* Check the parameters */
00826   assert_param(IS_ADC_CHANNEL(sConfigInjected->InjectedChannel));
00827   assert_param(IS_ADC_INJECTED_RANK(sConfigInjected->InjectedRank));
00828   assert_param(IS_ADC_SAMPLE_TIME(sConfigInjected->InjectedSamplingTime));
00829   assert_param(IS_ADC_EXT_INJEC_TRIG(sConfigInjected->ExternalTrigInjecConv));
00830   assert_param(IS_ADC_INJECTED_LENGTH(sConfigInjected->InjectedNbrOfConversion));
00831   assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->AutoInjectedConv));
00832   assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->InjectedDiscontinuousConvMode));
00833 
00834 #ifdef USE_FULL_ASSERT
00835   tmp = ADC_GET_RESOLUTION(hadc);
00836   assert_param(IS_ADC_RANGE(tmp, sConfigInjected->InjectedOffset));
00837 #endif /* USE_FULL_ASSERT  */
00838 
00839   if(sConfigInjected->ExternalTrigInjecConv != ADC_INJECTED_SOFTWARE_START)
00840   {
00841     assert_param(IS_ADC_EXT_INJEC_TRIG_EDGE(sConfigInjected->ExternalTrigInjecConvEdge));
00842   }
00843 
00844   /* Process locked */
00845   __HAL_LOCK(hadc);
00846   
00847   /* if ADC_Channel_10 ... ADC_Channel_18 is selected */
00848   if (sConfigInjected->InjectedChannel > ADC_CHANNEL_9)
00849   {
00850     /* Clear the old sample time */
00851     hadc->Instance->SMPR1 &= ~ADC_SMPR1(ADC_SMPR1_SMP10, sConfigInjected->InjectedChannel);
00852     
00853     /* Set the new sample time */
00854     hadc->Instance->SMPR1 |= ADC_SMPR1(sConfigInjected->InjectedSamplingTime, sConfigInjected->InjectedChannel);
00855   }
00856   else /* ADC_Channel include in ADC_Channel_[0..9] */
00857   {
00858     /* Clear the old sample time */
00859     hadc->Instance->SMPR2 &= ~ADC_SMPR2(ADC_SMPR2_SMP0, sConfigInjected->InjectedChannel);
00860     
00861     /* Set the new sample time */
00862     hadc->Instance->SMPR2 |= ADC_SMPR2(sConfigInjected->InjectedSamplingTime, sConfigInjected->InjectedChannel);
00863   }
00864   
00865   /*---------------------------- ADCx JSQR Configuration -----------------*/
00866   hadc->Instance->JSQR &= ~(ADC_JSQR_JL);
00867   hadc->Instance->JSQR |=  ADC_SQR1(sConfigInjected->InjectedNbrOfConversion);
00868   
00869   /* Rank configuration */
00870   
00871   /* Clear the old SQx bits for the selected rank */
00872   hadc->Instance->JSQR &= ~ADC_JSQR(ADC_JSQR_JSQ1, sConfigInjected->InjectedRank,sConfigInjected->InjectedNbrOfConversion);
00873    
00874   /* Set the SQx bits for the selected rank */
00875   hadc->Instance->JSQR |= ADC_JSQR(sConfigInjected->InjectedChannel, sConfigInjected->InjectedRank,sConfigInjected->InjectedNbrOfConversion);
00876 
00877   /* Enable external trigger if trigger selection is different of software  */
00878   /* start.                                                                 */
00879   /* Note: This configuration keeps the hardware feature of parameter       */
00880   /*       ExternalTrigConvEdge "trigger edge none" equivalent to           */
00881   /*       software start.                                                  */ 
00882   if(sConfigInjected->ExternalTrigInjecConv != ADC_INJECTED_SOFTWARE_START)
00883   {  
00884     /* Select external trigger to start conversion */
00885     hadc->Instance->CR2 &= ~(ADC_CR2_JEXTSEL);
00886     hadc->Instance->CR2 |=  sConfigInjected->ExternalTrigInjecConv;
00887     
00888     /* Select external trigger polarity */
00889     hadc->Instance->CR2 &= ~(ADC_CR2_JEXTEN);
00890     hadc->Instance->CR2 |= sConfigInjected->ExternalTrigInjecConvEdge;
00891   }
00892   else
00893   {
00894     /* Reset the external trigger */
00895     hadc->Instance->CR2 &= ~(ADC_CR2_JEXTSEL);
00896     hadc->Instance->CR2 &= ~(ADC_CR2_JEXTEN);  
00897   }
00898   
00899   if (sConfigInjected->AutoInjectedConv != DISABLE)
00900   {
00901     /* Enable the selected ADC automatic injected group conversion */
00902     hadc->Instance->CR1 |= ADC_CR1_JAUTO;
00903   }
00904   else
00905   {
00906     /* Disable the selected ADC automatic injected group conversion */
00907     hadc->Instance->CR1 &= ~(ADC_CR1_JAUTO);
00908   }
00909   
00910   if (sConfigInjected->InjectedDiscontinuousConvMode != DISABLE)
00911   {
00912     /* Enable the selected ADC injected discontinuous mode */
00913     hadc->Instance->CR1 |= ADC_CR1_JDISCEN;
00914   }
00915   else
00916   {
00917     /* Disable the selected ADC injected discontinuous mode */
00918     hadc->Instance->CR1 &= ~(ADC_CR1_JDISCEN);
00919   }
00920   
00921   switch(sConfigInjected->InjectedRank)
00922   {
00923     case 1U:
00924       /* Set injected channel 1 offset */
00925       hadc->Instance->JOFR1 &= ~(ADC_JOFR1_JOFFSET1);
00926       hadc->Instance->JOFR1 |= sConfigInjected->InjectedOffset;
00927       break;
00928     case 2U:
00929       /* Set injected channel 2 offset */
00930       hadc->Instance->JOFR2 &= ~(ADC_JOFR2_JOFFSET2);
00931       hadc->Instance->JOFR2 |= sConfigInjected->InjectedOffset;
00932       break;
00933     case 3U:
00934       /* Set injected channel 3 offset */
00935       hadc->Instance->JOFR3 &= ~(ADC_JOFR3_JOFFSET3);
00936       hadc->Instance->JOFR3 |= sConfigInjected->InjectedOffset;
00937       break;
00938     default:
00939       /* Set injected channel 4 offset */
00940       hadc->Instance->JOFR4 &= ~(ADC_JOFR4_JOFFSET4);
00941       hadc->Instance->JOFR4 |= sConfigInjected->InjectedOffset;
00942       break;
00943   }
00944 
00945   /* Pointer to the common control register to which is belonging hadc    */
00946   /* (Depending on STM32F4 product, there may be up to 3 ADC and 1 common */
00947   /* control register)                                                    */
00948     tmpADC_Common = ADC_COMMON_REGISTER(hadc);
00949 
00950   /* if ADC1 Channel_18 is selected enable VBAT Channel */
00951   if ((hadc->Instance == ADC1) && (sConfigInjected->InjectedChannel == ADC_CHANNEL_VBAT))
00952   {
00953     /* Enable the VBAT channel*/
00954     tmpADC_Common->CCR |= ADC_CCR_VBATE;
00955   }
00956   
00957   /* if ADC1 Channel_16 or Channel_17 is selected enable TSVREFE Channel(Temperature sensor and VREFINT) */
00958   if ((hadc->Instance == ADC1) && ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR) || (sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT)))
00959   {
00960     /* Enable the TSVREFE channel*/
00961     tmpADC_Common->CCR |= ADC_CCR_TSVREFE;
00962   }
00963   
00964   /* Process unlocked */
00965   __HAL_UNLOCK(hadc);
00966   
00967   /* Return function status */
00968   return HAL_OK;
00969 }
00970 
00971 /**
00972   * @brief  Configures the ADC multi-mode 
00973   * @param  hadc       pointer to a ADC_HandleTypeDef structure that contains
00974   *                     the configuration information for the specified ADC.  
00975   * @param  multimode  pointer to an ADC_MultiModeTypeDef structure that contains 
00976   *                     the configuration information for  multimode.
00977   * @retval HAL status
00978   */
00979 HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef* hadc, ADC_MultiModeTypeDef* multimode)
00980 {
00981 
00982   ADC_Common_TypeDef *tmpADC_Common;
00983 
00984   /* Check the parameters */
00985   assert_param(IS_ADC_MODE(multimode->Mode));
00986   assert_param(IS_ADC_DMA_ACCESS_MODE(multimode->DMAAccessMode));
00987   assert_param(IS_ADC_SAMPLING_DELAY(multimode->TwoSamplingDelay));
00988   
00989   /* Process locked */
00990   __HAL_LOCK(hadc);
00991 
00992   /* Pointer to the common control register to which is belonging hadc    */
00993   /* (Depending on STM32F4 product, there may be up to 3 ADC and 1 common */
00994   /* control register)                                                    */
00995   tmpADC_Common = ADC_COMMON_REGISTER(hadc);
00996 
00997   /* Set ADC mode */
00998   tmpADC_Common->CCR &= ~(ADC_CCR_MULTI);
00999   tmpADC_Common->CCR |= multimode->Mode;
01000   
01001   /* Set the ADC DMA access mode */
01002   tmpADC_Common->CCR &= ~(ADC_CCR_DMA);
01003   tmpADC_Common->CCR |= multimode->DMAAccessMode;
01004   
01005   /* Set delay between two sampling phases */
01006   tmpADC_Common->CCR &= ~(ADC_CCR_DELAY);
01007   tmpADC_Common->CCR |= multimode->TwoSamplingDelay;
01008   
01009   /* Process unlocked */
01010   __HAL_UNLOCK(hadc);
01011   
01012   /* Return function status */
01013   return HAL_OK;
01014 }
01015 
01016 /**
01017   * @}
01018   */
01019 
01020 /**
01021   * @brief  DMA transfer complete callback. 
01022   * @param  hdma pointer to a DMA_HandleTypeDef structure that contains
01023   *                the configuration information for the specified DMA module.
01024   * @retval None
01025   */
01026 static void ADC_MultiModeDMAConvCplt(DMA_HandleTypeDef *hdma)   
01027 {
01028   /* Retrieve ADC handle corresponding to current DMA handle */
01029   ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
01030   
01031   /* Update state machine on conversion status if not in error state */
01032   if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL | HAL_ADC_STATE_ERROR_DMA))
01033   {
01034     /* Update ADC state machine */
01035     SET_BIT(hadc->State, HAL_ADC_STATE_REG_EOC);
01036     
01037     /* Determine whether any further conversion upcoming on group regular   */
01038     /* by external trigger, continuous mode or scan sequence on going.      */
01039     /* Note: On STM32F4, there is no independent flag of end of sequence.   */
01040     /*       The test of scan sequence on going is done either with scan    */
01041     /*       sequence disabled or with end of conversion flag set to        */
01042     /*       of end of sequence.                                            */
01043     if(ADC_IS_SOFTWARE_START_REGULAR(hadc)                   &&
01044        (hadc->Init.ContinuousConvMode == DISABLE)            &&
01045        (HAL_IS_BIT_CLR(hadc->Instance->SQR1, ADC_SQR1_L) || 
01046         HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_EOCS)  )   )
01047     {
01048       /* Disable ADC end of single conversion interrupt on group regular */
01049       /* Note: Overrun interrupt was enabled with EOC interrupt in          */
01050       /* HAL_ADC_Start_IT(), but is not disabled here because can be used   */
01051       /* by overrun IRQ process below.                                      */
01052       __HAL_ADC_DISABLE_IT(hadc, ADC_IT_EOC);
01053       
01054       /* Set ADC state */
01055       CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY);   
01056       
01057       if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_INJ_BUSY))
01058       {
01059         SET_BIT(hadc->State, HAL_ADC_STATE_READY);
01060       }
01061     }
01062     
01063     /* Conversion complete callback */
01064     HAL_ADC_ConvCpltCallback(hadc);
01065   }
01066   else
01067   {
01068     /* Call DMA error callback */
01069     hadc->DMA_Handle->XferErrorCallback(hdma);
01070   }
01071 }
01072 
01073 /**
01074   * @brief  DMA half transfer complete callback. 
01075   * @param  hdma pointer to a DMA_HandleTypeDef structure that contains
01076   *                the configuration information for the specified DMA module.
01077   * @retval None
01078   */
01079 static void ADC_MultiModeDMAHalfConvCplt(DMA_HandleTypeDef *hdma)   
01080 {
01081     ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
01082     /* Conversion complete callback */
01083     HAL_ADC_ConvHalfCpltCallback(hadc); 
01084 }
01085 
01086 /**
01087   * @brief  DMA error callback 
01088   * @param  hdma pointer to a DMA_HandleTypeDef structure that contains
01089   *                the configuration information for the specified DMA module.
01090   * @retval None
01091   */
01092 static void ADC_MultiModeDMAError(DMA_HandleTypeDef *hdma)   
01093 {
01094     ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
01095     hadc->State= HAL_ADC_STATE_ERROR_DMA;
01096     /* Set ADC error code to DMA error */
01097     hadc->ErrorCode |= HAL_ADC_ERROR_DMA;
01098     HAL_ADC_ErrorCallback(hadc); 
01099 }
01100 
01101 /**
01102   * @}
01103   */
01104 
01105 #endif /* HAL_ADC_MODULE_ENABLED */
01106 /**
01107   * @}
01108   */ 
01109 
01110 /**
01111   * @}
01112   */ 
01113 
01114 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/