STM32L443xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_ll_adc.c 00004 * @author MCD Application Team 00005 * @brief ADC LL module driver 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * Copyright (c) 2017 STMicroelectronics. 00010 * All rights reserved. 00011 * 00012 * This software is licensed under terms that can be found in the LICENSE file 00013 * in the root directory of this software component. 00014 * If no LICENSE file comes with this software, it is provided AS-IS. 00015 * 00016 ****************************************************************************** 00017 */ 00018 #if defined(USE_FULL_LL_DRIVER) 00019 00020 /* Includes ------------------------------------------------------------------*/ 00021 #include "stm32l4xx_ll_adc.h" 00022 #include "stm32l4xx_ll_bus.h" 00023 00024 #ifdef USE_FULL_ASSERT 00025 #include "stm32_assert.h" 00026 #else 00027 #define assert_param(expr) ((void)0U) 00028 #endif 00029 00030 /** @addtogroup STM32L4xx_LL_Driver 00031 * @{ 00032 */ 00033 00034 #if defined (ADC1) || defined (ADC2) || defined (ADC3) 00035 00036 /** @addtogroup ADC_LL ADC 00037 * @{ 00038 */ 00039 00040 /* Private types -------------------------------------------------------------*/ 00041 /* Private variables ---------------------------------------------------------*/ 00042 /* Private constants ---------------------------------------------------------*/ 00043 /** @addtogroup ADC_LL_Private_Constants 00044 * @{ 00045 */ 00046 00047 /* Definitions of ADC hardware constraints delays */ 00048 /* Note: Only ADC peripheral HW delays are defined in ADC LL driver driver, */ 00049 /* not timeout values: */ 00050 /* Timeout values for ADC operations are dependent to device clock */ 00051 /* configuration (system clock versus ADC clock), */ 00052 /* and therefore must be defined in user application. */ 00053 /* Refer to @ref ADC_LL_EC_HW_DELAYS for description of ADC timeout */ 00054 /* values definition. */ 00055 /* Note: ADC timeout values are defined here in CPU cycles to be independent */ 00056 /* of device clock setting. */ 00057 /* In user application, ADC timeout values should be defined with */ 00058 /* temporal values, in function of device clock settings. */ 00059 /* Highest ratio CPU clock frequency vs ADC clock frequency: */ 00060 /* - ADC clock from synchronous clock with AHB prescaler 512, */ 00061 /* APB prescaler 16, ADC prescaler 4. */ 00062 /* - ADC clock from asynchronous clock (PLLSAI) with prescaler 1, */ 00063 /* with highest ratio CPU clock frequency vs HSI clock frequency: */ 00064 /* CPU clock frequency max 72MHz, PLLSAI freq min 26MHz: ratio 4. */ 00065 /* Unit: CPU cycles. */ 00066 #define ADC_CLOCK_RATIO_VS_CPU_HIGHEST (512UL * 16UL * 4UL) 00067 #define ADC_TIMEOUT_DISABLE_CPU_CYCLES (ADC_CLOCK_RATIO_VS_CPU_HIGHEST * 1UL) 00068 #define ADC_TIMEOUT_STOP_CONVERSION_CPU_CYCLES (ADC_CLOCK_RATIO_VS_CPU_HIGHEST * 1UL) 00069 00070 /** 00071 * @} 00072 */ 00073 00074 /* Private macros ------------------------------------------------------------*/ 00075 00076 /** @addtogroup ADC_LL_Private_Macros 00077 * @{ 00078 */ 00079 00080 /* Check of parameters for configuration of ADC hierarchical scope: */ 00081 /* common to several ADC instances. */ 00082 #define IS_LL_ADC_COMMON_CLOCK(__CLOCK__) \ 00083 (((__CLOCK__) == LL_ADC_CLOCK_SYNC_PCLK_DIV1) \ 00084 || ((__CLOCK__) == LL_ADC_CLOCK_SYNC_PCLK_DIV2) \ 00085 || ((__CLOCK__) == LL_ADC_CLOCK_SYNC_PCLK_DIV4) \ 00086 || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV1) \ 00087 || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV2) \ 00088 || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV4) \ 00089 || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV6) \ 00090 || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV8) \ 00091 || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV10) \ 00092 || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV12) \ 00093 || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV16) \ 00094 || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV32) \ 00095 || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV64) \ 00096 || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV128) \ 00097 || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV256) \ 00098 ) 00099 00100 /* Check of parameters for configuration of ADC hierarchical scope: */ 00101 /* ADC instance. */ 00102 #define IS_LL_ADC_RESOLUTION(__RESOLUTION__) \ 00103 (((__RESOLUTION__) == LL_ADC_RESOLUTION_12B) \ 00104 || ((__RESOLUTION__) == LL_ADC_RESOLUTION_10B) \ 00105 || ((__RESOLUTION__) == LL_ADC_RESOLUTION_8B) \ 00106 || ((__RESOLUTION__) == LL_ADC_RESOLUTION_6B) \ 00107 ) 00108 00109 #define IS_LL_ADC_DATA_ALIGN(__DATA_ALIGN__) \ 00110 (((__DATA_ALIGN__) == LL_ADC_DATA_ALIGN_RIGHT) \ 00111 || ((__DATA_ALIGN__) == LL_ADC_DATA_ALIGN_LEFT) \ 00112 ) 00113 00114 #define IS_LL_ADC_LOW_POWER(__LOW_POWER__) \ 00115 (((__LOW_POWER__) == LL_ADC_LP_MODE_NONE) \ 00116 || ((__LOW_POWER__) == LL_ADC_LP_AUTOWAIT) \ 00117 ) 00118 00119 /* Check of parameters for configuration of ADC hierarchical scope: */ 00120 /* ADC group regular */ 00121 #define IS_LL_ADC_REG_TRIG_SOURCE(__REG_TRIG_SOURCE__) \ 00122 (((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE) \ 00123 || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO) \ 00124 || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO2) \ 00125 || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH1) \ 00126 || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH2) \ 00127 || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3) \ 00128 || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_TRGO) \ 00129 || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH2) \ 00130 || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO) \ 00131 || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_CH4) \ 00132 || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_TRGO) \ 00133 || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_CH4) \ 00134 || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM6_TRGO) \ 00135 || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO) \ 00136 || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO2) \ 00137 || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM15_TRGO) \ 00138 || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE11) \ 00139 ) 00140 00141 #define IS_LL_ADC_REG_CONTINUOUS_MODE(__REG_CONTINUOUS_MODE__) \ 00142 (((__REG_CONTINUOUS_MODE__) == LL_ADC_REG_CONV_SINGLE) \ 00143 || ((__REG_CONTINUOUS_MODE__) == LL_ADC_REG_CONV_CONTINUOUS) \ 00144 ) 00145 00146 #define IS_LL_ADC_REG_DMA_TRANSFER(__REG_DMA_TRANSFER__) \ 00147 (((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_NONE) \ 00148 || ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_LIMITED) \ 00149 || ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_UNLIMITED) \ 00150 ) 00151 00152 #define IS_LL_ADC_REG_OVR_DATA_BEHAVIOR(__REG_OVR_DATA_BEHAVIOR__) \ 00153 (((__REG_OVR_DATA_BEHAVIOR__) == LL_ADC_REG_OVR_DATA_PRESERVED) \ 00154 || ((__REG_OVR_DATA_BEHAVIOR__) == LL_ADC_REG_OVR_DATA_OVERWRITTEN) \ 00155 ) 00156 00157 #define IS_LL_ADC_REG_SEQ_SCAN_LENGTH(__REG_SEQ_SCAN_LENGTH__) \ 00158 (((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_DISABLE) \ 00159 || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS) \ 00160 || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS) \ 00161 || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS) \ 00162 || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS) \ 00163 || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS) \ 00164 || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_7RANKS) \ 00165 || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS) \ 00166 || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_9RANKS) \ 00167 || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_10RANKS) \ 00168 || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_11RANKS) \ 00169 || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_12RANKS) \ 00170 || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_13RANKS) \ 00171 || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_14RANKS) \ 00172 || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_15RANKS) \ 00173 || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_16RANKS) \ 00174 ) 00175 00176 #define IS_LL_ADC_REG_SEQ_SCAN_DISCONT_MODE(__REG_SEQ_DISCONT_MODE__) \ 00177 (((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_DISABLE) \ 00178 || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_1RANK) \ 00179 || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_2RANKS) \ 00180 || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_3RANKS) \ 00181 || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_4RANKS) \ 00182 || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_5RANKS) \ 00183 || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_6RANKS) \ 00184 || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_7RANKS) \ 00185 || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_8RANKS) \ 00186 ) 00187 00188 /* Check of parameters for configuration of ADC hierarchical scope: */ 00189 /* ADC group injected */ 00190 #define IS_LL_ADC_INJ_TRIG_SOURCE(__INJ_TRIG_SOURCE__) \ 00191 (((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE) \ 00192 || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO) \ 00193 || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO2) \ 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_TRGO) \ 00198 || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH1) \ 00199 || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH3) \ 00200 || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH4) \ 00201 || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_TRGO) \ 00202 || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM6_TRGO) \ 00203 || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH4) \ 00204 || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_TRGO) \ 00205 || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_TRGO2) \ 00206 || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM15_TRGO) \ 00207 || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_EXTI_LINE15) \ 00208 ) 00209 00210 #define IS_LL_ADC_INJ_TRIG_EXT_EDGE(__INJ_TRIG_EXT_EDGE__) \ 00211 (((__INJ_TRIG_EXT_EDGE__) == LL_ADC_INJ_TRIG_EXT_RISING) \ 00212 || ((__INJ_TRIG_EXT_EDGE__) == LL_ADC_INJ_TRIG_EXT_FALLING) \ 00213 || ((__INJ_TRIG_EXT_EDGE__) == LL_ADC_INJ_TRIG_EXT_RISINGFALLING) \ 00214 ) 00215 00216 #define IS_LL_ADC_INJ_TRIG_AUTO(__INJ_TRIG_AUTO__) \ 00217 (((__INJ_TRIG_AUTO__) == LL_ADC_INJ_TRIG_INDEPENDENT) \ 00218 || ((__INJ_TRIG_AUTO__) == LL_ADC_INJ_TRIG_FROM_GRP_REGULAR) \ 00219 ) 00220 00221 #define IS_LL_ADC_INJ_SEQ_SCAN_LENGTH(__INJ_SEQ_SCAN_LENGTH__) \ 00222 (((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_DISABLE) \ 00223 || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_2RANKS) \ 00224 || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_3RANKS) \ 00225 || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_4RANKS) \ 00226 ) 00227 00228 #define IS_LL_ADC_INJ_SEQ_SCAN_DISCONT_MODE(__INJ_SEQ_DISCONT_MODE__) \ 00229 (((__INJ_SEQ_DISCONT_MODE__) == LL_ADC_INJ_SEQ_DISCONT_DISABLE) \ 00230 || ((__INJ_SEQ_DISCONT_MODE__) == LL_ADC_INJ_SEQ_DISCONT_1RANK) \ 00231 ) 00232 00233 #if defined(ADC_MULTIMODE_SUPPORT) 00234 /* Check of parameters for configuration of ADC hierarchical scope: */ 00235 /* multimode. */ 00236 #define IS_LL_ADC_MULTI_MODE(__MULTI_MODE__) \ 00237 (((__MULTI_MODE__) == LL_ADC_MULTI_INDEPENDENT) \ 00238 || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_SIMULT) \ 00239 || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_INTERL) \ 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_INT_INJ_SIM) \ 00245 ) 00246 00247 #define IS_LL_ADC_MULTI_DMA_TRANSFER(__MULTI_DMA_TRANSFER__) \ 00248 (((__MULTI_DMA_TRANSFER__) == LL_ADC_MULTI_REG_DMA_EACH_ADC) \ 00249 || ((__MULTI_DMA_TRANSFER__) == LL_ADC_MULTI_REG_DMA_LIMIT_RES12_10B) \ 00250 || ((__MULTI_DMA_TRANSFER__) == LL_ADC_MULTI_REG_DMA_LIMIT_RES8_6B) \ 00251 || ((__MULTI_DMA_TRANSFER__) == LL_ADC_MULTI_REG_DMA_UNLMT_RES12_10B) \ 00252 || ((__MULTI_DMA_TRANSFER__) == LL_ADC_MULTI_REG_DMA_UNLMT_RES8_6B) \ 00253 ) 00254 00255 #define IS_LL_ADC_MULTI_TWOSMP_DELAY(__MULTI_TWOSMP_DELAY__) \ 00256 (((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_1CYCLE) \ 00257 || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_2CYCLES) \ 00258 || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_3CYCLES) \ 00259 || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_4CYCLES) \ 00260 || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_5CYCLES) \ 00261 || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_6CYCLES) \ 00262 || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_7CYCLES) \ 00263 || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_8CYCLES) \ 00264 || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_9CYCLES) \ 00265 || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_10CYCLES) \ 00266 || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_11CYCLES) \ 00267 || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_12CYCLES) \ 00268 ) 00269 00270 #define IS_LL_ADC_MULTI_MASTER_SLAVE(__MULTI_MASTER_SLAVE__) \ 00271 (((__MULTI_MASTER_SLAVE__) == LL_ADC_MULTI_MASTER) \ 00272 || ((__MULTI_MASTER_SLAVE__) == LL_ADC_MULTI_SLAVE) \ 00273 || ((__MULTI_MASTER_SLAVE__) == LL_ADC_MULTI_MASTER_SLAVE) \ 00274 ) 00275 00276 #endif /* ADC_MULTIMODE_SUPPORT */ 00277 /** 00278 * @} 00279 */ 00280 00281 00282 /* Private function prototypes -----------------------------------------------*/ 00283 00284 /* Exported functions --------------------------------------------------------*/ 00285 /** @addtogroup ADC_LL_Exported_Functions 00286 * @{ 00287 */ 00288 00289 /** @addtogroup ADC_LL_EF_Init 00290 * @{ 00291 */ 00292 00293 /** 00294 * @brief De-initialize registers of all ADC instances belonging to 00295 * the same ADC common instance to their default reset values. 00296 * @note This function is performing a hard reset, using high level 00297 * clock source RCC ADC reset. 00298 * Caution: On this STM32 series, if several ADC instances are available 00299 * on the selected device, RCC ADC reset will reset 00300 * all ADC instances belonging to the common ADC instance. 00301 * To de-initialize only 1 ADC instance, use 00302 * function @ref LL_ADC_DeInit(). 00303 * @param ADCxy_COMMON ADC common instance 00304 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() ) 00305 * @retval An ErrorStatus enumeration value: 00306 * - SUCCESS: ADC common registers are de-initialized 00307 * - ERROR: not applicable 00308 */ 00309 ErrorStatus LL_ADC_CommonDeInit(ADC_Common_TypeDef *ADCxy_COMMON) 00310 { 00311 /* Check the parameters */ 00312 assert_param(IS_ADC_COMMON_INSTANCE(ADCxy_COMMON)); 00313 00314 /* Prevent unused argument compilation warning */ 00315 (void)(ADCxy_COMMON); 00316 00317 /* Force reset of ADC clock (core clock) */ 00318 LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_ADC); 00319 00320 /* Release reset of ADC clock (core clock) */ 00321 LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_ADC); 00322 00323 return SUCCESS; 00324 } 00325 00326 /** 00327 * @brief Initialize some features of ADC common parameters 00328 * (all ADC instances belonging to the same ADC common instance) 00329 * and multimode (for devices with several ADC instances available). 00330 * @note The setting of ADC common parameters is conditioned to 00331 * ADC instances state: 00332 * All ADC instances belonging to the same ADC common instance 00333 * must be disabled. 00334 * @param ADCxy_COMMON ADC common instance 00335 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() ) 00336 * @param ADC_CommonInitStruct Pointer to a @ref LL_ADC_CommonInitTypeDef structure 00337 * @retval An ErrorStatus enumeration value: 00338 * - SUCCESS: ADC common registers are initialized 00339 * - ERROR: ADC common registers are not initialized 00340 */ 00341 ErrorStatus LL_ADC_CommonInit(ADC_Common_TypeDef *ADCxy_COMMON, LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct) 00342 { 00343 ErrorStatus status = SUCCESS; 00344 00345 /* Check the parameters */ 00346 assert_param(IS_ADC_COMMON_INSTANCE(ADCxy_COMMON)); 00347 assert_param(IS_LL_ADC_COMMON_CLOCK(ADC_CommonInitStruct->CommonClock)); 00348 00349 #if defined(ADC_MULTIMODE_SUPPORT) 00350 assert_param(IS_LL_ADC_MULTI_MODE(ADC_CommonInitStruct->Multimode)); 00351 if (ADC_CommonInitStruct->Multimode != LL_ADC_MULTI_INDEPENDENT) 00352 { 00353 assert_param(IS_LL_ADC_MULTI_DMA_TRANSFER(ADC_CommonInitStruct->MultiDMATransfer)); 00354 assert_param(IS_LL_ADC_MULTI_TWOSMP_DELAY(ADC_CommonInitStruct->MultiTwoSamplingDelay)); 00355 } 00356 #endif /* ADC_MULTIMODE_SUPPORT */ 00357 00358 /* Note: Hardware constraint (refer to description of functions */ 00359 /* "LL_ADC_SetCommonXXX()" and "LL_ADC_SetMultiXXX()"): */ 00360 /* On this STM32 series, setting of these features is conditioned to */ 00361 /* ADC state: */ 00362 /* All ADC instances of the ADC common group must be disabled. */ 00363 if (__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(ADCxy_COMMON) == 0UL) 00364 { 00365 /* Configuration of ADC hierarchical scope: */ 00366 /* - common to several ADC */ 00367 /* (all ADC instances belonging to the same ADC common instance) */ 00368 /* - Set ADC clock (conversion clock) */ 00369 /* - multimode (if several ADC instances available on the */ 00370 /* selected device) */ 00371 /* - Set ADC multimode configuration */ 00372 /* - Set ADC multimode DMA transfer */ 00373 /* - Set ADC multimode: delay between 2 sampling phases */ 00374 #if defined(ADC_MULTIMODE_SUPPORT) 00375 if (ADC_CommonInitStruct->Multimode != LL_ADC_MULTI_INDEPENDENT) 00376 { 00377 MODIFY_REG(ADCxy_COMMON->CCR, 00378 ADC_CCR_CKMODE 00379 | ADC_CCR_PRESC 00380 | ADC_CCR_DUAL 00381 | ADC_CCR_MDMA 00382 | ADC_CCR_DELAY 00383 , 00384 ADC_CommonInitStruct->CommonClock 00385 | ADC_CommonInitStruct->Multimode 00386 | ADC_CommonInitStruct->MultiDMATransfer 00387 | ADC_CommonInitStruct->MultiTwoSamplingDelay 00388 ); 00389 } 00390 else 00391 { 00392 MODIFY_REG(ADCxy_COMMON->CCR, 00393 ADC_CCR_CKMODE 00394 | ADC_CCR_PRESC 00395 | ADC_CCR_DUAL 00396 | ADC_CCR_MDMA 00397 | ADC_CCR_DELAY 00398 , 00399 ADC_CommonInitStruct->CommonClock 00400 | LL_ADC_MULTI_INDEPENDENT 00401 ); 00402 } 00403 #else 00404 LL_ADC_SetCommonClock(ADCxy_COMMON, ADC_CommonInitStruct->CommonClock); 00405 #endif 00406 } 00407 else 00408 { 00409 /* Initialization error: One or several ADC instances belonging to */ 00410 /* the same ADC common instance are not disabled. */ 00411 status = ERROR; 00412 } 00413 00414 return status; 00415 } 00416 00417 /** 00418 * @brief Set each @ref LL_ADC_CommonInitTypeDef field to default value. 00419 * @param ADC_CommonInitStruct Pointer to a @ref LL_ADC_CommonInitTypeDef structure 00420 * whose fields will be set to default values. 00421 * @retval None 00422 */ 00423 void LL_ADC_CommonStructInit(LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct) 00424 { 00425 /* Set ADC_CommonInitStruct fields to default values */ 00426 /* Set fields of ADC common */ 00427 /* (all ADC instances belonging to the same ADC common instance) */ 00428 ADC_CommonInitStruct->CommonClock = LL_ADC_CLOCK_SYNC_PCLK_DIV2; 00429 00430 #if defined(ADC_MULTIMODE_SUPPORT) 00431 /* Set fields of ADC multimode */ 00432 ADC_CommonInitStruct->Multimode = LL_ADC_MULTI_INDEPENDENT; 00433 ADC_CommonInitStruct->MultiDMATransfer = LL_ADC_MULTI_REG_DMA_EACH_ADC; 00434 ADC_CommonInitStruct->MultiTwoSamplingDelay = LL_ADC_MULTI_TWOSMP_DELAY_1CYCLE; 00435 #endif /* ADC_MULTIMODE_SUPPORT */ 00436 } 00437 00438 /** 00439 * @brief De-initialize registers of the selected ADC instance 00440 * to their default reset values. 00441 * @note To reset all ADC instances quickly (perform a hard reset), 00442 * use function @ref LL_ADC_CommonDeInit(). 00443 * @note If this functions returns error status, it means that ADC instance 00444 * is in an unknown state. 00445 * In this case, perform a hard reset using high level 00446 * clock source RCC ADC reset. 00447 * Caution: On this STM32 series, if several ADC instances are available 00448 * on the selected device, RCC ADC reset will reset 00449 * all ADC instances belonging to the common ADC instance. 00450 * Refer to function @ref LL_ADC_CommonDeInit(). 00451 * @param ADCx ADC instance 00452 * @retval An ErrorStatus enumeration value: 00453 * - SUCCESS: ADC registers are de-initialized 00454 * - ERROR: ADC registers are not de-initialized 00455 */ 00456 ErrorStatus LL_ADC_DeInit(ADC_TypeDef *ADCx) 00457 { 00458 ErrorStatus status = SUCCESS; 00459 00460 __IO uint32_t timeout_cpu_cycles = 0UL; 00461 00462 /* Check the parameters */ 00463 assert_param(IS_ADC_ALL_INSTANCE(ADCx)); 00464 00465 /* Disable ADC instance if not already disabled. */ 00466 if (LL_ADC_IsEnabled(ADCx) == 1UL) 00467 { 00468 /* Set ADC group regular trigger source to SW start to ensure to not */ 00469 /* have an external trigger event occurring during the conversion stop */ 00470 /* ADC disable process. */ 00471 LL_ADC_REG_SetTriggerSource(ADCx, LL_ADC_REG_TRIG_SOFTWARE); 00472 00473 /* Stop potential ADC conversion on going on ADC group regular. */ 00474 if (LL_ADC_REG_IsConversionOngoing(ADCx) != 0UL) 00475 { 00476 if (LL_ADC_REG_IsStopConversionOngoing(ADCx) == 0UL) 00477 { 00478 LL_ADC_REG_StopConversion(ADCx); 00479 } 00480 } 00481 00482 /* Set ADC group injected trigger source to SW start to ensure to not */ 00483 /* have an external trigger event occurring during the conversion stop */ 00484 /* ADC disable process. */ 00485 LL_ADC_INJ_SetTriggerSource(ADCx, LL_ADC_INJ_TRIG_SOFTWARE); 00486 00487 /* Stop potential ADC conversion on going on ADC group injected. */ 00488 if (LL_ADC_INJ_IsConversionOngoing(ADCx) != 0UL) 00489 { 00490 if (LL_ADC_INJ_IsStopConversionOngoing(ADCx) == 0UL) 00491 { 00492 LL_ADC_INJ_StopConversion(ADCx); 00493 } 00494 } 00495 00496 /* Wait for ADC conversions are effectively stopped */ 00497 timeout_cpu_cycles = ADC_TIMEOUT_STOP_CONVERSION_CPU_CYCLES; 00498 while ((LL_ADC_REG_IsStopConversionOngoing(ADCx) 00499 | LL_ADC_INJ_IsStopConversionOngoing(ADCx)) == 1UL) 00500 { 00501 timeout_cpu_cycles--; 00502 if (timeout_cpu_cycles == 0UL) 00503 { 00504 /* Time-out error */ 00505 status = ERROR; 00506 break; 00507 } 00508 } 00509 00510 /* Flush group injected contexts queue (register JSQR): */ 00511 /* Note: Bit JQM must be set to empty the contexts queue (otherwise */ 00512 /* contexts queue is maintained with the last active context). */ 00513 LL_ADC_INJ_SetQueueMode(ADCx, LL_ADC_INJ_QUEUE_2CONTEXTS_END_EMPTY); 00514 00515 /* Disable the ADC instance */ 00516 LL_ADC_Disable(ADCx); 00517 00518 /* Wait for ADC instance is effectively disabled */ 00519 timeout_cpu_cycles = ADC_TIMEOUT_DISABLE_CPU_CYCLES; 00520 while (LL_ADC_IsDisableOngoing(ADCx) == 1UL) 00521 { 00522 timeout_cpu_cycles--; 00523 if (timeout_cpu_cycles == 0UL) 00524 { 00525 /* Time-out error */ 00526 status = ERROR; 00527 break; 00528 } 00529 } 00530 } 00531 00532 /* Check whether ADC state is compliant with expected state */ 00533 if (READ_BIT(ADCx->CR, 00534 (ADC_CR_JADSTP | ADC_CR_ADSTP | ADC_CR_JADSTART | ADC_CR_ADSTART 00535 | ADC_CR_ADDIS | ADC_CR_ADEN) 00536 ) 00537 == 0UL) 00538 { 00539 /* ========== Reset ADC registers ========== */ 00540 /* Reset register IER */ 00541 CLEAR_BIT(ADCx->IER, 00542 (LL_ADC_IT_ADRDY 00543 | LL_ADC_IT_EOC 00544 | LL_ADC_IT_EOS 00545 | LL_ADC_IT_OVR 00546 | LL_ADC_IT_EOSMP 00547 | LL_ADC_IT_JEOC 00548 | LL_ADC_IT_JEOS 00549 | LL_ADC_IT_JQOVF 00550 | LL_ADC_IT_AWD1 00551 | LL_ADC_IT_AWD2 00552 | LL_ADC_IT_AWD3 00553 ) 00554 ); 00555 00556 /* Reset register ISR */ 00557 SET_BIT(ADCx->ISR, 00558 (LL_ADC_FLAG_ADRDY 00559 | LL_ADC_FLAG_EOC 00560 | LL_ADC_FLAG_EOS 00561 | LL_ADC_FLAG_OVR 00562 | LL_ADC_FLAG_EOSMP 00563 | LL_ADC_FLAG_JEOC 00564 | LL_ADC_FLAG_JEOS 00565 | LL_ADC_FLAG_JQOVF 00566 | LL_ADC_FLAG_AWD1 00567 | LL_ADC_FLAG_AWD2 00568 | LL_ADC_FLAG_AWD3 00569 ) 00570 ); 00571 00572 /* Reset register CR */ 00573 /* - Bits ADC_CR_JADSTP, ADC_CR_ADSTP, ADC_CR_JADSTART, ADC_CR_ADSTART, */ 00574 /* ADC_CR_ADCAL, ADC_CR_ADDIS, ADC_CR_ADEN are in */ 00575 /* access mode "read-set": no direct reset applicable. */ 00576 /* - Reset Calibration mode to default setting (single ended). */ 00577 /* - Disable ADC internal voltage regulator. */ 00578 /* - Enable ADC deep power down. */ 00579 /* Note: ADC internal voltage regulator disable and ADC deep power */ 00580 /* down enable are conditioned to ADC state disabled: */ 00581 /* already done above. */ 00582 CLEAR_BIT(ADCx->CR, ADC_CR_ADVREGEN | ADC_CR_ADCALDIF); 00583 SET_BIT(ADCx->CR, ADC_CR_DEEPPWD); 00584 00585 /* Reset register CFGR */ 00586 MODIFY_REG(ADCx->CFGR, 00587 (ADC_CFGR_AWD1CH | ADC_CFGR_JAUTO | ADC_CFGR_JAWD1EN 00588 | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL | ADC_CFGR_JQM 00589 | ADC_CFGR_JDISCEN | ADC_CFGR_DISCNUM | ADC_CFGR_DISCEN 00590 | ADC_CFGR_AUTDLY | ADC_CFGR_CONT | ADC_CFGR_OVRMOD 00591 | ADC_CFGR_EXTEN | ADC_CFGR_EXTSEL | ADC_CFGR_ALIGN 00592 | ADC_CFGR_RES | ADC_CFGR_DMACFG | ADC_CFGR_DMAEN), 00593 ADC_CFGR_JQDIS 00594 ); 00595 00596 /* Reset register CFGR2 */ 00597 CLEAR_BIT(ADCx->CFGR2, 00598 (ADC_CFGR2_ROVSM | ADC_CFGR2_TROVS | ADC_CFGR2_OVSS 00599 | ADC_CFGR2_OVSR | ADC_CFGR2_JOVSE | ADC_CFGR2_ROVSE) 00600 ); 00601 00602 /* Reset register SMPR1 */ 00603 CLEAR_BIT(ADCx->SMPR1, 00604 (ADC_SMPR1_SMP9 | ADC_SMPR1_SMP8 | ADC_SMPR1_SMP7 00605 | ADC_SMPR1_SMP6 | ADC_SMPR1_SMP5 | ADC_SMPR1_SMP4 00606 | ADC_SMPR1_SMP3 | ADC_SMPR1_SMP2 | ADC_SMPR1_SMP1) 00607 ); 00608 00609 /* Reset register SMPR2 */ 00610 CLEAR_BIT(ADCx->SMPR2, 00611 (ADC_SMPR2_SMP18 | ADC_SMPR2_SMP17 | ADC_SMPR2_SMP16 00612 | ADC_SMPR2_SMP15 | ADC_SMPR2_SMP14 | ADC_SMPR2_SMP13 00613 | ADC_SMPR2_SMP12 | ADC_SMPR2_SMP11 | ADC_SMPR2_SMP10) 00614 ); 00615 00616 /* Reset register TR1 */ 00617 MODIFY_REG(ADCx->TR1, ADC_TR1_HT1 | ADC_TR1_LT1, ADC_TR1_HT1); 00618 00619 /* Reset register TR2 */ 00620 MODIFY_REG(ADCx->TR2, ADC_TR2_HT2 | ADC_TR2_LT2, ADC_TR2_HT2); 00621 00622 /* Reset register TR3 */ 00623 MODIFY_REG(ADCx->TR3, ADC_TR3_HT3 | ADC_TR3_LT3, ADC_TR3_HT3); 00624 00625 /* Reset register SQR1 */ 00626 CLEAR_BIT(ADCx->SQR1, 00627 (ADC_SQR1_SQ4 | ADC_SQR1_SQ3 | ADC_SQR1_SQ2 00628 | ADC_SQR1_SQ1 | ADC_SQR1_L) 00629 ); 00630 00631 /* Reset register SQR2 */ 00632 CLEAR_BIT(ADCx->SQR2, 00633 (ADC_SQR2_SQ9 | ADC_SQR2_SQ8 | ADC_SQR2_SQ7 00634 | ADC_SQR2_SQ6 | ADC_SQR2_SQ5) 00635 ); 00636 00637 /* Reset register SQR3 */ 00638 CLEAR_BIT(ADCx->SQR3, 00639 (ADC_SQR3_SQ14 | ADC_SQR3_SQ13 | ADC_SQR3_SQ12 00640 | ADC_SQR3_SQ11 | ADC_SQR3_SQ10) 00641 ); 00642 00643 /* Reset register SQR4 */ 00644 CLEAR_BIT(ADCx->SQR4, ADC_SQR4_SQ16 | ADC_SQR4_SQ15); 00645 00646 /* Reset register JSQR */ 00647 CLEAR_BIT(ADCx->JSQR, 00648 (ADC_JSQR_JL 00649 | ADC_JSQR_JEXTSEL | ADC_JSQR_JEXTEN 00650 | ADC_JSQR_JSQ4 | ADC_JSQR_JSQ3 00651 | ADC_JSQR_JSQ2 | ADC_JSQR_JSQ1) 00652 ); 00653 00654 /* Reset register DR */ 00655 /* Note: bits in access mode read only, no direct reset applicable */ 00656 00657 /* Reset register OFR1 */ 00658 CLEAR_BIT(ADCx->OFR1, ADC_OFR1_OFFSET1_EN | ADC_OFR1_OFFSET1_CH | ADC_OFR1_OFFSET1); 00659 /* Reset register OFR2 */ 00660 CLEAR_BIT(ADCx->OFR2, ADC_OFR2_OFFSET2_EN | ADC_OFR2_OFFSET2_CH | ADC_OFR2_OFFSET2); 00661 /* Reset register OFR3 */ 00662 CLEAR_BIT(ADCx->OFR3, ADC_OFR3_OFFSET3_EN | ADC_OFR3_OFFSET3_CH | ADC_OFR3_OFFSET3); 00663 /* Reset register OFR4 */ 00664 CLEAR_BIT(ADCx->OFR4, ADC_OFR4_OFFSET4_EN | ADC_OFR4_OFFSET4_CH | ADC_OFR4_OFFSET4); 00665 00666 /* Reset registers JDR1, JDR2, JDR3, JDR4 */ 00667 /* Note: bits in access mode read only, no direct reset applicable */ 00668 00669 /* Reset register AWD2CR */ 00670 CLEAR_BIT(ADCx->AWD2CR, ADC_AWD2CR_AWD2CH); 00671 00672 /* Reset register AWD3CR */ 00673 CLEAR_BIT(ADCx->AWD3CR, ADC_AWD3CR_AWD3CH); 00674 00675 /* Reset register DIFSEL */ 00676 CLEAR_BIT(ADCx->DIFSEL, ADC_DIFSEL_DIFSEL); 00677 00678 /* Reset register CALFACT */ 00679 CLEAR_BIT(ADCx->CALFACT, ADC_CALFACT_CALFACT_D | ADC_CALFACT_CALFACT_S); 00680 } 00681 else 00682 { 00683 /* ADC instance is in an unknown state */ 00684 /* Need to performing a hard reset of ADC instance, using high level */ 00685 /* clock source RCC ADC reset. */ 00686 /* Caution: On this STM32 series, if several ADC instances are available */ 00687 /* on the selected device, RCC ADC reset will reset */ 00688 /* all ADC instances belonging to the common ADC instance. */ 00689 /* Caution: On this STM32 series, if several ADC instances are available */ 00690 /* on the selected device, RCC ADC reset will reset */ 00691 /* all ADC instances belonging to the common ADC instance. */ 00692 status = ERROR; 00693 } 00694 00695 return status; 00696 } 00697 00698 /** 00699 * @brief Initialize some features of ADC instance. 00700 * @note These parameters have an impact on ADC scope: ADC instance. 00701 * Affects both group regular and group injected (availability 00702 * of ADC group injected depends on STM32 families). 00703 * Refer to corresponding unitary functions into 00704 * @ref ADC_LL_EF_Configuration_ADC_Instance . 00705 * @note The setting of these parameters by function @ref LL_ADC_Init() 00706 * is conditioned to ADC state: 00707 * ADC instance must be disabled. 00708 * This condition is applied to all ADC features, for efficiency 00709 * and compatibility over all STM32 families. However, the different 00710 * features can be set under different ADC state conditions 00711 * (setting possible with ADC enabled without conversion on going, 00712 * ADC enabled with conversion on going, ...) 00713 * Each feature can be updated afterwards with a unitary function 00714 * and potentially with ADC in a different state than disabled, 00715 * refer to description of each function for setting 00716 * conditioned to ADC state. 00717 * @note After using this function, some other features must be configured 00718 * using LL unitary functions. 00719 * The minimum configuration remaining to be done is: 00720 * - Set ADC group regular or group injected sequencer: 00721 * map channel on the selected sequencer rank. 00722 * Refer to function @ref LL_ADC_REG_SetSequencerRanks(). 00723 * - Set ADC channel sampling time 00724 * Refer to function LL_ADC_SetChannelSamplingTime(); 00725 * @param ADCx ADC instance 00726 * @param ADC_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure 00727 * @retval An ErrorStatus enumeration value: 00728 * - SUCCESS: ADC registers are initialized 00729 * - ERROR: ADC registers are not initialized 00730 */ 00731 ErrorStatus LL_ADC_Init(ADC_TypeDef *ADCx, LL_ADC_InitTypeDef *ADC_InitStruct) 00732 { 00733 ErrorStatus status = SUCCESS; 00734 00735 /* Check the parameters */ 00736 assert_param(IS_ADC_ALL_INSTANCE(ADCx)); 00737 00738 assert_param(IS_LL_ADC_RESOLUTION(ADC_InitStruct->Resolution)); 00739 assert_param(IS_LL_ADC_DATA_ALIGN(ADC_InitStruct->DataAlignment)); 00740 assert_param(IS_LL_ADC_LOW_POWER(ADC_InitStruct->LowPowerMode)); 00741 00742 /* Note: Hardware constraint (refer to description of this function): */ 00743 /* ADC instance must be disabled. */ 00744 if (LL_ADC_IsEnabled(ADCx) == 0UL) 00745 { 00746 /* Configuration of ADC hierarchical scope: */ 00747 /* - ADC instance */ 00748 /* - Set ADC data resolution */ 00749 /* - Set ADC conversion data alignment */ 00750 /* - Set ADC low power mode */ 00751 MODIFY_REG(ADCx->CFGR, 00752 ADC_CFGR_RES 00753 | ADC_CFGR_ALIGN 00754 | ADC_CFGR_AUTDLY 00755 , 00756 ADC_InitStruct->Resolution 00757 | ADC_InitStruct->DataAlignment 00758 | ADC_InitStruct->LowPowerMode 00759 ); 00760 00761 } 00762 else 00763 { 00764 /* Initialization error: ADC instance is not disabled. */ 00765 status = ERROR; 00766 } 00767 00768 return status; 00769 } 00770 00771 /** 00772 * @brief Set each @ref LL_ADC_InitTypeDef field to default value. 00773 * @param ADC_InitStruct Pointer to a @ref LL_ADC_InitTypeDef structure 00774 * whose fields will be set to default values. 00775 * @retval None 00776 */ 00777 void LL_ADC_StructInit(LL_ADC_InitTypeDef *ADC_InitStruct) 00778 { 00779 /* Set ADC_InitStruct fields to default values */ 00780 /* Set fields of ADC instance */ 00781 ADC_InitStruct->Resolution = LL_ADC_RESOLUTION_12B; 00782 ADC_InitStruct->DataAlignment = LL_ADC_DATA_ALIGN_RIGHT; 00783 ADC_InitStruct->LowPowerMode = LL_ADC_LP_MODE_NONE; 00784 00785 } 00786 00787 /** 00788 * @brief Initialize some features of ADC group regular. 00789 * @note These parameters have an impact on ADC scope: ADC group regular. 00790 * Refer to corresponding unitary functions into 00791 * @ref ADC_LL_EF_Configuration_ADC_Group_Regular 00792 * (functions with prefix "REG"). 00793 * @note The setting of these parameters by function @ref LL_ADC_Init() 00794 * is conditioned to ADC state: 00795 * ADC instance must be disabled. 00796 * This condition is applied to all ADC features, for efficiency 00797 * and compatibility over all STM32 families. However, the different 00798 * features can be set under different ADC state conditions 00799 * (setting possible with ADC enabled without conversion on going, 00800 * ADC enabled with conversion on going, ...) 00801 * Each feature can be updated afterwards with a unitary function 00802 * and potentially with ADC in a different state than disabled, 00803 * refer to description of each function for setting 00804 * conditioned to ADC state. 00805 * @note After using this function, other features must be configured 00806 * using LL unitary functions. 00807 * The minimum configuration remaining to be done is: 00808 * - Set ADC group regular or group injected sequencer: 00809 * map channel on the selected sequencer rank. 00810 * Refer to function @ref LL_ADC_REG_SetSequencerRanks(). 00811 * - Set ADC channel sampling time 00812 * Refer to function LL_ADC_SetChannelSamplingTime(); 00813 * @param ADCx ADC instance 00814 * @param ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure 00815 * @retval An ErrorStatus enumeration value: 00816 * - SUCCESS: ADC registers are initialized 00817 * - ERROR: ADC registers are not initialized 00818 */ 00819 ErrorStatus LL_ADC_REG_Init(ADC_TypeDef *ADCx, LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct) 00820 { 00821 ErrorStatus status = SUCCESS; 00822 00823 /* Check the parameters */ 00824 assert_param(IS_ADC_ALL_INSTANCE(ADCx)); 00825 assert_param(IS_LL_ADC_REG_TRIG_SOURCE(ADC_REG_InitStruct->TriggerSource)); 00826 assert_param(IS_LL_ADC_REG_SEQ_SCAN_LENGTH(ADC_REG_InitStruct->SequencerLength)); 00827 if (ADC_REG_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE) 00828 { 00829 assert_param(IS_LL_ADC_REG_SEQ_SCAN_DISCONT_MODE(ADC_REG_InitStruct->SequencerDiscont)); 00830 00831 /* ADC group regular continuous mode and discontinuous mode */ 00832 /* can not be enabled simultenaeously */ 00833 assert_param((ADC_REG_InitStruct->ContinuousMode == LL_ADC_REG_CONV_SINGLE) 00834 || (ADC_REG_InitStruct->SequencerDiscont == LL_ADC_REG_SEQ_DISCONT_DISABLE)); 00835 } 00836 assert_param(IS_LL_ADC_REG_CONTINUOUS_MODE(ADC_REG_InitStruct->ContinuousMode)); 00837 assert_param(IS_LL_ADC_REG_DMA_TRANSFER(ADC_REG_InitStruct->DMATransfer)); 00838 assert_param(IS_LL_ADC_REG_OVR_DATA_BEHAVIOR(ADC_REG_InitStruct->Overrun)); 00839 00840 /* Note: Hardware constraint (refer to description of this function): */ 00841 /* ADC instance must be disabled. */ 00842 if (LL_ADC_IsEnabled(ADCx) == 0UL) 00843 { 00844 /* Configuration of ADC hierarchical scope: */ 00845 /* - ADC group regular */ 00846 /* - Set ADC group regular trigger source */ 00847 /* - Set ADC group regular sequencer length */ 00848 /* - Set ADC group regular sequencer discontinuous mode */ 00849 /* - Set ADC group regular continuous mode */ 00850 /* - Set ADC group regular conversion data transfer: no transfer or */ 00851 /* transfer by DMA, and DMA requests mode */ 00852 /* - Set ADC group regular overrun behavior */ 00853 /* Note: On this STM32 series, ADC trigger edge is set to value 0x0 by */ 00854 /* setting of trigger source to SW start. */ 00855 if (ADC_REG_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE) 00856 { 00857 MODIFY_REG(ADCx->CFGR, 00858 ADC_CFGR_EXTSEL 00859 | ADC_CFGR_EXTEN 00860 | ADC_CFGR_DISCEN 00861 | ADC_CFGR_DISCNUM 00862 | ADC_CFGR_CONT 00863 | ADC_CFGR_DMAEN 00864 | ADC_CFGR_DMACFG 00865 | ADC_CFGR_OVRMOD 00866 , 00867 ADC_REG_InitStruct->TriggerSource 00868 | ADC_REG_InitStruct->SequencerDiscont 00869 | ADC_REG_InitStruct->ContinuousMode 00870 | ADC_REG_InitStruct->DMATransfer 00871 | ADC_REG_InitStruct->Overrun 00872 ); 00873 } 00874 else 00875 { 00876 MODIFY_REG(ADCx->CFGR, 00877 ADC_CFGR_EXTSEL 00878 | ADC_CFGR_EXTEN 00879 | ADC_CFGR_DISCEN 00880 | ADC_CFGR_DISCNUM 00881 | ADC_CFGR_CONT 00882 | ADC_CFGR_DMAEN 00883 | ADC_CFGR_DMACFG 00884 | ADC_CFGR_OVRMOD 00885 , 00886 ADC_REG_InitStruct->TriggerSource 00887 | LL_ADC_REG_SEQ_DISCONT_DISABLE 00888 | ADC_REG_InitStruct->ContinuousMode 00889 | ADC_REG_InitStruct->DMATransfer 00890 | ADC_REG_InitStruct->Overrun 00891 ); 00892 } 00893 00894 /* Set ADC group regular sequencer length and scan direction */ 00895 LL_ADC_REG_SetSequencerLength(ADCx, ADC_REG_InitStruct->SequencerLength); 00896 } 00897 else 00898 { 00899 /* Initialization error: ADC instance is not disabled. */ 00900 status = ERROR; 00901 } 00902 return status; 00903 } 00904 00905 /** 00906 * @brief Set each @ref LL_ADC_REG_InitTypeDef field to default value. 00907 * @param ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure 00908 * whose fields will be set to default values. 00909 * @retval None 00910 */ 00911 void LL_ADC_REG_StructInit(LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct) 00912 { 00913 /* Set ADC_REG_InitStruct fields to default values */ 00914 /* Set fields of ADC group regular */ 00915 /* Note: On this STM32 series, ADC trigger edge is set to value 0x0 by */ 00916 /* setting of trigger source to SW start. */ 00917 ADC_REG_InitStruct->TriggerSource = LL_ADC_REG_TRIG_SOFTWARE; 00918 ADC_REG_InitStruct->SequencerLength = LL_ADC_REG_SEQ_SCAN_DISABLE; 00919 ADC_REG_InitStruct->SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE; 00920 ADC_REG_InitStruct->ContinuousMode = LL_ADC_REG_CONV_SINGLE; 00921 ADC_REG_InitStruct->DMATransfer = LL_ADC_REG_DMA_TRANSFER_NONE; 00922 ADC_REG_InitStruct->Overrun = LL_ADC_REG_OVR_DATA_OVERWRITTEN; 00923 } 00924 00925 /** 00926 * @brief Initialize some features of ADC group injected. 00927 * @note These parameters have an impact on ADC scope: ADC group injected. 00928 * Refer to corresponding unitary functions into 00929 * @ref ADC_LL_EF_Configuration_ADC_Group_Regular 00930 * (functions with prefix "INJ"). 00931 * @note The setting of these parameters by function @ref LL_ADC_Init() 00932 * is conditioned to ADC state: 00933 * ADC instance must be disabled. 00934 * This condition is applied to all ADC features, for efficiency 00935 * and compatibility over all STM32 families. However, the different 00936 * features can be set under different ADC state conditions 00937 * (setting possible with ADC enabled without conversion on going, 00938 * ADC enabled with conversion on going, ...) 00939 * Each feature can be updated afterwards with a unitary function 00940 * and potentially with ADC in a different state than disabled, 00941 * refer to description of each function for setting 00942 * conditioned to ADC state. 00943 * @note After using this function, other features must be configured 00944 * using LL unitary functions. 00945 * The minimum configuration remaining to be done is: 00946 * - Set ADC group injected sequencer: 00947 * map channel on the selected sequencer rank. 00948 * Refer to function @ref LL_ADC_INJ_SetSequencerRanks(). 00949 * - Set ADC channel sampling time 00950 * Refer to function LL_ADC_SetChannelSamplingTime(); 00951 * @note Caution if feature ADC group injected contexts queue is enabled 00952 * (refer to with function @ref LL_ADC_INJ_SetQueueMode() ): 00953 * using successively several times this function will appear as 00954 * having no effect. 00955 * To set several features of ADC group injected, use 00956 * function @ref LL_ADC_INJ_ConfigQueueContext(). 00957 * @param ADCx ADC instance 00958 * @param ADC_INJ_InitStruct Pointer to a @ref LL_ADC_INJ_InitTypeDef structure 00959 * @retval An ErrorStatus enumeration value: 00960 * - SUCCESS: ADC registers are initialized 00961 * - ERROR: ADC registers are not initialized 00962 */ 00963 ErrorStatus LL_ADC_INJ_Init(ADC_TypeDef *ADCx, LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct) 00964 { 00965 ErrorStatus status = SUCCESS; 00966 00967 /* Check the parameters */ 00968 assert_param(IS_ADC_ALL_INSTANCE(ADCx)); 00969 assert_param(IS_LL_ADC_INJ_TRIG_SOURCE(ADC_INJ_InitStruct->TriggerSource)); 00970 assert_param(IS_LL_ADC_INJ_SEQ_SCAN_LENGTH(ADC_INJ_InitStruct->SequencerLength)); 00971 if (ADC_INJ_InitStruct->SequencerLength != LL_ADC_INJ_SEQ_SCAN_DISABLE) 00972 { 00973 assert_param(IS_LL_ADC_INJ_SEQ_SCAN_DISCONT_MODE(ADC_INJ_InitStruct->SequencerDiscont)); 00974 } 00975 assert_param(IS_LL_ADC_INJ_TRIG_AUTO(ADC_INJ_InitStruct->TrigAuto)); 00976 00977 /* Note: Hardware constraint (refer to description of this function): */ 00978 /* ADC instance must be disabled. */ 00979 if (LL_ADC_IsEnabled(ADCx) == 0UL) 00980 { 00981 /* Configuration of ADC hierarchical scope: */ 00982 /* - ADC group injected */ 00983 /* - Set ADC group injected trigger source */ 00984 /* - Set ADC group injected sequencer length */ 00985 /* - Set ADC group injected sequencer discontinuous mode */ 00986 /* - Set ADC group injected conversion trigger: independent or */ 00987 /* from ADC group regular */ 00988 /* Note: On this STM32 series, ADC trigger edge is set to value 0x0 by */ 00989 /* setting of trigger source to SW start. */ 00990 if (ADC_INJ_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE) 00991 { 00992 MODIFY_REG(ADCx->CFGR, 00993 ADC_CFGR_JDISCEN 00994 | ADC_CFGR_JAUTO 00995 , 00996 ADC_INJ_InitStruct->SequencerDiscont 00997 | ADC_INJ_InitStruct->TrigAuto 00998 ); 00999 } 01000 else 01001 { 01002 MODIFY_REG(ADCx->CFGR, 01003 ADC_CFGR_JDISCEN 01004 | ADC_CFGR_JAUTO 01005 , 01006 LL_ADC_REG_SEQ_DISCONT_DISABLE 01007 | ADC_INJ_InitStruct->TrigAuto 01008 ); 01009 } 01010 01011 MODIFY_REG(ADCx->JSQR, 01012 ADC_JSQR_JEXTSEL 01013 | ADC_JSQR_JEXTEN 01014 | ADC_JSQR_JL 01015 , 01016 ADC_INJ_InitStruct->TriggerSource 01017 | ADC_INJ_InitStruct->SequencerLength 01018 ); 01019 } 01020 else 01021 { 01022 /* Initialization error: ADC instance is not disabled. */ 01023 status = ERROR; 01024 } 01025 return status; 01026 } 01027 01028 /** 01029 * @brief Set each @ref LL_ADC_INJ_InitTypeDef field to default value. 01030 * @param ADC_INJ_InitStruct Pointer to a @ref LL_ADC_INJ_InitTypeDef structure 01031 * whose fields will be set to default values. 01032 * @retval None 01033 */ 01034 void LL_ADC_INJ_StructInit(LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct) 01035 { 01036 /* Set ADC_INJ_InitStruct fields to default values */ 01037 /* Set fields of ADC group injected */ 01038 ADC_INJ_InitStruct->TriggerSource = LL_ADC_INJ_TRIG_SOFTWARE; 01039 ADC_INJ_InitStruct->SequencerLength = LL_ADC_INJ_SEQ_SCAN_DISABLE; 01040 ADC_INJ_InitStruct->SequencerDiscont = LL_ADC_INJ_SEQ_DISCONT_DISABLE; 01041 ADC_INJ_InitStruct->TrigAuto = LL_ADC_INJ_TRIG_INDEPENDENT; 01042 } 01043 01044 /** 01045 * @} 01046 */ 01047 01048 /** 01049 * @} 01050 */ 01051 01052 /** 01053 * @} 01054 */ 01055 01056 #endif /* ADC1 || ADC2 || ADC3 */ 01057 01058 /** 01059 * @} 01060 */ 01061 01062 #endif /* USE_FULL_LL_DRIVER */