Skip to content

Commit 44dde66

Browse files
committed
[examples] Add example for Nucleo F042K6 with vector table in ram
1 parent 3b01d63 commit 44dde66

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2021, Christopher Durand
3+
*
4+
* This file is part of the modm project.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#include <modm/board.hpp>
12+
13+
using namespace Board;
14+
15+
// Blink LED with timer 14 interrupt. A custom handler is configured at runtime
16+
// in the vector table located in SRAM.
17+
18+
// If the LED is blinking with a period of 1 second, the vector table has been
19+
// successfully relocated to ram.
20+
// Set the option "modm:platform:core:vector_table_location" in project.xml
21+
// to place the vector table in ram on F0 devices without vector table relocation
22+
// support in the Cortex M0 core.
23+
24+
static void tim14Handler()
25+
{
26+
Timer14::acknowledgeInterruptFlags(Timer14::InterruptFlag::Update);
27+
LedD13::toggle();
28+
}
29+
30+
int
31+
main()
32+
{
33+
Board::initialize();
34+
LedD13::setOutput();
35+
36+
// Set custom handler, only works if vector table is in RAM
37+
NVIC_SetVector(TIM14_IRQn, reinterpret_cast<uintptr_t>(&tim14Handler));
38+
39+
Timer14::enable();
40+
Timer14::setMode(Timer14::Mode::UpCounter);
41+
Timer14::setPeriod<Board::SystemClock>(500'000 /* us */);
42+
Timer14::applyAndReset();
43+
Timer14::start();
44+
Timer14::enableInterrupt(Timer14::Interrupt::Update);
45+
Timer14::enableInterruptVector(true, 5);
46+
47+
uint32_t counter{0};
48+
while (true)
49+
{
50+
modm::delay(100ms);
51+
MODM_LOG_INFO << "loop: " << counter++ << modm::endl;
52+
}
53+
54+
return 0;
55+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<library>
2+
<extends>modm:nucleo-f042k6</extends>
3+
<options>
4+
<option name="modm:build:build.path">../../../build/nucleo_f042k6/vector_table_ram</option>
5+
<option name="modm:platform:core:vector_table_location">ram</option>
6+
</options>
7+
<modules>
8+
<module>modm:build:scons</module>
9+
<module>modm:platform:timer:14</module>
10+
</modules>
11+
</library>

0 commit comments

Comments
 (0)