STM32L4xx_HAL_Driver  1.14.0
ADC Input and Output operation functions

ADC IO operation functions. More...

Functions

HAL_StatusTypeDef HAL_ADC_Start (ADC_HandleTypeDef *hadc)
 Enable ADC, start conversion of regular group. More...
 
HAL_StatusTypeDef HAL_ADC_Stop (ADC_HandleTypeDef *hadc)
 Stop ADC conversion of regular group (and injected channels in case of auto_injection mode), disable ADC peripheral. More...
 
HAL_StatusTypeDef HAL_ADC_PollForConversion (ADC_HandleTypeDef *hadc, uint32_t Timeout)
 Wait for regular group conversion to be completed. More...
 
HAL_StatusTypeDef HAL_ADC_PollForEvent (ADC_HandleTypeDef *hadc, uint32_t EventType, uint32_t Timeout)
 Poll for ADC event. More...
 
HAL_StatusTypeDef HAL_ADC_Start_IT (ADC_HandleTypeDef *hadc)
 Enable ADC, start conversion of regular group with interruption. More...
 
HAL_StatusTypeDef HAL_ADC_Stop_IT (ADC_HandleTypeDef *hadc)
 Stop ADC conversion of regular group (and injected group in case of auto_injection mode), disable interrution of end-of-conversion, disable ADC peripheral. More...
 
HAL_StatusTypeDef HAL_ADC_Start_DMA (ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length)
 Enable ADC, start conversion of regular group and transfer result through DMA. More...
 
HAL_StatusTypeDef HAL_ADC_Stop_DMA (ADC_HandleTypeDef *hadc)
 Stop ADC conversion of regular group (and injected group in case of auto_injection mode), disable ADC DMA transfer, disable ADC peripheral. More...
 
uint32_t HAL_ADC_GetValue (ADC_HandleTypeDef *hadc)
 Get ADC regular group conversion result. More...
 
void HAL_ADC_IRQHandler (ADC_HandleTypeDef *hadc)
 Handle ADC interrupt request. More...
 
void HAL_ADC_ConvCpltCallback (ADC_HandleTypeDef *hadc)
 Conversion complete callback in non-blocking mode. More...
 
void HAL_ADC_ConvHalfCpltCallback (ADC_HandleTypeDef *hadc)
 Conversion DMA half-transfer callback in non-blocking mode. More...
 
void HAL_ADC_LevelOutOfWindowCallback (ADC_HandleTypeDef *hadc)
 Analog watchdog 1 callback in non-blocking mode. More...
 
void HAL_ADC_ErrorCallback (ADC_HandleTypeDef *hadc)
 ADC error callback in non-blocking mode (ADC conversion with interruption or transfer by DMA). More...
 

Detailed Description

ADC IO operation functions.

IO operation functions.

 ===============================================================================
                      ##### IO operation functions #####
 ===============================================================================
    [..]  This section provides functions allowing to:
      (+) Start conversion of regular group.
      (+) Stop conversion of regular group.
      (+) Poll for conversion complete on regular group.
      (+) Poll for conversion event.
      (+) Get result of regular channel conversion.
      (+) Start conversion of regular group and enable interruptions.
      (+) Stop conversion of regular group and disable interruptions.
      (+) Handle ADC interrupt request
      (+) Start conversion of regular group and enable DMA transfer.
      (+) Stop conversion of regular group and disable ADC DMA transfer.

Function Documentation

◆ HAL_ADC_ConvCpltCallback()

__weak void HAL_ADC_ConvCpltCallback ( ADC_HandleTypeDef hadc)

Conversion complete callback in non-blocking mode.

Parameters
hadcADC handle
Return values
None

Definition at line 2601 of file stm32l4xx_hal_adc.c.

2602 {
2603  /* Prevent unused argument(s) compilation warning */
2604  UNUSED(hadc);
2605 
2606  /* NOTE : This function should not be modified. When the callback is needed,
2607  function HAL_ADC_ConvCpltCallback must be implemented in the user file.
2608  */
2609 }

◆ HAL_ADC_ConvHalfCpltCallback()

__weak void HAL_ADC_ConvHalfCpltCallback ( ADC_HandleTypeDef hadc)

Conversion DMA half-transfer callback in non-blocking mode.

Parameters
hadcADC handle
Return values
None

Definition at line 2616 of file stm32l4xx_hal_adc.c.

2617 {
2618  /* Prevent unused argument(s) compilation warning */
2619  UNUSED(hadc);
2620 
2621  /* NOTE : This function should not be modified. When the callback is needed,
2622  function HAL_ADC_ConvHalfCpltCallback must be implemented in the user file.
2623  */
2624 }

◆ HAL_ADC_ErrorCallback()

__weak void HAL_ADC_ErrorCallback ( ADC_HandleTypeDef hadc)

ADC error callback in non-blocking mode (ADC conversion with interruption or transfer by DMA).

Note
In case of error due to overrun when using ADC with DMA transfer (HAL ADC handle parameter "ErrorCode" to state "HAL_ADC_ERROR_OVR"):
  • Reinitialize the DMA using function "HAL_ADC_Stop_DMA()".
  • If needed, restart a new ADC conversion using function "HAL_ADC_Start_DMA()" (this function is also clearing overrun flag)
Parameters
hadcADC handle
Return values
None

Definition at line 2653 of file stm32l4xx_hal_adc.c.

2654 {
2655  /* Prevent unused argument(s) compilation warning */
2656  UNUSED(hadc);
2657 
2658  /* NOTE : This function should not be modified. When the callback is needed,
2659  function HAL_ADC_ErrorCallback must be implemented in the user file.
2660  */
2661 }

◆ HAL_ADC_GetValue()

uint32_t HAL_ADC_GetValue ( ADC_HandleTypeDef hadc)

Get ADC regular group conversion result.

Note
Reading register DR automatically clears ADC flag EOC (ADC group regular end of unitary conversion).
This function does not clear ADC flag EOS (ADC group regular end of sequence conversion). Occurrence of flag EOS rising:
  • If sequencer is composed of 1 rank, flag EOS is equivalent to flag EOC.
  • If sequencer is composed of several ranks, during the scan sequence flag EOC only is raised, at the end of the scan sequence both flags EOC and EOS are raised. To clear this flag, either use function: in programming model IT: HAL_ADC_IRQHandler(), in programming model polling: HAL_ADC_PollForConversion() or __HAL_ADC_CLEAR_FLAG(&hadc, ADC_FLAG_EOS).
Parameters
hadcADC handle
Return values
ADCgroup regular conversion data

Definition at line 2214 of file stm32l4xx_hal_adc.c.

2215 {
2216  /* Check the parameters */
2217  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
2218 
2219  /* Note: EOC flag is not cleared here by software because automatically */
2220  /* cleared by hardware when reading register DR. */
2221 
2222  /* Return ADC converted value */
2223  return hadc->Instance->DR;
2224 }
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_ADC_IRQHandler()

void HAL_ADC_IRQHandler ( ADC_HandleTypeDef hadc)

Handle ADC interrupt request.

Parameters
hadcADC handle
Return values
None

Definition at line 2231 of file stm32l4xx_hal_adc.c.

