-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 180b337
Showing
20 changed files
with
9,246 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/result* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
[target.thumbv7m-none-eabi] | ||
# uncomment this to make `cargo run` execute programs on QEMU | ||
# runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel" | ||
|
||
[target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
# uncomment ONE of these three option to make `cargo run` start a GDB session | ||
# which option to pick depends on your system | ||
# runner = "arm-none-eabi-gdb -q -x openocd.gdb" | ||
# runner = "gdb-multiarch -q -x openocd.gdb" | ||
# runner = "gdb -q -x openocd.gdb" | ||
|
||
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", | ||
|
||
# LLD (shipped with the Rust toolchain) is used as the default linker | ||
"-C", "link-arg=-Tlink.x", | ||
|
||
# if you run into problems with LLD switch to the GNU linker by commenting out | ||
# this line | ||
"-C", "linker=lld", | ||
|
||
# if you need to link to pre-compiled C libraries provided by a C toolchain | ||
# use GCC as the linker by commenting out both lines above and then | ||
# uncommenting the three lines below | ||
# "-C", "linker=arm-none-eabi-gcc", | ||
# "-C", "link-arg=-Wl,-Tlink.x", | ||
# "-C", "link-arg=-nostartfiles", | ||
] | ||
|
||
[build] | ||
# Pick ONE of these compilation targets | ||
# target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ | ||
target = "thumbv7m-none-eabi" # Cortex-M3 | ||
# target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU) | ||
# target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) | ||
# target = "thumbv8m.base-none-eabi" # Cortex-M23 | ||
# target = "thumbv8m.main-none-eabi" # Cortex-M33 (no FPU) | ||
# target = "thumbv8m.main-none-eabihf" # Cortex-M33 (with FPU) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
**/*.rs.bk | ||
.#* | ||
.gdb_history | ||
target/ | ||
|
||
# editor files | ||
.vscode/* | ||
!.vscode/*.md | ||
!.vscode/*.svd | ||
!.vscode/launch.json | ||
!.vscode/tasks.json | ||
!.vscode/extensions.json |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
[package] | ||
authors = ["Alex Martens <[email protected]>"] | ||
edition = "2018" | ||
readme = "README.md" | ||
name = "app" | ||
version = "0.1.0" | ||
|
||
[dependencies] | ||
cortex-m = "0.7" | ||
cortex-m-rt = "0.7" | ||
cortex-m-semihosting = "0.5.0" | ||
panic-halt = "0.2.0" | ||
|
||
# Uncomment for the panic example. | ||
# panic-itm = "0.4.1" | ||
|
||
# Uncomment for the allocator example. | ||
# alloc-cortex-m = "0.4.0" | ||
|
||
# Uncomment for the device example. | ||
# Update `memory.x`, set target to `thumbv7em-none-eabihf` in `.cargo/config`, | ||
# and then use `cargo build --examples device` to build it. | ||
# [dependencies.stm32f3] | ||
# features = ["stm32f303", "rt"] | ||
# version = "0.7.1" | ||
|
||
# this lets you use `cargo fix`! | ||
[[bin]] | ||
name = "app" | ||
test = false | ||
bench = false | ||
|
||
[profile.release] | ||
codegen-units = 1 # better optimizations | ||
debug = true # symbols are nice and they don't increase the size on Flash | ||
lto = true # better optimizations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//! This build script copies the `memory.x` file from the crate root into | ||
//! a directory where the linker can always find it at build time. | ||
//! For many projects this is optional, as the linker always searches the | ||
//! project root directory -- wherever `Cargo.toml` is. However, if you | ||
//! are using a workspace or have a more complicated build setup, this | ||
//! build script becomes required. Additionally, by requesting that | ||
//! Cargo re-run the build script whenever `memory.x` is changed, | ||
//! updating `memory.x` ensures a rebuild of the application with the | ||
//! new memory settings. | ||
|
||
use std::env; | ||
use std::fs::File; | ||
use std::io::Write; | ||
use std::path::PathBuf; | ||
|
||
fn main() { | ||
// Put `memory.x` in our output directory and ensure it's | ||
// on the linker search path. | ||
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()); | ||
|
||
// By default, Cargo will re-run a build script whenever | ||
// any file in the project changes. By specifying `memory.x` | ||
// here, we ensure the build script is only re-run when | ||
// `memory.x` is changed. | ||
println!("cargo:rerun-if-changed=memory.x"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ lib | ||
, rustPlatform | ||
, lld | ||
}: | ||
|
||
let | ||
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); | ||
in | ||
rustPlatform.buildRustPackage { | ||
inherit (cargoToml.package) version; | ||
pname = cargoToml.package.name; | ||
|
||
src = ./.; | ||
|
||
cargoLock.lockFile = ./Cargo.lock; | ||
|
||
nativeBuildInputs = [ | ||
lld | ||
]; | ||
|
||
# no tests for no_std | ||
doCheck = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//! How to use the heap and a dynamic memory allocator | ||
//! | ||
//! This example depends on the alloc-cortex-m crate so you'll have to add it to your Cargo.toml: | ||
//! | ||
//! ``` text | ||
//! # or edit the Cargo.toml file manually | ||
//! $ cargo add alloc-cortex-m | ||
//! ``` | ||
//! | ||
//! --- | ||
|
||
#![feature(alloc_error_handler)] | ||
#![no_main] | ||
#![no_std] | ||
|
||
extern crate alloc; | ||
use panic_halt as _; | ||
|
||
use self::alloc::vec; | ||
use core::alloc::Layout; | ||
|
||
use alloc_cortex_m::CortexMHeap; | ||
use cortex_m::asm; | ||
use cortex_m_rt::entry; | ||
use cortex_m_semihosting::{hprintln, debug}; | ||
|
||
// this is the allocator the application will use | ||
#[global_allocator] | ||
static ALLOCATOR: CortexMHeap = CortexMHeap::empty(); | ||
|
||
const HEAP_SIZE: usize = 1024; // in bytes | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
// Initialize the allocator BEFORE you use it | ||
unsafe { ALLOCATOR.init(cortex_m_rt::heap_start() as usize, HEAP_SIZE) } | ||
|
||
// Growable array allocated on the heap | ||
let xs = vec![0, 1, 2]; | ||
|
||
hprintln!("{:?}", xs).unwrap(); | ||
|
||
// exit QEMU | ||
// NOTE do not run this on hardware; it can corrupt OpenOCD state | ||
debug::exit(debug::EXIT_SUCCESS); | ||
|
||
loop {} | ||
} | ||
|
||
// define what happens in an Out Of Memory (OOM) condition | ||
#[alloc_error_handler] | ||
fn alloc_error(_layout: Layout) -> ! { | ||
asm::bkpt(); | ||
|
||
loop {} | ||
} |
Oops, something went wrong.