From b4700a876f20f22eb6981d74ca411cef98372e00 Mon Sep 17 00:00:00 2001 From: Robbe Derks Date: Tue, 1 Aug 2023 20:48:10 -0700 Subject: [PATCH] Stable ADC on H7 (#1540) * 256x oversampling * reduce to 128x * fix misra --------- Co-authored-by: Comma Device --- board/stm32h7/lladc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/board/stm32h7/lladc.h b/board/stm32h7/lladc.h index 29d5e19d6..0a52b78d3 100644 --- a/board/stm32h7/lladc.h +++ b/board/stm32h7/lladc.h @@ -18,12 +18,12 @@ void adc_init(void) { } uint16_t adc_get_raw(uint8_t channel) { - ADC1->SQR1 &= ~(ADC_SQR1_L); ADC1->SQR1 = ((uint32_t) channel << 6U); - ADC1->SMPR1 = (0x7U << (channel * 3U) ); + ADC1->SMPR1 = (0x2U << (channel * 3U)); ADC1->PCSEL_RES0 = (0x1U << channel); + ADC1->CFGR2 = (127U << ADC_CFGR2_OVSR_Pos) | (0x7U << ADC_CFGR2_OVSS_Pos) | ADC_CFGR2_ROVSE; ADC1->CR |= ADC_CR_ADSTART; while (!(ADC1->ISR & ADC_ISR_EOC));