STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_hal_adc_ex.c
Go to the documentation of this file.
1 
42 /* Includes ------------------------------------------------------------------*/
43 #include "stm32l4xx_hal.h"
44 
54 #ifdef HAL_ADC_MODULE_ENABLED
55 
56 /* Private typedef -----------------------------------------------------------*/
57 /* Private define ------------------------------------------------------------*/
58 
63 #define ADC_JSQR_FIELDS ((ADC_JSQR_JL | ADC_JSQR_JEXTSEL | ADC_JSQR_JEXTEN |\
64  ADC_JSQR_JSQ1 | ADC_JSQR_JSQ2 |\
65  ADC_JSQR_JSQ3 | ADC_JSQR_JSQ4 ))
68 /* Fixed timeout value for ADC calibration. */
69 /* Values defined to be higher than worst cases: maximum ratio between ADC */
70 /* and CPU clock frequencies. */
71 /* Example of profile low frequency : ADC frequency at 31.25kHz (ADC clock */
72 /* source PLL SAI 8MHz, ADC clock prescaler 256), CPU frequency 80MHz. */
73 /* Calibration time max = 116 / fADC (refer to datasheet) */
74 /* = 296 960 CPU cycles */
75 #define ADC_CALIBRATION_TIMEOUT (296960UL)
81 /* Private macro -------------------------------------------------------------*/
82 /* Private variables ---------------------------------------------------------*/
83 /* Private function prototypes -----------------------------------------------*/
84 /* Exported functions --------------------------------------------------------*/
85 
129 HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef *hadc, uint32_t SingleDiff)
130 {
131  HAL_StatusTypeDef tmp_hal_status;
132  __IO uint32_t wait_loop_index = 0UL;
133 
134  /* Check the parameters */
135  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
136  assert_param(IS_ADC_SINGLE_DIFFERENTIAL(SingleDiff));
137 
138  /* Process locked */
139  __HAL_LOCK(hadc);
140 
141  /* Calibration prerequisite: ADC must be disabled. */
142 
143  /* Disable the ADC (if not already disabled) */
144  tmp_hal_status = ADC_Disable(hadc);
145 
146  /* Check if ADC is effectively disabled */
147  if (tmp_hal_status == HAL_OK)
148  {
149  /* Set ADC state */
150  ADC_STATE_CLR_SET(hadc->State,
151  HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
152  HAL_ADC_STATE_BUSY_INTERNAL);
153 
154  /* Start ADC calibration in mode single-ended or differential */
155  LL_ADC_StartCalibration(hadc->Instance, SingleDiff);
156 
157  /* Wait for calibration completion */
158  while (LL_ADC_IsCalibrationOnGoing(hadc->Instance) != 0UL)
159  {
160  wait_loop_index++;
161  if (wait_loop_index >= ADC_CALIBRATION_TIMEOUT)
162  {
163  /* Update ADC state machine to error */
164  ADC_STATE_CLR_SET(hadc->State,
165  HAL_ADC_STATE_BUSY_INTERNAL,
166  HAL_ADC_STATE_ERROR_INTERNAL);
167 
168  /* Process unlocked */
169  __HAL_UNLOCK(hadc);
170 
171  return HAL_ERROR;
172  }
173  }
174 
175  /* Set ADC state */
176  ADC_STATE_CLR_SET(hadc->State,
177  HAL_ADC_STATE_BUSY_INTERNAL,
178  HAL_ADC_STATE_READY);
179  }
180  else
181  {
182  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
183 
184  /* Note: No need to update variable "tmp_hal_status" here: already set */
185  /* to state "HAL_ERROR" by function disabling the ADC. */
186  }
187 
188  /* Process unlocked */
189  __HAL_UNLOCK(hadc);
190 
191  /* Return function status */
192  return tmp_hal_status;
193 }
194 
203 uint32_t HAL_ADCEx_Calibration_GetValue(ADC_HandleTypeDef *hadc, uint32_t SingleDiff)
204 {
205  /* Check the parameters */
206  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
207  assert_param(IS_ADC_SINGLE_DIFFERENTIAL(SingleDiff));
208 
209  /* Return the selected ADC calibration value */
210  return LL_ADC_GetCalibrationFactor(hadc->Instance, SingleDiff);
211 }
212 
223 HAL_StatusTypeDef HAL_ADCEx_Calibration_SetValue(ADC_HandleTypeDef *hadc, uint32_t SingleDiff, uint32_t CalibrationFactor)
224 {
225  HAL_StatusTypeDef tmp_hal_status = HAL_OK;
226  uint32_t tmp_adc_is_conversion_on_going_regular;
227  uint32_t tmp_adc_is_conversion_on_going_injected;
228 
229  /* Check the parameters */
230  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
231  assert_param(IS_ADC_SINGLE_DIFFERENTIAL(SingleDiff));
232  assert_param(IS_ADC_CALFACT(CalibrationFactor));
233 
234  /* Process locked */
235  __HAL_LOCK(hadc);
236 
237  /* Verification of hardware constraints before modifying the calibration */
238  /* factors register: ADC must be enabled, no conversion on going. */
239  tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
240  tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance);
241 
242  if ((LL_ADC_IsEnabled(hadc->Instance) != 0UL)
243  && (tmp_adc_is_conversion_on_going_regular == 0UL)
244  && (tmp_adc_is_conversion_on_going_injected == 0UL)
245  )
246  {
247  /* Set the selected ADC calibration value */
248  LL_ADC_SetCalibrationFactor(hadc->Instance, SingleDiff, CalibrationFactor);
249  }
250  else
251  {
252  /* Update ADC state machine */
253  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
254  /* Update ADC error code */
255  SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL);
256 
257  /* Update ADC state machine to error */
258  tmp_hal_status = HAL_ERROR;
259  }
260 
261  /* Process unlocked */
262  __HAL_UNLOCK(hadc);
263 
264  /* Return function status */
265  return tmp_hal_status;
266 }
267 
280 {
281  HAL_StatusTypeDef tmp_hal_status;
282  uint32_t tmp_config_injected_queue;
283 #if defined(ADC_MULTIMODE_SUPPORT)
284  uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
285 #endif
286 
287  /* Check the parameters */
288  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
289 
290  if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) != 0UL)
291  {
292  return HAL_BUSY;
293  }
294  else
295  {
296  /* In case of software trigger detection enabled, JQDIS must be set
297  (which can be done only if ADSTART and JADSTART are both cleared).
298  If JQDIS is not set at that point, returns an error
299  - since software trigger detection is disabled. User needs to
300  resort to HAL_ADCEx_DisableInjectedQueue() API to set JQDIS.
301  - or (if JQDIS is intentionally reset) since JEXTEN = 0 which means
302  the queue is empty */
303  tmp_config_injected_queue = READ_BIT(hadc->Instance->CFGR, ADC_CFGR_JQDIS);
304 
305  if ((READ_BIT(hadc->Instance->JSQR, ADC_JSQR_JEXTEN) == 0UL)
306  && (tmp_config_injected_queue == 0UL)
307  )
308  {
309  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
310  return HAL_ERROR;
311  }
312 
313  /* Process locked */
314  __HAL_LOCK(hadc);
315 
316  /* Enable the ADC peripheral */
317  tmp_hal_status = ADC_Enable(hadc);
318 
319  /* Start conversion if ADC is effectively enabled */
320  if (tmp_hal_status == HAL_OK)
321  {
322  /* Check if a regular conversion is ongoing */
323  if ((hadc->State & HAL_ADC_STATE_REG_BUSY) != 0UL)
324  {
325  /* Reset ADC error code field related to injected conversions only */
326  CLEAR_BIT(hadc->ErrorCode, HAL_ADC_ERROR_JQOVF);
327  }
328  else
329  {
330  /* Set ADC error code to none */
331  ADC_CLEAR_ERRORCODE(hadc);
332  }
333 
334  /* Set ADC state */
335  /* - Clear state bitfield related to injected group conversion results */
336  /* - Set state bitfield related to injected operation */
337  ADC_STATE_CLR_SET(hadc->State,
338  HAL_ADC_STATE_READY | HAL_ADC_STATE_INJ_EOC,
339  HAL_ADC_STATE_INJ_BUSY);
340 
341 #if defined(ADC_MULTIMODE_SUPPORT)
342  /* Reset HAL_ADC_STATE_MULTIMODE_SLAVE bit
343  - if ADC instance is master or if multimode feature is not available
344  - if multimode setting is disabled (ADC instance slave in independent mode) */
345  if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
346  || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
347  )
348  {
349  CLEAR_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
350  }
351 #endif
352 
353  /* Clear ADC group injected group conversion flag */
354  /* (To ensure of no unknown state from potential previous ADC operations) */
355  __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_JEOC | ADC_FLAG_JEOS));
356 
357  /* Process unlocked */
358  /* Unlock before starting ADC conversions: in case of potential */
359  /* interruption, to let the process to ADC IRQ Handler. */
360  __HAL_UNLOCK(hadc);
361 
362  /* Enable conversion of injected group, if automatic injected conversion */
363  /* is disabled. */
364  /* If software start has been selected, conversion starts immediately. */
365  /* If external trigger has been selected, conversion will start at next */
366  /* trigger event. */
367  /* Case of multimode enabled (when multimode feature is available): */
368  /* if ADC is slave, */
369  /* - ADC is enabled only (conversion is not started), */
370  /* - if multimode only concerns regular conversion, ADC is enabled */
371  /* and conversion is started. */
372  /* If ADC is master or independent, */
373  /* - ADC is enabled and conversion is started. */
374 #if defined(ADC_MULTIMODE_SUPPORT)
375  if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
376  || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
377  || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_SIMULT)
378  || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_INTERL)
379  )
380  {
381  /* ADC instance is not a multimode slave instance with multimode injected conversions enabled */
382  if (LL_ADC_INJ_GetTrigAuto(hadc->Instance) == LL_ADC_INJ_TRIG_INDEPENDENT)
383  {
384  LL_ADC_INJ_StartConversion(hadc->Instance);
385  }
386  }
387  else
388  {
389  /* ADC instance is not a multimode slave instance with multimode injected conversions enabled */
390  SET_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
391  }
392 #else
393  if (LL_ADC_INJ_GetTrigAuto(hadc->Instance) == LL_ADC_INJ_TRIG_INDEPENDENT)
394  {
395  /* Start ADC group injected conversion */
396  LL_ADC_INJ_StartConversion(hadc->Instance);
397  }
398 #endif
399 
400  }
401  else
402  {
403  /* Process unlocked */
404  __HAL_UNLOCK(hadc);
405  }
406 
407  /* Return function status */
408  return tmp_hal_status;
409  }
410 }
411 
429 {
430  HAL_StatusTypeDef tmp_hal_status;
431 
432  /* Check the parameters */
433  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
434 
435  /* Process locked */
436  __HAL_LOCK(hadc);
437 
438  /* 1. Stop potential conversion on going on injected group only. */
439  tmp_hal_status = ADC_ConversionStop(hadc, ADC_INJECTED_GROUP);
440 
441  /* Disable ADC peripheral if injected conversions are effectively stopped */
442  /* and if no conversion on regular group is on-going */
443  if (tmp_hal_status == HAL_OK)
444  {
445  if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL)
446  {
447  /* 2. Disable the ADC peripheral */
448  tmp_hal_status = ADC_Disable(hadc);
449 
450  /* Check if ADC is effectively disabled */
451  if (tmp_hal_status == HAL_OK)
452  {
453  /* Set ADC state */
454  ADC_STATE_CLR_SET(hadc->State,
455  HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
456  HAL_ADC_STATE_READY);
457  }
458  }
459  /* Conversion on injected group is stopped, but ADC not disabled since */
460  /* conversion on regular group is still running. */
461  else
462  {
463  /* Set ADC state */
464  CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
465  }
466  }
467 
468  /* Process unlocked */
469  __HAL_UNLOCK(hadc);
470 
471  /* Return function status */
472  return tmp_hal_status;
473 }
474 
483 HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef *hadc, uint32_t Timeout)
484 {
485  uint32_t tickstart;
486  uint32_t tmp_Flag_End;
487  uint32_t tmp_adc_inj_is_trigger_source_sw_start;
488  uint32_t tmp_adc_reg_is_trigger_source_sw_start;
489  uint32_t tmp_cfgr;
490 #if defined(ADC_MULTIMODE_SUPPORT)
491  const ADC_TypeDef *tmpADC_Master;
492  uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
493 #endif
494 
495  /* Check the parameters */
496  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
497 
498  /* If end of sequence selected */
499  if (hadc->Init.EOCSelection == ADC_EOC_SEQ_CONV)
500  {
501  tmp_Flag_End = ADC_FLAG_JEOS;
502  }
503  else /* end of conversion selected */
504  {
505  tmp_Flag_End = ADC_FLAG_JEOC;
506  }
507 
508  /* Get timeout */
509  tickstart = HAL_GetTick();
510 
511  /* Wait until End of Conversion or Sequence flag is raised */
512  while ((hadc->Instance->ISR & tmp_Flag_End) == 0UL)
513  {
514  /* Check if timeout is disabled (set to infinite wait) */
515  if (Timeout != HAL_MAX_DELAY)
516  {
517  if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0UL))
518  {
519  /* Update ADC state machine to timeout */
520  SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT);
521 
522  /* Process unlocked */
523  __HAL_UNLOCK(hadc);
524 
525  return HAL_TIMEOUT;
526  }
527  }
528  }
529 
530  /* Retrieve ADC configuration */
531  tmp_adc_inj_is_trigger_source_sw_start = LL_ADC_INJ_IsTriggerSourceSWStart(hadc->Instance);
532  tmp_adc_reg_is_trigger_source_sw_start = LL_ADC_REG_IsTriggerSourceSWStart(hadc->Instance);
533  /* Get relevant register CFGR in ADC instance of ADC master or slave */
534  /* in function of multimode state (for devices with multimode */
535  /* available). */
536 #if defined(ADC_MULTIMODE_SUPPORT)
537  if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
538  || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
539  || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_SIMULT)
540  || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_INTERL)
541  )
542  {
543  tmp_cfgr = READ_REG(hadc->Instance->CFGR);
544  }
545  else
546  {
547  tmpADC_Master = __LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance);
548  tmp_cfgr = READ_REG(tmpADC_Master->CFGR);
549  }
550 #else
551  tmp_cfgr = READ_REG(hadc->Instance->CFGR);
552 #endif
553 
554  /* Update ADC state machine */
555  SET_BIT(hadc->State, HAL_ADC_STATE_INJ_EOC);
556 
557  /* Determine whether any further conversion upcoming on group injected */
558  /* by external trigger or by automatic injected conversion */
559  /* from group regular. */
560  if ((tmp_adc_inj_is_trigger_source_sw_start != 0UL) ||
561  ((READ_BIT(tmp_cfgr, ADC_CFGR_JAUTO) == 0UL) &&
562  ((tmp_adc_reg_is_trigger_source_sw_start != 0UL) &&
563  (READ_BIT(tmp_cfgr, ADC_CFGR_CONT) == 0UL))))
564  {
565  /* Check whether end of sequence is reached */
566  if (__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_JEOS))
567  {
568  /* Particular case if injected contexts queue is enabled: */
569  /* when the last context has been fully processed, JSQR is reset */
570  /* by the hardware. Even if no injected conversion is planned to come */
571  /* (queue empty, triggers are ignored), it can start again */
572  /* immediately after setting a new context (JADSTART is still set). */
573  /* Therefore, state of HAL ADC injected group is kept to busy. */
574  if (READ_BIT(tmp_cfgr, ADC_CFGR_JQM) == 0UL)
575  {
576  /* Set ADC state */
577  CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
578 
579  if ((hadc->State & HAL_ADC_STATE_REG_BUSY) == 0UL)
580  {
581  SET_BIT(hadc->State, HAL_ADC_STATE_READY);
582  }
583  }
584  }
585  }
586 
587  /* Clear polled flag */
588  if (tmp_Flag_End == ADC_FLAG_JEOS)
589  {
590  /* Clear end of sequence JEOS flag of injected group if low power feature */
591  /* "LowPowerAutoWait " is disabled, to not interfere with this feature. */
592  /* For injected groups, no new conversion will start before JEOS is */
593  /* cleared. */
594  if (READ_BIT(tmp_cfgr, ADC_CFGR_AUTDLY) == 0UL)
595  {
596  __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_JEOC | ADC_FLAG_JEOS));
597  }
598  }
599  else
600  {
601  __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_JEOC);
602  }
603 
604  /* Return API HAL status */
605  return HAL_OK;
606 }
607 
621 {
622  HAL_StatusTypeDef tmp_hal_status;
623  uint32_t tmp_config_injected_queue;
624 #if defined(ADC_MULTIMODE_SUPPORT)
625  uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
626 #endif
627 
628  /* Check the parameters */
629  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
630 
631  if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) != 0UL)
632  {
633  return HAL_BUSY;
634  }
635  else
636  {
637  /* In case of software trigger detection enabled, JQDIS must be set
638  (which can be done only if ADSTART and JADSTART are both cleared).
639  If JQDIS is not set at that point, returns an error
640  - since software trigger detection is disabled. User needs to
641  resort to HAL_ADCEx_DisableInjectedQueue() API to set JQDIS.
642  - or (if JQDIS is intentionally reset) since JEXTEN = 0 which means
643  the queue is empty */
644  tmp_config_injected_queue = READ_BIT(hadc->Instance->CFGR, ADC_CFGR_JQDIS);
645 
646  if ((READ_BIT(hadc->Instance->JSQR, ADC_JSQR_JEXTEN) == 0UL)
647  && (tmp_config_injected_queue == 0UL)
648  )
649  {
650  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
651  return HAL_ERROR;
652  }
653 
654  /* Process locked */
655  __HAL_LOCK(hadc);
656 
657  /* Enable the ADC peripheral */
658  tmp_hal_status = ADC_Enable(hadc);
659 
660  /* Start conversion if ADC is effectively enabled */
661  if (tmp_hal_status == HAL_OK)
662  {
663  /* Check if a regular conversion is ongoing */
664  if ((hadc->State & HAL_ADC_STATE_REG_BUSY) != 0UL)
665  {
666  /* Reset ADC error code field related to injected conversions only */
667  CLEAR_BIT(hadc->ErrorCode, HAL_ADC_ERROR_JQOVF);
668  }
669  else
670  {
671  /* Set ADC error code to none */
672  ADC_CLEAR_ERRORCODE(hadc);
673  }
674 
675  /* Set ADC state */
676  /* - Clear state bitfield related to injected group conversion results */
677  /* - Set state bitfield related to injected operation */
678  ADC_STATE_CLR_SET(hadc->State,
679  HAL_ADC_STATE_READY | HAL_ADC_STATE_INJ_EOC,
680  HAL_ADC_STATE_INJ_BUSY);
681 
682 #if defined(ADC_MULTIMODE_SUPPORT)
683  /* Reset HAL_ADC_STATE_MULTIMODE_SLAVE bit
684  - if ADC instance is master or if multimode feature is not available
685  - if multimode setting is disabled (ADC instance slave in independent mode) */
686  if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
687  || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
688  )
689  {
690  CLEAR_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
691  }
692 #endif
693 
694  /* Clear ADC group injected group conversion flag */
695  /* (To ensure of no unknown state from potential previous ADC operations) */
696  __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_JEOC | ADC_FLAG_JEOS));
697 
698  /* Process unlocked */
699  /* Unlock before starting ADC conversions: in case of potential */
700  /* interruption, to let the process to ADC IRQ Handler. */
701  __HAL_UNLOCK(hadc);
702 
703  /* Enable ADC Injected context queue overflow interrupt if this feature */
704  /* is enabled. */
705  if ((hadc->Instance->CFGR & ADC_CFGR_JQM) != 0UL)
706  {
707  __HAL_ADC_ENABLE_IT(hadc, ADC_FLAG_JQOVF);
708  }
709 
710  /* Enable ADC end of conversion interrupt */
711  switch (hadc->Init.EOCSelection)
712  {
713  case ADC_EOC_SEQ_CONV:
714  __HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOC);
715  __HAL_ADC_ENABLE_IT(hadc, ADC_IT_JEOS);
716  break;
717  /* case ADC_EOC_SINGLE_CONV */
718  default:
719  __HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOS);
720  __HAL_ADC_ENABLE_IT(hadc, ADC_IT_JEOC);
721  break;
722  }
723 
724  /* Enable conversion of injected group, if automatic injected conversion */
725  /* is disabled. */
726  /* If software start has been selected, conversion starts immediately. */
727  /* If external trigger has been selected, conversion will start at next */
728  /* trigger event. */
729  /* Case of multimode enabled (when multimode feature is available): */
730  /* if ADC is slave, */
731  /* - ADC is enabled only (conversion is not started), */
732  /* - if multimode only concerns regular conversion, ADC is enabled */
733  /* and conversion is started. */
734  /* If ADC is master or independent, */
735  /* - ADC is enabled and conversion is started. */
736 #if defined(ADC_MULTIMODE_SUPPORT)
737  if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
738  || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
739  || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_SIMULT)
740  || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_INTERL)
741  )
742  {
743  /* ADC instance is not a multimode slave instance with multimode injected conversions enabled */
744  if (LL_ADC_INJ_GetTrigAuto(hadc->Instance) == LL_ADC_INJ_TRIG_INDEPENDENT)
745  {
746  LL_ADC_INJ_StartConversion(hadc->Instance);
747  }
748  }
749  else
750  {
751  /* ADC instance is not a multimode slave instance with multimode injected conversions enabled */
752  SET_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
753  }
754 #else
755  if (LL_ADC_INJ_GetTrigAuto(hadc->Instance) == LL_ADC_INJ_TRIG_INDEPENDENT)
756  {
757  /* Start ADC group injected conversion */
758  LL_ADC_INJ_StartConversion(hadc->Instance);
759  }
760 #endif
761 
762  }
763  else
764  {
765  /* Process unlocked */
766  __HAL_UNLOCK(hadc);
767  }
768 
769  /* Return function status */
770  return tmp_hal_status;
771  }
772 }
773 
794 {
795  HAL_StatusTypeDef tmp_hal_status;
796 
797  /* Check the parameters */
798  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
799 
800  /* Process locked */
801  __HAL_LOCK(hadc);
802 
803  /* 1. Stop potential conversion on going on injected group only. */
804  tmp_hal_status = ADC_ConversionStop(hadc, ADC_INJECTED_GROUP);
805 
806  /* Disable ADC peripheral if injected conversions are effectively stopped */
807  /* and if no conversion on the other group (regular group) is intended to */
808  /* continue. */
809  if (tmp_hal_status == HAL_OK)
810  {
811  /* Disable ADC end of conversion interrupt for injected channels */
812  __HAL_ADC_DISABLE_IT(hadc, (ADC_IT_JEOC | ADC_IT_JEOS | ADC_FLAG_JQOVF));
813 
814  if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL)
815  {
816  /* 2. Disable the ADC peripheral */
817  tmp_hal_status = ADC_Disable(hadc);
818 
819  /* Check if ADC is effectively disabled */
820  if (tmp_hal_status == HAL_OK)
821  {
822  /* Set ADC state */
823  ADC_STATE_CLR_SET(hadc->State,
824  HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
825  HAL_ADC_STATE_READY);
826  }
827  }
828  /* Conversion on injected group is stopped, but ADC not disabled since */
829  /* conversion on regular group is still running. */
830  else
831  {
832  /* Set ADC state */
833  CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
834  }
835  }
836 
837  /* Process unlocked */
838  __HAL_UNLOCK(hadc);
839 
840  /* Return function status */
841  return tmp_hal_status;
842 }
843 
844 #if defined(ADC_MULTIMODE_SUPPORT)
845 
860 HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length)
861 {
862  HAL_StatusTypeDef tmp_hal_status;
863  ADC_HandleTypeDef tmphadcSlave;
864  ADC_Common_TypeDef *tmpADC_Common;
865 
866  /* Check the parameters */
867  assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance));
868  assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ContinuousConvMode));
869  assert_param(IS_ADC_EXTTRIG_EDGE(hadc->Init.ExternalTrigConvEdge));
870  assert_param(IS_FUNCTIONAL_STATE(hadc->Init.DMAContinuousRequests));
871 
872  if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) != 0UL)
873  {
874  return HAL_BUSY;
875  }
876  else
877  {
878  /* Process locked */
879  __HAL_LOCK(hadc);
880 
881  /* Set a temporary handle of the ADC slave associated to the ADC master */
882  ADC_MULTI_SLAVE(hadc, &tmphadcSlave);
883 
884  if (tmphadcSlave.Instance == NULL)
885  {
886  /* Set ADC state */
887  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
888 
889  /* Process unlocked */
890  __HAL_UNLOCK(hadc);
891 
892  return HAL_ERROR;
893  }
894 
895  /* Enable the ADC peripherals: master and slave (in case if not already */
896  /* enabled previously) */
897  tmp_hal_status = ADC_Enable(hadc);
898  if (tmp_hal_status == HAL_OK)
899  {
900  tmp_hal_status = ADC_Enable(&tmphadcSlave);
901  }
902 
903  /* Start multimode conversion of ADCs pair */
904  if (tmp_hal_status == HAL_OK)
905  {
906  /* Set ADC state */
907  ADC_STATE_CLR_SET(hadc->State,
908  (HAL_ADC_STATE_READY | HAL_ADC_STATE_REG_EOC | HAL_ADC_STATE_REG_OVR | HAL_ADC_STATE_REG_EOSMP),
909  HAL_ADC_STATE_REG_BUSY);
910 
911  /* Set ADC error code to none */
912  ADC_CLEAR_ERRORCODE(hadc);
913 
914  /* Set the DMA transfer complete callback */
915  hadc->DMA_Handle->XferCpltCallback = ADC_DMAConvCplt;
916 
917  /* Set the DMA half transfer complete callback */
918  hadc->DMA_Handle->XferHalfCpltCallback = ADC_DMAHalfConvCplt;
919 
920  /* Set the DMA error callback */
921  hadc->DMA_Handle->XferErrorCallback = ADC_DMAError ;
922 
923  /* Pointer to the common control register */
924  tmpADC_Common = __LL_ADC_COMMON_INSTANCE(hadc->Instance);
925 
926  /* Manage ADC and DMA start: ADC overrun interruption, DMA start, ADC */
927  /* start (in case of SW start): */
928 
929  /* Clear regular group conversion flag and overrun flag */
930  /* (To ensure of no unknown state from potential previous ADC operations) */
931  __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_EOC | ADC_FLAG_EOS | ADC_FLAG_OVR));
932 
933  /* Process unlocked */
934  /* Unlock before starting ADC conversions: in case of potential */
935  /* interruption, to let the process to ADC IRQ Handler. */
936  __HAL_UNLOCK(hadc);
937 
938  /* Enable ADC overrun interrupt */
939  __HAL_ADC_ENABLE_IT(hadc, ADC_IT_OVR);
940 
941  /* Start the DMA channel */
942  tmp_hal_status = HAL_DMA_Start_IT(hadc->DMA_Handle, (uint32_t)&tmpADC_Common->CDR, (uint32_t)pData, Length);
943 
944  /* Enable conversion of regular group. */
945  /* If software start has been selected, conversion starts immediately. */
946  /* If external trigger has been selected, conversion will start at next */
947  /* trigger event. */
948  /* Start ADC group regular conversion */
949  LL_ADC_REG_StartConversion(hadc->Instance);
950  }
951  else
952  {
953  /* Process unlocked */
954  __HAL_UNLOCK(hadc);
955  }
956 
957  /* Return function status */
958  return tmp_hal_status;
959  }
960 }
961 
976 {
977  HAL_StatusTypeDef tmp_hal_status;
978  uint32_t tickstart;
979  ADC_HandleTypeDef tmphadcSlave;
980  uint32_t tmphadcSlave_conversion_on_going;
981  HAL_StatusTypeDef tmphadcSlave_disable_status;
982 
983  /* Check the parameters */
984  assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance));
985 
986  /* Process locked */
987  __HAL_LOCK(hadc);
988 
989 
990  /* 1. Stop potential multimode conversion on going, on regular and injected groups */
991  tmp_hal_status = ADC_ConversionStop(hadc, ADC_REGULAR_INJECTED_GROUP);
992 
993  /* Disable ADC peripheral if conversions are effectively stopped */
994  if (tmp_hal_status == HAL_OK)
995  {
996  /* Set a temporary handle of the ADC slave associated to the ADC master */
997  ADC_MULTI_SLAVE(hadc, &tmphadcSlave);
998 
999  if (tmphadcSlave.Instance == NULL)
1000  {
1001  /* Update ADC state machine to error */
1002  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
1003 
1004  /* Process unlocked */
1005  __HAL_UNLOCK(hadc);
1006 
1007  return HAL_ERROR;
1008  }
1009 
1010  /* Procedure to disable the ADC peripheral: wait for conversions */
1011  /* effectively stopped (ADC master and ADC slave), then disable ADC */
1012 
1013  /* 1. Wait for ADC conversion completion for ADC master and ADC slave */
1014  tickstart = HAL_GetTick();
1015 
1016  tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance);
1017  while ((LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 1UL)
1018  || (tmphadcSlave_conversion_on_going == 1UL)
1019  )
1020  {
1021  if ((HAL_GetTick() - tickstart) > ADC_STOP_CONVERSION_TIMEOUT)
1022  {
1023  /* Update ADC state machine to error */
1024  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
1025 
1026  /* Process unlocked */
1027  __HAL_UNLOCK(hadc);
1028 
1029  return HAL_ERROR;
1030  }
1031 
1032  tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance);
1033  }
1034 
1035  /* Disable the DMA channel (in case of DMA in circular mode or stop */
1036  /* while DMA transfer is on going) */
1037  /* Note: DMA channel of ADC slave should be stopped after this function */
1038  /* with HAL_ADC_Stop_DMA() API. */
1039  tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle);
1040 
1041  /* Check if DMA channel effectively disabled */
1042  if (tmp_hal_status == HAL_ERROR)
1043  {
1044  /* Update ADC state machine to error */
1045  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_DMA);
1046  }
1047 
1048  /* Disable ADC overrun interrupt */
1049  __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR);
1050 
1051  /* 2. Disable the ADC peripherals: master and slave */
1052  /* Update "tmp_hal_status" only if DMA channel disabling passed, to keep in */
1053  /* memory a potential failing status. */
1054  if (tmp_hal_status == HAL_OK)
1055  {
1056  tmphadcSlave_disable_status = ADC_Disable(&tmphadcSlave);
1057  if ((ADC_Disable(hadc) == HAL_OK) &&
1058  (tmphadcSlave_disable_status == HAL_OK))
1059  {
1060  tmp_hal_status = HAL_OK;
1061  }
1062  }
1063  else
1064  {
1065  /* In case of error, attempt to disable ADC master and slave without status assert */
1066  (void) ADC_Disable(hadc);
1067  (void) ADC_Disable(&tmphadcSlave);
1068  }
1069 
1070  /* Set ADC state (ADC master) */
1071  ADC_STATE_CLR_SET(hadc->State,
1072  HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
1073  HAL_ADC_STATE_READY);
1074  }
1075 
1076  /* Process unlocked */
1077  __HAL_UNLOCK(hadc);
1078 
1079  /* Return function status */
1080  return tmp_hal_status;
1081 }
1082 
1089 {
1090  const ADC_Common_TypeDef *tmpADC_Common;
1091 
1092  /* Check the parameters */
1093  assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance));
1094 
1095  /* Prevent unused argument(s) compilation warning if no assert_param check */
1096  /* and possible no usage in __LL_ADC_COMMON_INSTANCE() below */
1097  UNUSED(hadc);
1098 
1099  /* Pointer to the common control register */
1100  tmpADC_Common = __LL_ADC_COMMON_INSTANCE(hadc->Instance);
1101 
1102  /* Return the multi mode conversion value */
1103  return tmpADC_Common->CDR;
1104 }
1105 #endif /* ADC_MULTIMODE_SUPPORT */
1106 
1135 uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef *hadc, uint32_t InjectedRank)
1136 {
1137  uint32_t tmp_jdr;
1138 
1139  /* Check the parameters */
1140  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1141  assert_param(IS_ADC_INJECTED_RANK(InjectedRank));
1142 
1143  /* Get ADC converted value */
1144  switch (InjectedRank)
1145  {
1146  case ADC_INJECTED_RANK_4:
1147  tmp_jdr = hadc->Instance->JDR4;
1148  break;
1149  case ADC_INJECTED_RANK_3:
1150  tmp_jdr = hadc->Instance->JDR3;
1151  break;
1152  case ADC_INJECTED_RANK_2:
1153  tmp_jdr = hadc->Instance->JDR2;
1154  break;
1155  case ADC_INJECTED_RANK_1:
1156  default:
1157  tmp_jdr = hadc->Instance->JDR1;
1158  break;
1159  }
1160 
1161  /* Return ADC converted value */
1162  return tmp_jdr;
1163 }
1164 
1171 {
1172  /* Prevent unused argument(s) compilation warning */
1173  UNUSED(hadc);
1174 
1175  /* NOTE : This function should not be modified. When the callback is needed,
1176  function HAL_ADCEx_InjectedConvCpltCallback must be implemented in the user file.
1177  */
1178 }
1179 
1190 {
1191  /* Prevent unused argument(s) compilation warning */
1192  UNUSED(hadc);
1193 
1194  /* NOTE : This function should not be modified. When the callback is needed,
1195  function HAL_ADCEx_InjectedQueueOverflowCallback must be implemented in the user file.
1196  */
1197 }
1198 
1205 {
1206  /* Prevent unused argument(s) compilation warning */
1207  UNUSED(hadc);
1208 
1209  /* NOTE : This function should not be modified. When the callback is needed,
1210  function HAL_ADCEx_LevelOutOfWindow2Callback must be implemented in the user file.
1211  */
1212 }
1213 
1220 {
1221  /* Prevent unused argument(s) compilation warning */
1222  UNUSED(hadc);
1223 
1224  /* NOTE : This function should not be modified. When the callback is needed,
1225  function HAL_ADCEx_LevelOutOfWindow3Callback must be implemented in the user file.
1226  */
1227 }
1228 
1229 
1236 {
1237  /* Prevent unused argument(s) compilation warning */
1238  UNUSED(hadc);
1239 
1240  /* NOTE : This function should not be modified. When the callback is needed,
1241  function HAL_ADCEx_EndOfSamplingCallback must be implemented in the user file.
1242  */
1243 }
1244 
1253 {
1254  HAL_StatusTypeDef tmp_hal_status;
1255 
1256  /* Check the parameters */
1257  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1258 
1259  /* Process locked */
1260  __HAL_LOCK(hadc);
1261 
1262  /* 1. Stop potential regular conversion on going */
1263  tmp_hal_status = ADC_ConversionStop(hadc, ADC_REGULAR_GROUP);
1264 
1265  /* Disable ADC peripheral if regular conversions are effectively stopped
1266  and if no injected conversions are on-going */
1267  if (tmp_hal_status == HAL_OK)
1268  {
1269  /* Clear HAL_ADC_STATE_REG_BUSY bit */
1270  CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY);
1271 
1272  if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL)
1273  {
1274  /* 2. Disable the ADC peripheral */
1275  tmp_hal_status = ADC_Disable(hadc);
1276 
1277  /* Check if ADC is effectively disabled */
1278  if (tmp_hal_status == HAL_OK)
1279  {
1280  /* Set ADC state */
1281  ADC_STATE_CLR_SET(hadc->State,
1282  HAL_ADC_STATE_INJ_BUSY,
1283  HAL_ADC_STATE_READY);
1284  }
1285  }
1286  /* Conversion on injected group is stopped, but ADC not disabled since */
1287  /* conversion on regular group is still running. */
1288  else
1289  {
1290  SET_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
1291  }
1292  }
1293 
1294  /* Process unlocked */
1295  __HAL_UNLOCK(hadc);
1296 
1297  /* Return function status */
1298  return tmp_hal_status;
1299 }
1300 
1301 
1311 {
1312  HAL_StatusTypeDef tmp_hal_status;
1313 
1314  /* Check the parameters */
1315  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1316 
1317  /* Process locked */
1318  __HAL_LOCK(hadc);
1319 
1320  /* 1. Stop potential regular conversion on going */
1321  tmp_hal_status = ADC_ConversionStop(hadc, ADC_REGULAR_GROUP);
1322 
1323  /* Disable ADC peripheral if conversions are effectively stopped
1324  and if no injected conversion is on-going */
1325  if (tmp_hal_status == HAL_OK)
1326  {
1327  /* Clear HAL_ADC_STATE_REG_BUSY bit */
1328  CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY);
1329 
1330  /* Disable all regular-related interrupts */
1331  __HAL_ADC_DISABLE_IT(hadc, (ADC_IT_EOC | ADC_IT_EOS | ADC_IT_OVR));
1332 
1333  /* 2. Disable ADC peripheral if no injected conversions are on-going */
1334  if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL)
1335  {
1336  tmp_hal_status = ADC_Disable(hadc);
1337  /* if no issue reported */
1338  if (tmp_hal_status == HAL_OK)
1339  {
1340  /* Set ADC state */
1341  ADC_STATE_CLR_SET(hadc->State,
1342  HAL_ADC_STATE_INJ_BUSY,
1343  HAL_ADC_STATE_READY);
1344  }
1345  }
1346  else
1347  {
1348  SET_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
1349  }
1350  }
1351 
1352  /* Process unlocked */
1353  __HAL_UNLOCK(hadc);
1354 
1355  /* Return function status */
1356  return tmp_hal_status;
1357 }
1358 
1371 {
1372  HAL_StatusTypeDef tmp_hal_status;
1373 
1374  /* Check the parameters */
1375  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1376 
1377  /* Process locked */
1378  __HAL_LOCK(hadc);
1379 
1380  /* 1. Stop potential regular conversion on going */
1381  tmp_hal_status = ADC_ConversionStop(hadc, ADC_REGULAR_GROUP);
1382 
1383  /* Disable ADC peripheral if conversions are effectively stopped
1384  and if no injected conversion is on-going */
1385  if (tmp_hal_status == HAL_OK)
1386  {
1387  /* Clear HAL_ADC_STATE_REG_BUSY bit */
1388  CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY);
1389 
1390  /* Disable ADC DMA (ADC DMA configuration ADC_CFGR_DMACFG is kept) */
1391  CLEAR_BIT(hadc->Instance->CFGR, ADC_CFGR_DMAEN);
1392 
1393  /* Disable the DMA channel (in case of DMA in circular mode or stop while */
1394  /* while DMA transfer is on going) */
1395  tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle);
1396 
1397  /* Check if DMA channel effectively disabled */
1398  if (tmp_hal_status != HAL_OK)
1399  {
1400  /* Update ADC state machine to error */
1401  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_DMA);
1402  }
1403 
1404  /* Disable ADC overrun interrupt */
1405  __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR);
1406 
1407  /* 2. Disable the ADC peripheral */
1408  /* Update "tmp_hal_status" only if DMA channel disabling passed, */
1409  /* to keep in memory a potential failing status. */
1410  if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL)
1411  {
1412  if (tmp_hal_status == HAL_OK)
1413  {
1414  tmp_hal_status = ADC_Disable(hadc);
1415  }
1416  else
1417  {
1418  (void)ADC_Disable(hadc);
1419  }
1420 
1421  /* Check if ADC is effectively disabled */
1422  if (tmp_hal_status == HAL_OK)
1423  {
1424  /* Set ADC state */
1425  ADC_STATE_CLR_SET(hadc->State,
1426  HAL_ADC_STATE_INJ_BUSY,
1427  HAL_ADC_STATE_READY);
1428  }
1429  }
1430  else
1431  {
1432  SET_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
1433  }
1434  }
1435 
1436  /* Process unlocked */
1437  __HAL_UNLOCK(hadc);
1438 
1439  /* Return function status */
1440  return tmp_hal_status;
1441 }
1442 
1443 #if defined(ADC_MULTIMODE_SUPPORT)
1444 
1458 {
1459  HAL_StatusTypeDef tmp_hal_status;
1460  uint32_t tickstart;
1461  ADC_HandleTypeDef tmphadcSlave;
1462  uint32_t tmphadcSlave_conversion_on_going;
1463 
1464  /* Check the parameters */
1465  assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance));
1466 
1467  /* Process locked */
1468  __HAL_LOCK(hadc);
1469 
1470 
1471  /* 1. Stop potential multimode conversion on going, on regular groups */
1472  tmp_hal_status = ADC_ConversionStop(hadc, ADC_REGULAR_GROUP);
1473 
1474  /* Disable ADC peripheral if conversions are effectively stopped */
1475  if (tmp_hal_status == HAL_OK)
1476  {
1477  /* Clear HAL_ADC_STATE_REG_BUSY bit */
1478  CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY);
1479 
1480  /* Set a temporary handle of the ADC slave associated to the ADC master */
1481  ADC_MULTI_SLAVE(hadc, &tmphadcSlave);
1482 
1483  if (tmphadcSlave.Instance == NULL)
1484  {
1485  /* Update ADC state machine to error */
1486  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
1487 
1488  /* Process unlocked */
1489  __HAL_UNLOCK(hadc);
1490 
1491  return HAL_ERROR;
1492  }
1493 
1494  /* Procedure to disable the ADC peripheral: wait for conversions */
1495  /* effectively stopped (ADC master and ADC slave), then disable ADC */
1496 
1497  /* 1. Wait for ADC conversion completion for ADC master and ADC slave */
1498  tickstart = HAL_GetTick();
1499 
1500  tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance);
1501  while ((LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 1UL)
1502  || (tmphadcSlave_conversion_on_going == 1UL)
1503  )
1504  {
1505  if ((HAL_GetTick() - tickstart) > ADC_STOP_CONVERSION_TIMEOUT)
1506  {
1507  /* Update ADC state machine to error */
1508  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
1509 
1510  /* Process unlocked */
1511  __HAL_UNLOCK(hadc);
1512 
1513  return HAL_ERROR;
1514  }
1515 
1516  tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance);
1517  }
1518 
1519  /* Disable the DMA channel (in case of DMA in circular mode or stop */
1520  /* while DMA transfer is on going) */
1521  /* Note: DMA channel of ADC slave should be stopped after this function */
1522  /* with HAL_ADCEx_RegularStop_DMA() API. */
1523  tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle);
1524 
1525  /* Check if DMA channel effectively disabled */
1526  if (tmp_hal_status != HAL_OK)
1527  {
1528  /* Update ADC state machine to error */
1529  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_DMA);
1530  }
1531 
1532  /* Disable ADC overrun interrupt */
1533  __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR);
1534 
1535  /* 2. Disable the ADC peripherals: master and slave if no injected */
1536  /* conversion is on-going. */
1537  /* Update "tmp_hal_status" only if DMA channel disabling passed, to keep in */
1538  /* memory a potential failing status. */
1539  if (tmp_hal_status == HAL_OK)
1540  {
1541  if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL)
1542  {
1543  tmp_hal_status = ADC_Disable(hadc);
1544  if (tmp_hal_status == HAL_OK)
1545  {
1546  if (LL_ADC_INJ_IsConversionOngoing((&tmphadcSlave)->Instance) == 0UL)
1547  {
1548  tmp_hal_status = ADC_Disable(&tmphadcSlave);
1549  }
1550  }
1551  }
1552 
1553  if (tmp_hal_status == HAL_OK)
1554  {
1555  /* Both Master and Slave ADC's could be disabled. Update Master State */
1556  /* Clear HAL_ADC_STATE_INJ_BUSY bit, set HAL_ADC_STATE_READY bit */
1557  ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_BUSY, HAL_ADC_STATE_READY);
1558  }
1559  else
1560  {
1561  /* injected (Master or Slave) conversions are still on-going,
1562  no Master State change */
1563  }
1564  }
1565  }
1566 
1567  /* Process unlocked */
1568  __HAL_UNLOCK(hadc);
1569 
1570  /* Return function status */
1571  return tmp_hal_status;
1572 }
1573 #endif /* ADC_MULTIMODE_SUPPORT */
1574 
1632 {
1633  HAL_StatusTypeDef tmp_hal_status = HAL_OK;
1634  uint32_t tmpOffsetShifted;
1635  uint32_t tmp_config_internal_channel;
1636  uint32_t tmp_adc_is_conversion_on_going_regular;
1637  uint32_t tmp_adc_is_conversion_on_going_injected;
1638  __IO uint32_t wait_loop_index = 0;
1639 
1640  uint32_t tmp_JSQR_ContextQueueBeingBuilt = 0U;
1641 
1642  /* Check the parameters */
1643  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1644  assert_param(IS_ADC_SAMPLE_TIME(sConfigInjected->InjectedSamplingTime));
1645  assert_param(IS_ADC_SINGLE_DIFFERENTIAL(sConfigInjected->InjectedSingleDiff));
1646  assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->AutoInjectedConv));
1647  assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->QueueInjectedContext));
1648  assert_param(IS_ADC_EXTTRIGINJEC_EDGE(sConfigInjected->ExternalTrigInjecConvEdge));
1649  assert_param(IS_ADC_EXTTRIGINJEC(hadc, sConfigInjected->ExternalTrigInjecConv));
1650  assert_param(IS_ADC_OFFSET_NUMBER(sConfigInjected->InjectedOffsetNumber));
1651  assert_param(IS_ADC_RANGE(ADC_GET_RESOLUTION(hadc), sConfigInjected->InjectedOffset));
1652  assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->InjecOversamplingMode));
1653 
1654  if (hadc->Init.ScanConvMode != ADC_SCAN_DISABLE)
1655  {
1656  assert_param(IS_ADC_INJECTED_RANK(sConfigInjected->InjectedRank));
1657  assert_param(IS_ADC_INJECTED_NB_CONV(sConfigInjected->InjectedNbrOfConversion));
1658  assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->InjectedDiscontinuousConvMode));
1659  }
1660 
1661 
1662  /* if JOVSE is set, the value of the OFFSETy_EN bit in ADCx_OFRy register is
1663  ignored (considered as reset) */
1664  assert_param(!((sConfigInjected->InjectedOffsetNumber != ADC_OFFSET_NONE) && (sConfigInjected->InjecOversamplingMode == ENABLE)));
1665 
1666  /* JDISCEN and JAUTO bits can't be set at the same time */
1667  assert_param(!((sConfigInjected->InjectedDiscontinuousConvMode == ENABLE) && (sConfigInjected->AutoInjectedConv == ENABLE)));
1668 
1669  /* DISCEN and JAUTO bits can't be set at the same time */
1670  assert_param(!((hadc->Init.DiscontinuousConvMode == ENABLE) && (sConfigInjected->AutoInjectedConv == ENABLE)));
1671 
1672  /* Verification of channel number */
1673  if (sConfigInjected->InjectedSingleDiff != ADC_DIFFERENTIAL_ENDED)
1674  {
1675  assert_param(IS_ADC_CHANNEL(hadc, sConfigInjected->InjectedChannel));
1676  }
1677  else
1678  {
1679  assert_param(IS_ADC_DIFF_CHANNEL(hadc, sConfigInjected->InjectedChannel));
1680  }
1681 
1682  /* Process locked */
1683  __HAL_LOCK(hadc);
1684 
1685  /* Configuration of injected group sequencer: */
1686  /* Hardware constraint: Must fully define injected context register JSQR */
1687  /* before make it entering into injected sequencer queue. */
1688  /* */
1689  /* - if scan mode is disabled: */
1690  /* * Injected channels sequence length is set to 0x00: 1 channel */
1691  /* converted (channel on injected rank 1) */
1692  /* Parameter "InjectedNbrOfConversion" is discarded. */
1693  /* * Injected context register JSQR setting is simple: register is fully */
1694  /* defined on one call of this function (for injected rank 1) and can */
1695  /* be entered into queue directly. */
1696  /* - if scan mode is enabled: */
1697  /* * Injected channels sequence length is set to parameter */
1698  /* "InjectedNbrOfConversion". */
1699  /* * Injected context register JSQR setting more complex: register is */
1700  /* fully defined over successive calls of this function, for each */
1701  /* injected channel rank. It is entered into queue only when all */
1702  /* injected ranks have been set. */
1703  /* Note: Scan mode is not present by hardware on this device, but used */
1704  /* by software for alignment over all STM32 devices. */
1705 
1706  if ((hadc->Init.ScanConvMode == ADC_SCAN_DISABLE) ||
1707  (sConfigInjected->InjectedNbrOfConversion == 1U))
1708  {
1709  /* Configuration of context register JSQR: */
1710  /* - number of ranks in injected group sequencer: fixed to 1st rank */
1711  /* (scan mode disabled, only rank 1 used) */
1712  /* - external trigger to start conversion */
1713  /* - external trigger polarity */
1714  /* - channel set to rank 1 (scan mode disabled, only rank 1 can be used) */
1715 
1716  if (sConfigInjected->InjectedRank == ADC_INJECTED_RANK_1)
1717  {
1718  /* Enable external trigger if trigger selection is different of */
1719  /* software start. */
1720  /* Note: This configuration keeps the hardware feature of parameter */
1721  /* ExternalTrigInjecConvEdge "trigger edge none" equivalent to */
1722  /* software start. */
1723  if (sConfigInjected->ExternalTrigInjecConv != ADC_INJECTED_SOFTWARE_START)
1724  {
1725  tmp_JSQR_ContextQueueBeingBuilt = (ADC_JSQR_RK(sConfigInjected->InjectedChannel, ADC_INJECTED_RANK_1)
1726  | (sConfigInjected->ExternalTrigInjecConv & ADC_JSQR_JEXTSEL)
1727  | sConfigInjected->ExternalTrigInjecConvEdge
1728  );
1729  }
1730  else
1731  {
1732  tmp_JSQR_ContextQueueBeingBuilt = (ADC_JSQR_RK(sConfigInjected->InjectedChannel, ADC_INJECTED_RANK_1));
1733  }
1734 
1735  MODIFY_REG(hadc->Instance->JSQR, ADC_JSQR_FIELDS, tmp_JSQR_ContextQueueBeingBuilt);
1736  /* For debug and informative reasons, hadc handle saves JSQR setting */
1737  hadc->InjectionConfig.ContextQueue = tmp_JSQR_ContextQueueBeingBuilt;
1738 
1739  }
1740  }
1741  else
1742  {
1743  /* Case of scan mode enabled, several channels to set into injected group */
1744  /* sequencer. */
1745  /* */
1746  /* Procedure to define injected context register JSQR over successive */
1747  /* calls of this function, for each injected channel rank: */
1748  /* 1. Start new context and set parameters related to all injected */
1749  /* channels: injected sequence length and trigger. */
1750 
1751  /* if hadc->InjectionConfig.ChannelCount is equal to 0, this is the first */
1752  /* call of the context under setting */
1753  if (hadc->InjectionConfig.ChannelCount == 0U)
1754  {
1755  /* Initialize number of channels that will be configured on the context */
1756  /* being built */
1757  hadc->InjectionConfig.ChannelCount = sConfigInjected->InjectedNbrOfConversion;
1758  /* Handle hadc saves the context under build up over each HAL_ADCEx_InjectedConfigChannel()
1759  call, this context will be written in JSQR register at the last call.
1760  At this point, the context is merely reset */
1761  hadc->InjectionConfig.ContextQueue = 0x00000000U;
1762 
1763  /* Configuration of context register JSQR: */
1764  /* - number of ranks in injected group sequencer */
1765  /* - external trigger to start conversion */
1766  /* - external trigger polarity */
1767 
1768  /* Enable external trigger if trigger selection is different of */
1769  /* software start. */
1770  /* Note: This configuration keeps the hardware feature of parameter */
1771  /* ExternalTrigInjecConvEdge "trigger edge none" equivalent to */
1772  /* software start. */
1773  if (sConfigInjected->ExternalTrigInjecConv != ADC_INJECTED_SOFTWARE_START)
1774  {
1775  tmp_JSQR_ContextQueueBeingBuilt = ((sConfigInjected->InjectedNbrOfConversion - 1U)
1776  | (sConfigInjected->ExternalTrigInjecConv & ADC_JSQR_JEXTSEL)
1777  | sConfigInjected->ExternalTrigInjecConvEdge
1778  );
1779  }
1780  else
1781  {
1782  tmp_JSQR_ContextQueueBeingBuilt = ((sConfigInjected->InjectedNbrOfConversion - 1U));
1783  }
1784 
1785  }
1786 
1787  /* 2. Continue setting of context under definition with parameter */
1788  /* related to each channel: channel rank sequence */
1789  /* Clear the old JSQx bits for the selected rank */
1790  tmp_JSQR_ContextQueueBeingBuilt &= ~ADC_JSQR_RK(ADC_SQR3_SQ10, sConfigInjected->InjectedRank);
1791 
1792  /* Set the JSQx bits for the selected rank */
1793  tmp_JSQR_ContextQueueBeingBuilt |= ADC_JSQR_RK(sConfigInjected->InjectedChannel, sConfigInjected->InjectedRank);
1794 
1795  /* Decrease channel count */
1796  hadc->InjectionConfig.ChannelCount--;
1797 
1798  /* 3. tmp_JSQR_ContextQueueBeingBuilt is fully built for this HAL_ADCEx_InjectedConfigChannel()
1799  call, aggregate the setting to those already built during the previous
1800  HAL_ADCEx_InjectedConfigChannel() calls (for the same context of course) */
1801  hadc->InjectionConfig.ContextQueue |= tmp_JSQR_ContextQueueBeingBuilt;
1802 
1803  /* 4. End of context setting: if this is the last channel set, then write context
1804  into register JSQR and make it enter into queue */
1805  if (hadc->InjectionConfig.ChannelCount == 0U)
1806  {
1807  MODIFY_REG(hadc->Instance->JSQR, ADC_JSQR_FIELDS, hadc->InjectionConfig.ContextQueue);
1808  }
1809  }
1810 
1811  /* Parameters update conditioned to ADC state: */
1812  /* Parameters that can be updated when ADC is disabled or enabled without */
1813  /* conversion on going on injected group: */
1814  /* - Injected context queue: Queue disable (active context is kept) or */
1815  /* enable (context decremented, up to 2 contexts queued) */
1816  /* - Injected discontinuous mode: can be enabled only if auto-injected */
1817  /* mode is disabled. */
1818  if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL)
1819  {
1820  /* If auto-injected mode is disabled: no constraint */
1821  if (sConfigInjected->AutoInjectedConv == DISABLE)
1822  {
1823  MODIFY_REG(hadc->Instance->CFGR,
1824  ADC_CFGR_JQM | ADC_CFGR_JDISCEN,
1825  ADC_CFGR_INJECT_CONTEXT_QUEUE((uint32_t)sConfigInjected->QueueInjectedContext) |
1826  ADC_CFGR_INJECT_DISCCONTINUOUS((uint32_t)sConfigInjected->InjectedDiscontinuousConvMode));
1827  }
1828  /* If auto-injected mode is enabled: Injected discontinuous setting is */
1829  /* discarded. */
1830  else
1831  {
1832  MODIFY_REG(hadc->Instance->CFGR,
1833  ADC_CFGR_JQM | ADC_CFGR_JDISCEN,
1834  ADC_CFGR_INJECT_CONTEXT_QUEUE((uint32_t)sConfigInjected->QueueInjectedContext));
1835  }
1836 
1837  }
1838 
1839  /* Parameters update conditioned to ADC state: */
1840  /* Parameters that can be updated when ADC is disabled or enabled without */
1841  /* conversion on going on regular and injected groups: */
1842  /* - Automatic injected conversion: can be enabled if injected group */
1843  /* external triggers are disabled. */
1844  /* - Channel sampling time */
1845  /* - Channel offset */
1846  tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
1847  tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance);
1848 
1849  if ((tmp_adc_is_conversion_on_going_regular == 0UL)
1850  && (tmp_adc_is_conversion_on_going_injected == 0UL)
1851  )
1852  {
1853  /* If injected group external triggers are disabled (set to injected */
1854  /* software start): no constraint */
1855  if ((sConfigInjected->ExternalTrigInjecConv == ADC_INJECTED_SOFTWARE_START)
1856  || (sConfigInjected->ExternalTrigInjecConvEdge == ADC_EXTERNALTRIGINJECCONV_EDGE_NONE))
1857  {
1858  if (sConfigInjected->AutoInjectedConv == ENABLE)
1859  {
1860  SET_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO);
1861  }
1862  else
1863  {
1864  CLEAR_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO);
1865  }
1866  }
1867  /* If Automatic injected conversion was intended to be set and could not */
1868  /* due to injected group external triggers enabled, error is reported. */
1869  else
1870  {
1871  if (sConfigInjected->AutoInjectedConv == ENABLE)
1872  {
1873  /* Update ADC state machine to error */
1874  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
1875 
1876  tmp_hal_status = HAL_ERROR;
1877  }
1878  else
1879  {
1880  CLEAR_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO);
1881  }
1882  }
1883 
1884  if (sConfigInjected->InjecOversamplingMode == ENABLE)
1885  {
1886  assert_param(IS_ADC_OVERSAMPLING_RATIO(sConfigInjected->InjecOversampling.Ratio));
1887  assert_param(IS_ADC_RIGHT_BIT_SHIFT(sConfigInjected->InjecOversampling.RightBitShift));
1888 
1889  /* JOVSE must be reset in case of triggered regular mode */
1890  assert_param(!(READ_BIT(hadc->Instance->CFGR2, ADC_CFGR2_ROVSE | ADC_CFGR2_TROVS) == (ADC_CFGR2_ROVSE | ADC_CFGR2_TROVS)));
1891 
1892  /* Configuration of Injected Oversampler: */
1893  /* - Oversampling Ratio */
1894  /* - Right bit shift */
1895 
1896  /* Enable OverSampling mode */
1897  MODIFY_REG(hadc->Instance->CFGR2,
1898  ADC_CFGR2_JOVSE |
1899  ADC_CFGR2_OVSR |
1900  ADC_CFGR2_OVSS,
1901  ADC_CFGR2_JOVSE |
1902  sConfigInjected->InjecOversampling.Ratio |
1903  sConfigInjected->InjecOversampling.RightBitShift
1904  );
1905  }
1906  else
1907  {
1908  /* Disable Regular OverSampling */
1909  CLEAR_BIT(hadc->Instance->CFGR2, ADC_CFGR2_JOVSE);
1910  }
1911 
1912 #if defined(ADC_SMPR1_SMPPLUS)
1913  /* Manage specific case of sampling time 3.5 cycles replacing 2.5 cyles */
1914  if (sConfigInjected->InjectedSamplingTime == ADC_SAMPLETIME_3CYCLES_5)
1915  {
1916  /* Set sampling time of the selected ADC channel */
1917  LL_ADC_SetChannelSamplingTime(hadc->Instance, sConfigInjected->InjectedChannel, LL_ADC_SAMPLINGTIME_2CYCLES_5);
1918 
1919  /* Set ADC sampling time common configuration */
1920  LL_ADC_SetSamplingTimeCommonConfig(hadc->Instance, LL_ADC_SAMPLINGTIME_COMMON_3C5_REPL_2C5);
1921  }
1922  else
1923  {
1924  /* Set sampling time of the selected ADC channel */
1925  LL_ADC_SetChannelSamplingTime(hadc->Instance, sConfigInjected->InjectedChannel, sConfigInjected->InjectedSamplingTime);
1926 
1927  /* Set ADC sampling time common configuration */
1928  LL_ADC_SetSamplingTimeCommonConfig(hadc->Instance, LL_ADC_SAMPLINGTIME_COMMON_DEFAULT);
1929  }
1930 #else
1931  /* Set sampling time of the selected ADC channel */
1932  LL_ADC_SetChannelSamplingTime(hadc->Instance, sConfigInjected->InjectedChannel, sConfigInjected->InjectedSamplingTime);
1933 #endif
1934 
1935  /* Configure the offset: offset enable/disable, channel, offset value */
1936 
1937  /* Shift the offset with respect to the selected ADC resolution. */
1938  /* Offset has to be left-aligned on bit 11, the LSB (right bits) are set to 0 */
1939  tmpOffsetShifted = ADC_OFFSET_SHIFT_RESOLUTION(hadc, sConfigInjected->InjectedOffset);
1940 
1941  if (sConfigInjected->InjectedOffsetNumber != ADC_OFFSET_NONE)
1942  {
1943  /* Set ADC selected offset number */
1944  LL_ADC_SetOffset(hadc->Instance, sConfigInjected->InjectedOffsetNumber, sConfigInjected->InjectedChannel,
1945  tmpOffsetShifted);
1946 
1947  }
1948  else
1949  {
1950  /* Scan each offset register to check if the selected channel is targeted. */
1951  /* If this is the case, the corresponding offset number is disabled. */
1952  if(__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_1)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel))
1953  {
1954  LL_ADC_SetOffsetState(hadc->Instance, LL_ADC_OFFSET_1, LL_ADC_OFFSET_DISABLE);
1955  }
1956  if(__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_2)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel))
1957  {
1958  LL_ADC_SetOffsetState(hadc->Instance, LL_ADC_OFFSET_2, LL_ADC_OFFSET_DISABLE);
1959  }
1960  if(__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_3)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel))
1961  {
1962  LL_ADC_SetOffsetState(hadc->Instance, LL_ADC_OFFSET_3, LL_ADC_OFFSET_DISABLE);
1963  }
1964  if(__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_4)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel))
1965  {
1966  LL_ADC_SetOffsetState(hadc->Instance, LL_ADC_OFFSET_4, LL_ADC_OFFSET_DISABLE);
1967  }
1968  }
1969 
1970  }
1971 
1972  /* Parameters update conditioned to ADC state: */
1973  /* Parameters that can be updated only when ADC is disabled: */
1974  /* - Single or differential mode */
1975  if (LL_ADC_IsEnabled(hadc->Instance) == 0UL)
1976  {
1977  /* Set mode single-ended or differential input of the selected ADC channel */
1978  LL_ADC_SetChannelSingleDiff(hadc->Instance, sConfigInjected->InjectedChannel, sConfigInjected->InjectedSingleDiff);
1979 
1980  /* Configuration of differential mode */
1981  /* Note: ADC channel number masked with value "0x1F" to ensure shift value within 32 bits range */
1982  if (sConfigInjected->InjectedSingleDiff == ADC_DIFFERENTIAL_ENDED)
1983  {
1984  /* Set sampling time of the selected ADC channel */
1985  LL_ADC_SetChannelSamplingTime(hadc->Instance, (uint32_t)(__LL_ADC_DECIMAL_NB_TO_CHANNEL((__LL_ADC_CHANNEL_TO_DECIMAL_NB((uint32_t)sConfigInjected->InjectedChannel) + 1UL) & 0x1FUL)), sConfigInjected->InjectedSamplingTime);
1986  }
1987 
1988  }
1989 
1990  /* Management of internal measurement channels: Vbat/VrefInt/TempSensor */
1991  /* internal measurement paths enable: If internal channel selected, */
1992  /* enable dedicated internal buffers and path. */
1993  /* Note: these internal measurement paths can be disabled using */
1994  /* HAL_ADC_DeInit(). */
1995 
1996  if (__LL_ADC_IS_CHANNEL_INTERNAL(sConfigInjected->InjectedChannel))
1997  {
1998  tmp_config_internal_channel = LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
1999 
2000  /* If the requested internal measurement path has already been enabled, */
2001  /* bypass the configuration processing. */
2002  if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR)
2003  && ((tmp_config_internal_channel & LL_ADC_PATH_INTERNAL_TEMPSENSOR) == 0UL))
2004  {
2005  if (ADC_TEMPERATURE_SENSOR_INSTANCE(hadc))
2006  {
2007  LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance),
2008  LL_ADC_PATH_INTERNAL_TEMPSENSOR | tmp_config_internal_channel);
2009 
2010  /* Delay for temperature sensor stabilization time */
2011  /* Wait loop initialization and execution */
2012  /* Note: Variable divided by 2 to compensate partially */
2013  /* CPU processing cycles, scaling in us split to not */
2014  /* exceed 32 bits register capacity and handle low frequency. */
2015  wait_loop_index = ((LL_ADC_DELAY_TEMPSENSOR_STAB_US / 10UL) * (SystemCoreClock / (100000UL * 2UL)));
2016  while (wait_loop_index != 0UL)
2017  {
2018  wait_loop_index--;
2019  }
2020  }
2021  }
2022  else if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_VBAT)
2023  && ((tmp_config_internal_channel & LL_ADC_PATH_INTERNAL_VBAT) == 0UL))
2024  {
2025  if (ADC_BATTERY_VOLTAGE_INSTANCE(hadc))
2026  {
2027  LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance),
2028  LL_ADC_PATH_INTERNAL_VBAT | tmp_config_internal_channel);
2029  }
2030  }
2031  else if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT)
2032  && ((tmp_config_internal_channel & LL_ADC_PATH_INTERNAL_VREFINT) == 0UL))
2033  {
2034  if (ADC_VREFINT_INSTANCE(hadc))
2035  {
2036  LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance),
2037  LL_ADC_PATH_INTERNAL_VREFINT | tmp_config_internal_channel);
2038  }
2039  }
2040  else
2041  {
2042  /* nothing to do */
2043  }
2044  }
2045 
2046  /* Process unlocked */
2047  __HAL_UNLOCK(hadc);
2048 
2049  /* Return function status */
2050  return tmp_hal_status;
2051 }
2052 
2053 #if defined(ADC_MULTIMODE_SUPPORT)
2054 
2071 {
2072  HAL_StatusTypeDef tmp_hal_status = HAL_OK;
2073  ADC_Common_TypeDef *tmpADC_Common;
2074  ADC_HandleTypeDef tmphadcSlave;
2075  uint32_t tmphadcSlave_conversion_on_going;
2076 
2077  /* Check the parameters */
2078  assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance));
2079  assert_param(IS_ADC_MULTIMODE(multimode->Mode));
2080  if (multimode->Mode != ADC_MODE_INDEPENDENT)
2081  {
2082  assert_param(IS_ADC_DMA_ACCESS_MULTIMODE(multimode->DMAAccessMode));
2083  assert_param(IS_ADC_SAMPLING_DELAY(multimode->TwoSamplingDelay));
2084  }
2085 
2086  /* Process locked */
2087  __HAL_LOCK(hadc);
2088 
2089  ADC_MULTI_SLAVE(hadc, &tmphadcSlave);
2090 
2091  if (tmphadcSlave.Instance == NULL)
2092  {
2093  /* Update ADC state machine to error */
2094  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
2095 
2096  /* Process unlocked */
2097  __HAL_UNLOCK(hadc);
2098 
2099  return HAL_ERROR;
2100  }
2101 
2102  /* Parameters update conditioned to ADC state: */
2103  /* Parameters that can be updated when ADC is disabled or enabled without */
2104  /* conversion on going on regular group: */
2105  /* - Multimode DMA configuration */
2106  /* - Multimode DMA mode */
2107  tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance);
2108  if ((LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL)
2109  && (tmphadcSlave_conversion_on_going == 0UL))
2110  {
2111  /* Pointer to the common control register */
2112  tmpADC_Common = __LL_ADC_COMMON_INSTANCE(hadc->Instance);
2113 
2114  /* If multimode is selected, configure all multimode parameters. */
2115  /* Otherwise, reset multimode parameters (can be used in case of */
2116  /* transition from multimode to independent mode). */
2117  if (multimode->Mode != ADC_MODE_INDEPENDENT)
2118  {
2119  MODIFY_REG(tmpADC_Common->CCR, ADC_CCR_MDMA | ADC_CCR_DMACFG,
2120  multimode->DMAAccessMode |
2121  ADC_CCR_MULTI_DMACONTREQ((uint32_t)hadc->Init.DMAContinuousRequests));
2122 
2123  /* Parameters that can be updated only when ADC is disabled: */
2124  /* - Multimode mode selection */
2125  /* - Multimode delay */
2126  /* Note: Delay range depends on selected resolution: */
2127  /* from 1 to 12 clock cycles for 12 bits */
2128  /* from 1 to 10 clock cycles for 10 bits, */
2129  /* from 1 to 8 clock cycles for 8 bits */
2130  /* from 1 to 6 clock cycles for 6 bits */
2131  /* If a higher delay is selected, it will be clipped to maximum delay */
2132  /* range */
2133  if (__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) == 0UL)
2134  {
2135  MODIFY_REG(tmpADC_Common->CCR,
2136  ADC_CCR_DUAL |
2137  ADC_CCR_DELAY,
2138  multimode->Mode |
2139  multimode->TwoSamplingDelay
2140  );
2141  }
2142  }
2143  else /* ADC_MODE_INDEPENDENT */
2144  {
2145  CLEAR_BIT(tmpADC_Common->CCR, ADC_CCR_MDMA | ADC_CCR_DMACFG);
2146 
2147  /* Parameters that can be updated only when ADC is disabled: */
2148  /* - Multimode mode selection */
2149  /* - Multimode delay */
2150  if (__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) == 0UL)
2151  {
2152  CLEAR_BIT(tmpADC_Common->CCR, ADC_CCR_DUAL | ADC_CCR_DELAY);
2153  }
2154  }
2155  }
2156  /* If one of the ADC sharing the same common group is enabled, no update */
2157  /* could be done on neither of the multimode structure parameters. */
2158  else
2159  {
2160  /* Update ADC state machine to error */
2161  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
2162 
2163  tmp_hal_status = HAL_ERROR;
2164  }
2165 
2166  /* Process unlocked */
2167  __HAL_UNLOCK(hadc);
2168 
2169  /* Return function status */
2170  return tmp_hal_status;
2171 }
2172 #endif /* ADC_MULTIMODE_SUPPORT */
2173 
2184 {
2185  HAL_StatusTypeDef tmp_hal_status;
2186  uint32_t tmp_adc_is_conversion_on_going_regular;
2187  uint32_t tmp_adc_is_conversion_on_going_injected;
2188 
2189  /* Check the parameters */
2190  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
2191 
2192  tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
2193  tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance);
2194 
2195  /* Parameter can be set only if no conversion is on-going */
2196  if ((tmp_adc_is_conversion_on_going_regular == 0UL)
2197  && (tmp_adc_is_conversion_on_going_injected == 0UL)
2198  )
2199  {
2200  CLEAR_BIT(hadc->Instance->CFGR, ADC_CFGR_JQDIS);
2201 
2202  /* Update state, clear previous result related to injected queue overflow */
2203  CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_JQOVF);
2204 
2205  tmp_hal_status = HAL_OK;
2206  }
2207  else
2208  {
2209  tmp_hal_status = HAL_ERROR;
2210  }
2211 
2212  return tmp_hal_status;
2213 }
2214 
2225 {
2226  HAL_StatusTypeDef tmp_hal_status;
2227  uint32_t tmp_adc_is_conversion_on_going_regular;
2228  uint32_t tmp_adc_is_conversion_on_going_injected;
2229 
2230  /* Check the parameters */
2231  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
2232 
2233  tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
2234  tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance);
2235 
2236  /* Parameter can be set only if no conversion is on-going */
2237  if ((tmp_adc_is_conversion_on_going_regular == 0UL)
2238  && (tmp_adc_is_conversion_on_going_injected == 0UL)
2239  )
2240  {
2241  LL_ADC_INJ_SetQueueMode(hadc->Instance, LL_ADC_INJ_QUEUE_DISABLE);
2242  tmp_hal_status = HAL_OK;
2243  }
2244  else
2245  {
2246  tmp_hal_status = HAL_ERROR;
2247  }
2248 
2249  return tmp_hal_status;
2250 }
2251 
2262 {
2263  HAL_StatusTypeDef tmp_hal_status;
2264 
2265  /* Check the parameters */
2266  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
2267 
2268  /* Setting of this feature is conditioned to ADC state: ADC must be ADC disabled */
2269  if (LL_ADC_IsEnabled(hadc->Instance) == 0UL)
2270  {
2271  LL_ADC_DisableInternalRegulator(hadc->Instance);
2272  tmp_hal_status = HAL_OK;
2273  }
2274  else
2275  {
2276  tmp_hal_status = HAL_ERROR;
2277  }
2278 
2279  return tmp_hal_status;
2280 }
2281 
2299 {
2300  HAL_StatusTypeDef tmp_hal_status;
2301 
2302  /* Check the parameters */
2303  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
2304 
2305  /* Setting of this feature is conditioned to ADC state: ADC must be ADC disabled */
2306  if (LL_ADC_IsEnabled(hadc->Instance) == 0UL)
2307  {
2308  LL_ADC_EnableDeepPowerDown(hadc->Instance);
2309  tmp_hal_status = HAL_OK;
2310  }
2311  else
2312  {
2313  tmp_hal_status = HAL_ERROR;
2314  }
2315 
2316  return tmp_hal_status;
2317 }
2318 
2327 #endif /* HAL_ADC_MODULE_ENABLED */
2328 
2336 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
HAL_StatusTypeDef HAL_ADCEx_DisableInjectedQueue(ADC_HandleTypeDef *hadc)
Disable Injected Queue.
__STATIC_INLINE void LL_ADC_DisableInternalRegulator(ADC_TypeDef *ADCx)
Disable ADC internal voltage regulator.
HAL_StatusTypeDef HAL_ADCEx_Calibration_SetValue(ADC_HandleTypeDef *hadc, uint32_t SingleDiff, uint32_t CalibrationFactor)
Set the calibration factor to overwrite automatic conversion result. ADC must be enabled and no conve...
__STATIC_INLINE uint32_t LL_ADC_REG_IsTriggerSourceSWStart(ADC_TypeDef *ADCx)
Get ADC group regular conversion trigger source internal (SW start) or external.
HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef *hadc, uint32_t Timeout)
Wait for injected group conversion to be completed.
HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef *hadc)
Stop conversion of injected channels, disable interruption of end-of-conversion. Disable ADC peripher...
__STATIC_INLINE uint32_t LL_ADC_IsEnabled(ADC_TypeDef *ADCx)
Get the selected ADC instance enable state.
void HAL_ADCEx_LevelOutOfWindow2Callback(ADC_HandleTypeDef *hadc)
Analog watchdog 2 callback in non-blocking mode.
__STATIC_INLINE void LL_ADC_SetCalibrationFactor(ADC_TypeDef *ADCx, uint32_t SingleDiff, uint32_t CalibrationFactor)
Set ADC calibration factor in the mode single-ended or differential (for devices with differential mo...
__STATIC_INLINE uint32_t LL_ADC_GetOffsetChannel(ADC_TypeDef *ADCx, uint32_t Offsety)
Get for the ADC selected offset number 1, 2, 3 or 4: Channel to which the offset programmed will be a...
This file contains all the functions prototypes for the HAL module driver.
uint32_t HAL_ADCEx_Calibration_GetValue(ADC_HandleTypeDef *hadc, uint32_t SingleDiff)
Get the calibration factor.
HAL_StatusTypeDef HAL_ADCEx_RegularStop_DMA(ADC_HandleTypeDef *hadc)
Stop ADC conversion of regular group (and injected group in case of auto_injection mode)...
uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef *hadc, uint32_t InjectedRank)
Get ADC injected group conversion result.
HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef *hadc)
Stop conversion of injected channels. Disable ADC peripheral if no regular conversion is on going...
void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef *hadc)
Injected conversion complete callback in non-blocking mode.
__STATIC_INLINE void LL_ADC_SetChannelSingleDiff(ADC_TypeDef *ADCx, uint32_t Channel, uint32_t SingleDiff)
Set mode single-ended or differential input of the selected ADC channel.
HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef *hadc, uint32_t SingleDiff)
Perform an ADC automatic self-calibration Calibration prerequisite: ADC must be disabled (execute thi...
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...
HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef *hadc)
Enable ADC, start conversion of injected group.
HAL_StatusTypeDef HAL_ADCEx_EnableInjectedQueue(ADC_HandleTypeDef *hadc)
Enable Injected Queue.
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
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_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length)
Enable ADC, start MultiMode conversion and transfer regular results through DMA.
void HAL_ADCEx_InjectedQueueOverflowCallback(ADC_HandleTypeDef *hadc)
Injected context queue overflow callback.
__STATIC_INLINE uint32_t LL_ADC_INJ_GetTrigAuto(ADC_TypeDef *ADCx)
Get ADC group injected conversion trigger: independent or from ADC group regular. CFGR JAUTO LL_ADC_...
HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef *hadc)
Enable ADC, start conversion of injected group with interruption.
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.
HAL_StatusTypeDef HAL_ADCEx_RegularMultiModeStop_DMA(ADC_HandleTypeDef *hadc)
Stop DMA-based multimode ADC conversion, disable ADC DMA transfer, disable ADC peripheral if no injec...
__STATIC_INLINE void LL_ADC_SetOffsetState(ADC_TypeDef *ADCx, uint32_t Offsety, uint32_t OffsetState)
Set for the ADC selected offset number 1, 2, 3 or 4: force offset state disable or enable without mod...
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
struct __ADC_HandleTypeDef else typedef struct endif ADC_HandleTypeDef
ADC handle Structure definition.
HAL_StatusTypeDef HAL_ADCEx_EnterADCDeepPowerDownMode(ADC_HandleTypeDef *hadc)
Enter ADC deep-power-down mode.
__STATIC_INLINE void LL_ADC_SetChannelSamplingTime(ADC_TypeDef *ADCx, uint32_t Channel, uint32_t SamplingTime)
Set sampling time of the selected ADC channel Unit: ADC clock cycles.
return HAL_OK
void ADC_DMAHalfConvCplt(DMA_HandleTypeDef *hdma)
DMA half transfer complete callback.
__STATIC_INLINE void LL_ADC_EnableDeepPowerDown(ADC_TypeDef *ADCx)
Put ADC instance in deep power down state.
FunctionalState InjectedDiscontinuousConvMode
__STATIC_INLINE uint32_t LL_ADC_INJ_IsConversionOngoing(ADC_TypeDef *ADCx)
Get ADC group injected conversion state. CR JADSTART LL_ADC_INJ_IsConversionOngoing.
__STATIC_INLINE uint32_t LL_ADC_GetCommonPathInternalCh(ADC_Common_TypeDef *ADCxy_COMMON)
Get parameter common to several ADC: measurement path to internal channels (VrefInt, temperature sensor, ...).
void HAL_ADCEx_EndOfSamplingCallback(ADC_HandleTypeDef *hadc)
End Of Sampling callback in non-blocking mode.
HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef *hadc, ADC_InjectionConfTypeDef *sConfigInjected)
Configure a channel to be assigned to ADC group injected.
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
Abort the DMA Transfer.
__STATIC_INLINE void LL_ADC_INJ_SetQueueMode(ADC_TypeDef *ADCx, uint32_t QueueMode)
Set ADC group injected contexts queue mode.
ADC_InjOversamplingTypeDef InjecOversampling
__STATIC_INLINE void LL_ADC_SetOffset(ADC_TypeDef *ADCx, uint32_t Offsety, uint32_t Channel, uint32_t OffsetLevel)
Set ADC selected offset number 1, 2, 3 or 4.
__STATIC_INLINE uint32_t LL_ADC_IsCalibrationOnGoing(ADC_TypeDef *ADCx)
Get ADC calibration state. CR ADCAL LL_ADC_IsCalibrationOnGoing.
HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef *hadc, ADC_MultiModeTypeDef *multimode)
Enable ADC multimode and configure multimode parameters.
FunctionalState QueueInjectedContext
void HAL_ADCEx_LevelOutOfWindow3Callback(ADC_HandleTypeDef *hadc)
Analog watchdog 3 callback in non-blocking mode.
HAL_StatusTypeDef ADC_ConversionStop(ADC_HandleTypeDef *hadc, uint32_t ConversionGroup)
Stop ADC conversion.
__STATIC_INLINE uint32_t LL_ADC_INJ_IsTriggerSourceSWStart(ADC_TypeDef *ADCx)
Get ADC group injected conversion trigger source internal (SW start) or external. ...
Structure definition of ADC multimode.
HAL_StatusTypeDef ADC_Disable(ADC_HandleTypeDef *hadc)
Disable the selected ADC.
__STATIC_INLINE uint32_t LL_ADC_GetCalibrationFactor(ADC_TypeDef *ADCx, uint32_t SingleDiff)
Get ADC calibration factor in the mode single-ended or differential (for devices with differential mo...
__STATIC_INLINE uint32_t LL_ADC_REG_IsConversionOngoing(ADC_TypeDef *ADCx)
Get ADC group regular conversion state. CR ADSTART LL_ADC_REG_IsConversionOngoing.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
FunctionalState InjecOversamplingMode
HAL_StatusTypeDef HAL_ADCEx_DisableVoltageRegulator(ADC_HandleTypeDef *hadc)
Disable ADC voltage regulator.
HAL_StatusTypeDef HAL_ADCEx_RegularStop_IT(ADC_HandleTypeDef *hadc)
Stop ADC conversion of ADC groups regular and injected, disable interrution of end-of-conversion, disable ADC peripheral if no conversion is on going on injected group.
HAL_StatusTypeDef HAL_ADCEx_RegularStop(ADC_HandleTypeDef *hadc)
Stop ADC conversion of regular group (and injected channels in case of auto_injection mode)...
uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef *hadc)
Return the last ADC Master and Slave regular conversions results when in multimode configuration...
__STATIC_INLINE void LL_ADC_SetCommonPathInternalCh(ADC_Common_TypeDef *ADCxy_COMMON, uint32_t PathInternal)
Set parameter common to several ADC: measurement path to internal channels (VrefInt, temperature sensor, ...).
HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef *hadc)
Stop multimode ADC conversion, disable ADC DMA transfer, disable ADC peripheral.
__STATIC_INLINE void LL_ADC_SetSamplingTimeCommonConfig(ADC_TypeDef *ADCx, uint32_t SamplingTimeCommonConfig)
Set ADC sampling time common configuration impacting settings of sampling time channel wise...
Structure definition of ADC group injected and ADC channel affected to ADC group injected.
__STATIC_INLINE void LL_ADC_StartCalibration(ADC_TypeDef *ADCx, uint32_t SingleDiff)
Start ADC calibration in the mode single-ended or differential (for devices with differential mode av...
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
__STATIC_INLINE void LL_ADC_INJ_StartConversion(ADC_TypeDef *ADCx)
Start ADC group injected conversion.