Skip to content

Commit 9036666

Browse files
twasilczyksalkinium
authored andcommitted
Blinky example for SAMV
1 parent 94a3a72 commit 9036666

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

examples/samv/blink/main.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2021, Tomasz Wasilczyk
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/architecture/interface/clock.hpp>
12+
#include <modm/platform.hpp>
13+
14+
using namespace std::chrono_literals;
15+
using namespace modm::platform;
16+
17+
struct SystemClock
18+
{
19+
// Chosen to achieve 300MHz system clock
20+
static constexpr uint32_t PllAMult = 25;
21+
static constexpr uint32_t Frequency = 300'000'000; // PllAMult * Osc 12MHz
22+
23+
static bool inline
24+
enable()
25+
{
26+
ClockGen::setFlashLatency<Frequency / 2>(); // Flash runs off MCK
27+
28+
ClockGen::enableMainInternal(MainInternalFreq::Rc12Mhz);
29+
ClockGen::selectMainClockSource(MainClockSource::Internal);
30+
ClockGen::enablePllA<PllAMult>();
31+
ClockGen::selectMasterClk<MasterClkSource::PLLA_CLK, MasterClkPrescaler::CLK_1, MasterClkDivider::Div2>();
32+
ClockGen::updateCoreFrequency<Frequency>();
33+
34+
return true;
35+
}
36+
};
37+
38+
using Led0 = GpioD17;
39+
using Led1 = GpioD16;
40+
using Led2 = GpioD15;
41+
42+
int
43+
main()
44+
{
45+
WDT->WDT_MR = (WDT_MR_WDDIS_Msk); // turn off Watchdog
46+
47+
SystemClock::enable();
48+
SysTickTimer::initialize<SystemClock>();
49+
50+
Led0::setOutput(false);
51+
Led1::setOutput(true);
52+
Led2::setOutput(false);
53+
54+
while (1)
55+
{
56+
Led0::toggle();
57+
modm::delay(500ms);
58+
}
59+
60+
return 0;
61+
}

examples/samv/blink/openocd.cfg

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
source [find interface/jlink.cfg]
2+
transport select swd
3+
4+
source [find target/atsamv.cfg]
5+
6+
# Set boot mode selection to Flash (instead of SAM-BA on ROM)
7+
init
8+
halt
9+
atsamv gpnvm set 1

examples/samv/blink/project.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<library>
2+
<options>
3+
<option name="modm:target">samv70n20b-aabt</option>
4+
<option name="modm:build:build.path">../../../build/samv/blink</option>
5+
<option name="modm:build:openocd.cfg">openocd.cfg</option>
6+
</options>
7+
<modules>
8+
<module>modm:build:scons</module>
9+
<module>modm:platform:core</module>
10+
<module>modm:platform:clock</module>
11+
<module>modm:platform:gpio</module>
12+
<module>modm:architecture:delay</module>
13+
<module>modm:platform:clockgen</module>
14+
</modules>
15+
</library>

0 commit comments

Comments
 (0)