2232 {
2233  uint32_t overrun_error = 0UL; /* flag set if overrun occurrence has to be considered as an error */
2234  uint32_t tmp_isr = hadc->Instance->ISR;
2235  uint32_t tmp_ier = hadc->Instance->IER;
2236  uint32_t tmp_adc_inj_is_trigger_source_sw_start;
2237  uint32_t tmp_adc_reg_is_trigger_source_sw_start;
2238  uint32_t tmp_cfgr;
2239 #if defined(ADC_MULTIMODE_SUPPORT)
2240  const ADC_TypeDef *tmpADC_Master;
2241  uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
2242 #endif
2243 
2244  /* Check the parameters */
2245  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
2246  assert_param(IS_ADC_EOC_SELECTION(hadc->Init.EOCSelection));
2247 
2248  /* ========== Check End of Sampling flag for ADC group regular ========== */
2249  if (((tmp_isr & ADC_FLAG_EOSMP) == ADC_FLAG_EOSMP) && ((tmp_ier & ADC_IT_EOSMP) == ADC_IT_EOSMP))
2250  {
2251  /* Update state machine on end of sampling status if not in error state */
2252  if ((hadc->State & HAL_ADC_STATE_ERROR_INTERNAL) == 0UL)
2253  {
2254  /* Set ADC state */
2255  SET_BIT(hadc->State, HAL_ADC_STATE_REG_EOSMP);
2256  }
2257 
2258  /* End Of Sampling callback */
2259 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
2260  hadc->EndOfSamplingCallback(hadc);
2261 #else
2263 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
2264 
2265  /* Clear regular group conversion flag */
2266  __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_EOSMP);
2267  }
2268 
2269  /* ====== Check ADC group regular end of unitary conversion sequence conversions ===== */
2270  if ((((tmp_isr & ADC_FLAG_EOC) == ADC_FLAG_EOC) && ((tmp_ier & ADC_IT_EOC) == ADC_IT_EOC)) ||
2271  (((tmp_isr & ADC_FLAG_EOS) == ADC_FLAG_EOS) && ((tmp_ier & ADC_IT_EOS) == ADC_IT_EOS)))
2272  {
2273  /* Update state machine on conversion status if not in error state */
2274  if ((hadc->State & HAL_ADC_STATE_ERROR_INTERNAL) == 0UL)
2275  {
2276  /* Set ADC state */
2277  SET_BIT(hadc->State, HAL_ADC_STATE_REG_EOC);
2278  }
2279 
2280  /* Determine whether any further conversion upcoming on group regular */
2281  /* by external trigger, continuous mode or scan sequence on going */
2282  /* to disable interruption. */
2283  if (LL_ADC_REG_IsTriggerSourceSWStart(hadc->Instance) != 0UL)
2284  {
2285  /* Get relevant register CFGR in ADC instance of ADC master or slave */
2286  /* in function of multimode state (for devices with multimode */
2287  /* available). */
2288 #if defined(ADC_MULTIMODE_SUPPORT)
2289  if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
2290  || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
2291  || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_SIMULT)
2292  || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_ALTERN)
2293  )
2294  {
2295  /* check CONT bit directly in handle ADC CFGR register */
2296  tmp_cfgr = READ_REG(hadc->Instance->CFGR);
2297  }
2298  else
2299  {
2300  /* else need to check Master ADC CONT bit */
2301  tmpADC_Master = __LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance);
2302  tmp_cfgr = READ_REG(tmpADC_Master->CFGR);
2303  }
2304 #else
2305  tmp_cfgr = READ_REG(hadc->Instance->CFGR);
2306 #endif
2307 
2308  /* Carry on if continuous mode is disabled */
2309  if (READ_BIT(tmp_cfgr, ADC_CFGR_CONT) != ADC_CFGR_CONT)
2310  {
2311  /* If End of Sequence is reached, disable interrupts */
2312  if (__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_EOS))
2313  {
2314  /* Allowed to modify bits ADC_IT_EOC/ADC_IT_EOS only if bit */
2315  /* ADSTART==0 (no conversion on going) */
2316  if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL)
2317  {
2318  /* Disable ADC end of sequence conversion interrupt */
2319  /* Note: Overrun interrupt was enabled with EOC interrupt in */
2320  /* HAL_Start_IT(), but is not disabled here because can be used */
2321  /* by overrun IRQ process below. */
2322  __HAL_ADC_DISABLE_IT(hadc, ADC_IT_EOC | ADC_IT_EOS);
2323 
2324  /* Set ADC state */
2325  CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY);
2326 
2327  if ((hadc->State & HAL_ADC_STATE_INJ_BUSY) == 0UL)
2328  {
2329  SET_BIT(hadc->State, HAL_ADC_STATE_READY);
2330  }
2331  }
2332  else
2333  {
2334  /* Change ADC state to error state */
2335  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
2336 
2337  /* Set ADC error code to ADC peripheral internal error */
2338  SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL);
2339  }
2340  }
2341  }
2342  }
2343 
2344  /* Conversion complete callback */
2345  /* Note: Into callback function "HAL_ADC_ConvCpltCallback()", */
2346  /* to determine if conversion has been triggered from EOC or EOS, */
2347  /* possibility to use: */
2348  /* " if( __HAL_ADC_GET_FLAG(&hadc, ADC_FLAG_EOS)) " */
2349 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
2350  hadc->ConvCpltCallback(hadc);
2351 #else
2353 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
2354 
2355  /* Clear regular group conversion flag */
2356  /* Note: in case of overrun set to ADC_OVR_DATA_PRESERVED, end of */
2357  /* conversion flags clear induces the release of the preserved data.*/
2358  /* Therefore, if the preserved data value is needed, it must be */
2359  /* read preliminarily into HAL_ADC_ConvCpltCallback(). */
2360  __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_EOC | ADC_FLAG_EOS));
2361  }
2362 
2363  /* ====== Check ADC group injected end of unitary conversion sequence conversions ===== */
2364  if ((((tmp_isr & ADC_FLAG_JEOC) == ADC_FLAG_JEOC) && ((tmp_ier & ADC_IT_JEOC) == ADC_IT_JEOC)) ||
2365  (((tmp_isr & ADC_FLAG_JEOS) == ADC_FLAG_JEOS) && ((tmp_ier & ADC_IT_JEOS) == ADC_IT_JEOS)))
2366  {
2367  /* Update state machine on conversion status if not in error state */
2368  if ((hadc->State & HAL_ADC_STATE_ERROR_INTERNAL) == 0UL)
2369  {
2370  /* Set ADC state */
2371  SET_BIT(hadc->State, HAL_ADC_STATE_INJ_EOC);
2372  }
2373 
2374  /* Retrieve ADC configuration */
2375  tmp_adc_inj_is_trigger_source_sw_start = LL_ADC_INJ_IsTriggerSourceSWStart(hadc->Instance);
2376  tmp_adc_reg_is_trigger_source_sw_start = LL_ADC_REG_IsTriggerSourceSWStart(hadc->Instance);
2377  /* Get relevant register CFGR in ADC instance of ADC master or slave */
2378  /* in function of multimode state (for devices with multimode */
2379  /* available). */
2380 #if defined(ADC_MULTIMODE_SUPPORT)
2381  if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
2382  || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
2383  || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_SIMULT)
2384  || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_INTERL)
2385  )
2386  {
2387  tmp_cfgr = READ_REG(hadc->Instance->CFGR);
2388  }
2389  else
2390  {
2391  tmpADC_Master = __LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance);
2392  tmp_cfgr = READ_REG(tmpADC_Master->CFGR);
2393  }
2394 #else
2395  tmp_cfgr = READ_REG(hadc->Instance->CFGR);
2396 #endif
2397 
2398  /* Disable interruption if no further conversion upcoming by injected */
2399  /* external trigger or by automatic injected conversion with regular */
2400  /* group having no further conversion upcoming (same conditions as */
2401  /* regular group interruption disabling above), */
2402  /* and if injected scan sequence is completed. */
2403  if ((tmp_adc_inj_is_trigger_source_sw_start != 0UL) ||
2404  ((READ_BIT(tmp_cfgr, ADC_CFGR_JAUTO) == 0UL) &&
2405  ((tmp_adc_reg_is_trigger_source_sw_start != 0UL) &&
2406  (READ_BIT(tmp_cfgr, ADC_CFGR_CONT) == 0UL))))
2407  {
2408  /* If End of Sequence is reached, disable interrupts */
2409  if (__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_JEOS))
2410  {
2411  /* Particular case if injected contexts queue is enabled: */
2412  /* when the last context has been fully processed, JSQR is reset */
2413  /* by the hardware. Even if no injected conversion is planned to come */
2414  /* (queue empty, triggers are ignored), it can start again */
2415  /* immediately after setting a new context (JADSTART is still set). */
2416  /* Therefore, state of HAL ADC injected group is kept to busy. */
2417  if (READ_BIT(tmp_cfgr, ADC_CFGR_JQM) == 0UL)
2418  {
2419  /* Allowed to modify bits ADC_IT_JEOC/ADC_IT_JEOS only if bit */
2420  /* JADSTART==0 (no conversion on going) */
2421  if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL)
2422  {
2423  /* Disable ADC end of sequence conversion interrupt */
2424  __HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOC | ADC_IT_JEOS);
2425 
2426  /* Set ADC state */
2427  CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
2428 
2429  if ((hadc->State & HAL_ADC_STATE_REG_BUSY) == 0UL)
2430  {
2431  SET_BIT(hadc->State, HAL_ADC_STATE_READY);
2432  }
2433  }
2434  else
2435  {
2436  /* Update ADC state machine to error */
2437  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
2438 
2439  /* Set ADC error code to ADC peripheral internal error */
2440  SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL);
2441  }
2442  }
2443  }
2444  }
2445 
2446  /* Injected Conversion complete callback */
2447  /* Note: HAL_ADCEx_InjectedConvCpltCallback can resort to
2448  if( __HAL_ADC_GET_FLAG(&hadc, ADC_FLAG_JEOS)) or
2449  if( __HAL_ADC_GET_FLAG(&hadc, ADC_FLAG_JEOC)) to determine whether
2450  interruption has been triggered by end of conversion or end of
2451  sequence. */
2452 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
2453  hadc->InjectedConvCpltCallback(hadc);
2454 #else
2456 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
2457 
2458  /* Clear injected group conversion flag */
2459  __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_JEOC | ADC_FLAG_JEOS);
2460  }
2461 
2462  /* ========== Check Analog watchdog 1 flag ========== */
2463  if (((tmp_isr & ADC_FLAG_AWD1) == ADC_FLAG_AWD1) && ((tmp_ier & ADC_IT_AWD1) == ADC_IT_AWD1))
2464  {
2465  /* Set ADC state */
2466  SET_BIT(hadc->State, HAL_ADC_STATE_AWD1);
2467 
2468  /* Level out of window 1 callback */
2469 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
2470  hadc->LevelOutOfWindowCallback(hadc);
2471 #else
2473 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
2474 
2475  /* Clear ADC analog watchdog flag */
2476  __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_AWD1);
2477  }
2478 
2479  /* ========== Check analog watchdog 2 flag ========== */
2480  if (((tmp_isr & ADC_FLAG_AWD2) == ADC_FLAG_AWD2) && ((tmp_ier & ADC_IT_AWD2) == ADC_IT_AWD2))
2481  {
2482  /* Set ADC state */
2483  SET_BIT(hadc->State, HAL_ADC_STATE_AWD2);
2484 
2485  /* Level out of window 2 callback */
2486 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
2487  hadc->LevelOutOfWindow2Callback(hadc);
2488 #else
2490 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
2491 
2492  /* Clear ADC analog watchdog flag */
2493  __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_AWD2);
2494  }
2495 
2496  /* ========== Check analog watchdog 3 flag ========== */
2497  if (((tmp_isr & ADC_FLAG_AWD3) == ADC_FLAG_AWD3) && ((tmp_ier & ADC_IT_AWD3) == ADC_IT_AWD3))
2498  {
2499  /* Set ADC state */
2500  SET_BIT(hadc->State, HAL_ADC_STATE_AWD3);
2501 
2502  /* Level out of window 3 callback */
2503 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
2504  hadc->LevelOutOfWindow3Callback(hadc);
2505 #else
2507 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
2508 
2509  /* Clear ADC analog watchdog flag */
2510  __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_AWD3);
2511  }
2512 
2513  /* ========== Check Overrun flag ========== */
2514  if (((tmp_isr & ADC_FLAG_OVR) == ADC_FLAG_OVR) && ((tmp_ier & ADC_IT_OVR) == ADC_IT_OVR))
2515  {
2516  /* If overrun is set to overwrite previous data (default setting), */
2517  /* overrun event is not considered as an error. */
2518  /* (cf ref manual "Managing conversions without using the DMA and without */
2519  /* overrun ") */
2520  /* Exception for usage with DMA overrun event always considered as an */
2521  /* error. */
2522  if (hadc->Init.Overrun == ADC_OVR_DATA_PRESERVED)
2523  {
2524  overrun_error = 1UL;
2525  }
2526  else
2527  {
2528  /* Check DMA configuration */
2529 #if defined(ADC_MULTIMODE_SUPPORT)
2530  if (tmp_multimode_config != LL_ADC_MULTI_INDEPENDENT)
2531  {
2532  /* Multimode (when feature is available) is enabled,
2533  Common Control Register MDMA bits must be checked. */
2534  if (LL_ADC_GetMultiDMATransfer(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) != LL_ADC_MULTI_REG_DMA_EACH_ADC)
2535  {
2536  overrun_error = 1UL;
2537  }
2538  }
2539  else
2540 #endif
2541  {
2542  /* Multimode not set or feature not available or ADC independent */
2543  if ((hadc->Instance->CFGR & ADC_CFGR_DMAEN) != 0UL)
2544  {
2545  overrun_error = 1UL;
2546  }
2547  }
2548  }
2549 
2550  if (overrun_error == 1UL)
2551  {
2552  /* Change ADC state to error state */
2553  SET_BIT(hadc->State, HAL_ADC_STATE_REG_OVR);
2554 
2555  /* Set ADC error code to overrun */
2556  SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_OVR);
2557 
2558  /* Error callback */
2559  /* Note: In case of overrun, ADC conversion data is preserved until */
2560  /* flag OVR is reset. */
2561  /* Therefore, old ADC conversion data can be retrieved in */
2562  /* function "HAL_ADC_ErrorCallback()". */
2563 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
2564  hadc->ErrorCallback(hadc);
2565 #else
2566  HAL_ADC_ErrorCallback(hadc);
2567 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
2568  }
2569 
2570  /* Clear ADC overrun flag */
2571  __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_OVR);
2572  }
2573 
2574  /* ========== Check Injected context queue overflow flag ========== */
2575  if (((tmp_isr & ADC_FLAG_JQOVF) == ADC_FLAG_JQOVF) && ((tmp_ier & ADC_IT_JQOVF) == ADC_IT_JQOVF))
2576  {
2577  /* Change ADC state to overrun state */
2578  SET_BIT(hadc->State, HAL_ADC_STATE_INJ_JQOVF);
2579 
2580  /* Set ADC error code to Injected context queue overflow */
2581  SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_JQOVF);
2582 
2583  /* Clear the Injected context queue overflow flag */
2584  __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_JQOVF);
2585 
2586  /* Injected context queue overflow callback */
2587 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
2588  hadc->InjectedQueueOverflowCallback(hadc);
2589 #else
2591 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
2592  }
2593 
2594 }
__STATIC_INLINE uint32_t LL_ADC_REG_IsTriggerSourceSWStart(ADC_TypeDef *ADCx)
Get ADC group regular conversion trigger source internal (SW start) or external.
void HAL_ADCEx_LevelOutOfWindow2Callback(ADC_HandleTypeDef *hadc)
Analog watchdog 2 callback in non-blocking mode.
void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef *hadc)
Injected conversion complete callback in non-blocking mode.
__STATIC_INLINE uint32_t LL_ADC_GetMultimode(ADC_Common_TypeDef *ADCxy_COMMON)
Get ADC multimode configuration to operate in independent mode or multimode (for devices with several...
void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc)
ADC error callback in non-blocking mode (ADC conversion with interruption or transfer by DMA)...
void HAL_ADCEx_InjectedQueueOverflowCallback(ADC_HandleTypeDef *hadc)
Injected context queue overflow callback.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)
Conversion complete callback in non-blocking mode.
__STATIC_INLINE uint32_t LL_ADC_INJ_IsConversionOngoing(ADC_TypeDef *ADCx)
Get ADC group injected conversion state. CR JADSTART LL_ADC_INJ_IsConversionOngoing.
void HAL_ADCEx_EndOfSamplingCallback(ADC_HandleTypeDef *hadc)
End Of Sampling callback in non-blocking mode.
__STATIC_INLINE uint32_t LL_ADC_GetMultiDMATransfer(ADC_Common_TypeDef *ADCxy_COMMON)
Get ADC multimode conversion data transfer: no transfer or transfer by DMA.
void HAL_ADCEx_LevelOutOfWindow3Callback(ADC_HandleTypeDef *hadc)
Analog watchdog 3 callback in non-blocking mode.
__STATIC_INLINE uint32_t LL_ADC_INJ_IsTriggerSourceSWStart(ADC_TypeDef *ADCx)
Get ADC group injected conversion trigger source internal (SW start) or external. ...
__STATIC_INLINE uint32_t LL_ADC_REG_IsConversionOngoing(ADC_TypeDef *ADCx)
Get ADC group regular conversion state. CR ADSTART LL_ADC_REG_IsConversionOngoing.
void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef *hadc)
Analog watchdog 1 callback in non-blocking mode.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_ADC_LevelOutOfWindowCallback()

