mirror of https://github.com/Desuuuu/klipper.git
stm32: Support reading chip based temperature sensor on stm32f1/2/4
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
d9b7891133
commit
d985b53ccb
|
@ -1,6 +1,6 @@
|
||||||
// ADC functions on STM32
|
// ADC functions on STM32
|
||||||
//
|
//
|
||||||
// Copyright (C) 2019 Kevin O'Connor <kevin@koconnor.net>
|
// Copyright (C) 2019-2020 Kevin O'Connor <kevin@koconnor.net>
|
||||||
//
|
//
|
||||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
|
|
||||||
|
@ -15,11 +15,23 @@
|
||||||
|
|
||||||
DECL_CONSTANT("ADC_MAX", 4095);
|
DECL_CONSTANT("ADC_MAX", 4095);
|
||||||
|
|
||||||
|
#define ADC_TEMPERATURE_PIN 0xfe
|
||||||
|
DECL_ENUMERATION("pin", "ADC_TEMPERATURE", ADC_TEMPERATURE_PIN);
|
||||||
|
|
||||||
static const uint8_t adc_pins[] = {
|
static const uint8_t adc_pins[] = {
|
||||||
GPIO('A', 0), GPIO('A', 1), GPIO('A', 2), GPIO('A', 3),
|
GPIO('A', 0), GPIO('A', 1), GPIO('A', 2), GPIO('A', 3),
|
||||||
GPIO('A', 4), GPIO('A', 5), GPIO('A', 6), GPIO('A', 7),
|
GPIO('A', 4), GPIO('A', 5), GPIO('A', 6), GPIO('A', 7),
|
||||||
GPIO('B', 0), GPIO('B', 1), GPIO('C', 0), GPIO('C', 1),
|
GPIO('B', 0), GPIO('B', 1), GPIO('C', 0), GPIO('C', 1),
|
||||||
GPIO('C', 2), GPIO('C', 3), GPIO('C', 4), GPIO('C', 5),
|
GPIO('C', 2), GPIO('C', 3), GPIO('C', 4), GPIO('C', 5),
|
||||||
|
|
||||||
|
#if CONFIG_MACH_STM32F1
|
||||||
|
ADC_TEMPERATURE_PIN,
|
||||||
|
#elif CONFIG_MACH_STM32F2 || CONFIG_MACH_STM32F407
|
||||||
|
ADC_TEMPERATURE_PIN, 0x00, 0x00,
|
||||||
|
#elif CONFIG_MACH_STM32F446
|
||||||
|
0x00, 0x00, ADC_TEMPERATURE_PIN,
|
||||||
|
#endif
|
||||||
|
|
||||||
#if CONFIG_MACH_STM32F4
|
#if CONFIG_MACH_STM32F4
|
||||||
0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00,
|
||||||
GPIO('F', 6), GPIO('F', 7), GPIO('F', 8), GPIO('F', 9),
|
GPIO('F', 6), GPIO('F', 7), GPIO('F', 8), GPIO('F', 9),
|
||||||
|
@ -29,7 +41,8 @@ static const uint8_t adc_pins[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
#if CONFIG_MACH_STM32F1
|
#if CONFIG_MACH_STM32F1
|
||||||
#define CR2_FLAGS (ADC_CR2_ADON | (7 << ADC_CR2_EXTSEL_Pos) | ADC_CR2_EXTTRIG)
|
#define CR2_FLAGS (ADC_CR2_ADON | (7 << ADC_CR2_EXTSEL_Pos) | ADC_CR2_EXTTRIG \
|
||||||
|
| ADC_CR2_TSVREFE)
|
||||||
#else
|
#else
|
||||||
#define CR2_FLAGS ADC_CR2_ADON
|
#define CR2_FLAGS ADC_CR2_ADON
|
||||||
#endif
|
#endif
|
||||||
|
@ -71,11 +84,11 @@ gpio_adc_setup(uint32_t pin)
|
||||||
ADC_TypeDef *adc = ADC1;
|
ADC_TypeDef *adc = ADC1;
|
||||||
uint32_t adc_base = ADC1_BASE;
|
uint32_t adc_base = ADC1_BASE;
|
||||||
#if CONFIG_MACH_STM32F4
|
#if CONFIG_MACH_STM32F4
|
||||||
if (chan >= 16) {
|
if (chan >= 19) {
|
||||||
// On the STM32F4, some ADC channels are only available from ADC3
|
// On the STM32F4, some ADC channels are only available from ADC3
|
||||||
adc = ADC3;
|
adc = ADC3;
|
||||||
adc_base += 0x800;
|
adc_base += 0x800;
|
||||||
chan -= 16;
|
chan -= 19;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -94,7 +107,13 @@ gpio_adc_setup(uint32_t pin)
|
||||||
adc->CR2 = CR2_FLAGS;
|
adc->CR2 = CR2_FLAGS;
|
||||||
}
|
}
|
||||||
|
|
||||||
gpio_peripheral(pin, GPIO_ANALOG, 0);
|
if (pin == ADC_TEMPERATURE_PIN) {
|
||||||
|
#if !CONFIG_MACH_STM32F1
|
||||||
|
ADC123_COMMON->CCR = ADC_CCR_TSVREFE;
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
gpio_peripheral(pin, GPIO_ANALOG, 0);
|
||||||
|
}
|
||||||
|
|
||||||
return (struct gpio_adc){ .adc = adc, .chan = chan };
|
return (struct gpio_adc){ .adc = adc, .chan = chan };
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue