@@ -46,6 +46,10 @@ static PinName g_current_pin = NC;
46
46
#endif
47
47
#endif /* !ADC_SAMPLINGTIME */
48
48
49
+ #if defined(ADC_VER_V5_V90) && !defined(ADC3_SAMPLINGTIME)
50
+ #define ADC3_SAMPLINGTIME ADC3_SAMPLETIME_24CYCLES_5;
51
+ #endif
52
+
49
53
/*
50
54
* Minimum ADC sampling time is required when reading
51
55
* internal channels so set it to max possible value.
@@ -770,6 +774,11 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
770
774
} else {
771
775
AdcHandle.Instance = (ADC_TypeDef *)pinmap_peripheral (pin, PinMap_ADC);
772
776
channel = get_adc_channel (pin, &bank);
777
+ #if defined(ADC_VER_V5_V90)
778
+ if (AdcHandle.Instance == ADC3) {
779
+ samplingTime = ADC3_SAMPLINGTIME;
780
+ }
781
+ #endif
773
782
}
774
783
775
784
if (AdcHandle.Instance == NP) {
@@ -822,7 +831,7 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
822
831
AdcHandle.Init .EOCSelection = ADC_EOC_SINGLE_CONV; /* EOC flag picked-up to indicate conversion end */
823
832
#endif
824
833
#if !defined(STM32F1xx) && !defined(STM32F2xx) && !defined(STM32F4xx) && \
825
- !defined (STM32F7xx) && !defined (STM32F373xC) && ! defined (STM32F378xx )
834
+ !defined (STM32F7xx) && !defined (ADC1_V2_5 )
826
835
AdcHandle.Init .LowPowerAutoWait = DISABLE; /* Auto-delayed conversion feature disabled */
827
836
#endif
828
837
#if !defined(STM32F1xx) && !defined(STM32F2xx) && !defined(STM32F3xx) && \
@@ -846,11 +855,11 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
846
855
AdcHandle.Init .NbrOfDiscConversion = 0 ; /* Parameter discarded because sequencer is disabled */
847
856
#endif
848
857
AdcHandle.Init .ExternalTrigConv = ADC_SOFTWARE_START; /* Software start to trig the 1st conversion manually, without external event */
849
- #if !defined(STM32F1xx) && !defined(STM32F373xC) && !defined(STM32F378xx )
858
+ #if !defined(STM32F1xx) && !defined(ADC1_V2_5 )
850
859
AdcHandle.Init .ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; /* Parameter discarded because software trigger chosen */
851
860
#endif
852
861
#if !defined(STM32F1xx) && !defined(STM32H7xx) && !defined(STM32MP1xx) && \
853
- !defined (STM32F373xC) && ! defined (STM32F378xx )
862
+ !defined (ADC1_V2_5 )
854
863
AdcHandle.Init .DMAContinuousRequests = DISABLE; /* DMA one-shot mode selected (not applied to this example) */
855
864
#endif
856
865
#ifdef ADC_CONVERSIONDATA_DR
@@ -901,13 +910,12 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
901
910
902
911
AdcChannelConf.Channel = channel; /* Specifies the channel to configure into ADC */
903
912
904
- #if defined(STM32L4xx) || defined(STM32L5xx) || defined(STM32WBxx)
905
- if (!IS_ADC_CHANNEL (&AdcHandle, AdcChannelConf.Channel )) {
906
- #elif defined(STM32G4xx)
913
+ #if defined(STM32G4xx) || defined(STM32L4xx) || defined(STM32L5xx) || \
914
+ defined (STM32WBxx)
907
915
if (!IS_ADC_CHANNEL (&AdcHandle, AdcChannelConf.Channel )) {
908
916
#else
909
917
if (!IS_ADC_CHANNEL (AdcChannelConf.Channel )) {
910
- #endif /* STM32L4xx || STM32WBxx */
918
+ #endif
911
919
return 0 ;
912
920
}
913
921
#ifdef ADC_SCAN_SEQ_FIXED
@@ -922,17 +930,14 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
922
930
AdcChannelConf.SamplingTime = ADC_SAMPLINGTIME_COMMON_1; /* Sampling time value to be set for the selected channel */
923
931
#endif
924
932
#endif
925
- #if !defined(STM32F0xx) && !defined(STM32F1xx) && !defined(STM32F2xx) && \
926
- !defined (STM32F4xx) && !defined (STM32F7xx) && !defined (STM32G0xx) && \
927
- !defined (STM32L0xx) && !defined (STM32L1xx) && !defined (STM32WLxx) && \
928
- !defined (STM32F373xC) && !defined (STM32F378xx)
933
+ #if defined(ADC_DIFFERENTIAL_ENDED) && !defined(ADC1_V2_5)
929
934
AdcChannelConf.SingleDiff = ADC_SINGLE_ENDED; /* Single-ended input channel */
930
935
AdcChannelConf.OffsetNumber = ADC_OFFSET_NONE; /* No offset subtraction */
931
936
#endif
932
937
#if !defined(STM32F0xx) && !defined(STM32F1xx) && !defined(STM32F2xx) && \
933
938
!defined (STM32G0xx) && !defined (STM32L0xx) && !defined (STM32L1xx) && \
934
939
!defined (STM32WBxx) && !defined (STM32WLxx) && \
935
- !defined (STM32F373xC) && ! defined (STM32F378xx )
940
+ !defined (ADC1_V2_5 )
936
941
AdcChannelConf.Offset = 0 ; /* Parameter discarded because offset correction is disabled */
937
942
#endif
938
943
#if defined (STM32H7xx) || defined(STM32MP1xx)
@@ -946,18 +951,14 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
946
951
return 0 ;
947
952
}
948
953
949
- #if defined(STM32F0xx) || defined(STM32F1xx) || defined(STM32F3xx) || \
950
- defined (STM32G0xx) || defined (STM32G4xx) || defined (STM32H7xx) || \
951
- defined (STM32L0xx) || defined (STM32L4xx) || defined (STM32MP1xx) || \
952
- defined (STM32WBxx) || defined (STM32WLxx)
954
+ #if defined(ADC_CR_ADCAL) || defined(ADC_CR2_RSTCAL)
953
955
/* ##-2.1- Calibrate ADC then Start the conversion process ####################*/
954
- #if defined(STM32F0xx) || defined(STM32G0xx) || defined(STM32F1xx) || \
955
- defined (STM32WLxx) || defined (STM32F373xC) || defined (STM32F378xx)
956
- if (HAL_ADCEx_Calibration_Start (&AdcHandle) != HAL_OK)
957
- #elif defined (STM32H7xx) || defined(STM32MP1xx)
956
+ #if defined(ADC_CALIB_OFFSET)
958
957
if (HAL_ADCEx_Calibration_Start (&AdcHandle, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK)
959
- #else
958
+ #elif defined(ADC_SINGLE_ENDED) && !defined(ADC1_V2_5)
960
959
if (HAL_ADCEx_Calibration_Start (&AdcHandle, ADC_SINGLE_ENDED) != HAL_OK)
960
+ #else
961
+ if (HAL_ADCEx_Calibration_Start (&AdcHandle) != HAL_OK)
961
962
#endif
962
963
{
963
964
/* ADC Calibration Error */
0 commit comments