Skip to content

Commit ceca9d4

Browse files
authored
Add adafruit matrix portal m4 (#713)
* Adding Matrix Portal M4 with blinky example * Fixing tier * Fixing rust formatting * Fixing toml, README and crates.json * Adding cortex-m feature * Adding to top level README
1 parent 4e7f8ef commit ceca9d4

File tree

11 files changed

+655
-1
lines changed

11 files changed

+655
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The Peripheral Access Crates (PACs) are automatically generated from Microchip S
4343
| [atsamd21g](https://docs.rs/atsamd21g/) | [![Crates.io](https://img.shields.io/crates/v/atsamd21g.svg)](https://crates.io/crates/atsamd21g) | [Arduino Nano 33 IOT][arduino_nano33_iot], [Circuit Playground Express][circuit_playground_express], [Feather M0][feather_m0]\*, [ItsyBitsy M0][itsybitsy_m0], [Metro M0][metro_m0]\*, [MKR1000][arduino_mkr1000], [MKR Vidor 4000][arduino_mkr_vidor_4000], [MKR ZERO][arduino_mkrzero], [P1AM-100][p1am_100], [SAMD21 Mini][samd21_mini], [SODAQ ONE][sodaq_one], [Wio Lite MG126][wio_lite_mg126], [Wio Lite W600][wio_lite_w600], [Xiao M0][xiao_m0] |
4444
| [atsamd21j](https://docs.rs/atsamd21j/) | [![Crates.io](https://img.shields.io/crates/v/atsamd21j.svg)](https://crates.io/crates/atsamd21j) | [SODAQ SARA AFF][sodaq_sara_aff] |
4545
| [atsamd51g](https://docs.rs/atsamd51g/) | [![Crates.io](https://img.shields.io/crates/v/atsamd51g.svg)](https://crates.io/crates/atsamd51g) | [ItsyBitsy M4][itsybitsy_m4], [Trellis M4][trellis_m4] |
46-
| [atsamd51j](https://docs.rs/atsamd51j/) | [![Crates.io](https://img.shields.io/crates/v/atsamd51j.svg)](https://crates.io/crates/atsamd51j) | [EdgeBadge][edgebadge], [Feather M4][feather_m4]\*, [Metro M4][metro_m4]\*, [PyPortal][pyportal] |
46+
| [atsamd51j](https://docs.rs/atsamd51j/) | [![Crates.io](https://img.shields.io/crates/v/atsamd51j.svg)](https://crates.io/crates/atsamd51j) | [EdgeBadge][edgebadge], [Feather M4][feather_m4]\*, [Metro M4][metro_m4]\*, [PyPortal][pyportal], [Matrix Portal M4][matrix_portal_m4] |
4747
| [atsame51n](https://docs.rs/atsame51n/) | [![Crates.io](https://img.shields.io/crates/v/atsame51n.svg)](https://crates.io/crates/atsame51n) | |
4848
| [atsamd51p](https://docs.rs/atsamd51p/) | [![Crates.io](https://img.shields.io/crates/v/atsamd51p.svg)](https://crates.io/crates/atsamd51p) | [Grand Central M4 Express][grand_central_m4], [Wio Terminal][wio_terminal] |
4949
| [atsame51g](https://docs.rs/atsame51g/) | [![Crates.io](https://img.shields.io/crates/v/atsame51g.svg)](https://crates.io/crates/atsame51g) | |
@@ -69,6 +69,7 @@ The Peripheral Access Crates (PACs) are automatically generated from Microchip S
6969
[grand_central_m4]: https://github.com/atsamd-rs/atsamd/tree/master/boards/grand_central_m4/
7070
[itsybitsy_m0]: https://github.com/atsamd-rs/atsamd/tree/master/boards/itsybitsy_m0/
7171
[itsybitsy_m4]: https://github.com/atsamd-rs/atsamd/tree/master/boards/itsybitsy_m4/
72+
[matrix_portal_m4]: https://github.com/atsamd-rs/atsamd/tree/master/boards/matrix_portal_m4/
7273
[metro_m0]: https://github.com/atsamd-rs/atsamd/tree/master/boards/metro_m0/
7374
[metro_m4]: https://github.com/atsamd-rs/atsamd/tree/master/boards/metro_m4/
7475
[neo_trinkey]: https://github.com/atsamd-rs/atsamd/tree/master/boards/neo_trinkey

boards/matrix_portal_m4/.cargo/config

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# vim:ft=toml:
2+
[target.thumbv7em-none-eabihf]
3+
#runner = 'arm-none-eabi-gdb'
4+
runner = 'probe-run --chip ATSAMD51J19A'
5+
6+
[build]
7+
target = "thumbv7em-none-eabihf"
8+
rustflags = [
9+
10+
# This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x
11+
# See https://github.com/rust-embedded/cortex-m-quickstart/pull/95
12+
"-C", "link-arg=--nmagic",
13+
14+
"-C", "link-arg=-Tlink.x",
15+
]

boards/matrix_portal_m4/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Unreleased
2+
3+
-
4+
5+
# v0.1.0
6+
7+
- Added blinky_basic.rs example
8+
- Added pin mapping to pin.rs
9+
10+
---
11+
12+
Changelog tracking started at v0.1.0

boards/matrix_portal_m4/Cargo.toml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[package]
2+
name = "matrix_portal_m4"
3+
version = "0.1.0"
4+
authors = ["Salsa Steve <elmanstevelaguna@gmail.com>"]
5+
description = "Board Support crate for the Matrix Portal M4"
6+
keywords = ["no-std", "arm", "cortex-m", "embedded-hal"]
7+
categories = ["embedded", "hardware-support", "no-std"]
8+
license = "MIT OR Apache-2.0"
9+
repository = "https://github.com/atsamd-rs/atsamd"
10+
readme = "README.md"
11+
edition = "2021"
12+
13+
# for cargo flash
14+
[package.metadata]
15+
chip = "ATSAMD51J19A"
16+
17+
[dependencies.cortex-m-rt]
18+
version = "0.7"
19+
optional = true
20+
21+
[dependencies.atsamd-hal]
22+
version = "0.16.0"
23+
default-features = false
24+
25+
[dependencies.usb-device]
26+
version = "0.3.1"
27+
optional = true
28+
29+
[dependencies.cortex-m]
30+
version = "0.7"
31+
features = ["critical-section-single-core"]
32+
33+
[dev-dependencies]
34+
panic-halt = "0.2"
35+
36+
[features]
37+
# ask the HAL to enable atsamd51j support
38+
default = ["rt", "atsamd-hal/samd51j", "atsamd-hal/samd51"]
39+
rt = ["cortex-m-rt", "atsamd-hal/samd51j-rt"]
40+
unproven = ["atsamd-hal/unproven"]
41+
usb = ["atsamd-hal/usb", "usb-device"]
42+
43+
44+
[[example]]
45+
name = "blinky_basic"

boards/matrix_portal_m4/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Adafruit Matrix Portal M4 Board Support Crate
2+
3+
This crate provides a type-safe API for working with the [Adafruit Matrix Portal M4
4+
board](https://www.adafruit.com/product/4745).
5+
6+
## Prerequisites
7+
* Install the cross compile toolchain `rustup target add thumbv7em-none-eabihf`
8+
* Install [cargo-hf2 the hf2 bootloader flasher tool](https://crates.io/crates/cargo-hf2) however your platform requires
9+
10+
## Uploading an example
11+
Check out the repository for examples:
12+
13+
https://github.com/atsamd-rs/atsamd/tree/master/boards/matrix_portal_m4/examples
14+
15+
* Be in this directory `cd boards/matrix_portal_m4`
16+
* Put your device in bootloader mode usually by hitting the reset button twice.
17+
* Build and upload in one step
18+
```
19+
20+
$ cargo hf2 --release --example blinky_basic --vid 0x239a --pid 0x00c9
21+
Finished release [optimized] target(s) in 0.74s
22+
Trying Ok(Some("Adafruit Industries")) Ok(Some("Matrix Portal M4"))
23+
Flashing "/Users/User/atsamd/boards/matrix_portal_m4/target/thumbv7em-none-eabihf/release/examples/blinky_basic"
24+
Finished in 0.051s
25+
$
26+
```

boards/matrix_portal_m4/build.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use std::env;
2+
use std::fs::File;
3+
use std::io::Write;
4+
use std::path::PathBuf;
5+
fn main() {
6+
if env::var_os("CARGO_FEATURE_RT").is_some() {
7+
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
8+
File::create(out.join("memory.x"))
9+
.unwrap()
10+
.write_all(include_bytes!("memory.x"))
11+
.unwrap();
12+
println!("cargo:rustc-link-search={}", out.display());
13+
println!("cargo:rerun-if-changed=memory.x");
14+
}
15+
println!("cargo:rerun-if-changed=build.rs");
16+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#![no_std]
2+
#![no_main]
3+
4+
use matrix_portal_m4::{entry, hal, pac, Pins};
5+
#[cfg(not(feature = "panic_led"))]
6+
use panic_halt as _;
7+
8+
use hal::clock::GenericClockController;
9+
use hal::delay::Delay;
10+
use hal::prelude::*;
11+
use pac::{CorePeripherals, Peripherals};
12+
13+
#[entry]
14+
fn main() -> ! {
15+
let mut peripherals = Peripherals::take().unwrap();
16+
let core = CorePeripherals::take().unwrap();
17+
let mut clocks = GenericClockController::with_internal_32kosc(
18+
peripherals.GCLK,
19+
&mut peripherals.MCLK,
20+
&mut peripherals.OSC32KCTRL,
21+
&mut peripherals.OSCCTRL,
22+
&mut peripherals.NVMCTRL,
23+
);
24+
let mut delay = Delay::new(core.SYST, &mut clocks);
25+
delay.delay_ms(400u16);
26+
27+
let pins = Pins::new(peripherals.PORT);
28+
let mut red_led = pins.led.into_push_pull_output();
29+
30+
loop {
31+
delay.delay_ms(200u8);
32+
red_led.set_high().unwrap();
33+
delay.delay_ms(200u8);
34+
red_led.set_low().unwrap();
35+
}
36+
}

boards/matrix_portal_m4/memory.x

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
MEMORY
2+
{
3+
/* Leave 16k for the default bootloader on the Matrix Portal M4 */
4+
FLASH (rx) : ORIGIN = 0x00000000 + 16K, LENGTH = 512K - 16K
5+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K
6+
}
7+
_stack_start = ORIGIN(RAM) + LENGTH(RAM);
8+

boards/matrix_portal_m4/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![no_std]
2+
3+
pub use atsamd_hal as hal;
4+
pub use hal::ehal;
5+
pub use hal::pac;
6+
7+
pub mod pins;
8+
pub use pins::*;
9+
10+
#[cfg(feature = "rt")]
11+
pub use cortex_m_rt::entry;

0 commit comments

Comments
 (0)