-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[examples] Add example for Nucleo F042K6 with vector table in ram
- Loading branch information
1 parent
3b01d63
commit 44dde66
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2021, Christopher Durand | ||
* | ||
* 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; | ||
|
||
// Blink LED with timer 14 interrupt. A custom handler is configured at runtime | ||
// in the vector table located in SRAM. | ||
|
||
// If the LED is blinking with a period of 1 second, the vector table has been | ||
// successfully relocated to ram. | ||
// Set the option "modm:platform:core:vector_table_location" in project.xml | ||
// to place the vector table in ram on F0 devices without vector table relocation | ||
// support in the Cortex M0 core. | ||
|
||
static void tim14Handler() | ||
{ | ||
Timer14::acknowledgeInterruptFlags(Timer14::InterruptFlag::Update); | ||
LedD13::toggle(); | ||
} | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
LedD13::setOutput(); | ||
|
||
// Set custom handler, only works if vector table is in RAM | ||
NVIC_SetVector(TIM14_IRQn, reinterpret_cast<uintptr_t>(&tim14Handler)); | ||
|
||
Timer14::enable(); | ||
Timer14::setMode(Timer14::Mode::UpCounter); | ||
Timer14::setPeriod<Board::SystemClock>(500'000 /* us */); | ||
Timer14::applyAndReset(); | ||
Timer14::start(); | ||
Timer14::enableInterrupt(Timer14::Interrupt::Update); | ||
Timer14::enableInterruptVector(true, 5); | ||
|
||
uint32_t counter{0}; | ||
while (true) | ||
{ | ||
modm::delay(100ms); | ||
MODM_LOG_INFO << "loop: " << counter++ << modm::endl; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<library> | ||
<extends>modm:nucleo-f042k6</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/nucleo_f042k6/vector_table_ram</option> | ||
<option name="modm:platform:core:vector_table_location">ram</option> | ||
</options> | ||
<modules> | ||
<module>modm:build:scons</module> | ||
<module>modm:platform:timer:14</module> | ||
</modules> | ||
</library> |