|
| 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 | +} |
0 commit comments