From fb7d8e23dc77c1a230d8fa7902feee6a9c94e7bc Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 23 Aug 2025 11:40:44 +0200 Subject: [PATCH] fix(h7rs): ADC oversampling (#6540) --- radio/src/targets/common/arm/stm32/stm32_adc.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/radio/src/targets/common/arm/stm32/stm32_adc.cpp b/radio/src/targets/common/arm/stm32/stm32_adc.cpp index 75d8c860b..6e6faff8f 100644 --- a/radio/src/targets/common/arm/stm32/stm32_adc.cpp +++ b/radio/src/targets/common/arm/stm32/stm32_adc.cpp @@ -241,7 +241,11 @@ static void adc_setup_scan_mode(ADC_TypeDef* ADCx, uint8_t nconv) } /* Start ADC calibration in mode single-ended or differential */ +#if defined(STM32H7RS) + LL_ADC_StartCalibration(ADCx, LL_ADC_SINGLE_ENDED); +#else LL_ADC_StartCalibration(ADCx, LL_ADC_CALIB_OFFSET_LINEARITY, LL_ADC_SINGLE_ENDED); +#endif /* Wait for calibration completion */ while (LL_ADC_IsCalibrationOnGoing(ADCx) != 0UL); @@ -267,8 +271,15 @@ static void adc_setup_scan_mode(ADC_TypeDef* ADCx, uint8_t nconv) } #if defined(STM32H7RS) || defined(STM32H7) || defined(STM32H5) + +#if defined(ADC3) + #define _SUPPORTS_OVS(adc) (adc != ADC3) +#else + #define _SUPPORTS_OVS(adc) (true) +#endif + // set hardware oversampling - if (!_adc_oversampling_disabled && ADCx != ADC3) { + if (!_adc_oversampling_disabled && _SUPPORTS_OVS(ADCx)) { // LL_ADC_OVS_RATIO_x in stm32h7xx_ll_adc.h is broken // so actual oversampling count need to be used // ADC3 oversampling is disabled because of issues in LL libs