STM32F103xB HAL User Manual
stm32f1xx_ll_adc.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f1xx_ll_adc.c
00004   * @author  MCD Application Team
00005   * @brief   ADC LL module driver
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
00010   * All rights reserved.</center></h2>
00011   *
00012   * This software component is licensed by ST under BSD 3-Clause license,
00013   * the "License"; You may not use this file except in compliance with the
00014   * License. You may obtain a copy of the License at:
00015   *                        opensource.org/licenses/BSD-3-Clause
00016   *
00017   ******************************************************************************
00018   */
00019 
00020 #if defined(USE_FULL_LL_DRIVER)
00021 
00022 /* Includes ------------------------------------------------------------------*/
00023 #include "stm32f1xx_ll_adc.h"
00024 #include "stm32f1xx_ll_bus.h"
00025 
00026 #ifdef  USE_FULL_ASSERT
00027   #include "stm32_assert.h"
00028 #else
00029   #define assert_param(expr) ((void)0U)
00030 #endif
00031 
00032 /** @addtogroup STM32F1xx_LL_Driver
00033   * @{
00034   */
00035 
00036 #if defined (ADC1) || defined (ADC2) || defined (ADC3)
00037 
00038 /** @addtogroup ADC_LL ADC
00039   * @{
00040   */
00041 
00042 /* Private types -------------------------------------------------------------*/
00043 /* Private variables ---------------------------------------------------------*/
00044 /* Private constants ---------------------------------------------------------*/
00045 /* Private macros ------------------------------------------------------------*/
00046 
00047 /** @addtogroup ADC_LL_Private_Macros
00048   * @{
00049   */
00050 
00051 /* Check of parameters for configuration of ADC hierarchical scope:           */
00052 /* common to several ADC instances.                                           */
00053 /* Check of parameters for configuration of ADC hierarchical scope:           */
00054 /* ADC instance.                                                              */
00055 #define IS_LL_ADC_DATA_ALIGN(__DATA_ALIGN__)                                   \
00056   (   ((__DATA_ALIGN__) == LL_ADC_DATA_ALIGN_RIGHT)                            \
00057    || ((__DATA_ALIGN__) == LL_ADC_DATA_ALIGN_LEFT)                             \
00058   )
00059 
00060 #define IS_LL_ADC_SCAN_SELECTION(__SCAN_SELECTION__)                           \
00061   (   ((__SCAN_SELECTION__) == LL_ADC_SEQ_SCAN_DISABLE)                        \
00062    || ((__SCAN_SELECTION__) == LL_ADC_SEQ_SCAN_ENABLE)                         \
00063   )
00064 
00065 #define IS_LL_ADC_SEQ_SCAN_MODE(__SEQ_SCAN_MODE__)                             \
00066   (   ((__SCAN_MODE__) == LL_ADC_SEQ_SCAN_DISABLE)                             \
00067    || ((__SCAN_MODE__) == LL_ADC_SEQ_SCAN_ENABLE)                              \
00068   )
00069 
00070 /* Check of parameters for configuration of ADC hierarchical scope:           */
00071 /* ADC group regular                                                          */
00072 #if defined(ADC3)
00073 #define IS_LL_ADC_REG_TRIG_SOURCE(__ADC_INSTANCE__, __REG_TRIG_SOURCE__)       \
00074   ((((__ADC_INSTANCE__) == ADC1) || ((__ADC_INSTANCE__) == ADC2))              \
00075     ? (   ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE)                  \
00076        || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3)              \
00077        || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH1)              \
00078        || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH2)              \
00079        || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH2)              \
00080        || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO)             \
00081        || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_CH4)              \
00082        || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE11)           \
00083        || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO)             \
00084       )                                                                        \
00085       :                                                                        \
00086       (   ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE)                  \
00087        || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3)              \
00088        || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_CH1)              \
00089        || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH3)              \
00090        || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_CH1)              \
00091        || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO_ADC3)        \
00092        || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM5_CH1)              \
00093        || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM5_CH3)              \
00094       )                                                                        \
00095   )
00096 #else
00097 #if defined (STM32F101xE) || defined (STM32F105xC) || defined (STM32F107xC)
00098 #define IS_LL_ADC_REG_TRIG_SOURCE(__REG_TRIG_SOURCE__)                         \
00099   (   ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE)                      \
00100    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3)                  \
00101    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH1)                  \
00102    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH2)                  \
00103    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH2)                  \
00104    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO)                 \
00105    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_CH4)                  \
00106    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE11)               \
00107    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO)                 \
00108   )
00109 #else
00110 #define IS_LL_ADC_REG_TRIG_SOURCE(__REG_TRIG_SOURCE__)                         \
00111   (   ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE)                      \
00112    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3)                  \
00113    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH1)                  \
00114    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH2)                  \
00115    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH2)                  \
00116    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO)                 \
00117    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_CH4)                  \
00118    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE11)               \
00119   )
00120 #endif
00121 #endif
00122 #define IS_LL_ADC_REG_CONTINUOUS_MODE(__REG_CONTINUOUS_MODE__)                 \
00123   (   ((__REG_CONTINUOUS_MODE__) == LL_ADC_REG_CONV_SINGLE)                    \
00124    || ((__REG_CONTINUOUS_MODE__) == LL_ADC_REG_CONV_CONTINUOUS)                \
00125   )
00126 
00127 #define IS_LL_ADC_REG_DMA_TRANSFER(__REG_DMA_TRANSFER__)                       \
00128   (   ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_NONE)                 \
00129    || ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_UNLIMITED)            \
00130   )
00131 
00132 #define IS_LL_ADC_REG_SEQ_SCAN_LENGTH(__REG_SEQ_SCAN_LENGTH__)                 \
00133   (   ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_DISABLE)               \
00134    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS)         \
00135    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS)         \
00136    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS)         \
00137    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS)         \
00138    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS)         \
00139    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_7RANKS)         \
00140    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS)         \
00141    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_9RANKS)         \
00142    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_10RANKS)        \
00143    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_11RANKS)        \
00144    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_12RANKS)        \
00145    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_13RANKS)        \
00146    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_14RANKS)        \
00147    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_15RANKS)        \
00148    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_16RANKS)        \
00149   )
00150 
00151 #define IS_LL_ADC_REG_SEQ_SCAN_DISCONT_MODE(__REG_SEQ_DISCONT_MODE__)          \
00152   (   ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_DISABLE)           \
00153    || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_1RANK)             \
00154    || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_2RANKS)            \
00155    || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_3RANKS)            \
00156    || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_4RANKS)            \
00157    || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_5RANKS)            \
00158    || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_6RANKS)            \
00159    || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_7RANKS)            \
00160    || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_8RANKS)            \
00161   )
00162 
00163 /* Check of parameters for configuration of ADC hierarchical scope:           */
00164 /* ADC group injected                                                         */
00165 #if defined(ADC3)
00166 #define IS_LL_ADC_INJ_TRIG_SOURCE(__ADC_INSTANCE__, __INJ_TRIG_SOURCE__)       \
00167   ((((__ADC_INSTANCE__) == ADC1) || ((__ADC_INSTANCE__) == ADC2))              \
00168     ? (   ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE)                  \
00169        || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO)             \
00170        || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4)              \
00171        || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_TRGO)             \
00172        || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_CH1)              \
00173        || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH4)              \
00174        || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_TRGO)             \
00175        || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_EXTI_LINE15)           \
00176        || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH4)              \
00177       )                                                                        \
00178       :                                                                        \
00179       (   ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE)                  \
00180        || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO)             \
00181        || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4)              \
00182        || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_CH3)              \
00183        || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH2)              \
00184        || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH4_ADC3)         \
00185        || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM5_TRGO)             \
00186        || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM5_CH4)              \
00187       )                                                                        \
00188   )
00189 #else
00190 #if defined (STM32F101xE) || defined (STM32F105xC) || defined (STM32F107xC)
00191 #define IS_LL_ADC_INJ_TRIG_SOURCE(__INJ_TRIG_SOURCE__)                         \
00192   (   ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE)                      \
00193    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO)                 \
00194    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4)                  \
00195    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_TRGO)                 \
00196    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_CH1)                  \
00197    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH4)                  \
00198    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_TRGO)                 \
00199    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_EXTI_LINE15)               \
00200    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH4)                  \
00201   )
00202 #else
00203 #define IS_LL_ADC_INJ_TRIG_SOURCE(__INJ_TRIG_SOURCE__)                         \
00204   (   ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE)                      \
00205    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO)                 \
00206    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4)                  \
00207    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_TRGO)                 \
00208    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_CH1)                  \
00209    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH4)                  \
00210    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_TRGO)                 \
00211    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_EXTI_LINE15)               \
00212   )
00213 #endif
00214 #endif
00215 #define IS_LL_ADC_INJ_TRIG_AUTO(__INJ_TRIG_AUTO__)                             \
00216   (   ((__INJ_TRIG_AUTO__) == LL_ADC_INJ_TRIG_INDEPENDENT)                     \
00217    || ((__INJ_TRIG_AUTO__) == LL_ADC_INJ_TRIG_FROM_GRP_REGULAR)                \
00218   )
00219 
00220 #define IS_LL_ADC_INJ_SEQ_SCAN_LENGTH(__INJ_SEQ_SCAN_LENGTH__)                 \
00221   (   ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_DISABLE)               \
00222    || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_2RANKS)         \
00223    || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_3RANKS)         \
00224    || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_4RANKS)         \
00225   )
00226 
00227 #define IS_LL_ADC_INJ_SEQ_SCAN_DISCONT_MODE(__INJ_SEQ_DISCONT_MODE__)          \
00228   (   ((__INJ_SEQ_DISCONT_MODE__) == LL_ADC_INJ_SEQ_DISCONT_DISABLE)           \
00229    || ((__INJ_SEQ_DISCONT_MODE__) == LL_ADC_INJ_SEQ_DISCONT_1RANK)             \
00230   )
00231 
00232 #if defined(ADC_MULTIMODE_SUPPORT)
00233 /* Check of parameters for configuration of ADC hierarchical scope:           */
00234 /* multimode.                                                                 */
00235 #define IS_LL_ADC_MULTI_MODE(__MULTI_MODE__)                                   \
00236   (   ((__MULTI_MODE__) == LL_ADC_MULTI_INDEPENDENT)                           \
00237    || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_SIMULT)                       \
00238    || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_INTERL_FAST)                  \
00239    || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_INTERL_SLOW)                  \
00240    || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_INJ_SIMULT)                       \
00241    || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_INJ_ALTERN)                       \
00242    || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_SIM_INJ_SIM)                  \
00243    || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_SIM_INJ_ALT)                  \
00244    || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_INTFAST_INJ_SIM)              \
00245    || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_INTSLOW_INJ_SIM)              \
00246   )
00247 
00248 #define IS_LL_ADC_MULTI_MASTER_SLAVE(__MULTI_MASTER_SLAVE__)                   \
00249   (   ((__MULTI_MASTER_SLAVE__) == LL_ADC_MULTI_MASTER)                        \
00250    || ((__MULTI_MASTER_SLAVE__) == LL_ADC_MULTI_SLAVE)                         \
00251    || ((__MULTI_MASTER_SLAVE__) == LL_ADC_MULTI_MASTER_SLAVE)                  \
00252   )
00253 
00254 #endif /* ADC_MULTIMODE_SUPPORT */
00255 /**
00256   * @}
00257   */
00258 
00259 
00260 /* Private function prototypes -----------------------------------------------*/
00261 
00262 /* Exported functions --------------------------------------------------------*/
00263 /** @addtogroup ADC_LL_Exported_Functions
00264   * @{
00265   */
00266 
00267 /** @addtogroup ADC_LL_EF_Init
00268   * @{
00269   */
00270 
00271 /**
00272   * @brief  De-initialize registers of all ADC instances belonging to
00273   *         the same ADC common instance to their default reset values.
00274   * @param  ADCxy_COMMON ADC common instance
00275   *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
00276   * @retval An ErrorStatus enumeration value:
00277   *          - SUCCESS: ADC common registers are de-initialized
00278   *          - ERROR: not applicable
00279   */
00280 ErrorStatus LL_ADC_CommonDeInit(ADC_Common_TypeDef *ADCxy_COMMON)
00281 {
00282   /* Check the parameters */
00283   assert_param(IS_ADC_COMMON_INSTANCE(ADCxy_COMMON));
00284   
00285   /* Force reset of ADC clock (core clock) */
00286   LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_ADC1);
00287   
00288   /* Release reset of ADC clock (core clock) */
00289   LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_ADC1);
00290   
00291   return SUCCESS;
00292 }
00293 
00294 /**
00295   * @brief  Initialize some features of ADC common parameters
00296   *         (all ADC instances belonging to the same ADC common instance)
00297   *         and multimode (for devices with several ADC instances available).
00298   * @note   The setting of ADC common parameters is conditioned to
00299   *         ADC instances state:
00300   *         All ADC instances belonging to the same ADC common instance
00301   *         must be disabled.
00302   * @param  ADCxy_COMMON ADC common instance
00303   *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
00304   * @param  ADC_CommonInitStruct Pointer to a @ref LL_ADC_CommonInitTypeDef structure
00305   * @retval An ErrorStatus enumeration value:
00306   *          - SUCCESS: ADC common registers are initialized
00307   *          - ERROR: ADC common registers are not initialized
00308   */
00309 ErrorStatus LL_ADC_CommonInit(ADC_Common_TypeDef *ADCxy_COMMON, LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct)
00310 {
00311   ErrorStatus status = SUCCESS;
00312   
00313   /* Check the parameters */
00314   assert_param(IS_ADC_COMMON_INSTANCE(ADCxy_COMMON));
00315 #if defined(ADC_MULTIMODE_SUPPORT)
00316   assert_param(IS_LL_ADC_MULTI_MODE(ADC_CommonInitStruct->Multimode));
00317 #endif /* ADC_MULTIMODE_SUPPORT */
00318 
00319   /* Note: Hardware constraint (refer to description of functions             */
00320   /*       "LL_ADC_SetCommonXXX()" and "LL_ADC_SetMultiXXX()"):               */
00321   /*       On this STM32 serie, setting of these features is conditioned to   */
00322   /*       ADC state:                                                         */
00323   /*       All ADC instances of the ADC common group must be disabled.        */
00324   if(__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(ADCxy_COMMON) == 0U)
00325   {
00326     /* Configuration of ADC hierarchical scope:                               */
00327     /*  - common to several ADC                                               */
00328     /*    (all ADC instances belonging to the same ADC common instance)       */
00329     /*  - multimode (if several ADC instances available on the                */
00330     /*    selected device)                                                    */
00331     /*    - Set ADC multimode configuration                                   */
00332     /*    - Set ADC multimode DMA transfer                                    */
00333     /*    - Set ADC multimode: delay between 2 sampling phases                */
00334 #if defined(ADC_MULTIMODE_SUPPORT)
00335     if(ADC_CommonInitStruct->Multimode != LL_ADC_MULTI_INDEPENDENT)
00336     {
00337       MODIFY_REG(ADCxy_COMMON->CR1,
00338                  ADC_CR1_DUALMOD,
00339                  ADC_CommonInitStruct->Multimode
00340                 );
00341     }
00342     else
00343     {
00344       MODIFY_REG(ADCxy_COMMON->CR1,
00345                  ADC_CR1_DUALMOD,
00346                  LL_ADC_MULTI_INDEPENDENT
00347                 );
00348     }
00349 #endif
00350   }
00351   else
00352   {
00353     /* Initialization error: One or several ADC instances belonging to        */
00354     /* the same ADC common instance are not disabled.                         */
00355     status = ERROR;
00356   }
00357   
00358   return status;
00359 }
00360 
00361 /**
00362   * @brief  Set each @ref LL_ADC_CommonInitTypeDef field to default value.
00363   * @param  ADC_CommonInitStruct Pointer to a @ref LL_ADC_CommonInitTypeDef structure
00364   *                              whose fields will be set to default values.
00365   * @retval None
00366   */
00367 void LL_ADC_CommonStructInit(LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct)
00368 {
00369   /* Set ADC_CommonInitStruct fields to default values */
00370   /* Set fields of ADC common */
00371   /* (all ADC instances belonging to the same ADC common instance) */
00372   
00373 #if defined(ADC_MULTIMODE_SUPPORT)
00374   /* Set fields of ADC multimode */
00375   ADC_CommonInitStruct->Multimode             = LL_ADC_MULTI_INDEPENDENT;
00376 #endif /* ADC_MULTIMODE_SUPPORT */
00377 }
00378 
00379 /**
00380   * @brief  De-initialize registers of the selected ADC instance
00381   *         to their default reset values.
00382   * @note   To reset all ADC instances quickly (perform a hard reset),
00383   *         use function @ref LL_ADC_CommonDeInit().
00384   * @param  ADCx ADC instance
00385   * @retval An ErrorStatus enumeration value:
00386   *          - SUCCESS: ADC registers are de-initialized
00387   *          - ERROR: ADC registers are not de-initialized
00388   */
00389 ErrorStatus LL_ADC_DeInit(ADC_TypeDef *ADCx)
00390 {
00391   ErrorStatus status = SUCCESS;
00392   
00393   /* Check the parameters */
00394   assert_param(IS_ADC_ALL_INSTANCE(ADCx));
00395   
00396   /* Disable ADC instance if not already disabled.                            */
00397   if(LL_ADC_IsEnabled(ADCx) == 1U)
00398   {
00399     /* Set ADC group regular trigger source to SW start to ensure to not      */
00400     /* have an external trigger event occurring during the conversion stop    */
00401     /* ADC disable process.                                                   */
00402     LL_ADC_REG_SetTriggerSource(ADCx, LL_ADC_REG_TRIG_SOFTWARE);
00403     
00404     /* Set ADC group injected trigger source to SW start to ensure to not     */
00405     /* have an external trigger event occurring during the conversion stop    */
00406     /* ADC disable process.                                                   */
00407     LL_ADC_INJ_SetTriggerSource(ADCx, LL_ADC_INJ_TRIG_SOFTWARE);
00408     
00409     /* Disable the ADC instance */
00410     LL_ADC_Disable(ADCx);
00411   }
00412   
00413   /* Check whether ADC state is compliant with expected state */
00414   /* (hardware requirements of bits state to reset registers below) */
00415   if(READ_BIT(ADCx->CR2, ADC_CR2_ADON) == 0U)
00416   {
00417     /* ========== Reset ADC registers ========== */
00418     /* Reset register SR */
00419     CLEAR_BIT(ADCx->SR,
00420               (  LL_ADC_FLAG_STRT
00421                | LL_ADC_FLAG_JSTRT
00422                | LL_ADC_FLAG_EOS
00423                | LL_ADC_FLAG_JEOS
00424                | LL_ADC_FLAG_AWD1 )
00425              );
00426     
00427     /* Reset register CR1 */
00428   #if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
00429 
00430     CLEAR_BIT(ADCx->CR1,
00431               (  ADC_CR1_AWDEN   | ADC_CR1_JAWDEN  | ADC_CR1_DUALMOD
00432                | ADC_CR1_DISCNUM | ADC_CR1_JDISCEN | ADC_CR1_DISCEN
00433                | ADC_CR1_JAUTO   | ADC_CR1_AWDSGL  | ADC_CR1_SCAN
00434                | ADC_CR1_JEOCIE  | ADC_CR1_AWDIE   | ADC_CR1_EOCIE
00435                | ADC_CR1_AWDCH                                     )
00436              );
00437   #else 
00438 
00439     CLEAR_BIT(ADCx->CR1,
00440               (  ADC_CR1_AWDEN   | ADC_CR1_JAWDEN  | ADC_CR1_DISCNUM 
00441                | ADC_CR1_JDISCEN | ADC_CR1_DISCEN  | ADC_CR1_JAUTO
00442                | ADC_CR1_AWDSGL  | ADC_CR1_SCAN    | ADC_CR1_JEOCIE  
00443                | ADC_CR1_AWDIE   | ADC_CR1_EOCIE   | ADC_CR1_AWDCH )
00444              );
00445   #endif
00446     
00447     /* Reset register CR2 */
00448     CLEAR_BIT(ADCx->CR2,
00449               (  ADC_CR2_TSVREFE
00450                | ADC_CR2_SWSTART  | ADC_CR2_EXTTRIG  | ADC_CR2_EXTSEL
00451                | ADC_CR2_JSWSTART | ADC_CR2_JEXTTRIG | ADC_CR2_JEXTSEL
00452                | ADC_CR2_ALIGN    | ADC_CR2_DMA
00453                | ADC_CR2_RSTCAL   | ADC_CR2_CAL
00454                | ADC_CR2_CONT     | ADC_CR2_ADON                      )
00455              );
00456     
00457     /* Reset register SMPR1 */
00458     CLEAR_BIT(ADCx->SMPR1,
00459               (  ADC_SMPR1_SMP17 | ADC_SMPR1_SMP16
00460                | ADC_SMPR1_SMP15 | ADC_SMPR1_SMP14 | ADC_SMPR1_SMP13
00461                | ADC_SMPR1_SMP12 | ADC_SMPR1_SMP11 | ADC_SMPR1_SMP10)
00462              );
00463     
00464     /* Reset register SMPR2 */
00465     CLEAR_BIT(ADCx->SMPR2,
00466               (  ADC_SMPR2_SMP9
00467                | ADC_SMPR2_SMP8 | ADC_SMPR2_SMP7 | ADC_SMPR2_SMP6
00468                | ADC_SMPR2_SMP5 | ADC_SMPR2_SMP4 | ADC_SMPR2_SMP3
00469                | ADC_SMPR2_SMP2 | ADC_SMPR2_SMP1 | ADC_SMPR2_SMP0)
00470              );
00471     
00472     /* Reset register JOFR1 */
00473     CLEAR_BIT(ADCx->JOFR1, ADC_JOFR1_JOFFSET1);
00474     /* Reset register JOFR2 */
00475     CLEAR_BIT(ADCx->JOFR2, ADC_JOFR2_JOFFSET2);
00476     /* Reset register JOFR3 */
00477     CLEAR_BIT(ADCx->JOFR3, ADC_JOFR3_JOFFSET3);
00478     /* Reset register JOFR4 */
00479     CLEAR_BIT(ADCx->JOFR4, ADC_JOFR4_JOFFSET4);
00480     
00481     /* Reset register HTR */
00482     SET_BIT(ADCx->HTR, ADC_HTR_HT);
00483     /* Reset register LTR */
00484     CLEAR_BIT(ADCx->LTR, ADC_LTR_LT);
00485     
00486     /* Reset register SQR1 */
00487     CLEAR_BIT(ADCx->SQR1,
00488               (  ADC_SQR1_L
00489                | ADC_SQR1_SQ16
00490                | ADC_SQR1_SQ15 | ADC_SQR1_SQ14 | ADC_SQR1_SQ13)
00491              );
00492              
00493     /* Reset register SQR2 */
00494     CLEAR_BIT(ADCx->SQR2,
00495               (  ADC_SQR2_SQ12 | ADC_SQR2_SQ11 | ADC_SQR2_SQ10
00496                | ADC_SQR2_SQ9 | ADC_SQR2_SQ8 | ADC_SQR2_SQ7)
00497              );
00498 
00499     /* Reset register SQR3 */
00500     CLEAR_BIT(ADCx->SQR3,
00501               (  ADC_SQR3_SQ6 | ADC_SQR3_SQ5 | ADC_SQR3_SQ4
00502                | ADC_SQR3_SQ3 | ADC_SQR3_SQ2 | ADC_SQR3_SQ1)
00503              );
00504     
00505     /* Reset register JSQR */
00506     CLEAR_BIT(ADCx->JSQR,
00507               (  ADC_JSQR_JL
00508                | ADC_JSQR_JSQ4 | ADC_JSQR_JSQ3
00509                | ADC_JSQR_JSQ2 | ADC_JSQR_JSQ1  )
00510              );
00511     
00512     /* Reset register DR */
00513     /* bits in access mode read only, no direct reset applicable */
00514     
00515     /* Reset registers JDR1, JDR2, JDR3, JDR4 */
00516     /* bits in access mode read only, no direct reset applicable */
00517     
00518   }
00519   
00520   return status;
00521 }
00522 
00523 /**
00524   * @brief  Initialize some features of ADC instance.
00525   * @note   These parameters have an impact on ADC scope: ADC instance.
00526   *         Affects both group regular and group injected (availability
00527   *         of ADC group injected depends on STM32 families).
00528   *         Refer to corresponding unitary functions into
00529   *         @ref ADC_LL_EF_Configuration_ADC_Instance .
00530   * @note   The setting of these parameters by function @ref LL_ADC_Init()
00531   *         is conditioned to ADC state:
00532   *         ADC instance must be disabled.
00533   *         This condition is applied to all ADC features, for efficiency
00534   *         and compatibility over all STM32 families. However, the different
00535   *         features can be set under different ADC state conditions
00536   *         (setting possible with ADC enabled without conversion on going,
00537   *         ADC enabled with conversion on going, ...)
00538   *         Each feature can be updated afterwards with a unitary function
00539   *         and potentially with ADC in a different state than disabled,
00540   *         refer to description of each function for setting
00541   *         conditioned to ADC state.
00542   * @note   After using this function, some other features must be configured
00543   *         using LL unitary functions.
00544   *         The minimum configuration remaining to be done is:
00545   *          - Set ADC group regular or group injected sequencer:
00546   *            map channel on the selected sequencer rank.
00547   *            Refer to function @ref LL_ADC_REG_SetSequencerRanks().
00548   *          - Set ADC channel sampling time
00549   *            Refer to function LL_ADC_SetChannelSamplingTime();
00550   * @param  ADCx ADC instance
00551   * @param  ADC_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
00552   * @retval An ErrorStatus enumeration value:
00553   *          - SUCCESS: ADC registers are initialized
00554   *          - ERROR: ADC registers are not initialized
00555   */
00556 ErrorStatus LL_ADC_Init(ADC_TypeDef *ADCx, LL_ADC_InitTypeDef *ADC_InitStruct)
00557 {
00558   ErrorStatus status = SUCCESS;
00559   
00560   /* Check the parameters */
00561   assert_param(IS_ADC_ALL_INSTANCE(ADCx));
00562   
00563   assert_param(IS_LL_ADC_DATA_ALIGN(ADC_InitStruct->DataAlignment));
00564   assert_param(IS_LL_ADC_SCAN_SELECTION(ADC_InitStruct->SequencersScanMode));
00565   
00566   /* Note: Hardware constraint (refer to description of this function):       */
00567   /*       ADC instance must be disabled.                                     */
00568   if(LL_ADC_IsEnabled(ADCx) == 0U)
00569   {
00570     /* Configuration of ADC hierarchical scope:                               */
00571     /*  - ADC instance                                                        */
00572     /*    - Set ADC conversion data alignment                                 */
00573     MODIFY_REG(ADCx->CR1,
00574                  ADC_CR1_SCAN
00575               ,
00576                  ADC_InitStruct->SequencersScanMode
00577               );
00578     
00579     MODIFY_REG(ADCx->CR2,
00580                  ADC_CR2_ALIGN
00581               ,
00582                  ADC_InitStruct->DataAlignment
00583               );
00584 
00585   }
00586   else
00587   {
00588     /* Initialization error: ADC instance is not disabled. */
00589     status = ERROR;
00590   }
00591   return status;
00592 }
00593 
00594 /**
00595   * @brief  Set each @ref LL_ADC_InitTypeDef field to default value.
00596   * @param  ADC_InitStruct Pointer to a @ref LL_ADC_InitTypeDef structure
00597   *                        whose fields will be set to default values.
00598   * @retval None
00599   */
00600 void LL_ADC_StructInit(LL_ADC_InitTypeDef *ADC_InitStruct)
00601 {
00602   /* Set ADC_InitStruct fields to default values */
00603   /* Set fields of ADC instance */
00604   ADC_InitStruct->DataAlignment = LL_ADC_DATA_ALIGN_RIGHT;
00605   
00606   /* Enable scan mode to have a generic behavior with ADC of other            */
00607   /* STM32 families, without this setting available:                          */
00608   /* ADC group regular sequencer and ADC group injected sequencer depend      */
00609   /* only of their own configuration.                                         */
00610   ADC_InitStruct->SequencersScanMode      = LL_ADC_SEQ_SCAN_ENABLE;
00611   
00612 }
00613 
00614 /**
00615   * @brief  Initialize some features of ADC group regular.
00616   * @note   These parameters have an impact on ADC scope: ADC group regular.
00617   *         Refer to corresponding unitary functions into
00618   *         @ref ADC_LL_EF_Configuration_ADC_Group_Regular
00619   *         (functions with prefix "REG").
00620   * @note   The setting of these parameters by function @ref LL_ADC_Init()
00621   *         is conditioned to ADC state:
00622   *         ADC instance must be disabled.
00623   *         This condition is applied to all ADC features, for efficiency
00624   *         and compatibility over all STM32 families. However, the different
00625   *         features can be set under different ADC state conditions
00626   *         (setting possible with ADC enabled without conversion on going,
00627   *         ADC enabled with conversion on going, ...)
00628   *         Each feature can be updated afterwards with a unitary function
00629   *         and potentially with ADC in a different state than disabled,
00630   *         refer to description of each function for setting
00631   *         conditioned to ADC state.
00632   * @note   After using this function, other features must be configured
00633   *         using LL unitary functions.
00634   *         The minimum configuration remaining to be done is:
00635   *          - Set ADC group regular or group injected sequencer:
00636   *            map channel on the selected sequencer rank.
00637   *            Refer to function @ref LL_ADC_REG_SetSequencerRanks().
00638   *          - Set ADC channel sampling time
00639   *            Refer to function LL_ADC_SetChannelSamplingTime();
00640   * @param  ADCx ADC instance
00641   * @param  ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
00642   * @retval An ErrorStatus enumeration value:
00643   *          - SUCCESS: ADC registers are initialized
00644   *          - ERROR: ADC registers are not initialized
00645   */
00646 ErrorStatus LL_ADC_REG_Init(ADC_TypeDef *ADCx, LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct)
00647 {
00648   ErrorStatus status = SUCCESS;
00649   
00650   /* Check the parameters */
00651   assert_param(IS_ADC_ALL_INSTANCE(ADCx));
00652 #if defined(ADC3)
00653   assert_param(IS_LL_ADC_REG_TRIG_SOURCE(ADCx, ADC_REG_InitStruct->TriggerSource));
00654 #else
00655   assert_param(IS_LL_ADC_REG_TRIG_SOURCE(ADC_REG_InitStruct->TriggerSource));
00656 #endif
00657   assert_param(IS_LL_ADC_REG_SEQ_SCAN_LENGTH(ADC_REG_InitStruct->SequencerLength));
00658   if(ADC_REG_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
00659   {
00660     assert_param(IS_LL_ADC_REG_SEQ_SCAN_DISCONT_MODE(ADC_REG_InitStruct->SequencerDiscont));
00661   }
00662   assert_param(IS_LL_ADC_REG_CONTINUOUS_MODE(ADC_REG_InitStruct->ContinuousMode));
00663   assert_param(IS_LL_ADC_REG_DMA_TRANSFER(ADC_REG_InitStruct->DMATransfer));
00664   
00665   /* ADC group regular continuous mode and discontinuous mode                 */
00666   /* can not be enabled simultenaeously                                       */
00667   assert_param((ADC_REG_InitStruct->ContinuousMode == LL_ADC_REG_CONV_SINGLE)
00668                || (ADC_REG_InitStruct->SequencerDiscont == LL_ADC_REG_SEQ_DISCONT_DISABLE));
00669   
00670   /* Note: Hardware constraint (refer to description of this function):       */
00671   /*       ADC instance must be disabled.                                     */
00672   if(LL_ADC_IsEnabled(ADCx) == 0U)
00673   {
00674     /* Configuration of ADC hierarchical scope:                               */
00675     /*  - ADC group regular                                                   */
00676     /*    - Set ADC group regular trigger source                              */
00677     /*    - Set ADC group regular sequencer length                            */
00678     /*    - Set ADC group regular sequencer discontinuous mode                */
00679     /*    - Set ADC group regular continuous mode                             */
00680     /*    - Set ADC group regular conversion data transfer: no transfer or    */
00681     /*      transfer by DMA, and DMA requests mode                            */
00682     /* Note: On this STM32 serie, ADC trigger edge is set when starting       */
00683     /*       ADC conversion.                                                  */
00684     /*       Refer to function @ref LL_ADC_REG_StartConversionExtTrig().      */
00685     if(ADC_REG_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
00686     {
00687       MODIFY_REG(ADCx->CR1,
00688                    ADC_CR1_DISCEN
00689                  | ADC_CR1_DISCNUM
00690                 ,
00691                    ADC_REG_InitStruct->SequencerLength
00692                  | ADC_REG_InitStruct->SequencerDiscont
00693                 );
00694     }
00695     else
00696     {
00697       MODIFY_REG(ADCx->CR1,
00698                    ADC_CR1_DISCEN
00699                  | ADC_CR1_DISCNUM
00700                 ,
00701                    ADC_REG_InitStruct->SequencerLength
00702                  | LL_ADC_REG_SEQ_DISCONT_DISABLE
00703                 );
00704     }
00705     
00706     MODIFY_REG(ADCx->CR2,
00707                  ADC_CR2_EXTSEL
00708                | ADC_CR2_CONT
00709                | ADC_CR2_DMA
00710               ,
00711                  ADC_REG_InitStruct->TriggerSource
00712                | ADC_REG_InitStruct->ContinuousMode
00713                | ADC_REG_InitStruct->DMATransfer
00714               );
00715 
00716     /* Set ADC group regular sequencer length and scan direction */
00717     /* Note: Hardware constraint (refer to description of this function):     */
00718     /* Note: If ADC instance feature scan mode is disabled                    */
00719     /*       (refer to  ADC instance initialization structure                 */
00720     /*       parameter @ref SequencersScanMode                                */
00721     /*       or function @ref LL_ADC_SetSequencersScanMode() ),               */
00722     /*       this parameter is discarded.                                     */
00723     LL_ADC_REG_SetSequencerLength(ADCx, ADC_REG_InitStruct->SequencerLength);
00724   }
00725   else
00726   {
00727     /* Initialization error: ADC instance is not disabled. */
00728     status = ERROR;
00729   }
00730   return status;
00731 }
00732 
00733 /**
00734   * @brief  Set each @ref LL_ADC_REG_InitTypeDef field to default value.
00735   * @param  ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
00736   *                            whose fields will be set to default values.
00737   * @retval None
00738   */
00739 void LL_ADC_REG_StructInit(LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct)
00740 {
00741   /* Set ADC_REG_InitStruct fields to default values */
00742   /* Set fields of ADC group regular */
00743   /* Note: On this STM32 serie, ADC trigger edge is set when starting         */
00744   /*       ADC conversion.                                                    */
00745   /*       Refer to function @ref LL_ADC_REG_StartConversionExtTrig().        */
00746   ADC_REG_InitStruct->TriggerSource    = LL_ADC_REG_TRIG_SOFTWARE;
00747   ADC_REG_InitStruct->SequencerLength  = LL_ADC_REG_SEQ_SCAN_DISABLE;
00748   ADC_REG_InitStruct->SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE;
00749   ADC_REG_InitStruct->ContinuousMode   = LL_ADC_REG_CONV_SINGLE;
00750   ADC_REG_InitStruct->DMATransfer      = LL_ADC_REG_DMA_TRANSFER_NONE;
00751 }
00752 
00753 /**
00754   * @brief  Initialize some features of ADC group injected.
00755   * @note   These parameters have an impact on ADC scope: ADC group injected.
00756   *         Refer to corresponding unitary functions into
00757   *         @ref ADC_LL_EF_Configuration_ADC_Group_Regular
00758   *         (functions with prefix "INJ").
00759   * @note   The setting of these parameters by function @ref LL_ADC_Init()
00760   *         is conditioned to ADC state:
00761   *         ADC instance must be disabled.
00762   *         This condition is applied to all ADC features, for efficiency
00763   *         and compatibility over all STM32 families. However, the different
00764   *         features can be set under different ADC state conditions
00765   *         (setting possible with ADC enabled without conversion on going,
00766   *         ADC enabled with conversion on going, ...)
00767   *         Each feature can be updated afterwards with a unitary function
00768   *         and potentially with ADC in a different state than disabled,
00769   *         refer to description of each function for setting
00770   *         conditioned to ADC state.
00771   * @note   After using this function, other features must be configured
00772   *         using LL unitary functions.
00773   *         The minimum configuration remaining to be done is:
00774   *          - Set ADC group injected sequencer:
00775   *            map channel on the selected sequencer rank.
00776   *            Refer to function @ref LL_ADC_INJ_SetSequencerRanks().
00777   *          - Set ADC channel sampling time
00778   *            Refer to function LL_ADC_SetChannelSamplingTime();
00779   * @param  ADCx ADC instance
00780   * @param  ADC_INJ_InitStruct Pointer to a @ref LL_ADC_INJ_InitTypeDef structure
00781   * @retval An ErrorStatus enumeration value:
00782   *          - SUCCESS: ADC registers are initialized
00783   *          - ERROR: ADC registers are not initialized
00784   */
00785 ErrorStatus LL_ADC_INJ_Init(ADC_TypeDef *ADCx, LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct)
00786 {
00787   ErrorStatus status = SUCCESS;
00788   
00789   /* Check the parameters */
00790   assert_param(IS_ADC_ALL_INSTANCE(ADCx));
00791 #if defined(ADC3)
00792   assert_param(IS_LL_ADC_INJ_TRIG_SOURCE(ADCx, ADC_INJ_InitStruct->TriggerSource));
00793 #else
00794   assert_param(IS_LL_ADC_INJ_TRIG_SOURCE(ADC_INJ_InitStruct->TriggerSource));
00795 #endif
00796   assert_param(IS_LL_ADC_INJ_SEQ_SCAN_LENGTH(ADC_INJ_InitStruct->SequencerLength));
00797   if(ADC_INJ_InitStruct->SequencerLength != LL_ADC_INJ_SEQ_SCAN_DISABLE)
00798   {
00799     assert_param(IS_LL_ADC_INJ_SEQ_SCAN_DISCONT_MODE(ADC_INJ_InitStruct->SequencerDiscont));
00800   }
00801   assert_param(IS_LL_ADC_INJ_TRIG_AUTO(ADC_INJ_InitStruct->TrigAuto));
00802   
00803   /* Note: Hardware constraint (refer to description of this function):       */
00804   /*       ADC instance must be disabled.                                     */
00805   if(LL_ADC_IsEnabled(ADCx) == 0U)
00806   {
00807     /* Configuration of ADC hierarchical scope:                               */
00808     /*  - ADC group injected                                                  */
00809     /*    - Set ADC group injected trigger source                             */
00810     /*    - Set ADC group injected sequencer length                           */
00811     /*    - Set ADC group injected sequencer discontinuous mode               */
00812     /*    - Set ADC group injected conversion trigger: independent or         */
00813     /*      from ADC group regular                                            */
00814     /* Note: On this STM32 serie, ADC trigger edge is set when starting       */
00815     /*       ADC conversion.                                                  */
00816     /*       Refer to function @ref LL_ADC_INJ_StartConversionExtTrig().      */
00817     if(ADC_INJ_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
00818     {
00819       MODIFY_REG(ADCx->CR1,
00820                    ADC_CR1_JDISCEN
00821                  | ADC_CR1_JAUTO
00822                 ,
00823                    ADC_INJ_InitStruct->SequencerDiscont
00824                  | ADC_INJ_InitStruct->TrigAuto
00825                 );
00826     }
00827     else
00828     {
00829       MODIFY_REG(ADCx->CR1,
00830                    ADC_CR1_JDISCEN
00831                  | ADC_CR1_JAUTO
00832                 ,
00833                    LL_ADC_REG_SEQ_DISCONT_DISABLE
00834                  | ADC_INJ_InitStruct->TrigAuto
00835                 );
00836     }
00837     
00838     MODIFY_REG(ADCx->CR2,
00839                ADC_CR2_JEXTSEL
00840               ,
00841                ADC_INJ_InitStruct->TriggerSource
00842               );
00843     
00844     /* Note: Hardware constraint (refer to description of this function):     */
00845     /* Note: If ADC instance feature scan mode is disabled                    */
00846     /*       (refer to  ADC instance initialization structure                 */
00847     /*       parameter @ref SequencersScanMode                                */
00848     /*       or function @ref LL_ADC_SetSequencersScanMode() ),               */
00849     /*       this parameter is discarded.                                     */
00850     LL_ADC_INJ_SetSequencerLength(ADCx, ADC_INJ_InitStruct->SequencerLength);
00851   }
00852   else
00853   {
00854     /* Initialization error: ADC instance is not disabled. */
00855     status = ERROR;
00856   }
00857   return status;
00858 }
00859 
00860 /**
00861   * @brief  Set each @ref LL_ADC_INJ_InitTypeDef field to default value.
00862   * @param  ADC_INJ_InitStruct Pointer to a @ref LL_ADC_INJ_InitTypeDef structure
00863   *                            whose fields will be set to default values.
00864   * @retval None
00865   */
00866 void LL_ADC_INJ_StructInit(LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct)
00867 {
00868   /* Set ADC_INJ_InitStruct fields to default values */
00869   /* Set fields of ADC group injected */
00870   ADC_INJ_InitStruct->TriggerSource    = LL_ADC_INJ_TRIG_SOFTWARE;
00871   ADC_INJ_InitStruct->SequencerLength  = LL_ADC_INJ_SEQ_SCAN_DISABLE;
00872   ADC_INJ_InitStruct->SequencerDiscont = LL_ADC_INJ_SEQ_DISCONT_DISABLE;
00873   ADC_INJ_InitStruct->TrigAuto         = LL_ADC_INJ_TRIG_INDEPENDENT;
00874 }
00875 
00876 /**
00877   * @}
00878   */
00879 
00880 /**
00881   * @}
00882   */
00883 
00884 /**
00885   * @}
00886   */
00887 
00888 #endif /* ADC1 || ADC2 || ADC3 */
00889 
00890 /**
00891   * @}
00892   */
00893 
00894 #endif /* USE_FULL_LL_DRIVER */
00895 
00896 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/