69
69
/** @addtogroup STM32F4xx_System_Private_Defines
70
70
* @{
71
71
*/
72
- #if defined(ADC_SAMPLETIME_15CYCLES )
73
- #define SAMPLINGTIME ADC_SAMPLETIME_15CYCLES;
72
+ #if defined(ADC_SAMPLETIME_8CYCLES_5 )
73
+ #define SAMPLINGTIME ADC_SAMPLETIME_8CYCLES_5;
74
+ #elif defined(ADC_SAMPLETIME_12CYCLES_5 )
75
+ #define SAMPLINGTIME ADC_SAMPLETIME_12CYCLES_5;
74
76
#elif defined(ADC_SAMPLETIME_13CYCLES_5 )
75
77
#define SAMPLINGTIME ADC_SAMPLETIME_13CYCLES_5;
76
- #elif defined(ADC_SAMPLETIME_19CYCLES_5 )
77
- #define SAMPLINGTIME ADC_SAMPLETIME_19CYCLES_5 ;
78
+ #elif defined(ADC_SAMPLETIME_15CYCLES )
79
+ #define SAMPLINGTIME ADC_SAMPLETIME_15CYCLES ;
78
80
#elif defined(ADC_SAMPLETIME_16CYCLES )
79
81
#define SAMPLINGTIME ADC_SAMPLETIME_16CYCLES;
80
- #elif defined(ADC_SAMPLETIME_12CYCLES_5 )
81
- #define SAMPLINGTIME ADC_SAMPLETIME_12CYCLES_5 ;
82
+ #elif defined(ADC_SAMPLETIME_19CYCLES_5 )
83
+ #define SAMPLINGTIME ADC_SAMPLETIME_19CYCLES_5 ;
82
84
#else
83
85
#error "ADC SAMPLINGTIME could not be defined"
84
86
#endif
85
87
86
88
#ifndef STM32F1xx
87
- #ifdef ADC_CLOCK_SYNC_PCLK_DIV2
89
+ #ifdef ADC_CLOCK_SYNC_PCLK_DIV4
90
+ #define ADC_CLOCK_DIV ADC_CLOCK_SYNC_PCLK_DIV4
91
+ #elif ADC_CLOCK_SYNC_PCLK_DIV2
88
92
#define ADC_CLOCK_DIV ADC_CLOCK_SYNC_PCLK_DIV2
89
93
#elif defined(ADC_CLOCK_ASYNC_DIV1 )
90
94
#define ADC_CLOCK_DIV ADC_CLOCK_ASYNC_DIV1
@@ -265,6 +269,9 @@ void HAL_DAC_MspInit(DAC_HandleTypeDef *hdac)
265
269
#endif
266
270
#ifdef __HAL_RCC_DAC_CLK_ENABLE
267
271
__HAL_RCC_DAC_CLK_ENABLE ();
272
+ #endif
273
+ #ifdef __HAL_RCC_DAC12_CLK_ENABLE
274
+ __HAL_RCC_DAC12_CLK_ENABLE ();
268
275
#endif
269
276
/* Configure DAC GPIO pins */
270
277
pinmap_pinout (g_current_pin , PinMap_DAC );
@@ -422,8 +429,9 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc)
422
429
#ifdef __HAL_RCC_ADC_CLK_ENABLE
423
430
__HAL_RCC_ADC_CLK_ENABLE ();
424
431
#endif
425
- /* For STM32F1xx, ADC prescaler is confgured in SystemClock_Config (variant.cpp) */
426
- #if defined(__HAL_RCC_ADC_CONFIG ) && !defined(STM32F1xx )
432
+ /* For STM32F1xx and STM32H7xx, ADC prescaler is configured in
433
+ SystemClock_Config (variant.cpp) */
434
+ #if defined(__HAL_RCC_ADC_CONFIG ) && !defined(STM32F1xx ) && !defined(STM32H7xx )
427
435
/* ADC Periph interface clock configuration */
428
436
__HAL_RCC_ADC_CONFIG (RCC_ADCCLKSOURCE_SYSCLK );
429
437
#endif
@@ -538,13 +546,19 @@ uint16_t adc_read_value(PinName pin)
538
546
if (AdcHandle .Instance == NP ) return 0 ;
539
547
540
548
#ifndef STM32F1xx
541
- AdcHandle .Init .ClockPrescaler = ADC_CLOCK_DIV ; /* Asynchronous clock mode, input ADC clock divided */
549
+ AdcHandle .Init .ClockPrescaler = ADC_CLOCK_DIV ; /* Asynchronous clock mode, input ADC clock divided */
542
550
AdcHandle .Init .Resolution = ADC_RESOLUTION_12B ; /* 12-bit resolution for converted data */
543
551
AdcHandle .Init .EOCSelection = ADC_EOC_SINGLE_CONV ; /* EOC flag picked-up to indicate conversion end */
544
552
AdcHandle .Init .ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE ; /* Parameter discarded because software trigger chosen */
553
+ #ifdef STM32H7xx
554
+ AdcHandle .Init .ConversionDataManagement = ADC_CONVERSIONDATA_DR ; /* Regular Conversion data stored in DR register only */
555
+ #else
545
556
AdcHandle .Init .DMAContinuousRequests = DISABLE ; /* DMA one-shot mode selected (not applied to this example) */
546
- #endif
557
+ #endif /* STM32H7xx */
558
+ #endif /* STM32F1xx */
559
+ #ifndef STM32H7xx
547
560
AdcHandle .Init .DataAlign = ADC_DATAALIGN_RIGHT ; /* Right-alignment for converted data */
561
+ #endif /* !STM32H7xx */
548
562
AdcHandle .Init .ScanConvMode = DISABLE ; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
549
563
AdcHandle .Init .ContinuousConvMode = DISABLE ; /* Continuous mode disabled to have only 1 conversion at each conversion trig */
550
564
AdcHandle .Init .DiscontinuousConvMode = DISABLE ; /* Parameter discarded because sequencer is disabled */
@@ -556,17 +570,20 @@ uint16_t adc_read_value(PinName pin)
556
570
AdcHandle .Init .Overrun = ADC_OVR_DATA_OVERWRITTEN ; /* DR register is overwritten with the last conversion result in case of overrun */
557
571
#ifdef STM32F0xx
558
572
AdcHandle .Init .SamplingTimeCommon = SAMPLINGTIME ;
559
- #else // STM32L0
573
+ #else /* STM32L0 */
560
574
//LowPowerFrequencyMode to enable if clk freq < 2.8Mhz
561
575
AdcHandle .Init .SamplingTime = SAMPLINGTIME ;
562
- #endif
576
+ #endif /* STM32F0xx */
563
577
#else
564
- #ifdef STM32F3xx
578
+ #if defined ( STM32F3xx ) || defined ( STM32H7xx )
565
579
AdcHandle .Init .LowPowerAutoWait = DISABLE ; /* Auto-delayed conversion feature disabled */
566
- #endif
580
+ #ifndef STM32H7xx
581
+ AdcHandle .Init .Overrun = ADC_OVR_DATA_OVERWRITTEN ; /* DR register is overwritten with the last conversion result in case of overrun */
582
+ #endif /* !STM32H7xx */
583
+ #endif /* STM32F3xx || STM32H7xx */
567
584
AdcHandle .Init .NbrOfConversion = 1 ; /* Specifies the number of ranks that will be converted within the regular group sequencer. */
568
585
AdcHandle .Init .NbrOfDiscConversion = 0 ; /* Parameter discarded because sequencer is disabled */
569
- #endif
586
+ #endif /* STM32F0xx || STM32L0xx */
570
587
571
588
g_current_pin = pin ; /* Needed for HAL_ADC_MspInit*/
572
589
@@ -579,12 +596,12 @@ uint16_t adc_read_value(PinName pin)
579
596
if (!IS_ADC_CHANNEL (& AdcHandle , AdcChannelConf .Channel )) return 0 ;
580
597
#else
581
598
if (!IS_ADC_CHANNEL (AdcChannelConf .Channel )) return 0 ;
582
- #endif
599
+ #endif /* STM32L4xx */
583
600
AdcChannelConf .Rank = ADC_REGULAR_RANK_1 ; /* Specifies the rank in the regular group sequencer */
584
601
#ifndef STM32L0xx
585
602
AdcChannelConf .SamplingTime = SAMPLINGTIME ; /* Sampling time value to be set for the selected channel */
586
603
#endif
587
- #if defined (STM32F3xx ) || defined (STM32L4xx )
604
+ #if defined (STM32F3xx ) || defined (STM32L4xx ) || defined ( STM32H7xx )
588
605
AdcChannelConf .SingleDiff = ADC_SINGLE_ENDED ; /* Single-ended input channel */
589
606
AdcChannelConf .OffsetNumber = ADC_OFFSET_NONE ; /* No offset subtraction */
590
607
AdcChannelConf .Offset = 0 ; /* Parameter discarded because offset correction is disabled */
@@ -596,10 +613,13 @@ uint16_t adc_read_value(PinName pin)
596
613
return 0 ;
597
614
}
598
615
599
- #if defined (STM32F0xx ) || defined (STM32F1xx ) || defined (STM32F3xx ) || defined (STM32L0xx ) || defined (STM32L4xx )
616
+ #if defined (STM32F0xx ) || defined (STM32F1xx ) || defined (STM32F3xx ) || \
617
+ defined (STM32H7xx ) || defined (STM32L0xx ) || defined (STM32L4xx )
600
618
/*##-2.1- Calibrate ADC then Start the conversion process ####################*/
601
619
#if defined (STM32F0xx ) || defined (STM32F1xx )
602
620
if (HAL_ADCEx_Calibration_Start (& AdcHandle ) != HAL_OK )
621
+ #elif defined (STM32H7xx )
622
+ if (HAL_ADCEx_Calibration_Start (& AdcHandle , ADC_CALIB_OFFSET , ADC_SINGLE_ENDED ) != HAL_OK )
603
623
#else
604
624
if (HAL_ADCEx_Calibration_Start (& AdcHandle , ADC_SINGLE_ENDED ) != HAL_OK )
605
625
#endif
0 commit comments