summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuuki NAGAO <wf.yn386@gmail.com>2023-07-08 10:59:35 +0900
committerDamien George <damien@micropython.org>2023-07-13 12:39:06 +1000
commit0ba94a67ba72f2e04bfc26dcf0ed687addd0d740 (patch)
treed2b46cc65b9d5d2953296d87c25fbc8c2a1cbf1b
parentde8035b51070f14b3af32870fb8eede97ddb4215 (diff)
stm32/adc: Fix pyb.ADCAll.read_core_temp for G4 MCUs.
For STM32G4, * TS_CAL1 raw data acquired at a temperature of 30°C * TS_CAL2 raw data acquired at a temperature of 130°C Also, these values are at VDDA=3.0V. Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
-rw-r--r--ports/stm32/adc.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/ports/stm32/adc.c b/ports/stm32/adc.c
index e2eb5f7e5..fc0882286 100644
--- a/ports/stm32/adc.c
+++ b/ports/stm32/adc.c
@@ -866,6 +866,12 @@ int adc_read_core_temp(ADC_HandleTypeDef *adcHandle) {
STATIC volatile float adc_refcor = 1.0f;
float adc_read_core_temp_float(ADC_HandleTypeDef *adcHandle) {
+ #if defined(STM32G4) || defined(STM32L1) || defined(STM32L4)
+ // Update the reference correction factor before reading tempsensor
+ // because TS_CAL1 and TS_CAL2 of STM32G4,L1/L4 are at VDDA=3.0V
+ adc_read_core_vref(adcHandle);
+ #endif
+
#if defined(STM32G4)
int32_t raw_value = 0;
if (adcHandle->Instance == ADC1) {
@@ -873,15 +879,11 @@ float adc_read_core_temp_float(ADC_HandleTypeDef *adcHandle) {
} else {
return 0;
}
+ float core_temp_avg_slope = (*ADC_CAL2 - *ADC_CAL1) / 100.0f;
#else
- #if defined(STM32L1) || defined(STM32L4)
- // Update the reference correction factor before reading tempsensor
- // because TS_CAL1 and TS_CAL2 of STM32L1/L4 are at VDDA=3.0V
- adc_read_core_vref(adcHandle);
- #endif
int32_t raw_value = adc_config_and_read_ref(adcHandle, ADC_CHANNEL_TEMPSENSOR);
- #endif
float core_temp_avg_slope = (*ADC_CAL2 - *ADC_CAL1) / 80.0f;
+ #endif
return (((float)raw_value * adc_refcor - *ADC_CAL1) / core_temp_avg_slope) + 30.0f;
}