@@ -486,6 +486,8 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef *hadc)
486
486
}
487
487
#endif
488
488
#ifdef __HAL_RCC_ADC_CLK_DISABLE
489
+ __HAL_RCC_ADC_FORCE_RESET ();
490
+ __HAL_RCC_ADC_RELEASE_RESET ();
489
491
__HAL_RCC_ADC_CLK_DISABLE ();
490
492
#endif
491
493
}
@@ -526,13 +528,18 @@ uint16_t adc_read_value(PinName pin)
526
528
AdcHandle .Init .DiscontinuousConvMode = DISABLE ; /* Parameter discarded because sequencer is disabled */
527
529
AdcHandle .Init .ExternalTrigConv = ADC_SOFTWARE_START ; /* Software start to trig the 1st conversion manually, without external event */
528
530
AdcHandle .State = HAL_ADC_STATE_RESET ;
529
- #if defined (STM32F0xx ) || defined (STM32L0xx )
531
+ #if defined (STM32F0xx ) || defined( STM32G0xx ) || defined (STM32L0xx )
530
532
AdcHandle .Init .LowPowerAutoWait = DISABLE ; /* Auto-delayed conversion feature disabled */
531
533
AdcHandle .Init .LowPowerAutoPowerOff = DISABLE ; /* ADC automatically powers-off after a conversion and automatically wakes-up when a new conversion is triggered */
532
534
AdcHandle .Init .Overrun = ADC_OVR_DATA_OVERWRITTEN ; /* DR register is overwritten with the last conversion result in case of overrun */
533
535
#ifdef STM32F0xx
534
536
AdcHandle .Init .SamplingTimeCommon = SAMPLINGTIME ;
535
- #else /* STM32L0 */
537
+ #elif STM32G0xx
538
+ AdcHandle .Init .SamplingTimeCommon1 = SAMPLINGTIME ; /* Set sampling time common to a group of channels. */
539
+ AdcHandle .Init .SamplingTimeCommon2 = SAMPLINGTIME ; /* Set sampling time common to a group of channels, second common setting possible.*/
540
+ AdcHandle .Init .OversamplingMode = DISABLE ;
541
+ AdcHandle .Init .TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH ;
542
+ #else
536
543
//LowPowerFrequencyMode to enable if clk freq < 2.8Mhz
537
544
AdcHandle .Init .SamplingTime = SAMPLINGTIME ;
538
545
#endif /* STM32F0xx */
@@ -543,9 +550,12 @@ uint16_t adc_read_value(PinName pin)
543
550
AdcHandle .Init .Overrun = ADC_OVR_DATA_OVERWRITTEN ; /* DR register is overwritten with the last conversion result in case of overrun */
544
551
#endif /* !STM32H7xx */
545
552
#endif /* STM32F3xx || STM32H7xx */
546
- AdcHandle .Init .NbrOfConversion = 1 ; /* Specifies the number of ranks that will be converted within the regular group sequencer. */
547
553
AdcHandle .Init .NbrOfDiscConversion = 0 ; /* Parameter discarded because sequencer is disabled */
548
- #endif /* STM32F0xx || STM32L0xx */
554
+ #endif /* STM32F0xx || STM32G0xx || STM32L0xx */
555
+
556
+ #if !defined (STM32F0xx ) && !defined (STM32L0xx )
557
+ AdcHandle .Init .NbrOfConversion = 1 ; /* Specifies the number of ranks that will be converted within the regular group sequencer. */
558
+ #endif
549
559
550
560
g_current_pin = pin ; /* Needed for HAL_ADC_MspInit*/
551
561
@@ -565,8 +575,12 @@ uint16_t adc_read_value(PinName pin)
565
575
#endif /* STM32L4xx */
566
576
AdcChannelConf .Rank = ADC_REGULAR_RANK_1 ; /* Specifies the rank in the regular group sequencer */
567
577
#ifndef STM32L0xx
578
+ #if defined (STM32G0xx )
579
+ AdcChannelConf .SamplingTime = ADC_SAMPLINGTIME_COMMON_1 ; /* Sampling time value to be set for the selected channel */
580
+ #else
568
581
AdcChannelConf .SamplingTime = SAMPLINGTIME ; /* Sampling time value to be set for the selected channel */
569
582
#endif
583
+ #endif
570
584
#if defined (STM32F3xx ) || defined (STM32L4xx ) || defined (STM32H7xx ) || defined(STM32WBxx )
571
585
AdcChannelConf .SingleDiff = ADC_SINGLE_ENDED ; /* Single-ended input channel */
572
586
AdcChannelConf .OffsetNumber = ADC_OFFSET_NONE ; /* No offset subtraction */
@@ -579,10 +593,10 @@ uint16_t adc_read_value(PinName pin)
579
593
}
580
594
581
595
#if defined (STM32F0xx ) || defined (STM32F1xx ) || defined (STM32F3xx ) || \
582
- defined (STM32H7xx ) || defined (STM32L0xx ) || defined (STM32L4xx ) || \
583
- defined(STM32WBxx )
596
+ defined (STM32H7xx ) || defined (STM32G0xx ) || defined (STM32L0xx ) || \
597
+ defined ( STM32L4xx ) || defined (STM32WBxx )
584
598
/*##-2.1- Calibrate ADC then Start the conversion process ####################*/
585
- #if defined (STM32F0xx ) || defined (STM32F1xx )
599
+ #if defined (STM32F0xx ) || defined (STM32G0xx ) || defined ( STM32F1xx )
586
600
if (HAL_ADCEx_Calibration_Start (& AdcHandle ) != HAL_OK )
587
601
#elif defined (STM32H7xx )
588
602
if (HAL_ADCEx_Calibration_Start (& AdcHandle , ADC_CALIB_OFFSET , ADC_SINGLE_ENDED ) != HAL_OK )
0 commit comments