Skip to content

Commit f7cf8de

Browse files
bors[bot]japaric
andcommitted
Merge #29
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 <[email protected]>
2 parents 43acbc4 + 66c0c58 commit f7cf8de

33 files changed

+1035
-715
lines changed

.cargo/config

+31-20
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,50 @@
11
[target.thumbv6m-none-eabi]
22
runner = 'arm-none-eabi-gdb'
33
rustflags = [
4-
"-C", "link-arg=-Tlink.x",
5-
"-C", "linker=lld",
6-
"-Z", "linker-flavor=ld.lld",
7-
# "-C", "linker=arm-none-eabi-ld",
8-
# "-Z", "linker-flavor=ld",
4+
"-C", "link-arg=-Wl,-Tlink.x",
5+
"-C", "link-arg=-nostartfiles",
6+
7+
# uncomment to use rustc LLD to link programs (a)
8+
# "-C", "link-arg=-Tlink.x",
9+
# "-C", "linker=lld",
10+
# "-Z", "linker-flavor=ld.lld",
911
]
1012

1113
[target.thumbv7m-none-eabi]
1214
runner = 'arm-none-eabi-gdb'
1315
rustflags = [
14-
"-C", "link-arg=-Tlink.x",
15-
"-C", "linker=lld",
16-
"-Z", "linker-flavor=ld.lld",
17-
# "-C", "linker=arm-none-eabi-ld",
18-
# "-Z", "linker-flavor=ld",
16+
"-C", "link-arg=-Wl,-Tlink.x",
17+
"-C", "link-arg=-nostartfiles",
18+
19+
# uncomment to use rustc LLD to link programs (a)
20+
# "-C", "link-arg=-Tlink.x",
21+
# "-C", "linker=lld",
22+
# "-Z", "linker-flavor=ld.lld",
1923
]
2024

2125
[target.thumbv7em-none-eabi]
2226
runner = 'arm-none-eabi-gdb'
2327
rustflags = [
24-
"-C", "link-arg=-Tlink.x",
25-
"-C", "linker=lld",
26-
"-Z", "linker-flavor=ld.lld",
27-
# "-C", "linker=arm-none-eabi-ld",
28-
# "-Z", "linker-flavor=ld",
28+
"-C", "link-arg=-Wl,-Tlink.x",
29+
"-C", "link-arg=-nostartfiles",
30+
31+
# uncomment to use rustc LLD to link programs (a)
32+
# "-C", "link-arg=-Tlink.x",
33+
# "-C", "linker=lld",
34+
# "-Z", "linker-flavor=ld.lld",
2935
]
3036

