]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32L0/stm32l0xx_hal_adc.c
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32L0 / stm32l0xx_hal_adc.c
1 /**
2   ******************************************************************************
3   * @file    stm32l0xx_hal_adc.c
4   * @author  MCD Application Team
5   * @version V1.2.0
6   * @date    06-February-2015
7   * @brief   This file provides firmware functions to manage the following 
8   *          functionalities of the Analog to Digital Convertor (ADC)
9   *          peripheral:
10   *           + Initialization and de-initialization functions
11   *             ++ Initialization and Configuration of ADC
12   *           + Operation functions
13   *             ++ Start, stop, get result of conversions of regular 
14   *             groups, using 3 possible modes : polling, interruption or DMA.
15   *             ++ Calibration feature
16   *           + Control functions
17   *             ++ Analog Watchdog configuration
18   *             ++ Regular Channels Configuration
19   *           + State functions
20   *             ++ ADC state machine management
21   *             ++ Interrupts and flags management
22   *         
23   @verbatim
24   ==============================================================================
25                     ##### ADC specific features #####
26   ==============================================================================
27   [..] 
28   (#) 12-bit, 10-bit, 8-bit or 6-bit configurable resolution.
29
30   (#) A built-in hardware oversampler allows to improve analog performances
31       while off-loading the related computational burden from the CPU.
32
33   (#) Interrupt generation at the end of conversion and in case of analog
34       watchdog or overrun events.
35   
36   (#) Single and continuous conversion modes.
37   
38   (#) Scan or discontinuous mode conversion of channel 0 to channel 18.
39
40   (#) Configurable scan direction (Upward from channel 0 to 18 or Backward from
41       channel 18 to channel 0)
42   
43   (#) Data alignment with in-built data coherency.
44   
45   (#) Channel-wise programmable sampling time.
46
47   (#) External trigger option with configurable polarity.
48
49   (#) DMA request generation during regular channel conversion.
50   
51   (#) ADC supply requirements: 2.4 V to 3.6 V at full speed and down to 1.8 V at 
52       slower speed.
53   
54   (#) ADC input range: VREF- =VIN =VREF+.
55
56   (#) ADC self-calibration.
57
58   (#) ADC is automatically powered off (AutoOff mode) except during the active
59       conversion phase. This dramatically reduces the power consumption of the
60       ADC.
61
62   (#) Wait mode to prevent ADC overrun in applications with low frequency.
63
64
65                      ##### How to use this driver #####
66   ==============================================================================
67     [..]
68
69     (#) Enable the ADC interface 
70         As prerequisite, into HAL_ADC_MspInit(), ADC clock must be configured  
71         at RCC top level.
72
73         Depending on both possible clock sources: PCLK clock or ADC asynchronous
74         clock. 
75           __HAL_RCC_ADC1_CLK_ENABLE();                                                            
76
77
78     (#) ADC pins configuration
79          (++) Enable the clock for the ADC GPIOs using the following function:
80              __HAL_RCC_GPIOx_CLK_ENABLE();   
81          (++) Configure these ADC pins in analog mode using HAL_GPIO_Init();  
82   
83      (#) Configure the ADC parameters (conversion resolution, oversampler, 
84          data alignment, continuous mode,...) using the HAL_ADC_Init() function.
85
86      (#) Activate the ADC peripheral using one of the start functions: 
87          HAL_ADC_Start(), HAL_ADC_Start_IT() or HAL_ADC_Start_DMA()
88   
89      *** Channels configuration ***
90      ===============================
91      [..]    
92        (+) To configure the ADC channels group, use HAL_ADC_ConfigChannel() function.   
93        (+) To read the ADC converted values, use the HAL_ADC_GetValue() function.
94             
95      *** DMA feature configuration ***
96      =================================
97      [..]
98        (+) To enable the DMA mode, use the HAL_ADC_Start_DMA() function.
99        (+) To enable the generation of DMA requests continuously at the end of 
100            the last DMA transfer, set .Init.DMAContinuousRequests to ENABLE and
101            call HAL_ADC_Init() function.
102
103   
104     @endverbatim
105   ******************************************************************************
106   * @attention
107   *
108   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
109   *
110   * Redistribution and use in source and binary forms, with or without modification,
111   * are permitted provided that the following conditions are met:
112   *   1. Redistributions of source code must retain the above copyright notice,
113   *      this list of conditions and the following disclaimer.
114   *   2. Redistributions in binary form must reproduce the above copyright notice,
115   *      this list of conditions and the following disclaimer in the documentation
116   *      and/or other materials provided with the distribution.
117   *   3. Neither the name of STMicroelectronics nor the names of its contributors
118   *      may be used to endorse or promote products derived from this software
119   *      without specific prior written permission.
120   *
121   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
122   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
123   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
124   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
125   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
126   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
127   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
128   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
129   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
130   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
131   *
132   ******************************************************************************  
133   */
134
135 /* Includes ------------------------------------------------------------------*/
136 #include "stm32l0xx_hal.h"
137
138 /** @addtogroup STM32L0xx_HAL_Driver
139   * @{
140   */
141
142 /** @addtogroup ADC 
143   * @brief ADC driver modules
144   * @{
145   */ 
146
147 #ifdef HAL_ADC_MODULE_ENABLED
148     
149 /* Private typedef -----------------------------------------------------------*/
150 /* Private define ------------------------------------------------------------*/
151
152 /* Delay for ADC stabilization time.                                          */
153 /* Maximum delay is 1us (refer to device datasheet, parameter tSTART). */
154 /* Unit: us */
155 #define ADC_STAB_DELAY_US       ((uint32_t) 1)
156
157 /* Delay for temperature sensor stabilization time. */
158 /* Maximum delay is 10us (refer to device datasheet, parameter tSTART). */
159 /* Unit: us */
160 #define ADC_TEMPSENSOR_DELAY_US ((uint32_t) 10) 
161
162 /* Private macro -------------------------------------------------------------*/
163 /* Private variables ---------------------------------------------------------*/
164 /* Private function prototypes -----------------------------------------------*/
165 static HAL_StatusTypeDef ADC_Enable(ADC_HandleTypeDef* hadc);
166 static void ADC_DMAConvCplt(DMA_HandleTypeDef *hdma);
167 static void ADC_DMAHalfConvCplt(DMA_HandleTypeDef *hdma);
168 static void ADC_DMAError(DMA_HandleTypeDef *hdma);
169 static HAL_StatusTypeDef ADC_ConversionStop(ADC_HandleTypeDef* hadc, uint32_t ConversionGroup);
170 static HAL_StatusTypeDef ADC_Disable(ADC_HandleTypeDef* hadc);
171 static void ADC_DelayMicroSecond(uint32_t microSecond);
172
173 /* Private functions ---------------------------------------------------------*/
174
175 /** @defgroup ADC_Private_Functions
176   * @{
177   */ 
178
179 /** @defgroup ADC_Group1 Initialization/de-initialization functions 
180  *  @brief    Initialization and Configuration functions 
181  *
182 @verbatim    
183  ===============================================================================
184               ##### Initialization and de-initialization functions #####
185  ===============================================================================
186     [..]  This section provides functions allowing to:
187       (+) Initialize and configure the ADC. 
188       (+) De-initialize the ADC. 
189          
190 @endverbatim
191   * @{
192   */
193
194
195 /**
196   * @brief  Initializes the ADCx peripheral according to the specified parameters 
197   *         in the ADC_InitStruct.
198   * @note   This function is used to configure the global features of the ADC 
199   *         (ClockPrescaler, Resolution, Data Alignment and number of conversion), however,
200   *         the rest of the configuration parameters are specific to the regular
201   *         channels group (scan mode activation, continuous mode activation,
202   *         External trigger source and edge, DMA continuous request after the  
203   *         last transfer and End of conversion selection).
204   *         
205   *         As prerequisite, into HAL_ADC_MspInit(), ADC clock must be 
206   *         configured at RCC top level.
207   *         See commented example code below that can be copied 
208   *         and uncommented into HAL_ADC_MspInit().
209   *         
210   * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains
211   *         the configuration information for the specified ADC.  
212   * @retval HAL status
213   */
214 HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc)
215 {
216   uint32_t tickstart = 0x00;
217   
218   /* Check ADC handle */
219   if(hadc == NULL)
220   {
221      return HAL_ERROR;
222   }
223   
224   /* Check the parameters */
225   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
226   assert_param(IS_ADC_CLOCKPRESCALER(hadc->Init.ClockPrescaler));
227   assert_param(IS_ADC_RESOLUTION(hadc->Init.Resolution));
228   assert_param(IS_ADC_SAMPLE_TIME(hadc->Init.SamplingTime));
229   assert_param(IS_ADC_SCAN_MODE(hadc->Init.ScanConvMode));  
230   assert_param(IS_ADC_DATA_ALIGN(hadc->Init.DataAlign)); 
231   assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ContinuousConvMode));         
232   assert_param(IS_FUNCTIONAL_STATE(hadc->Init.DiscontinuousConvMode));
233   assert_param(IS_ADC_EXTTRIG_EDGE(hadc->Init.ExternalTrigConvEdge));
234   assert_param(IS_ADC_EXTERNAL_TRIG_CONV(hadc->Init.ExternalTrigConv));   
235   assert_param(IS_FUNCTIONAL_STATE(hadc->Init.DMAContinuousRequests));      
236   assert_param(IS_ADC_EOC_SELECTION(hadc->Init.EOCSelection));
237   assert_param(IS_ADC_OVERRUN(hadc->Init.Overrun));         
238   assert_param(IS_FUNCTIONAL_STATE(hadc->Init.LowPowerAutoWait));
239   assert_param(IS_FUNCTIONAL_STATE(hadc->Init.LowPowerFrequencyMode));
240   assert_param(IS_FUNCTIONAL_STATE(hadc->Init.LowPowerAutoPowerOff));
241   assert_param(IS_FUNCTIONAL_STATE(hadc->Init.OversamplingMode));
242
243   if(hadc->State == HAL_ADC_STATE_RESET)
244   {
245     /* Init the low level hardware */
246     HAL_ADC_MspInit(hadc);
247   }
248   
249   /* Configuration of ADC parameters if previous preliminary actions are      */ 
250   /* correctly completed.                                                     */
251   /* and if there is no conversion on going  (ADC can be enabled anyway,      */ 
252   /* in case of call of this function to update a parameter                   */
253   /* on the fly).                                                             */
254   if ((hadc->State == HAL_ADC_STATE_ERROR) ||
255       (ADC_IS_CONVERSION_ONGOING(hadc) != RESET)  )
256   {
257     /* Update ADC state machine to error */
258     hadc->State = HAL_ADC_STATE_ERROR;
259     /* Process unlocked */
260     __HAL_UNLOCK(hadc);
261     return HAL_ERROR;
262   }
263
264   /* Initialize the ADC state */
265   hadc->State = HAL_ADC_STATE_BUSY;
266   
267   /* Configuration of ADC clock: clock source PCLK or asynchronous with 
268   selectable prescaler */
269   __HAL_ADC_CLOCK_PRESCALER(hadc);
270   
271   /* Set the Low Frequency mode */
272   ADC->CCR &= (uint32_t)~ADC_CCR_LFMEN;
273   ADC->CCR |=__HAL_ADC_CCR_LOWFREQUENCY(hadc->Init.LowPowerFrequencyMode);  
274    
275   /* Enable voltage regulator (if disabled at this step) */
276   if (HAL_IS_BIT_CLR(hadc->Instance->CR, ADC_CR_ADVREGEN))
277   {
278     /* Disable the ADC (if not already disabled) */
279     if (ADC_IS_ENABLE(hadc) != RESET )
280     {
281       /* Check if conditions to disable the ADC are fulfilled */
282       if (ADC_DISABLING_CONDITIONS(hadc) != RESET)
283       {
284         __HAL_ADC_DISABLE(hadc);    
285       }
286       else  
287       {
288         hadc->State= HAL_ADC_STATE_ERROR;
289         
290         /* Process unlocked */
291         __HAL_UNLOCK(hadc);
292         
293         return HAL_ERROR;
294       }   
295       
296       /* Get timeout */
297       tickstart = HAL_GetTick();
298
299       /* Wait for disabling completion */
300       while(HAL_IS_BIT_SET(hadc->Instance->CR, ADC_CR_ADEN))
301       {
302         /* Check for the Timeout */
303         if(ADC_ENABLE_TIMEOUT != HAL_MAX_DELAY)
304         {          
305           if((HAL_GetTick() - tickstart ) > ADC_DISABLE_TIMEOUT)
306           {
307             hadc->State= HAL_ADC_STATE_TIMEOUT;
308             
309             /* Process unlocked */
310             __HAL_UNLOCK(hadc);
311             
312             return HAL_TIMEOUT;
313           }
314         }
315       }
316       
317     }
318   
319     /* Set ADVREGEN bit */
320     hadc->Instance->CR |= ADC_CR_ADVREGEN;
321   }
322   
323   /* Configuration of ADC:                                                    */
324   /*  - Resolution                                                            */
325   /*  - Data alignment                                                        */
326   /*  - Scan direction                                                         */
327   /*  - External trigger to start conversion                                  */
328   /*  - External trigger polarity                                             */
329   /*  - Continuous conversion mode                                            */
330   /*  - DMA continuous request                                                */
331   /*  - Overrun                                                               */
332   /*  - AutoDelay feature                                                     */
333   /*  - Discontinuous mode                                                    */
334   hadc->Instance->CFGR1 &= ~( ADC_CFGR1_RES   |
335                              ADC_CFGR1_ALIGN  |
336                              ADC_CFGR1_SCANDIR  |
337                              ADC_CFGR1_EXTSEL |
338                              ADC_CFGR1_EXTEN  |
339                              ADC_CFGR1_CONT   |
340                              ADC_CFGR1_DMACFG |
341                              ADC_CFGR1_OVRMOD |
342                              ADC_CFGR1_AUTDLY |
343                              ADC_CFGR1_AUTOFF |
344                              ADC_CFGR1_DISCEN);
345   
346   hadc->Instance->CFGR1 |= ( hadc->Init.Resolution                                       |
347                             hadc->Init.DataAlign                                         |
348                             ADC_SCANDIR(hadc->Init.ScanConvMode)             |
349                             hadc->Init.ExternalTrigConvEdge                              |
350                             ADC_CONTINUOUS(hadc->Init.ContinuousConvMode)    | 
351                             ADC_DMACONTREQ(hadc->Init.DMAContinuousRequests) |
352                             hadc->Init.Overrun                                           |
353                             __HAL_ADC_CFGR1_AutoDelay(hadc->Init.LowPowerAutoWait)       |
354                             __HAL_ADC_CFGR1_AUTOFF(hadc->Init.LowPowerAutoPowerOff));
355   
356   /* Configure the external trigger only if Conversion edge is not "NONE" */
357   if (hadc->Init.ExternalTrigConvEdge != ADC_EXTERNALTRIGCONVEDGE_NONE)
358   {
359     hadc->Instance->CFGR1 |= hadc->Init.ExternalTrigConv;
360   }
361   
362   /* Enable discontinuous mode only if continuous mode is disabled */
363   if ((hadc->Init.DiscontinuousConvMode == ENABLE) && (hadc->Init.ContinuousConvMode == DISABLE))
364   {  
365     /* Enable the selected ADC discontinuous mode */   
366     hadc->Instance->CFGR1 |= ( ADC_CFGR1_DISCEN);
367   }
368   
369   if (hadc->Init.OversamplingMode == ENABLE)
370   {
371     assert_param(IS_ADC_OVERSAMPLING_RATIO(hadc->Init.Oversample.Ratio));
372     assert_param(IS_ADC_RIGHT_BIT_SHIFT(hadc->Init.Oversample.RightBitShift));
373     assert_param(IS_ADC_TRIGGERED_OVERSAMPLING_MODE(hadc->Init.Oversample.TriggeredMode));
374
375     /* Configuration of Oversampler:                                          */
376     /*  - Oversampling Ratio                                                  */
377     /*  - Right bit shift                                                     */
378     /*  - Triggered mode                                                      */
379     
380     hadc->Instance->CFGR2 &= ~( ADC_CFGR2_OVSR |
381                                 ADC_CFGR2_OVSS |
382                                 ADC_CFGR2_TOVS );
383     
384     hadc->Instance->CFGR2 |= ( hadc->Init.Oversample.Ratio         |
385                                hadc->Init.Oversample.RightBitShift             |
386                                hadc->Init.Oversample.TriggeredMode );
387     
388     /* Enable OverSampling mode */
389      hadc->Instance->CFGR2 |= ADC_CFGR2_OVSE;
390   }
391   else
392   {
393     /* Disable OverSampling mode */
394      hadc->Instance->CFGR2 &= ~ADC_CFGR2_OVSE;
395   }    
396   
397   /* Clear the old sampling time */
398   hadc->Instance->SMPR &= (uint32_t)(~ADC_SMPR_SMPR);
399   
400   /* Set the new sample time */
401   hadc->Instance->SMPR |= hadc->Init.SamplingTime;
402   
403   
404   /* Set ADC error code to none */
405   hadc->ErrorCode = HAL_ADC_ERROR_NONE;
406   
407   /* Initialize the ADC state */
408   hadc->State = HAL_ADC_STATE_READY;
409   
410   /* Return function status */
411   return HAL_OK;
412 }
413
414 /**
415   * @brief  Deinitialize the ADC peripheral registers to its default reset values.
416   * @note   To not impact other ADCs, reset of common ADC registers have been
417   *         left commented below.
418   *         If needed, the example code can be copied and uncommented into
419   *         function HAL_ADC_MspDeInit().
420   * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains
421   *         the configuration information for the specified ADC.  
422   * @retval HAL status
423   */
424 HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef* hadc)
425 {
426   uint32_t tickstart = 0;
427   
428   /* Check ADC handle */
429   if(hadc == NULL)
430   {
431      return HAL_ERROR;
432   }
433   
434   /* Check the parameters */
435   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
436   
437   /* Change ADC state */
438   hadc->State = HAL_ADC_STATE_BUSY;
439   
440   /* Stop potential conversion ongoing */
441   if (HAL_IS_BIT_SET(hadc->Instance->CR, ADC_CR_ADSTART) && HAL_IS_BIT_CLR(hadc->Instance->CR, ADC_CR_ADDIS))
442   {
443     /* Stop regular conversion */
444     hadc->Instance->CR |= ADC_CR_ADSTP;
445   }
446   
447   /* Disable ADC: Solution to recover from an unknown ADC state (for example, */
448   /* in case of forbidden action on register bits)                            */
449   /* Procedure to disable the ADC peripheral: wait for conversions            */
450   /* effectively stopped, then disable ADC                                    */
451   /* 1. Wait until ADSTART = 0 */
452   
453   /* Get timeout */
454   tickstart = HAL_GetTick();  
455   
456   while(HAL_IS_BIT_SET(hadc->Instance->CR, ADC_CR_ADSTART))
457   {
458     /* Check for the Timeout */
459     if(ADC_STOP_CONVERSION_TIMEOUT != HAL_MAX_DELAY)
460     {
461       if((HAL_GetTick() - tickstart ) > ADC_STOP_CONVERSION_TIMEOUT)
462       {
463         hadc->State= HAL_ADC_STATE_TIMEOUT;
464         
465         /* Process unlocked */
466         __HAL_UNLOCK(hadc);
467         
468         return HAL_TIMEOUT;
469       }
470     }
471   }
472   
473   /* 2. Disable the ADC peripheral */
474   __HAL_ADC_DISABLE(hadc);
475   
476     
477   /* Reset ADC registers****************/
478   /* Reset register IER */
479   __HAL_ADC_DISABLE_IT(hadc, (ADC_IT_AWD | ADC_IT_OVR | ADC_IT_EOCAL | ADC_IT_EOS |  \
480                               ADC_IT_EOC | ADC_IT_RDY | ADC_IT_EOSMP ));
481       
482   /* Reset register ISR */
483   __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_AWD | ADC_FLAG_EOCAL | ADC_FLAG_OVR | ADC_FLAG_EOS |  \
484                               ADC_FLAG_EOC | ADC_FLAG_EOSMP | ADC_FLAG_RDY));
485   
486   /* Reset register CR */
487   /* Disable voltage regulator */
488   /* Note: Regulator disable useful for power saving */
489   /* Reset ADVREGEN bit */
490   hadc->Instance->CR &= ~ADC_CR_ADVREGEN;
491   
492   /* Bits ADC_CR_ADSTP, ADC_CR_ADSTART are in access mode "read-set": no direct reset applicable */
493   /* No action */
494   
495   /* Reset register CFGR1 */
496   hadc->Instance->CFGR1 &= ~(ADC_CFGR1_AWDCH  | ADC_CFGR1_AWDEN  | ADC_CFGR1_AWDSGL | \
497                              ADC_CFGR1_DISCEN | ADC_CFGR1_AUTOFF | ADC_CFGR1_AUTDLY | \
498                              ADC_CFGR1_CONT   | ADC_CFGR1_OVRMOD | ADC_CFGR1_EXTEN  | \
499                              ADC_CFGR1_EXTSEL | ADC_CFGR1_ALIGN  | ADC_CFGR1_RES    | \
500                              ADC_CFGR1_SCANDIR| ADC_CFGR1_DMACFG | ADC_CFGR1_DMAEN);
501
502   /* Reset register CFGR2 */
503   hadc->Instance->CFGR2 &= ~(ADC_CFGR2_TOVS  | ADC_CFGR2_OVSS  | ADC_CFGR2_OVSR | \
504                              ADC_CFGR2_OVSE  | ADC_CFGR2_CKMODE );
505   
506   /* Reset register SMPR */
507   hadc->Instance->SMPR &= ~(ADC_SMPR_SMPR);
508   
509   /* Reset register TR */
510   hadc->Instance->TR &= ~(ADC_TR_LT | ADC_TR_HT);
511   
512   /* Reset register CALFACT */
513   hadc->Instance->CALFACT &= ~(ADC_CALFACT_CALFACT);
514   
515   /* Reset register DR */
516   /* bits in access mode read only, no direct reset applicable*/
517
518   /* Reset register CALFACT */
519   hadc->Instance->CALFACT &= ~(ADC_CALFACT_CALFACT);
520
521     
522   /* DeInit the low level hardware */
523   HAL_ADC_MspDeInit(hadc);
524   
525   /* Set ADC error code to none */
526   hadc->ErrorCode = HAL_ADC_ERROR_NONE;
527   
528   /* Change ADC state */
529   hadc->State = HAL_ADC_STATE_RESET; 
530   
531   /* Return function status */
532   return HAL_OK;
533 }
534
535 /**
536   * @brief  Initializes the ADC MSP.
537   * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains
538   *         the configuration information for the specified ADC.  
539   * @retval None
540   */
541 __weak void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
542 {
543   /* NOTE : This function Should not be modified, when the callback is needed,
544             the HAL_ADC_MspInit could be implemented in the user file
545    */ 
546 }
547
548 /**
549   * @brief  DeInitializes the ADC MSP.
550   * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains
551   *         the configuration information for the specified ADC.  
552   * @retval None
553   */
554 __weak void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
555 {
556   /* NOTE : This function Should not be modified, when the callback is needed,
557             the HAL_ADC_MspDeInit could be implemented in the user file
558    */ 
559 }
560
561 /**
562   * @}
563   */
564
565 /** @defgroup ADC_Group2 I/O operation functions
566  *  @brief    I/O operation functions 
567  *
568 @verbatim   
569  ===============================================================================
570              ##### IO operation functions #####
571  ===============================================================================  
572     [..]  This section provides functions allowing to:
573       (+) Start conversion.
574       (+) Stop conversion.
575       (+) poll for conversion complete.
576       (+) poll for conversion event.
577       (+) Start conversion and enable interrupt.
578       (+) Stop conversion and disable interrupt.
579       (+) handle ADC interrupt request.
580       (+) Start conversion of regular channel and enable DMA transfer.
581       (+) Stop conversion of regular channel and disable DMA transfer.
582       (+) Get result of regular channel conversion.
583       (+) Handle ADC interrupt request.
584
585 @endverbatim
586   * @{
587   */
588
589
590 /**
591   * @brief  Enables ADC and starts conversion of the regular channels.
592   * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains
593   *         the configuration information for the specified ADC.
594   * @retval HAL status
595   */
596 HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc)
597 {
598   HAL_StatusTypeDef tmpHALStatus = HAL_OK;
599   
600   /* Check the parameters */
601   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
602   
603   /* Perform ADC enable and conversion start if no conversion is on going */
604   if (ADC_IS_CONVERSION_ONGOING(hadc) == RESET)
605   {
606     /* Process locked */
607     __HAL_LOCK(hadc);
608     
609     /* Change ADC state */
610     hadc->State = HAL_ADC_STATE_BUSY_REG;
611     
612     /* Set ADC error code to none */
613     hadc->ErrorCode = HAL_ADC_ERROR_NONE;
614   
615     /* Enable the ADC peripheral */
616     /* If low power mode AutoPowerOff is enabled, power-on/off phases are       */
617     /* performed automatically by hardware.                                     */
618     if (hadc->Init.LowPowerAutoPowerOff != ENABLE)
619     {
620       tmpHALStatus = ADC_Enable(hadc);
621     }
622     
623     /* Start conversion if ADC is effectively enabled */
624     if (tmpHALStatus != HAL_ERROR)
625     {
626       /* ADC start conversion command */
627       hadc->Instance->CR |= ADC_CR_ADSTART;
628     }
629         
630     /* Process unlocked */
631     __HAL_UNLOCK(hadc);
632   }
633   else
634   {
635     tmpHALStatus = HAL_BUSY;
636   }
637   
638   /* Return function status */
639   return tmpHALStatus;
640 }
641
642 /**
643   * @brief  Stop ADC conversion of regular channels, disable ADC peripheral.
644   * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains
645   *         the configuration information for the specified ADC.
646   * @retval None
647   */
648 HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef* hadc)
649 {
650   HAL_StatusTypeDef tmpHALStatus = HAL_OK;
651   
652   /* Process locked */
653   __HAL_LOCK(hadc);
654   
655   /* 1. Stop potential conversion ongoing (regular conversion) */
656   tmpHALStatus = ADC_ConversionStop(hadc, ADC_REGULAR_GROUP);
657   
658   /* 2. Disable ADC peripheral if conversions are effectively stopped */
659   if (tmpHALStatus != HAL_ERROR)
660   {
661     /* Disable the ADC peripheral */
662     tmpHALStatus = ADC_Disable(hadc);
663     
664     /* Check if ADC is effectively disabled */
665     if ((hadc->State != HAL_ADC_STATE_ERROR) && (tmpHALStatus != HAL_ERROR))
666     {
667       /* Change ADC state */
668       hadc->State = HAL_ADC_STATE_READY;
669     }
670     else
671     {
672       return HAL_ERROR;
673     }
674   }
675   else
676   {   
677     return HAL_ERROR;
678   }  
679   
680   /* Process unlocked */
681   __HAL_UNLOCK(hadc);
682   
683   /* Return function status */
684   return HAL_OK;
685 }
686
687 /**
688   * @brief  Wait for regular group conversion to be completed.
689   * @note   ADC conversion flags EOS (end of sequence) and EOC (end of
690   *         conversion) are cleared by this function, with an exception:
691   *         if low power feature "LowPowerAutoWait" is enabled, flags are 
692   *         not cleared to not interfere with this feature until data register
693   *         is read using function HAL_ADC_GetValue().
694   * @note   This function cannot be used in a particular setup: ADC configured 
695   *         in DMA mode and polling for end of each conversion (ADC init
696   *         parameter "EOCSelection" set to ADC_EOC_SINGLE_CONV).
697   *         In this case, DMA resets the flag EOC and polling cannot be
698   *         performed on each conversion. Nevertheless, polling can still 
699   *         be performed on the complete sequence.
700   * @param  hadc: ADC handle
701   * @param  Timeout: Timeout value in millisecond.
702   * @retval HAL status
703   */
704 HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout)
705 {
706   uint32_t tickstart = 0;
707   uint32_t tmp_Flag_EOC;
708  
709   /* Check the parameters */
710   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
711
712   /* If end of conversion selected to end of sequence */
713   if (hadc->Init.EOCSelection == ADC_EOC_SEQ_CONV)
714   {
715     tmp_Flag_EOC = ADC_FLAG_EOS;
716   }
717   /* If end of conversion selected to end of each conversion */
718   else /* ADC_EOC_SINGLE_CONV */
719   {
720     /* Verification that ADC configuration is compliant with polling for      */
721     /* each conversion:                                                       */
722     /* Particular case is ADC configured in DMA mode and ADC sequencer with   */
723     /* several ranks and polling for end of each conversion.                  */
724     /* For code simplicity sake, this particular case is generalized to       */
725     /* ADC configured in DMA mode and and polling for end of each conversion. */
726     if (HAL_IS_BIT_SET(hadc->Instance->CFGR1, ADC_CFGR1_DMAEN))
727     {
728       /* Update ADC state machine to error */
729       hadc->State = HAL_ADC_STATE_ERROR;
730       
731       /* Process unlocked */
732       __HAL_UNLOCK(hadc);
733       
734       return HAL_ERROR;
735     }
736     else
737     {
738       tmp_Flag_EOC = (ADC_FLAG_EOC | ADC_FLAG_EOS);
739     }
740   }
741   
742   /* Get tick */
743   tickstart = HAL_GetTick();
744   
745   /* Wait until End of Conversion flag is raised */
746   while(HAL_IS_BIT_CLR(hadc->Instance->ISR, tmp_Flag_EOC))
747   {
748     /* Check if timeout is disabled (set to infinite wait) */
749     if(Timeout != HAL_MAX_DELAY)
750     {
751       if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
752       {
753         /* Update ADC state machine to timeout */
754         hadc->State = HAL_ADC_STATE_TIMEOUT;
755         
756         /* Process unlocked */
757         __HAL_UNLOCK(hadc);
758         
759         return HAL_TIMEOUT;
760       }
761     }
762   }
763   
764   /* Clear end of conversion flag of regular group if low power feature       */
765   /* "LowPowerAutoWait " is disabled, to not interfere with this feature      */
766   /* until data register is read using function HAL_ADC_GetValue().           */
767   if (hadc->Init.LowPowerAutoWait == DISABLE)
768   {
769     /* Clear regular group conversion flag */
770     __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_EOC | ADC_FLAG_EOS));
771   }
772   
773   /* Update state machine on conversion status if not in error state */
774   if(hadc->State != HAL_ADC_STATE_ERROR)
775   {
776     /* Change ADC state */
777     hadc->State = HAL_ADC_STATE_EOC;
778   }
779   
780   /* Return ADC state */
781   return HAL_OK;
782 }
783
784 /**
785   * @brief  Poll for conversion event.
786   * @param  hadc: ADC handle.
787   * @param  EventType: the ADC event type.
788   *          This parameter can be one of the following values:
789   *            @arg ADC_AWD_EVENT: ADC Analog watchdog event.
790   *            @arg ADC_OVR_EVENT: ADC Overrun event.
791   * @param  Timeout: Timeout value in millisecond.
792   * @retval HAL status
793   */
794 HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout)
795 {
796   uint32_t tickstart = 0; 
797   
798   /* Check the parameters */
799   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
800   assert_param(IS_ADC_EVENT_TYPE(EventType));
801   
802   /* Get timeout */
803   tickstart = HAL_GetTick();
804   
805   /* Check selected event flag */
806   while(!(__HAL_ADC_GET_FLAG(hadc,EventType)))
807   {
808     /* Check if timeout is disabled (set to infinite wait) */
809     if(Timeout != HAL_MAX_DELAY)
810     {
811       if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
812       {
813         /* Update ADC state machine to timeout */
814         hadc->State = HAL_ADC_STATE_TIMEOUT;
815         
816         /* Process unlocked */
817         __HAL_UNLOCK(hadc);
818         
819         return HAL_TIMEOUT;
820       }
821     }
822   }
823   
824   switch(EventType)
825   {
826     /* Check analog watchdog flag */
827   case ADC_AWD_EVENT:
828     /* Change ADC state */
829     hadc->State = HAL_ADC_STATE_AWD;
830     
831     /* Clear ADC analog watchdog flag */
832     __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_AWD);
833     break;
834     
835     /* Case ADC_OVR_EVENT */
836   default:
837     /* Change ADC state */
838     hadc->State = HAL_ADC_STATE_ERROR;
839     
840     /* Clear ADC Overrun flag */
841     __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_OVR);
842     break;
843   }
844   
845   /* Return ADC state */
846   return HAL_OK;
847 }
848
849 /**
850   * @brief  Enables the interrupt and starts ADC conversion of regular channels.
851   * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains
852   *         the configuration information for the specified ADC.
853   * @retval HAL status.
854   */
855 HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc)
856 {
857   HAL_StatusTypeDef tmpHALStatus = HAL_OK;
858     
859   /* Check the parameters */
860   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
861   
862   /* Perform ADC enable and conversion start if no conversion is on going */
863   if (ADC_IS_CONVERSION_ONGOING(hadc) == RESET)
864   {
865     /* Process locked */
866     __HAL_LOCK(hadc);
867     
868     /* State machine update: Change ADC state */
869     hadc->State = HAL_ADC_STATE_BUSY_REG;
870     
871     /* Set ADC error code to none */
872     hadc->ErrorCode = HAL_ADC_ERROR_NONE;
873     
874     /* Enable the ADC peripheral */
875     /* If low power mode AutoPowerOff is enabled, power-on/off phases are       */
876     /* performed automatically by hardware.                                     */
877     if (hadc->Init.LowPowerAutoPowerOff != ENABLE)
878     {
879       tmpHALStatus = ADC_Enable(hadc);
880     }
881     
882     /* Start conversion if ADC is effectively enabled */
883     if (tmpHALStatus != HAL_ERROR)
884     {
885       /* Enable ADC overrun interrupt */
886       __HAL_ADC_ENABLE_IT(hadc, ADC_IT_OVR);
887       
888       /* Enable ADC end of conversion interrupt */
889       switch(hadc->Init.EOCSelection)
890       {
891         case ADC_EOC_SEQ_CONV: 
892           __HAL_ADC_DISABLE_IT(hadc, ADC_IT_EOC);
893           __HAL_ADC_ENABLE_IT(hadc, ADC_IT_EOS);
894           break;
895         /* case ADC_EOC_SINGLE_CONV */
896         default:
897           __HAL_ADC_DISABLE_IT(hadc, ADC_IT_EOS);
898           __HAL_ADC_ENABLE_IT(hadc, ADC_IT_EOC);
899           break;
900       }
901       
902       /* ADC start conversion command */
903       hadc->Instance->CR |= ADC_CR_ADSTART;
904     }
905     
906     else
907     {
908       tmpHALStatus = HAL_ERROR;
909     }
910     
911     /* Process unlocked */
912     __HAL_UNLOCK(hadc);
913   }
914   else
915   {
916     tmpHALStatus = HAL_BUSY;
917   }
918
919   /* Return function status */
920   return tmpHALStatus;
921 }
922
923 /**
924   * @brief  Stop ADC conversion of regular channels, disable interruptions
925   *         EOC/EOS/OVR, disable ADC peripheral.
926   * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains
927   *         the configuration information for the specified ADC.
928   * @retval None
929   */
930 HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc)
931 {
932   HAL_StatusTypeDef tmpHALStatus = HAL_OK;
933     
934   /* Process locked */
935   __HAL_LOCK(hadc);
936   
937   /* 1. Stop potential conversion ongoing (regular conversion) */
938   tmpHALStatus = ADC_ConversionStop(hadc, ADC_REGULAR_GROUP);
939   
940   /* 2. Disable ADC peripheral if conversions are effectively stopped */
941   if (tmpHALStatus != HAL_ERROR)
942   {
943     /* Disable ADC interrupts */
944     __HAL_ADC_DISABLE_IT(hadc, (ADC_IT_EOC | ADC_IT_EOS | ADC_IT_OVR));
945     
946     /* Disable the ADC peripheral */
947     tmpHALStatus = ADC_Disable(hadc);
948     
949     /* Check if ADC is effectively disabled */
950     if ((hadc->State != HAL_ADC_STATE_ERROR) && (tmpHALStatus != HAL_ERROR))
951     {
952       /* Change ADC state */
953       hadc->State = HAL_ADC_STATE_READY;
954     }
955     else
956     {
957       return HAL_ERROR;
958     }
959   }
960   else
961   {   
962     return HAL_ERROR;
963   }
964   
965   
966   /* Process unlocked */
967   __HAL_UNLOCK(hadc);
968   
969   /* Return function status */
970   return HAL_OK;
971 }
972
973 /**
974   * @brief  Handles ADC interrupt request  
975   * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains
976   *         the configuration information for the specified ADC.
977   * @retval None
978   */
979 void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc)
980 {
981   /* Check the parameters */
982   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
983   assert_param(IS_ADC_EOC_SELECTION(hadc->Init.EOCSelection));
984   
985   
986   /* Check End of Conversion flag for regular channels */
987   if( (__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_EOC) && __HAL_ADC_GET_IT_SOURCE(hadc, ADC_IT_EOC)) || \
988       (__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_EOS) && __HAL_ADC_GET_IT_SOURCE(hadc, ADC_IT_EOS)) )
989   {
990     /* Change ADC state */
991     hadc->State = HAL_ADC_STATE_EOC;
992
993     
994     /* Disable interruption if no further conversion upcoming by continuous mode or external trigger */
995     if((hadc->Init.ContinuousConvMode == DISABLE) && \
996        (hadc->Init.ExternalTrigConvEdge == ADC_EXTERNALTRIGCONVEDGE_NONE)
997        )
998     {
999       /* Allowed to modify bits ADC_IT_EOC/ADC_IT_EOS only if bit ADSTART==0 (no conversion on going) */
1000       if (HAL_IS_BIT_CLR(hadc->Instance->CR, ADC_CR_ADSTART))
1001       {
1002         /* Cases of interruption after each conversion or after each sequence */
1003         /* If interruption after each sequence */
1004         if (hadc->Init.EOCSelection == ADC_EOC_SEQ_CONV)
1005         {
1006           /* Allowed to modify bits ADC_IT_EOC/ADC_IT_EOS/ADC_IT_OVR only if bit*/
1007           /* ADSTART==0 (no conversion on going)                                */
1008           if (ADC_IS_CONVERSION_ONGOING(hadc) == RESET)
1009           {
1010             /* If End of Sequence is reached, disable interrupts */
1011             if( __HAL_ADC_GET_FLAG(hadc, ADC_FLAG_EOS) )
1012             {
1013               /* DISABLE ADC end of sequence conversion interrupt  */
1014               /* DISABLE ADC overrun interrupt */
1015               __HAL_ADC_DISABLE_IT(hadc, ADC_IT_EOC | ADC_IT_EOS | ADC_IT_OVR);
1016             }
1017           }
1018           else
1019           {
1020             /* Change ADC state to error state */
1021             hadc->State = HAL_ADC_STATE_ERROR;
1022             /* Set ADC error code to ADC IP internal error */
1023             hadc->ErrorCode |= HAL_ADC_ERROR_INTERNAL;
1024           }
1025         }
1026         /* If interruption after each conversion */
1027         else
1028         {
1029           /* DISABLE ADC end of single conversion interrupt */
1030           /* DISABLE ADC overrun interrupt */
1031           __HAL_ADC_DISABLE_IT(hadc, ADC_IT_EOC | ADC_IT_OVR);
1032         }
1033       }
1034       else
1035       {
1036         /* Change ADC state to error state */
1037         hadc->State = HAL_ADC_STATE_ERROR;
1038       }       
1039     }    
1040
1041     /* Conversion complete callback */
1042     /* Note: into callback, to determine if callback has been triggered from EOC or EOS, */
1043     /*       it is possible to use: if( __HAL_ADC_GET_FLAG(hadc, ADC_FLAG_EOS))         */
1044     HAL_ADC_ConvCpltCallback(hadc);
1045     
1046     /* Clear regular channels conversion flag */
1047     if (hadc->Init.LowPowerAutoWait != ENABLE)
1048     {
1049       __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_EOC | ADC_FLAG_EOS) );
1050     }
1051   }
1052   
1053    
1054   /* Check Analog watchdog flags */
1055   if( (__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_AWD) && __HAL_ADC_GET_IT_SOURCE(hadc, ADC_IT_AWD)))
1056   {
1057     /* Change ADC state */
1058     hadc->State = HAL_ADC_STATE_AWD;
1059     
1060     /* Level out of window callback */
1061     HAL_ADC_LevelOutOfWindowCallback(hadc);
1062     
1063     /* Clear ADC Analog watchdog flag */
1064     __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_AWD);    
1065   }  
1066   
1067   /* Check Overrun flag */
1068   if(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_OVR) && __HAL_ADC_GET_IT_SOURCE(hadc, ADC_IT_OVR))
1069   {
1070     /* Change ADC state to overrun state */
1071     hadc->State = HAL_ADC_STATE_ERROR;
1072     
1073     /* Set ADC error code to overrun */
1074     hadc->ErrorCode |= HAL_ADC_ERROR_OVR;
1075     
1076     /* Clear the Overrun flag */
1077     __HAL_ADC_CLEAR_FLAG(hadc,ADC_FLAG_OVR);
1078     
1079     /* Error callback */ 
1080     HAL_ADC_ErrorCallback(hadc);
1081   }
1082 }
1083
1084 /**
1085   * @brief  Enables ADC DMA request after last transfer (Single-ADC mode) and enables ADC peripheral  
1086   * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains
1087   *         the configuration information for the specified ADC.
1088   * @param  pData: The destination Buffer address.
1089   * @param  Length: The length of data to be transferred from ADC peripheral to memory.
1090   * @retval None
1091   */
1092 HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length)
1093 {
1094   HAL_StatusTypeDef tmpHALStatus = HAL_OK;
1095   
1096   /* Check the parameters */
1097   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1098   
1099   /* Perform ADC enable and conversion start if no conversion is on going */
1100   if (ADC_IS_CONVERSION_ONGOING(hadc) == RESET)
1101   {
1102     /* Process locked */
1103     __HAL_LOCK(hadc);
1104     
1105     /* Change ADC state */
1106     hadc->State = HAL_ADC_STATE_BUSY_REG;
1107     
1108     /* Set ADC error code to none */
1109     hadc->ErrorCode = HAL_ADC_ERROR_NONE;
1110   
1111     /* Enable the ADC peripheral */
1112     /* If low power mode AutoPowerOff is enabled, power-on/off phases are       */
1113     /* performed automatically by hardware.                                     */
1114     if (hadc->Init.LowPowerAutoPowerOff != ENABLE)
1115     {
1116       tmpHALStatus = ADC_Enable(hadc);
1117     }
1118     
1119     /* Start conversion if ADC is effectively enabled */
1120     if (tmpHALStatus != HAL_ERROR)
1121     {
1122       /* Enable ADC DMA mode */
1123       hadc->Instance->CFGR1 |= ADC_CFGR1_DMAEN;
1124       
1125       /* Set the DMA transfer complete callback */
1126       hadc->DMA_Handle->XferCpltCallback = ADC_DMAConvCplt;
1127   
1128       /* Set the DMA half transfer complete callback */
1129       hadc->DMA_Handle->XferHalfCpltCallback = ADC_DMAHalfConvCplt;
1130       
1131       /* Set the DMA error callback */
1132       hadc->DMA_Handle->XferErrorCallback = ADC_DMAError;
1133       
1134       /* Manage ADC and DMA start: ADC overrun interruption, DMA start,
1135          ADC start (in case of SW start) */
1136       
1137       /* Enable ADC overrun interrupt */
1138       __HAL_ADC_ENABLE_IT(hadc, ADC_IT_OVR);
1139       
1140       /* Enable the DMA Stream */
1141       HAL_DMA_Start_IT(hadc->DMA_Handle, (uint32_t)&hadc->Instance->DR, (uint32_t)pData, Length);
1142        
1143       /* ADC start conversion command */
1144       hadc->Instance->CR |= ADC_CR_ADSTART;
1145     }
1146         
1147     /* Process unlocked */
1148     __HAL_UNLOCK(hadc);
1149   }
1150   else
1151   {
1152     tmpHALStatus = HAL_BUSY;
1153   }
1154   
1155   /* Return function status */
1156   return tmpHALStatus;
1157 }
1158
1159 /**
1160   * @brief  Disable ADC DMA (Single-ADC mode), disable ADC peripheral
1161   * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains
1162   *         the configuration information for the specified ADC.
1163   * @retval None
1164   */
1165 HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc)
1166 {
1167   HAL_StatusTypeDef tmpHALStatus = HAL_OK;
1168   
1169   /* Process locked */
1170   __HAL_LOCK(hadc);
1171   
1172   /* 1. Stop potential conversion ongoing (regular conversion) */
1173   tmpHALStatus = ADC_ConversionStop(hadc, ADC_REGULAR_GROUP);
1174   
1175   /* 2. Disable ADC peripheral if conversions are effectively stopped */
1176   if (tmpHALStatus != HAL_ERROR)
1177   {
1178     /* Disable ADC DMA (ADC DMA configuration ADC_CFGR_DMACFG is kept) */
1179     hadc->Instance->CFGR1 &= ~ADC_CFGR1_DMAEN;
1180     
1181     /* Disable the DMA Stream */
1182     if (HAL_DMA_Abort(hadc->DMA_Handle) != HAL_OK)
1183     {
1184       /* Update ADC state machine to error */
1185       hadc->State = HAL_ADC_STATE_ERROR;
1186       
1187       /* Process unlocked */
1188       __HAL_UNLOCK(hadc);
1189       
1190       return HAL_ERROR;
1191     }
1192     
1193     /* Disable ADC overrun interrupt */
1194     __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR);
1195     
1196     /* Disable the ADC peripheral */
1197     tmpHALStatus = ADC_Disable(hadc);
1198     
1199     /* Check if ADC is effectively disabled */
1200     if ((hadc->State != HAL_ADC_STATE_ERROR) && (tmpHALStatus != HAL_ERROR))
1201     {
1202       /* Change ADC state */
1203       hadc->State = HAL_ADC_STATE_READY;
1204     }
1205     else
1206     {
1207       return HAL_ERROR;
1208     }
1209   }
1210   else
1211   {   
1212     return HAL_ERROR;
1213   }  
1214   
1215   /* Process unlocked */
1216   __HAL_UNLOCK(hadc);
1217   
1218   /* Return function status */
1219   return HAL_OK;
1220 }
1221
1222 /**
1223   * @brief  Gets the converted value from data register of regular channel.
1224   * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains
1225   *         the configuration information for the specified ADC.
1226   * @retval Converted value
1227   */
1228 uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef* hadc)
1229 {       
1230   /* Return the selected ADC converted value */ 
1231   return hadc->Instance->DR;
1232 }
1233
1234 /**
1235   * @brief  Regular conversion complete callback in non blocking mode 
1236   * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains
1237   *         the configuration information for the specified ADC.
1238   * @retval None
1239   */
1240 __weak void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
1241 {
1242   /* NOTE : This function Should not be modified, when the callback is needed,
1243             the HAL_ADC_ConvCpltCallback could be implemented in the user file
1244    */
1245 }
1246
1247 /**
1248   * @brief  Regular conversion half DMA transfer callback in non blocking mode 
1249   * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains
1250   *         the configuration information for the specified ADC.
1251   * @retval None
1252   */
1253 __weak void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc)
1254 {
1255   /* NOTE : This function Should not be modified, when the callback is needed,
1256             the HAL_ADC_ConvHalfCpltCallback could be implemented in the user file
1257    */
1258 }
1259
1260 /**
1261   * @brief  Analog watchdog callback in non blocking mode 
1262   * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains
1263   *         the configuration information for the specified ADC.
1264   * @retval None
1265   */
1266 __weak void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc)
1267 {
1268   /* NOTE : This function Should not be modified, when the callback is needed,
1269             the HAL_ADC_LevelOoutOfWindowCallback could be implemented in the user file
1270    */
1271 }
1272
1273 /**
1274   * @brief  Error ADC callback.
1275   * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains
1276   *         the configuration information for the specified ADC.
1277   * @retval None
1278   */
1279 __weak void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc)
1280 {
1281   /* NOTE : This function Should not be modified, when the callback is needed,
1282             the HAL_ADC_ErrorCallback could be implemented in the user file
1283    */
1284 }
1285
1286 /**
1287   * @}
1288   */
1289
1290 /** @defgroup ADC_Group3 Peripheral Control functions
1291  *  @brief      Peripheral Control functions 
1292  *
1293 @verbatim   
1294  ===============================================================================
1295              ##### Peripheral Control functions #####
1296  ===============================================================================  
1297     [..]  This section provides functions allowing to:
1298       (+) Configure channels.
1299       (+) Configure the analog watch dog.
1300       
1301 @endverbatim
1302   * @{
1303   */
1304
1305
1306 /**
1307   * @brief  Configures the selected ADC regular channel: sampling time,
1308   *         offset,.
1309   * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains
1310   *         the configuration information for the specified ADC.
1311   * @param  sConfig: ADC regular channel configuration structure.
1312   * @retval HAL status
1313   */
1314 HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig)
1315 {
1316   /* Check the parameters */
1317   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1318   assert_param(IS_ADC_CHANNEL(sConfig->Channel));
1319   
1320   /* Process locked */
1321   __HAL_LOCK(hadc);    
1322   
1323   /* Parameters update conditioned to ADC state:                              */
1324   /* Parameters that can be updated when ADC is disabled or enabled without   */
1325   /* conversion on going :                                                    */
1326   /*  - Channel number                                                        */
1327   /*  - Management of internal measurement channels: Vbat/VrefInt/TempSensor  */
1328   if (ADC_IS_CONVERSION_ONGOING(hadc) != RESET)
1329   {
1330     /* Update ADC state machine to error */
1331     hadc->State = HAL_ADC_STATE_ERROR;
1332     /* Process unlocked */
1333     __HAL_UNLOCK(hadc);
1334     return HAL_ERROR;
1335   }
1336   
1337   /* Enable selected channels */
1338   hadc->Instance->CHSELR |= (uint32_t)(sConfig->Channel & ADC_CHANNEL_MASK);
1339   
1340   /* Management of internal measurement channels: Vlcd/VrefInt/TempSensor     */
1341   /* internal measurement paths enable: If internal channel selected, enable  */
1342   /* dedicated internal buffers and path.                                     */
1343   
1344   /* If Temperature sensor channel is selected, then enable the internal      */
1345   /* buffers and path  */
1346   if (((sConfig->Channel & ADC_CHANNEL_MASK) & ADC_CHANNEL_TEMPSENSOR ) == (ADC_CHANNEL_TEMPSENSOR & ADC_CHANNEL_MASK))
1347   {
1348     ADC->CCR |= ADC_CCR_TSEN;   
1349     
1350     /* Delay for temperature sensor stabilization time */
1351     ADC_DelayMicroSecond(ADC_TEMPSENSOR_DELAY_US);
1352   }
1353   
1354   /* If VRefInt channel is selected, then enable the internal buffers and path   */
1355   if (((sConfig->Channel & ADC_CHANNEL_MASK) & ADC_CHANNEL_VREFINT) == (ADC_CHANNEL_VREFINT & ADC_CHANNEL_MASK))
1356   {
1357     ADC->CCR |= ADC_CCR_VREFEN;   
1358   }
1359   
1360   /* If Vlcd channel is selected, then enable the internal buffers and path   */
1361   if (((sConfig->Channel & ADC_CHANNEL_MASK) & ADC_CHANNEL_VLCD) == (ADC_CHANNEL_VLCD & ADC_CHANNEL_MASK))
1362   {
1363     ADC->CCR |= ADC_CCR_VLCDEN;   
1364   }
1365  
1366   /* Process unlocked */
1367   __HAL_UNLOCK(hadc);
1368   
1369   /* Return function status */
1370   return HAL_OK;
1371 }
1372
1373 /**
1374   * @brief  Configures the analog watchdog.
1375   * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains
1376   *         the configuration information for the specified ADC.
1377   * @param  AnalogWDGConfig : pointer to an ADC_AnalogWDGConfTypeDef structure 
1378   *         that contains the configuration information of ADC analog watchdog.
1379   * @retval HAL status    
1380   */
1381 HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig)
1382 {
1383   uint32_t tmpAWDHighThresholdShifted;
1384   uint32_t tmpAWDLowThresholdShifted;
1385   
1386   /* Check the parameters */
1387   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1388   assert_param(IS_ADC_ANALOG_WATCHDOG_MODE(AnalogWDGConfig->WatchdogMode));
1389   assert_param(IS_ADC_CHANNEL(AnalogWDGConfig->Channel));
1390   assert_param(IS_FUNCTIONAL_STATE(AnalogWDGConfig->ITMode));
1391   
1392   assert_param(IS_ADC_RANGE(ADC_GET_RESOLUTION(hadc), AnalogWDGConfig->HighThreshold));
1393   assert_param(IS_ADC_RANGE(ADC_GET_RESOLUTION(hadc), AnalogWDGConfig->LowThreshold));
1394   
1395   /* Process locked */
1396   __HAL_LOCK(hadc);
1397   
1398   /* Parameters update conditioned to ADC state:                              */
1399   /* Parameters that can be updated when ADC is disabled or enabled without   */
1400   /* conversion on going :                                                    */
1401   /*  - Analog watchdog channels                                              */
1402   /*  - Analog watchdog thresholds                                            */
1403   if (ADC_IS_CONVERSION_ONGOING(hadc) != RESET)
1404   {
1405     /* Update ADC state machine to error */
1406     hadc->State = HAL_ADC_STATE_ERROR;
1407     /* Process unlocked */
1408     __HAL_UNLOCK(hadc);
1409     return HAL_ERROR;
1410   }
1411
1412   /* Configure ADC Analog watchdog interrupt */
1413   if(AnalogWDGConfig->ITMode == ENABLE)
1414   {
1415     /* Enable the ADC Analog watchdog interrupt */
1416     __HAL_ADC_ENABLE_IT(hadc, ADC_IT_AWD);
1417   }
1418   else
1419   {
1420     /* Disable the ADC Analog watchdog interrupt */
1421     __HAL_ADC_DISABLE_IT(hadc, ADC_IT_AWD);
1422   }
1423     
1424   /* Configuration of analog watchdog:                                        */
1425   /*  - Set the analog watchdog mode                                          */
1426   /*  - Set the Analog watchdog channel (is not used if watchdog              */
1427   /*    mode "all channels": ADC_CFGR1_AWD1SGL=0)                             */
1428   hadc->Instance->CFGR1 &= ~( ADC_CFGR1_AWDSGL |
1429                              ADC_CFGR1_AWDEN  |
1430                              ADC_CFGR1_AWDCH);
1431   
1432   hadc->Instance->CFGR1 |= ( AnalogWDGConfig->WatchdogMode |
1433                             (AnalogWDGConfig->Channel & ADC_CHANNEL_AWD_MASK));
1434   
1435   
1436   /* Shift the offset in function of the selected ADC resolution: Thresholds  */
1437   /* have to be left-aligned on bit 11, the LSB (right bits) are set to 0     */
1438   tmpAWDHighThresholdShifted = ADC_AWD1THRESHOLD_SHIFT_RESOLUTION(hadc, AnalogWDGConfig->HighThreshold);
1439   tmpAWDLowThresholdShifted  = ADC_AWD1THRESHOLD_SHIFT_RESOLUTION(hadc, AnalogWDGConfig->LowThreshold);
1440   
1441   /* Clear High & Low high thresholds */
1442   hadc->Instance->TR &= (uint32_t) ~ (ADC_TR_HT | ADC_TR_LT);
1443   
1444   /* Set the high threshold */
1445   hadc->Instance->TR = ADC_TRX_HIGHTHRESHOLD (tmpAWDHighThresholdShifted);
1446   /* Set the low threshold */
1447   hadc->Instance->TR |= tmpAWDLowThresholdShifted;  
1448   
1449   /* Process unlocked */
1450   __HAL_UNLOCK(hadc);
1451   
1452   /* Return function status */
1453   return HAL_OK;
1454 }
1455
1456 /**
1457   * @}
1458   */
1459
1460 /** @defgroup ADC_Group4 ADC Peripheral State functions
1461  *  @brief   ADC Peripheral State functions 
1462  *
1463 @verbatim   
1464  ===============================================================================
1465             ##### ADC Peripheral State functions #####
1466  ===============================================================================  
1467     [..]
1468     This subsection provides functions allowing to
1469       (+) Check the ADC state.
1470       (+) handle ADC interrupt request.
1471          
1472 @endverbatim
1473   * @{
1474   */
1475
1476 /**
1477   * @brief  return the ADC state
1478   * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains
1479   *         the configuration information for the specified ADC.
1480   * @retval HAL state
1481   */
1482 HAL_ADC_StateTypeDef HAL_ADC_GetState(ADC_HandleTypeDef* hadc)
1483 {
1484   /* Return ADC state */
1485   return hadc->State;
1486 }
1487
1488 /**
1489   * @brief  Return the ADC error code
1490   * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains
1491   *         the configuration information for the specified ADC.
1492   * @retval ADC Error Code
1493   */
1494 uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc)
1495 {
1496   return hadc->ErrorCode;
1497 }
1498
1499
1500 /**
1501   * @}
1502   */
1503
1504 /**
1505   * @brief  Enable the selected ADC.
1506   * @note   Prerequisite condition to use this function: ADC must be disabled
1507   *         and voltage regulator must be enabled (done into HAL_ADC_Init()).
1508   * @note If low power mode AutoPowerOff is enabled, power-on/off phases are
1509   * performed automatically by hardware.
1510   * In this mode, this function is useless and must not be called because 
1511   * flag ADC_FLAG_RDY is not usable.
1512   * Therefore, this function must be called under condition of
1513   * "if (hadc->Init.LowPowerAutoPowerOff != ENABLE)". 
1514   * @param  hadc: ADC handle
1515   * @retval HAL status.
1516   */
1517 static HAL_StatusTypeDef ADC_Enable(ADC_HandleTypeDef* hadc)
1518 {
1519   uint32_t tickstart = 0;
1520
1521   /* ADC enable and wait for ADC ready (in case of ADC is disabled or         */
1522   /* enabling phase not yet completed: flag ADC ready not yet set).           */
1523   /* Timeout implemented to not be stuck if ADC cannot be enabled (possible   */
1524   /* causes: ADC clock not running, ...).                                     */
1525   if (ADC_IS_ENABLE(hadc) == RESET)
1526   {
1527     /* Check if conditions to enable the ADC are fulfilled */
1528     if (ADC_ENABLING_CONDITIONS(hadc) == RESET)
1529     {
1530       /* Update ADC state machine to error */
1531       hadc->State = HAL_ADC_STATE_ERROR;
1532       
1533       /* Set ADC error code to ADC IP internal error */
1534       hadc->ErrorCode |= HAL_ADC_ERROR_INTERNAL;
1535       
1536       return HAL_ERROR;
1537     }
1538     
1539     /* Enable the ADC peripheral */
1540     __HAL_ADC_ENABLE(hadc);
1541     
1542     /* Delay for ADC stabilization time. */
1543     ADC_DelayMicroSecond(ADC_STAB_DELAY_US);
1544
1545     /* Wait for ADC effectively enabled */
1546     /* Get timeout */
1547     tickstart = HAL_GetTick();  
1548     
1549     /* Skip polling for RDY ADRDY when AutoOFF is enabled  */
1550     if (hadc->Init.LowPowerAutoPowerOff != ENABLE)
1551     {      
1552       while(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_RDY) == RESET)
1553       {
1554         /* Check for the Timeout */
1555         if(ADC_ENABLE_TIMEOUT != HAL_MAX_DELAY)
1556         {
1557           if((HAL_GetTick() - tickstart ) > ADC_ENABLE_TIMEOUT)
1558           {
1559             /* Update ADC state machine to error */
1560             hadc->State = HAL_ADC_STATE_ERROR;
1561             
1562             /* Set ADC error code to ADC IP internal error */
1563             hadc->ErrorCode |= HAL_ADC_ERROR_INTERNAL;
1564             
1565             return HAL_ERROR;
1566           }
1567         }
1568       }
1569     }
1570   }
1571    
1572   /* Return HAL status */
1573   return HAL_OK;
1574 }
1575
1576 /**
1577   * @brief  Disable the selected ADC.
1578   * @note   Prerequisite condition to use this function: ADC conversions must be
1579   *         stopped to disable the ADC.
1580   * @param  hadc: ADC handle
1581   * @retval HAL status.
1582   */
1583 static HAL_StatusTypeDef ADC_Disable(ADC_HandleTypeDef* hadc)
1584 {
1585   uint32_t tickstart = 0;
1586   
1587   /* Verification if ADC is not already disabled:                             */
1588   /* forbidden to disable ADC (set bit ADC_CR_ADDIS) if ADC is already        */
1589   /* disabled.                                                                */
1590   if (ADC_IS_ENABLE(hadc) != RESET )
1591   {
1592     /* Check if conditions to disable the ADC are fulfilled */
1593     if (ADC_DISABLING_CONDITIONS(hadc) != RESET)
1594     {
1595       /* Disable the ADC peripheral */
1596       __HAL_ADC_DISABLE(hadc);
1597     }
1598     else
1599     {
1600       /* Update ADC state machine to error */
1601       hadc->State = HAL_ADC_STATE_ERROR;
1602       
1603       /* Set ADC error code to ADC internal error */
1604       hadc->ErrorCode |= HAL_ADC_ERROR_INTERNAL;
1605       
1606       return HAL_ERROR;
1607     }
1608      
1609     /* Wait for ADC effectively disabled */
1610     /* Get timeout */
1611     tickstart = HAL_GetTick();
1612     
1613     while(HAL_IS_BIT_SET(hadc->Instance->CR, ADC_CR_ADEN))
1614     {
1615       /* Check for the Timeout */
1616       if(ADC_ENABLE_TIMEOUT != HAL_MAX_DELAY)
1617       {
1618         if((HAL_GetTick() - tickstart ) > ADC_DISABLE_TIMEOUT)
1619         {
1620           /* Update ADC state machine to error */
1621           hadc->State = HAL_ADC_STATE_ERROR;
1622           
1623           /* Set ADC error code to ADC internal error */
1624           hadc->ErrorCode |= HAL_ADC_ERROR_INTERNAL;
1625           
1626           return HAL_ERROR;
1627         }
1628       }
1629     }
1630   }
1631   
1632   /* Return HAL status */
1633   return HAL_OK;
1634 }
1635
1636 /**
1637   * @brief  Stop ADC conversion.
1638   * @note   Prerequisite condition to use this function: ADC conversions must be
1639   *         stopped to disable the ADC.
1640   * @param  hadc: ADC handle
1641   * @param  ConversionGroup: Only ADC group regular.
1642   *          This parameter can be one of the following values:
1643   *            @arg ADC_REGULAR_GROUP: ADC regular conversion type.
1644   * @retval HAL status.
1645   */
1646 static HAL_StatusTypeDef ADC_ConversionStop(ADC_HandleTypeDef* hadc, uint32_t ConversionGroup)
1647 {
1648   uint32_t tickstart = 0 ;
1649
1650   /* Check the parameters */
1651   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1652   assert_param(IS_ADC_CONVERSION_GROUP(ConversionGroup));
1653   
1654   /* Parameters update conditioned to ADC state:                              */
1655   /* Parameters that can be updated when ADC is disabled or enabled without   */
1656   /* conversion on going :                                                    */
1657   if (ADC_IS_CONVERSION_ONGOING(hadc) != RESET)
1658   {
1659     /* Update ADC state machine to error */
1660     hadc->State = HAL_ADC_STATE_ERROR;
1661     /* Process unlocked */
1662     return HAL_ERROR;
1663   }  
1664   
1665   /* Verification: if ADC is not already stopped, bypass this function */
1666   if (HAL_IS_BIT_SET(hadc->Instance->CR, ADC_CR_ADSTART))
1667   {    
1668     /* Stop potential conversion on regular group */
1669     if (ConversionGroup == ADC_REGULAR_GROUP)
1670     {
1671       /* Software is allowed to set ADSTP only when ADSTART=1 and ADDIS=0 */
1672       if (HAL_IS_BIT_SET(hadc->Instance->CR, ADC_CR_ADSTART) && \
1673           HAL_IS_BIT_CLR(hadc->Instance->CR, ADC_CR_ADDIS)                  )
1674       {
1675         /* Stop conversions on regular group */
1676         hadc->Instance->CR |= ADC_CR_ADSTP;
1677       }
1678     }
1679     
1680     /* Wait for conversion effectively stopped */
1681     /* Get timeout */
1682     tickstart = HAL_GetTick();
1683       
1684     while((hadc->Instance->CR & ADC_CR_ADSTART) != RESET)
1685     {
1686       /* Check for the Timeout */
1687       if(ADC_STOP_CONVERSION_TIMEOUT != HAL_MAX_DELAY)
1688       {
1689         if((HAL_GetTick() - tickstart ) > ADC_STOP_CONVERSION_TIMEOUT)
1690         {
1691           /* Update ADC state machine to error */
1692           hadc->State = HAL_ADC_STATE_ERROR;
1693           
1694           /* Set ADC error code to ADC IP internal error */
1695           hadc->ErrorCode |= HAL_ADC_ERROR_INTERNAL;
1696           
1697           return HAL_ERROR;
1698         }
1699       }
1700     }    
1701   }
1702    
1703   /* Return HAL status */
1704   return HAL_OK;
1705 }
1706
1707 /**
1708   * @brief  DMA transfer complete callback. 
1709   * @param  hdma: pointer to DMA handle.
1710   * @retval None
1711   */
1712 static void ADC_DMAConvCplt(DMA_HandleTypeDef *hdma)   
1713 {
1714     ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1715
1716     /* Change ADC state */
1717     hadc->State = HAL_ADC_STATE_EOC;
1718     
1719     HAL_ADC_ConvCpltCallback(hadc); 
1720 }
1721
1722 /**
1723   * @brief  DMA half transfer complete callback. 
1724   * @param  hdma: pointer to DMA handle.
1725   * @retval None
1726   */
1727 static void ADC_DMAHalfConvCplt(DMA_HandleTypeDef *hdma)   
1728 {
1729     ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1730     
1731     /* Conversion complete callback */
1732     HAL_ADC_ConvHalfCpltCallback(hadc); 
1733 }
1734
1735 /**
1736   * @brief  DMA error callback 
1737   * @param  hdma: pointer to DMA handle.
1738   * @retval None
1739   */
1740 static void ADC_DMAError(DMA_HandleTypeDef *hdma)   
1741 {
1742     ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1743     hadc->State= HAL_ADC_STATE_ERROR;
1744     /* Set ADC error code to DMA error */
1745     hadc->ErrorCode |= HAL_ADC_ERROR_DMA;
1746     HAL_ADC_ErrorCallback(hadc); 
1747 }
1748
1749 /**
1750   * @brief  Delay micro seconds 
1751   * @param  microSecond : delay
1752   * @retval None
1753   */
1754 static void ADC_DelayMicroSecond(uint32_t microSecond)
1755 {
1756   /* Compute number of CPU cycles to wait for */
1757   __IO uint32_t waitLoopIndex = (microSecond * (SystemCoreClock / 1000000));
1758
1759   while(waitLoopIndex != 0)
1760   {
1761     waitLoopIndex--;
1762   } 
1763 }
1764
1765 /**
1766   * @}
1767   */
1768
1769 #endif /* HAL_ADC_MODULE_ENABLED */
1770 /**
1771   * @}
1772   */
1773
1774 /**
1775   * @}
1776   */ 
1777
1778 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/