STM32L4xx_HAL_Driver  1.14.0
Peripheral Control functions

Peripheral Control functions. More...

Functions

HAL_StatusTypeDef HAL_ADC_ConfigChannel (ADC_HandleTypeDef *hadc, ADC_ChannelConfTypeDef *sConfig)
 Configure a channel to be assigned to ADC group regular. More...
 
HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig (ADC_HandleTypeDef *hadc, ADC_AnalogWDGConfTypeDef *AnalogWDGConfig)
 Configure the analog watchdog. More...
 

Detailed Description

Peripheral Control functions.

 ===============================================================================
             ##### Peripheral Control functions #####
 ===============================================================================
    [..]  This section provides functions allowing to:
      (+) Configure channels on regular group
      (+) Configure the analog watchdog

Function Documentation

◆ HAL_ADC_AnalogWDGConfig()

HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig ( ADC_HandleTypeDef hadc,
ADC_AnalogWDGConfTypeDef AnalogWDGConfig 
)

Configure the analog watchdog.

Note
Possibility to update parameters on the fly: This function initializes the selected analog watchdog, successive calls to this function can be used to reconfigure some parameters of structure "ADC_AnalogWDGConfTypeDef" on the fly, without resetting the ADC. The setting of these parameters is conditioned to ADC state. For parameters constraints, see comments of structure "ADC_AnalogWDGConfTypeDef".
On this STM32 serie, analog watchdog thresholds cannot be modified while ADC conversion is on going.
Parameters
hadcADC handle
AnalogWDGConfigStructure of ADC analog watchdog configuration
Return values
HALstatus

Definition at line 2941 of file stm32l4xx_hal_adc.c.