3137
[target.thumbv7em-none-eabihf]
3238
runner = 'arm-none-eabi-gdb'
3339
rustflags = [
34-
"-C", "link-arg=-Tlink.x",
35-
"-C", "linker=lld",
36-
"-Z", "linker-flavor=ld.lld",
37-
# "-C", "linker=arm-none-eabi-ld",
38-
# "-Z", "linker-flavor=ld",
40+
"-C", "link-arg=-Wl,-Tlink.x",
41+
"-C", "link-arg=-nostartfiles",
42+
43+
# uncomment to use rustc LLD to link programs (a)
44+
# "-C", "link-arg=-Tlink.x",
45+
# "-C", "linker=lld",
46+
# "-Z", "linker-flavor=ld.lld",
3947
]
48+
49+
# (a) you also need to comment out the other two `link-arg` lines. But note that as of v0.6.0 LLD
50+
# has a bug where it mislinks FFI calls and they up crashing the program at runtime

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
**/*.rs.bk
2+
.#*
23
.gdb_history
34
Cargo.lock
45
target/

.travis.yml

+4-12
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,29 @@ matrix:
66
rust: nightly
77
addons:
88
apt:
9-
sources:
10-
- debian-sid
119
packages:
12-
- binutils-arm-none-eabi
10+
- gcc-arm-none-eabi
1311

1412
- env: TARGET=thumbv7m-none-eabi
1513
rust: nightly
1614
addons:
1715
apt:
18-
sources:
19-
- debian-sid
2016
packages:
21-
- binutils-arm-none-eabi
17+
- gcc-arm-none-eabi
2218

2319
- env: TARGET=thumbv7em-none-eabi
2420
rust: nightly
2521
addons:
2622
apt:
27-
sources:
28-
- debian-sid
2923
packages:
30-
- binutils-arm-none-eabi
24+
- gcc-arm-none-eabi
3125

3226
- env: TARGET=thumbv7em-none-eabihf
3327
rust: nightly
3428
addons:
3529
apt:
36-
sources:
37-
- debian-sid
3830
packages:
39-
- binutils-arm-none-eabi
31+
- gcc-arm-none-eabi
4032

4133
before_install: set -e
4234

CHANGELOG.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55

66
## [Unreleased]
77

8+
## [v0.3.0] - 2018-05-12
9+
10+
### Changed
11+
12+
- [breaking-change] `arm-none-eabi-gcc` is now a mandatory dependency as it's required by the
13+
`cortex-m-rt` dependency and also the default linker.
14+
15+
- Bumped the `cortex-m` and `cortex-m-rt` dependencies to v0.5.0. Updated all the examples to match
16+
the new `cortex-m-rt` API.
17+
18+
- Updated the `allocator` example to compile on a recent nightly.
19+
20+
- Removed `opt-level = "s"` from `profile.release`. This flag is still unstable.
21+
22+
- Set the number of codegen-units to 1 when compiling in release mode. This produces smaller and
23+
faster binaries.
24+
825
## [v0.2.7] - 2018-04-24
926

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

150167
- Initial release
151168

152-
[Unreleased]: https://github.com/japaric/cortex-m-quickstart/compare/v0.2.7...HEAD
169+
[Unreleased]: https://github.com/japaric/cortex-m-quickstart/compare/v0.3.0...HEAD
170+
[v0.3.0]: https://github.com/japaric/cortex-m-quickstart/compare/v0.2.7...v0.3.0
153171
[v0.2.7]: https://github.com/japaric/cortex-m-quickstart/compare/v0.2.6...v0.2.7
154172
[v0.2.6]: https://github.com/japaric/cortex-m-quickstart/compare/v0.2.5...v0.2.6
155173
[v0.2.5]: https://github.com/japaric/cortex-m-quickstart/compare/v0.2.4...v0.2.5

Cargo.toml

+12-9
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,26 @@ keywords = ["arm", "cortex-m", "template"]
66
license = "MIT OR Apache-2.0"
77
name = "cortex-m-quickstart"
88
repository = "https://github.com/japaric/cortex-m-quickstart"
9-
version = "0.2.7"
9+
version = "0.3.0"
1010

1111
[dependencies]
12-
cortex-m = "0.4.0"
13-
cortex-m-rt = "0.4.0"
14-
cortex-m-semihosting = "0.2.0"
15-
panic-abort = "0.1.1"
16-
panic-semihosting = "0.1.0"
12+
cortex-m = "0.5.0"
13+
cortex-m-rt = "0.5.0"
14+
cortex-m-semihosting = "0.3.0"
15+
panic-semihosting = "0.2.0"
16+
17+
# Uncomment for the panic example.
18+
# panic-itm = "0.1.1"
19+
1720
# Uncomment for the allocator example.
18-
#alloc-cortex-m = "0.3.3"
21+
# alloc-cortex-m = "0.3.4"
1922

2023
# Uncomment for the device example.
2124
# [dependencies.stm32f103xx]
2225
# features = ["rt"]
23-
# version = "0.9.0"
26+
# version = "0.10.0"
2427

2528
[profile.release]
29+
codegen-units = 1 # better optimizations
2630
debug = true
2731
lto = true
28-
opt-level = "s"

ci/script.sh

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ main() {
99
cat >memory.x <<'EOF'
1010
MEMORY
1111
{
12-
/* NOTE K = KiBi = 1024 bytes */
1312
FLASH : ORIGIN = 0x08000000, LENGTH = 256K
1413
RAM : ORIGIN = 0x20000000, LENGTH = 40K
1514
}
1615
EOF
1716

