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 feather_m4_can board, add mcan example #681

Open
wants to merge 1 commit 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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ In addition to the PACs and HAL, there numerous **B**oard **S**upport **P**ackag
| [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) | |
| [atsame51j](https://docs.rs/atsame51j/) | [![Crates.io](https://img.shields.io/crates/v/atsame51j.svg)](https://crates.io/crates/atsame51j) | |
| [atsame51j](https://docs.rs/atsame51j/) | [![Crates.io](https://img.shields.io/crates/v/atsame51j.svg)](https://crates.io/crates/atsame51j) | [Feather M4 CAN][feather_m4_can] |
| [atsame51n](https://docs.rs/atsame51n/) | [![Crates.io](https://img.shields.io/crates/v/atsame51n.svg)](https://crates.io/crates/atsame51n) | |
| [atsame53j](https://docs.rs/atsame53j/) | [![Crates.io](https://img.shields.io/crates/v/atsame53j.svg)](https://crates.io/crates/atsame53j) | |
| [atsame53n](https://docs.rs/atsame53n/) | [![Crates.io](https://img.shields.io/crates/v/atsame53n.svg)](https://crates.io/crates/atsame53n) | |
Expand All @@ -38,6 +38,7 @@ In addition to the PACs and HAL, there numerous **B**oard **S**upport **P**ackag
[edgebadge]: https://github.com/atsamd-rs/atsamd/tree/master/boards/edgebadge
[feather_m0]: https://github.com/atsamd-rs/atsamd/tree/master/boards/feather_m0/
[feather_m4]: https://github.com/atsamd-rs/atsamd/tree/master/boards/feather_m4/
[feather_m4_can]: https://github.com/atsamd-rs/atsamd/tree/master/boards/feather_m4_can/
[gemma_m0]: https://github.com/atsamd-rs/atsamd/tree/master/boards/gemma_m0/
[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/
Expand Down
14 changes: 14 additions & 0 deletions boards/feather_m4_can/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# vim:ft=toml:
[target.thumbv7em-none-eabihf]
runner = 'arm-none-eabi-gdb'

[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",
]
9 changes: 9 additions & 0 deletions boards/feather_m4_can/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# v0.1.0

- The board is added as a clone of `feather_m4` with chip changed ATSAM(D->E)51J
- Adapt pinmux: alternate function pins for CAN1 connecting to TCAN1051 transceiver
- Clone `mcan` example from `atsame54_xpro` board (using periodic task instead of button)

---

Changelog tracking started at v0.1.0
107 changes: 107 additions & 0 deletions boards/feather_m4_can/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
[package]
name = "feather_m4_can"
version = "0.1.0"
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", "can"]
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_can/"

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

[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]
mcan = "0.2"
dwt-systick-monotonic = "1.1"
panic-rtt-target = { version = "0.1", features = ["cortex-m"] }
rtt-target = { version = "0.3", features = ["cortex-m"] }
cortex-m = "0.7"
usbd-serial = "0.1"
cortex-m-rtic = "1.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 atsame51j support
default = ["rt", "atsamd-hal/same51j", "atsamd-hal/same51"]
rt = ["cortex-m-rt", "atsamd-hal/same51j-rt"]
unproven = ["atsamd-hal/unproven"]
usb = ["atsamd-hal/usb", "usb-device"]
can = ["atsamd-hal/can"]
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"

[[example]]
name = "blinky_basic"

[[example]]
name = "pwm"
required-features = ["unproven"]

[[example]]
name = "neopixel_rainbow"

[[example]]
name = "usb_echo"
required-features = ["usb"]

[[example]]
name = "dmac"
required-features = ["dma"]

[[example]]
name = "uart"
required-features = ["dma"]

[[example]]
name = "pukcc_test"
required-features = ["unproven", "usb"]

[[example]]
name = "nvm_dsu"
required-features = ["unproven", "usb"]

[[example]]
name = "smart_eeprom"
required-features = ["unproven", "usb"]

[[example]]
name = "i2c"
required-features = ["atsamd-hal/dma"]

[[example]]
name = "mcan"
required-features = ["can"]
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 Board Support Crate

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

## 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_can`
* 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_can/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();
}
}
Loading