Skip to content

Commit fdbb45b

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

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 2 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:cortex-m:vector_table_location" in project.xml
21+
// to place the vector table in ram.
22+
23+
static void tim2Handler()
24+
{
25+
Timer2::acknowledgeInterruptFlags(Timer2::InterruptFlag::Update);
26+
LedD13::toggle();
27+
}
28+
29+
int
30+
main()
31+
{
32+
Board::initialize();
33+
LedD13::setOutput();
34+
35+
// Set custom handler, only works if vector table is in RAM
36+
NVIC_SetVector(TIM2_IRQn, reinterpret_cast<uintptr_t>(&tim2Handler));
37+
38+
Timer2::enable();
39+
Timer2::setMode(Timer2::Mode::UpCounter);
40+
Timer2::setPeriod<Board::SystemClock>(500'000 /* us */);
41+
Timer2::applyAndReset();
42+
Timer2::start();
43+
Timer2::enableInterrupt(Timer2::Interrupt::Update);
44+
Timer2::enableInterruptVector(true, 5);
45+
46+
uint32_t counter{0};
47+
while (true)
48+
{
49+
modm::delay(100ms);
50+
MODM_LOG_INFO << "loop: " << counter++ << modm::endl;
51+
}
52+
53+
return 0;
54+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<library>
2+
<extends>modm:nucleo-l031k6</extends>
3+
<options>
4+
<option name="modm:build:build.path">../../../build/nucleo_l031k6/vector_table_ram</option>
5+
<option name="modm:platform:cortex-m:vector_table_location">ram</option>
6+
</options>
7+
<modules>
8+
<module>modm:build:scons</module>
9+
<module>modm:platform:timer:2</module>
10+
</modules>
11+
</library>

0 commit comments

Comments
 (0)