From 8e961f9eb66f23e4c762b0e2bb5736b67143c4b8 Mon Sep 17 00:00:00 2001 From: bugobliterator Date: Tue, 25 Apr 2023 13:01:42 +1000 Subject: [PATCH 1/2] AP_HAL_ChibiOS: add support for MCU monitoring on H750 based boards --- libraries/AP_HAL_ChibiOS/AnalogIn.cpp | 12 +++++++++--- .../AP_HAL_ChibiOS/hwdef/scripts/STM32H750xx.py | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/AnalogIn.cpp b/libraries/AP_HAL_ChibiOS/AnalogIn.cpp index bb1b31e2d52d6..f9e0c425d6172 100644 --- a/libraries/AP_HAL_ChibiOS/AnalogIn.cpp +++ b/libraries/AP_HAL_ChibiOS/AnalogIn.cpp @@ -80,9 +80,15 @@ const AnalogIn::pin_info AnalogIn::pin_config[] = { HAL_ANALOG_PINS }; #if defined(HAL_ANALOG3_PINS) || HAL_WITH_MCU_MONITORING #if HAL_WITH_MCU_MONITORING // internal ADC channels (from H7 reference manual) - #define ADC3_VSENSE_CHAN 18 - #define ADC3_VREFINT_CHAN 19 - #define ADC3_VBAT4_CHAN 17 + #ifndef ADC3_VSENSE_CHAN + #define ADC3_VSENSE_CHAN 18 + #endif + #ifndef ADC3_VREFINT_CHAN + #define ADC3_VREFINT_CHAN 19 + #endif + #ifndef ADC3_VBAT4_CHAN + #define ADC3_VBAT4_CHAN 17 + #endif #define HAL_MCU_MONITORING_PINS {ADC3_VBAT4_CHAN, 252, 3.30/4096}, {ADC3_VSENSE_CHAN, 253, 3.30/4096}, {ADC3_VREFINT_CHAN, 254, 3.30/4096} #else #define HAL_MCU_MONITORING_PINS diff --git a/libraries/AP_HAL_ChibiOS/hwdef/scripts/STM32H750xx.py b/libraries/AP_HAL_ChibiOS/hwdef/scripts/STM32H750xx.py index 5ea12627080ea..df482604224a3 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/scripts/STM32H750xx.py +++ b/libraries/AP_HAL_ChibiOS/hwdef/scripts/STM32H750xx.py @@ -76,6 +76,10 @@ 'DEFINES' : { 'HAL_HAVE_HARDWARE_DOUBLE' : '1', + 'HAL_WITH_MCU_MONITORING' : '1', + 'ADC3_VSENSE_CHAN' : 17, + 'ADC3_VREFINT_CHAN' : 18, + 'ADC3_VBAT4_CHAN' : 16, 'STM32H7' : '1', }, From d4aaef41e2aa0c0a531c65a6c6abb4e00eef9a41 Mon Sep 17 00:00:00 2001 From: Andy Piper Date: Tue, 16 May 2023 16:36:13 +0100 Subject: [PATCH 2/2] AP_HAL_ChibiOS: use ADC3 on STM32H730 and STM32H750 --- libraries/AP_HAL_ChibiOS/hwdef/common/stm32h7_type2_mcuconf.h | 3 +++ libraries/AP_HAL_ChibiOS/hwdef/scripts/STM32H730xx.py | 4 ++++ libraries/AP_HAL_ChibiOS/hwdef/scripts/STM32H750xx.py | 3 --- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/stm32h7_type2_mcuconf.h b/libraries/AP_HAL_ChibiOS/hwdef/common/stm32h7_type2_mcuconf.h index 197b3bcb5b72e..783c8e13bcfff 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/common/stm32h7_type2_mcuconf.h +++ b/libraries/AP_HAL_ChibiOS/hwdef/common/stm32h7_type2_mcuconf.h @@ -328,6 +328,9 @@ #ifndef STM32_ADC_SAMPLES_SIZE #define STM32_ADC_SAMPLES_SIZE 16 #endif +#ifndef STM32_ADC_USE_ADC3 +#define STM32_ADC_USE_ADC3 TRUE +#endif #define STM32_ADC_COMPACT_SAMPLES FALSE #define STM32_ADC_USE_ADC12 TRUE #define STM32_ADC_ADC12_DMA_PRIORITY 2 diff --git a/libraries/AP_HAL_ChibiOS/hwdef/scripts/STM32H730xx.py b/libraries/AP_HAL_ChibiOS/hwdef/scripts/STM32H730xx.py index 9ef0393b84e44..ff91d24acc634 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/scripts/STM32H730xx.py +++ b/libraries/AP_HAL_ChibiOS/hwdef/scripts/STM32H730xx.py @@ -81,6 +81,10 @@ 'DEFINES' : { 'HAL_HAVE_HARDWARE_DOUBLE' : '1', + 'HAL_WITH_MCU_MONITORING' : '1', + 'ADC3_VSENSE_CHAN' : 17, + 'ADC3_VREFINT_CHAN' : 18, + 'ADC3_VBAT4_CHAN' : 16, 'STM32H7' : '1', }, diff --git a/libraries/AP_HAL_ChibiOS/hwdef/scripts/STM32H750xx.py b/libraries/AP_HAL_ChibiOS/hwdef/scripts/STM32H750xx.py index df482604224a3..8248e6e1d7721 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/scripts/STM32H750xx.py +++ b/libraries/AP_HAL_ChibiOS/hwdef/scripts/STM32H750xx.py @@ -77,9 +77,6 @@ 'DEFINES' : { 'HAL_HAVE_HARDWARE_DOUBLE' : '1', 'HAL_WITH_MCU_MONITORING' : '1', - 'ADC3_VSENSE_CHAN' : 17, - 'ADC3_VREFINT_CHAN' : 18, - 'ADC3_VBAT4_CHAN' : 16, 'STM32H7' : '1', },