Skip to content

Commit

Permalink
Merge pull request #20044 from bissell-homecare-inc/stm32_adc_cal
Browse files Browse the repository at this point in the history
cpu/stm32: add ADCAL operation
  • Loading branch information
maribu authored Nov 28, 2023
2 parents ad7bf85 + b09713e commit 7790f85
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cpu/stm32/periph/adc_f0_g0.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ int adc_init(adc_t line)
}
/* reset configuration */
ADC1->CFGR2 = 0;
#if defined(ADC_CR_ADVREGEN)
/* calibrate ADC, per RM0454 section 14.3.3 */
/* 1. ensure ADEN=0, ADVREGEN=1, DMAEN=0 */
ADC1->CR |= ADC_CR_ADVREGEN;
ADC1->CR &= ~(ADC_CR_ADCAL | ADC_CR_ADEN );
ADC1->CFGR1 &= ~(ADC_CFGR1_DMAEN);
/* 2. Set ADCAL=1 */
ADC1->CR |= ADC_CR_ADCAL;
/* 3. Wait for ADCAL=0 (or EOCAL=1) */
while ((ADC1->ISR & ADC_ISR_EOCAL)) {}
#endif
/* enable device */
ADC1->CR = ADC_CR_ADEN;
/* configure sampling time to save value */
Expand Down

0 comments on commit 7790f85

Please sign in to comment.