1817
local examples=(
1918
crash
19+
exception
2020
hello
21-
override-exception-handler
21+
minimal
2222
panic
2323
)
2424
for ex in "${examples[@]}"; do
@@ -33,17 +33,15 @@ EOF
3333
cargo build --target $TARGET --example $ex --release
3434

3535
examples+=( $ex )
36-
3736
fi
3837

3938
# Allocator example needs an extra dependency
4039
cat >>Cargo.toml <<'EOF'
4140
[dependencies.alloc-cortex-m]
42-
version = "0.3.3"
41+
version = "0.3.4"
4342
EOF
4443

4544
local ex=allocator
46-
cargo build --target $TARGET --example $ex
4745
cargo build --target $TARGET --example $ex --release
4846

4947
examples+=( $ex )
@@ -53,7 +51,7 @@ EOF
5351
cat >>Cargo.toml <<'EOF'
5452
[dependencies.stm32f103xx]
5553
features = ["rt"]
56-
version = "0.9.0"
54+
version = "0.10.0"
5755
EOF
5856

5957
local ex=device

examples/allocator.rs

+34-19
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,65 @@
1111
1212
#![feature(alloc)]
1313
#![feature(global_allocator)]
14-
#![feature(used)]
14+
#![feature(lang_items)]
15+
#![no_main]
1516
#![no_std]
1617

1718
// This is the allocator crate; you can use a different one
1819
extern crate alloc_cortex_m;
1920
#[macro_use]
2021
extern crate alloc;
2122
extern crate cortex_m;
22-
extern crate cortex_m_rt;
23-
extern crate cortex_m_semihosting;
24-
extern crate panic_abort; // panicking behavior
23+
#[macro_use]
24+
extern crate cortex_m_rt as rt;
25+
extern crate cortex_m_semihosting as sh;
26+
extern crate panic_semihosting;
2527

2628
use core::fmt::Write;
2729

2830
use alloc_cortex_m::CortexMHeap;
2931
use cortex_m::asm;
30-
use cortex_m_semihosting::hio;
32+
use rt::ExceptionFrame;
33+
use sh::hio;
3134

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

35-
extern "C" {
36-
static mut _sheap: u32;
37-
}
38-
3939
const HEAP_SIZE: usize = 1024; // in bytes
4040

41-
fn main() {
42-
// Initialize the allocator
43-
let start = unsafe { &mut _sheap as *mut u32 as usize };
44-
unsafe { ALLOCATOR.init(start, HEAP_SIZE) }
41+
entry!(main);
42+
43+
fn main() -> ! {
44+
// Initialize the allocator BEFORE you use it
45+
unsafe { ALLOCATOR.init(rt::heap_start() as usize, HEAP_SIZE) }
4546

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

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

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

58-
extern "C" fn default_handler() {
56+
// define what happens in an Out Of Memory (OOM) condition
57+
#[lang = "oom"]
58+
#[no_mangle]
59+
pub fn rust_oom() -> ! {
5960
asm::bkpt();
61+
62+
loop {}
63+
}
64+
65+
exception!(HardFault, hard_fault);
66+
67+
fn hard_fault(ef: &ExceptionFrame) -> ! {
68+
panic!("HardFault at {:#?}", ef);
69+
}
70+
71+
exception!(*, default_handler);
72+
73+
fn default_handler(irqn: i16) {
74+
panic!("Unhandled exception (IRQn = {})", irqn);
6075
}

0 commit comments

Comments
 (0)