Skip to content
This repository was archived by the owner on Jan 24, 2022. It is now read-only.

Commit c359f73

Browse files
bors[bot]japaric
andcommitted
Merge #69
69: compile on stable r=japaric a=japaric with these changes this crate compiles on stable Co-authored-by: Jorge Aparicio <jorge@japaric.io>
2 parents 1865c7a + 2f410f2 commit c359f73

18 files changed

+1287
-619
lines changed

Diff for: .travis.yml

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
language: rust
2+
3+
matrix:
4+
include:
5+
- env: TARGET=x86_64-unknown-linux-gnu
6+
7+
- env: TARGET=thumbv6m-none-eabi
8+
rust: beta
9+
addons:
10+
apt:
11+
packages:
12+
- gcc-arm-none-eabi
13+
14+
- env: TARGET=thumbv7m-none-eabi
15+
rust: beta
16+
addons:
17+
apt:
18+
packages:
19+
- gcc-arm-none-eabi
20+
21+
- env: TARGET=thumbv7em-none-eabi
22+
rust: beta
23+
addons:
24+
apt:
25+
packages:
26+
- gcc-arm-none-eabi
27+
28+
- env: TARGET=thumbv7em-none-eabihf
29+
rust: beta
30+
addons:
31+
apt:
32+
packages:
33+
- gcc-arm-none-eabi
34+
35+
- env: TARGET=thumbv6m-none-eabi
36+
rust: nightly
37+
addons:
38+
apt:
39+
packages:
40+
- gcc-arm-none-eabi
41+
42+
- env: TARGET=thumbv7m-none-eabi
43+
rust: nightly
44+
addons:
45+
apt:
46+
packages:
47+
- gcc-arm-none-eabi
48+
49+
- env: TARGET=thumbv7em-none-eabi
50+
rust: nightly
51+
addons:
52+
apt:
53+
packages:
54+
- gcc-arm-none-eabi
55+
56+
- env: TARGET=thumbv7em-none-eabihf
57+
rust: nightly
58+
addons:
59+
apt:
60+
packages:
61+
- gcc-arm-none-eabi
62+
63+
before_install: set -e
64+
65+
install:
66+
- bash ci/install.sh
67+
68+
script:
69+
- bash ci/script.sh
70+
71+
after_script: set +e
72+
73+
cache: cache
74+
75+
before_cache:
76+
- chmod -R a+r $HOME/.cargo;
77+
78+
branches:
79+
only:
80+
- staging
81+
- trying
82+
83+
notifications:
84+
email:
85+
on_success: never

Diff for: CHANGELOG.md

+37
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,43 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
## [v0.5.0] - 2018-05-12
11+
12+
### Added
13+
14+
- An `entry!` macro to set the entry point of the program.
15+
16+
- A `heap_start` function that returns a pointer into the start of the heap region.
17+
18+
- A `device` feature. When disabled this crate provides the interrupt vectors; when enabled the
19+
interrupt vectors are expected to be provided by another crate. Read the documentation for
20+
details.
21+
22+
### Changed
23+
24+
- This crate now compiles on the beta and stable channels.
25+
26+
- [breaking-change] this crate now requires `arm-none-eabi-gcc` to be installed and available in
27+
`$PATH` to compile.
28+
29+
- [breaking-change] the `start` lang item has been removed. The standard `main` interface won't
30+
work. Instead use `#![no_main]` and the `entry!` macro. See documentation for details.
31+
32+
- [breaking-change] the `default_handler!` macro has been merged into the `exception!` macro. Use
33+
`exception!(*, ..)` to set the default exception handler.
34+
35+
- [breaking-change] there's no weak default handler so a default handler must be defined by the
36+
application, or one of its dependencies.
37+
38+
- [breaking-change] the syntax of the third argument of the `exception!` handler has changed. See
39+
the documentation of the macro for details.
40+
41+
- [breaking-change] the exception names that the `exception!` macro accepts has changed to match the
42+
CMSIS specification. See the documentation of the macro for the list of names it accepts.
43+
44+
- [breaking-change] The number of symbol interfaces has been reduced. Check the advanced section of
45+
the documentation for details.
46+
1047
## [v0.4.0] - 2018-04-09
1148

