8000 Merge pull request #1493 from fpistm/ADC · stm32duino/Arduino_Core_STM32@5d64997 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5d64997

Browse files
authored
Merge pull request #1493 from fpistm/ADC
bsp: ADC enhancements
2 parents 974b356 + 7fb0803 commit 5d64997

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

libraries/SrcWrapper/src/stm32/analog.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ static PinName g_current_pin = NC;
4646
#endif
4747
#endif /* !ADC_SAMPLINGTIME */
4848

49+
#if defined(ADC_VER_V5_V90) && !defined(ADC3_SAMPLINGTIME)
50+
#define ADC3_SAMPLINGTIME ADC3_SAMPLETIME_24CYCLES_5;
51+
#endif
52+
4953
/*
5054
* Minimum ADC sampling time is required when reading
5155
* internal channels so set it to max possible value.
@@ -770,6 +774,11 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
770774
} else {
771775
AdcHandle.Instance = (ADC_TypeDef *)pinmap_peripheral(pin, PinMap_ADC);
772776
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
773782
}
774783

775784
if (AdcHandle.Instance == NP) {
@@ -822, 8000 7 +831,7 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
822831
AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV; /* EOC flag picked-up to indicate conversion end */
823832
#endif
824833
#if !defined(STM32F1xx) && !defined(STM32F2xx) && !defined(STM32F4xx) && \
825-
!defined(STM32F7xx) && !defined(STM32F373xC) && !defined(STM32F378xx)
834+
!defined(STM32F7xx) && !defined(ADC1_V2_5)
826835
AdcHandle.Init.LowPowerAutoWait = DISABLE; /* Auto-delayed conversion feature disabled */
827836
#endif
828837
#if !defined(STM32F1xx) && !defined(STM32F2xx) && !defined(STM32F3xx) && \
@@ -846,11 +855,11 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
846855
AdcHandle.Init.NbrOfDiscConversion = 0; /* Parameter discarded because sequencer is disabled */
847856
#endif
848857
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)
850859
AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; /* Parameter discarded because software trigger chosen */
851860
#endif
852861
#if !defined(STM32F1xx) && !defined(STM32H7xx) && !defined(STM32MP1xx) && \
853-
!defined(STM32F373xC) && !defined(STM32F378xx)
862+
!defined(ADC1_V2_5)
854863
AdcHandle.Init.DMAContinuousRequests = DISABLE; /* DMA one-shot mode selected (not applied to this example) */
855864
#endif
856865
#ifdef ADC_CONVERSIONDATA_DR
@@ -901,13 +910,12 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
901910

902911
AdcChannelConf.Channel = channel; /* Specifies the channel to configure into ADC */
903912

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)
907915
if (!IS_ADC_CHANNEL(&AdcHandle, AdcChannelConf.Channel)) {
908916
#else
909917
if (!IS_ADC_CHANNEL(AdcChannelConf.Channel)) {
910-
#endif /* STM32L4xx || STM32WBxx */
918+
#endif
911919
return 0;
912920
}
913921
#ifdef ADC_SCAN_SEQ_FIXED
@@ -922,17 +930,14 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
922930
AdcChannelConf.SamplingTime = ADC_SAMPLINGTIME_COMMON_1; /* Sampling time value to be set for the selected channel */
923931
#endif
924932
#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)
929934
AdcChannelConf.SingleDiff = ADC_SINGLE_ENDED; /* Single-ended input channel */
930935
AdcChannelConf.OffsetNumber = ADC_OFFSET_NONE; /* No offset subtraction */
931936
#endif
932937
#if !defined(STM32F0xx) && !defined(STM32F1xx) && !defined(STM32F2xx) && \
933938
!defined(STM32G0xx) && !defined(STM32L0xx) && !defined(STM32L1xx) && \
934939
!defined(STM32WBxx) && !defined(STM32WLxx) && \
935-
!defined(STM32F373xC) && !defined(STM32F378xx)
940+
!defined(ADC1_V2_5)
936941
AdcChannelConf.Offset = 0; /* Parameter discarded because offset correction is disabled */
937942
#endif
938943
#if defined (STM32H7xx) || defined(STM32MP1xx)
@@ -946,18 +951,14 @@ uint16_t adc_read_value(PinName pin, uint32_t resolution)
946951
return 0;
947952
}
948953

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)
953955
/*##-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)
958957
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)
960959
if (HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_SINGLE_ENDED) != HAL_OK)
960+
#else
961+
if (HAL_ADCEx_Calibration_Start(&AdcHandle) != HAL_OK)
961962
#endif
962963
{
963964
/* ADC Calibration Error */

0 commit comments

Comments
 (0)
0