Skip to content

Commit 028716a

Browse files
chris-durandsalkinium
authored andcommitted
[stm32] Fix ADC temperature sensor for F030 and F070 devices
1 parent 2055b53 commit 028716a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/modm/platform/adc/stm32f0/adc.hpp.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,16 @@ public:
316316
public:
317317
static constexpr uint8_t TS_CAL1_TEMP{30};
318318
%% if target.family in ["f0"]
319-
static constexpr uint8_t TS_CAL2_TEMP{110};
320319
static constexpr uint16_t VDDA_CAL{3300};
321320
static inline volatile uint16_t *const VREFINT_CAL{(volatile uint16_t *)0x1FFF'F7BA};
322321
static inline volatile uint16_t *const TS_CAL1{(volatile uint16_t *)0x1FFF'F7B8};
322+
%% if target.name in ["30", "70"]
323+
// defined in F030 reference manual
324+
static constexpr uint16_t TS_AVG_SLOPE{5336};
325+
%% else
326+
static constexpr uint8_t TS_CAL2_TEMP{110};
323327
static inline volatile uint16_t *const TS_CAL2{(volatile uint16_t *)0x1FFF'F7C2};
328+
%% endif
324329
%% else
325330
static constexpr uint8_t TS_CAL2_TEMP{130};
326331
static constexpr uint16_t VDDA_CAL{3000};

src/modm/platform/adc/stm32f0/adc_impl.hpp.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,13 @@ modm::platform::Adc{{ id }}::readTemperature(uint16_t Vref)
245245
// Sample time must be at least 5us!!!
246246
const int32_t TS_DATA = readChannel(Channel::Temperature);
247247

248+
%% if target.family == "f0" and target.name in ["30", "70"]
249+
const int32_t value = (int32_t(*TS_CAL1) - (TS_DATA * Vref / VDDA_CAL)) * 1000;
250+
return value / TS_AVG_SLOPE + TS_CAL1_TEMP;
251+
%% else
248252
const int32_t value = int32_t(TS_CAL2_TEMP - TS_CAL1_TEMP) * (TS_DATA * Vref / VDDA_CAL - *TS_CAL1);
249253
return value / (*TS_CAL2 - *TS_CAL1) + TS_CAL1_TEMP;
254+
%% endif
250255
}
251256

252257
uint16_t

0 commit comments

Comments
 (0)