From df843b044dcb6b1c992edca3a0b117d071b8ae28 Mon Sep 17 00:00:00 2001 From: Tomasz Wasilczyk Date: Mon, 13 Sep 2021 12:02:27 -0700 Subject: [PATCH] Blinky example for SAMV --- examples/samv/blink/main.cpp | 63 +++++++++++++++++++++++++++++++++ examples/samv/blink/openocd.cfg | 9 +++++ examples/samv/blink/project.xml | 15 ++++++++ 3 files changed, 87 insertions(+) create mode 100644 examples/samv/blink/main.cpp create mode 100644 examples/samv/blink/openocd.cfg create mode 100644 examples/samv/blink/project.xml diff --git a/examples/samv/blink/main.cpp b/examples/samv/blink/main.cpp new file mode 100644 index 0000000000..d1c824f872 --- /dev/null +++ b/examples/samv/blink/main.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2021, Tomasz Wasilczyk + * + * 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 +#include + +using namespace std::chrono_literals; +using namespace modm::platform; + +struct SystemClock +{ + // Chosen to achieve 300MHz system clock + static constexpr uint32_t PllAMult = 25; + static constexpr uint32_t Frequency = 300'000'000; // TODO: PllAMult * 12'000'000 (OSC12M); + + static bool inline + enable() + { + ClockGen::setFlashLatency(); // TODO: what is this for? + ClockGen::updateCoreFrequency(); + + ClockGen::enableMainInternal(); + ClockGen::selectMainClockSource(); + ClockGen::enablePllA(); + ClockGen::selectMasterClk(); + + return true; + } +}; + +int +main() +{ + WDT->WDT_MR = (WDT_MR_WDDIS_Msk); // turn off Watchdog + SystemClock::enable(); + SysTickTimer::initialize(); + + using Led0 = modm::platform::GpioD17; + using Led1 = modm::platform::GpioD16; + using Led2 = modm::platform::GpioD15; + using DispDC = modm::platform::GpioD26; + + Led0::setOutput(false); + Led1::setOutput(true); + Led2::setOutput(false); + DispDC::setOutput(false); + + while (1) + { + Led0::toggle(); + DispDC::toggle(); + modm::delay(500ms); + } + + return 0; +} diff --git a/examples/samv/blink/openocd.cfg b/examples/samv/blink/openocd.cfg new file mode 100644 index 0000000000..a9b9337d7b --- /dev/null +++ b/examples/samv/blink/openocd.cfg @@ -0,0 +1,9 @@ +source [find interface/jlink.cfg] +transport select swd + +source [find target/atsamv.cfg] + +# Set boot mode selection to Flash (instead of SAM-BA on ROM) +init +halt +atsamv gpnvm set 1 diff --git a/examples/samv/blink/project.xml b/examples/samv/blink/project.xml new file mode 100644 index 0000000000..471cfbc581 --- /dev/null +++ b/examples/samv/blink/project.xml @@ -0,0 +1,15 @@ + + + + + + + + modm:build:scons + modm:platform:core + modm:platform:clock + modm:platform:gpio + modm:architecture:delay + modm:platform:clockgen + +