Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:06

0001 /**
0002   ******************************************************************************
0003   * @file    stm32h7xx_hal_adc_ex.c
0004   * @author  MCD Application Team
0005   * @brief   This file provides firmware functions to manage the following
0006   *          functionalities of the Analog to Digital Converter (ADC)
0007   *          peripheral:
0008   *           + Peripheral Control functions
0009   *          Other functions (generic functions) are available in file
0010   *          "stm32h7xx_hal_adc.c".
0011   *
0012   ******************************************************************************
0013   * @attention
0014   *
0015   * Copyright (c) 2017 STMicroelectronics.
0016   * All rights reserved.
0017   *
0018   * This software is licensed under terms that can be found in the LICENSE file
0019   * in the root directory of this software component.
0020   * If no LICENSE file comes with this software, it is provided AS-IS.
0021   *
0022   ******************************************************************************
0023   @verbatim
0024   [..]
0025   (@) Sections "ADC peripheral features" and "How to use this driver" are
0026       available in file of generic functions "stm32h7xx_hal_adc.c".
0027   [..]
0028   @endverbatim
0029   ******************************************************************************
0030   */
0031 
0032 /* Includes ------------------------------------------------------------------*/
0033 #include "stm32h7xx_hal.h"
0034 
0035 /** @addtogroup STM32H7xx_HAL_Driver
0036   * @{
0037   */
0038 
0039 /** @defgroup ADCEx ADCEx
0040   * @ingroup RTEMSBSPsARMSTM32H7
0041   * @brief ADC Extended HAL module driver
0042   * @{
0043   */
0044 
0045 #ifdef HAL_ADC_MODULE_ENABLED
0046 
0047 /* Private typedef -----------------------------------------------------------*/
0048 /* Private define ------------------------------------------------------------*/
0049 
0050 /** @defgroup ADCEx_Private_Constants ADC Extended Private Constants
0051   * @ingroup RTEMSBSPsARMSTM32H7
0052   * @{
0053   */
0054 
0055 #define ADC_JSQR_FIELDS  ((ADC_JSQR_JL | ADC_JSQR_JEXTSEL | ADC_JSQR_JEXTEN |\
0056                            ADC_JSQR_JSQ1  | ADC_JSQR_JSQ2 |\
0057                            ADC_JSQR_JSQ3 | ADC_JSQR_JSQ4 ))  /*!< ADC_JSQR fields of parameters that can be updated anytime
0058                                                                   once the ADC is enabled */
0059 
0060 /* Fixed timeout value for ADC calibration.                                   */
0061 /* Fixed timeout value for ADC calibration.                                     */
0062 /* Values defined to be higher than worst cases: low clock frequency,         */
0063 /* maximum prescalers.                                                        */
0064 /* Ex of profile low frequency : f_ADC at 0.125 Mhz (minimum value              */
0065 /* according to Data sheet), calibration_time MAX = 165010 / f_ADC              */
0066 /*           165010 / 125000 = 1.32s                                            */
0067 /* At maximum CPU speed (480 MHz), this means                                   */
0068 /*    1.32 * 480 MHz = 633600000 CPU cycles                                     */
0069 #define ADC_CALIBRATION_TIMEOUT         (633600000U)   /*!< ADC calibration time-out value */
0070 
0071 
0072 /**
0073   * @}
0074   */
0075 
0076 /* Private macro -------------------------------------------------------------*/
0077 /* Private variables ---------------------------------------------------------*/
0078 /* Private function prototypes -----------------------------------------------*/
0079 /* Exported functions --------------------------------------------------------*/
0080 
0081 /** @defgroup ADCEx_Exported_Functions ADC Extended Exported Functions
0082   * @ingroup RTEMSBSPsARMSTM32H7
0083   * @{
0084   */
0085 
0086 /** @defgroup ADCEx_Exported_Functions_Group1 Extended Input and Output operation functions
0087   * @ingroup RTEMSBSPsARMSTM32H7
0088   * @brief    Extended IO operation functions
0089   *
0090 @verbatim
0091  ===============================================================================
0092                       ##### IO operation functions #####
0093  ===============================================================================
0094     [..]  This section provides functions allowing to:
0095 
0096       (+) Perform the ADC self-calibration for single or differential ending.
0097       (+) Get calibration factors for single or differential ending.
0098       (+) Set calibration factors for single or differential ending.
0099 
0100       (+) Start conversion of ADC group injected.
0101       (+) Stop conversion of ADC group injected.
0102       (+) Poll for conversion complete on ADC group injected.
0103       (+) Get result of ADC group injected channel conversion.
0104       (+) Start conversion of ADC group injected and enable interruptions.
0105       (+) Stop conversion of ADC group injected and disable interruptions.
0106 
0107       (+) When multimode feature is available, start multimode and enable DMA transfer.
0108       (+) Stop multimode and disable ADC DMA transfer.
0109       (+) Get result of multimode conversion.
0110 
0111 @endverbatim
0112   * @{
0113   */
0114 
0115 /**
0116   * @brief  Perform an ADC automatic self-calibration
0117   *         Calibration prerequisite: ADC must be disabled (execute this
0118   *         function before HAL_ADC_Start() or after HAL_ADC_Stop() ).
0119   * @param  hadc       ADC handle
0120 * @param  CalibrationMode       Selection of calibration offset or
0121   *         linear calibration offset.
0122   *           @arg ADC_CALIB_OFFSET       Channel in mode calibration offset
0123   *           @arg ADC_CALIB_OFFSET_LINEARITY Channel in mode linear calibration offset
0124   * @param  SingleDiff Selection of single-ended or differential input
0125   *         This parameter can be one of the following values:
0126   *           @arg @ref ADC_SINGLE_ENDED       Channel in mode input single ended
0127   *           @arg @ref ADC_DIFFERENTIAL_ENDED Channel in mode input differential ended
0128   * @retval HAL status
0129   */
0130 HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef *hadc, uint32_t CalibrationMode, uint32_t SingleDiff)
0131 {
0132   HAL_StatusTypeDef tmp_hal_status;
0133   __IO uint32_t wait_loop_index = 0UL;
0134 
0135   /* Check the parameters */
0136   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
0137   assert_param(IS_ADC_SINGLE_DIFFERENTIAL(SingleDiff));
0138 
0139   /* Process locked */
0140   __HAL_LOCK(hadc);
0141 
0142   /* Calibration prerequisite: ADC must be disabled. */
0143 
0144   /* Disable the ADC (if not already disabled) */
0145   tmp_hal_status = ADC_Disable(hadc);
0146 
0147   /* Check if ADC is effectively disabled */
0148   if (tmp_hal_status == HAL_OK)
0149   {
0150     /* Set ADC state */
0151     ADC_STATE_CLR_SET(hadc->State,
0152                       HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
0153                       HAL_ADC_STATE_BUSY_INTERNAL);
0154 
0155     /* Start ADC calibration in mode single-ended or differential */
0156     LL_ADC_StartCalibration(hadc->Instance, CalibrationMode, SingleDiff);
0157 
0158     /* Wait for calibration completion */
0159     while (LL_ADC_IsCalibrationOnGoing(hadc->Instance) != 0UL)
0160     {
0161       wait_loop_index++;
0162       if (wait_loop_index >= ADC_CALIBRATION_TIMEOUT)
0163       {
0164         /* Update ADC state machine to error */
0165         ADC_STATE_CLR_SET(hadc->State,
0166                           HAL_ADC_STATE_BUSY_INTERNAL,
0167                           HAL_ADC_STATE_ERROR_INTERNAL);
0168 
0169         /* Process unlocked */
0170         __HAL_UNLOCK(hadc);
0171 
0172         return HAL_ERROR;
0173       }
0174     }
0175 
0176     /* Set ADC state */
0177     ADC_STATE_CLR_SET(hadc->State,
0178                       HAL_ADC_STATE_BUSY_INTERNAL,
0179                       HAL_ADC_STATE_READY);
0180   }
0181   else
0182   {
0183     SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
0184 
0185     /* Note: No need to update variable "tmp_hal_status" here: already set    */
0186     /*       to state "HAL_ERROR" by function disabling the ADC.              */
0187   }
0188 
0189   /* Process unlocked */
0190   __HAL_UNLOCK(hadc);
0191 
0192   /* Return function status */
0193   return tmp_hal_status;
0194 }
0195 
0196 /**
0197   * @brief  Get the calibration factor.
0198   * @param hadc ADC handle.
0199   * @param SingleDiff This parameter can be only:
0200   *           @arg @ref ADC_SINGLE_ENDED       Channel in mode input single ended
0201   *           @arg @ref ADC_DIFFERENTIAL_ENDED Channel in mode input differential ended
0202   * @retval Calibration value.
0203   */
0204 uint32_t HAL_ADCEx_Calibration_GetValue(ADC_HandleTypeDef *hadc, uint32_t SingleDiff)
0205 {
0206   /* Check the parameters */
0207   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
0208   assert_param(IS_ADC_SINGLE_DIFFERENTIAL(SingleDiff));
0209 
0210   /* Return the selected ADC calibration value */
0211   return LL_ADC_GetCalibrationOffsetFactor(hadc->Instance, SingleDiff);
0212 }
0213 
0214 /**
0215   * @brief  Get the calibration factor from automatic conversion result
0216   * @param  hadc ADC handle
0217   * @param  LinearCalib_Buffer: Linear calibration factor
0218   * @retval HAL state
0219   */
0220 HAL_StatusTypeDef HAL_ADCEx_LinearCalibration_GetValue(ADC_HandleTypeDef *hadc, uint32_t *LinearCalib_Buffer)
0221 {
0222   uint32_t cnt;
0223   HAL_StatusTypeDef tmp_hal_status = HAL_OK;
0224   uint32_t temp_REG_IsConversionOngoing = 0UL;
0225 
0226   /* Check the parameters */
0227   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
0228 
0229   /* Enable the ADC ADEN = 1 to be able to read the linear calibration factor */
0230   if (LL_ADC_IsEnabled(hadc->Instance) == 0UL)
0231   {
0232     tmp_hal_status = ADC_Enable(hadc);
0233   }
0234 
0235   if (tmp_hal_status == HAL_OK)
0236   {
0237     if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) != 0UL)
0238     {
0239       LL_ADC_REG_StopConversion(hadc->Instance);
0240       temp_REG_IsConversionOngoing = 1UL;
0241     }
0242     for (cnt = ADC_LINEAR_CALIB_REG_COUNT; cnt > 0UL; cnt--)
0243     {
0244       LinearCalib_Buffer[cnt - 1U] = LL_ADC_GetCalibrationLinearFactor(hadc->Instance, ADC_CR_LINCALRDYW6 >> (ADC_LINEAR_CALIB_REG_COUNT - cnt));
0245     }
0246     if (temp_REG_IsConversionOngoing != 0UL)
0247     {
0248       LL_ADC_REG_StartConversion(hadc->Instance);
0249     }
0250   }
0251 
0252   return tmp_hal_status;
0253 }
0254 
0255 /**
0256   * @brief  Set the calibration factor to overwrite automatic conversion result.
0257   *         ADC must be enabled and no conversion is ongoing.
0258   * @param hadc ADC handle
0259   * @param SingleDiff This parameter can be only:
0260   *           @arg @ref ADC_SINGLE_ENDED       Channel in mode input single ended
0261   *           @arg @ref ADC_DIFFERENTIAL_ENDED Channel in mode input differential ended
0262   * @param CalibrationFactor Calibration factor On devices STM32H72xx and STM32H73xx this parameter is coded on 11 bits
0263   *                                             maximum for ADC1/2 and on 7 bits for ADC3.
0264   *                                             On devices STM32H74xx and STM32H75xx this parameter is coded on 11 bits.
0265   * @retval HAL state
0266   */
0267 HAL_StatusTypeDef HAL_ADCEx_Calibration_SetValue(ADC_HandleTypeDef *hadc, uint32_t SingleDiff, uint32_t CalibrationFactor)
0268 {
0269   HAL_StatusTypeDef tmp_hal_status = HAL_OK;
0270   uint32_t tmp_adc_is_conversion_on_going_regular;
0271   uint32_t tmp_adc_is_conversion_on_going_injected;
0272 
0273   /* Check the parameters */
0274   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
0275   assert_param(IS_ADC_SINGLE_DIFFERENTIAL(SingleDiff));
0276 
0277 #if defined(ADC_VER_V5_V90)
0278   if (hadc->Instance == ADC3)
0279   {
0280     assert_param(IS_ADC_CALFACT_ADC3(CalibrationFactor));
0281   }
0282   else
0283   {
0284     assert_param(IS_ADC_CALFACT(CalibrationFactor));
0285   }
0286 #else
0287   assert_param(IS_ADC_CALFACT(CalibrationFactor));
0288 #endif
0289 
0290   /* Process locked */
0291   __HAL_LOCK(hadc);
0292 
0293   /* Verification of hardware constraints before modifying the calibration    */
0294   /* factors register: ADC must be enabled, no conversion on going.           */
0295   tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
0296   tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance);
0297 
0298   if ((LL_ADC_IsEnabled(hadc->Instance) != 0UL)
0299       && (tmp_adc_is_conversion_on_going_regular == 0UL)
0300       && (tmp_adc_is_conversion_on_going_injected == 0UL)
0301      )
0302   {
0303     /* Set the selected ADC calibration value */
0304     LL_ADC_SetCalibrationOffsetFactor(hadc->Instance, SingleDiff, CalibrationFactor);
0305   }
0306   else
0307   {
0308     /* Update ADC state machine */
0309     SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
0310     /* Update ADC error code */
0311     SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL);
0312 
0313     /* Update ADC state machine to error */
0314     tmp_hal_status = HAL_ERROR;
0315   }
0316 
0317   /* Process unlocked */
0318   __HAL_UNLOCK(hadc);
0319 
0320   /* Return function status */
0321   return tmp_hal_status;
0322 }
0323 
0324 /**
0325   * @brief  Set the linear calibration factor
0326   * @param  hadc ADC handle
0327   * @param  LinearCalib_Buffer: Linear calibration factor
0328   * @retval HAL state
0329   */
0330 HAL_StatusTypeDef HAL_ADCEx_LinearCalibration_SetValue(ADC_HandleTypeDef *hadc, uint32_t *LinearCalib_Buffer)
0331 {
0332   uint32_t cnt;
0333   __IO uint32_t wait_loop_index = 0;
0334   uint32_t temp_REG_IsConversionOngoing = 0UL;
0335 
0336   /* Check the parameters */
0337   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
0338 
0339   /* - Exit from deep-power-down mode and ADC voltage regulator enable        */
0340   /*  Exit deep power down mode if still in that state                        */
0341   if (HAL_IS_BIT_SET(hadc->Instance->CR, ADC_CR_DEEPPWD))
0342   {
0343     /* Exit deep power down mode */
0344     CLEAR_BIT(hadc->Instance->CR, ADC_CR_DEEPPWD);
0345 
0346     /* System was in deep power down mode, calibration must
0347        be relaunched or a previously saved calibration factor
0348        re-applied once the ADC voltage regulator is enabled */
0349   }
0350 
0351 
0352   if (HAL_IS_BIT_CLR(hadc->Instance->CR, ADC_CR_ADVREGEN))
0353   {
0354     /* Enable ADC internal voltage regulator                                  */
0355     SET_BIT(hadc->Instance->CR, ADC_CR_ADVREGEN);
0356     /* Delay for ADC stabilization time                                       */
0357     /* Wait loop initialization and execution                                 */
0358     /* Note: Variable divided by 2 to compensate partially                    */
0359     /*       CPU processing cycles.                                           */
0360     wait_loop_index = ((ADC_STAB_DELAY_US / 10UL) * ((SystemCoreClock / (100000UL * 2UL)) + 1UL));
0361     while (wait_loop_index != 0UL)
0362     {
0363       wait_loop_index--;
0364     }
0365   }
0366 
0367 
0368   /* Verification that ADC voltage regulator is correctly enabled, whether    */
0369   /* or not ADC is coming from state reset (if any potential problem of       */
0370   /* clocking, voltage regulator would not be enabled).                       */
0371   if (HAL_IS_BIT_CLR(hadc->Instance->CR, ADC_CR_ADVREGEN))
0372   {
0373     /* Update ADC state machine to error */
0374     SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
0375 
0376     /* Set ADC error code to ADC peripheral internal error */
0377     SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL);
0378 
0379     return  HAL_ERROR;
0380   }
0381   /* Enable the ADC peripheral */
0382   if (LL_ADC_IsEnabled(hadc->Instance) == 0UL) /* Enable the ADC if it is disabled */
0383   {
0384     if (ADC_Enable(hadc) != HAL_OK)
0385     {
0386       return  HAL_ERROR;
0387     }
0388     else
0389     {
0390       for (cnt = ADC_LINEAR_CALIB_REG_COUNT; cnt > 0UL ; cnt--)
0391       {
0392         LL_ADC_SetCalibrationLinearFactor(hadc->Instance, ADC_CR_LINCALRDYW6 >> (ADC_LINEAR_CALIB_REG_COUNT - cnt), LinearCalib_Buffer[cnt - 1U]);
0393       }
0394       (void)ADC_Disable(hadc);
0395     }
0396   }
0397   else  /* ADC is already enabled, so no need to enable it but need to stop conversion */
0398   {
0399     if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) != 0UL)
0400     {
0401       LL_ADC_REG_StopConversion(hadc->Instance);
0402       temp_REG_IsConversionOngoing = 1UL;
0403     }
0404     for (cnt = ADC_LINEAR_CALIB_REG_COUNT; cnt > 0UL ; cnt--)
0405     {
0406       LL_ADC_SetCalibrationLinearFactor(hadc->Instance, ADC_CR_LINCALRDYW6 >> (ADC_LINEAR_CALIB_REG_COUNT - cnt), LinearCalib_Buffer[cnt - 1U]);
0407     }
0408     if (temp_REG_IsConversionOngoing != 0UL)
0409     {
0410       LL_ADC_REG_StartConversion(hadc->Instance);
0411     }
0412   }
0413   return HAL_OK;
0414 }
0415 
0416 /**
0417   * @brief  Load the calibration factor from engi bytes
0418   * @param  hadc ADC handle
0419   * @retval HAL state
0420   */
0421 HAL_StatusTypeDef HAL_ADCEx_LinearCalibration_FactorLoad(ADC_HandleTypeDef *hadc)
0422 {
0423   HAL_StatusTypeDef tmp_hal_status = HAL_OK;
0424   uint32_t cnt, FactorOffset;
0425   uint32_t LinearCalib_Buffer[ADC_LINEAR_CALIB_REG_COUNT];
0426 
0427   /* Linearity calibration is retrieved from engi bytes
0428      read values from registers and put them to the CALFACT2 register */
0429   /* If needed linearity calibration can be done in runtime using
0430      LL_ADC_GetCalibrationLinearFactor()                             */
0431   if (hadc->Instance == ADC1)
0432   {
0433     FactorOffset = 0UL;
0434   }
0435   else if (hadc->Instance == ADC2)
0436   {
0437     FactorOffset = 8UL;
0438   }
0439   else   /*Case ADC3*/
0440   {
0441     FactorOffset = 16UL;
0442   }
0443 
0444   for (cnt = 0UL; cnt < ADC_LINEAR_CALIB_REG_COUNT; cnt++)
0445   {
0446     LinearCalib_Buffer[cnt] = *(uint32_t *)(ADC_LINEAR_CALIB_REG_1_ADDR + FactorOffset + cnt);
0447   }
0448   if (HAL_ADCEx_LinearCalibration_SetValue(hadc, (uint32_t *)LinearCalib_Buffer) != HAL_OK)
0449   {
0450     tmp_hal_status = HAL_ERROR;
0451   }
0452 
0453   return tmp_hal_status;
0454 }
0455 
0456 /**
0457   * @brief  Enable ADC, start conversion of injected group.
0458   * @note   Interruptions enabled in this function: None.
0459   * @note   Case of multimode enabled when multimode feature is available:
0460   *         HAL_ADCEx_InjectedStart() API must be called for ADC slave first,
0461   *         then for ADC master.
0462   *         For ADC slave, ADC is enabled only (conversion is not started).
0463   *         For ADC master, ADC is enabled and multimode conversion is started.
0464   * @param hadc ADC handle.
0465   * @retval HAL status
0466   */
0467 HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef *hadc)
0468 {
0469   HAL_StatusTypeDef tmp_hal_status;
0470   uint32_t tmp_config_injected_queue;
0471   uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
0472 
0473   /* Check the parameters */
0474   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
0475 
0476   if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) != 0UL)
0477   {
0478     return HAL_BUSY;
0479   }
0480   else
0481   {
0482     /* In case of software trigger detection enabled, JQDIS must be set
0483       (which can be done only if ADSTART and JADSTART are both cleared).
0484        If JQDIS is not set at that point, returns an error
0485        - since software trigger detection is disabled. User needs to
0486        resort to HAL_ADCEx_DisableInjectedQueue() API to set JQDIS.
0487        - or (if JQDIS is intentionally reset) since JEXTEN = 0 which means
0488          the queue is empty */
0489     tmp_config_injected_queue = READ_BIT(hadc->Instance->CFGR, ADC_CFGR_JQDIS);
0490 
0491     if ((READ_BIT(hadc->Instance->JSQR, ADC_JSQR_JEXTEN) == 0UL)
0492         && (tmp_config_injected_queue == 0UL)
0493        )
0494     {
0495       SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
0496       return HAL_ERROR;
0497     }
0498 
0499     /* Process locked */
0500     __HAL_LOCK(hadc);
0501 
0502     /* Enable the ADC peripheral */
0503     tmp_hal_status = ADC_Enable(hadc);
0504 
0505     /* Start conversion if ADC is effectively enabled */
0506     if (tmp_hal_status == HAL_OK)
0507     {
0508       /* Check if a regular conversion is ongoing */
0509       if ((hadc->State & HAL_ADC_STATE_REG_BUSY) != 0UL)
0510       {
0511         /* Reset ADC error code field related to injected conversions only */
0512         CLEAR_BIT(hadc->ErrorCode, HAL_ADC_ERROR_JQOVF);
0513       }
0514       else
0515       {
0516         /* Set ADC error code to none */
0517         ADC_CLEAR_ERRORCODE(hadc);
0518       }
0519 
0520       /* Set ADC state                                                        */
0521       /* - Clear state bitfield related to injected group conversion results  */
0522       /* - Set state bitfield related to injected operation                   */
0523       ADC_STATE_CLR_SET(hadc->State,
0524                         HAL_ADC_STATE_READY | HAL_ADC_STATE_INJ_EOC,
0525                         HAL_ADC_STATE_INJ_BUSY);
0526 
0527       /* Reset HAL_ADC_STATE_MULTIMODE_SLAVE bit
0528         - if ADC instance is master or if multimode feature is not available
0529         - if multimode setting is disabled (ADC instance slave in independent mode) */
0530       if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
0531           || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
0532          )
0533       {
0534         CLEAR_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
0535       }
0536 
0537       /* Clear ADC group injected group conversion flag */
0538       /* (To ensure of no unknown state from potential previous ADC operations) */
0539       __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_JEOC | ADC_FLAG_JEOS));
0540 
0541       /* Process unlocked */
0542       /* Unlock before starting ADC conversions: in case of potential         */
0543       /* interruption, to let the process to ADC IRQ Handler.                 */
0544       __HAL_UNLOCK(hadc);
0545 
0546       /* Enable conversion of injected group, if automatic injected conversion  */
0547       /* is disabled.                                                           */
0548       /* If software start has been selected, conversion starts immediately.    */
0549       /* If external trigger has been selected, conversion will start at next   */
0550       /* trigger event.                                                         */
0551       /* Case of multimode enabled (when multimode feature is available):       */
0552       /* if ADC is slave,                                                       */
0553       /*    - ADC is enabled only (conversion is not started),                  */
0554       /*    - if multimode only concerns regular conversion, ADC is enabled     */
0555       /*     and conversion is started.                                         */
0556       /* If ADC is master or independent,                                       */
0557       /*    - ADC is enabled and conversion is started.                         */
0558       if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
0559           || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
0560           || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_SIMULT)
0561           || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_INTERL)
0562          )
0563       {
0564         /* ADC instance is not a multimode slave instance with multimode injected conversions enabled */
0565         if (LL_ADC_INJ_GetTrigAuto(hadc->Instance) == LL_ADC_INJ_TRIG_INDEPENDENT)
0566         {
0567           LL_ADC_INJ_StartConversion(hadc->Instance);
0568         }
0569       }
0570       else
0571       {
0572         /* ADC instance is not a multimode slave instance with multimode injected conversions enabled */
0573         SET_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
0574       }
0575 
0576     }
0577     else
0578     {
0579       /* Process unlocked */
0580       __HAL_UNLOCK(hadc);
0581     }
0582 
0583     /* Return function status */
0584     return tmp_hal_status;
0585   }
0586 }
0587 
0588 /**
0589   * @brief  Stop conversion of injected channels. Disable ADC peripheral if
0590   *         no regular conversion is on going.
0591   * @note   If ADC must be disabled and if conversion is on going on
0592   *         regular group, function HAL_ADC_Stop must be used to stop both
0593   *         injected and regular groups, and disable the ADC.
0594   * @note   If injected group mode auto-injection is enabled,
0595   *         function HAL_ADC_Stop must be used.
0596   * @note   In case of multimode enabled (when multimode feature is available),
0597   *         HAL_ADCEx_InjectedStop() must be called for ADC master first, then for ADC slave.
0598   *         For ADC master, conversion is stopped and ADC is disabled.
0599   *         For ADC slave, ADC is disabled only (conversion stop of ADC master
0600   *         has already stopped conversion of ADC slave).
0601   * @param hadc ADC handle.
0602   * @retval HAL status
0603   */
0604 HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef *hadc)
0605 {
0606   HAL_StatusTypeDef tmp_hal_status;
0607 
0608   /* Check the parameters */
0609   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
0610 
0611   /* Process locked */
0612   __HAL_LOCK(hadc);
0613 
0614   /* 1. Stop potential conversion on going on injected group only. */
0615   tmp_hal_status = ADC_ConversionStop(hadc, ADC_INJECTED_GROUP);
0616 
0617   /* Disable ADC peripheral if injected conversions are effectively stopped   */
0618   /* and if no conversion on regular group is on-going                       */
0619   if (tmp_hal_status == HAL_OK)
0620   {
0621     if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL)
0622     {
0623       /* 2. Disable the ADC peripheral */
0624       tmp_hal_status = ADC_Disable(hadc);
0625 
0626       /* Check if ADC is effectively disabled */
0627       if (tmp_hal_status == HAL_OK)
0628       {
0629         /* Set ADC state */
0630         ADC_STATE_CLR_SET(hadc->State,
0631                           HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
0632                           HAL_ADC_STATE_READY);
0633       }
0634     }
0635     /* Conversion on injected group is stopped, but ADC not disabled since    */
0636     /* conversion on regular group is still running.                          */
0637     else
0638     {
0639       /* Set ADC state */
0640       CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
0641     }
0642   }
0643 
0644   /* Process unlocked */
0645   __HAL_UNLOCK(hadc);
0646 
0647   /* Return function status */
0648   return tmp_hal_status;
0649 }
0650 
0651 /**
0652   * @brief  Wait for injected group conversion to be completed.
0653   * @param hadc ADC handle
0654   * @param Timeout Timeout value in millisecond.
0655   * @note   Depending on hadc->Init.EOCSelection, JEOS or JEOC is
0656   *         checked and cleared depending on AUTDLY bit status.
0657   * @retval HAL status
0658   */
0659 HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef *hadc, uint32_t Timeout)
0660 {
0661   uint32_t tickstart;
0662   uint32_t tmp_Flag_End;
0663   uint32_t tmp_adc_inj_is_trigger_source_sw_start;
0664   uint32_t tmp_adc_reg_is_trigger_source_sw_start;
0665   uint32_t tmp_cfgr;
0666   const ADC_TypeDef *tmpADC_Master;
0667   uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
0668 
0669   /* Check the parameters */
0670   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
0671 
0672   /* If end of sequence selected */
0673   if (hadc->Init.EOCSelection == ADC_EOC_SEQ_CONV)
0674   {
0675     tmp_Flag_End = ADC_FLAG_JEOS;
0676   }
0677   else /* end of conversion selected */
0678   {
0679     tmp_Flag_End = ADC_FLAG_JEOC;
0680   }
0681 
0682   /* Get timeout */
0683   tickstart = HAL_GetTick();
0684 
0685   /* Wait until End of Conversion or Sequence flag is raised */
0686   while ((hadc->Instance->ISR & tmp_Flag_End) == 0UL)
0687   {
0688     /* Check if timeout is disabled (set to infinite wait) */
0689     if (Timeout != HAL_MAX_DELAY)
0690     {
0691       if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0UL))
0692       {
0693         if((hadc->Instance->ISR & tmp_Flag_End) == 0UL)
0694         {
0695           /* Update ADC state machine to timeout */
0696           SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT);
0697 
0698           /* Process unlocked */
0699           __HAL_UNLOCK(hadc);
0700 
0701           return HAL_TIMEOUT;
0702         }
0703       }
0704     }
0705   }
0706 
0707   /* Retrieve ADC configuration */
0708   tmp_adc_inj_is_trigger_source_sw_start = LL_ADC_INJ_IsTriggerSourceSWStart(hadc->Instance);
0709   tmp_adc_reg_is_trigger_source_sw_start = LL_ADC_REG_IsTriggerSourceSWStart(hadc->Instance);
0710   /* Get relevant register CFGR in ADC instance of ADC master or slave  */
0711   /* in function of multimode state (for devices with multimode         */
0712   /* available).                                                        */
0713   if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
0714       || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
0715       || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_SIMULT)
0716       || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_INTERL)
0717      )
0718   {
0719     tmp_cfgr = READ_REG(hadc->Instance->CFGR);
0720   }
0721   else
0722   {
0723     tmpADC_Master = __LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance);
0724     tmp_cfgr = READ_REG(tmpADC_Master->CFGR);
0725   }
0726 
0727   /* Update ADC state machine */
0728   SET_BIT(hadc->State, HAL_ADC_STATE_INJ_EOC);
0729 
0730   /* Determine whether any further conversion upcoming on group injected      */
0731   /* by external trigger or by automatic injected conversion                  */
0732   /* from group regular.                                                      */
0733   if ((tmp_adc_inj_is_trigger_source_sw_start != 0UL)            ||
0734       ((READ_BIT(tmp_cfgr, ADC_CFGR_JAUTO) == 0UL)      &&
0735        ((tmp_adc_reg_is_trigger_source_sw_start != 0UL)  &&
0736         (READ_BIT(tmp_cfgr, ADC_CFGR_CONT) == 0UL))))
0737   {
0738     /* Check whether end of sequence is reached */
0739     if (__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_JEOS))
0740     {
0741       /* Particular case if injected contexts queue is enabled:             */
0742       /* when the last context has been fully processed, JSQR is reset      */
0743       /* by the hardware. Even if no injected conversion is planned to come */
0744       /* (queue empty, triggers are ignored), it can start again            */
0745       /* immediately after setting a new context (JADSTART is still set).   */
0746       /* Therefore, state of HAL ADC injected group is kept to busy.        */
0747       if (READ_BIT(tmp_cfgr, ADC_CFGR_JQM) == 0UL)
0748       {
0749         /* Set ADC state */
0750         CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
0751 
0752         if ((hadc->State & HAL_ADC_STATE_REG_BUSY) == 0UL)
0753         {
0754           SET_BIT(hadc->State, HAL_ADC_STATE_READY);
0755         }
0756       }
0757     }
0758   }
0759 
0760   /* Clear polled flag */
0761   if (tmp_Flag_End == ADC_FLAG_JEOS)
0762   {
0763     /* Clear end of sequence JEOS flag of injected group if low power feature */
0764     /* "LowPowerAutoWait " is disabled, to not interfere with this feature.   */
0765     /* For injected groups, no new conversion will start before JEOS is       */
0766     /* cleared.                                                               */
0767     if (READ_BIT(tmp_cfgr, ADC_CFGR_AUTDLY) == 0UL)
0768     {
0769       __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_JEOC | ADC_FLAG_JEOS));
0770     }
0771   }
0772   else
0773   {
0774     __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_JEOC);
0775   }
0776 
0777   /* Return API HAL status */
0778   return HAL_OK;
0779 }
0780 
0781 /**
0782   * @brief  Enable ADC, start conversion of injected group with interruption.
0783   * @note   Interruptions enabled in this function according to initialization
0784   *         setting : JEOC (end of conversion) or JEOS (end of sequence)
0785   * @note   Case of multimode enabled (when multimode feature is enabled):
0786   *         HAL_ADCEx_InjectedStart_IT() API must be called for ADC slave first,
0787   *         then for ADC master.
0788   *         For ADC slave, ADC is enabled only (conversion is not started).
0789   *         For ADC master, ADC is enabled and multimode conversion is started.
0790   * @param hadc ADC handle.
0791   * @retval HAL status.
0792   */
0793 HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef *hadc)
0794 {
0795   HAL_StatusTypeDef tmp_hal_status;
0796   uint32_t tmp_config_injected_queue;
0797   uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
0798 
0799   /* Check the parameters */
0800   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
0801 
0802   if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) != 0UL)
0803   {
0804     return HAL_BUSY;
0805   }
0806   else
0807   {
0808     /* In case of software trigger detection enabled, JQDIS must be set
0809       (which can be done only if ADSTART and JADSTART are both cleared).
0810        If JQDIS is not set at that point, returns an error
0811        - since software trigger detection is disabled. User needs to
0812        resort to HAL_ADCEx_DisableInjectedQueue() API to set JQDIS.
0813        - or (if JQDIS is intentionally reset) since JEXTEN = 0 which means
0814          the queue is empty */
0815     tmp_config_injected_queue = READ_BIT(hadc->Instance->CFGR, ADC_CFGR_JQDIS);
0816 
0817     if ((READ_BIT(hadc->Instance->JSQR, ADC_JSQR_JEXTEN) == 0UL)
0818         && (tmp_config_injected_queue == 0UL)
0819        )
0820     {
0821       SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
0822       return HAL_ERROR;
0823     }
0824 
0825     /* Process locked */
0826     __HAL_LOCK(hadc);
0827 
0828     /* Enable the ADC peripheral */
0829     tmp_hal_status = ADC_Enable(hadc);
0830 
0831     /* Start conversion if ADC is effectively enabled */
0832     if (tmp_hal_status == HAL_OK)
0833     {
0834       /* Check if a regular conversion is ongoing */
0835       if ((hadc->State & HAL_ADC_STATE_REG_BUSY) != 0UL)
0836       {
0837         /* Reset ADC error code field related to injected conversions only */
0838         CLEAR_BIT(hadc->ErrorCode, HAL_ADC_ERROR_JQOVF);
0839       }
0840       else
0841       {
0842         /* Set ADC error code to none */
0843         ADC_CLEAR_ERRORCODE(hadc);
0844       }
0845 
0846       /* Set ADC state                                                        */
0847       /* - Clear state bitfield related to injected group conversion results  */
0848       /* - Set state bitfield related to injected operation                   */
0849       ADC_STATE_CLR_SET(hadc->State,
0850                         HAL_ADC_STATE_READY | HAL_ADC_STATE_INJ_EOC,
0851                         HAL_ADC_STATE_INJ_BUSY);
0852 
0853       /* Reset HAL_ADC_STATE_MULTIMODE_SLAVE bit
0854         - if ADC instance is master or if multimode feature is not available
0855         - if multimode setting is disabled (ADC instance slave in independent mode) */
0856       if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
0857           || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
0858          )
0859       {
0860         CLEAR_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
0861       }
0862 
0863       /* Clear ADC group injected group conversion flag */
0864       /* (To ensure of no unknown state from potential previous ADC operations) */
0865       __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_JEOC | ADC_FLAG_JEOS));
0866 
0867       /* Process unlocked */
0868       /* Unlock before starting ADC conversions: in case of potential         */
0869       /* interruption, to let the process to ADC IRQ Handler.                 */
0870       __HAL_UNLOCK(hadc);
0871 
0872       /* Enable ADC Injected context queue overflow interrupt if this feature   */
0873       /* is enabled.                                                            */
0874       if ((hadc->Instance->CFGR & ADC_CFGR_JQM) != 0UL)
0875       {
0876         __HAL_ADC_ENABLE_IT(hadc, ADC_FLAG_JQOVF);
0877       }
0878 
0879       /* Enable ADC end of conversion interrupt */
0880       switch (hadc->Init.EOCSelection)
0881       {
0882         case ADC_EOC_SEQ_CONV:
0883           __HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOC);
0884           __HAL_ADC_ENABLE_IT(hadc, ADC_IT_JEOS);
0885           break;
0886         /* case ADC_EOC_SINGLE_CONV */
0887         default:
0888           __HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOS);
0889           __HAL_ADC_ENABLE_IT(hadc, ADC_IT_JEOC);
0890           break;
0891       }
0892 
0893       /* Enable conversion of injected group, if automatic injected conversion  */
0894       /* is disabled.                                                           */
0895       /* If software start has been selected, conversion starts immediately.    */
0896       /* If external trigger has been selected, conversion will start at next   */
0897       /* trigger event.                                                         */
0898       /* Case of multimode enabled (when multimode feature is available):       */
0899       /* if ADC is slave,                                                       */
0900       /*    - ADC is enabled only (conversion is not started),                  */
0901       /*    - if multimode only concerns regular conversion, ADC is enabled     */
0902       /*     and conversion is started.                                         */
0903       /* If ADC is master or independent,                                       */
0904       /*    - ADC is enabled and conversion is started.                         */
0905       if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance)
0906           || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT)
0907           || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_SIMULT)
0908           || (tmp_multimode_config == LL_ADC_MULTI_DUAL_REG_INTERL)
0909          )
0910       {
0911         /* ADC instance is not a multimode slave instance with multimode injected conversions enabled */
0912         if (LL_ADC_INJ_GetTrigAuto(hadc->Instance) == LL_ADC_INJ_TRIG_INDEPENDENT)
0913         {
0914           LL_ADC_INJ_StartConversion(hadc->Instance);
0915         }
0916       }
0917       else
0918       {
0919         /* ADC instance is not a multimode slave instance with multimode injected conversions enabled */
0920         SET_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
0921       }
0922 
0923     }
0924     else
0925     {
0926       /* Process unlocked */
0927       __HAL_UNLOCK(hadc);
0928     }
0929 
0930     /* Return function status */
0931     return tmp_hal_status;
0932   }
0933 }
0934 
0935 /**
0936   * @brief  Stop conversion of injected channels, disable interruption of
0937   *         end-of-conversion. Disable ADC peripheral if no regular conversion
0938   *         is on going.
0939   * @note   If ADC must be disabled and if conversion is on going on
0940   *         regular group, function HAL_ADC_Stop must be used to stop both
0941   *         injected and regular groups, and disable the ADC.
0942   * @note   If injected group mode auto-injection is enabled,
0943   *         function HAL_ADC_Stop must be used.
0944   * @note   Case of multimode enabled (when multimode feature is available):
0945   *         HAL_ADCEx_InjectedStop_IT() API must be called for ADC master first,
0946   *         then for ADC slave.
0947   *         For ADC master, conversion is stopped and ADC is disabled.
0948   *         For ADC slave, ADC is disabled only (conversion stop of ADC master
0949   *         has already stopped conversion of ADC slave).
0950   * @note   In case of auto-injection mode, HAL_ADC_Stop() must be used.
0951   * @param hadc ADC handle
0952   * @retval HAL status
0953   */
0954 HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef *hadc)
0955 {
0956   HAL_StatusTypeDef tmp_hal_status;
0957 
0958   /* Check the parameters */
0959   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
0960 
0961   /* Process locked */
0962   __HAL_LOCK(hadc);
0963 
0964   /* 1. Stop potential conversion on going on injected group only. */
0965   tmp_hal_status = ADC_ConversionStop(hadc, ADC_INJECTED_GROUP);
0966 
0967   /* Disable ADC peripheral if injected conversions are effectively stopped   */
0968   /* and if no conversion on the other group (regular group) is intended to   */
0969   /* continue.                                                                */
0970   if (tmp_hal_status == HAL_OK)
0971   {
0972     /* Disable ADC end of conversion interrupt for injected channels */
0973     __HAL_ADC_DISABLE_IT(hadc, (ADC_IT_JEOC | ADC_IT_JEOS | ADC_FLAG_JQOVF));
0974 
0975     if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL)
0976     {
0977       /* 2. Disable the ADC peripheral */
0978       tmp_hal_status = ADC_Disable(hadc);
0979 
0980       /* Check if ADC is effectively disabled */
0981       if (tmp_hal_status == HAL_OK)
0982       {
0983         /* Set ADC state */
0984         ADC_STATE_CLR_SET(hadc->State,
0985                           HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
0986                           HAL_ADC_STATE_READY);
0987       }
0988     }
0989     /* Conversion on injected group is stopped, but ADC not disabled since    */
0990     /* conversion on regular group is still running.                          */
0991     else
0992     {
0993       /* Set ADC state */
0994       CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
0995     }
0996   }
0997 
0998   /* Process unlocked */
0999   __HAL_UNLOCK(hadc);
1000 
1001   /* Return function status */
1002   return tmp_hal_status;
1003 }
1004 
1005 /**
1006   * @brief  Enable ADC, start MultiMode conversion and transfer regular results through DMA.
1007   * @note   Multimode must have been previously configured using
1008   *         HAL_ADCEx_MultiModeConfigChannel() function.
1009   *         Interruptions enabled in this function:
1010   *          overrun, DMA half transfer, DMA transfer complete.
1011   *         Each of these interruptions has its dedicated callback function.
1012   * @note   Case of ADC slave using its own DMA channel (typical case being both ADC instances using DMA channel
1013   *         of ADC master with data concatenated): multimode must be configured without data packing and
1014   *         this function must be called first with handle of ADC slave, then with handle of ADC master.
1015   * @note   State field of Slave ADC handle is not updated in this configuration:
1016   *         user should not rely on it for information related to Slave regular
1017   *         conversions.
1018   * @param hadc ADC handle of ADC master (handle of ADC slave must not be used)
1019   * @param pData Destination Buffer address.
1020   * @param Length Length of data to be transferred from ADC peripheral to memory (in bytes).
1021   * @retval HAL status
1022   */
1023 HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length)
1024 {
1025   HAL_StatusTypeDef tmp_hal_status;
1026   ADC_HandleTypeDef tmphadcSlave;
1027   ADC_Common_TypeDef *tmpADC_Common;
1028 
1029   /* Check the parameters */
1030   assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance));
1031   assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ContinuousConvMode));
1032   assert_param(IS_ADC_EXTTRIG_EDGE(hadc->Init.ExternalTrigConvEdge));
1033 
1034   if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) != 0UL)
1035   {
1036     return HAL_BUSY;
1037   }
1038   else
1039   {
1040     /* Process locked */
1041     __HAL_LOCK(hadc);
1042 
1043     /* Case of ADC slave using its own DMA channel: check whether handle selected
1044        corresponds to ADC master or slave instance */
1045     if (__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) != hadc->Instance)
1046     {
1047       /* Case of ADC slave selected: enable ADC instance */
1048       tmp_hal_status = ADC_Enable(hadc);
1049     }
1050     else
1051     {
1052       tmphadcSlave.State = HAL_ADC_STATE_RESET;
1053       tmphadcSlave.ErrorCode = HAL_ADC_ERROR_NONE;
1054       /* Set a temporary handle of the ADC slave associated to the ADC master   */
1055       ADC_MULTI_SLAVE(hadc, &tmphadcSlave);
1056 
1057       if (tmphadcSlave.Instance == NULL)
1058       {
1059         /* Set ADC state */
1060         SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
1061 
1062         /* Process unlocked */
1063         __HAL_UNLOCK(hadc);
1064 
1065         return HAL_ERROR;
1066       }
1067 
1068       /* Enable the ADC peripherals: master and slave (in case if not already   */
1069       /* enabled previously)                                                    */
1070       tmp_hal_status = ADC_Enable(hadc);
1071       if (tmp_hal_status == HAL_OK)
1072       {
1073         tmp_hal_status = ADC_Enable(&tmphadcSlave);
1074       }
1075     }
1076 
1077     /* Start multimode conversion of ADCs pair */
1078     if (tmp_hal_status == HAL_OK)
1079     {
1080       /* Set ADC state */
1081       ADC_STATE_CLR_SET(hadc->State,
1082                         (HAL_ADC_STATE_READY | HAL_ADC_STATE_REG_EOC | HAL_ADC_STATE_REG_OVR | HAL_ADC_STATE_REG_EOSMP),
1083                         HAL_ADC_STATE_REG_BUSY);
1084 
1085       /* Set ADC error code to none */
1086       ADC_CLEAR_ERRORCODE(hadc);
1087 
1088       /* Set the DMA transfer complete callback */
1089       hadc->DMA_Handle->XferCpltCallback = ADC_DMAConvCplt;
1090 
1091       /* Set the DMA half transfer complete callback */
1092       hadc->DMA_Handle->XferHalfCpltCallback = ADC_DMAHalfConvCplt;
1093 
1094       /* Set the DMA error callback */
1095       hadc->DMA_Handle->XferErrorCallback = ADC_DMAError ;
1096 
1097       /* Manage ADC and DMA start: ADC overrun interruption, DMA start, ADC     */
1098       /* start (in case of SW start):                                           */
1099 
1100       /* Clear regular group conversion flag and overrun flag */
1101       /* (To ensure of no unknown state from potential previous ADC operations) */
1102       __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_EOC | ADC_FLAG_EOS | ADC_FLAG_OVR));
1103 
1104       /* Process unlocked */
1105       /* Unlock before starting ADC conversions: in case of potential         */
1106       /* interruption, to let the process to ADC IRQ Handler.                 */
1107       __HAL_UNLOCK(hadc);
1108 
1109       /* Enable ADC overrun interrupt */
1110       __HAL_ADC_ENABLE_IT(hadc, ADC_IT_OVR);
1111 
1112       /* Case of ADC slave using its own DMA channel: check whether handle selected
1113          corresponds to ADC master or slave instance */
1114       if (__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) != hadc->Instance)
1115       {
1116         /* Case of ADC slave selected: Start the DMA channel. */
1117         /* Note: Data transfer will start upon next call of this function using handle of ADC master */
1118         tmp_hal_status = HAL_DMA_Start_IT(hadc->DMA_Handle, (uint32_t)&hadc->Instance->DR, (uint32_t)pData, Length);
1119       }
1120       else
1121       {
1122         /* Pointer to the common control register  */
1123         tmpADC_Common = __LL_ADC_COMMON_INSTANCE(hadc->Instance);
1124 
1125         /* Start the DMA channel */
1126         tmp_hal_status = HAL_DMA_Start_IT(hadc->DMA_Handle, (uint32_t)&tmpADC_Common->CDR, (uint32_t)pData, Length);
1127 
1128         /* Enable conversion of regular group.                                    */
1129         /* If software start has been selected, conversion starts immediately.    */
1130         /* If external trigger has been selected, conversion will start at next   */
1131         /* trigger event.                                                         */
1132         /* Start ADC group regular conversion */
1133         LL_ADC_REG_StartConversion(hadc->Instance);
1134       }
1135     }
1136     else
1137     {
1138       /* Process unlocked */
1139       __HAL_UNLOCK(hadc);
1140     }
1141 
1142     /* Return function status */
1143     return tmp_hal_status;
1144   }
1145 }
1146 
1147 /**
1148   * @brief  Stop multimode ADC conversion, disable ADC DMA transfer, disable ADC peripheral.
1149   * @note   Multimode is kept enabled after this function. MultiMode DMA bits
1150   *         (MDMA and DMACFG bits of common CCR register) are maintained. To disable
1151   *         Multimode (set with HAL_ADCEx_MultiModeConfigChannel()), ADC must be
1152   *         reinitialized using HAL_ADC_Init() or HAL_ADC_DeInit(), or the user can
1153   *         resort to HAL_ADCEx_DisableMultiMode() API.
1154   * @note   In case of DMA configured in circular mode, function
1155   *         HAL_ADC_Stop_DMA() must be called after this function with handle of
1156   *         ADC slave, to properly disable the DMA channel.
1157   * @param hadc ADC handle of ADC master (handle of ADC slave must not be used)
1158   * @retval HAL status
1159   */
1160 HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef *hadc)
1161 {
1162   HAL_StatusTypeDef tmp_hal_status;
1163   uint32_t tickstart;
1164   ADC_HandleTypeDef tmphadcSlave;
1165   uint32_t tmphadcSlave_conversion_on_going;
1166   HAL_StatusTypeDef tmphadcSlave_disable_status;
1167 
1168   /* Check the parameters */
1169   assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance));
1170 
1171   /* Process locked */
1172   __HAL_LOCK(hadc);
1173 
1174 
1175   /* 1. Stop potential multimode conversion on going, on regular and injected groups */
1176   tmp_hal_status = ADC_ConversionStop(hadc, ADC_REGULAR_INJECTED_GROUP);
1177 
1178   /* Disable ADC peripheral if conversions are effectively stopped */
1179   if (tmp_hal_status == HAL_OK)
1180   {
1181     tmphadcSlave.State = HAL_ADC_STATE_RESET;
1182     tmphadcSlave.ErrorCode = HAL_ADC_ERROR_NONE;
1183 
1184     /* Set a temporary handle of the ADC slave associated to the ADC master   */
1185     ADC_MULTI_SLAVE(hadc, &tmphadcSlave);
1186 
1187     if (tmphadcSlave.Instance == NULL)
1188     {
1189       /* Update ADC state machine to error */
1190       SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
1191 
1192       /* Process unlocked */
1193       __HAL_UNLOCK(hadc);
1194 
1195       return HAL_ERROR;
1196     }
1197 
1198     /* Procedure to disable the ADC peripheral: wait for conversions          */
1199     /* effectively stopped (ADC master and ADC slave), then disable ADC       */
1200 
1201     /* 1. Wait for ADC conversion completion for ADC master and ADC slave */
1202     tickstart = HAL_GetTick();
1203 
1204     tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance);
1205     while ((LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 1UL)
1206            || (tmphadcSlave_conversion_on_going == 1UL)
1207           )
1208     {
1209       if ((HAL_GetTick() - tickstart) > ADC_STOP_CONVERSION_TIMEOUT)
1210       {
1211         /* New check to avoid false timeout detection in case of preemption */
1212         tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance);
1213 
1214         if((LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 1UL)
1215            || (tmphadcSlave_conversion_on_going == 1UL)
1216           )
1217         {
1218           /* Update ADC state machine to error */
1219           SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
1220 
1221           /* Process unlocked */
1222           __HAL_UNLOCK(hadc);
1223 
1224           return HAL_ERROR;
1225         }
1226       }
1227 
1228       tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance);
1229     }
1230 
1231     /* Disable the DMA channel (in case of DMA in circular mode or stop       */
1232     /* while DMA transfer is on going)                                        */
1233     /* Note: DMA channel of ADC slave should be stopped after this function   */
1234     /*       with HAL_ADC_Stop_DMA() API.                                     */
1235     tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle);
1236 
1237     /* Check if DMA channel effectively disabled */
1238     if (tmp_hal_status == HAL_ERROR)
1239     {
1240       /* Update ADC state machine to error */
1241       SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_DMA);
1242     }
1243 
1244     /* Disable ADC overrun interrupt */
1245     __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR);
1246 
1247     /* 2. Disable the ADC peripherals: master and slave */
1248     /* Update "tmp_hal_status" only if DMA channel disabling passed, to keep in */
1249     /* memory a potential failing status.                                     */
1250     if (tmp_hal_status == HAL_OK)
1251     {
1252       tmphadcSlave_disable_status = ADC_Disable(&tmphadcSlave);
1253       if ((ADC_Disable(hadc) == HAL_OK)           &&
1254           (tmphadcSlave_disable_status == HAL_OK))
1255       {
1256         tmp_hal_status = HAL_OK;
1257       }
1258     }
1259     else
1260     {
1261       /* In case of error, attempt to disable ADC master and slave without status assert */
1262       (void) ADC_Disable(hadc);
1263       (void) ADC_Disable(&tmphadcSlave);
1264     }
1265 
1266     /* Set ADC state (ADC master) */
1267     ADC_STATE_CLR_SET(hadc->State,
1268                       HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
1269                       HAL_ADC_STATE_READY);
1270   }
1271 
1272   /* Process unlocked */
1273   __HAL_UNLOCK(hadc);
1274 
1275   /* Return function status */
1276   return tmp_hal_status;
1277 }
1278 
1279 /**
1280   * @brief  Return the last ADC Master and Slave regular conversions results when in multimode configuration.
1281   * @param hadc ADC handle of ADC Master (handle of ADC Slave must not be used)
1282   * @retval The converted data values.
1283   */
1284 uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef *hadc)
1285 {
1286   const ADC_Common_TypeDef *tmpADC_Common;
1287 
1288   /* Check the parameters */
1289   assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance));
1290 
1291   /* Prevent unused argument(s) compilation warning if no assert_param check */
1292   /* and possible no usage in __LL_ADC_COMMON_INSTANCE() below               */
1293   UNUSED(hadc);
1294 
1295   /* Pointer to the common control register  */
1296   tmpADC_Common = __LL_ADC_COMMON_INSTANCE(hadc->Instance);
1297 
1298   /* Return the multi mode conversion value */
1299   return tmpADC_Common->CDR;
1300 }
1301 
1302 /**
1303   * @brief  Get ADC injected group conversion result.
1304   * @note   Reading register JDRx automatically clears ADC flag JEOC
1305   *         (ADC group injected end of unitary conversion).
1306   * @note   This function does not clear ADC flag JEOS
1307   *         (ADC group injected end of sequence conversion)
1308   *         Occurrence of flag JEOS rising:
1309   *          - If sequencer is composed of 1 rank, flag JEOS is equivalent
1310   *            to flag JEOC.
1311   *          - If sequencer is composed of several ranks, during the scan
1312   *            sequence flag JEOC only is raised, at the end of the scan sequence
1313   *            both flags JEOC and EOS are raised.
1314   *         Flag JEOS must not be cleared by this function because
1315   *         it would not be compliant with low power features
1316   *         (feature low power auto-wait, not available on all STM32 families).
1317   *         To clear this flag, either use function:
1318   *         in programming model IT: @ref HAL_ADC_IRQHandler(), in programming
1319   *         model polling: @ref HAL_ADCEx_InjectedPollForConversion()
1320   *         or @ref __HAL_ADC_CLEAR_FLAG(&hadc, ADC_FLAG_JEOS).
1321   * @param hadc ADC handle
1322   * @param InjectedRank the converted ADC injected rank.
1323   *          This parameter can be one of the following values:
1324   *            @arg @ref ADC_INJECTED_RANK_1 ADC group injected rank 1
1325   *            @arg @ref ADC_INJECTED_RANK_2 ADC group injected rank 2
1326   *            @arg @ref ADC_INJECTED_RANK_3 ADC group injected rank 3
1327   *            @arg @ref ADC_INJECTED_RANK_4 ADC group injected rank 4
1328   * @retval ADC group injected conversion data
1329   */
1330 uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef *hadc, uint32_t InjectedRank)
1331 {
1332   uint32_t tmp_jdr;
1333 
1334   /* Check the parameters */
1335   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1336   assert_param(IS_ADC_INJECTED_RANK(InjectedRank));
1337 
1338   /* Get ADC converted value */
1339   switch (InjectedRank)
1340   {
1341     case ADC_INJECTED_RANK_4:
1342       tmp_jdr = hadc->Instance->JDR4;
1343       break;
1344     case ADC_INJECTED_RANK_3:
1345       tmp_jdr = hadc->Instance->JDR3;
1346       break;
1347     case ADC_INJECTED_RANK_2:
1348       tmp_jdr = hadc->Instance->JDR2;
1349       break;
1350     case ADC_INJECTED_RANK_1:
1351     default:
1352       tmp_jdr = hadc->Instance->JDR1;
1353       break;
1354   }
1355 
1356   /* Return ADC converted value */
1357   return tmp_jdr;
1358 }
1359 
1360 /**
1361   * @brief  Injected conversion complete callback in non-blocking mode.
1362   * @param hadc ADC handle
1363   * @retval None
1364   */
1365 __weak void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef *hadc)
1366 {
1367   /* Prevent unused argument(s) compilation warning */
1368   UNUSED(hadc);
1369 
1370   /* NOTE : This function should not be modified. When the callback is needed,
1371             function HAL_ADCEx_InjectedConvCpltCallback must be implemented in the user file.
1372   */
1373 }
1374 
1375 /**
1376   * @brief  Injected context queue overflow callback.
1377   * @note   This callback is called if injected context queue is enabled
1378             (parameter "QueueInjectedContext" in injected channel configuration)
1379             and if a new injected context is set when queue is full (maximum 2
1380             contexts).
1381   * @param hadc ADC handle
1382   * @retval None
1383   */
1384 __weak void HAL_ADCEx_InjectedQueueOverflowCallback(ADC_HandleTypeDef *hadc)
1385 {
1386   /* Prevent unused argument(s) compilation warning */
1387   UNUSED(hadc);
1388 
1389   /* NOTE : This function should not be modified. When the callback is needed,
1390             function HAL_ADCEx_InjectedQueueOverflowCallback must be implemented in the user file.
1391   */
1392 }
1393 
1394 /**
1395   * @brief  Analog watchdog 2 callback in non-blocking mode.
1396   * @param hadc ADC handle
1397   * @retval None
1398   */
1399 __weak void HAL_ADCEx_LevelOutOfWindow2Callback(ADC_HandleTypeDef *hadc)
1400 {
1401   /* Prevent unused argument(s) compilation warning */
1402   UNUSED(hadc);
1403 
1404   /* NOTE : This function should not be modified. When the callback is needed,
1405             function HAL_ADCEx_LevelOutOfWindow2Callback must be implemented in the user file.
1406   */
1407 }
1408 
1409 /**
1410   * @brief  Analog watchdog 3 callback in non-blocking mode.
1411   * @param hadc ADC handle
1412   * @retval None
1413   */
1414 __weak void HAL_ADCEx_LevelOutOfWindow3Callback(ADC_HandleTypeDef *hadc)
1415 {
1416   /* Prevent unused argument(s) compilation warning */
1417   UNUSED(hadc);
1418 
1419   /* NOTE : This function should not be modified. When the callback is needed,
1420             function HAL_ADCEx_LevelOutOfWindow3Callback must be implemented in the user file.
1421   */
1422 }
1423 
1424 
1425 /**
1426   * @brief  End Of Sampling callback in non-blocking mode.
1427   * @param hadc ADC handle
1428   * @retval None
1429   */
1430 __weak void HAL_ADCEx_EndOfSamplingCallback(ADC_HandleTypeDef *hadc)
1431 {
1432   /* Prevent unused argument(s) compilation warning */
1433   UNUSED(hadc);
1434 
1435   /* NOTE : This function should not be modified. When the callback is needed,
1436             function HAL_ADCEx_EndOfSamplingCallback must be implemented in the user file.
1437   */
1438 }
1439 
1440 /**
1441   * @brief  Stop ADC conversion of regular group (and injected channels in
1442   *         case of auto_injection mode), disable ADC peripheral if no
1443   *         conversion is on going on injected group.
1444   * @param hadc ADC handle
1445   * @retval HAL status.
1446   */
1447 HAL_StatusTypeDef HAL_ADCEx_RegularStop(ADC_HandleTypeDef *hadc)
1448 {
1449   HAL_StatusTypeDef tmp_hal_status;
1450 
1451   /* Check the parameters */
1452   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1453 
1454   /* Process locked */
1455   __HAL_LOCK(hadc);
1456 
1457   /* 1. Stop potential regular conversion on going */
1458   tmp_hal_status = ADC_ConversionStop(hadc, ADC_REGULAR_GROUP);
1459 
1460   /* Disable ADC peripheral if regular conversions are effectively stopped
1461      and if no injected conversions are on-going */
1462   if (tmp_hal_status == HAL_OK)
1463   {
1464     /* Clear HAL_ADC_STATE_REG_BUSY bit */
1465     CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY);
1466 
1467     if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL)
1468     {
1469       /* 2. Disable the ADC peripheral */
1470       tmp_hal_status = ADC_Disable(hadc);
1471 
1472       /* Check if ADC is effectively disabled */
1473       if (tmp_hal_status == HAL_OK)
1474       {
1475         /* Set ADC state */
1476         ADC_STATE_CLR_SET(hadc->State,
1477                           HAL_ADC_STATE_INJ_BUSY,
1478                           HAL_ADC_STATE_READY);
1479       }
1480     }
1481     /* Conversion on injected group is stopped, but ADC not disabled since    */
1482     /* conversion on regular group is still running.                          */
1483     else
1484     {
1485       SET_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
1486     }
1487   }
1488 
1489   /* Process unlocked */
1490   __HAL_UNLOCK(hadc);
1491 
1492   /* Return function status */
1493   return tmp_hal_status;
1494 }
1495 
1496 
1497 /**
1498   * @brief  Stop ADC conversion of ADC groups regular and injected,
1499   *         disable interrution of end-of-conversion,
1500   *         disable ADC peripheral if no conversion is on going
1501   *         on injected group.
1502   * @param hadc ADC handle
1503   * @retval HAL status.
1504   */
1505 HAL_StatusTypeDef HAL_ADCEx_RegularStop_IT(ADC_HandleTypeDef *hadc)
1506 {
1507   HAL_StatusTypeDef tmp_hal_status;
1508 
1509   /* Check the parameters */
1510   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1511 
1512   /* Process locked */
1513   __HAL_LOCK(hadc);
1514 
1515   /* 1. Stop potential regular conversion on going */
1516   tmp_hal_status = ADC_ConversionStop(hadc, ADC_REGULAR_GROUP);
1517 
1518   /* Disable ADC peripheral if conversions are effectively stopped
1519     and if no injected conversion is on-going */
1520   if (tmp_hal_status == HAL_OK)
1521   {
1522     /* Clear HAL_ADC_STATE_REG_BUSY bit */
1523     CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY);
1524 
1525     /* Disable all regular-related interrupts */
1526     __HAL_ADC_DISABLE_IT(hadc, (ADC_IT_EOC | ADC_IT_EOS | ADC_IT_OVR));
1527 
1528     /* 2. Disable ADC peripheral if no injected conversions are on-going */
1529     if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL)
1530     {
1531       tmp_hal_status = ADC_Disable(hadc);
1532       /* if no issue reported */
1533       if (tmp_hal_status == HAL_OK)
1534       {
1535         /* Set ADC state */
1536         ADC_STATE_CLR_SET(hadc->State,
1537                           HAL_ADC_STATE_INJ_BUSY,
1538                           HAL_ADC_STATE_READY);
1539       }
1540     }
1541     else
1542     {
1543       SET_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
1544     }
1545   }
1546 
1547   /* Process unlocked */
1548   __HAL_UNLOCK(hadc);
1549 
1550   /* Return function status */
1551   return tmp_hal_status;
1552 }
1553 
1554 /**
1555   * @brief  Stop ADC conversion of regular group (and injected group in
1556   *         case of auto_injection mode), disable ADC DMA transfer, disable
1557   *         ADC peripheral if no conversion is on going
1558   *         on injected group.
1559   * @note   HAL_ADCEx_RegularStop_DMA() function is dedicated to single-ADC mode only.
1560   *         For multimode (when multimode feature is available),
1561   *         HAL_ADCEx_RegularMultiModeStop_DMA() API must be used.
1562   * @param hadc ADC handle
1563   * @retval HAL status.
1564   */
1565 HAL_StatusTypeDef HAL_ADCEx_RegularStop_DMA(ADC_HandleTypeDef *hadc)
1566 {
1567   HAL_StatusTypeDef tmp_hal_status;
1568 
1569   /* Check the parameters */
1570   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1571 
1572   /* Process locked */
1573   __HAL_LOCK(hadc);
1574 
1575   /* 1. Stop potential regular conversion on going */
1576   tmp_hal_status = ADC_ConversionStop(hadc, ADC_REGULAR_GROUP);
1577 
1578   /* Disable ADC peripheral if conversions are effectively stopped
1579      and if no injected conversion is on-going */
1580   if (tmp_hal_status == HAL_OK)
1581   {
1582     /* Clear HAL_ADC_STATE_REG_BUSY bit */
1583     CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY);
1584 
1585     /* Disable ADC DMA (ADC DMA configuration ADC_CFGR_DMACFG is kept) */
1586     MODIFY_REG(hadc->Instance->CFGR, ADC_CFGR_DMNGT_0 | ADC_CFGR_DMNGT_1, 0UL);
1587 
1588     /* Disable the DMA channel (in case of DMA in circular mode or stop while */
1589     /* while DMA transfer is on going)                                        */
1590     tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle);
1591 
1592     /* Check if DMA channel effectively disabled */
1593     if (tmp_hal_status != HAL_OK)
1594     {
1595       /* Update ADC state machine to error */
1596       SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_DMA);
1597     }
1598 
1599     /* Disable ADC overrun interrupt */
1600     __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR);
1601 
1602     /* 2. Disable the ADC peripheral */
1603     /* Update "tmp_hal_status" only if DMA channel disabling passed,          */
1604     /* to keep in memory a potential failing status.                          */
1605     if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL)
1606     {
1607       if (tmp_hal_status == HAL_OK)
1608       {
1609         tmp_hal_status = ADC_Disable(hadc);
1610       }
1611       else
1612       {
1613         (void)ADC_Disable(hadc);
1614       }
1615 
1616       /* Check if ADC is effectively disabled */
1617       if (tmp_hal_status == HAL_OK)
1618       {
1619         /* Set ADC state */
1620         ADC_STATE_CLR_SET(hadc->State,
1621                           HAL_ADC_STATE_INJ_BUSY,
1622                           HAL_ADC_STATE_READY);
1623       }
1624     }
1625     else
1626     {
1627       SET_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
1628     }
1629   }
1630 
1631   /* Process unlocked */
1632   __HAL_UNLOCK(hadc);
1633 
1634   /* Return function status */
1635   return tmp_hal_status;
1636 }
1637 
1638 /**
1639   * @brief  Stop DMA-based multimode ADC conversion, disable ADC DMA transfer, disable ADC peripheral if no injected conversion is on-going.
1640   * @note   Multimode is kept enabled after this function. Multimode DMA bits
1641   *         (MDMA and DMACFG bits of common CCR register) are maintained. To disable
1642   *         multimode (set with HAL_ADCEx_MultiModeConfigChannel()), ADC must be
1643   *         reinitialized using HAL_ADC_Init() or HAL_ADC_DeInit(), or the user can
1644   *         resort to HAL_ADCEx_DisableMultiMode() API.
1645   * @note   In case of DMA configured in circular mode, function
1646   *         HAL_ADCEx_RegularStop_DMA() must be called after this function with handle of
1647   *         ADC slave, to properly disable the DMA channel.
1648   * @param hadc ADC handle of ADC master (handle of ADC slave must not be used)
1649   * @retval HAL status
1650   */
1651 HAL_StatusTypeDef HAL_ADCEx_RegularMultiModeStop_DMA(ADC_HandleTypeDef *hadc)
1652 {
1653   HAL_StatusTypeDef tmp_hal_status;
1654   uint32_t tickstart;
1655   ADC_HandleTypeDef tmphadcSlave;
1656   uint32_t tmphadcSlave_conversion_on_going;
1657 
1658   /* Check the parameters */
1659   assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance));
1660 
1661   /* Process locked */
1662   __HAL_LOCK(hadc);
1663 
1664 
1665   /* 1. Stop potential multimode conversion on going, on regular groups */
1666   tmp_hal_status = ADC_ConversionStop(hadc, ADC_REGULAR_GROUP);
1667 
1668   /* Disable ADC peripheral if conversions are effectively stopped */
1669   if (tmp_hal_status == HAL_OK)
1670   {
1671     /* Clear HAL_ADC_STATE_REG_BUSY bit */
1672     CLEAR_BIT(hadc->State, HAL_ADC_STATE_REG_BUSY);
1673 
1674     tmphadcSlave.State = HAL_ADC_STATE_RESET;
1675     tmphadcSlave.ErrorCode = HAL_ADC_ERROR_NONE;
1676 
1677     /* Set a temporary handle of the ADC slave associated to the ADC master   */
1678     ADC_MULTI_SLAVE(hadc, &tmphadcSlave);
1679 
1680     if (tmphadcSlave.Instance == NULL)
1681     {
1682       /* Update ADC state machine to error */
1683       SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
1684 
1685       /* Process unlocked */
1686       __HAL_UNLOCK(hadc);
1687 
1688       return HAL_ERROR;
1689     }
1690 
1691     /* Procedure to disable the ADC peripheral: wait for conversions          */
1692     /* effectively stopped (ADC master and ADC slave), then disable ADC       */
1693 
1694     /* 1. Wait for ADC conversion completion for ADC master and ADC slave */
1695     tickstart = HAL_GetTick();
1696 
1697     tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance);
1698     while ((LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 1UL)
1699            || (tmphadcSlave_conversion_on_going == 1UL)
1700           )
1701     {
1702       if ((HAL_GetTick() - tickstart) > ADC_STOP_CONVERSION_TIMEOUT)
1703       {
1704         /* New check to avoid false timeout detection in case of preemption */
1705         tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance);
1706 
1707         if((LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 1UL)
1708            || (tmphadcSlave_conversion_on_going == 1UL)
1709           )
1710         {
1711           /* Update ADC state machine to error */
1712           SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
1713 
1714           /* Process unlocked */
1715           __HAL_UNLOCK(hadc);
1716 
1717           return HAL_ERROR;
1718         }
1719       }
1720 
1721       tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance);
1722     }
1723 
1724     /* Disable the DMA channel (in case of DMA in circular mode or stop       */
1725     /* while DMA transfer is on going)                                        */
1726     /* Note: DMA channel of ADC slave should be stopped after this function   */
1727     /* with HAL_ADCEx_RegularStop_DMA() API.                                  */
1728     tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle);
1729 
1730     /* Check if DMA channel effectively disabled */
1731     if (tmp_hal_status != HAL_OK)
1732     {
1733       /* Update ADC state machine to error */
1734       SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_DMA);
1735     }
1736 
1737     /* Disable ADC overrun interrupt */
1738     __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR);
1739 
1740     /* 2. Disable the ADC peripherals: master and slave if no injected        */
1741     /*   conversion is on-going.                                              */
1742     /* Update "tmp_hal_status" only if DMA channel disabling passed, to keep in */
1743     /* memory a potential failing status.                                     */
1744     if (tmp_hal_status == HAL_OK)
1745     {
1746       if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL)
1747       {
1748         tmp_hal_status =  ADC_Disable(hadc);
1749         if (tmp_hal_status == HAL_OK)
1750         {
1751           if (LL_ADC_INJ_IsConversionOngoing((&tmphadcSlave)->Instance) == 0UL)
1752           {
1753             tmp_hal_status =  ADC_Disable(&tmphadcSlave);
1754           }
1755         }
1756       }
1757 
1758       if (tmp_hal_status == HAL_OK)
1759       {
1760         /* Both Master and Slave ADC's could be disabled. Update Master State */
1761         /* Clear HAL_ADC_STATE_INJ_BUSY bit, set HAL_ADC_STATE_READY bit */
1762         ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_BUSY, HAL_ADC_STATE_READY);
1763       }
1764       else
1765       {
1766         /* injected (Master or Slave) conversions are still on-going,
1767            no Master State change */
1768       }
1769     }
1770   }
1771 
1772   /* Process unlocked */
1773   __HAL_UNLOCK(hadc);
1774 
1775   /* Return function status */
1776   return tmp_hal_status;
1777 }
1778 
1779 /**
1780   * @}
1781   */
1782 
1783 /** @defgroup ADCEx_Exported_Functions_Group2 ADC Extended Peripheral Control functions
1784   * @ingroup RTEMSBSPsARMSTM32H7
1785   * @brief    ADC Extended Peripheral Control functions
1786   *
1787 @verbatim
1788  ===============================================================================
1789              ##### Peripheral Control functions #####
1790  ===============================================================================
1791     [..]  This section provides functions allowing to:
1792       (+) Configure channels on injected group
1793       (+) Configure multimode when multimode feature is available
1794       (+) Enable or Disable Injected Queue
1795       (+) Disable ADC voltage regulator
1796       (+) Enter ADC deep-power-down mode
1797 
1798 @endverbatim
1799   * @{
1800   */
1801 
1802 /**
1803   * @brief  Configure a channel to be assigned to ADC group injected.
1804   * @note   Possibility to update parameters on the fly:
1805   *         This function initializes injected group, following calls to this
1806   *         function can be used to reconfigure some parameters of structure
1807   *         "ADC_InjectionConfTypeDef" on the fly, without resetting the ADC.
1808   *         The setting of these parameters is conditioned to ADC state:
1809   *         Refer to comments of structure "ADC_InjectionConfTypeDef".
1810   * @note   In case of usage of internal measurement channels:
1811   *         Vbat/VrefInt/TempSensor.
1812   *         These internal paths can be disabled using function
1813   *         HAL_ADC_DeInit().
1814   * @note   Caution: For Injected Context Queue use, a context must be fully
1815   *         defined before start of injected conversion. All channels are configured
1816   *         consecutively for the same ADC instance. Therefore, the number of calls to
1817   *         HAL_ADCEx_InjectedConfigChannel() must be equal to the value of parameter
1818   *         InjectedNbrOfConversion for each context.
1819   *  - Example 1: If 1 context is intended to be used (or if there is no use of the
1820   *    Injected Queue Context feature) and if the context contains 3 injected ranks
1821   *    (InjectedNbrOfConversion = 3), HAL_ADCEx_InjectedConfigChannel() must be
1822   *    called once for each channel (i.e. 3 times) before starting a conversion.
1823   *    This function must not be called to configure a 4th injected channel:
1824   *    it would start a new context into context queue.
1825   *  - Example 2: If 2 contexts are intended to be used and each of them contains
1826   *    3 injected ranks (InjectedNbrOfConversion = 3),
1827   *    HAL_ADCEx_InjectedConfigChannel() must be called once for each channel and
1828   *    for each context (3 channels x 2 contexts = 6 calls). Conversion can
1829   *    start once the 1st context is set, that is after the first three
1830   *    HAL_ADCEx_InjectedConfigChannel() calls. The 2nd context can be set on the fly.
1831   * @param hadc ADC handle
1832   * @param sConfigInjected Structure of ADC injected group and ADC channel for
1833   *         injected group.
1834   * @retval HAL status
1835   */
1836 HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef *hadc, ADC_InjectionConfTypeDef *sConfigInjected)
1837 {
1838   HAL_StatusTypeDef tmp_hal_status = HAL_OK;
1839   uint32_t tmpOffsetShifted;
1840   uint32_t tmp_config_internal_channel;
1841   uint32_t tmp_adc_is_conversion_on_going_regular;
1842   uint32_t tmp_adc_is_conversion_on_going_injected;
1843   __IO uint32_t wait_loop_index = 0;
1844 
1845   uint32_t tmp_JSQR_ContextQueueBeingBuilt = 0U;
1846 
1847   /* Check the parameters */
1848   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
1849   assert_param(IS_ADC_SAMPLE_TIME(sConfigInjected->InjectedSamplingTime));
1850   assert_param(IS_ADC_SINGLE_DIFFERENTIAL(sConfigInjected->InjectedSingleDiff));
1851   assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->AutoInjectedConv));
1852   assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->QueueInjectedContext));
1853   assert_param(IS_ADC_EXTTRIGINJEC_EDGE(sConfigInjected->ExternalTrigInjecConvEdge));
1854   assert_param(IS_ADC_EXTTRIGINJEC(sConfigInjected->ExternalTrigInjecConv));
1855   assert_param(IS_ADC_OFFSET_NUMBER(sConfigInjected->InjectedOffsetNumber));
1856   assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->InjecOversamplingMode));
1857 #if defined(ADC_VER_V5_V90)
1858   assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->InjectedOffsetSaturation));
1859   if (hadc->Instance == ADC3)
1860   {
1861     assert_param(IS_ADC3_OFFSET_SIGN(sConfigInjected->InjectedOffsetSign));
1862     assert_param(IS_ADC3_RANGE(ADC_GET_RESOLUTION(hadc), sConfigInjected->InjectedOffset));
1863   }
1864   else
1865 #endif /* ADC_VER_V5_V90 */
1866   {
1867     assert_param(IS_ADC_RANGE(ADC_GET_RESOLUTION(hadc), sConfigInjected->InjectedOffset));
1868   }
1869 
1870   if (hadc->Init.ScanConvMode != ADC_SCAN_DISABLE)
1871   {
1872     assert_param(IS_ADC_INJECTED_RANK(sConfigInjected->InjectedRank));
1873     assert_param(IS_ADC_INJECTED_NB_CONV(sConfigInjected->InjectedNbrOfConversion));
1874     assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->InjectedDiscontinuousConvMode));
1875   }
1876 
1877   /* Check offset range according to oversampling setting */
1878   if (hadc->Init.OversamplingMode == ENABLE)
1879   {
1880     assert_param(IS_ADC_RANGE(ADC_GET_RESOLUTION(hadc), sConfigInjected->InjectedOffset / (hadc->Init.Oversampling.Ratio + 1U)));
1881   }
1882   else
1883   {
1884     assert_param(IS_ADC_RANGE(ADC_GET_RESOLUTION(hadc), sConfigInjected->InjectedOffset));
1885   }
1886 #if defined(ADC_VER_V5_V90)
1887   /* if JOVSE is set, the value of the OFFSETy_EN bit in ADCx_OFRy register is
1888      ignored (considered as reset) */
1889   if (hadc->Instance == ADC3)
1890   {
1891     assert_param(!((sConfigInjected->InjectedOffsetNumber != ADC_OFFSET_NONE) && (sConfigInjected->InjecOversamplingMode == ENABLE)));
1892   }
1893 #endif  /* ADC_VER_V5_V90 */
1894   /* JDISCEN and JAUTO bits can't be set at the same time  */
1895   assert_param(!((sConfigInjected->InjectedDiscontinuousConvMode == ENABLE) && (sConfigInjected->AutoInjectedConv == ENABLE)));
1896 
1897   /*  DISCEN and JAUTO bits can't be set at the same time */
1898   assert_param(!((hadc->Init.DiscontinuousConvMode == ENABLE) && (sConfigInjected->AutoInjectedConv == ENABLE)));
1899 
1900   /* Verification of channel number */
1901   if (sConfigInjected->InjectedSingleDiff != ADC_DIFFERENTIAL_ENDED)
1902   {
1903     assert_param(IS_ADC_CHANNEL(sConfigInjected->InjectedChannel));
1904   }
1905   else
1906   {
1907     if (hadc->Instance == ADC1)
1908     {
1909       assert_param(IS_ADC1_DIFF_CHANNEL(sConfigInjected->InjectedChannel));
1910     }
1911     if (hadc->Instance == ADC2)
1912     {
1913       assert_param(IS_ADC2_DIFF_CHANNEL(sConfigInjected->InjectedChannel));
1914     }
1915 #if defined (ADC3)
1916     if (hadc->Instance == ADC3)
1917     {
1918       assert_param(IS_ADC3_DIFF_CHANNEL(sConfigInjected->InjectedChannel));
1919     }
1920 #endif
1921   }
1922 
1923   /* Process locked */
1924   __HAL_LOCK(hadc);
1925 
1926   /* Configuration of injected group sequencer:                               */
1927   /* Hardware constraint: Must fully define injected context register JSQR    */
1928   /* before make it entering into injected sequencer queue.                   */
1929   /*                                                                          */
1930   /* - if scan mode is disabled:                                              */
1931   /*    * Injected channels sequence length is set to 0x00: 1 channel         */
1932   /*      converted (channel on injected rank 1)                              */
1933   /*      Parameter "InjectedNbrOfConversion" is discarded.                   */
1934   /*    * Injected context register JSQR setting is simple: register is fully */
1935   /*      defined on one call of this function (for injected rank 1) and can  */
1936   /*      be entered into queue directly.                                     */
1937   /* - if scan mode is enabled:                                               */
1938   /*    * Injected channels sequence length is set to parameter               */
1939   /*      "InjectedNbrOfConversion".                                          */
1940   /*    * Injected context register JSQR setting more complex: register is    */
1941   /*      fully defined over successive calls of this function, for each      */
1942   /*      injected channel rank. It is entered into queue only when all       */
1943   /*      injected ranks have been set.                                       */
1944   /*   Note: Scan mode is not present by hardware on this device, but used    */
1945   /*   by software for alignment over all STM32 devices.                      */
1946 
1947   if ((hadc->Init.ScanConvMode == ADC_SCAN_DISABLE)  ||
1948       (sConfigInjected->InjectedNbrOfConversion == 1U))
1949   {
1950     /* Configuration of context register JSQR:                                */
1951     /*  - number of ranks in injected group sequencer: fixed to 1st rank      */
1952     /*    (scan mode disabled, only rank 1 used)                              */
1953     /*  - external trigger to start conversion                                */
1954     /*  - external trigger polarity                                           */
1955     /*  - channel set to rank 1 (scan mode disabled, only rank 1 can be used) */
1956 
1957     if (sConfigInjected->InjectedRank == ADC_INJECTED_RANK_1)
1958     {
1959       /* Enable external trigger if trigger selection is different of         */
1960       /* software start.                                                      */
1961       /* Note: This configuration keeps the hardware feature of parameter     */
1962       /*       ExternalTrigInjecConvEdge "trigger edge none" equivalent to    */
1963       /*       software start.                                                */
1964       if (sConfigInjected->ExternalTrigInjecConv != ADC_INJECTED_SOFTWARE_START)
1965       {
1966         tmp_JSQR_ContextQueueBeingBuilt = (ADC_JSQR_RK(sConfigInjected->InjectedChannel, ADC_INJECTED_RANK_1)
1967                                            | (sConfigInjected->ExternalTrigInjecConv & ADC_JSQR_JEXTSEL)
1968                                            | sConfigInjected->ExternalTrigInjecConvEdge
1969                                           );
1970       }
1971       else
1972       {
1973         tmp_JSQR_ContextQueueBeingBuilt = (ADC_JSQR_RK(sConfigInjected->InjectedChannel, ADC_INJECTED_RANK_1));
1974       }
1975 
1976       MODIFY_REG(hadc->Instance->JSQR, ADC_JSQR_FIELDS, tmp_JSQR_ContextQueueBeingBuilt);
1977       /* For debug and informative reasons, hadc handle saves JSQR setting */
1978       hadc->InjectionConfig.ContextQueue = tmp_JSQR_ContextQueueBeingBuilt;
1979 
1980     }
1981   }
1982   else
1983   {
1984     /* Case of scan mode enabled, several channels to set into injected group */
1985     /* sequencer.                                                             */
1986     /*                                                                        */
1987     /* Procedure to define injected context register JSQR over successive     */
1988     /* calls of this function, for each injected channel rank:                */
1989     /* 1. Start new context and set parameters related to all injected        */
1990     /*    channels: injected sequence length and trigger.                     */
1991 
1992     /* if hadc->InjectionConfig.ChannelCount is equal to 0, this is the first */
1993     /*   call of the context under setting                                    */
1994     if (hadc->InjectionConfig.ChannelCount == 0U)
1995     {
1996       /* Initialize number of channels that will be configured on the context */
1997       /*  being built                                                         */
1998       hadc->InjectionConfig.ChannelCount = sConfigInjected->InjectedNbrOfConversion;
1999       /* Handle hadc saves the context under build up over each HAL_ADCEx_InjectedConfigChannel()
2000          call, this context will be written in JSQR register at the last call.
2001          At this point, the context is merely reset  */
2002       hadc->InjectionConfig.ContextQueue = 0x00000000U;
2003 
2004       /* Configuration of context register JSQR:                              */
2005       /*  - number of ranks in injected group sequencer                       */
2006       /*  - external trigger to start conversion                              */
2007       /*  - external trigger polarity                                         */
2008 
2009       /* Enable external trigger if trigger selection is different of         */
2010       /* software start.                                                      */
2011       /* Note: This configuration keeps the hardware feature of parameter     */
2012       /*       ExternalTrigInjecConvEdge "trigger edge none" equivalent to    */
2013       /*       software start.                                                */
2014       if (sConfigInjected->ExternalTrigInjecConv != ADC_INJECTED_SOFTWARE_START)
2015       {
2016         tmp_JSQR_ContextQueueBeingBuilt = ((sConfigInjected->InjectedNbrOfConversion - 1U)
2017                                            | (sConfigInjected->ExternalTrigInjecConv & ADC_JSQR_JEXTSEL)
2018                                            | sConfigInjected->ExternalTrigInjecConvEdge
2019                                           );
2020       }
2021       else
2022       {
2023         tmp_JSQR_ContextQueueBeingBuilt = ((sConfigInjected->InjectedNbrOfConversion - 1U));
2024       }
2025 
2026     }
2027 
2028     /* 2. Continue setting of context under definition with parameter       */
2029     /*    related to each channel: channel rank sequence                    */
2030     /* Clear the old JSQx bits for the selected rank */
2031     tmp_JSQR_ContextQueueBeingBuilt &= ~ADC_JSQR_RK(ADC_SQR3_SQ10, sConfigInjected->InjectedRank);
2032 
2033     /* Set the JSQx bits for the selected rank */
2034     tmp_JSQR_ContextQueueBeingBuilt |= ADC_JSQR_RK(sConfigInjected->InjectedChannel, sConfigInjected->InjectedRank);
2035 
2036     /* Decrease channel count  */
2037     hadc->InjectionConfig.ChannelCount--;
2038 
2039     /* 3. tmp_JSQR_ContextQueueBeingBuilt is fully built for this HAL_ADCEx_InjectedConfigChannel()
2040           call, aggregate the setting to those already built during the previous
2041           HAL_ADCEx_InjectedConfigChannel() calls (for the same context of course)  */
2042     hadc->InjectionConfig.ContextQueue |= tmp_JSQR_ContextQueueBeingBuilt;
2043 
2044     /* 4. End of context setting: if this is the last channel set, then write context
2045         into register JSQR and make it enter into queue                   */
2046     if (hadc->InjectionConfig.ChannelCount == 0U)
2047     {
2048       MODIFY_REG(hadc->Instance->JSQR, ADC_JSQR_FIELDS, hadc->InjectionConfig.ContextQueue);
2049     }
2050   }
2051 
2052   /* Parameters update conditioned to ADC state:                              */
2053   /* Parameters that can be updated when ADC is disabled or enabled without   */
2054   /* conversion on going on injected group:                                   */
2055   /*  - Injected context queue: Queue disable (active context is kept) or     */
2056   /*    enable (context decremented, up to 2 contexts queued)                 */
2057   /*  - Injected discontinuous mode: can be enabled only if auto-injected     */
2058   /*    mode is disabled.                                                     */
2059   if (LL_ADC_INJ_IsConversionOngoing(hadc->Instance) == 0UL)
2060   {
2061     if (!(__LL_ADC_IS_CHANNEL_INTERNAL(sConfigInjected->InjectedChannel)))
2062     {
2063 #if defined(ADC_VER_V5_V90)
2064       if (hadc->Instance != ADC3)
2065       {
2066         /* ADC channels preselection */
2067         hadc->Instance->PCSEL_RES0 |= (1UL << (__LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel) & 0x1FUL));
2068       }
2069 #else
2070       /* ADC channels preselection */
2071       hadc->Instance->PCSEL |= (1UL << (__LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel) & 0x1FUL));
2072 #endif /* ADC_VER_V5_V90 */
2073     }
2074 
2075     /* If auto-injected mode is disabled: no constraint                       */
2076     if (sConfigInjected->AutoInjectedConv == DISABLE)
2077     {
2078       MODIFY_REG(hadc->Instance->CFGR,
2079                  ADC_CFGR_JQM | ADC_CFGR_JDISCEN,
2080                  ADC_CFGR_INJECT_CONTEXT_QUEUE((uint32_t)sConfigInjected->QueueInjectedContext)           |
2081                  ADC_CFGR_INJECT_DISCCONTINUOUS((uint32_t)sConfigInjected->InjectedDiscontinuousConvMode));
2082     }
2083     /* If auto-injected mode is enabled: Injected discontinuous setting is    */
2084     /* discarded.                                                             */
2085     else
2086     {
2087       MODIFY_REG(hadc->Instance->CFGR,
2088                  ADC_CFGR_JQM | ADC_CFGR_JDISCEN,
2089                  ADC_CFGR_INJECT_CONTEXT_QUEUE((uint32_t)sConfigInjected->QueueInjectedContext));
2090     }
2091 
2092   }
2093 
2094   /* Parameters update conditioned to ADC state:                              */
2095   /* Parameters that can be updated when ADC is disabled or enabled without   */
2096   /* conversion on going on regular and injected groups:                      */
2097   /*  - Automatic injected conversion: can be enabled if injected group       */
2098   /*    external triggers are disabled.                                       */
2099   /*  - Channel sampling time                                                 */
2100   /*  - Channel offset                                                        */
2101   tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
2102   tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance);
2103 
2104   if ((tmp_adc_is_conversion_on_going_regular == 0UL)
2105       && (tmp_adc_is_conversion_on_going_injected == 0UL)
2106      )
2107   {
2108     /* If injected group external triggers are disabled (set to injected      */
2109     /* software start): no constraint                                         */
2110     if ((sConfigInjected->ExternalTrigInjecConv == ADC_INJECTED_SOFTWARE_START)
2111         || (sConfigInjected->ExternalTrigInjecConvEdge == ADC_EXTERNALTRIGINJECCONV_EDGE_NONE))
2112     {
2113       if (sConfigInjected->AutoInjectedConv == ENABLE)
2114       {
2115         SET_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO);
2116       }
2117       else
2118       {
2119         CLEAR_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO);
2120       }
2121     }
2122     /* If Automatic injected conversion was intended to be set and could not  */
2123     /* due to injected group external triggers enabled, error is reported.    */
2124     else
2125     {
2126       if (sConfigInjected->AutoInjectedConv == ENABLE)
2127       {
2128         /* Update ADC state machine to error */
2129         SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
2130 
2131         tmp_hal_status = HAL_ERROR;
2132       }
2133       else
2134       {
2135         CLEAR_BIT(hadc->Instance->CFGR, ADC_CFGR_JAUTO);
2136       }
2137     }
2138 
2139     if (sConfigInjected->InjecOversamplingMode == ENABLE)
2140     {
2141 #if defined(ADC_VER_V5_V90)
2142       if (hadc->Instance == ADC3)
2143       {
2144         assert_param(IS_ADC_OVERSAMPLING_RATIO_ADC3(sConfigInjected->InjecOversampling.Ratio));
2145       }
2146       else
2147       {
2148         assert_param(IS_ADC_OVERSAMPLING_RATIO(sConfigInjected->InjecOversampling.Ratio));
2149       }
2150 #else
2151       assert_param(IS_ADC_OVERSAMPLING_RATIO(sConfigInjected->InjecOversampling.Ratio));
2152 #endif
2153       assert_param(IS_ADC_RIGHT_BIT_SHIFT(sConfigInjected->InjecOversampling.RightBitShift));
2154 
2155       /*  JOVSE must be reset in case of triggered regular mode  */
2156       assert_param(!(READ_BIT(hadc->Instance->CFGR2, ADC_CFGR2_ROVSE | ADC_CFGR2_TROVS) == (ADC_CFGR2_ROVSE | ADC_CFGR2_TROVS)));
2157 
2158       /* Configuration of Injected Oversampler:                                 */
2159       /*  - Oversampling Ratio                                                  */
2160       /*  - Right bit shift                                                     */
2161 
2162       /* Enable OverSampling mode */
2163 #if defined(ADC_VER_V5_V90)
2164       if (hadc->Instance != ADC3)
2165       {
2166         MODIFY_REG(hadc->Instance->CFGR2,
2167                    ADC_CFGR2_JOVSE |
2168                    ADC_CFGR2_OVSR  |
2169                    ADC_CFGR2_OVSS,
2170                    ADC_CFGR2_JOVSE                                  |
2171                   ((sConfigInjected->InjecOversampling.Ratio - 1UL) << ADC_CFGR2_OVSR_Pos) |
2172                    sConfigInjected->InjecOversampling.RightBitShift
2173                   );
2174       }
2175       else
2176       {
2177         MODIFY_REG(hadc->Instance->CFGR2,
2178                    ADC_CFGR2_JOVSE |
2179                    ADC3_CFGR2_OVSR  |
2180                    ADC_CFGR2_OVSS,
2181                    ADC_CFGR2_JOVSE                                  |
2182                   (sConfigInjected->InjecOversampling.Ratio)        |
2183                    sConfigInjected->InjecOversampling.RightBitShift
2184                   );
2185       }
2186 #else
2187       MODIFY_REG(hadc->Instance->CFGR2,
2188            ADC_CFGR2_JOVSE |
2189            ADC_CFGR2_OVSR  |
2190            ADC_CFGR2_OVSS,
2191            ADC_CFGR2_JOVSE                                  |
2192           ((sConfigInjected->InjecOversampling.Ratio - 1UL) << ADC_CFGR2_OVSR_Pos) |
2193            sConfigInjected->InjecOversampling.RightBitShift
2194           );
2195 #endif
2196     }
2197     else
2198     {
2199       /* Disable Regular OverSampling */
2200       CLEAR_BIT(hadc->Instance->CFGR2, ADC_CFGR2_JOVSE);
2201     }
2202 
2203     /* Set sampling time of the selected ADC channel */
2204     LL_ADC_SetChannelSamplingTime(hadc->Instance, sConfigInjected->InjectedChannel, sConfigInjected->InjectedSamplingTime);
2205 
2206     /* Configure the offset: offset enable/disable, channel, offset value */
2207 
2208     /* Shift the offset with respect to the selected ADC resolution. */
2209     /* Offset has to be left-aligned on bit 11, the LSB (right bits) are set to 0 */
2210 #if defined(ADC_VER_V5_V90)
2211     if (hadc->Instance == ADC3)
2212     {
2213       tmpOffsetShifted = ADC3_OFFSET_SHIFT_RESOLUTION(hadc, sConfigInjected->InjectedOffset);
2214     }
2215     else
2216 #endif /* ADC_VER_V5_V90 */
2217     {
2218       tmpOffsetShifted = ADC_OFFSET_SHIFT_RESOLUTION(hadc, sConfigInjected->InjectedOffset);
2219     }
2220 
2221     if (sConfigInjected->InjectedOffsetNumber != ADC_OFFSET_NONE)
2222     {
2223       /* Set ADC selected offset number */
2224       LL_ADC_SetOffset(hadc->Instance, sConfigInjected->InjectedOffsetNumber, sConfigInjected->InjectedChannel, tmpOffsetShifted);
2225 
2226 #if defined(ADC_VER_V5_V90)
2227       if (hadc->Instance == ADC3)
2228       {
2229         /* Set ADC selected offset sign & saturation */
2230         LL_ADC_SetOffsetSign(hadc->Instance, sConfigInjected->InjectedOffsetNumber, sConfigInjected->InjectedOffsetSign);
2231         LL_ADC_SetOffsetSaturation(hadc->Instance, sConfigInjected->InjectedOffsetNumber, (sConfigInjected->InjectedOffsetSaturation == ENABLE) ? LL_ADC_OFFSET_SATURATION_ENABLE : LL_ADC_OFFSET_SATURATION_DISABLE);
2232       }
2233       else
2234 #endif /* ADC_VER_V5_V90 */
2235       {
2236         /* Set ADC selected offset signed saturation */
2237         LL_ADC_SetOffsetSignedSaturation(hadc->Instance, sConfigInjected->InjectedOffsetNumber, (sConfigInjected->InjectedOffsetSignedSaturation == ENABLE) ? LL_ADC_OFFSET_SIGNED_SATURATION_ENABLE : LL_ADC_OFFSET_SIGNED_SATURATION_DISABLE);
2238       }
2239 
2240     }
2241     else
2242     {
2243 #if defined(ADC_VER_V5_V90)
2244       if (hadc->Instance == ADC3)
2245       {
2246         /* Scan each offset register to check if the selected channel is targeted. */
2247         /* If this is the case, the corresponding offset number is disabled.       */
2248         if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_1)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel))
2249         {
2250           LL_ADC_SetOffsetState(hadc->Instance, LL_ADC_OFFSET_1, LL_ADC_OFFSET_DISABLE);
2251         }
2252         if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_2)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel))
2253         {
2254           LL_ADC_SetOffsetState(hadc->Instance, LL_ADC_OFFSET_2, LL_ADC_OFFSET_DISABLE);
2255         }
2256         if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_3)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel))
2257         {
2258           LL_ADC_SetOffsetState(hadc->Instance, LL_ADC_OFFSET_3, LL_ADC_OFFSET_DISABLE);
2259         }
2260         if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_4)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel))
2261         {
2262           LL_ADC_SetOffsetState(hadc->Instance, LL_ADC_OFFSET_4, LL_ADC_OFFSET_DISABLE);
2263         }
2264       }
2265       else
2266 #endif /* ADC_VER_V5_V90 */
2267       {
2268         /* Scan each offset register to check if the selected channel is targeted. */
2269         /* If this is the case, the corresponding offset number is disabled.       */
2270         if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_1)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel))
2271         {
2272           LL_ADC_SetOffset(hadc->Instance, LL_ADC_OFFSET_1, sConfigInjected->InjectedChannel, LL_ADC_OFFSET_SIGNED_SATURATION_DISABLE);
2273         }
2274         if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_2)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel))
2275         {
2276           LL_ADC_SetOffset(hadc->Instance, LL_ADC_OFFSET_2, sConfigInjected->InjectedChannel, LL_ADC_OFFSET_SIGNED_SATURATION_DISABLE);
2277         }
2278         if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_3)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel))
2279         {
2280           LL_ADC_SetOffset(hadc->Instance, LL_ADC_OFFSET_4, sConfigInjected->InjectedChannel, LL_ADC_OFFSET_SIGNED_SATURATION_DISABLE);
2281         }
2282         if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_4)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfigInjected->InjectedChannel))
2283         {
2284           LL_ADC_SetOffset(hadc->Instance, LL_ADC_OFFSET_4, sConfigInjected->InjectedChannel, LL_ADC_OFFSET_SIGNED_SATURATION_DISABLE);
2285         }
2286       }
2287     }
2288 
2289   }
2290 
2291   /* Parameters update conditioned to ADC state:                              */
2292   /* Parameters that can be updated only when ADC is disabled:                */
2293   /*  - Single or differential mode                                           */
2294   /*  - Internal measurement channels: Vbat/VrefInt/TempSensor                */
2295   if (LL_ADC_IsEnabled(hadc->Instance) == 0UL)
2296   {
2297     /* Set mode single-ended or differential input of the selected ADC channel */
2298     LL_ADC_SetChannelSingleDiff(hadc->Instance, sConfigInjected->InjectedChannel, sConfigInjected->InjectedSingleDiff);
2299 
2300     /* Configuration of differential mode */
2301     /* Note: ADC channel number masked with value "0x1F" to ensure shift value within 32 bits range */
2302     if (sConfigInjected->InjectedSingleDiff == ADC_DIFFERENTIAL_ENDED)
2303     {
2304       /* Set sampling time of the selected ADC channel */
2305       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);
2306     }
2307 
2308     /* Management of internal measurement channels: Vbat/VrefInt/TempSensor   */
2309     /* internal measurement paths enable: If internal channel selected,       */
2310     /* enable dedicated internal buffers and path.                            */
2311     /* Note: these internal measurement paths can be disabled using           */
2312     /* HAL_ADC_DeInit().                                                      */
2313 
2314     if (__LL_ADC_IS_CHANNEL_INTERNAL(sConfigInjected->InjectedChannel))
2315     {
2316       /* Configuration of common ADC parameters (continuation)                */
2317       /* Software is allowed to change common parameters only when all ADCs   */
2318       /* of the common group are disabled.                                    */
2319       if (__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) == 0UL)
2320       {
2321         tmp_config_internal_channel = LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
2322 
2323         /* If the requested internal measurement path has already been enabled, */
2324         /* bypass the configuration processing.                                 */
2325         if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR) && ((tmp_config_internal_channel & LL_ADC_PATH_INTERNAL_TEMPSENSOR) == 0UL))
2326         {
2327           if (ADC_TEMPERATURE_SENSOR_INSTANCE(hadc))
2328           {
2329             LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_TEMPSENSOR | tmp_config_internal_channel);
2330 
2331             /* Delay for temperature sensor stabilization time */
2332             /* Wait loop initialization and execution */
2333             /* Note: Variable divided by 2 to compensate partially              */
2334             /*       CPU processing cycles, scaling in us split to not          */
2335             /*       exceed 32 bits register capacity and handle low frequency. */
2336             wait_loop_index = ((LL_ADC_DELAY_TEMPSENSOR_STAB_US / 10UL) * ((SystemCoreClock / (100000UL * 2UL)) + 1UL));
2337             while (wait_loop_index != 0UL)
2338             {
2339               wait_loop_index--;
2340             }
2341           }
2342         }
2343         else if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_VBAT) && ((tmp_config_internal_channel & LL_ADC_PATH_INTERNAL_VBAT) == 0UL))
2344         {
2345           if (ADC_BATTERY_VOLTAGE_INSTANCE(hadc))
2346           {
2347             LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_VBAT | tmp_config_internal_channel);
2348           }
2349         }
2350         else if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT) && ((tmp_config_internal_channel & LL_ADC_PATH_INTERNAL_VREFINT) == 0UL))
2351         {
2352           if (ADC_VREFINT_INSTANCE(hadc))
2353           {
2354             LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance), LL_ADC_PATH_INTERNAL_VREFINT | tmp_config_internal_channel);
2355           }
2356         }
2357         else
2358         {
2359           /* nothing to do */
2360         }
2361       }
2362       /* If the requested internal measurement path has already been enabled  */
2363       /* and other ADC of the common group are enabled, internal              */
2364       /* measurement paths cannot be enabled.                                 */
2365       else
2366       {
2367         /* Update ADC state machine to error */
2368         SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
2369 
2370         tmp_hal_status = HAL_ERROR;
2371       }
2372     }
2373 
2374   }
2375 
2376   /* Process unlocked */
2377   __HAL_UNLOCK(hadc);
2378 
2379   /* Return function status */
2380   return tmp_hal_status;
2381 }
2382 
2383 /**
2384   * @brief  Enable ADC multimode and configure multimode parameters
2385   * @note   Possibility to update parameters on the fly:
2386   *         This function initializes multimode parameters, following
2387   *         calls to this function can be used to reconfigure some parameters
2388   *         of structure "ADC_MultiModeTypeDef" on the fly, without resetting
2389   *         the ADCs.
2390   *         The setting of these parameters is conditioned to ADC state.
2391   *         For parameters constraints, see comments of structure
2392   *         "ADC_MultiModeTypeDef".
2393   * @note   To move back configuration from multimode to single mode, ADC must
2394   *         be reset (using function HAL_ADC_Init() ).
2395   * @param hadc Master ADC handle
2396   * @param multimode Structure of ADC multimode configuration
2397   * @retval HAL status
2398   */
2399 HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef *hadc, ADC_MultiModeTypeDef *multimode)
2400 {
2401   HAL_StatusTypeDef tmp_hal_status = HAL_OK;
2402   ADC_Common_TypeDef *tmpADC_Common;
2403   ADC_HandleTypeDef  tmphadcSlave;
2404   uint32_t tmphadcSlave_conversion_on_going;
2405 
2406   /* Check the parameters */
2407   assert_param(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance));
2408   assert_param(IS_ADC_MULTIMODE(multimode->Mode));
2409   if (multimode->Mode != ADC_MODE_INDEPENDENT)
2410   {
2411     assert_param(IS_ADC_DUAL_DATA_MODE(multimode->DualModeData));
2412     assert_param(IS_ADC_SAMPLING_DELAY(multimode->TwoSamplingDelay));
2413   }
2414 
2415   /* Process locked */
2416   __HAL_LOCK(hadc);
2417 
2418   tmphadcSlave.State = HAL_ADC_STATE_RESET;
2419   tmphadcSlave.ErrorCode = HAL_ADC_ERROR_NONE;
2420 
2421   ADC_MULTI_SLAVE(hadc, &tmphadcSlave);
2422 
2423   if (tmphadcSlave.Instance == NULL)
2424   {
2425     /* Update ADC state machine to error */
2426     SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
2427 
2428     /* Process unlocked */
2429     __HAL_UNLOCK(hadc);
2430 
2431     return HAL_ERROR;
2432   }
2433 
2434   /* Parameters update conditioned to ADC state:                              */
2435   /* Parameters that can be updated when ADC is disabled or enabled without   */
2436   /* conversion on going on regular group:                                    */
2437   /*  - Multimode DATA Format configuration                                   */
2438   tmphadcSlave_conversion_on_going = LL_ADC_REG_IsConversionOngoing((&tmphadcSlave)->Instance);
2439   if ((LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL)
2440       && (tmphadcSlave_conversion_on_going == 0UL))
2441   {
2442     /* Pointer to the common control register */
2443     tmpADC_Common = __LL_ADC_COMMON_INSTANCE(hadc->Instance);
2444 
2445     /* If multimode is selected, configure all multimode parameters.          */
2446     /* Otherwise, reset multimode parameters (can be used in case of          */
2447     /* transition from multimode to independent mode).                        */
2448     if (multimode->Mode != ADC_MODE_INDEPENDENT)
2449     {
2450       MODIFY_REG(tmpADC_Common->CCR, ADC_CCR_DAMDF, multimode->DualModeData);
2451 
2452       /* Parameters that can be updated only when ADC is disabled:              */
2453       /*  - Multimode mode selection                                            */
2454       /*  - Multimode delay                                                     */
2455       /*    Note: Delay range depends on selected resolution:                   */
2456       /*      from 1 to 9 clock cycles for 16 bits                              */
2457       /*      from 1 to 9 clock cycles for 14 bits,                             */
2458       /*      from 1 to 8 clock cycles for 12 bits                              */
2459       /*      from 1 to 6 clock cycles for 10 and 8 bits                        */
2460       /*    If a higher delay is selected, it will be clipped to maximum delay  */
2461       /*    range                                                               */
2462 
2463       if (__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) == 0UL)
2464       {
2465         MODIFY_REG(tmpADC_Common->CCR,
2466                    ADC_CCR_DUAL |
2467                    ADC_CCR_DELAY,
2468                    multimode->Mode |
2469                    multimode->TwoSamplingDelay
2470                   );
2471       }
2472     }
2473     else /* ADC_MODE_INDEPENDENT */
2474     {
2475       CLEAR_BIT(tmpADC_Common->CCR, ADC_CCR_DAMDF);
2476 
2477       /* Parameters that can be updated only when ADC is disabled:                */
2478       /*  - Multimode mode selection                                              */
2479       /*  - Multimode delay                                                       */
2480       if (__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__LL_ADC_COMMON_INSTANCE(hadc->Instance)) == 0UL)
2481       {
2482         CLEAR_BIT(tmpADC_Common->CCR, ADC_CCR_DUAL | ADC_CCR_DELAY);
2483       }
2484     }
2485   }
2486   /* If one of the ADC sharing the same common group is enabled, no update    */
2487   /* could be done on neither of the multimode structure parameters.          */
2488   else
2489   {
2490     /* Update ADC state machine to error */
2491     SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
2492 
2493     tmp_hal_status = HAL_ERROR;
2494   }
2495 
2496   /* Process unlocked */
2497   __HAL_UNLOCK(hadc);
2498 
2499   /* Return function status */
2500   return tmp_hal_status;
2501 }
2502 
2503 /**
2504   * @brief  Enable Injected Queue
2505   * @note   This function resets CFGR register JQDIS bit in order to enable the
2506   *         Injected Queue. JQDIS can be written only when ADSTART and JDSTART
2507   *         are both equal to 0 to ensure that no regular nor injected
2508   *         conversion is ongoing.
2509   * @param hadc ADC handle
2510   * @retval HAL status
2511   */
2512 HAL_StatusTypeDef HAL_ADCEx_EnableInjectedQueue(ADC_HandleTypeDef *hadc)
2513 {
2514   HAL_StatusTypeDef tmp_hal_status;
2515   uint32_t tmp_adc_is_conversion_on_going_regular;
2516   uint32_t tmp_adc_is_conversion_on_going_injected;
2517 
2518   /* Check the parameters */
2519   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
2520 
2521   tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
2522   tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance);
2523 
2524   /* Parameter can be set only if no conversion is on-going */
2525   if ((tmp_adc_is_conversion_on_going_regular == 0UL)
2526       && (tmp_adc_is_conversion_on_going_injected == 0UL)
2527      )
2528   {
2529     CLEAR_BIT(hadc->Instance->CFGR, ADC_CFGR_JQDIS);
2530 
2531     /* Update state, clear previous result related to injected queue overflow */
2532     CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_JQOVF);
2533 
2534     tmp_hal_status = HAL_OK;
2535   }
2536   else
2537   {
2538     tmp_hal_status = HAL_ERROR;
2539   }
2540 
2541   return tmp_hal_status;
2542 }
2543 
2544 /**
2545   * @brief  Disable Injected Queue
2546   * @note   This function sets CFGR register JQDIS bit in order to disable the
2547   *         Injected Queue. JQDIS can be written only when ADSTART and JDSTART
2548   *         are both equal to 0 to ensure that no regular nor injected
2549   *         conversion is ongoing.
2550   * @param hadc ADC handle
2551   * @retval HAL status
2552   */
2553 HAL_StatusTypeDef HAL_ADCEx_DisableInjectedQueue(ADC_HandleTypeDef *hadc)
2554 {
2555   HAL_StatusTypeDef tmp_hal_status;
2556   uint32_t tmp_adc_is_conversion_on_going_regular;
2557   uint32_t tmp_adc_is_conversion_on_going_injected;
2558 
2559   /* Check the parameters */
2560   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
2561 
2562   tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
2563   tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance);
2564 
2565   /* Parameter can be set only if no conversion is on-going */
2566   if ((tmp_adc_is_conversion_on_going_regular == 0UL)
2567       && (tmp_adc_is_conversion_on_going_injected == 0UL)
2568      )
2569   {
2570     LL_ADC_INJ_SetQueueMode(hadc->Instance, LL_ADC_INJ_QUEUE_DISABLE);
2571     tmp_hal_status = HAL_OK;
2572   }
2573   else
2574   {
2575     tmp_hal_status = HAL_ERROR;
2576   }
2577 
2578   return tmp_hal_status;
2579 }
2580 
2581 /**
2582   * @brief  Disable ADC voltage regulator.
2583   * @note   Disabling voltage regulator allows to save power. This operation can
2584   *         be carried out only when ADC is disabled.
2585   * @note   To enable again the voltage regulator, the user is expected to
2586   *         resort to HAL_ADC_Init() API.
2587   * @param hadc ADC handle
2588   * @retval HAL status
2589   */
2590 HAL_StatusTypeDef HAL_ADCEx_DisableVoltageRegulator(ADC_HandleTypeDef *hadc)
2591 {
2592   HAL_StatusTypeDef tmp_hal_status;
2593 
2594   /* Check the parameters */
2595   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
2596 
2597   /* Setting of this feature is conditioned to ADC state: ADC must be ADC disabled */
2598   if (LL_ADC_IsEnabled(hadc->Instance) == 0UL)
2599   {
2600     LL_ADC_DisableInternalRegulator(hadc->Instance);
2601     tmp_hal_status = HAL_OK;
2602   }
2603   else
2604   {
2605     tmp_hal_status = HAL_ERROR;
2606   }
2607 
2608   return tmp_hal_status;
2609 }
2610 
2611 /**
2612   * @brief  Enter ADC deep-power-down mode
2613   * @note   This mode is achieved in setting DEEPPWD bit and allows to save power
2614   *         in reducing leakage currents. It is particularly interesting before
2615   *         entering stop modes.
2616   * @note   Setting DEEPPWD automatically clears ADVREGEN bit and disables the
2617   *         ADC voltage regulator. This means that this API encompasses
2618   *         HAL_ADCEx_DisableVoltageRegulator(). Additionally, the internal
2619   *         calibration is lost.
2620   * @note   To exit the ADC deep-power-down mode, the user is expected to
2621   *         resort to HAL_ADC_Init() API as well as to relaunch a calibration
2622   *         with HAL_ADCEx_Calibration_Start() API or to re-apply a previously
2623   *         saved calibration factor.
2624   * @param hadc ADC handle
2625   * @retval HAL status
2626   */
2627 HAL_StatusTypeDef HAL_ADCEx_EnterADCDeepPowerDownMode(ADC_HandleTypeDef *hadc)
2628 {
2629   HAL_StatusTypeDef tmp_hal_status;
2630 
2631   /* Check the parameters */
2632   assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
2633 
2634   /* Setting of this feature is conditioned to ADC state: ADC must be ADC disabled */
2635   if (LL_ADC_IsEnabled(hadc->Instance) == 0UL)
2636   {
2637     LL_ADC_EnableDeepPowerDown(hadc->Instance);
2638     tmp_hal_status = HAL_OK;
2639   }
2640   else
2641   {
2642     tmp_hal_status = HAL_ERROR;
2643   }
2644 
2645   return tmp_hal_status;
2646 }
2647 
2648 /**
2649   * @}
2650   */
2651 
2652 /**
2653   * @}
2654   */
2655 
2656 #endif /* HAL_ADC_MODULE_ENABLED */
2657 /**
2658   * @}
2659   */
2660 
2661 /**
2662   * @}
2663   */
2664