Skip to content

Commit

Permalink
[examples] Add example for Nucleo F042K6 with vector table in ram
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-durand committed Nov 18, 2021
1 parent 3b01d63 commit 44dde66
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
55 changes: 55 additions & 0 deletions examples/nucleo_f042k6/vector_table_ram/main.cpp
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;
}
11 changes: 11 additions & 0 deletions examples/nucleo_f042k6/vector_table_ram/project.xml
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>

0 comments on commit 44dde66

Please sign in to comment.