From 1163f2c7ab8355ac6383ec6e854cf03f17a3d80b Mon Sep 17 00:00:00 2001 From: jeromecoutant Date: Thu, 22 Mar 2018 13:18:55 +0100 Subject: [PATCH] STM32F7 ADC internal channels update --- targets/TARGET_STM/TARGET_STM32F7/analogin_device.c | 11 ++++++++++- .../TARGET_STM32F7/device/stm32f7xx_hal_adc.h | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/targets/TARGET_STM/TARGET_STM32F7/analogin_device.c b/targets/TARGET_STM/TARGET_STM32F7/analogin_device.c index 6592383e19..2d5c50d548 100644 --- a/targets/TARGET_STM/TARGET_STM32F7/analogin_device.c +++ b/targets/TARGET_STM/TARGET_STM32F7/analogin_device.c @@ -107,7 +107,7 @@ uint16_t adc_read(analogin_t *obj) // Configure ADC channel sConfig.Rank = 1; - sConfig.SamplingTime = ADC_SAMPLETIME_15CYCLES; + sConfig.SamplingTime = ADC_SAMPLETIME_56CYCLES; sConfig.Offset = 0; switch (obj->channel) { @@ -161,17 +161,26 @@ uint16_t adc_read(analogin_t *obj) break; case 16: sConfig.Channel = ADC_CHANNEL_TEMPSENSOR; + sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES; break; case 17: sConfig.Channel = ADC_CHANNEL_VREFINT; + sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES; break; case 18: sConfig.Channel = ADC_CHANNEL_VBAT; + sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES; break; default: return 0; } + // Measuring VBAT sets the ADC_CCR_VBATE bit in ADC->CCR, and there is not + // possibility with the ST HAL driver to clear it. If it isn't cleared, + // VBAT remains connected to the ADC channel in preference to temperature, + // so VBAT readings are returned in place of temperature. + ADC->CCR &= ~(ADC_CCR_VBATE | ADC_CCR_TSVREFE); + HAL_ADC_ConfigChannel(&obj->handle, &sConfig); HAL_ADC_Start(&obj->handle); // Start conversion diff --git a/targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_hal_adc.h b/targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_hal_adc.h index 43480e1e01..04291ac5a0 100644 --- a/targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_hal_adc.h +++ b/targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_hal_adc.h @@ -44,6 +44,9 @@ /* Includes ------------------------------------------------------------------*/ #include "stm32f7xx_hal_def.h" +/* Include low level driver */ +#include "stm32f7xx_ll_adc.h" + /** @addtogroup STM32F7xx_HAL_Driver * @{ */