From 833501dee6b71c9f254b5e9702055290da3a6b8a Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Fri, 19 Mar 2021 02:32:08 -0700 Subject: [PATCH] stm32h7:adc fix temperature sensing --- platforms/nuttx/src/px4/stm/stm32h7/adc/adc.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/platforms/nuttx/src/px4/stm/stm32h7/adc/adc.cpp b/platforms/nuttx/src/px4/stm/stm32h7/adc/adc.cpp index f3379ee6dc..68d640fa55 100644 --- a/platforms/nuttx/src/px4/stm/stm32h7/adc/adc.cpp +++ b/platforms/nuttx/src/px4/stm/stm32h7/adc/adc.cpp @@ -40,6 +40,14 @@ #include #include +/* + * If there is only one ADC in use in PX4 and it is not + * ADC3 we still need ADC3 for temperature sensing. + */ +#if SYSTEM_ADC_COUNT == 1 && SYSTEM_ADC_BASE != STM32_ADC3_BASE +# undef SYSTEM_ADC_COUNT +# define SYSTEM_ADC_COUNT 2 +#endif /* * Register accessors. @@ -280,8 +288,15 @@ uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel) /* Add a channel mapping for ADC3 on the H7 */ if (channel == PX4_ADC_INTERNAL_TEMP_SENSOR_CHANNEL) { + static bool once = false; channel = ADC3_INTERNAL_TEMP_SENSOR_CHANNEL; base_address = STM32_ADC3_BASE; + + // Init it once (px4_arch_adc_init does this as well, but this is less cycles) + if (!once) { + once = true; + px4_arch_adc_init(base_address); + } }