-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[src] Add support for Microchip SAM devices
- Loading branch information
Showing
46 changed files
with
1,461 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2019, Ethan Slattery | ||
* | ||
* 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; | ||
using namespace std::chrono_literals; | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
LedRx::set(); | ||
|
||
while (1) | ||
{ | ||
LedTx::toggle(); | ||
LedRx::toggle(); | ||
modm::delay(500ms); | ||
|
||
#ifdef MODM_BOARD_HAS_LOGGER | ||
static uint32_t counter(0); | ||
MODM_LOG_INFO << "Loop counter: " << (counter++) << modm::endl; | ||
#endif | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<library> | ||
<extends>modm:samd21-mini</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/samd/blink</option> | ||
</options> | ||
<modules> | ||
<module>modm:build:scons</module> | ||
</modules> | ||
</library> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2019 Niklas Hauser | ||
* | ||
* 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/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#ifndef MODM_DEVICE_HPP | ||
#define MODM_DEVICE_HPP | ||
|
||
#define DONT_USE_CMSIS_INIT 1 | ||
%% for define in defines | ||
#define {{ define }} 1 | ||
%% endfor | ||
|
||
#include <stdint.h> | ||
// Defines for example the modm_always_inline macro | ||
#include <modm/architecture/utils.hpp> | ||
|
||
// Include external device headers: | ||
%% for header in headers | ||
#include <{{ header }}> | ||
%% endfor | ||
|
||
#endif // MODM_DEVICE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2019, Niklas Hauser | ||
# | ||
# 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/. | ||
# ----------------------------------------------------------------------------- | ||
|
||
import re | ||
from pathlib import Path | ||
|
||
# ----------------------------------------------------------------------------- | ||
def init(module): | ||
module.name = ":cmsis:device" | ||
|
||
def prepare(module, options): | ||
device = options[":target"] | ||
if device.identifier["platform"] != "sam": | ||
return False | ||
|
||
module.depends(":cmsis:core") | ||
return True | ||
|
||
pp = {} | ||
def validate(env): | ||
device = env[":target"] | ||
name = device.partname.split("-")[0] | ||
|
||
|
||
define = "__{}__".format(name.upper()) | ||
family_file = None | ||
for famfile in Path(localpath("sam")).glob("**/sam.h"): | ||
content = famfile.read_text(encoding="utf-8", errors="replace") | ||
match = re.findall(r"defined\((?P<define>__SAM.*?__)\)", content) | ||
if match is not None and define in match: | ||
family_file = famfile.relative_to(localpath(".")) | ||
|
||
if family_file is None: | ||
raise ValidateException("No device define found for '{}'!".format(device.partname)) | ||
|
||
family_folder = family_file.parent | ||
device_header = "{}.h".format(name) | ||
|
||
global pp | ||
pp = { | ||
"define": define, | ||
"folder": family_folder, | ||
"device_header": device_header, | ||
} | ||
|
||
def build(env): | ||
global pp | ||
env.collect(":build:path.include", "modm/ext") | ||
env.collect(":build:path.include", "modm/ext/cmsis/device") | ||
|
||
env.outbasepath = "modm/ext/cmsis/device" | ||
files = ["sam.h", "component-version.h", "pio", "instance", "component", pp["device_header"]] | ||
for file in files: | ||
env.copy(localpath(pp["folder"], file), file) | ||
|
||
env.substitutions = { | ||
"headers": [pp["device_header"]], | ||
"defines": [pp["define"]], | ||
} | ||
env.outbasepath = "modm/src/modm/platform" | ||
env.template("device.hpp.in") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (c) 2016-2017, Sascha Schade | ||
* Copyright (c) 2017-2018, Niklas Hauser | ||
* | ||
* 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/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#pragma once | ||
|
||
#include <modm/platform.hpp> | ||
#include <modm/architecture/interface/clock.hpp> | ||
|
||
using namespace modm::platform; | ||
|
||
|
||
/// @ingroup modm_board_feather_m0 | ||
namespace Board | ||
{ | ||
using namespace modm::literals; | ||
|
||
/// samd21g18a running at 48MHz generated from the external 32.768 KHz crystal | ||
struct SystemClock { | ||
static constexpr uint32_t Frequency = 48_MHz; | ||
// static constexpr uint32_t Ahb = Frequency; | ||
// static constexpr uint32_t Apba = Frequency; | ||
// static constexpr uint32_t Apbb = Frequency; | ||
// static constexpr uint32_t Apbc = Frequency; | ||
|
||
// static constexpr uint32_t Adc = Apb2; | ||
|
||
// static constexpr uint32_t SercomSlow = Apb2; | ||
// static constexpr uint32_t Sercom0 = Apb2; | ||
// static constexpr uint32_t Sercom1 = Apb2; | ||
// static constexpr uint32_t Sercom2 = Apb2; | ||
// static constexpr uint32_t Sercom3 = Apb2; | ||
// static constexpr uint32_t Sercom4 = Apb2; | ||
// static constexpr uint32_t Sercom5 = Apb2; | ||
|
||
// static constexpr uint32_t Apb1Timer = Apb1 * 2; | ||
// static constexpr uint32_t Apb2Timer = Apb2 * 1; | ||
// static constexpr uint32_t Timer1 = Apb2Timer; | ||
// static constexpr uint32_t Timer2 = Apb1Timer; | ||
// static constexpr uint32_t Timer3 = Apb1Timer; | ||
// static constexpr uint32_t Timer4 = Apb1Timer; | ||
|
||
static bool inline | ||
enable() | ||
{ | ||
// GenericClockController::enableExternalCrystal(Frequency); | ||
|
||
// switch system clock to PLL output | ||
// GenericClockController::enableSystemClock(ClockControl::SystemClockSource::Pll); | ||
|
||
// update frequencies for busy-wait delay functions | ||
// GenericClockController::updateCoreFrequency<Frequency>(); | ||
|
||
return true; | ||
} | ||
}; | ||
|
||
// User LED (inverted, because connected to 3V3) | ||
// using LedRed = GpioOutputA17; | ||
// using Leds = SoftwareGpioPort< LedRed >; | ||
|
||
// using Button = GpioUnused; | ||
|
||
inline void | ||
initialize() | ||
{ | ||
SystemClock::enable(); | ||
SysTickTimer::initialize<SystemClock>(); | ||
|
||
// LedGreen::setOutput(modm::Gpio::Low); | ||
} | ||
|
||
} // Board namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<library> | ||
<repositories> | ||
<repository> | ||
<path>../../../../repo.lb</path> | ||
</repository> | ||
</repositories> | ||
|
||
<options> | ||
<option name="modm:target">samd21g18a-uu</option> | ||
</options> | ||
<modules> | ||
<module>modm:board:feather-m0</module> | ||
</modules> | ||
</library> |
Oops, something went wrong.