1249
### Added

Diff for: Cargo.toml

+11-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,16 @@ keywords = ["arm", "cortex-m", "runtime", "startup"]
77
license = "MIT OR Apache-2.0"
88
name = "cortex-m-rt"
99
repository = "https://github.com/japaric/cortex-m-rt"
10-
version = "0.4.0"
10+
version = "0.5.0"
11+
12+
[build-dependencies]
13+
cc = "1.0.10"
1114

1215
[dependencies]
13-
cortex-m = "0.3.0"
14-
r0 = "0.2.1"
16+
r0 = "0.2.1"
17+
18+
[dev-dependencies]
19+
panic-semihosting = "0.2.0"
20+
21+
[features]
22+
device = []

Diff for: asm.s

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.global HardFault
2+
.thumb_func
3+
HardFault:
4+
mrs r0, MSP
5+
bl UserHardFault

Diff for: bors.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
status = [
2+
"continuous-integration/travis-ci/push",
3+
]

Diff for: build.rs

+45-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
extern crate cc;
2+
13
use std::env;
24
use std::fs::File;
35
use std::io::Write;
@@ -7,14 +9,48 @@ fn main() {
79
let target = env::var("TARGET").unwrap();
810

911
has_fpu(&target);
10-
is_armv6m(&target);
12+
let is_armv6m = is_armv6m(&target);
13+
14+
if target.starts_with("thumbv") {
15+
cc::Build::new().file("asm.s").compile("asm");
16+
}
1117

1218
// Put the linker script somewhere the linker can find it
1319
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
14-
File::create(out.join("link.x"))
15-
.unwrap()
16-
.write_all(include_bytes!("link.x"))
17-
.unwrap();
20+
let link_x = include_bytes!("link.x.in");
21+
let mut f = if env::var_os("CARGO_FEATURE_DEVICE").is_some() {
22+
let mut f = File::create(out.join("link.x")).unwrap();
23+
24+
writeln!(
25+
f,
26+
r#"
27+
/* Provides weak aliases (cf. PROVIDED) for device specific interrupt handlers */
28+
/* This will usually be provided by a device crate generated using svd2rust (see `device.x`) */
29+
INCLUDE device.x"#
30+
).unwrap();
31+
f.write_all(link_x).unwrap();
32+
f
33+
} else {
34+
let mut f = File::create(out.join("link.x")).unwrap();
35+
f.write_all(link_x).unwrap();
36+
f
37+
};
38+
39+
let max_int_handlers = if is_armv6m { 32 } else { 240 };
40+
41+
// checking the size of the interrupts portion of the vector table is sub-architecture dependent
42+
writeln!(
43+
f,
44+
r#"
45+
ASSERT(__einterrupts - __eexceptions <= 0x{:x}, "
46+
There can't be more than {} interrupt handlers. This may be a bug in
47+
your device crate, or you may have registered more than 240 interrupt
48+
handlers.");
49+
"#,
50+
max_int_handlers * 4,
51+
max_int_handlers
52+
).unwrap();
53+
1854
println!("cargo:rustc-link-search={}", out.display());
1955

2056
println!("cargo:rerun-if-changed=build.rs");
@@ -27,8 +63,11 @@ fn has_fpu(target: &str) {
2763
}
2864
}
2965

30-
fn is_armv6m(target: &str) {
66+
fn is_armv6m(target: &str) -> bool {
3167
if target.starts_with("thumbv6m-") {
3268
println!("cargo:rustc-cfg=armv6m");
69+
true
70+
} else {
71+
false
3372
}
3473
}

Diff for: ci/install.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
set -euxo pipefail
2+
3+
main() {
4+
if [ $TARGET != x86_64-unknown-linux-gnu ]; then
5+
rustup target add $TARGET
6+
fi
7+
}
8+
9+
main

Diff for: ci/script.sh

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
set -euxo pipefail
2+
3+
main() {
4+
cargo check --target $TARGET
5+
6+
cargo check --target $TARGET --features device
7+
8+
local examples=(
9+
minimal
10+
main
11+
state
12+
)
13+
if [ $TRAVIS_RUST_VERSION = nightly ]; then
14+
for ex in "${examples[@]}"; do
15+
cargo rustc --target $TARGET --example $ex -- \
16+
-C link-arg=-nostartfiles \
17+
-C link-arg=-Wl,-Tlink.x
18+
19+
cargo rustc --target $TARGET --example $ex --release -- \
20+
-C link-arg=-nostartfiles \
21+
-C link-arg=-Wl,-Tlink.x
22+
done
23+
24+
cargo rustc --target $TARGET --example device --features device -- \
25+
-C link-arg=-nostartfiles \
26+
-C link-arg=-Wl,-Tlink.x
27+
28+
cargo rustc --target $TARGET --example device --features device --release -- \
29+
-C link-arg=-nostartfiles \
30+
-C link-arg=-Wl,-Tlink.x
31+
fi
32+
}
33+
34+
main

Diff for: device.x

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* Sample device.x file */
2+
PROVIDE(WWDG = DefaultHandler);
3+
PROVIDE(PVD = DefaultHandler);

Diff for: examples/device.rs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//! Manually create the interrupts portion of the vector table
2+
3+
#![deny(unsafe_code)]
4+
#![deny(warnings)]
5+
#![no_main]
6+
#![no_std]
7+
8+
#[macro_use(entry, exception)]
9+
extern crate cortex_m_rt as rt;
10+
extern crate panic_semihosting;
11+
12+
use rt::ExceptionFrame;
13+
14+
// the program entry point
15+
entry!(main);
16+
17+
fn main() -> ! {
18+
loop {}
19+
}
20+
21+
// the hard fault handler
22+
exception!(HardFault, hard_fault);
23+
24+
fn hard_fault(_ef: &ExceptionFrame) -> ! {
25+
loop {}
26+
}
27+
28+
// the default exception handler
29+
exception!(*, default_handler);
30+
31+
fn default_handler(_irqn: i16) {}
32+
33+
// interrupts portion of the vector table
34+
pub union Vector {
35+
handler: unsafe extern "C" fn(),
36+
reserved: usize,
37+
}
38+
39+
extern "C" {
40+
fn WWDG();
41+
fn PVD();
42+
}
43+
44+
#[link_section = ".vector_table.interrupts"]
45+
#[no_mangle]
46+
pub static __INTERRUPTS: [Vector; 3] = [
47+
Vector { handler: WWDG },
48+
Vector { reserved: 0 },
49+
Vector { handler: PVD },
50+
];

Diff for: examples/main.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//! Directly plug a `main` symbol instead of using `entry!`
2+
3+
#![deny(warnings)]
4+
#![no_main]
5+
#![no_std]
6+
7+
#[macro_use(exception)]
8+
extern crate cortex_m_rt as rt;
9+
extern crate panic_semihosting;
10+
11+
use rt::ExceptionFrame;
12+
13+
#[no_mangle]
14+
pub unsafe extern "C" fn main() -> ! {
15+
loop {}
16+
}
17+
18+
// the hard fault handler
19+
exception!(HardFault, hard_fault);
20+
21+
fn hard_fault(_ef: &ExceptionFrame) -> ! {
22+
loop {}
23+
}
24+
25+
// the default exception handler
26+
exception!(*, default_handler);
27+
28+
fn default_handler(_irqn: i16) {}

Diff for: examples/minimal.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//! Minimal `cortex-m-rt` based program
2+
3+
#![deny(unsafe_code)]
4+
#![deny(warnings)]
5+
#![no_main]
6+
#![no_std]
7+
8+
#[macro_use(entry, exception)]
9+
extern crate cortex_m_rt as rt;
10+
extern crate panic_semihosting;
11+
12+
use rt::ExceptionFrame;
13+
14+
// the program entry point
15+
entry!(main);
16+
17+
fn main() -> ! {
18+
loop {}
19+
}
20+
21+
// the hard fault handler
22+
exception!(HardFault, hard_fault);
23+
24+
fn hard_fault(_ef: &ExceptionFrame) -> ! {
25+
loop {}
26+
}
27+
28+
// the default exception handler
29+
exception!(*, default_handler);
30+
31+
fn default_handler(_irqn: i16) {}

0 commit comments

Comments
 (0)