Skip to content

Commit

Permalink
[examples] Add example for Nucleo L031K6 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 44dde66 commit fdbb45b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
54 changes: 54 additions & 0 deletions examples/nucleo_l031k6/vector_table_ram/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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 2 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:cortex-m:vector_table_location" in project.xml
// to place the vector table in ram.

static void tim2Handler()
{
Timer2::acknowledgeInterruptFlags(Timer2::InterruptFlag::Update);
LedD13::toggle();
}

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

// Set custom handler, only works if vector table is in RAM
NVIC_SetVector(TIM2_IRQn, reinterpret_cast<uintptr_t>(&tim2Handler));

Timer2::enable();
Timer2::setMode(Timer2::Mode::UpCounter);
Timer2::setPeriod<Board::SystemClock>(500'000 /* us */);
Timer2::applyAndReset();
Timer2::start();
Timer2::enableInterrupt(Timer2::Interrupt::Update);
Timer2::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_l031k6/vector_table_ram/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<library>
<extends>modm:nucleo-l031k6</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_l031k6/vector_table_ram</option>
<option name="modm:platform:cortex-m:vector_table_location">ram</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:platform:timer:2</module>
</modules>
</library>

0 comments on commit fdbb45b

Please sign in to comment.