stm32: Add MCU temp for Stm32h7 (#5606)

Added mcu temperature to the stm32h7 processor.

Signed-off-by: Aaron DeLyser <bluwolf@gmail.com>
This commit is contained in:
adelyser 2022-06-27 08:16:09 -06:00 committed by GitHub
parent 045455648a
commit 84b2bfe313
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -72,6 +72,7 @@ class PrinterTemperatureMCU:
('stm32f070', self.config_stm32f070), ('stm32f070', self.config_stm32f070),
('stm32f072', self.config_stm32f0x2), ('stm32f072', self.config_stm32f0x2),
('stm32g0', self.config_stm32g0), ('stm32g0', self.config_stm32g0),
('stm32h7', self.config_stm32h7),
('', self.config_unknown)] ('', self.config_unknown)]
for name, func in cfg_funcs: for name, func in cfg_funcs:
if self.mcu_type.startswith(name): if self.mcu_type.startswith(name):
@ -143,6 +144,11 @@ class PrinterTemperatureMCU:
cal_adc_130 = self.read16(0x1FFF75CA) * 3.0 / (3.3 * 4095.) cal_adc_130 = self.read16(0x1FFF75CA) * 3.0 / (3.3 * 4095.)
self.slope = (130. - 30.) / (cal_adc_130 - cal_adc_30) self.slope = (130. - 30.) / (cal_adc_130 - cal_adc_30)
self.base_temperature = self.calc_base(30., cal_adc_30) self.base_temperature = self.calc_base(30., cal_adc_30)
def config_stm32h7(self):
cal_adc_30 = self.read16(0x1FF1E820) / 65535.
cal_adc_110 = self.read16(0x1FF1E840) / 65535.
self.slope = (110. - 30.) / (cal_adc_110 - cal_adc_30)
self.base_temperature = self.calc_base(30., cal_adc_30)
def read16(self, addr): def read16(self, addr):
params = self.debug_read_cmd.send([1, addr]) params = self.debug_read_cmd.send([1, addr])
return params['val'] return params['val']

View File

@ -22,6 +22,9 @@
#define ADC_ISR_LDORDY_Msk (0x1UL << ADC_ISR_LDORDY_Pos) #define ADC_ISR_LDORDY_Msk (0x1UL << ADC_ISR_LDORDY_Pos)
#define ADC_ISR_LDORDY ADC_ISR_LDORDY_Msk #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); DECL_CONSTANT("ADC_MAX", 4095);
// GPIOs like A0_C are not covered! // GPIOs like A0_C are not covered!
@ -88,7 +91,7 @@ static const uint8_t adc_pins[] = {
GPIO('H', 4), // ADC3_INP15 GPIO('H', 4), // ADC3_INP15
GPIO('H', 5), // ADC3_INP16 GPIO('H', 5), // ADC3_INP16
0, // Vbat/4 0, // Vbat/4
0, // VSENSE ADC_TEMPERATURE_PIN,// VSENSE
0, // VREFINT 0, // VREFINT
}; };
@ -185,7 +188,13 @@ gpio_adc_setup(uint32_t pin)
MODIFY_REG(adc->CFGR2, ADC_CFGR2_OVSS_Msk, MODIFY_REG(adc->CFGR2, ADC_CFGR2_OVSS_Msk,
OVERSAMPLES_EXPONENT << ADC_CFGR2_OVSS_Pos); OVERSAMPLES_EXPONENT << ADC_CFGR2_OVSS_Pos);
} }
if (pin == ADC_TEMPERATURE_PIN) {
ADC3_COMMON->CCR = ADC_CCR_TSEN;
} else {
gpio_peripheral(pin, GPIO_ANALOG, 0); gpio_peripheral(pin, GPIO_ANALOG, 0);
}
// Preselect (connect) channel // Preselect (connect) channel
adc->PCSEL |= (1 << chan); adc->PCSEL |= (1 << chan);
return (struct gpio_adc){ .adc = adc, .chan = chan }; return (struct gpio_adc){ .adc = adc, .chan = chan };