drivers: sensor: stm32 Vref sensor calibration on 12bit

The Calibration value of the VRef on stm32U5 is acquired on 14Bit by ADC1
and should be adjusted on 12bit becasue the resolution is 12bit
in this stm32_vref driver.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
This commit is contained in:
Francois Ramu 2023-08-10 15:08:17 +02:00 committed by Carles Cufí
commit 4e070a0867

View file

@ -86,7 +86,16 @@ static int stm32_vref_channel_get(const struct device *dev, enum sensor_channel
#endif /* CONFIG_SOC_SERIES_STM32H5X */ #endif /* CONFIG_SOC_SERIES_STM32H5X */
/* Calculate VREF+ using VREFINT bandgap voltage and calibration data */ /* Calculate VREF+ using VREFINT bandgap voltage and calibration data */
#if defined(CONFIG_SOC_SERIES_STM32U5X)
/*
* The VREF CALIBRATION value is acquired on 14 bits
* and the data acquired is on 12 bits
* since the adc_sequence.resolution is 12
*/
vref = (cfg->cal_mv * (*cfg->cal_addr) >> 2) / data->raw;
#else
vref = cfg->cal_mv * (*cfg->cal_addr) / data->raw; vref = cfg->cal_mv * (*cfg->cal_addr) / data->raw;
#endif /* CONFIG_SOC_SERIES_STM32H5X */
/* millivolt to volt */ /* millivolt to volt */
vref /= 1000; vref /= 1000;