From 6d04a67b02b18744b4f15c2129fd921e66d7fb88 Mon Sep 17 00:00:00 2001 From: dino Date: Wed, 10 Mar 2021 10:35:46 +0100 Subject: [PATCH] Moving define to microhal.h files, for each ST architecture. Correct channels were verified with ST_CUBE header files. For the H7 its a simplification for the current used H7x3. Other devices in that family expect the temperarture on channel 18. F1: channel 16 F3: channel 16 F4: channel 18 F7: channel 18 H7: channel 17, on STMf32Hx3 --- boards/px4/fmu-v5/src/board_config.h | 2 -- boards/px4/fmu-v5x/src/board_config.h | 2 -- platforms/nuttx/src/px4/stm/stm32_common/adc/adc.cpp | 8 +++----- .../src/px4/stm/stm32f1/include/px4_arch/micro_hal.h | 1 + .../src/px4/stm/stm32f3/include/px4_arch/micro_hal.h | 1 + .../src/px4/stm/stm32f4/include/px4_arch/micro_hal.h | 2 +- .../src/px4/stm/stm32f7/include/px4_arch/micro_hal.h | 2 ++ platforms/nuttx/src/px4/stm/stm32h7/adc/adc.cpp | 2 +- .../src/px4/stm/stm32h7/include/px4_arch/micro_hal.h | 1 + 9 files changed, 10 insertions(+), 11 deletions(-) diff --git a/boards/px4/fmu-v5/src/board_config.h b/boards/px4/fmu-v5/src/board_config.h index 4706402070..6cfdf8fa60 100644 --- a/boards/px4/fmu-v5/src/board_config.h +++ b/boards/px4/fmu-v5/src/board_config.h @@ -137,8 +137,6 @@ #define ADC_HW_REV_SENSE_CHANNEL /* PC3 */ ADC1_CH(13) #define ADC1_SPARE_1_CHANNEL /* PC4 */ ADC1_CH(14) -#define ADC_INTERNAL_TEMP_SENSOR_CHANNEL (18) /* No Gpio assigned, internal channel*/ - #if BOARD_HAS_NBAT_V == 2 && BOARD_HAS_NBAT_I == 2 #define ADC_CHANNELS \ ((1 << ADC_BATTERY1_VOLTAGE_CHANNEL) | \ diff --git a/boards/px4/fmu-v5x/src/board_config.h b/boards/px4/fmu-v5x/src/board_config.h index cf956131ae..64bcd8e4fb 100644 --- a/boards/px4/fmu-v5x/src/board_config.h +++ b/boards/px4/fmu-v5x/src/board_config.h @@ -156,8 +156,6 @@ #define ADC_HW_VER_SENSE_CHANNEL /* PF4 */ ADC3_CH(14) #define ADC_HW_REV_SENSE_CHANNEL /* PF5 */ ADC3_CH(15) -#define ADC_INTERNAL_TEMP_SENSOR_CHANNEL (18) /* No Gpio assigned, internal channel*/ - #define ADC_CHANNELS \ ((1 << ADC_SCALED_VDD_3V3_SENSORS1_CHANNEL) | \ (1 << ADC_SCALED_VDD_3V3_SENSORS2_CHANNEL) | \ diff --git a/platforms/nuttx/src/px4/stm/stm32_common/adc/adc.cpp b/platforms/nuttx/src/px4/stm/stm32_common/adc/adc.cpp index 78f541871a..e0d4fda808 100644 --- a/platforms/nuttx/src/px4/stm/stm32_common/adc/adc.cpp +++ b/platforms/nuttx/src/px4/stm/stm32_common/adc/adc.cpp @@ -235,11 +235,9 @@ float px4_arch_adc_reference_v() uint32_t px4_arch_adc_temp_sensor_mask() { -#ifdef ADC_INTERNAL_TEMP_SENSOR_CHANNEL - return 1 << ADC_INTERNAL_TEMP_SENSOR_CHANNEL; -#else - return 1 << 16; -#endif + + return 1 << PX4_ADC_INTERNAL_TEMP_SENSOR_CHANNEL; + } uint32_t px4_arch_adc_dn_fullcount() diff --git a/platforms/nuttx/src/px4/stm/stm32f1/include/px4_arch/micro_hal.h b/platforms/nuttx/src/px4/stm/stm32f1/include/px4_arch/micro_hal.h index 8422adc558..0132c1cd23 100644 --- a/platforms/nuttx/src/px4/stm/stm32f1/include/px4_arch/micro_hal.h +++ b/platforms/nuttx/src/px4/stm/stm32f1/include/px4_arch/micro_hal.h @@ -46,5 +46,6 @@ __BEGIN_DECLS # define PX4_BBSRAM_GETDESC_IOCTL STM32_BBSRAM_GETDESC_IOCTL #endif #define PX4_NUMBER_I2C_BUSES STM32_NI2C +#define APX4_ADC_INTERNAL_TEMP_SENSOR_CHANNEL 16 __END_DECLS diff --git a/platforms/nuttx/src/px4/stm/stm32f3/include/px4_arch/micro_hal.h b/platforms/nuttx/src/px4/stm/stm32f3/include/px4_arch/micro_hal.h index 2c06c7641c..6347607bcb 100644 --- a/platforms/nuttx/src/px4/stm/stm32f3/include/px4_arch/micro_hal.h +++ b/platforms/nuttx/src/px4/stm/stm32f3/include/px4_arch/micro_hal.h @@ -46,6 +46,7 @@ __BEGIN_DECLS # define PX4_BBSRAM_GETDESC_IOCTL STM32_BBSRAM_GETDESC_IOCTL #endif #define PX4_NUMBER_I2C_BUSES STM32_NI2C +#define APX4_ADC_INTERNAL_TEMP_SENSOR_CHANNEL 16 __END_DECLS diff --git a/platforms/nuttx/src/px4/stm/stm32f4/include/px4_arch/micro_hal.h b/platforms/nuttx/src/px4/stm/stm32f4/include/px4_arch/micro_hal.h index 2c06c7641c..edf02df263 100644 --- a/platforms/nuttx/src/px4/stm/stm32f4/include/px4_arch/micro_hal.h +++ b/platforms/nuttx/src/px4/stm/stm32f4/include/px4_arch/micro_hal.h @@ -46,6 +46,6 @@ __BEGIN_DECLS # define PX4_BBSRAM_GETDESC_IOCTL STM32_BBSRAM_GETDESC_IOCTL #endif #define PX4_NUMBER_I2C_BUSES STM32_NI2C - +#define PX4_ADC_INTERNAL_TEMP_SENSOR_CHANNEL 18 __END_DECLS diff --git a/platforms/nuttx/src/px4/stm/stm32f7/include/px4_arch/micro_hal.h b/platforms/nuttx/src/px4/stm/stm32f7/include/px4_arch/micro_hal.h index 0dc0c6e1a5..4652afe349 100644 --- a/platforms/nuttx/src/px4/stm/stm32f7/include/px4_arch/micro_hal.h +++ b/platforms/nuttx/src/px4/stm/stm32f7/include/px4_arch/micro_hal.h @@ -46,6 +46,8 @@ __BEGIN_DECLS #define PX4_BBSRAM_GETDESC_IOCTL STM32F7_BBSRAM_GETDESC_IOCTL #define PX4_FLASH_BASE 0x08000000 #define PX4_NUMBER_I2C_BUSES STM32F7_NI2C +#define PX4_ADC_INTERNAL_TEMP_SENSOR_CHANNEL 18 + int stm32_flash_lock(void); int stm32_flash_unlock(void); diff --git a/platforms/nuttx/src/px4/stm/stm32h7/adc/adc.cpp b/platforms/nuttx/src/px4/stm/stm32h7/adc/adc.cpp index d1b8258c1a..a3f8673f2d 100644 --- a/platforms/nuttx/src/px4/stm/stm32h7/adc/adc.cpp +++ b/platforms/nuttx/src/px4/stm/stm32h7/adc/adc.cpp @@ -315,7 +315,7 @@ float px4_arch_adc_reference_v() uint32_t px4_arch_adc_temp_sensor_mask() { - return 1 << 16; + return 1 << APX4_ADC_INTERNAL_TEMP_SENSOR_CHANNEL; } uint32_t px4_arch_adc_dn_fullcount() 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 ac301667a4..09d92029fd 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,5 +62,6 @@ 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 APX4_ADC_INTERNAL_TEMP_SENSOR_CHANNEL 17 //Valid for ADC3 on H7x3 __END_DECLS