2942 {
2943  HAL_StatusTypeDef tmp_hal_status = HAL_OK;
2944  uint32_t tmpAWDHighThresholdShifted;
2945  uint32_t tmpAWDLowThresholdShifted;
2946  uint32_t tmp_adc_is_conversion_on_going_regular;
2947  uint32_t tmp_adc_is_conversion_on_going_injected;
2948 
2949  /* Check the parameters */
2950  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
2951  assert_param(IS_ADC_ANALOG_WATCHDOG_NUMBER(AnalogWDGConfig->WatchdogNumber));
2952  assert_param(IS_ADC_ANALOG_WATCHDOG_MODE(AnalogWDGConfig->WatchdogMode));
2953  assert_param(IS_FUNCTIONAL_STATE(AnalogWDGConfig->ITMode));
2954 
2955  if ((AnalogWDGConfig->WatchdogMode == ADC_ANALOGWATCHDOG_SINGLE_REG) ||
2956  (AnalogWDGConfig->WatchdogMode == ADC_ANALOGWATCHDOG_SINGLE_INJEC) ||
2957  (AnalogWDGConfig->WatchdogMode == ADC_ANALOGWATCHDOG_SINGLE_REGINJEC))
2958  {
2959  assert_param(IS_ADC_CHANNEL(hadc, AnalogWDGConfig->Channel));
2960  }
2961 
2962  /* Verify thresholds range */
2963  if (hadc->Init.OversamplingMode == ENABLE)
2964  {
2965  /* Case of oversampling enabled: depending on ratio and shift configuration,
2966  analog watchdog thresholds can be higher than ADC resolution.
2967  Verify if thresholds are within maximum thresholds range. */
2968  assert_param(IS_ADC_RANGE(ADC_RESOLUTION_12B, AnalogWDGConfig->HighThreshold));
2969  assert_param(IS_ADC_RANGE(ADC_RESOLUTION_12B, AnalogWDGConfig->LowThreshold));
2970  }
2971  else
2972  {
2973  /* Verify if thresholds are within the selected ADC resolution */
2974  assert_param(IS_ADC_RANGE(ADC_GET_RESOLUTION(hadc), AnalogWDGConfig->HighThreshold));
2975  assert_param(IS_ADC_RANGE(ADC_GET_RESOLUTION(hadc), AnalogWDGConfig->LowThreshold));
2976  }
2977 
2978  /* Process locked */
2979  __HAL_LOCK(hadc);
2980 
2981  /* Parameters update conditioned to ADC state: */
2982  /* Parameters that can be updated when ADC is disabled or enabled without */
2983  /* conversion on going on ADC groups regular and injected: */
2984  /* - Analog watchdog channels */
2985  /* - Analog watchdog thresholds */
2986  tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
2987  tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance);
2988  if ((tmp_adc_is_conversion_on_going_regular == 0UL)
2989  && (tmp_adc_is_conversion_on_going_injected == 0UL)
2990  )
2991  {
2992  /* Analog watchdog configuration */
2993  if (AnalogWDGConfig->WatchdogNumber == ADC_ANALOGWATCHDOG_1)
2994  {
2995  /* Configuration of analog watchdog: */
2996  /* - Set the analog watchdog enable mode: one or overall group of */
2997  /* channels, on groups regular and-or injected. */
2998  switch (AnalogWDGConfig->WatchdogMode)
2999  {
3000  case ADC_ANALOGWATCHDOG_SINGLE_REG:
3001  LL_ADC_SetAnalogWDMonitChannels(hadc->Instance, LL_ADC_AWD1, __LL_ADC_ANALOGWD_CHANNEL_GROUP(AnalogWDGConfig->Channel,
3002  LL_ADC_GROUP_REGULAR));
3003  break;
3004 
3005  case ADC_ANALOGWATCHDOG_SINGLE_INJEC:
3006  LL_ADC_SetAnalogWDMonitChannels(hadc->Instance, LL_ADC_AWD1, __LL_ADC_ANALOGWD_CHANNEL_GROUP(AnalogWDGConfig->Channel,
3007  LL_ADC_GROUP_INJECTED));
3008  break;
3009 
3010  case ADC_ANALOGWATCHDOG_SINGLE_REGINJEC:
3011  LL_ADC_SetAnalogWDMonitChannels(hadc->Instance, LL_ADC_AWD1, __LL_ADC_ANALOGWD_CHANNEL_GROUP(AnalogWDGConfig->Channel,
3012  LL_ADC_GROUP_REGULAR_INJECTED));
3013  break;
3014 
3015  case ADC_ANALOGWATCHDOG_ALL_REG:
3016  LL_ADC_SetAnalogWDMonitChannels(hadc->Instance, LL_ADC_AWD1, LL_ADC_AWD_ALL_CHANNELS_REG);
3017  break;
3018 
3019  case ADC_ANALOGWATCHDOG_ALL_INJEC:
3020  LL_ADC_SetAnalogWDMonitChannels(hadc->Instance, LL_ADC_AWD1, LL_ADC_AWD_ALL_CHANNELS_INJ);
3021  break;
3022 
3023  case ADC_ANALOGWATCHDOG_ALL_REGINJEC:
3024  LL_ADC_SetAnalogWDMonitChannels(hadc->Instance, LL_ADC_AWD1, LL_ADC_AWD_ALL_CHANNELS_REG_INJ);
3025  break;
3026 
3027  default: /* ADC_ANALOGWATCHDOG_NONE */
3028  LL_ADC_SetAnalogWDMonitChannels(hadc->Instance, LL_ADC_AWD1, LL_ADC_AWD_DISABLE);
3029  break;
3030  }
3031 
3032  /* Shift the offset in function of the selected ADC resolution: */
3033  /* Thresholds have to be left-aligned on bit 11, the LSB (right bits) */
3034  /* are set to 0 */
3035  tmpAWDHighThresholdShifted = ADC_AWD1THRESHOLD_SHIFT_RESOLUTION(hadc, AnalogWDGConfig->HighThreshold);
3036  tmpAWDLowThresholdShifted = ADC_AWD1THRESHOLD_SHIFT_RESOLUTION(hadc, AnalogWDGConfig->LowThreshold);
3037 
3038  /* Set ADC analog watchdog thresholds value of both thresholds high and low */
3039  LL_ADC_ConfigAnalogWDThresholds(hadc->Instance, AnalogWDGConfig->WatchdogNumber, tmpAWDHighThresholdShifted, tmpAWDLowThresholdShifted);
3040 
3041  /* Update state, clear previous result related to AWD1 */
3042  CLEAR_BIT(hadc->State, HAL_ADC_STATE_AWD1);
3043 
3044  /* Clear flag ADC analog watchdog */
3045  /* Note: Flag cleared Clear the ADC Analog watchdog flag to be ready */
3046  /* to use for HAL_ADC_IRQHandler() or HAL_ADC_PollForEvent() */
3047  /* (in case left enabled by previous ADC operations). */
3048  LL_ADC_ClearFlag_AWD1(hadc->Instance);
3049 
3050  /* Configure ADC analog watchdog interrupt */
3051  if (AnalogWDGConfig->ITMode == ENABLE)
3052  {
3053  LL_ADC_EnableIT_AWD1(hadc->Instance);
3054  }
3055  else
3056  {
3057  LL_ADC_DisableIT_AWD1(hadc->Instance);
3058  }
3059  }
3060  /* Case of ADC_ANALOGWATCHDOG_2 or ADC_ANALOGWATCHDOG_3 */
3061  else
3062  {
3063  switch (AnalogWDGConfig->WatchdogMode)
3064  {
3065  case ADC_ANALOGWATCHDOG_SINGLE_REG:
3066  case ADC_ANALOGWATCHDOG_SINGLE_INJEC:
3067  case ADC_ANALOGWATCHDOG_SINGLE_REGINJEC:
3068  /* Update AWD by bitfield to keep the possibility to monitor */
3069  /* several channels by successive calls of this function. */
3070  if (AnalogWDGConfig->WatchdogNumber == ADC_ANALOGWATCHDOG_2)
3071  {
3072  SET_BIT(hadc->Instance->AWD2CR, (1UL << (__LL_ADC_CHANNEL_TO_DECIMAL_NB(AnalogWDGConfig->Channel) & 0x1FUL)));
3073  }
3074  else
3075  {
3076  SET_BIT(hadc->Instance->AWD3CR, (1UL << (__LL_ADC_CHANNEL_TO_DECIMAL_NB(AnalogWDGConfig->Channel) & 0x1FUL)));
3077  }
3078  break;
3079 
3080  case ADC_ANALOGWATCHDOG_ALL_REG:
3081  case ADC_ANALOGWATCHDOG_ALL_INJEC:
3082  case ADC_ANALOGWATCHDOG_ALL_REGINJEC:
3083  LL_ADC_SetAnalogWDMonitChannels(hadc->Instance, AnalogWDGConfig->WatchdogNumber, LL_ADC_AWD_ALL_CHANNELS_REG_INJ);
3084  break;
3085 
3086  default: /* ADC_ANALOGWATCHDOG_NONE */
3087  LL_ADC_SetAnalogWDMonitChannels(hadc->Instance, AnalogWDGConfig->WatchdogNumber, LL_ADC_AWD_DISABLE);
3088  break;
3089  }
3090 
3091  /* Shift the thresholds in function of the selected ADC resolution */
3092  /* have to be left-aligned on bit 7, the LSB (right bits) are set to 0 */
3093  tmpAWDHighThresholdShifted = ADC_AWD23THRESHOLD_SHIFT_RESOLUTION(hadc, AnalogWDGConfig->HighThreshold);
3094  tmpAWDLowThresholdShifted = ADC_AWD23THRESHOLD_SHIFT_RESOLUTION(hadc, AnalogWDGConfig->LowThreshold);
3095 
3096  /* Set ADC analog watchdog thresholds value of both thresholds high and low */
3097  LL_ADC_ConfigAnalogWDThresholds(hadc->Instance, AnalogWDGConfig->WatchdogNumber, tmpAWDHighThresholdShifted, tmpAWDLowThresholdShifted);
3098 
3099  if (AnalogWDGConfig->WatchdogNumber == ADC_ANALOGWATCHDOG_2)
3100  {
3101  /* Update state, clear previous result related to AWD2 */
3102  CLEAR_BIT(hadc->State, HAL_ADC_STATE_AWD2);
3103 
3104  /* Clear flag ADC analog watchdog */
3105  /* Note: Flag cleared Clear the ADC Analog watchdog flag to be ready */
3106  /* to use for HAL_ADC_IRQHandler() or HAL_ADC_PollForEvent() */
3107  /* (in case left enabled by previous ADC operations). */
3108  LL_ADC_ClearFlag_AWD2(hadc->Instance);
3109 
3110  /* Configure ADC analog watchdog interrupt */
3111  if (AnalogWDGConfig->ITMode == ENABLE)
3112  {
3113  LL_ADC_EnableIT_AWD2(hadc->Instance);
3114  }
3115  else
3116  {
3117  LL_ADC_DisableIT_AWD2(hadc->Instance);
3118  }
3119  }
3120  /* (AnalogWDGConfig->WatchdogNumber == ADC_ANALOGWATCHDOG_3) */
3121  else
3122  {
3123  /* Update state, clear previous result related to AWD3 */
3124  CLEAR_BIT(hadc->State, HAL_ADC_STATE_AWD3);
3125 
3126  /* Clear flag ADC analog watchdog */
3127  /* Note: Flag cleared Clear the ADC Analog watchdog flag to be ready */
3128  /* to use for HAL_ADC_IRQHandler() or HAL_ADC_PollForEvent() */
3129  /* (in case left enabled by previous ADC operations). */
3130  LL_ADC_ClearFlag_AWD3(hadc->Instance);
3131 
3132  /* Configure ADC analog watchdog interrupt */
3133  if (AnalogWDGConfig->ITMode == ENABLE)
3134  {
3135  LL_ADC_EnableIT_AWD3(hadc->Instance);
3136  }
3137  else
3138  {
3139  LL_ADC_DisableIT_AWD3(hadc->Instance);
3140  }
3141  }
3142  }
3143 
3144  }
3145  /* If a conversion is on going on ADC group regular or injected, no update */
3146  /* could be done on neither of the AWD configuration structure parameters. */
3147  else
3148  {
3149  /* Update ADC state machine to error */
3150  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
3151 
3152  tmp_hal_status = HAL_ERROR;
3153  }
3154  /* Process unlocked */
3155  __HAL_UNLOCK(hadc);
3156 
3157  /* Return function status */
3158  return tmp_hal_status;
3159 }
__STATIC_INLINE void LL_ADC_EnableIT_AWD1(ADC_TypeDef *ADCx)
Enable interruption ADC analog watchdog 1. IER AWD1IE LL_ADC_EnableIT_AWD1.
__STATIC_INLINE void LL_ADC_ClearFlag_AWD1(ADC_TypeDef *ADCx)
Clear flag ADC analog watchdog 1. ISR AWD1 LL_ADC_ClearFlag_AWD1.
__STATIC_INLINE void LL_ADC_ClearFlag_AWD3(ADC_TypeDef *ADCx)
Clear flag ADC analog watchdog 3. ISR AWD3 LL_ADC_ClearFlag_AWD3.
__HAL_UNLOCK(hrtc)
__STATIC_INLINE void LL_ADC_DisableIT_AWD2(ADC_TypeDef *ADCx)
Disable interruption ADC analog watchdog 2. IER AWD2IE LL_ADC_DisableIT_AWD2.
__STATIC_INLINE void LL_ADC_EnableIT_AWD3(ADC_TypeDef *ADCx)
Enable interruption ADC analog watchdog 3. IER AWD3IE LL_ADC_EnableIT_AWD3.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
return HAL_OK
__STATIC_INLINE void LL_ADC_DisableIT_AWD3(ADC_TypeDef *ADCx)
Disable interruption ADC analog watchdog 3. IER AWD3IE LL_ADC_DisableIT_AWD3.
__STATIC_INLINE uint32_t LL_ADC_INJ_IsConversionOngoing(ADC_TypeDef *ADCx)
Get ADC group injected conversion state. CR JADSTART LL_ADC_INJ_IsConversionOngoing.
__STATIC_INLINE void LL_ADC_ClearFlag_AWD2(ADC_TypeDef *ADCx)
Clear flag ADC analog watchdog 2. ISR AWD2 LL_ADC_ClearFlag_AWD2.
__STATIC_INLINE void LL_ADC_DisableIT_AWD1(ADC_TypeDef *ADCx)
Disable interruption ADC analog watchdog 1. IER AWD1IE LL_ADC_DisableIT_AWD1.
__STATIC_INLINE void LL_ADC_ConfigAnalogWDThresholds(ADC_TypeDef *ADCx, uint32_t AWDy, uint32_t AWDThresholdHighValue, uint32_t AWDThresholdLowValue)
Set ADC analog watchdog thresholds value of both thresholds high and low.
__STATIC_INLINE uint32_t LL_ADC_REG_IsConversionOngoing(ADC_TypeDef *ADCx)
Get ADC group regular conversion state. CR ADSTART LL_ADC_REG_IsConversionOngoing.
__STATIC_INLINE void LL_ADC_SetAnalogWDMonitChannels(ADC_TypeDef *ADCx, uint32_t AWDy, uint32_t AWDChannelGroup)
Set ADC analog watchdog monitored channels: a single channel, multiple channels or all channels...
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
__STATIC_INLINE void LL_ADC_EnableIT_AWD2(ADC_TypeDef *ADCx)
Enable interruption ADC analog watchdog 2. IER AWD2IE LL_ADC_EnableIT_AWD2.