__weak void HAL_ADC_LevelOutOfWindowCallback ( ADC_HandleTypeDef hadc)

Analog watchdog 1 callback in non-blocking mode.

Parameters
hadcADC handle
Return values
None

Definition at line 2631 of file stm32l4xx_hal_adc.c.

2632 {
2633  /* Prevent unused argument(s) compilation warning */
2634  UNUSED(hadc);
2635 
2636  /* NOTE : This function should not be modified. When the callback is needed,
2637  function HAL_ADC_LevelOutOfWindowCallback must be implemented in the user file.
2638  */
2639 }

◆ HAL_ADC_PollForConversion()

HAL_StatusTypeDef HAL_ADC_PollForConversion ( ADC_HandleTypeDef hadc,
uint32_t  Timeout 
)

Wait for regular group conversion to be completed.

Note
ADC conversion flags EOS (end of sequence) and EOC (end of conversion) are cleared by this function, with an exception: if low power feature "LowPowerAutoWait" is enabled, flags are not cleared to not interfere with this feature until data register is read using function HAL_ADC_GetValue().
This function cannot be used in a particular setup: ADC configured in DMA mode and polling for end of each conversion (ADC init parameter "EOCSelection" set to ADC_EOC_SINGLE_CONV). In this case, DMA resets the flag EOC and polling cannot be performed on each conversion. Nevertheless, polling can still be performed on the complete sequence (ADC init parameter "EOCSelection" set to ADC_EOC_SEQ_CONV).
Parameters
hadcADC handle
TimeoutTimeout value in millisecond.
Return values
HALstatus

