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 mkrwifi1010 #236

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions boards/arduino_mkrwifi1010/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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",
]
43 changes: 43 additions & 0 deletions boards/arduino_mkrwifi1010/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "arduino_mkrwifi1010"
version = "0.1.0"
authors = ["Jacob Davis-Hansson <[email protected]>"]
description = "Board Support crate for the Arduino MKR WiFi 1010"
keywords = ["no-std", "arm", "cortex-m", "embedded-hal"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/atsamd-rs/atsamd"
readme = "README.md"
documentation = "https://atsamd-rs.github.io/atsamd/atsamd21e18a/arduino_mkrwifi1010/"

[dependencies]
cortex-m = "~0.6"
embedded-hal = "~0.2.3"
nb = "~0.1"

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

[dependencies.atsamd-hal]
path = "../../hal"
version = "~0.9"
default-features = false

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

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

[dependencies.usbd-serial]
version = "~0.1"
optional = true

[features]
# ask the HAL to enable atsamd21e18a support
default = ["rt", "atsamd-hal/samd21e18a"]
rt = ["cortex-m-rt", "atsamd-hal/samd21e18a-rt"]
usb = ["atsamd-hal/usb", "usb-device", "usbd-serial"]
unproven = ["atsamd-hal/unproven"]
use_semihosting = []
26 changes: 26 additions & 0 deletions boards/arduino_mkrwifi1010/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Adafruit Gemma M0 Board Support Crate

This crate provides a type-safe API for working with the [Adafruit Gemma M0
board](https://www.adafruit.com/product/3501).

## Prerequisites
* Install the cross compile toolchain `rustup target add thumbv6m-none-eabi`
* 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/gemma_m0/examples

* Be in this directory `cd boards/gemma_m0`
* 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
Finished release [optimized + debuginfo] target(s) in 0.19s
Searching for a connected device with known vid/pid pair.
Trying Ok(Some("Adafruit Industries")) Ok(Some("PyBadge"))
Flashing "/Users/User/atsamd/boards/gemma_m0/target/thumbv7em-none-eabihf/release/examples/blinky_basic"
Finished in 0.079s
$
```
16 changes: 16 additions & 0 deletions boards/arduino_mkrwifi1010/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");
}
32 changes: 32 additions & 0 deletions boards/arduino_mkrwifi1010/examples/blinky_basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#![no_std]
#![no_main]

extern crate arduino_mkrwifi1010 as hal;
extern crate panic_halt;

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

#[entry]
fn main() -> ! {
let mut peripherals = Peripherals::take().unwrap();
let core = CorePeripherals::take().unwrap();
let mut clocks = GenericClockController::with_external_32kosc(
peripherals.GCLK,
&mut peripherals.PM,
&mut peripherals.SYSCTRL,
&mut peripherals.NVMCTRL,
);
let mut pins = hal::Pins::new(peripherals.PORT);
let mut red_led = pins.d13.into_open_drain_output(&mut pins.port);
let mut delay = Delay::new(core.SYST, &mut clocks);
loop {
delay.delay_ms(200u8);
red_led.set_high().unwrap();
delay.delay_ms(200u8);
red_led.set_low().unwrap();
}
}
5 changes: 5 additions & 0 deletions boards/arduino_mkrwifi1010/memory.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000+0x2000, LENGTH = 0x00040000-0x2000 /* First 8KB used by bootloader */
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000
}
106 changes: 106 additions & 0 deletions boards/arduino_mkrwifi1010/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#![no_std]

extern crate atsamd_hal as hal;

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

use hal::prelude::*;
use hal::*;

pub use hal::target_device as pac;
pub use hal::common::*;
pub use hal::samd21::*;

use gpio::{Floating, Input, Port};

define_pins!(
/// Maps the pins to their arduino names and
/// the numbers printed on the board.
/// From https://github.com/arduino/ArduinoCore-samd/blob/master/variants/mkrwifi1010/variant.cpp
struct Pins,
target_device: target_device,

/// RX
pin rx = b23,

/// TX
pin tx = b22,

/// Digital 0
pin d0 = a22,

/// Digital 1
pin d1 = a23,

/// Digital 2: ADC
pin d2 = a10,

/// Digital 3: ADC
pin d3 = a11,

/// Digital 4
pin d4 = b10,

/// Digital 5
pin d5 = b11,

/// Digital 6: LED_BUILTIN
pin d6 = a20,

/// Digital 7
pin d7 = a21,

/// Digital 8/SC1 MOSI
pin mosi = a16,

/// Digital 9/SC1 SCK
pin sck = a17,

/// Digital 10/SC1 MISO
pin miso = a19,

/// Digital 11/SC2 SDA
pin sda = a8,

/// Digital 12/SC2 SCL
pin scl = a9,

/// Analog 0/DAC0
pin a0 = a2,

/// Analog 1
pin a1 = b2,

/// Analog 2
pin a2 = b3,

/// Analog 3
pin a3 = a4,

/// Analog 4
pin a4 = a5,

/// Analog 5
pin a5 = a6,

/// Analog 6
pin a6 = a7,

pin nina_mosi = a12,
pin nina_miso = a13,
pin nina_cs = a14,
pin nina_sck = a15,
pin nina_gpio0 = a27,
pin nina_resetn = b8,
pin nina_ack = a28,

pin adc_vbat = b9,

pin usb_dm = a24,
pin usb_dp = a25,
pin usb_id = a18,
pin aref = a3,
);