Crate f3 [−] [src]
A crate to play with the STM32F3DISCOVERY
(What? You don't have one? How come? They are awesome and cheap ($15 + shipping))
(No, I'm not associated to STM32. I just like this board in particular.)
Features
- High-level API over LEDs, sensors, timers, etc.
- An
iprint!
family of macros that sink their output to the ITM (Instrumentation Trace Macrocell) so you send data to the host over the same USB cable that you are using to debug your device. - By default,
panic!
s also sink their messages to the ITM - By default, an informative exception handler that tells you what went wrong.
- By default, everything (LEDs, sensors, etc) is initialized before the user entry point,
main
. So everything Just Works out of the box. - Plenty of examples
Also, all the "default" behaviors can be overridden:
- The default exception handler
- The default
panic_fmt
implementation - The default system initialization routine that runs before main.
Requirements and starter code
Today, you need these 7 things, one of them optional, but hopefully you won't need 3 of them in the future:
- Nightly Rust compiler:
rustup default nightly
- Xargo version 0.1.12 or newer. (After rust-lang/rfcs#1133 gets accepted and implemented you won't need Xargo anymore)
- A binary Cargo project that depends on this crate.
$ cargo new --bin foo && cd $_
$ edit Cargo.toml && tail -n2 $_
[dependencies]
f3 = "0.1.0"
- Optionally, you can also set
profile.release.lto = true
for even smaller binaries.
$ edit Cargo.toml && tail -n2 $_
[profile.release]
lto = true
- This
.cargo/config
in the root of your Cargo project. (If Cargo build scripts ever gain a feature to pass arbitrary arguments to the linker then you won't need this. Settingbuild.target
though always improves ergonomics)
$ cat .cargo/config
[build]
target = "thumbv7em-none-eabihf"
[target.thumbv7em-none-eabihf]
rustflags = [
"-C",
"link-arg=-Tstm32f3discovery.ld",
"-C",
"link-arg=-nostartfiles",
]
- This target specification file. (You won't need this after 2016-10-05 as these targets have already landed in the compiler)
$ cat thumbv7em-none-eabihf.json
{
"arch": "arm",
"data-layout": "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64",
"executables": true,
"features": "+vfp4,+d16,+fp-only-sp",
"linker": "arm-none-eabi-gcc",
"llvm-target": "thumbv7em-none-eabihf",
"os": "none",
"panic-strategy": "abort",
"relocation-model": "static",
"target-endian": "little",
"target-pointer-width": "32"
}
- And this starter code:
$ cat src/main.rs
#![no_main]
#![no_std]
extern crate f3;
#[export_name = "main"]
pub fn main() -> ! {
// Your code goes here!
loop {}
}
With all that in place, you can finally build the project using Xargo:
$ xargo build [--target thumbv7em-none-eabihf] [--release]
Check out the Copper book for instructions on how to Flash and Debug this program!
Examples
See the examples module.
Modules
delay |
Delays |
examples |
Examples |
exception |
Exceptions |
itm |
ITM (Instrumentation Trace Macrocell) |
led |
LEDs |
peripheral |
Low-level access to peripherals |
Macros
iprint |
Macro for sending |
iprintln |
Macro for sending |