Skip to content

Commit

Permalink
Merge #29
Browse files Browse the repository at this point in the history
29: use less unstable dependencies r=japaric a=japaric

This PR and the ones at the bottom reduce the number of unstable features needed for Cortex-M development to a single one: `lang = "panic_fmt"`, which already has a path towards stabilization and which we hope to get on stable by 1.28.

[Check out the temporary documentation](https://japaric.github.io/cortex-m-quickstart/cortex_m_quickstart/index.html) (we still need more docs) to try out this preview. 

We would love your input on [these unresolved questions](rust-embedded/cortex-m-rt#69 (comment))

This PR depends on:

- rust-embedded/cortex-m-rt#69
- rust-embedded/cortex-m#88
- rust-embedded/panic-semihosting#2
- rust-embedded/svd2rust#203
- japaric/stm32f103xx#24

Co-authored-by: Jorge Aparicio <jorge@japaric.io>
  • Loading branch information
bors[bot] and japaric committed May 12, 2018
2 parents 43acbc4 + 66c0c58 commit f7cf8de
Show file tree
Hide file tree
Showing 33 changed files with 1,035 additions and 715 deletions.
51 changes: 31 additions & 20 deletions .cargo/config
@@ -1,39 +1,50 @@
[target.thumbv6m-none-eabi]
runner = 'arm-none-eabi-gdb'
rustflags = [
"-C", "link-arg=-Tlink.x",
"-C", "linker=lld",
"-Z", "linker-flavor=ld.lld",
# "-C", "linker=arm-none-eabi-ld",
# "-Z", "linker-flavor=ld",
"-C", "link-arg=-Wl,-Tlink.x",
"-C", "link-arg=-nostartfiles",

# uncomment to use rustc LLD to link programs (a)
# "-C", "link-arg=-Tlink.x",
# "-C", "linker=lld",
# "-Z", "linker-flavor=ld.lld",
]

[target.thumbv7m-none-eabi]
runner = 'arm-none-eabi-gdb'
rustflags = [
"-C", "link-arg=-Tlink.x",
"-C", "linker=lld",
"-Z", "linker-flavor=ld.lld",
# "-C", "linker=arm-none-eabi-ld",
# "-Z", "linker-flavor=ld",
"-C", "link-arg=-Wl,-Tlink.x",
"-C", "link-arg=-nostartfiles",

# uncomment to use rustc LLD to link programs (a)
# "-C", "link-arg=-Tlink.x",
# "-C", "linker=lld",
# "-Z", "linker-flavor=ld.lld",
]

[target.thumbv7em-none-eabi]
runner = 'arm-none-eabi-gdb'
rustflags = [
"-C", "link-arg=-Tlink.x",
"-C", "linker=lld",
"-Z", "linker-flavor=ld.lld",
# "-C", "linker=arm-none-eabi-ld",
# "-Z", "linker-flavor=ld",
"-C", "link-arg=-Wl,-Tlink.x",
"-C", "link-arg=-nostartfiles",

# uncomment to use rustc LLD to link programs (a)
# "-C", "link-arg=-Tlink.x",
# "-C", "linker=lld",
# "-Z", "linker-flavor=ld.lld",
]

[target.thumbv7em-none-eabihf]
runner = 'arm-none-eabi-gdb'
rustflags = [
"-C", "link-arg=-Tlink.x",
"-C", "linker=lld",
"-Z", "linker-flavor=ld.lld",
# "-C", "linker=arm-none-eabi-ld",
# "-Z", "linker-flavor=ld",
"-C", "link-arg=-Wl,-Tlink.x",
"-C", "link-arg=-nostartfiles",

# uncomment to use rustc LLD to link programs (a)
# "-C", "link-arg=-Tlink.x",
# "-C", "linker=lld",
# "-Z", "linker-flavor=ld.lld",
]

# (a) you also need to comment out the other two `link-arg` lines. But note that as of v0.6.0 LLD
# has a bug where it mislinks FFI calls and they up crashing the program at runtime
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
**/*.rs.bk
.#*
.gdb_history
Cargo.lock
target/
16 changes: 4 additions & 12 deletions .travis.yml
Expand Up @@ -6,37 +6,29 @@ matrix:
rust: nightly
addons:
apt:
sources:
- debian-sid
packages:
- binutils-arm-none-eabi
- gcc-arm-none-eabi

- env: TARGET=thumbv7m-none-eabi
rust: nightly
addons:
apt:
sources:
- debian-sid
packages:
- binutils-arm-none-eabi
- gcc-arm-none-eabi

- env: TARGET=thumbv7em-none-eabi
rust: nightly
addons:
apt:
sources:
- debian-sid
packages:
- binutils-arm-none-eabi
- gcc-arm-none-eabi

- env: TARGET=thumbv7em-none-eabihf
rust: nightly
addons:
apt:
sources:
- debian-sid
packages:
- binutils-arm-none-eabi
- gcc-arm-none-eabi

before_install: set -e

Expand Down
20 changes: 19 additions & 1 deletion CHANGELOG.md
Expand Up @@ -5,6 +5,23 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [v0.3.0] - 2018-05-12

### Changed

- [breaking-change] `arm-none-eabi-gcc` is now a mandatory dependency as it's required by the
`cortex-m-rt` dependency and also the default linker.

- Bumped the `cortex-m` and `cortex-m-rt` dependencies to v0.5.0. Updated all the examples to match
the new `cortex-m-rt` API.

- Updated the `allocator` example to compile on a recent nightly.

- Removed `opt-level = "s"` from `profile.release`. This flag is still unstable.

- Set the number of codegen-units to 1 when compiling in release mode. This produces smaller and
faster binaries.

## [v0.2.7] - 2018-04-24

### Changed
Expand Down Expand Up @@ -149,7 +166,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).

- Initial release

[Unreleased]: https://github.com/japaric/cortex-m-quickstart/compare/v0.2.7...HEAD
[Unreleased]: https://github.com/japaric/cortex-m-quickstart/compare/v0.3.0...HEAD
[v0.3.0]: https://github.com/japaric/cortex-m-quickstart/compare/v0.2.7...v0.3.0
[v0.2.7]: https://github.com/japaric/cortex-m-quickstart/compare/v0.2.6...v0.2.7
[v0.2.6]: https://github.com/japaric/cortex-m-quickstart/compare/v0.2.5...v0.2.6
[v0.2.5]: https://github.com/japaric/cortex-m-quickstart/compare/v0.2.4...v0.2.5
Expand Down
21 changes: 12 additions & 9 deletions Cargo.toml
Expand Up @@ -6,23 +6,26 @@ keywords = ["arm", "cortex-m", "template"]
license = "MIT OR Apache-2.0"
name = "cortex-m-quickstart"
repository = "https://github.com/japaric/cortex-m-quickstart"
version = "0.2.7"
version = "0.3.0"

[dependencies]
cortex-m = "0.4.0"
cortex-m-rt = "0.4.0"
cortex-m-semihosting = "0.2.0"
panic-abort = "0.1.1"
panic-semihosting = "0.1.0"
cortex-m = "0.5.0"
cortex-m-rt = "0.5.0"
cortex-m-semihosting = "0.3.0"
panic-semihosting = "0.2.0"

# Uncomment for the panic example.
# panic-itm = "0.1.1"

# Uncomment for the allocator example.
#alloc-cortex-m = "0.3.3"
# alloc-cortex-m = "0.3.4"

# Uncomment for the device example.
# [dependencies.stm32f103xx]
# features = ["rt"]
# version = "0.9.0"
# version = "0.10.0"

[profile.release]
codegen-units = 1 # better optimizations
debug = true
lto = true
opt-level = "s"
10 changes: 4 additions & 6 deletions ci/script.sh
Expand Up @@ -9,16 +9,16 @@ main() {
cat >memory.x <<'EOF'
MEMORY
{
/* NOTE K = KiBi = 1024 bytes */
FLASH : ORIGIN = 0x08000000, LENGTH = 256K
RAM : ORIGIN = 0x20000000, LENGTH = 40K
}
EOF

local examples=(
crash
exception
hello
override-exception-handler
minimal
panic
)
for ex in "${examples[@]}"; do
Expand All @@ -33,17 +33,15 @@ EOF
cargo build --target $TARGET --example $ex --release

examples+=( $ex )

fi

# Allocator example needs an extra dependency
cat >>Cargo.toml <<'EOF'
[dependencies.alloc-cortex-m]
version = "0.3.3"
version = "0.3.4"
EOF

local ex=allocator
cargo build --target $TARGET --example $ex
cargo build --target $TARGET --example $ex --release

examples+=( $ex )
Expand All @@ -53,7 +51,7 @@ EOF
cat >>Cargo.toml <<'EOF'
[dependencies.stm32f103xx]
features = ["rt"]
version = "0.9.0"
version = "0.10.0"
EOF

local ex=device
Expand Down
53 changes: 34 additions & 19 deletions examples/allocator.rs
Expand Up @@ -11,50 +11,65 @@

#![feature(alloc)]
#![feature(global_allocator)]
#![feature(used)]
#![feature(lang_items)]
#![no_main]
#![no_std]

// This is the allocator crate; you can use a different one
extern crate alloc_cortex_m;
#[macro_use]
extern crate alloc;
extern crate cortex_m;
extern crate cortex_m_rt;
extern crate cortex_m_semihosting;
extern crate panic_abort; // panicking behavior
#[macro_use]
extern crate cortex_m_rt as rt;
extern crate cortex_m_semihosting as sh;
extern crate panic_semihosting;

use core::fmt::Write;

use alloc_cortex_m::CortexMHeap;
use cortex_m::asm;
use cortex_m_semihosting::hio;
use rt::ExceptionFrame;
use sh::hio;

// this is the allocator the application will use
#[global_allocator]
static ALLOCATOR: CortexMHeap = CortexMHeap::empty();

extern "C" {
static mut _sheap: u32;
}

const HEAP_SIZE: usize = 1024; // in bytes

fn main() {
// Initialize the allocator
let start = unsafe { &mut _sheap as *mut u32 as usize };
unsafe { ALLOCATOR.init(start, HEAP_SIZE) }
entry!(main);

fn main() -> ! {
// Initialize the allocator BEFORE you use it
unsafe { ALLOCATOR.init(rt::heap_start() as usize, HEAP_SIZE) }

// Growable array allocated on the heap
let xs = vec![0, 1, 2];

let mut stdout = hio::hstdout().unwrap();
writeln!(stdout, "{:?}", xs).unwrap();
}

// As we are not using interrupts, we just register a dummy catch all handler
#[link_section = ".vector_table.interrupts"]
#[used]
static INTERRUPTS: [extern "C" fn(); 240] = [default_handler; 240];
loop {}
}

extern "C" fn default_handler() {
// define what happens in an Out Of Memory (OOM) condition
#[lang = "oom"]
#[no_mangle]
pub fn rust_oom() -> ! {
asm::bkpt();

loop {}
}

exception!(HardFault, hard_fault);

fn hard_fault(ef: &ExceptionFrame) -> ! {
panic!("HardFault at {:#?}", ef);
}

exception!(*, default_handler);

fn default_handler(irqn: i16) {
panic!("Unhandled exception (IRQn = {})", irqn);
}

0 comments on commit f7cf8de

Please sign in to comment.