aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2022-12-14 11:36:18 -0500
committerKevin O'Connor <kevin@koconnor.net>2023-01-17 18:22:21 -0500
commit33f973e4523a0d86110bef19e9e0de6a8092ade1 (patch)
treee610d2bca7f7246ef5b1d9facad503ecf454f5ef
parentcefbad9ef4cea82c6bc006b1f78f174f69bc594e (diff)
downloadkutter-33f973e4523a0d86110bef19e9e0de6a8092ade1.tar.gz
kutter-33f973e4523a0d86110bef19e9e0de6a8092ade1.tar.xz
kutter-33f973e4523a0d86110bef19e9e0de6a8092ade1.zip
stm32: Don't set boost nor linear calibration on stm32h723 adc3
Only adc1 and adc2 have these CR register bits on stm32h723. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--src/stm32/stm32h7_adc.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/stm32/stm32h7_adc.c b/src/stm32/stm32h7_adc.c
index 75a56508..fdd8d21d 100644
--- a/src/stm32/stm32h7_adc.c
+++ b/src/stm32/stm32h7_adc.c
@@ -210,20 +210,26 @@ gpio_adc_setup(uint32_t pin)
// Enable the ADC
if (!(adc->CR & ADC_CR_ADEN)) {
// Switch on voltage regulator and wait for it to stabilize
- adc->CR = ADC_CR_ADVREGEN;
+ uint32_t cr = ADC_CR_ADVREGEN;
+ adc->CR = cr;
uint32_t end = timer_read_time() + timer_from_us(20);
while (timer_is_before(timer_read_time(), end))
;
- // Perform adc calibration
- uint32_t cr = ADC_CR_ADVREGEN | ADC_CR_ADCAL;
+ // Setup chip specific flags
#if CONFIG_MACH_STM32H7
- // Set boost mode on stm32h7 (adc clock is at 25Mhz)
- cr |= 0b10 << ADC_CR_BOOST_Pos;
- // Use linear calibration on stm32h7
- cr |= ADC_CR_ADCALLIN;
+ if (!(CONFIG_MACH_STM32H723 && adc == ADC3)) {
+ // Use linear calibration on stm32h7
+ cr |= ADC_CR_ADCALLIN;
+ // Set boost mode on stm32h7 (adc clock is at 25Mhz)
+ cr |= 0b10 << ADC_CR_BOOST_Pos;
+ // Set 12bit samples on the stm32h7
+ adc->CFGR = ADC_CFGR_JQDIS | (0b110 << ADC_CFGR_RES_Pos);
+ }
#endif
- adc->CR = cr;
+
+ // Perform adc calibration
+ adc->CR = cr | ADC_CR_ADCAL;
while (adc->CR & ADC_CR_ADCAL)
;
@@ -242,12 +248,6 @@ gpio_adc_setup(uint32_t pin)
| (aticks << 27));
adc->SMPR1 = av;
adc->SMPR2 = av;
-
- // The stm32h7 chips need to be set to 12bit samples
-#if CONFIG_MACH_STM32H7
- if (!(CONFIG_MACH_STM32H723 && adc == ADC3))
- adc->CFGR = ADC_CFGR_JQDIS | (0b110 << ADC_CFGR_RES_Pos);
-#endif
}
if (pin == ADC_TEMPERATURE_PIN) {