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

Add adafruit matrix portal m4 #713

Merged
merged 7 commits into from
Jan 9, 2024
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The Peripheral Access Crates (PACs) are automatically generated from Microchip S
| [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] |
| [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] |
| [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] |
| [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] |
| [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] |
| [atsame51n](https://docs.rs/atsame51n/) | [![Crates.io](https://img.shields.io/crates/v/atsame51n.svg)](https://crates.io/crates/atsame51n) | |
| [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] |
| [atsame51g](https://docs.rs/atsame51g/) | [![Crates.io](https://img.shields.io/crates/v/atsame51g.svg)](https://crates.io/crates/atsame51g) | |
Expand All @@ -69,6 +69,7 @@ The Peripheral Access Crates (PACs) are automatically generated from Microchip S
[grand_central_m4]: https://github.com/atsamd-rs/atsamd/tree/master/boards/grand_central_m4/
[itsybitsy_m0]: https://github.com/atsamd-rs/atsamd/tree/master/boards/itsybitsy_m0/
[itsybitsy_m4]: https://github.com/atsamd-rs/atsamd/tree/master/boards/itsybitsy_m4/
[matrix_portal_m4]: https://github.com/atsamd-rs/atsamd/tree/master/boards/matrix_portal_m4/
[metro_m0]: https://github.com/atsamd-rs/atsamd/tree/master/boards/metro_m0/
[metro_m4]: https://github.com/atsamd-rs/atsamd/tree/master/boards/metro_m4/
[neo_trinkey]: https://github.com/atsamd-rs/atsamd/tree/master/boards/neo_trinkey
Expand Down
15 changes: 15 additions & 0 deletions boards/matrix_portal_m4/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# vim:ft=toml:
[target.thumbv7em-none-eabihf]
#runner = 'arm-none-eabi-gdb'
runner = 'probe-run --chip ATSAMD51J19A'

[build]
target = "thumbv7em-none-eabihf"
rustflags = [

# This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x
# See https://github.com/rust-embedded/cortex-m-quickstart/pull/95
"-C", "link-arg=--nmagic",

"-C", "link-arg=-Tlink.x",
]
12 changes: 12 additions & 0 deletions boards/matrix_portal_m4/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Unreleased

-

# v0.1.0

- Added blinky_basic.rs example
- Added pin mapping to pin.rs

---

Changelog tracking started at v0.1.0
45 changes: 45 additions & 0 deletions boards/matrix_portal_m4/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[package]
name = "matrix_portal_m4"
version = "0.1.0"
authors = ["Salsa Steve <elmanstevelaguna@gmail.com>"]
description = "Board Support crate for the Matrix Portal M4"
keywords = ["no-std", "arm", "cortex-m", "embedded-hal"]
categories = ["embedded", "hardware-support", "no-std"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/atsamd-rs/atsamd"
readme = "README.md"
edition = "2021"

# for cargo flash
[package.metadata]
chip = "ATSAMD51J19A"

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

[dependencies.atsamd-hal]
version = "0.16.0"
default-features = false

[dependencies.usb-device]
version = "0.3.1"
optional = true

[dependencies.cortex-m]
version = "0.7"
features = ["critical-section-single-core"]
salsasteve marked this conversation as resolved.
Show resolved Hide resolved

[dev-dependencies]
panic-halt = "0.2"

[features]
# ask the HAL to enable atsamd51j support
default = ["rt", "atsamd-hal/samd51j", "atsamd-hal/samd51"]
rt = ["cortex-m-rt", "atsamd-hal/samd51j-rt"]
unproven = ["atsamd-hal/unproven"]
usb = ["atsamd-hal/usb", "usb-device"]


[[example]]
name = "blinky_basic"
26 changes: 26 additions & 0 deletions boards/matrix_portal_m4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Adafruit Matrix Portal M4 Board Support Crate

This crate provides a type-safe API for working with the [Adafruit Matrix Portal M4
board](https://www.adafruit.com/product/4745).

## Prerequisites
* Install the cross compile toolchain `rustup target add thumbv7em-none-eabihf`
* Install [cargo-hf2 the hf2 bootloader flasher tool](https://crates.io/crates/cargo-hf2) however your platform requires

## Uploading an example
Check out the repository for examples:

https://github.com/atsamd-rs/atsamd/tree/master/boards/matrix_portal_m4/examples

* Be in this directory `cd boards/matrix_portal_m4`
* Put your device in bootloader mode usually by hitting the reset button twice.
* Build and upload in one step
```

$ cargo hf2 --release --example blinky_basic --vid 0x239a --pid 0x00c9
Finished release [optimized] target(s) in 0.74s
Trying Ok(Some("Adafruit Industries")) Ok(Some("Matrix Portal M4"))
Flashing "/Users/User/atsamd/boards/matrix_portal_m4/target/thumbv7em-none-eabihf/release/examples/blinky_basic"
Finished in 0.051s
$
```
16 changes: 16 additions & 0 deletions boards/matrix_portal_m4/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
fn main() {
if env::var_os("CARGO_FEATURE_RT").is_some() {
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=memory.x");
}
println!("cargo:rerun-if-changed=build.rs");
}
36 changes: 36 additions & 0 deletions boards/matrix_portal_m4/examples/blinky_basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#![no_std]
#![no_main]

use matrix_portal_m4::{entry, hal, pac, Pins};
#[cfg(not(feature = "panic_led"))]
use panic_halt as _;

use hal::clock::GenericClockController;
use hal::delay::Delay;
use hal::prelude::*;
use pac::{CorePeripherals, Peripherals};

#[entry]
fn main() -> ! {
let mut peripherals = Peripherals::take().unwrap();
let core = CorePeripherals::take().unwrap();
let mut clocks = GenericClockController::with_internal_32kosc(
peripherals.GCLK,
&mut peripherals.MCLK,
&mut peripherals.OSC32KCTRL,
&mut peripherals.OSCCTRL,
&mut peripherals.NVMCTRL,
);
let mut delay = Delay::new(core.SYST, &mut clocks);
delay.delay_ms(400u16);

let pins = Pins::new(peripherals.PORT);
let mut red_led = pins.led.into_push_pull_output();

loop {
delay.delay_ms(200u8);
red_led.set_high().unwrap();
delay.delay_ms(200u8);
red_led.set_low().unwrap();
}
}
8 changes: 8 additions & 0 deletions boards/matrix_portal_m4/memory.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
MEMORY
{
/* Leave 16k for the default bootloader on the Matrix Portal M4 */
FLASH (rx) : ORIGIN = 0x00000000 + 16K, LENGTH = 512K - 16K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K
}
_stack_start = ORIGIN(RAM) + LENGTH(RAM);

11 changes: 11 additions & 0 deletions boards/matrix_portal_m4/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![no_std]

pub use atsamd_hal as hal;
pub use hal::ehal;
pub use hal::pac;

pub mod pins;
pub use pins::*;

#[cfg(feature = "rt")]
pub use cortex_m_rt::entry;
Loading