Skip to content

Commit

Permalink
[stm32] Fix ADC temperature sensor for F030 and F70 devices
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-durand committed Jan 13, 2021
1 parent ef58e46 commit ac1d2b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/modm/platform/adc/stm32f0/adc.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,16 @@ public:
public:
static constexpr uint8_t TS_CAL1_TEMP{30};
%% if target.family in ["f0"]
static constexpr uint8_t TS_CAL2_TEMP{110};
static constexpr uint16_t VDDA_CAL{3300};
static inline volatile uint16_t *const VREFINT_CAL{(volatile uint16_t *)0x1FFF'F7BA};
static inline volatile uint16_t *const TS_CAL1{(volatile uint16_t *)0x1FFF'F7B8};
%% if target.name not in ["30", "70"]
static constexpr uint8_t TS_CAL2_TEMP{110};
static inline volatile uint16_t *const TS_CAL2{(volatile uint16_t *)0x1FFF'F7C2};
%% else
// defined in F030 reference manual
static constexpr uint16_t TS_AVG_SLOPE{5336};
%% endif
%% else
static constexpr uint8_t TS_CAL2_TEMP{130};
static constexpr uint16_t VDDA_CAL{3000};
Expand Down
5 changes: 5 additions & 0 deletions src/modm/platform/adc/stm32f0/adc_impl.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,13 @@ modm::platform::Adc{{ id }}::readTemperature(uint16_t Vref)
// Sample time must be at least 5us!!!
const int32_t TS_DATA = readChannel(Channel::Temperature);

%% if target.family != "f0" or target.name not in ["30", "70"]
const int32_t value = int32_t(TS_CAL2_TEMP - TS_CAL1_TEMP) * (TS_DATA * Vref / VDDA_CAL - *TS_CAL1);
return value / (*TS_CAL2 - *TS_CAL1) + TS_CAL1_TEMP;
%% else
const int32_t value = (int32_t(*TS_CAL1) + (TS_DATA * Vref / VDDA_CAL)) * 1000;
return value / TS_AVG_SLOPE + TS_CAL1_TEMP;
%% endif
}

uint16_t
Expand Down

0 comments on commit ac1d2b0

Please sign in to comment.