Definition at line 1404 of file stm32l4xx_hal_adc.c.

1405 {
1406  uint32_t tickstart;
1407  uint32_t tmp_Flag_End;
1408  uint32_t tmp_cfgr;
1409 #if defined(ADC_MULTIMODE_SUPPORT)
1410  const ADC_TypeDef *tmpADC_Master;
1411  uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
1412 #endif
1413 
1414  /* Check the parameters */
1415  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1416 
1417  /* If end of conversion selected to end of sequence conversions */
1418  if (hadc->Init.EOCSelection == ADC_EOC_SEQ_CONV)
1419  {
1420  tmp_Flag_End = ADC_FLAG_EOS;
1421  }
1422  /* If end of conversion selected to end of unitary conversion */
1423  else /* ADC_EOC_SINGLE_CONV */
1424  {
1425  /* Verification that ADC configuration is compliant with polling for */
1426  /* each conversion: */
1427  /* Particular case is ADC configured in DMA mode and ADC sequencer with */
1428  /* several ranks and polling for end of each conversion. */
1429  /* For code simplicity sake, this particular case is generalized to */
1430  /* ADC configured in DMA mode and and polling for end of each conversion. */
1431 #if defined(ADC_MULTIMODE_SUPPORT)
1432  if ((tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
1433  || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_SIMULT)
1434  || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_ALTERN)
1435  )
1436  {
1437  /* Check ADC DMA mode in independent mode on ADC group regular */
1438  if (READ_BIT(hadc->Instance->CFGR, ADC_CFGR_DMAEN) != 0UL)
1439  {
1440  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
1441  return HAL_ERROR;
1442  }
1443  else
1444  {
1445  tmp_Flag_End = (ADC_FLAG_EOC);
1446  }
1447  }
1448  else
1449  {
1450  /* Check ADC DMA mode in multimode on ADC group regular */
1451  if (LL_ADC_GetMultiDMATransfer(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) != LL_ADC_MULTI_REG_DMA_EACH_ADC)
1452  {
1453  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
1454  return HAL_ERROR;
1455  }
1456  else
1457  {
1458  tmp_Flag_End = (ADC_FLAG_EOC);
1459  }
1460  }
1461 #else
1462  /* Check ADC DMA mode */
1463  if (READ_BIT(hadc->Instance->CFGR, ADC_CFGR_DMAEN) != 0UL)
1464  {
1465  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
1466  return HAL_ERROR;
1467  }
1468  else
1469  {
1470  tmp_Flag_End = (ADC_FLAG_EOC);
1471  }
1472 #endif
1473  }
1474 
1475  /* Get tick count */
1476  tickstart = HAL_GetTick();
1477 
1478  /* Wait until End of unitary conversion or sequence conversions flag is raised */
1479  while ((hadc->Instance->ISR & tmp_Flag_End) == 0UL)
1480  {
1481  /* Check if timeout is disabled (set to infinite wait) */
1482  if (Timeout != HAL_MAX_DELAY)
1483  {
1484  if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0UL))
1485  {
1486  /* Update ADC state machine to timeout */
1487  SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT);
1488 
1489  /* Process unlocked */
1490  __HAL_UNLOCK(hadc);
1491 
1492  return HAL_TIMEOUT;
1493  }
1494  }
1495  }
1496 
1497  /* Update ADC state machine */
1498  SET_BIT(hadc->State, HAL_ADC_STATE_REG_EOC);
1499 
1500  /* Determine whether any further conversion upcoming on group regular */
1501  /* by external trigger, continuous mode or scan sequence on going. */
1502  if ((LL_ADC_REG_IsTriggerSourceSWStart(hadc->Instance) != 0UL)
1503  && (hadc->Init.ContinuousConvMode == DISABLE)
1504  )
1505  {
1506  /* Check whether end of sequence is reached */
1507  if (__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_EOS))
1508  {
1509  /* Set ADC state */
1510  CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY);
1511 
1512  if ((hadc->State & HAL_ADC_STATE_INJ_BUSY) == 0UL)
1513  {
1514  SET_BIT(hadc->State, HAL_ADC_STATE_READY);
1515  }
1516  }
1517  }
1518 
1519  /* Get relevant register CFGR in ADC instance of ADC master or slave */
1520  /* in function of multimode state (for devices with multimode */
1521  /* available). */
1522 #if defined(ADC_MULTIMODE_SUPPORT)
1523  if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
1524  || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
1525  || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_SIMULT)
1526  || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_ALTERN)
1527  )
1528  {
1529  /* Retrieve handle ADC CFGR register */
1530  tmp_cfgr = READ_REG(hadc->Instance->CFGR);
1531  }
1532  else
1533  {
1534  /* Retrieve Master ADC CFGR register */
1535  tmpADC_Master = __LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance);
1536  tmp_cfgr = READ_REG(tmpADC_Master->CFGR);
1537  }
1538 #else
1539  /* Retrieve handle ADC CFGR register */
1540  tmp_cfgr = READ_REG(hadc->Instance->CFGR);
1541 #endif
1542 
1543  /* Clear polled flag */
1544  if (tmp_Flag_End == ADC_FLAG_EOS)
1545  {
1546  __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_EOS);
1547  }
1548  else
1549  {
1550  /* Clear end of conversion EOC flag of regular group if low power feature */
1551  /* "LowPowerAutoWait " is disabled, to not interfere with this feature */
1552  /* until data register is read using function HAL_ADC_GetValue(). */
1553  if (READ_BIT(tmp_cfgr, ADC_CFGR_AUTDLY) == 0UL)
1554  {
1555  __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_EOC | ADC_FLAG_EOS));
1556  }
1557  }
1558 
1559  /* Return function status */
1560  return HAL_OK;
1561 }
__STATIC_INLINE uint32_t LL_ADC_REG_IsTriggerSourceSWStart(ADC_TypeDef *ADCx)
Get ADC group regular conversion trigger source internal (SW start) or external.
__STATIC_INLINE uint32_t LL_ADC_GetMultimode(ADC_Common_TypeDef *ADCxy_COMMON)
Get ADC multimode configuration to operate in independent mode or multimode (for devices with several...
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
return HAL_OK
__STATIC_INLINE uint32_t LL_ADC_GetMultiDMATransfer(ADC_Common_TypeDef *ADCxy_COMMON)
Get ADC multimode conversion data transfer: no transfer or transfer by DMA.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_ADC_PollForEvent()

HAL_StatusTypeDef HAL_ADC_PollForEvent ( ADC_HandleTypeDef hadc,
uint32_t  EventType,
uint32_t  Timeout 
)

Poll for ADC event.

Parameters
hadcADC handle
EventTypethe ADC event type. This parameter can be one of the following values:
  • ADC_EOSMP_EVENT ADC End of Sampling event
  • ADC_AWD1_EVENT ADC Analog watchdog 1 event (main analog watchdog, present on all STM32 devices)
  • ADC_AWD2_EVENT ADC Analog watchdog 2 event (additional analog watchdog, not present on all STM32 families)
  • ADC_AWD3_EVENT ADC Analog watchdog 3 event (additional analog watchdog, not present on all STM32 families)
  • ADC_OVR_EVENT ADC Overrun event
  • ADC_JQOVF_EVENT ADC Injected context queue overflow event
TimeoutTimeout value in millisecond.
Note
The relevant flag is cleared if found to be set, except for ADC_FLAG_OVR. Indeed, the latter is reset only if hadc->Init.Overrun field is set to ADC_OVR_DATA_OVERWRITTEN. Otherwise, data register may be potentially overwritten by a new converted data as soon as OVR is cleared. To reset OVR flag once the preserved data is retrieved, the user can resort to macro __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_OVR);
Return values
HALstatus

Definition at line 1583 of file stm32l4xx_hal_adc.c.

