Skip to content

Commit

Permalink
Add example blink-timer
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehaenger committed Jul 16, 2024
1 parent 20fd9d8 commit a429199
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
52 changes: 52 additions & 0 deletions examples/stm32c0x/blink-timer/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2024, Jörg Ebeling
*
* 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/platform.hpp>

#include "../custom-board.hpp"

using namespace Board;
using namespace std::chrono_literals;

MODM_ISR(TIM14)
{
Timer14::acknowledgeInterruptFlags(Timer14::InterruptFlag::Update);
LedGn::toggle();
}

MODM_ISR(TIM16)
{
Timer16::acknowledgeInterruptFlags(Timer16::InterruptFlag::Update);
LedRd::toggle();
}

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

Timer14::enable();
Timer14::setMode(Timer14::Mode::UpCounter);
Timer14::setPeriod<Board::SystemClock>(1000ms);
Timer14::applyAndReset();
Timer14::start();
Timer14::enableInterrupt(Timer14::Interrupt::Update);
Timer14::enableInterruptVector(true, 5);

Timer16::enable();
Timer16::setMode(Timer16::Mode::UpCounter);
Timer16::setPeriod<Board::SystemClock>(250ms);
Timer16::applyAndReset();
Timer16::start();
Timer16::enableInterrupt(Timer16::Interrupt::Update);
Timer16::enableInterruptVector(true, 5);

while (true) {}
}
20 changes: 20 additions & 0 deletions examples/stm32c0x/blink-timer/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<library>
<repositories>
<repository>
<path>../../../repo.lb</path>
</repository>
</repositories>
<options>
<option name="modm:target">stm32c011f6p6</option>
<option name="modm:build:build.path">../../../build/stm32c0x/blink-timer</option>
</options>
<modules>
<module>modm:platform:core</module>
<module>modm:platform:rcc</module>
<module>modm:platform:gpio</module>
<module>modm:platform:timer:14</module>
<module>modm:platform:timer:16</module>
<module>modm:architecture:clock</module>
<module>modm:build:scons</module>
</modules>
</library>
5 changes: 5 additions & 0 deletions examples/stm32c0x/custom-board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ struct SystemClock
static constexpr uint32_t Flash = Ahb;
static constexpr uint32_t Exti = Ahb;
static constexpr uint32_t Rcc = Ahb;
static constexpr uint32_t Timer1 = Apb;
static constexpr uint32_t Timer3 = Apb;
static constexpr uint32_t Timer14 = Apb;
static constexpr uint32_t Timer16 = Apb;
static constexpr uint32_t Timer17 = Apb;

static bool inline enable()
{
Expand Down

0 comments on commit a429199

Please sign in to comment.