This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch releases/12.9
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/releases/12.9 by this push:
     new df37552a82 arch/stm32f0l0g0/stm32_adc.c: fix ADC calibration
df37552a82 is described below

commit df37552a828b5c2a82b38dc09e1c40b43016e5f7
Author: raiden00pl <[email protected]>
AuthorDate: Fri Apr 4 14:37:37 2025 +0200

    arch/stm32f0l0g0/stm32_adc.c: fix ADC calibration
    
    Fix and enable ADC calibration. The ADC voltage regulator must be
    enabled and regulator start-up time must be respected.
    
    tested on nucleo-c071rb and b-l072z-lrwan1
    
    Signed-off-by: raiden00pl <[email protected]>
---
 arch/arm/src/stm32f0l0g0/stm32_adc.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/arch/arm/src/stm32f0l0g0/stm32_adc.c 
b/arch/arm/src/stm32f0l0g0/stm32_adc.c
index 891c7a2c49..7ef424ba01 100644
--- a/arch/arm/src/stm32f0l0g0/stm32_adc.c
+++ b/arch/arm/src/stm32f0l0g0/stm32_adc.c
@@ -1029,18 +1029,16 @@ static void adc_watchdog_cfg(struct stm32_dev_s *priv)
 
 static void adc_calibrate(struct stm32_dev_s *priv)
 {
-#if 0 /* Doesn't work */
-  /* Calibrate the ADC */
+  /* Calibrate the ADC.
+   *   1. ADC must be disabled
+   *   2. the voltage regulater must be enabled
+   */
 
-  adc_modifyreg(priv, STM32_ADC_CR_OFFSET, ADC_CR_ADCALDIF, AD_CR_ADCAL);
+  adc_modifyreg(priv, STM32_ADC_CR_OFFSET, 0, ADC_CR_ADCAL);
 
   /* Wait for the calibration to complete */
 
   while ((adc_getreg(priv, STM32_ADC_CR_OFFSET) & ADC_CR_ADCAL) != 0);
-
-#else
-  UNUSED(priv);
-#endif
 }
 
 /****************************************************************************
@@ -1072,7 +1070,13 @@ static void adc_mode_cfg(struct stm32_dev_s *priv)
 
 static void adc_voltreg_cfg(struct stm32_dev_s *priv)
 {
-  UNUSED(priv);
+  /* Enable voltage regulator - required by ADC calibration */
+
+  adc_putreg(priv, STM32_ADC_CR_OFFSET, ADC_CR_ADVREGEN);
+
+  /* Wait for ADC voltage regulator start-up */
+
+  up_udelay(50);
 }
 
 /****************************************************************************

Reply via email to