1584 {
1585  uint32_t tickstart;
1586 
1587  /* Check the parameters */
1588  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1589  assert_param(IS_ADC_EVENT_TYPE(EventType));
1590 
1591  /* Get tick count */
1592  tickstart = HAL_GetTick();
1593 
1594  /* Check selected event flag */
1595  while (__HAL_ADC_GET_FLAG(hadc, EventType) == 0UL)
1596  {
1597  /* Check if timeout is disabled (set to infinite wait) */
1598  if (Timeout != HAL_MAX_DELAY)
1599  {
1600  if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0UL))
1601  {
1602  /* Update ADC state machine to timeout */
1603  SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT);
1604 
1605  /* Process unlocked */
1606  __HAL_UNLOCK(hadc);
1607 
1608  return HAL_TIMEOUT;
1609  }
1610  }
1611  }
1612 
1613  switch (EventType)
1614  {
1615  /* End Of Sampling event */
1616  case ADC_EOSMP_EVENT:
1617  /* Set ADC state */
1618  SET_BIT(hadc->State, HAL_ADC_STATE_REG_EOSMP);
1619 
1620  /* Clear the End Of Sampling flag */
1621  __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_EOSMP);
1622 
1623  break;
1624 
1625  /* Analog watchdog (level out of window) event */
1626  /* Note: In case of several analog watchdog enabled, if needed to know */
1627  /* which one triggered and on which ADCx, test ADC state of analog watchdog */
1628  /* flags HAL_ADC_STATE_AWD1/2/3 using function "HAL_ADC_GetState()". */
1629  /* For example: */
1630  /* " if ((HAL_ADC_GetState(hadc1) & HAL_ADC_STATE_AWD1) != 0UL) " */
1631  /* " if ((HAL_ADC_GetState(hadc1) & HAL_ADC_STATE_AWD2) != 0UL) " */
1632  /* " if ((HAL_ADC_GetState(hadc1) & HAL_ADC_STATE_AWD3) != 0UL) " */
1633 
1634  /* Check analog watchdog 1 flag */
1635  case ADC_AWD_EVENT:
1636  /* Set ADC state */
1637  SET_BIT(hadc->State, HAL_ADC_STATE_AWD1);
1638 
1639  /* Clear ADC analog watchdog flag */
1640  __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_AWD1);
1641 
1642  break;
1643 
1644  /* Check analog watchdog 2 flag */
1645  case ADC_AWD2_EVENT:
1646  /* Set ADC state */
1647  SET_BIT(hadc->State, HAL_ADC_STATE_AWD2);
1648 
1649  /* Clear ADC analog watchdog flag */
1650  __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_AWD2);
1651 
1652  break;
1653 
1654  /* Check analog watchdog 3 flag */
1655  case ADC_AWD3_EVENT:
1656  /* Set ADC state */
1657  SET_BIT(hadc->State, HAL_ADC_STATE_AWD3);
1658 
1659  /* Clear ADC analog watchdog flag */
1660  __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_AWD3);
1661 
1662  break;
1663 
1664  /* Injected context queue overflow event */
1665  case ADC_JQOVF_EVENT:
1666  /* Set ADC state */
1667  SET_BIT(hadc->State, HAL_ADC_STATE_INJ_JQOVF);
1668 
1669  /* Set ADC error code to Injected context queue overflow */
1670  SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_JQOVF);
1671 
1672  /* Clear ADC Injected context queue overflow flag */
1673  __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_JQOVF);
1674 
1675  break;
1676 
1677  /* Overrun event */
1678  default: /* Case ADC_OVR_EVENT */
1679  /* If overrun is set to overwrite previous data, overrun event is not */
1680  /* considered as an error. */
1681  /* (cf ref manual "Managing conversions without using the DMA and without */
1682  /* overrun ") */
1683  if (hadc->Init.Overrun == ADC_OVR_DATA_PRESERVED)
1684  {
1685  /* Set ADC state */
1686  SET_BIT(hadc->State, HAL_ADC_STATE_REG_OVR);
1687 
1688  /* Set ADC error code to overrun */
1689  SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_OVR);
1690  }
1691  else
1692  {
1693  /* Clear ADC Overrun flag only if Overrun is set to ADC_OVR_DATA_OVERWRITTEN
1694  otherwise, data register is potentially overwritten by new converted data as soon
1695  as OVR is cleared. */
1696  __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_OVR);
1697  }
1698  break;
1699  }
1700 
1701  /* Return function status */
1702  return HAL_OK;
1703 }
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
return HAL_OK
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_ADC_Start()

HAL_StatusTypeDef HAL_ADC_Start ( ADC_HandleTypeDef hadc)

Enable ADC, start conversion of regular group.

Note
Interruptions enabled in this function: None.
Case of multimode enabled (when multimode feature is available): if ADC is Slave, ADC is enabled but conversion is not started, if ADC is master, ADC is enabled and multimode conversion is started.
Parameters
hadcADC handle
Return values
HALstatus

Definition at line 1215 of file stm32l4xx_hal_adc.c.

1216 {
1217  HAL_StatusTypeDef tmp_hal_status;
1218 #if defined(ADC_MULTIMODE_SUPPORT)
1219  const ADC_TypeDef *tmpADC_Master;
1220  uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
1221 #endif
1222 
1223  /* Check the parameters */
1224  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1225 
1226  /* Perform ADC enable and conversion start if no conversion is on going */
1227  if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL)
1228  {
1229  /* Process locked */
1230  __HAL_LOCK(hadc);
1231 
1232  /* Enable the ADC peripheral */
1233  tmp_hal_status = ADC_Enable(hadc);
1234 
1235  /* Start conversion if ADC is effectively enabled */
1236  if (tmp_hal_status == HAL_OK)
1237  {
1238  /* Set ADC state */
1239  /* - Clear state bitfield related to regular group conversion results */
1240  /* - Set state bitfield related to regular operation */
1241  ADC_STATE_CLR_SET(hadc->State,
1242  HAL_ADC_STATE_READY | HAL_ADC_STATE_REG_EOC | HAL_ADC_STATE_REG_OVR | HAL_ADC_STATE_REG_EOSMP,
1243  HAL_ADC_STATE_REG_BUSY);
1244 
1245 #if defined(ADC_MULTIMODE_SUPPORT)
1246  /* Reset HAL_ADC_STATE_MULTIMODE_SLAVE bit
1247  - if ADC instance is master or if multimode feature is not available
1248  - if multimode setting is disabled (ADC instance slave in independent mode) */
1249  if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
1250  || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
1251  )
1252  {
1253  CLEAR_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
1254  }
1255 #endif
1256 
1257  /* Set ADC error code */
1258  /* Check if a conversion is on going on ADC group injected */
1259  if (HAL_IS_BIT_SET(hadc->State, HAL_ADC_STATE_INJ_BUSY))
1260  {
1261  /* Reset ADC error code fields related to regular conversions only */
1262  CLEAR_BIT(hadc->ErrorCode, (HAL_ADC_ERROR_OVR | HAL_ADC_ERROR_DMA));
1263  }
1264  else
1265  {
1266  /* Reset all ADC error code fields */
1267  ADC_CLEAR_ERRORCODE(hadc);
1268  }
1269 
1270  /* Clear ADC group regular conversion flag and overrun flag */
1271  /* (To ensure of no unknown state from potential previous ADC operations) */
1272  __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_EOC | ADC_FLAG_EOS | ADC_FLAG_OVR));
1273 
1274  /* Process unlocked */
1275  /* Unlock before starting ADC conversions: in case of potential */
1276  /* interruption, to let the process to ADC IRQ Handler. */
1277  __HAL_UNLOCK(hadc);
1278 
1279  /* Enable conversion of regular group. */
1280  /* If software start has been selected, conversion starts immediately. */
1281  /* If external trigger has been selected, conversion will start at next */
1282  /* trigger event. */
1283  /* Case of multimode enabled (when multimode feature is available): */
1284  /* - if ADC is slave and dual regular conversions are enabled, ADC is */
1285  /* enabled only (conversion is not started), */
1286  /* - if ADC is master, ADC is enabled and conversion is started. */
1287 #if defined(ADC_MULTIMODE_SUPPORT)
1288  if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
1289  || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
1290  || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_SIMULT)
1291  || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_ALTERN)
1292  )
1293  {
1294  /* ADC instance is not a multimode slave instance with multimode regular conversions enabled */
1295  if (READ_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO) != 0UL)
1296  {
1297  ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY);
1298  }
1299 
1300  /* Start ADC group regular conversion */
1301  LL_ADC_REG_StartConversion(hadc->Instance);
1302  }
1303  else
1304  {
1305  /* ADC instance is a multimode slave instance with multimode regular conversions enabled */
1306  SET_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
1307  /* if Master ADC JAUTO bit is set, update Slave State in setting
1308  HAL_ADC_STATE_INJ_BUSY bit and in resetting HAL_ADC_STATE_INJ_EOC bit */
1309  tmpADC_Master = __LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance);
1310  if (READ_BIT(tmpADC_Master->CFGR, ADC_CFGR_JAUTO) != 0UL)
1311  {
1312  ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY);
1313  }
1314 
1315  }
1316 #else
1317  if (READ_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO) != 0UL)
1318  {
1319  ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY);
1320  }
1321 
1322  /* Start ADC group regular conversion */
1323  LL_ADC_REG_StartConversion(hadc->Instance);
1324 #endif
1325  }
1326  else
1327  {
1328  /* Process unlocked */
1329  __HAL_UNLOCK(hadc);
1330  }
1331  }
1332  else
1333  {
1334  tmp_hal_status = HAL_BUSY;
1335  }
1336 
1337  /* Return function status */
1338  return tmp_hal_status;
1339 }
__STATIC_INLINE uint32_t LL_ADC_GetMultimode(ADC_Common_TypeDef *ADCxy_COMMON)
Get ADC multimode configuration to operate in independent mode or multimode (for devices with several...
__HAL_UNLOCK(hrtc)
__STATIC_INLINE void LL_ADC_REG_StartConversion(ADC_TypeDef *ADCx)
Start ADC group regular conversion.
HAL_StatusTypeDef ADC_Enable(ADC_HandleTypeDef *hadc)
Enable the selected ADC.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
return HAL_OK
__STATIC_INLINE uint32_t LL_ADC_REG_IsConversionOngoing(ADC_TypeDef *ADCx)
Get ADC group regular conversion state. CR ADSTART LL_ADC_REG_IsConversionOngoing.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_ADC_Start_DMA()

HAL_StatusTypeDef HAL_ADC_Start_DMA ( ADC_HandleTypeDef hadc,
uint32_t *  pData,
uint32_t  Length 
)

Enable ADC, start conversion of regular group and transfer result through DMA.

Note
Interruptions enabled in this function: overrun (if applicable), DMA half transfer, DMA transfer complete. Each of these interruptions has its dedicated callback function.
Case of multimode enabled (when multimode feature is available): HAL_ADC_Start_DMA() is designed for single-ADC mode only. For multimode, the dedicated HAL_ADCEx_MultiModeStart_DMA() function must be used.
Parameters
hadcADC handle
pDataDestination Buffer address.
LengthNumber of data to be transferred from ADC peripheral to memory
Return values
HALstatus.

Definition at line 1988 of file stm32l4xx_hal_adc.c.

1989 {
1990  HAL_StatusTypeDef tmp_hal_status;
1991 #if defined(ADC_MULTIMODE_SUPPORT)
1992  uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
1993 #endif
1994 
1995  /* Check the parameters */
1996  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1997 
1998  /* Perform ADC enable and conversion start if no conversion is on going */
1999  if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL)
2000  {
2001  /* Process locked */
2002  __HAL_LOCK(hadc);
2003 
2004 #if defined(ADC_MULTIMODE_SUPPORT)
2005  /* Ensure that multimode regular conversions are not enabled. */
2006  /* Otherwise, dedicated API HAL_ADCEx_MultiModeStart_DMA() must be used. */
2007  if ((tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
2008  || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_SIMULT)
2009  || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_ALTERN)
2010  )
2011 #endif
2012  {
2013  /* Enable the ADC peripheral */
2014  tmp_hal_status = ADC_Enable(hadc);
2015 
2016  /* Start conversion if ADC is effectively enabled */
2017  if (tmp_hal_status == HAL_OK)
2018  {
2019  /* Set ADC state */
2020  /* - Clear state bitfield related to regular group conversion results */
2021  /* - Set state bitfield related to regular operation */
2022  ADC_STATE_CLR_SET(hadc->State,
2023  HAL_ADC_STATE_READY | HAL_ADC_STATE_REG_EOC | HAL_ADC_STATE_REG_OVR | HAL_ADC_STATE_REG_EOSMP,
2024  HAL_ADC_STATE_REG_BUSY);
2025 
2026 #if defined(ADC_MULTIMODE_SUPPORT)
2027  /* Reset HAL_ADC_STATE_MULTIMODE_SLAVE bit
2028  - if ADC instance is master or if multimode feature is not available
2029  - if multimode setting is disabled (ADC instance slave in independent mode) */
2030  if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
2031  || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
2032  )
2033  {
2034  CLEAR_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
2035  }
2036 #endif
2037 
2038  /* Check if a conversion is on going on ADC group injected */
2039  if ((hadc->State & HAL_ADC_STATE_INJ_BUSY) != 0UL)
2040  {
2041  /* Reset ADC error code fields related to regular conversions only */
2042  CLEAR_BIT(hadc->ErrorCode, (HAL_ADC_ERROR_OVR | HAL_ADC_ERROR_DMA));
2043  }
2044  else
2045  {
2046  /* Reset all ADC error code fields */
2047  ADC_CLEAR_ERRORCODE(hadc);
2048  }
2049 
2050  /* Set the DMA transfer complete callback */
2051  hadc->DMA_Handle->XferCpltCallback = ADC_DMAConvCplt;
2052 
2053  /* Set the DMA half transfer complete callback */
2054  hadc->DMA_Handle->XferHalfCpltCallback = ADC_DMAHalfConvCplt;
2055 
2056  /* Set the DMA error callback */
2057  hadc->DMA_Handle->XferErrorCallback = ADC_DMAError;
2058 
2059 
2060  /* Manage ADC and DMA start: ADC overrun interruption, DMA start, */
2061  /* ADC start (in case of SW start): */
2062 
2063  /* Clear regular group conversion flag and overrun flag */
2064  /* (To ensure of no unknown state from potential previous ADC */
2065  /* operations) */
2066  __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_EOC | ADC_FLAG_EOS | ADC_FLAG_OVR));
2067 
2068  /* Process unlocked */
2069  /* Unlock before starting ADC conversions: in case of potential */
2070  /* interruption, to let the process to ADC IRQ Handler. */
2071  __HAL_UNLOCK(hadc);
2072 
2073  /* With DMA, overrun event is always considered as an error even if
2074  hadc->Init.Overrun is set to ADC_OVR_DATA_OVERWRITTEN. Therefore,
2075  ADC_IT_OVR is enabled. */
2076  __HAL_ADC_ENABLE_IT(hadc, ADC_IT_OVR);
2077 
2078  /* Enable ADC DMA mode */
2079  SET_BIT(hadc->Instance->CFGR, ADC_CFGR_DMAEN);
2080 
2081  /* Start the DMA channel */
2082  tmp_hal_status = HAL_DMA_Start_IT(hadc->DMA_Handle, (uint32_t)&hadc->Instance->DR, (uint32_t)pData, Length);
2083 
2084  /* Enable conversion of regular group. */
2085  /* If software start has been selected, conversion starts immediately. */
2086  /* If external trigger has been selected, conversion will start at next */
2087  /* trigger event. */
2088  /* Start ADC group regular conversion */
2089  LL_ADC_REG_StartConversion(hadc->Instance);
2090  }
2091  else
2092  {
2093  /* Process unlocked */
2094  __HAL_UNLOCK(hadc);
2095  }
2096 
2097  }
2098 #if defined(ADC_MULTIMODE_SUPPORT)
2099  else
2100  {
2101  tmp_hal_status = HAL_ERROR;
2102  /* Process unlocked */
2103  __HAL_UNLOCK(hadc);
2104  }
2105 #endif
2106  }
2107  else
2108  {
2109  tmp_hal_status = HAL_BUSY;
2110  }
2111 
2112  /* Return function status */
2113  return tmp_hal_status;
2114 }
void ADC_DMAConvCplt(DMA_HandleTypeDef *hdma)
DMA transfer complete callback.
__STATIC_INLINE uint32_t LL_ADC_GetMultimode(ADC_Common_TypeDef *ADCxy_COMMON)
Get ADC multimode configuration to operate in independent mode or multimode (for devices with several...
void ADC_DMAError(DMA_HandleTypeDef *hdma)
DMA error callback.
__HAL_UNLOCK(hrtc)
__STATIC_INLINE void LL_ADC_REG_StartConversion(ADC_TypeDef *ADCx)
Start ADC group regular conversion.
HAL_StatusTypeDef ADC_Enable(ADC_HandleTypeDef *hadc)
Enable the selected ADC.
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
Start the DMA Transfer with interrupt enabled.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
return HAL_OK
void ADC_DMAHalfConvCplt(DMA_HandleTypeDef *hdma)
DMA half transfer complete callback.
__STATIC_INLINE uint32_t LL_ADC_REG_IsConversionOngoing(ADC_TypeDef *ADCx)
Get ADC group regular conversion state. CR ADSTART LL_ADC_REG_IsConversionOngoing.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_ADC_Start_IT()

HAL_StatusTypeDef HAL_ADC_Start_IT ( ADC_HandleTypeDef hadc)

Enable ADC, start conversion of regular group with interruption.

Note
Interruptions enabled in this function according to initialization setting : EOC (end of conversion), EOS (end of sequence), OVR overrun. Each of these interruptions has its dedicated callback function.
Case of multimode enabled (when multimode feature is available): HAL_ADC_Start_IT() must be called for ADC Slave first, then for ADC Master. For ADC Slave, ADC is enabled only (conversion is not started). For ADC Master, ADC is enabled and multimode conversion is started.
To guarantee a proper reset of all interruptions once all the needed conversions are obtained, HAL_ADC_Stop_IT() must be called to ensure a correct stop of the IT-based conversions.
By default, HAL_ADC_Start_IT() does not enable the End Of Sampling interruption. If required (e.g. in case of oversampling with trigger mode), the user must:
  1. first clear the EOSMP flag if set with macro __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_EOSMP)
  2. then enable the EOSMP interrupt with macro __HAL_ADC_ENABLE_IT(hadc, ADC_IT_EOSMP) before calling HAL_ADC_Start_IT().
Parameters
hadcADC handle
Return values
HALstatus

Definition at line 1728 of file stm32l4xx_hal_adc.c.

1729 {
1730  HAL_StatusTypeDef tmp_hal_status;
1731 #if defined(ADC_MULTIMODE_SUPPORT)
1732  const ADC_TypeDef *tmpADC_Master;
1733  uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
1734 #endif
1735 
1736  /* Check the parameters */
1737  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1738 
1739  /* Perform ADC enable and conversion start if no conversion is on going */
1740  if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL)
1741  {
1742  /* Process locked */
1743  __HAL_LOCK(hadc);
1744 
1745  /* Enable the ADC peripheral */
1746  tmp_hal_status = ADC_Enable(hadc);
1747 
1748  /* Start conversion if ADC is effectively enabled */
1749  if (tmp_hal_status == HAL_OK)
1750  {
1751  /* Set ADC state */
1752  /* - Clear state bitfield related to regular group conversion results */
1753  /* - Set state bitfield related to regular operation */
1754  ADC_STATE_CLR_SET(hadc->State,
1755  HAL_ADC_STATE_READY | HAL_ADC_STATE_REG_EOC | HAL_ADC_STATE_REG_OVR | HAL_ADC_STATE_REG_EOSMP,
1756  HAL_ADC_STATE_REG_BUSY);
1757 
1758 #if defined(ADC_MULTIMODE_SUPPORT)
1759  /* Reset HAL_ADC_STATE_MULTIMODE_SLAVE bit
1760  - if ADC instance is master or if multimode feature is not available
1761  - if multimode setting is disabled (ADC instance slave in independent mode) */
1762  if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
1763  || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
1764  )
1765  {
1766  CLEAR_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
1767  }
1768 #endif
1769 
1770  /* Set ADC error code */
1771  /* Check if a conversion is on going on ADC group injected */
1772  if ((hadc->State & HAL_ADC_STATE_INJ_BUSY) != 0UL)
1773  {
1774  /* Reset ADC error code fields related to regular conversions only */
1775  CLEAR_BIT(hadc->ErrorCode, (HAL_ADC_ERROR_OVR | HAL_ADC_ERROR_DMA));
1776  }
1777  else
1778  {
1779  /* Reset all ADC error code fields */
1780  ADC_CLEAR_ERRORCODE(hadc);
1781  }
1782 
1783  /* Clear ADC group regular conversion flag and overrun flag */
1784  /* (To ensure of no unknown state from potential previous ADC operations) */
1785  __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_EOC | ADC_FLAG_EOS | ADC_FLAG_OVR));
1786 
1787  /* Process unlocked */
1788  /* Unlock before starting ADC conversions: in case of potential */
1789  /* interruption, to let the process to ADC IRQ Handler. */
1790  __HAL_UNLOCK(hadc);
1791 
1792  /* Disable all interruptions before enabling the desired ones */
1793  __HAL_ADC_DISABLE_IT(hadc, (ADC_IT_EOC | ADC_IT_EOS | ADC_IT_OVR));
1794 
1795  /* Enable ADC end of conversion interrupt */
1796  switch (hadc->Init.EOCSelection)
1797  {
1798  case ADC_EOC_SEQ_CONV:
1799  __HAL_ADC_ENABLE_IT(hadc, ADC_IT_EOS);
1800  break;
1801  /* case ADC_EOC_SINGLE_CONV */
1802  default:
1803  __HAL_ADC_ENABLE_IT(hadc, ADC_IT_EOC);
1804  break;
1805  }
1806 
1807  /* Enable ADC overrun interrupt */
1808  /* If hadc->Init.Overrun is set to ADC_OVR_DATA_PRESERVED, only then is
1809  ADC_IT_OVR enabled; otherwise data overwrite is considered as normal
1810  behavior and no CPU time is lost for a non-processed interruption */
1811  if (hadc->Init.Overrun == ADC_OVR_DATA_PRESERVED)
1812  {
1813  __HAL_ADC_ENABLE_IT(hadc, ADC_IT_OVR);
1814  }
1815 
1816  /* Enable conversion of regular group. */
1817  /* If software start has been selected, conversion starts immediately. */
1818  /* If external trigger has been selected, conversion will start at next */
1819  /* trigger event. */
1820  /* Case of multimode enabled (when multimode feature is available): */
1821  /* - if ADC is slave and dual regular conversions are enabled, ADC is */
1822  /* enabled only (conversion is not started), */
1823  /* - if ADC is master, ADC is enabled and conversion is started. */
1824 #if defined(ADC_MULTIMODE_SUPPORT)
1825  if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
1826  || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
1827  || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_SIMULT)
1828  || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_ALTERN)
1829  )
1830  {
1831  /* ADC instance is not a multimode slave instance with multimode regular conversions enabled */
1832  if (READ_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO) != 0UL)
1833  {
1834  ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY);
1835 
1836  /* Enable as well injected interruptions in case
1837  HAL_ADCEx_InjectedStart_IT() has not been called beforehand. This
1838  allows to start regular and injected conversions when JAUTO is
1839  set with a single call to HAL_ADC_Start_IT() */
1840  switch (hadc->Init.EOCSelection)
1841  {
1842  case ADC_EOC_SEQ_CONV:
1843  __HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOC);
1844  __HAL_ADC_ENABLE_IT(hadc, ADC_IT_JEOS);
1845  break;
1846  /* case ADC_EOC_SINGLE_CONV */
1847  default:
1848  __HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOS);
1849  __HAL_ADC_ENABLE_IT(hadc, ADC_IT_JEOC);
1850  break;
1851  }
1852  }
1853 
1854  /* Start ADC group regular conversion */
1855  LL_ADC_REG_StartConversion(hadc->Instance);
1856  }
1857  else
1858  {
1859  /* ADC instance is a multimode slave instance with multimode regular conversions enabled */
1860  SET_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
1861  /* if Master ADC JAUTO bit is set, Slave injected interruptions
1862  are enabled nevertheless (for same reason as above) */
1863  tmpADC_Master = __LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance);
1864  if (READ_BIT(tmpADC_Master->CFGR, ADC_CFGR_JAUTO) != 0UL)
1865  {
1866  /* First, update Slave State in setting HAL_ADC_STATE_INJ_BUSY bit
1867  and in resetting HAL_ADC_STATE_INJ_EOC bit */
1868  ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY);
1869  /* Next, set Slave injected interruptions */
1870  switch (hadc->Init.EOCSelection)
1871  {
1872  case ADC_EOC_SEQ_CONV:
1873  __HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOC);
1874  __HAL_ADC_ENABLE_IT(hadc, ADC_IT_JEOS);
1875  break;
1876  /* case ADC_EOC_SINGLE_CONV */
1877  default:
1878  __HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOS);
1879  __HAL_ADC_ENABLE_IT(hadc, ADC_IT_JEOC);
1880  break;
1881  }
1882  }
1883  }
1884 #else
1885  /* ADC instance is not a multimode slave instance with multimode regular conversions enabled */
1886  if (READ_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO) != 0UL)
1887  {
1888  ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY);
1889 
1890  /* Enable as well injected interruptions in case
1891  HAL_ADCEx_InjectedStart_IT() has not been called beforehand. This
1892  allows to start regular and injected conversions when JAUTO is
1893  set with a single call to HAL_ADC_Start_IT() */
1894  switch (hadc->Init.EOCSelection)
1895  {
1896  case ADC_EOC_SEQ_CONV:
1897  __HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOC);
1898  __HAL_ADC_ENABLE_IT(hadc, ADC_IT_JEOS);
1899  break;
1900  /* case ADC_EOC_SINGLE_CONV */
1901  default:
1902  __HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOS);
1903  __HAL_ADC_ENABLE_IT(hadc, ADC_IT_JEOC);
1904  break;
1905  }
1906  }
1907 
1908  /* Start ADC group regular conversion */
1909  LL_ADC_REG_StartConversion(hadc->Instance);
1910 #endif
1911  }
1912  else
1913  {
1914  /* Process unlocked */
1915  __HAL_UNLOCK(hadc);
1916  }
1917 
1918  }
1919  else
1920  {
1921  tmp_hal_status = HAL_BUSY;
1922  }
1923 
1924  /* Return function status */
1925  return tmp_hal_status;
1926 }
__STATIC_INLINE uint32_t LL_ADC_GetMultimode(ADC_Common_TypeDef *ADCxy_COMMON)
Get ADC multimode configuration to operate in independent mode or multimode (for devices with several...
__HAL_UNLOCK(hrtc)
__STATIC_INLINE void LL_ADC_REG_StartConversion(ADC_TypeDef *ADCx)
Start ADC group regular conversion.
HAL_StatusTypeDef ADC_Enable(ADC_HandleTypeDef *hadc)
Enable the selected ADC.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
return HAL_OK
__STATIC_INLINE uint32_t LL_ADC_REG_IsConversionOngoing(ADC_TypeDef *ADCx)
Get ADC group regular conversion state. CR ADSTART LL_ADC_REG_IsConversionOngoing.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_ADC_Stop()

HAL_StatusTypeDef HAL_ADC_Stop ( ADC_HandleTypeDef hadc)

Stop ADC conversion of regular group (and injected channels in case of auto_injection mode), disable ADC peripheral.

Note
: ADC peripheral disable is forcing stop of potential conversion on injected group. If injected group is under use, it should be preliminarily stopped using HAL_ADCEx_InjectedStop function.
Parameters
hadcADC handle
Return values
HALstatus.

Definition at line 1350 of file stm32l4xx_hal_adc.c.

1351 {
1352  HAL_StatusTypeDef tmp_hal_status;
1353 
1354  /* Check the parameters */
1355  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1356 
1357  /* Process locked */
1358  __HAL_LOCK(hadc);
1359 
1360  /* 1. Stop potential conversion on going, on ADC groups regular and injected */
1361  tmp_hal_status = ADC_ConversionStop(hadc, ADC_REGULAR_INJECTED_GROUP);
1362 
1363  /* Disable ADC peripheral if conversions are effectively stopped */
1364  if (tmp_hal_status == HAL_OK)
1365  {
1366  /* 2. Disable the ADC peripheral */
1367  tmp_hal_status = ADC_Disable(hadc);
1368 
1369  /* Check if ADC is effectively disabled */
1370  if (tmp_hal_status == HAL_OK)
1371  {
1372  /* Set ADC state */
1373  ADC_STATE_CLR_SET(hadc->State,
1374  HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
1375  HAL_ADC_STATE_READY);
1376  }
1377  }
1378 
1379  /* Process unlocked */
1380  __HAL_UNLOCK(hadc);
1381 
1382  /* Return function status */
1383  return tmp_hal_status;
1384 }
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
HAL_StatusTypeDef ADC_ConversionStop(ADC_HandleTypeDef *hadc, uint32_t ConversionGroup)
Stop ADC conversion.
HAL_StatusTypeDef ADC_Disable(ADC_HandleTypeDef *hadc)
Disable the selected ADC.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_ADC_Stop_DMA()

HAL_StatusTypeDef HAL_ADC_Stop_DMA ( ADC_HandleTypeDef hadc)

Stop ADC conversion of regular group (and injected group in case of auto_injection mode), disable ADC DMA transfer, disable ADC peripheral.

Note
: ADC peripheral disable is forcing stop of potential conversion on ADC group injected. If ADC group injected is under use, it should be preliminarily stopped using HAL_ADCEx_InjectedStop function.
Case of multimode enabled (when multimode feature is available): HAL_ADC_Stop_DMA() function is dedicated to single-ADC mode only. For multimode, the dedicated HAL_ADCEx_MultiModeStop_DMA() API must be used.
Parameters
hadcADC handle
Return values
HALstatus.

Definition at line 2129 of file stm32l4xx_hal_adc.c.

2130 {
2131  HAL_StatusTypeDef tmp_hal_status;
2132 
2133  /* Check the parameters */
2134  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
2135 
2136  /* Process locked */
2137  __HAL_LOCK(hadc);
2138 
2139  /* 1. Stop potential ADC group regular conversion on going */
2140  tmp_hal_status = ADC_ConversionStop(hadc, ADC_REGULAR_INJECTED_GROUP);
2141 
2142  /* Disable ADC peripheral if conversions are effectively stopped */
2143  if (tmp_hal_status == HAL_OK)
2144  {
2145  /* Disable ADC DMA (ADC DMA configuration of continous requests is kept) */
2146  CLEAR_BIT(hadc->Instance->CFGR, ADC_CFGR_DMAEN);
2147 
2148  /* Disable the DMA channel (in case of DMA in circular mode or stop */
2149  /* while DMA transfer is on going) */
2150  if (hadc->DMA_Handle->State == HAL_DMA_STATE_BUSY)
2151  {
2152  tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle);
2153 
2154  /* Check if DMA channel effectively disabled */
2155  if (tmp_hal_status != HAL_OK)
2156  {
2157  /* Update ADC state machine to error */
2158  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_DMA);
2159  }
2160  }
2161 
2162  /* Disable ADC overrun interrupt */
2163  __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR);
2164 
2165  /* 2. Disable the ADC peripheral */
2166  /* Update "tmp_hal_status" only if DMA channel disabling passed, */
2167  /* to keep in memory a potential failing status. */
2168  if (tmp_hal_status == HAL_OK)
2169  {
2170  tmp_hal_status = ADC_Disable(hadc);
2171  }
2172  else
2173  {
2174  (void)ADC_Disable(hadc);
2175  }
2176 
2177  /* Check if ADC is effectively disabled */
2178  if (tmp_hal_status == HAL_OK)
2179  {
2180  /* Set ADC state */
2181  ADC_STATE_CLR_SET(hadc->State,
2182  HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
2183  HAL_ADC_STATE_READY);
2184  }
2185 
2186  }
2187 
2188  /* Process unlocked */
2189  __HAL_UNLOCK(hadc);
2190 
2191  /* Return function status */
2192  return tmp_hal_status;
2193 }
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
return HAL_OK
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
Abort the DMA Transfer.
HAL_StatusTypeDef ADC_ConversionStop(ADC_HandleTypeDef *hadc, uint32_t ConversionGroup)
Stop ADC conversion.
HAL_StatusTypeDef ADC_Disable(ADC_HandleTypeDef *hadc)
Disable the selected ADC.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_ADC_Stop_IT()

