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 Board support package for Adafruit Feather M4 CAN #622

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions boards/feather_m4_can/.cargo/config.toml
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",
]
27 changes: 27 additions & 0 deletions boards/feather_m4_can/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Unreleased

# v0.10.1

- Update to `atsamd-hal` version `0.15.1`
- Make use of `bsp_peripherals` macro

# v0.10.0

- Update `lib.rs` and examples to reflect removal of `v1` APIs and promotion of `v2` APIs
- Add an `i2c` example
- Update `i2c_master` convenience function to use the new `sercom::v2::i2c` API
- Updated to 2021 edition, updated dependencies, removed unused dependencies (#562)

# v0.9.0

- replace deprecated `SpinTimer` with `TimerCounter` in the `neopixel_rainbow` example
- remove extraneous `embedded-hal` dependencies from BSPs
- cleanup `cortex_m` dependency
- move `usbd-x` crates used only in examples to `[dev-dependencies]`
- removed unnecessary dependency on `nb` (#510)
- add Public Key Cryptography Controller (PUKCC) example (#486)
- Update to use refactored SPI module (#467)

---

Changelog tracking started at v0.8.0
59 changes: 59 additions & 0 deletions boards/feather_m4_can/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[package]
name = "feather_m4_can"
version = "0.10.1"
edition = "2021"
authors = ["Theodore DeRego <[email protected]>"]
description = "Board Support crate for the Adafruit Feather M4 CAN"
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"
documentation = "https://atsamd-rs.github.io/atsamd/atsamd51j/feather_m4/"

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

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

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

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

[dev-dependencies]
cortex-m = "0.7"
usbd-serial = "0.1"
panic-halt = "0.2"
panic-semihosting = "0.5"
smart-leds = "0.3"
ws2812-timer-delay = "0.3"
heapless = "0.7"

[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"]
dma = ["atsamd-hal/dma", "unproven"]
max-channels = ["dma", "atsamd-hal/dma"]


[profile.dev]
incremental = false
codegen-units = 1
debug = true
lto = true

[profile.release]
debug = true
lto = true
opt-level = "s"
26 changes: 26 additions & 0 deletions boards/feather_m4_can/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Adafruit Feather M4 CAN Board Support Crate

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

## 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/feather_m4_can/examples

* Be in this directory `cd boards/feather_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
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/feather_m4/target/thumbv7em-none-eabihf/release/examples/blinky_basic"
Finished in 0.079s
$
```
16 changes: 16 additions & 0 deletions boards/feather_m4_can/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");
}
37 changes: 37 additions & 0 deletions boards/feather_m4_can/examples/blinky_basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#![no_std]
#![no_main]

use feather_m4_can as bsp;
#[cfg(not(feature = "use_semihosting"))]
use panic_halt as _;
#[cfg(feature = "use_semihosting")]
use panic_semihosting as _;

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

#[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.MCLK,
&mut peripherals.OSC32KCTRL,
&mut peripherals.OSCCTRL,
&mut peripherals.NVMCTRL,
);
let pins = bsp::Pins::new(peripherals.PORT);
let mut red_led = pins.d13.into_push_pull_output();
let mut delay = Delay::new(core.SYST, &mut clocks);
loop {
delay.delay_ms(2000u16);
red_led.set_high().unwrap();
delay.delay_ms(2000u16);
red_led.set_low().unwrap();
}
}
67 changes: 67 additions & 0 deletions boards/feather_m4_can/examples/neopixel_rainbow.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#![no_std]
#![no_main]

// Neopixel Rainbow
// This only functions when the --release version is compiled. Using the debug
// version leads to slow pulse durations which results in a straight white LED
// output.
//
// // Needs to be compiled with --release for the timing to be correct

use bsp::hal;
use feather_m4_can as bsp;

#[cfg(not(feature = "use_semihosting"))]
use panic_halt as _;
#[cfg(feature = "use_semihosting")]
use panic_semihosting as _;

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

use smart_leds::{
hsv::{hsv2rgb, Hsv},
SmartLedsWrite,
};
use ws2812_timer_delay::Ws2812;

#[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.MCLK,
&mut peripherals.OSC32KCTRL,
&mut peripherals.OSCCTRL,
&mut peripherals.NVMCTRL,
);
let pins = bsp::Pins::new(peripherals.PORT);
let mut delay = Delay::new(core.SYST, &mut clocks);

let gclk0 = clocks.gclk0();
let timer_clock = clocks.tc2_tc3(&gclk0).unwrap();
let mut timer = TimerCounter::tc3_(&timer_clock, peripherals.TC3, &mut peripherals.MCLK);
timer.start(3.mhz());

let neopixel_pin = pins.neopixel.into_push_pull_output();
let mut neopixel_power_pin = pins.neopixel_pwr.into_push_pull_output();
neopixel_power_pin.set_high().unwrap();
let mut neopixel = Ws2812::new(timer, neopixel_pin);

loop {
for j in 0..255u8 {
let colors = [hsv2rgb(Hsv {
hue: j,
sat: 255,
val: 2,
})];
neopixel.write(colors.iter().cloned()).unwrap();
delay.delay_ms(5u8);
}
}
}
8 changes: 8 additions & 0 deletions boards/feather_m4_can/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 Feather M4 */
FLASH (rx) : ORIGIN = 0x00000000 + 16K, LENGTH = 512K - 16K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K
}
_stack_start = ORIGIN(RAM) + LENGTH(RAM);

Loading