aboutsummaryrefslogtreecommitdiffstats
path: root/src/stm32/stm32h7_adc.c
diff options
context:
space:
mode:
authoradelyser <12093019+adelyser@users.noreply.github.com>2022-06-27 08:16:09 -0600
committerGitHub <noreply@github.com>2022-06-27 10:16:09 -0400
commit84b2bfe3135990983d55fd4d530139cf8ddb1f33 (patch)
treefbda9bc0f166ad0552a505af91c335ba9b213ad3 /src/stm32/stm32h7_adc.c
parent045455648a34a113e73ee9056466b5e5047a0f17 (diff)
downloadkutter-84b2bfe3135990983d55fd4d530139cf8ddb1f33.tar.gz
kutter-84b2bfe3135990983d55fd4d530139cf8ddb1f33.tar.xz
kutter-84b2bfe3135990983d55fd4d530139cf8ddb1f33.zip
stm32: Add MCU temp for Stm32h7 (#5606)
Added mcu temperature to the stm32h7 processor. Signed-off-by: Aaron DeLyser <bluwolf@gmail.com>
Diffstat (limited to 'src/stm32/stm32h7_adc.c')
-rw-r--r--src/stm32/stm32h7_adc.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/stm32/stm32h7_adc.c b/src/stm32/stm32h7_adc.c
index 2733b24f..ca149d3d 100644
--- a/src/stm32/stm32h7_adc.c
+++ b/src/stm32/stm32h7_adc.c
@@ -22,6 +22,9 @@
#define ADC_ISR_LDORDY_Msk (0x1UL << ADC_ISR_LDORDY_Pos)
#define ADC_ISR_LDORDY ADC_ISR_LDORDY_Msk
+#define ADC_TEMPERATURE_PIN 0xfe
+DECL_ENUMERATION("pin", "ADC_TEMPERATURE", ADC_TEMPERATURE_PIN);
+
DECL_CONSTANT("ADC_MAX", 4095);
// GPIOs like A0_C are not covered!
@@ -88,7 +91,7 @@ static const uint8_t adc_pins[] = {
GPIO('H', 4), // ADC3_INP15
GPIO('H', 5), // ADC3_INP16
0, // Vbat/4
- 0, // VSENSE
+ ADC_TEMPERATURE_PIN,// VSENSE
0, // VREFINT
};
@@ -185,7 +188,13 @@ gpio_adc_setup(uint32_t pin)
MODIFY_REG(adc->CFGR2, ADC_CFGR2_OVSS_Msk,
OVERSAMPLES_EXPONENT << ADC_CFGR2_OVSS_Pos);
}
- gpio_peripheral(pin, GPIO_ANALOG, 0);
+
+ if (pin == ADC_TEMPERATURE_PIN) {
+ ADC3_COMMON->CCR = ADC_CCR_TSEN;
+ } else {
+ gpio_peripheral(pin, GPIO_ANALOG, 0);
+ }
+
// Preselect (connect) channel
adc->PCSEL |= (1 << chan);
return (struct gpio_adc){ .adc = adc, .chan = chan };