|     HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef *hadc, uint32_t CalibrationMode, uint32_t SingleDiff)
    {
      HAL_StatusTypeDef tmp_hal_status;
      __IO uint32_t wait_loop_index = 0UL;
      UNUSED(SingleDiff); /* STM32U5 calibration is not making difference between Single and Diff ended */
      /* We keep this to be inligne with old products API and for any further use */
      /* Check the parameters */
      assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
      assert_param(IS_ADC_SINGLE_DIFFERENTIAL(SingleDiff));
      __HAL_LOCK(hadc);
      /* Calibration prerequisite: ADC must be disabled. */
      /* Disable the ADC (if not already disabled) */
      tmp_hal_status = ADC_Disable(hadc);
      /* Check if ADC is effectively disabled */
      if (tmp_hal_status == HAL_OK)
      {
        /* Set ADC state */
        ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY, HAL_ADC_STATE_BUSY_INTERNAL);
        /* Start ADC calibration in mode single-ended or differential */
        LL_ADC_StartCalibration(hadc->Instance, CalibrationMode);
        /* Wait for calibration completion */
        while (LL_ADC_IsCalibrationOnGoing(hadc->Instance) != 0UL)
        {
          wait_loop_index++;
          if (wait_loop_index >= ADC_CALIBRATION_TIMEOUT)
          {
            /* Update ADC state machine to error */
            ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_BUSY_INTERNAL, HAL_ADC_STATE_ERROR_INTERNAL);
            __HAL_UNLOCK(hadc);
            return HAL_ERROR;
          }
        }
        /* Set ADC state */
        ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_BUSY_INTERNAL, HAL_ADC_STATE_READY);
      }
      else
      {
        SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
        /* Note: No need to update variable "tmp_hal_status" here: already set    */
        /*       to state "HAL_ERROR" by function disabling the ADC.              */
      }
      __HAL_UNLOCK(hadc);
      return tmp_hal_status;
    }
 |