This project is an example of how you can setup an external project using zinc to target the Teensy. The actual example used here is one taken from the Zinc examples, but with this infrastructure in place, you can create whatever you want.
- Install rustup
$ rustup update nightly-2016-05-12
- In your project dir:
$ rustup override set nightly-2016-05-12
- Install
arm-none-eabi
gcc suite (for cortex-m4)$ brew cask install gcc-arm-embedded
- Setup the
thumbv7em-none-eabi
target$ echo -e '[target.thumbv7em-none-eabi]\nlinker = "arm-none-eabi-gcc"\nar = "arm-none-eabi-ar"\n' >> ~/.cargo/config
- Install the Teensy Loader CLI
$ brew install -dv --HEAD teensy_loader_cli
The code can be built with cargo.
$ cargo build --release --target=thumbv7em-none-eabi
This will generate an object file, to turn this into a bin file or hex file you will need to run objdump on the resultant binary. E.g.
$ objdump -O ihex ./target/thumbv7em-none-eabi/release/blink blink.hex
Since you are like to need to type this quite frequently, you may want to create a Makefile like this one to reduce the number of commands you need to type.
$ teensy_loader_cli -s --mcu=mk20dx256 -v ./target/thumbv7em-none-eabi/release/blink.hex
Teensy Loader, Command Line, Version 2.0
Read "target/thumbv7em-none-eabi/release/blink.hex": 3236 bytes, 1.2% usage
Soft reboot is not implemented for OSX
Waiting for Teensy device...
(hint: press the reset button)
Found HalfKay Bootloader
Read "target/thumbv7em-none-eabi/release/blink.hex": 3236 bytes, 1.2% usage
Programming....
Booting
$ rust new --bin --vcs git rust-teensy3-blink
$ cd rust-teensy-blink
Add the following to Cargo.toml, replacing the information preset here with information that makes sense for your MCU, binary, etc.
[package]
name = "rust-teensy3-blink"
version = "0.1.0"
authors = [YOU, "Geoff Cant <nem@erlang.geek.nz>", "Paul Osborne <osbpau@gmail.com>"]
[dependencies.zinc]
git = "https://github.com/Gyscos/zinc.git"
branch = "crazy"
features = ["mcu_k20"]
[dependencies.macro_platformtree]
git = "https://github.com/Gyscos/zinc.git"
branch = "crazy"
path = "macro_platformtree"
[dependencies.ioreg]
git = "https://github.com/Gyscos/zinc.git"
branch = "crazy"
path = "ioreg"
[dependencies.platformtree]
git = "https://github.com/Gyscos/zinc.git"
branch = "crazy"
path = "platformtree"
[dependencies.rust-libcore]
version = "*"
[[bin]]
name = "blink"
path = "blink.rs"
Grab a suitable target specification from those available in the root
of the Zinc repository (thumbv7em-none-eabi.json
for the Teensy 3.1 and 3.2).
This usually requires putting a couple lines like this in your
.cargo/config
so that Rust knows to use a proper cross-linker for
your target:
[target.thumbv7em-none-eabi]
linker = "arm-none-eabi-gcc"
ar = "arm-none-eabi-ar"
[target.thumbv7m-none-eabi]
linker = "arm-none-eabi-gcc"
ar = "arm-none-eabi-ar"
You can start with the Makefile from the example and go from there.
Write your code using Zinc!