From 3796a319599e84b58886ec6f733277bfe4f1a747 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 25 Jul 2022 10:21:29 -0400 Subject: [PATCH] stm32: Add CCRDY check to stm32g0 adc The stm32g0 specification states that it is required to wait for the CCRDY flag to be raised after changing the channel configuration. Signed-off-by: Kevin O'Connor --- src/stm32/stm32f0_adc.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/stm32/stm32f0_adc.c b/src/stm32/stm32f0_adc.c index 8f27dce7..f46ccbde 100644 --- a/src/stm32/stm32f0_adc.c +++ b/src/stm32/stm32f0_adc.c @@ -119,7 +119,16 @@ gpio_adc_sample(struct gpio_adc g) return 0; goto need_delay; } +#if CONFIG_MACH_STM32G0 + if (adc->CHSELR != g.chan) { + adc->ISR = ADC_ISR_CCRDY; + adc->CHSELR = g.chan; + while (!(adc->ISR & ADC_ISR_CCRDY)) + ; + } +#else adc->CHSELR = g.chan; +#endif adc->CR = CR_FLAGS | ADC_CR_ADSTART; need_delay: