Skip to content

Commit e3217ad

Browse files
bors[bot]japaric
andcommitted
Merge #88
88: make compilable on stable r=japaric a=japaric This PR makes this crate compilable on stable when the "inline-asm" and "singleton" Cargo features are disabled (they are enabled by default to maintain backwards compatibility). The main change has been replacing almost (\*) all inline `asm!` invocations with FFI calls into external assembly files. (\*) Stuff that has not been converted into external assembly file and thus is not available on stable: - Reading the (A)PSR register (I'm not sure if this will work with the extra function call overhead) - Reading and writing the Link Register (LR) - Reading and writing the Program Counter (PC) I would appreciate if someone checked that all the stuff that's now using FFI calls has the same semantics as the inline `asm!` version. Co-authored-by: Jorge Aparicio <[email protected]>
2 parents 00d6faa + 05bbc3b commit e3217ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+946
-300
lines changed

.travis.yml

+48-1
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,62 @@ language: rust
33
matrix:
44
include:
55
- env: TARGET=x86_64-unknown-linux-gnu
6-
rust: nightly
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+
735
- env: TARGET=thumbv6m-none-eabi
836
rust: nightly
37+
addons:
38+
apt:
39+
packages:
40+
- gcc-arm-none-eabi
41+
942
- env: TARGET=thumbv7m-none-eabi
1043
rust: nightly
44+
addons:
45+
apt:
46+
packages:
47+
- gcc-arm-none-eabi
48+
1149
- env: TARGET=thumbv7em-none-eabi
1250
rust: nightly
51+
addons:
52+
apt:
53+
packages:
54+
- gcc-arm-none-eabi
55+
1356
- env: TARGET=thumbv7em-none-eabihf
1457
rust: nightly
58+
addons:
59+
apt:
60+
packages:
61+
- gcc-arm-none-eabi
1562

1663
before_install: set -e
1764

CHANGELOG.md

+44-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,50 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8-
## [Unreleased]
8+
## [v0.5.0] - 2018-05-11
9+
10+
### Added
11+
12+
- `DebugMonitor` and `SecureFault` variants to the `Exception` enumeration.
13+
14+
- An optional `"inline-asm"` feature
15+
16+
### Changed
17+
18+
- [breaking-change] This crate now requires `arm-none-eabi-gcc` to be installed and available in
19+
`$PATH` when built with the `"inline-asm"` feature disabled (which is disabled by default).
20+
21+
- [breaking-change] The `register::{apsr,lr,pc}` modules are now behind the `"inline-asm"` feature.
22+
23+
- [breaking-change] Some variants of the `Exception` enumeration are no longer available on
24+
`thumbv6m-none-eabi`. See API docs for details.
25+
26+
- [breaking-change] Several of the variants of the `Exception` enumeration have been renamed to
27+
match the CMSIS specification.
28+
29+
- [breaking-change] fixed typo in `shcrs` field of `scb::RegisterBlock`; it was previously named
30+
`shpcrs`.
31+
32+
- [breaking-change] removed several fields from `scb::RegisterBlock` on ARMv6-M. These registers are
33+
not available on that sub-architecture.
34+
35+
- [breaking-change] changed the type of `scb::RegisterBlock.shpr` from `RW<u8>` to `RW<u32>` on
36+
ARMv6-M. These registers are word accessible only on that sub-architecture.
37+
38+
- [breaking-change] renamed the `mmar` field of `scb::RegisterBlock` to `mmfar` to match the CMSIS
39+
name.
40+
41+
- [breaking-change] removed the `iabr` field from `scb::RegisterBlock` on ARMv6-M. This register is
42+
not available on that sub-architecture.
43+
44+
- [breaking-change] removed several fields from `cpuid::RegisterBlock` on ARMv6-M. These registers
45+
are not available on that sub-architecture.
46+
47+
### Removed
48+
49+
- [breaking-change] The `exception` module has been removed. A replacement for `Exception::active`
50+
can be found in `SCB::vect_active`. A modified version `exception::Exception` can be found in the
51+
`peripheral::scb` module.
952

1053
## [v0.4.3] - 2018-01-25
1154

Cargo.toml

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

1215
[dependencies]
13-
aligned = "0.1.1"
14-
bare-metal = "0.1.0"
16+
aligned = "0.2.0"
17+
bare-metal = "0.2.0"
1518
volatile-register = "0.2.0"
16-
untagged-option = "0.1.1"
1719

1820
[features]
1921
cm7-r0p1 = []
22+
inline-asm = []

asm/basepri_max-cm7-r0p1.s

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.global __basepri_max
2+
.syntax unified
3+
__basepri_max:
4+
mrs r1, PRIMASK
5+
cpsid i
6+
tst.w r1, #1
7+
msr BASEPRI_MAX, r0
8+
it ne
9+
bxne lr
10+
cpsie i
11+
bx lr

asm/basepri_max.s

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.global __basepri_max
2+
__basepri_max:
3+
msr BASEPRI_MAX, r0
4+
bx lr

asm/basepri_r.s

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.global __basepri_r
2+
__basepri_r:
3+
mrs r0, BASEPRI
4+
bx lr

asm/basepri_w-cm7-r0p1.s

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.global __basepri_w
2+
.syntax unified
3+
__basepri_w:
4+
mrs r1, PRIMASK
5+
cpsid i
6+
tst.w r1, #1
7+
msr BASEPRI, r0
8+
it ne
9+
bxne lr
10+
cpsie i
11+
bx lr

asm/basepri_w.s

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.global __basepri_w
2+
__basepri_w:
3+
msr BASEPRI, r0
4+
bx lr

asm/bkpt.s

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.global __bkpt
2+
__bkpt:
3+
bkpt
4+
bx lr

asm/control.s

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.global __control
2+
__control:
3+
mrs r0, CONTROL
4+
bx lr

asm/cpsid.s

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.global __cpsid
2+
__cpsid:
3+
cpsid i
4+
bx lr

asm/cpsie.s

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.global __cpsie
2+
__cpsie:
3+
cpsie i
4+
bx lr

asm/dmb.s

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.global __dmb
2+
__dmb:
3+
dmb 0xF
4+
bx lr

asm/dsb.s

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.global __dsb
2+
__dsb:
3+
dsb 0xF
4+
bx lr

asm/faultmask.s

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.global __faultmask
2+
__faultmask:
3+
mrs r0, FAULTMASK
4+
bx lr

asm/isb.s

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.global __isb
2+
__isb:
3+
isb 0xF
4+
bx lr

asm/msp_r.s

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.global __msp_r
2+
__msp_r:
3+
mrs r0, MSP
4+
bx lr

asm/msp_w.s

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.global __msp_w
2+
__msp_w:
3+
msr MSP, r0
4+
bx lr

asm/nop.s

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.global __nop
2+
__nop:
3+
bx lr

asm/primask.s

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.global __primask
2+
__primask:
3+
mrs r0, PRIMASK
4+
bx lr

asm/psp_r.s

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.global __psp_r
2+
__psp_r:
3+
mrs r0, PSP
4+
bx lr

asm/psp_w.s

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.global __psp_w
2+
__psp_w:
3+
msr PSP, r0
4+
bx lr

asm/sev.s

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.global __sev
2+
__sev:
3+
sev
4+
bx lr

asm/wfe.s

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.global __wfe
2+
__wfe:
3+
wfe
4+
bx lr

asm/wfi.s

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.global __wfi
2+
__wfi:
3+
wfi
4+
bx lr

build.rs

+41-1
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,58 @@
1+
extern crate cc;
2+
13
use std::env;
24

35
fn main() {
46
let target = env::var("TARGET").unwrap();
57

8+
if target.starts_with("thumb") && env::var_os("CARGO_FEATURE_INLINE_ASM").is_none() {
9+
// NOTE we need to place each routine in a separate assembly file or the linker won't be
10+
// able to discard the unused routines
11+
let mut build = cc::Build::new();
12+
build
13+
.file("asm/basepri_r.s")
14+
.file("asm/bkpt.s")
15+
.file("asm/control.s")
16+
.file("asm/cpsid.s")
17+
.file("asm/cpsie.s")
18+
.file("asm/dmb.s")
19+
.file("asm/dsb.s")
20+
.file("asm/faultmask.s")
21+
.file("asm/isb.s")
22+
.file("asm/msp_r.s")
23+
.file("asm/msp_w.s")
24+
.file("asm/nop.s")
25+
.file("asm/primask.s")
26+
.file("asm/psp_r.s")
27+
.file("asm/psp_w.s")
28+
.file("asm/sev.s")
29+
.file("asm/wfe.s")
30+
.file("asm/wfi.s");
31+
32+
if env::var_os("CARGO_FEATURE_CM7_R0P1").is_some() {
33+
build.file("asm/basepri_max-cm7-r0p1.s");
34+
build.file("asm/basepri_w-cm7-r0p1.s");
35+
} else {
36+
build.file("asm/basepri_max.s");
37+
build.file("asm/basepri_w.s");
38+
}
39+
40+
build.compile("asm");
41+
}
42+
643
if target.starts_with("thumbv6m-") {
44+
println!("cargo:rustc-cfg=cortex_m");
745
println!("cargo:rustc-cfg=armv6m");
846
} else if target.starts_with("thumbv7m-") {
47+
println!("cargo:rustc-cfg=cortex_m");
948
println!("cargo:rustc-cfg=armv7m");
1049
} else if target.starts_with("thumbv7em-") {
50+
println!("cargo:rustc-cfg=cortex_m");
1151
println!("cargo:rustc-cfg=armv7m");
1252
//println!("cargo:rustc-cfg=armv7em");
1353
}
1454

15-
if target.ends_with("eabihf") {
55+
if target.ends_with("-eabihf") {
1656
println!("cargo:rustc-cfg=has_fpu");
1757
}
1858
}

ci/script.sh

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
set -euxo pipefail
22

33
main() {
4+
cargo check --target $TARGET
5+
6+
if [ $TRAVIS_RUST_VERSION = nightly ]; then
7+
cargo check --target $TARGET --features inline-asm
8+
fi
9+
410
case $TARGET in
511
thumbv7em-none-eabi*)
612
cargo check --target $TARGET --features cm7-r0p1
7-
cargo check --target $TARGET
13+
14+
if [ $TRAVIS_RUST_VERSION = nightly ]; then
15+
cargo check --target $TARGET --features 'cm7-r0p1 inline-asm'
16+
fi
817
;;
18+
919
thumbv*-none-eabi*)
10-
cargo check --target $TARGET
1120
;;
12-
*)
21+
22+
x86_64-unknown-linux-gnu)
1323
cargo test --target $TARGET
1424
;;
1525
esac

0 commit comments

Comments
 (0)