1 /**
2   ******************************************************************************
3   * @file    stm32f0xx_ll_adc.c
4   * @author  MCD Application Team
5   * @brief   ADC LL module driver
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2016 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 #if defined(USE_FULL_LL_DRIVER)
20 
21 /* Includes ------------------------------------------------------------------*/
22 #include "stm32f0xx_ll_adc.h"
23 #include "stm32f0xx_ll_bus.h"
24 
25 #ifdef  USE_FULL_ASSERT
26   #include "stm32_assert.h"
27 #else
28   #define assert_param(expr) ((void)0U)
29 #endif
30 
31 /** @addtogroup STM32F0xx_LL_Driver
32   * @{
33   */
34 
35 #if defined (ADC1)
36 
37 /** @addtogroup ADC_LL ADC
38   * @{
39   */
40 
41 /* Private types -------------------------------------------------------------*/
42 /* Private variables ---------------------------------------------------------*/
43 /* Private constants ---------------------------------------------------------*/
44 /** @addtogroup ADC_LL_Private_Constants
45   * @{
46   */
47 
48 /* Definitions of ADC hardware constraints delays */
49 /* Note: Only ADC IP HW delays are defined in ADC LL driver driver,           */
50 /*       not timeout values:                                                  */
51 /*       Timeout values for ADC operations are dependent to device clock      */
52 /*       configuration (system clock versus ADC clock),                       */
53 /*       and therefore must be defined in user application.                   */
54 /*       Refer to @ref ADC_LL_EC_HW_DELAYS for description of ADC timeout     */
55 /*       values definition.                                                   */
56 /* Note: ADC timeout values are defined here in CPU cycles to be independent  */
57 /*       of device clock setting.                                             */
58 /*       In user application, ADC timeout values should be defined with       */
59 /*       temporal values, in function of device clock settings.               */
60 /*       Highest ratio CPU clock frequency vs ADC clock frequency:            */
61 /*        - ADC clock from synchronous clock with AHB prescaler 512,          */
62 /*          APB prescaler 16, ADC prescaler 4.                                */
63 /*        - ADC clock from asynchronous clock (HSI) with prescaler 1,         */
64 /*          with highest ratio CPU clock frequency vs HSI clock frequency:    */
65 /*          CPU clock frequency max 48MHz, HSI frequency 14MHz: ratio 4.      */
66 /* Unit: CPU cycles.                                                          */
67 #define ADC_CLOCK_RATIO_VS_CPU_HIGHEST          ((uint32_t) 512U * 16U * 4U)
68 #define ADC_TIMEOUT_DISABLE_CPU_CYCLES          (ADC_CLOCK_RATIO_VS_CPU_HIGHEST * 1U)
69 #define ADC_TIMEOUT_STOP_CONVERSION_CPU_CYCLES  (ADC_CLOCK_RATIO_VS_CPU_HIGHEST * 1U)
70 
71 /**
72   * @}
73   */
74 
75 /* Private macros ------------------------------------------------------------*/
76 
77 /** @addtogroup ADC_LL_Private_Macros
78   * @{
79   */
80 
81 /* Check of parameters for configuration of ADC hierarchical scope:           */
82 /* common to several ADC instances.                                           */
83 /* Check of parameters for configuration of ADC hierarchical scope:           */
84 /* ADC instance.                                                              */
85 #define IS_LL_ADC_CLOCK(__CLOCK__)                                             \
86   (   ((__CLOCK__) == LL_ADC_CLOCK_SYNC_PCLK_DIV4)                             \
87    || ((__CLOCK__) == LL_ADC_CLOCK_SYNC_PCLK_DIV2)                             \
88    || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC)                                      \
89   )
90 
91 #define IS_LL_ADC_RESOLUTION(__RESOLUTION__)                                   \
92   (   ((__RESOLUTION__) == LL_ADC_RESOLUTION_12B)                              \
93    || ((__RESOLUTION__) == LL_ADC_RESOLUTION_10B)                              \
94    || ((__RESOLUTION__) == LL_ADC_RESOLUTION_8B)                               \
95    || ((__RESOLUTION__) == LL_ADC_RESOLUTION_6B)                               \
96   )
97 
98 #define IS_LL_ADC_DATA_ALIGN(__DATA_ALIGN__)                                   \
99   (   ((__DATA_ALIGN__) == LL_ADC_DATA_ALIGN_RIGHT)                            \
100    || ((__DATA_ALIGN__) == LL_ADC_DATA_ALIGN_LEFT)                             \
101   )
102 
103 #define IS_LL_ADC_LOW_POWER(__LOW_POWER__)                                     \
104   (   ((__LOW_POWER__) == LL_ADC_LP_MODE_NONE)                                 \
105    || ((__LOW_POWER__) == LL_ADC_LP_AUTOWAIT)                                  \
106    || ((__LOW_POWER__) == LL_ADC_LP_AUTOPOWEROFF)                              \
107    || ((__LOW_POWER__) == LL_ADC_LP_AUTOWAIT_AUTOPOWEROFF)                     \
108   )
109 
110 /* Check of parameters for configuration of ADC hierarchical scope:           */
111 /* ADC group regular                                                          */
112 #define IS_LL_ADC_REG_TRIG_SOURCE(__REG_TRIG_SOURCE__)                         \
113   (   ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE)                      \
114    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO)                 \
115    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH4)                  \
116    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_TRGO)                 \
117    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO)                 \
118    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM15_TRGO)                \
119   )
120 
121 #define IS_LL_ADC_REG_CONTINUOUS_MODE(__REG_CONTINUOUS_MODE__)                 \
122   (   ((__REG_CONTINUOUS_MODE__) == LL_ADC_REG_CONV_SINGLE)                    \
123    || ((__REG_CONTINUOUS_MODE__) == LL_ADC_REG_CONV_CONTINUOUS)                \
124   )
125 
126 #define IS_LL_ADC_REG_DMA_TRANSFER(__REG_DMA_TRANSFER__)                       \
127   (   ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_NONE)                 \
128    || ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_LIMITED)              \
129    || ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_UNLIMITED)            \
130   )
131 
132 #define IS_LL_ADC_REG_OVR_DATA_BEHAVIOR(__REG_OVR_DATA_BEHAVIOR__)             \
133   (   ((__REG_OVR_DATA_BEHAVIOR__) == LL_ADC_REG_OVR_DATA_PRESERVED)           \
134    || ((__REG_OVR_DATA_BEHAVIOR__) == LL_ADC_REG_OVR_DATA_OVERWRITTEN)         \
135   )
136 
137 #define IS_LL_ADC_REG_SEQ_SCAN_DISCONT_MODE(__REG_SEQ_DISCONT_MODE__)          \
138   (   ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_DISABLE)           \
139    || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_1RANK)             \
140   )
141 
142 /**
143   * @}
144   */
145 
146 
147 /* Private function prototypes -----------------------------------------------*/
148 
149 /* Exported functions --------------------------------------------------------*/
150 /** @addtogroup ADC_LL_Exported_Functions
151   * @{
152   */
153 
154 /** @addtogroup ADC_LL_EF_Init
155   * @{
156   */
157 
158 /**
159   * @brief  De-initialize registers of all ADC instances belonging to
160   *         the same ADC common instance to their default reset values.
161   * @note   This function is performing a hard reset, using high level
162   *         clock source RCC ADC reset.
163   * @param  ADCxy_COMMON ADC common instance
164   *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
165   * @retval An ErrorStatus enumeration value:
166   *          - SUCCESS: ADC common registers are de-initialized
167   *          - ERROR: not applicable
168   */
LL_ADC_CommonDeInit(ADC_Common_TypeDef * ADCxy_COMMON)169 ErrorStatus LL_ADC_CommonDeInit(ADC_Common_TypeDef *ADCxy_COMMON)
170 {
171   /* Check the parameters */
172   assert_param(IS_ADC_COMMON_INSTANCE(ADCxy_COMMON));
173 
174   /* Force reset of ADC clock (core clock) */
175   LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_ADC1);
176 
177   /* Release reset of ADC clock (core clock) */
178   LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_ADC1);
179 
180   return SUCCESS;
181 }
182 
183 
184 /**
185   * @brief  De-initialize registers of the selected ADC instance
186   *         to their default reset values.
187   * @note   To reset all ADC instances quickly (perform a hard reset),
188   *         use function @ref LL_ADC_CommonDeInit().
189   * @note   If this functions returns error status, it means that ADC instance
190   *         is in an unknown state.
191   *         In this case, perform a hard reset using high level
192   *         clock source RCC ADC reset.
193   *         Refer to function @ref LL_ADC_CommonDeInit().
194   * @param  ADCx ADC instance
195   * @retval An ErrorStatus enumeration value:
196   *          - SUCCESS: ADC registers are de-initialized
197   *          - ERROR: ADC registers are not de-initialized
198   */
LL_ADC_DeInit(ADC_TypeDef * ADCx)199 ErrorStatus LL_ADC_DeInit(ADC_TypeDef *ADCx)
200 {
201   ErrorStatus status = SUCCESS;
202 
203   __IO uint32_t timeout_cpu_cycles = 0U;
204 
205   /* Check the parameters */
206   assert_param(IS_ADC_ALL_INSTANCE(ADCx));
207 
208   /* Disable ADC instance if not already disabled.                            */
209   if(LL_ADC_IsEnabled(ADCx) == 1U)
210   {
211     /* Stop potential ADC conversion on going on ADC group regular.           */
212     if(LL_ADC_REG_IsConversionOngoing(ADCx) != 0U)
213     {
214       if(LL_ADC_REG_IsStopConversionOngoing(ADCx) == 0U)
215       {
216         LL_ADC_REG_StopConversion(ADCx);
217       }
218     }
219 
220     /* Wait for ADC conversions are effectively stopped                       */
221     timeout_cpu_cycles = ADC_TIMEOUT_STOP_CONVERSION_CPU_CYCLES;
222     while (LL_ADC_REG_IsStopConversionOngoing(ADCx) == 1UL)
223     {
224       timeout_cpu_cycles--;
225       if (timeout_cpu_cycles == 0UL)
226       {
227         /* Time-out error */
228         status = ERROR;
229         break;
230       }
231     }
232   }
233 
234   /* Disable the ADC instance */
235   LL_ADC_Disable(ADCx);
236 
237   /* Wait for ADC instance is effectively disabled */
238   timeout_cpu_cycles = ADC_TIMEOUT_DISABLE_CPU_CYCLES;
239   while (LL_ADC_IsDisableOngoing(ADCx) == 1U)
240   {
241     if(timeout_cpu_cycles-- == 0U)
242     {
243       /* Time-out error */
244       status = ERROR;
245     }
246   }
247 
248   /* Check whether ADC state is compliant with expected state */
249   if(READ_BIT(ADCx->CR,
250               (  ADC_CR_ADSTP | ADC_CR_ADSTART
251                | ADC_CR_ADDIS | ADC_CR_ADEN   )
252              )
253      == 0U)
254   {
255     /* ========== Reset ADC registers ========== */
256     /* Reset register IER */
257     CLEAR_BIT(ADCx->IER,
258               (  LL_ADC_IT_ADRDY
259                | LL_ADC_IT_EOC
260                | LL_ADC_IT_EOS
261                | LL_ADC_IT_OVR
262                | LL_ADC_IT_EOSMP
263                | LL_ADC_IT_AWD1 )
264              );
265 
266     /* Reset register ISR */
267     SET_BIT(ADCx->ISR,
268             (  LL_ADC_FLAG_ADRDY
269              | LL_ADC_FLAG_EOC
270              | LL_ADC_FLAG_EOS
271              | LL_ADC_FLAG_OVR
272              | LL_ADC_FLAG_EOSMP
273              | LL_ADC_FLAG_AWD1 )
274            );
275 
276     /* Reset register CR */
277     /* Bits ADC_CR_ADCAL, ADC_CR_ADSTP, ADC_CR_ADSTART are in access mode     */
278     /* "read-set": no direct reset applicable.                                */
279     /* No action on register CR */
280 
281     /* Reset register CFGR1 */
282     CLEAR_BIT(ADCx->CFGR1,
283               (  ADC_CFGR1_AWDCH   | ADC_CFGR1_AWDEN  | ADC_CFGR1_AWDSGL  | ADC_CFGR1_DISCEN
284                | ADC_CFGR1_AUTOFF  | ADC_CFGR1_WAIT   | ADC_CFGR1_CONT    | ADC_CFGR1_OVRMOD
285                | ADC_CFGR1_EXTEN   | ADC_CFGR1_EXTSEL | ADC_CFGR1_ALIGN   | ADC_CFGR1_RES
286                | ADC_CFGR1_SCANDIR | ADC_CFGR1_DMACFG | ADC_CFGR1_DMAEN                     )
287              );
288 
289     /* Reset register CFGR2 */
290     /* Note: Update of ADC clock mode is conditioned to ADC state disabled:   */
291     /*       already done above.                                              */
292     CLEAR_BIT(ADCx->CFGR2, ADC_CFGR2_CKMODE);
293 
294     /* Reset register SMPR */
295     CLEAR_BIT(ADCx->SMPR, ADC_SMPR_SMP);
296 
297     /* Reset register TR */
298     MODIFY_REG(ADCx->TR, ADC_TR_HT | ADC_TR_LT, ADC_TR_HT);
299 
300     /* Reset register CHSELR */
301 #if defined(ADC_CCR_VBATEN)
302     CLEAR_BIT(ADCx->CHSELR,
303               (  ADC_CHSELR_CHSEL18 | ADC_CHSELR_CHSEL17 | ADC_CHSELR_CHSEL16
304                | ADC_CHSELR_CHSEL15 | ADC_CHSELR_CHSEL14 | ADC_CHSELR_CHSEL13 | ADC_CHSELR_CHSEL12
305                | ADC_CHSELR_CHSEL11 | ADC_CHSELR_CHSEL10 | ADC_CHSELR_CHSEL9  | ADC_CHSELR_CHSEL8
306                | ADC_CHSELR_CHSEL7  | ADC_CHSELR_CHSEL6  | ADC_CHSELR_CHSEL5  | ADC_CHSELR_CHSEL4
307                | ADC_CHSELR_CHSEL3  | ADC_CHSELR_CHSEL2  | ADC_CHSELR_CHSEL1  | ADC_CHSELR_CHSEL0 )
308              );
309 #else
310     CLEAR_BIT(ADCx->CHSELR,
311               (                       ADC_CHSELR_CHSEL17 | ADC_CHSELR_CHSEL16
312                | ADC_CHSELR_CHSEL15 | ADC_CHSELR_CHSEL14 | ADC_CHSELR_CHSEL13 | ADC_CHSELR_CHSEL12
313                | ADC_CHSELR_CHSEL11 | ADC_CHSELR_CHSEL10 | ADC_CHSELR_CHSEL9  | ADC_CHSELR_CHSEL8
314                | ADC_CHSELR_CHSEL7  | ADC_CHSELR_CHSEL6  | ADC_CHSELR_CHSEL5  | ADC_CHSELR_CHSEL4
315                | ADC_CHSELR_CHSEL3  | ADC_CHSELR_CHSEL2  | ADC_CHSELR_CHSEL1  | ADC_CHSELR_CHSEL0 )
316              );
317 #endif
318 
319     /* Reset register DR */
320     /* bits in access mode read only, no direct reset applicable */
321 
322   }
323   else
324   {
325     /* ADC instance is in an unknown state */
326     /* Need to performing a hard reset of ADC instance, using high level      */
327     /* clock source RCC ADC reset.                                            */
328     /* Caution: On this STM32 series, if several ADC instances are available   */
329     /*          on the selected device, RCC ADC reset will reset              */
330     /*          all ADC instances belonging to the common ADC instance.       */
331     status = ERROR;
332   }
333 
334   return status;
335 }
336 
337 /**
338   * @brief  Initialize some features of ADC instance.
339   * @note   These parameters have an impact on ADC scope: ADC instance.
340   *         Refer to corresponding unitary functions into
341   *         @ref ADC_LL_EF_Configuration_ADC_Instance .
342   * @note   The setting of these parameters by function @ref LL_ADC_Init()
343   *         is conditioned to ADC state:
344   *         ADC instance must be disabled.
345   *         This condition is applied to all ADC features, for efficiency
346   *         and compatibility over all STM32 families. However, the different
347   *         features can be set under different ADC state conditions
348   *         (setting possible with ADC enabled without conversion on going,
349   *         ADC enabled with conversion on going, ...)
350   *         Each feature can be updated afterwards with a unitary function
351   *         and potentially with ADC in a different state than disabled,
352   *         refer to description of each function for setting
353   *         conditioned to ADC state.
354   * @note   After using this function, some other features must be configured
355   *         using LL unitary functions.
356   *         The minimum configuration remaining to be done is:
357   *          - Set ADC group regular sequencer:
358   *            map channel on rank corresponding to channel number.
359   *            Refer to function @ref LL_ADC_REG_SetSequencerChannels();
360   *          - Set ADC channel sampling time
361   *            Refer to function LL_ADC_SetChannelSamplingTime();
362   * @param  ADCx ADC instance
363   * @param  ADC_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
364   * @retval An ErrorStatus enumeration value:
365   *          - SUCCESS: ADC registers are initialized
366   *          - ERROR: ADC registers are not initialized
367   */
LL_ADC_Init(ADC_TypeDef * ADCx,LL_ADC_InitTypeDef * ADC_InitStruct)368 ErrorStatus LL_ADC_Init(ADC_TypeDef *ADCx, LL_ADC_InitTypeDef *ADC_InitStruct)
369 {
370   ErrorStatus status = SUCCESS;
371 
372   /* Check the parameters */
373   assert_param(IS_ADC_ALL_INSTANCE(ADCx));
374 
375   assert_param(IS_LL_ADC_CLOCK(ADC_InitStruct->Clock));
376   assert_param(IS_LL_ADC_RESOLUTION(ADC_InitStruct->Resolution));
377   assert_param(IS_LL_ADC_DATA_ALIGN(ADC_InitStruct->DataAlignment));
378   assert_param(IS_LL_ADC_LOW_POWER(ADC_InitStruct->LowPowerMode));
379 
380   /* Note: Hardware constraint (refer to description of this function):       */
381   /*       ADC instance must be disabled.                                     */
382   if(LL_ADC_IsEnabled(ADCx) == 0U)
383   {
384     /* Configuration of ADC hierarchical scope:                               */
385     /*  - ADC instance                                                        */
386     /*    - Set ADC data resolution                                           */
387     /*    - Set ADC conversion data alignment                                 */
388     /*    - Set ADC low power mode                                            */
389     MODIFY_REG(ADCx->CFGR1,
390                  ADC_CFGR1_RES
391                | ADC_CFGR1_ALIGN
392                | ADC_CFGR1_WAIT
393                | ADC_CFGR1_AUTOFF
394               ,
395                  ADC_InitStruct->Resolution
396                | ADC_InitStruct->DataAlignment
397                | ADC_InitStruct->LowPowerMode
398               );
399 
400     MODIFY_REG(ADCx->CFGR2,
401                ADC_CFGR2_CKMODE
402               ,
403                ADC_InitStruct->Clock
404               );
405   }
406   else
407   {
408     /* Initialization error: ADC instance is not disabled. */
409     status = ERROR;
410   }
411   return status;
412 }
413 
414 /**
415   * @brief  Set each @ref LL_ADC_InitTypeDef field to default value.
416   * @param  ADC_InitStruct Pointer to a @ref LL_ADC_InitTypeDef structure
417   *                        whose fields will be set to default values.
418   * @retval None
419   */
LL_ADC_StructInit(LL_ADC_InitTypeDef * ADC_InitStruct)420 void LL_ADC_StructInit(LL_ADC_InitTypeDef *ADC_InitStruct)
421 {
422   /* Set ADC_InitStruct fields to default values */
423   /* Set fields of ADC instance */
424   ADC_InitStruct->Clock         = LL_ADC_CLOCK_SYNC_PCLK_DIV2;
425   ADC_InitStruct->Resolution    = LL_ADC_RESOLUTION_12B;
426   ADC_InitStruct->DataAlignment = LL_ADC_DATA_ALIGN_RIGHT;
427   ADC_InitStruct->LowPowerMode  = LL_ADC_LP_MODE_NONE;
428 
429 }
430 
431 /**
432   * @brief  Initialize some features of ADC group regular.
433   * @note   These parameters have an impact on ADC scope: ADC group regular.
434   *         Refer to corresponding unitary functions into
435   *         @ref ADC_LL_EF_Configuration_ADC_Group_Regular
436   *         (functions with prefix "REG").
437   * @note   The setting of these parameters by function @ref LL_ADC_Init()
438   *         is conditioned to ADC state:
439   *         ADC instance must be disabled.
440   *         This condition is applied to all ADC features, for efficiency
441   *         and compatibility over all STM32 families. However, the different
442   *         features can be set under different ADC state conditions
443   *         (setting possible with ADC enabled without conversion on going,
444   *         ADC enabled with conversion on going, ...)
445   *         Each feature can be updated afterwards with a unitary function
446   *         and potentially with ADC in a different state than disabled,
447   *         refer to description of each function for setting
448   *         conditioned to ADC state.
449   * @note   After using this function, other features must be configured
450   *         using LL unitary functions.
451   *         The minimum configuration remaining to be done is:
452   *          - Set ADC group regular sequencer:
453   *            map channel on rank corresponding to channel number.
454   *            Refer to function @ref LL_ADC_REG_SetSequencerChannels();
455   *          - Set ADC channel sampling time
456   *            Refer to function LL_ADC_SetChannelSamplingTime();
457   * @param  ADCx ADC instance
458   * @param  ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
459   * @retval An ErrorStatus enumeration value:
460   *          - SUCCESS: ADC registers are initialized
461   *          - ERROR: ADC registers are not initialized
462   */
LL_ADC_REG_Init(ADC_TypeDef * ADCx,LL_ADC_REG_InitTypeDef * ADC_REG_InitStruct)463 ErrorStatus LL_ADC_REG_Init(ADC_TypeDef *ADCx, LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct)
464 {
465   ErrorStatus status = SUCCESS;
466 
467   /* Check the parameters */
468   assert_param(IS_ADC_ALL_INSTANCE(ADCx));
469   assert_param(IS_LL_ADC_REG_TRIG_SOURCE(ADC_REG_InitStruct->TriggerSource));
470   assert_param(IS_LL_ADC_REG_SEQ_SCAN_DISCONT_MODE(ADC_REG_InitStruct->SequencerDiscont));
471   assert_param(IS_LL_ADC_REG_CONTINUOUS_MODE(ADC_REG_InitStruct->ContinuousMode));
472   assert_param(IS_LL_ADC_REG_DMA_TRANSFER(ADC_REG_InitStruct->DMATransfer));
473   assert_param(IS_LL_ADC_REG_OVR_DATA_BEHAVIOR(ADC_REG_InitStruct->Overrun));
474 
475   /* ADC group regular continuous mode and discontinuous mode                 */
476   /* can not be enabled simultenaeously                                       */
477   assert_param((ADC_REG_InitStruct->ContinuousMode == LL_ADC_REG_CONV_SINGLE)
478                || (ADC_REG_InitStruct->SequencerDiscont == LL_ADC_REG_SEQ_DISCONT_DISABLE));
479 
480   /* Note: Hardware constraint (refer to description of this function):       */
481   /*       ADC instance must be disabled.                                     */
482   if(LL_ADC_IsEnabled(ADCx) == 0U)
483   {
484     /* Configuration of ADC hierarchical scope:                               */
485     /*  - ADC group regular                                                   */
486     /*    - Set ADC group regular trigger source                              */
487     /*    - Set ADC group regular sequencer discontinuous mode                */
488     /*    - Set ADC group regular continuous mode                             */
489     /*    - Set ADC group regular conversion data transfer: no transfer or    */
490     /*      transfer by DMA, and DMA requests mode                            */
491     /*    - Set ADC group regular overrun behavior                            */
492     /* Note: On this STM32 series, ADC trigger edge is set to value 0x0 by     */
493     /*       setting of trigger source to SW start.                           */
494     MODIFY_REG(ADCx->CFGR1,
495                  ADC_CFGR1_EXTSEL
496                | ADC_CFGR1_EXTEN
497                | ADC_CFGR1_DISCEN
498                | ADC_CFGR1_CONT
499                | ADC_CFGR1_DMAEN
500                | ADC_CFGR1_DMACFG
501                | ADC_CFGR1_OVRMOD
502               ,
503                  ADC_REG_InitStruct->TriggerSource
504                | ADC_REG_InitStruct->SequencerDiscont
505                | ADC_REG_InitStruct->ContinuousMode
506                | ADC_REG_InitStruct->DMATransfer
507                | ADC_REG_InitStruct->Overrun
508               );
509 
510   }
511   else
512   {
513     /* Initialization error: ADC instance is not disabled. */
514     status = ERROR;
515   }
516   return status;
517 }
518 
519 /**
520   * @brief  Set each @ref LL_ADC_REG_InitTypeDef field to default value.
521   * @param  ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
522   *                            whose fields will be set to default values.
523   * @retval None
524   */
LL_ADC_REG_StructInit(LL_ADC_REG_InitTypeDef * ADC_REG_InitStruct)525 void LL_ADC_REG_StructInit(LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct)
526 {
527   /* Set ADC_REG_InitStruct fields to default values */
528   /* Set fields of ADC group regular */
529   /* Note: On this STM32 series, ADC trigger edge is set to value 0x0 by       */
530   /*       setting of trigger source to SW start.                             */
531   ADC_REG_InitStruct->TriggerSource    = LL_ADC_REG_TRIG_SOFTWARE;
532   ADC_REG_InitStruct->SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE;
533   ADC_REG_InitStruct->ContinuousMode   = LL_ADC_REG_CONV_SINGLE;
534   ADC_REG_InitStruct->DMATransfer      = LL_ADC_REG_DMA_TRANSFER_NONE;
535   ADC_REG_InitStruct->Overrun          = LL_ADC_REG_OVR_DATA_OVERWRITTEN;
536 }
537 
538 /**
539   * @}
540   */
541 
542 /**
543   * @}
544   */
545 
546 /**
547   * @}
548   */
549 
550 #endif /* ADC1 */
551 
552 /**
553   * @}
554   */
555 
556 #endif /* USE_FULL_LL_DRIVER */
557 
558