Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stm32] Fix address of F0 temperature calibration values #526

Merged
merged 5 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/nucleo_f042k6/adc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ main()
MODM_LOG_INFO << "Vref=" << Vref << modm::endl;
MODM_LOG_INFO << "Temp=" << Temp << modm::endl;

MODM_LOG_INFO << "TS_CAL1=" << uint16_t(*((volatile uint16_t *)0x1FFF77B8)) << modm::endl;
MODM_LOG_INFO << "TS_CAL2=" << uint16_t(*((volatile uint16_t *)0x1FFF77C2)) << modm::endl;
MODM_LOG_INFO << "VREFINT_CAL=" << uint16_t(*((volatile uint16_t *)0x1FFFF7BA)) << modm::endl;
MODM_LOG_INFO << "TS_CAL1=" << *Adc::TS_CAL1 << modm::endl;
MODM_LOG_INFO << "TS_CAL2=" << *Adc::TS_CAL2 << modm::endl;
MODM_LOG_INFO << "VREFINT_CAL=" << *Adc::VREFINT_CAL << modm::endl;

Adc::setPinChannel<AdcIn1>();
Adc::setResolution(Adc::Resolution::Bits12);
Expand Down
30 changes: 30 additions & 0 deletions examples/stm32f030f4p6_demo_board/adc/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2020, Niklas Hauser
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <modm/board.hpp>

using namespace Board;

int
main()
{
Board::initialize();

Adc::initialize<Board::SystemClock, Adc::ClockMode::Synchronous, 12_MHz>();
const uint16_t Vref = Adc::readInternalVoltageReference();

while (true)
{
int16_t Temp = Adc::readTemperature(Vref);
LedOrange::set(Temp > 30);
modm::delay(1s);
}

return 0;
}
2 changes: 2 additions & 0 deletions examples/stm32f030f4p6_demo_board/adc/openocd.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Replace this with your custom programmer
source [find interface/stlink-v2.cfg]
11 changes: 11 additions & 0 deletions examples/stm32f030f4p6_demo_board/adc/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<library>
<extends>modm:stm32f030_demo</extends>
<options>
<option name="modm:build:build.path">../../../build/stm32f030f4p6_demo/adc</option>
<option name="modm:build:openocd.cfg">openocd.cfg</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:platform:adc</module>
</modules>
</library>
2 changes: 1 addition & 1 deletion src/modm/board/stm32f030f4p6_demo/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct SystemClock {
};

// User LED
using LedOrange = GpioOutputA4;
using LedOrange = GpioInverted< GpioOutputA4 >;
using Leds = SoftwareGpioPort< LedOrange >;

using Button = GpioUnused;
Expand Down
13 changes: 9 additions & 4 deletions 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 *)0x1FFFF7BA};
static inline volatile uint16_t *const TS_CAL1{(volatile uint16_t *)0x1FFF77B8};
static inline volatile uint16_t *const TS_CAL2{(volatile uint16_t *)0x1FFF77C2};
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 in ["30", "70"]
// defined in F030 reference manual
static constexpr uint16_t TS_AVG_SLOPE{5336};
%% else
static constexpr uint8_t TS_CAL2_TEMP{110};
static inline volatile uint16_t *const TS_CAL2{(volatile uint16_t *)0x1FFF'F7C2};
%% 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" and target.name in ["30", "70"]
const int32_t value = (int32_t(*TS_CAL1) - (TS_DATA * Vref / VDDA_CAL)) * 1000;
return value / TS_AVG_SLOPE + TS_CAL1_TEMP;
%% else
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;
%% endif
chris-durand marked this conversation as resolved.
Show resolved Hide resolved
}

uint16_t
Expand Down