From 44b2e0b72969bc00cd380914d9aba5685e1bb9e0 Mon Sep 17 00:00:00 2001 From: dino Date: Wed, 17 Mar 2021 17:02:33 +0100 Subject: [PATCH] As David request --- platforms/nuttx/src/px4/stm/stm32h7/adc/adc.cpp | 7 +++++-- .../nuttx/src/px4/stm/stm32h7/include/px4_arch/micro_hal.h | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/platforms/nuttx/src/px4/stm/stm32h7/adc/adc.cpp b/platforms/nuttx/src/px4/stm/stm32h7/adc/adc.cpp index 5836b9f6102..f3379ee6dc7 100644 --- a/platforms/nuttx/src/px4/stm/stm32h7/adc/adc.cpp +++ b/platforms/nuttx/src/px4/stm/stm32h7/adc/adc.cpp @@ -116,6 +116,7 @@ # error "ADC STM32_PLL2P_FREQUENCY too high - no divisor found " #endif +#define ADC3_INTERNAL_TEMP_SENSOR_CHANNEL 18 //define to map the internal temperature channel. int px4_arch_adc_init(uint32_t base_address) { @@ -276,8 +277,10 @@ uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel) { irqstate_t flags = px4_enter_critical_section(); - if (channel > PX4_ADC_ADC3_CHANNEL_OFFSET) { - channel = channel - PX4_ADC_ADC3_CHANNEL_OFFSET; + /* Add a channel mapping for ADC3 on the H7 */ + + if (channel == PX4_ADC_INTERNAL_TEMP_SENSOR_CHANNEL) { + channel = ADC3_INTERNAL_TEMP_SENSOR_CHANNEL; base_address = STM32_ADC3_BASE; } diff --git a/platforms/nuttx/src/px4/stm/stm32h7/include/px4_arch/micro_hal.h b/platforms/nuttx/src/px4/stm/stm32h7/include/px4_arch/micro_hal.h index 84b3269cffa..7c73bf5f61f 100644 --- a/platforms/nuttx/src/px4/stm/stm32h7/include/px4_arch/micro_hal.h +++ b/platforms/nuttx/src/px4/stm/stm32h7/include/px4_arch/micro_hal.h @@ -62,8 +62,7 @@ int stm32h7_flash_lock(size_t addr); int stm32h7_flash_unlock(size_t addr); int stm32h7_flash_writeprotect(size_t block, bool enabled); #define stm32_flash_lock() stm32h7_flash_lock(PX4_FLASH_BASE) -#define PX4_ADC_ADC3_CHANNEL_OFFSET 7 #define PX4_ADC_ADC3_BASE STM32_ADC3_BASE -#define PX4_ADC_INTERNAL_TEMP_SENSOR_CHANNEL (18 + PX4_ADC_ADC3_CHANNEL_OFFSET) //Valid for ADC3 on H7x3 +#define PX4_ADC_INTERNAL_TEMP_SENSOR_CHANNEL (20) //Valid for ADC3 on H7x3 __END_DECLS