Skip to content

Commit b5826ed

Browse files
committed
Add feather_m4_can board, add mcan example
- the new `feather_m4_can` board is added as a clone of `feather_m4` with the chip changed ATSAM(D->E)51J - apply changes in board layout from `Feather M4` - adapt pinmux: alternate function pins for CAN1 connecting to TCAN1051 transceiver (RX, TX, S) and BOOST_EN - add aref pin on PA03 - move battery pin from PB01 to PB00 - Neopixel: update data to be on PB02, add enable pin PB03 - add neopixel rainbow example - adapt `mcan` example from `xplain` board replacing button triggering by a periodic task
1 parent 67561d0 commit b5826ed

26 files changed

+3336
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ In addition to the PACs and HAL, there numerous **B**oard **S**upport **P**ackag
2121
| [atsame51n](https://docs.rs/atsame51n/) | [![Crates.io](https://img.shields.io/crates/v/atsame51n.svg)](https://crates.io/crates/atsame51n) | |
2222
| [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] |
2323
| [atsame51g](https://docs.rs/atsame51g/) | [![Crates.io](https://img.shields.io/crates/v/atsame51g.svg)](https://crates.io/crates/atsame51g) | |
24-
| [atsame51j](https://docs.rs/atsame51j/) | [![Crates.io](https://img.shields.io/crates/v/atsame51j.svg)](https://crates.io/crates/atsame51j) | |
24+
| [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] |
2525
| [atsame51n](https://docs.rs/atsame51n/) | [![Crates.io](https://img.shields.io/crates/v/atsame51n.svg)](https://crates.io/crates/atsame51n) | |
2626
| [atsame53j](https://docs.rs/atsame53j/) | [![Crates.io](https://img.shields.io/crates/v/atsame53j.svg)](https://crates.io/crates/atsame53j) | |
2727
| [atsame53n](https://docs.rs/atsame53n/) | [![Crates.io](https://img.shields.io/crates/v/atsame53n.svg)](https://crates.io/crates/atsame53n) | |
@@ -38,6 +38,7 @@ In addition to the PACs and HAL, there numerous **B**oard **S**upport **P**ackag
3838
[edgebadge]: https://github.com/atsamd-rs/atsamd/tree/master/boards/edgebadge
3939
[feather_m0]: https://github.com/atsamd-rs/atsamd/tree/master/boards/feather_m0/
4040
[feather_m4]: https://github.com/atsamd-rs/atsamd/tree/master/boards/feather_m4/
41+
[feather_m4_can]: https://github.com/atsamd-rs/atsamd/tree/master/boards/feather_m4_can/
4142
[gemma_m0]: https://github.com/atsamd-rs/atsamd/tree/master/boards/gemma_m0/
4243
[grand_central_m4]: https://github.com/atsamd-rs/atsamd/tree/master/boards/grand_central_m4/
4344
[itsybitsy_m0]: https://github.com/atsamd-rs/atsamd/tree/master/boards/itsybitsy_m0/

boards/feather_m4_can/.cargo/config

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

boards/feather_m4_can/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# v0.1.0
2+
3+
- The board is added as a clone of `feather_m4` with chip changed ATSAM(D->E)51J
4+
- Adapt pinmux: alternate function pins for CAN1 connecting to TCAN1051 transceiver
5+
- Clone `mcan` example from `atsame54_xpro` board (using periodic task instead of button)
6+
7+
---
8+
9+
Changelog tracking started at v0.1.0

boards/feather_m4_can/Cargo.toml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
[package]
2+
name = "feather_m4_can"
3+
version = "0.1.0"
4+
edition = "2021"
5+
authors = ["Theodore DeRego <[email protected]>"]
6+
description = "Board Support crate for the Adafruit Feather M4 CAN"
7+
keywords = ["no-std", "arm", "cortex-m", "embedded-hal", "can"]
8+
categories = ["embedded", "hardware-support", "no-std"]
9+
license = "MIT OR Apache-2.0"
10+
repository = "https://github.com/atsamd-rs/atsamd"
11+
readme = "README.md"
12+
documentation = "https://atsamd-rs.github.io/atsamd/atsamd51j/feather_m4_can/"
13+
14+
# for cargo flash
15+
[package.metadata]
16+
chip = "ATSAME51J19A"
17+
18+
[dependencies.cortex-m-rt]
19+
version = "0.7"
20+
optional = true
21+
22+
[dependencies.atsamd-hal]
23+
path = "../../hal"
24+
version = "0.15.1"
25+
default-features = false
26+
27+
[dependencies.usb-device]
28+
version = "0.2"
29+
optional = true
30+
31+
[dev-dependencies]
32+
mcan = "0.2"
33+
dwt-systick-monotonic = "1.1"
34+
panic-rtt-target = { version = "0.1", features = ["cortex-m"] }
35+
rtt-target = { version = "0.3", features = ["cortex-m"] }
36+
cortex-m = "0.7"
37+
usbd-serial = "0.1"
38+
cortex-m-rtic = "1.1"
39+
panic-halt = "0.2"
40+
panic-semihosting = "0.5"
41+
smart-leds = "0.3"
42+
ws2812-timer-delay = "0.3"
43+
heapless = "0.7"
44+
45+
[features]
46+
# ask the HAL to enable atsame51j support
47+
default = ["rt", "atsamd-hal/same51j", "atsamd-hal/same51"]
48+
rt = ["cortex-m-rt", "atsamd-hal/same51j-rt"]
49+
unproven = ["atsamd-hal/unproven"]
50+
usb = ["atsamd-hal/usb", "usb-device"]
51+
can = ["atsamd-hal/can"]
52+
dma = ["atsamd-hal/dma", "unproven"]
53+
max-channels = ["dma", "atsamd-hal/dma"]
54+
55+
56+
[profile.dev]
57+
incremental = false
58+
codegen-units = 1
59+
debug = true
60+
lto = true
61+
62+
[profile.release]
63+
debug = true
64+
lto = true
65+
opt-level = "s"
66+
67+
[[example]]
68+
name = "blinky_basic"
69+
70+
[[example]]
71+
name = "pwm"
72+
required-features = ["unproven"]
73+
74+
[[example]]
75+
name = "neopixel_rainbow"
76+
77+
[[example]]
78+
name = "usb_echo"
79+
required-features = ["usb"]
80+
81+
[[example]]
82+
name = "dmac"
83+
required-features = ["dma"]
84+
85+
[[example]]
86+
name = "uart"
87+
required-features = ["dma"]
88+
89+
[[example]]
90+
name = "pukcc_test"
91+
required-features = ["unproven", "usb"]
92+
93+
[[example]]
94+
name = "nvm_dsu"
95+
required-features = ["unproven", "usb"]
96+
97+
[[example]]
98+
name = "smart_eeprom"
99+
required-features = ["unproven", "usb"]
100+
101+
[[example]]
102+
name = "i2c"
103+
required-features = ["atsamd-hal/dma"]
104+
105+
[[example]]
106+
name = "mcan"
107+
required-features = ["can"]

boards/feather_m4_can/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Adafruit Feather M4 Board Support Crate
2+
3+
This crate provides a type-safe API for working with the [Adafruit Feather M4
4+
board](https://www.adafruit.com/product/3857).
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/feather_m4_can/examples
14+
15+
* Be in this directory `cd boards/feather_m4_can`
16+
* Put your device in bootloader mode usually by hitting the reset button twice.
17+
* Build and upload in one step
18+
```
19+
$ cargo hf2 --release --example blinky_basic
20+
Finished release [optimized + debuginfo] target(s) in 0.19s
21+
Searching for a connected device with known vid/pid pair.
22+
Trying Ok(Some("Adafruit Industries")) Ok(Some("PyBadge"))
23+
Flashing "/Users/User/atsamd/boards/feather_m4_can/target/thumbv7em-none-eabihf/release/examples/blinky_basic"
24+
Finished in 0.079s
25+
$
26+
```

boards/feather_m4_can/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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#![no_std]
2+
#![no_main]
3+
4+
use feather_m4_can as bsp;
5+
#[cfg(not(feature = "use_semihosting"))]
6+
use panic_halt as _;
7+
#[cfg(feature = "use_semihosting")]
8+
use panic_semihosting as _;
9+
10+
use bsp::entry;
11+
use bsp::hal;
12+
use hal::clock::GenericClockController;
13+
use hal::delay::Delay;
14+
use hal::pac::{CorePeripherals, Peripherals};
15+
use hal::prelude::*;
16+
17+
#[entry]
18+
fn main() -> ! {
19+
let mut peripherals = Peripherals::take().unwrap();
20+
let core = CorePeripherals::take().unwrap();
21+
let mut clocks = GenericClockController::with_external_32kosc(
22+
peripherals.GCLK,
23+
&mut peripherals.MCLK,
24+
&mut peripherals.OSC32KCTRL,
25+
&mut peripherals.OSCCTRL,
26+
&mut peripherals.NVMCTRL,
27+
);
28+
let pins = bsp::Pins::new(peripherals.PORT);
29+
let mut red_led = pins.d13.into_push_pull_output();
30+
let mut delay = Delay::new(core.SYST, &mut clocks);
31+
loop {
32+
delay.delay_ms(2000u16);
33+
red_led.set_high().unwrap();
34+
delay.delay_ms(2000u16);
35+
red_led.set_low().unwrap();
36+
}
37+
}

0 commit comments

Comments
 (0)