Skip to content

Commit

Permalink
Basic hello world example that runs on the metro m0 express
Browse files Browse the repository at this point in the history
  • Loading branch information
wez committed Mar 17, 2018
1 parent cf39404 commit d127ec7
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 2 deletions.
13 changes: 13 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# samd21 is a Cortex-M0 and thus thumbv6m

[build]
target = "thumbv6m-none-eabi"

[target.thumbv6m-none-eabi]
runner = 'arm-none-eabi-gdb'
rustflags = [
"-C", "link-arg=-Tlink.x",
"-C", "linker=arm-none-eabi-ld",
"-Z", "linker-flavor=ld",
"-Z", "thinlto=no",
]
18 changes: 18 additions & 0 deletions .gdbinit
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# print demangled symbols by default
set print asm-demangle on

# JLink
target extended-remote :2331
monitor flash breakpoints 1
# allow hprints to show up in gdb
monitor semihosting enable
monitor semihosting IOClient 3

monitor reset
load

# OpenOCD
#target extended-remote :3333
#monitor arm semihosting enable
#load
#step
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
[._]*.sw[a-p]
/target
Cargo.lock
/.gdb_history
26 changes: 26 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
[workspace]
members = ["atsamd21g18a"]

[package]
name = "samd21"
version = "0.0.0"

[dependencies]
cortex-m = "0.4.3"
cortex-m-semihosting = "0.2.0"

[dependencies.cortex-m-rt]
version = "0.3.13"
features = ["abort-on-panic"]

[dependencies.atsamd21g18a]
path = "atsamd21g18a"
features = ["rt"]

# disable both incremental compilation and parallel codegen to
# reduce the chances of running into rust-lang/rust#47074
[profile.dev]
codegen-units = 1
incremental = false

[profile.release]
debug = true
lto = true
10 changes: 10 additions & 0 deletions Xargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[dependencies.core]
stage = 0

# [dependencies.alloc] # Uncomment for the alloc example.
# stage = 0

[dependencies.compiler_builtins]
features = ["mem"]
stage = 1

4 changes: 2 additions & 2 deletions atsamd21g18a/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ license = "MIT OR Apache-2.0"

[dependencies]
bare-metal = "0.1.1"
cortex-m = "0.4.0"
cortex-m = "0.4.3"
vcell = "0.1.0"

[dependencies.cortex-m-rt]
optional = true
version = "0.3.0"
version = "0.3.13"

[features]
rt = ["cortex-m-rt"]
17 changes: 17 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;

fn main() {
// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out.join("memory.x"))
.unwrap()
.write_all(include_bytes!("memory.x"))
.unwrap();
println!("cargo:rustc-link-search={}", out.display());

println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=memory.x");
}
8 changes: 8 additions & 0 deletions memory.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
MEMORY
{
// Leave 8k for the default bootloader on the Metro M0
FLASH (rx) : ORIGIN = 0x00000000 + 8K, LENGTH = 256K - 8K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
}
_stack_start = ORIGIN(RAM) + LENGTH(RAM);

15 changes: 15 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![feature(used)]
#![no_std]

extern crate atsamd21g18a;
extern crate cortex_m;
extern crate cortex_m_rt;
extern crate cortex_m_semihosting;

use core::fmt::Write;
use cortex_m_semihosting::hio;

fn main() {
let mut stdout = hio::hstdout().unwrap();
writeln!(stdout, "Hello, world!").unwrap();
}

0 comments on commit d127ec7

Please sign in to comment.