HAL_StatusTypeDef HAL_ADC_Stop_IT ( ADC_HandleTypeDef hadc)

Stop ADC conversion of regular group (and injected group in case of auto_injection mode), disable interrution of end-of-conversion, disable ADC peripheral.

Parameters
hadcADC handle
Return values
HALstatus.

Definition at line 1935 of file stm32l4xx_hal_adc.c.

1936 {
1937  HAL_StatusTypeDef tmp_hal_status;
1938 
1939  /* Check the parameters */
1940  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1941 
1942  /* Process locked */
1943  __HAL_LOCK(hadc);
1944 
1945  /* 1. Stop potential conversion on going, on ADC groups regular and injected */
1946  tmp_hal_status = ADC_ConversionStop(hadc, ADC_REGULAR_INJECTED_GROUP);
1947 
1948  /* Disable ADC peripheral if conversions are effectively stopped */
1949  if (tmp_hal_status == HAL_OK)
1950  {
1951  /* Disable ADC end of conversion interrupt for regular group */
1952  /* Disable ADC overrun interrupt */
1953  __HAL_ADC_DISABLE_IT(hadc, (ADC_IT_EOC | ADC_IT_EOS | ADC_IT_OVR));
1954 
1955  /* 2. Disable the ADC peripheral */
1956  tmp_hal_status = ADC_Disable(hadc);
1957 
1958  /* Check if ADC is effectively disabled */
1959  if (tmp_hal_status == HAL_OK)
1960  {
1961  /* Set ADC state */
1962  ADC_STATE_CLR_SET(hadc->State,
1963  HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
1964  HAL_ADC_STATE_READY);
1965  }
1966  }
1967 
1968  /* Process unlocked */
1969  __HAL_UNLOCK(hadc);
1970 
1971  /* Return function status */
1972  return tmp_hal_status;
1973 }
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
HAL_StatusTypeDef ADC_ConversionStop(ADC_HandleTypeDef *hadc, uint32_t ConversionGroup)
Stop ADC conversion.
HAL_StatusTypeDef ADC_Disable(ADC_HandleTypeDef *hadc)
Disable the selected ADC.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))