◆ HAL_ADC_ConfigChannel()

HAL_StatusTypeDef HAL_ADC_ConfigChannel ( ADC_HandleTypeDef hadc,
ADC_ChannelConfTypeDef sConfig 
)

Configure a channel to be assigned to ADC group regular.

Note
In case of usage of internal measurement channels: Vbat/VrefInt/TempSensor. These internal paths can be disabled using function HAL_ADC_DeInit().
Possibility to update parameters on the fly: This function initializes channel into ADC group regular, following calls to this function can be used to reconfigure some parameters of structure "ADC_ChannelConfTypeDef" on the fly, without resetting the ADC. The setting of these parameters is conditioned to ADC state: Refer to comments of structure "ADC_ChannelConfTypeDef".
Parameters
hadcADC handle
sConfigStructure of ADC channel assigned to ADC group regular.
Return values
HALstatus

Definition at line 2699 of file stm32l4xx_hal_adc.c.

2700 {
2701  HAL_StatusTypeDef tmp_hal_status = HAL_OK;
2702  uint32_t tmpOffsetShifted;
2703  uint32_t tmp_config_internal_channel;
2704  __IO uint32_t wait_loop_index = 0;
2705  uint32_t tmp_adc_is_conversion_on_going_regular;
2706  uint32_t tmp_adc_is_conversion_on_going_injected;
2707 
2708  /* Check the parameters */
2709  assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
2710  assert_param(IS_ADC_REGULAR_RANK(sConfig->Rank));
2711  assert_param(IS_ADC_SAMPLE_TIME(sConfig->SamplingTime));
2712  assert_param(IS_ADC_SINGLE_DIFFERENTIAL(sConfig->SingleDiff));
2713  assert_param(IS_ADC_OFFSET_NUMBER(sConfig->OffsetNumber));
2714  assert_param(IS_ADC_RANGE(ADC_GET_RESOLUTION(hadc), sConfig->Offset));
2715 
2716  /* if ROVSE is set, the value of the OFFSETy_EN bit in ADCx_OFRy register is
2717  ignored (considered as reset) */
2718  assert_param(!((sConfig->OffsetNumber != ADC_OFFSET_NONE) && (hadc->Init.OversamplingMode == ENABLE)));
2719 
2720  /* Verification of channel number */
2721  if (sConfig->SingleDiff != ADC_DIFFERENTIAL_ENDED)
2722  {
2723  assert_param(IS_ADC_CHANNEL(hadc, sConfig->Channel));
2724  }
2725  else
2726  {
2727  assert_param(IS_ADC_DIFF_CHANNEL(hadc, sConfig->Channel));
2728  }
2729 
2730  /* Process locked */
2731  __HAL_LOCK(hadc);
2732 
2733  /* Parameters update conditioned to ADC state: */
2734  /* Parameters that can be updated when ADC is disabled or enabled without */
2735  /* conversion on going on regular group: */
2736  /* - Channel number */
2737  /* - Channel rank */
2738  if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL)
2739  {
2740  #if !defined (USE_FULL_ASSERT)
2741  /* Correspondence for compatibility with legacy definition of */
2742  /* sequencer ranks in direct number format. This correspondence can */
2743  /* be done only on ranks 1 to 5 due to literal values. */
2744  /* Note: Sequencer ranks in direct number format are no more used */
2745  /* and are detected by activating USE_FULL_ASSERT feature. */
2746  if (sConfig->Rank <= 5U)
2747  {
2748  switch (sConfig->Rank)
2749  {
2750  case 2U: sConfig->Rank = ADC_REGULAR_RANK_2; break;
2751  case 3U: sConfig->Rank = ADC_REGULAR_RANK_3; break;
2752  case 4U: sConfig->Rank = ADC_REGULAR_RANK_4; break;
2753  case 5U: sConfig->Rank = ADC_REGULAR_RANK_5; break;
2754  /* case 1U */
2755  default: sConfig->Rank = ADC_REGULAR_RANK_1; break;
2756  }
2757  }
2758  #endif
2759 
2760  /* Set ADC group regular sequence: channel on the selected scan sequence rank */
2761  LL_ADC_REG_SetSequencerRanks(hadc->Instance, sConfig->Rank, sConfig->Channel);
2762 
2763  /* Parameters update conditioned to ADC state: */
2764  /* Parameters that can be updated when ADC is disabled or enabled without */
2765  /* conversion on going on regular group: */
2766  /* - Channel sampling time */
2767  /* - Channel offset */
2768  tmp_adc_is_conversion_on_going_regular = LL_ADC_REG_IsConversionOngoing(hadc->Instance);
2769  tmp_adc_is_conversion_on_going_injected = LL_ADC_INJ_IsConversionOngoing(hadc->Instance);
2770  if ((tmp_adc_is_conversion_on_going_regular == 0UL)
2771  && (tmp_adc_is_conversion_on_going_injected == 0UL)
2772  )
2773  {
2774 #if defined(ADC_SMPR1_SMPPLUS)
2775  /* Manage specific case of sampling time 3.5 cycles replacing 2.5 cyles */
2776  if (sConfig->SamplingTime == ADC_SAMPLETIME_3CYCLES_5)
2777  {
2778  /* Set sampling time of the selected ADC channel */
2779  LL_ADC_SetChannelSamplingTime(hadc->Instance, sConfig->Channel, LL_ADC_SAMPLINGTIME_2CYCLES_5);
2780 
2781  /* Set ADC sampling time common configuration */
2782  LL_ADC_SetSamplingTimeCommonConfig(hadc->Instance, LL_ADC_SAMPLINGTIME_COMMON_3C5_REPL_2C5);
2783  }
2784  else
2785  {
2786  /* Set sampling time of the selected ADC channel */
2787  LL_ADC_SetChannelSamplingTime(hadc->Instance, sConfig->Channel, sConfig->SamplingTime);
2788 
2789  /* Set ADC sampling time common configuration */
2790  LL_ADC_SetSamplingTimeCommonConfig(hadc->Instance, LL_ADC_SAMPLINGTIME_COMMON_DEFAULT);
2791  }
2792 #else
2793  /* Set sampling time of the selected ADC channel */
2794  LL_ADC_SetChannelSamplingTime(hadc->Instance, sConfig->Channel, sConfig->SamplingTime);
2795 #endif
2796 
2797  /* Configure the offset: offset enable/disable, channel, offset value */
2798 
2799  /* Shift the offset with respect to the selected ADC resolution. */
2800  /* Offset has to be left-aligned on bit 11, the LSB (right bits) are set to 0 */
2801  tmpOffsetShifted = ADC_OFFSET_SHIFT_RESOLUTION(hadc, (uint32_t)sConfig->Offset);
2802 
2803  if (sConfig->OffsetNumber != ADC_OFFSET_NONE)
2804  {
2805  /* Set ADC selected offset number */
2806  LL_ADC_SetOffset(hadc->Instance, sConfig->OffsetNumber, sConfig->Channel, tmpOffsetShifted);
2807 
2808  }
2809  else
2810  {
2811  /* Scan each offset register to check if the selected channel is targeted. */
2812  /* If this is the case, the corresponding offset number is disabled. */
2813  if(__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_1)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfig->Channel))
2814  {
2815  LL_ADC_SetOffsetState(hadc->Instance, LL_ADC_OFFSET_1, LL_ADC_OFFSET_DISABLE);
2816  }
2817  if(__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_2)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfig->Channel))
2818  {
2819  LL_ADC_SetOffsetState(hadc->Instance, LL_ADC_OFFSET_2, LL_ADC_OFFSET_DISABLE);
2820  }
2821  if(__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_3)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfig->Channel))
2822  {
2823  LL_ADC_SetOffsetState(hadc->Instance, LL_ADC_OFFSET_3, LL_ADC_OFFSET_DISABLE);
2824  }
2825  if(__LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_GetOffsetChannel(hadc->Instance, LL_ADC_OFFSET_4)) == __LL_ADC_CHANNEL_TO_DECIMAL_NB(sConfig->Channel))
2826  {
2827  LL_ADC_SetOffsetState(hadc->Instance, LL_ADC_OFFSET_4, LL_ADC_OFFSET_DISABLE);
2828  }
2829  }
2830  }
2831 
2832  /* Parameters update conditioned to ADC state: */
2833  /* Parameters that can be updated only when ADC is disabled: */
2834  /* - Single or differential mode */
2835  if (LL_ADC_IsEnabled(hadc->Instance) == 0UL)
2836  {
2837  /* Set mode single-ended or differential input of the selected ADC channel */
2838  LL_ADC_SetChannelSingleDiff(hadc->Instance, sConfig->Channel, sConfig->SingleDiff);
2839 
2840  /* Configuration of differential mode */
2841  if (sConfig->SingleDiff == ADC_DIFFERENTIAL_ENDED)
2842  {
2843  /* Set sampling time of the selected ADC channel */
2844  /* Note: ADC channel number masked with value "0x1F" to ensure shift value within 32 bits range */
2845  LL_ADC_SetChannelSamplingTime(hadc->Instance,
2846  (uint32_t)(__LL_ADC_DECIMAL_NB_TO_CHANNEL((__LL_ADC_CHANNEL_TO_DECIMAL_NB((uint32_t)sConfig->Channel) + 1UL) & 0x1FUL)),
2847  sConfig->SamplingTime);
2848  }
2849 
2850  }
2851 
2852  /* Management of internal measurement channels: Vbat/VrefInt/TempSensor. */
2853  /* If internal channel selected, enable dedicated internal buffers and */
2854  /* paths. */
2855  /* Note: these internal measurement paths can be disabled using */
2856  /* HAL_ADC_DeInit(). */
2857 
2858  if (__LL_ADC_IS_CHANNEL_INTERNAL(sConfig->Channel))
2859  {
2860  tmp_config_internal_channel = LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance));
2861 
2862  /* If the requested internal measurement path has already been enabled, */
2863  /* bypass the configuration processing. */
2864  if ((sConfig->Channel == ADC_CHANNEL_TEMPSENSOR) && ((tmp_config_internal_channel & LL_ADC_PATH_INTERNAL_TEMPSENSOR) == 0UL))
2865  {
2866  if (ADC_TEMPERATURE_SENSOR_INSTANCE(hadc))
2867  {
2868  LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance),
2869  LL_ADC_PATH_INTERNAL_TEMPSENSOR | tmp_config_internal_channel);
2870 
2871  /* Delay for temperature sensor stabilization time */
2872  /* Wait loop initialization and execution */
2873  /* Note: Variable divided by 2 to compensate partially */
2874  /* CPU processing cycles, scaling in us split to not */
2875  /* exceed 32 bits register capacity and handle low frequency. */
2876  wait_loop_index = ((LL_ADC_DELAY_TEMPSENSOR_STAB_US / 10UL) * (SystemCoreClock / (100000UL * 2UL)));
2877  while (wait_loop_index != 0UL)
2878  {
2879  wait_loop_index--;
2880  }
2881  }
2882  }
2883  else if ((sConfig->Channel == ADC_CHANNEL_VBAT) && ((tmp_config_internal_channel & LL_ADC_PATH_INTERNAL_VBAT) == 0UL))
2884  {
2885  if (ADC_BATTERY_VOLTAGE_INSTANCE(hadc))
2886  {
2887  LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance),
2888  LL_ADC_PATH_INTERNAL_VBAT | tmp_config_internal_channel);
2889  }
2890  }
2891  else if ((sConfig->Channel == ADC_CHANNEL_VREFINT)
2892  && ((tmp_config_internal_channel & LL_ADC_PATH_INTERNAL_VREFINT) == 0UL))
2893  {
2894  if (ADC_VREFINT_INSTANCE(hadc))
2895  {
2896  LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(hadc->Instance),
2897  LL_ADC_PATH_INTERNAL_VREFINT | tmp_config_internal_channel);
2898  }
2899  }
2900  else
2901  {
2902  /* nothing to do */
2903  }
2904  }
2905  }
2906 
2907  /* If a conversion is on going on regular group, no update on regular */
2908  /* channel could be done on neither of the channel configuration structure */
2909  /* parameters. */
2910  else
2911  {
2912  /* Update ADC state machine to error */
2913  SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
2914 
2915  tmp_hal_status = HAL_ERROR;
2916  }
2917 
2918  /* Process unlocked */
2919  __HAL_UNLOCK(hadc);
2920 
2921  /* Return function status */
2922  return tmp_hal_status;
2923 }
__STATIC_INLINE uint32_t LL_ADC_IsEnabled(ADC_TypeDef *ADCx)
Get the selected ADC instance enable state.
__STATIC_INLINE void LL_ADC_REG_SetSequencerRanks(ADC_TypeDef *ADCx, uint32_t Rank, uint32_t Channel)
Set ADC group regular sequence: channel on the selected scan sequence rank.
__STATIC_INLINE uint32_t LL_ADC_GetOffsetChannel(ADC_TypeDef *ADCx, uint32_t Offsety)
Get for the ADC selected offset number 1, 2, 3 or 4: Channel to which the offset programmed will be a...
__STATIC_INLINE void LL_ADC_SetChannelSingleDiff(ADC_TypeDef *ADCx, uint32_t Channel, uint32_t SingleDiff)
Set mode single-ended or differential input of the selected ADC channel.
__HAL_UNLOCK(hrtc)
__STATIC_INLINE void LL_ADC_SetOffsetState(ADC_TypeDef *ADCx, uint32_t Offsety, uint32_t OffsetState)
Set for the ADC selected offset number 1, 2, 3 or 4: force offset state disable or enable without mod...
__HAL_LOCK(hrtc)
__STATIC_INLINE void LL_ADC_SetChannelSamplingTime(ADC_TypeDef *ADCx, uint32_t Channel, uint32_t SamplingTime)
Set sampling time of the selected ADC channel Unit: ADC clock cycles.
return HAL_OK
__STATIC_INLINE uint32_t LL_ADC_INJ_IsConversionOngoing(ADC_TypeDef *ADCx)
Get ADC group injected conversion state. CR JADSTART LL_ADC_INJ_IsConversionOngoing.
__STATIC_INLINE uint32_t LL_ADC_GetCommonPathInternalCh(ADC_Common_TypeDef *ADCxy_COMMON)
Get parameter common to several ADC: measurement path to internal channels (VrefInt, temperature sensor, ...).
__STATIC_INLINE void LL_ADC_SetOffset(ADC_TypeDef *ADCx, uint32_t Offsety, uint32_t Channel, uint32_t OffsetLevel)
Set ADC selected offset number 1, 2, 3 or 4.
__STATIC_INLINE uint32_t LL_ADC_REG_IsConversionOngoing(ADC_TypeDef *ADCx)
Get ADC group regular conversion state. CR ADSTART LL_ADC_REG_IsConversionOngoing.
__STATIC_INLINE void LL_ADC_SetCommonPathInternalCh(ADC_Common_TypeDef *ADCxy_COMMON, uint32_t PathInternal)
Set parameter common to several ADC: measurement path to internal channels (VrefInt, temperature sensor, ...).
__STATIC_INLINE void LL_ADC_SetSamplingTimeCommonConfig(ADC_TypeDef *ADCx, uint32_t SamplingTimeCommonConfig)
Set ADC sampling time common configuration impacting settings of sampling time channel wise...
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))