Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for ATSAM arm processors #194

Merged
merged 11 commits into from
Jul 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ jobs:
name: Generic Examples
command: |
(cd examples && ../tools/scripts/examples_compile.py generic)
- run:
name: Examples SAM Devices
command: |
(cd examples && ../tools/scripts/examples_compile.py samd)
- run:
name: Execute Python Scripts
command: |
Expand Down Expand Up @@ -157,6 +161,23 @@ jobs:
path: test/all/log
destination: log

samd-compile-all:
docker:
- image: modm/modm-build:latest
steps:
- checkout
- run:
name: Checkout code and update modm tools
command: |
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade --upgrade-strategy=eager modm & wait
- run:
name: Compile HAL for all SAMD
command: |
(cd test/all && python3 run_all.py samd)
- store_artifacts:
path: test/all/log
destination: log

stm32f0-compile-all:
docker:
- image: modm/modm-build:latest
Expand Down Expand Up @@ -437,6 +458,12 @@ workflows:
filters:
branches:
ignore: /^develop.*/
- samd-compile-all:
requires:
- unittests-linux-generic
filters:
branches:
ignore: /^develop.*/
- stm32f0-compile-all:
requires:
- unittests-linux-generic
Expand Down Expand Up @@ -514,6 +541,7 @@ workflows:
ignore: /^develop.*/
requires:
- avr-compile-all
- samd-compile-all
- stm32f0-compile-all
- stm32f1-compile-all
- stm32f2-compile-all
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@
[submodule "ext/adamgreen/crashcatcher"]
path = ext/adamgreen/crashcatcher
url = https://github.com/modm-ext/CrashCatcher-partial.git
[submodule "ext/microchip/sam"]
path = ext/microchip/sam
url = https://github.com/modm-io/cmsis-header-sam.git
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ git clone --recurse-submodules https://github.com/modm-io/modm.git

## Targets

modm can generate code for <!--avrcount-->530<!--/avrcount--> AVR and <!--stmcount-->1959<!--/stmcount-->
modm can generate code for <!--avrcount-->530<!--/avrcount--> AVR,
<!--samcount-->163<!--/samcount--> SAM and <!--stmcount-->1959<!--/stmcount-->
STM32 devices, however, there are different levels of support and testing.

<center>
Expand All @@ -81,6 +82,7 @@ STM32 devices, however, there are different levels of support and testing.
| STM32F2 | ★★★★ | STM32F3 | ★★★★★ | STM32F4 | ★★★★★ |
| STM32F7 | ★★★★ | STM32L1 | ★★★★ | STM32L4 | ★★★★ |
| STM32L4+ | ★★★★ | STM32G0 | ★★★★ | STM32G4 | ★★★★ |
| SAMD21 | ★ | | | | |

</center>

Expand Down Expand Up @@ -130,31 +132,33 @@ documentation.
<td align="center">DISCO-L152RC</td>
<td align="center">DISCO-L476VG</td>
</tr><tr>
<td align="center">FEATHER-M0</td>
<td align="center">MEGA-2560-PRO</td>
<td align="center">MINI-F401</td>
<td align="center">MINI-F411</td>
<td align="center">NUCLEO-F031K6</td>
</tr><tr>
<td align="center">NUCLEO-F031K6</td>
<td align="center">NUCLEO-F042K6</td>
<td align="center">NUCLEO-F103RB</td>
<td align="center">NUCLEO-F303K8</td>
<td align="center">NUCLEO-F303RE</td>
</tr><tr>
<td align="center">NUCLEO-F303RE</td>
<td align="center">NUCLEO-F401RE</td>
<td align="center">NUCLEO-F411RE</td>
<td align="center">NUCLEO-F429ZI</td>
<td align="center">NUCLEO-F446RE</td>
</tr><tr>
<td align="center">NUCLEO-F446RE</td>
<td align="center">NUCLEO-F746ZG</td>
<td align="center">NUCLEO-G071RB</td>
<td align="center">NUCLEO-G474RE</td>
<td align="center">NUCLEO-L152RE</td>
</tr><tr>
<td align="center">NUCLEO-L152RE</td>
<td align="center">NUCLEO-L432KC</td>
<td align="center">NUCLEO-L476RG</td>
<td align="center">OLIMEXINO-STM32</td>
<td align="center">STM32F030F4P6-DEMO</td>
</tr><tr>
<td align="center">SAMD21-MINI</td>
<td align="center">STM32F030F4P6-DEMO</td>
</tr>
</table>
<!--/bsptable-->
Expand Down
4 changes: 4 additions & 0 deletions docs/src/guide/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ well:
brew install arm-gcc-bin
brew install openocd --HEAD

To program Microchip SAM devices via the bootloader, install the `bossac` tool:

brew cask install bossa

We recommend the use of a graphical frontend for GDB called [gdbgui][]:

pip3 install gdbgui
Expand Down
35 changes: 35 additions & 0 deletions examples/samd/blink/main.cpp
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;
}
9 changes: 9 additions & 0 deletions examples/samd/blink/project.xml
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>
29 changes: 29 additions & 0 deletions ext/microchip/device.hpp.in
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
70 changes: 70 additions & 0 deletions ext/microchip/module.lb
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")
1 change: 1 addition & 0 deletions ext/microchip/sam
Submodule sam added at 9f0812
1 change: 1 addition & 0 deletions repo.lb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class DevicesCache(dict):
"stm32g0", "stm32g4",
"stm32l1", "stm32l4",
"at90", "attiny", "atmega",
"samd21",
"hosted"]
device_file_names = [dfn for dfn in device_file_names if any(s in dfn for s in supported)]

Expand Down
81 changes: 81 additions & 0 deletions src/modm/board/feather_m0/board.hpp
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
14 changes: 14 additions & 0 deletions src/modm/board/feather_m0/board.xml
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>
Loading