Skip to content

Commit a03f997

Browse files
bors[bot]japaric
andcommitted
Merge #203
203: cortex-m: generate code that compiles on stable r=japaric a=japaric This is still missing some stuff: - svd2rust must now generate an interrupts.x linker script and a build script that puts the linker script somewhere the linker can find it. See japaric/stm32f103xx#24 for a sample of what those files look like. - we have to decide how to organize the svd2rust output. It probably makes sense to generate 3 files on $PWD (lib.rs, build.rs, interrupts.x) for Cortex-M and a single lib.rs for the other targets. - I probably broke the other targets; need to test them Co-authored-by: Jorge Aparicio <[email protected]>
2 parents f271405 + 692220e commit a03f997

File tree

8 files changed

+374
-250
lines changed

8 files changed

+374
-250
lines changed

.travis.yml

+11-11
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@ matrix:
1212
include:
1313
# Nightly, for testing
1414
- env: TARGET=x86_64-unknown-linux-gnu VENDOR=Atmel
15-
rust: nightly
15+
1616
- env: TARGET=x86_64-unknown-linux-gnu VENDOR=Freescale
17-
rust: nightly
17+
1818
- env: TARGET=x86_64-unknown-linux-gnu VENDOR=Fujitsu
19-
rust: nightly
19+
2020
- env: TARGET=x86_64-unknown-linux-gnu VENDOR=Holtek
21-
rust: nightly
21+
2222
- env: TARGET=x86_64-unknown-linux-gnu VENDOR=Nordic
23-
rust: nightly
23+
2424
- env: TARGET=x86_64-unknown-linux-gnu VENDOR=Nuvoton
25-
rust: nightly
25+
2626
- env: TARGET=x86_64-unknown-linux-gnu VENDOR=NXP
27-
rust: nightly
27+
2828
- env: TARGET=x86_64-unknown-linux-gnu VENDOR=SiliconLabs
29-
rust: nightly
29+
3030
- env: TARGET=x86_64-unknown-linux-gnu VENDOR=Spansion
31-
rust: nightly
31+
3232
- env: TARGET=x86_64-unknown-linux-gnu VENDOR=STMicro
33-
rust: nightly
33+
3434
- env: TARGET=x86_64-unknown-linux-gnu VENDOR=Toshiba
35-
rust: nightly
35+
3636
- env: TARGET=x86_64-unknown-linux-gnu VENDOR=OTHER
3737
rust: nightly
3838

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ keywords = [
1919
license = "MIT OR Apache-2.0"
2020
name = "svd2rust"
2121
repository = "https://github.com/japaric/svd2rust"
22-
version = "0.12.1"
22+
version = "0.13.0"
2323

2424
[[bin]]
2525
doc = false

ci/install.sh

+1-8
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,7 @@ main() {
1919
--git japaric/cross \
2020
--tag $tag
2121

22-
if [ ! -z ${VENDOR-} ]; then
23-
curl -LSfs https://japaric.github.io/trust/install.sh | \
24-
sh -s -- \
25-
--crate rustfmt \
26-
--force \
27-
--git japaric/rustfmt-bin \
28-
--tag v0.8.4-20170605
29-
fi
22+
rustup component add rustfmt-preview
3023
}
3124

3225
main

ci/script.sh

+56-8
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@ test_svd() {
88
)
99

1010
# NOTE we care about errors in svd2rust, but not about errors / warnings in rustfmt
11-
target/$TARGET/release/svd2rust -i $td/${1}.svd | \
12-
( rustfmt 2>/dev/null > $td/src/lib.rs || true )
11+
local cwd=$(pwd)
12+
pushd $td
13+
$cwd/target/$TARGET/release/svd2rust -i ${1}.svd
14+
15+
mv lib.rs src/lib.rs
16+
17+
# ignore rustfmt errors
18+
rustfmt src/lib.rs || true
19+
popd
1320

1421
cargo check --manifest-path $td/Cargo.toml
1522
}
@@ -34,18 +41,17 @@ main() {
3441

3542
# test crate
3643
cargo init --name foo $td
37-
echo 'bare-metal = "0.1.0"' >> $td/Cargo.toml
38-
echo 'cortex-m = "0.4.0"' >> $td/Cargo.toml
39-
echo 'cortex-m-rt = "0.3.0"' >> $td/Cargo.toml
44+
echo 'cortex-m = "0.5.0"' >> $td/Cargo.toml
45+
echo 'cortex-m-rt = "0.5.0"' >> $td/Cargo.toml
4046
echo 'vcell = "0.1.0"' >> $td/Cargo.toml
41-
echo 'msp430 = "0.1.0"' >> $td/Cargo.toml
42-
# echo 'riscv = "0.1.4"' >> $td/Cargo.toml
43-
# echo 'riscv-rt = "0.1.3"' >> $td/Cargo.toml
4447
echo '[profile.dev]' >> $td/Cargo.toml
4548
echo 'incremental = false' >> $td/Cargo.toml
4649

4750
case $VENDOR in
4851
Atmel)
52+
echo '[dependencies.bare-metal]' >> $td/Cargo.toml
53+
echo 'version = "0.2.0"' >> $td/Cargo.toml
54+
4955
# BAD-SVD missing resetValue
5056
# test_svd AT91SAM9CN11
5157
# test_svd AT91SAM9CN12
@@ -129,6 +135,9 @@ main() {
129135
;;
130136

131137
Freescale)
138+
echo '[dependencies.bare-metal]' >> $td/Cargo.toml
139+
echo 'version = "0.2.0"' >> $td/Cargo.toml
140+
132141
# BAD-SVD bad enumeratedValue value
133142
# test_svd MKV56F20
134143
# test_svd MKV56F22
@@ -277,6 +286,9 @@ main() {
277286
;;
278287

279288
Fujitsu)
289+
echo '[dependencies.bare-metal]' >> $td/Cargo.toml
290+
echo 'version = "0.2.0"' >> $td/Cargo.toml
291+
280292
# OK
281293
test_svd MB9AF10xN
282294
test_svd MB9AF10xR
@@ -381,6 +393,9 @@ main() {
381393
;;
382394

383395
Holtek)
396+
echo '[dependencies.bare-metal]' >> $td/Cargo.toml
397+
echo 'version = "0.2.0"' >> $td/Cargo.toml
398+
384399
# OK
385400
test_svd ht32f125x
386401
test_svd ht32f175x
@@ -389,6 +404,18 @@ main() {
389404

390405
# test other targets (architectures)
391406
OTHER)
407+
echo '[dependencies.bare-metal]' >> $td/Cargo.toml
408+
echo 'version = "0.1.0"' >> $td/Cargo.toml
409+
410+
echo '[dependencies.msp430]' >> $td/Cargo.toml
411+
echo 'version = "0.1.0"' >> $td/Cargo.toml
412+
413+
# echo '[dependencies.riscv]' >> $td/Cargo.toml
414+
# echo 'version = "0.2.0"' >> $td/Cargo.toml
415+
416+
# echo '[dependencies.riscv-rt]' >> $td/Cargo.toml
417+
# echo 'version = "0.2.0"' >> $td/Cargo.toml
418+
392419
(
393420
cd $td &&
394421
curl -LO \
@@ -415,6 +442,9 @@ main() {
415442
;;
416443

417444
Nordic)
445+
echo '[dependencies.bare-metal]' >> $td/Cargo.toml
446+
echo 'version = "0.2.0"' >> $td/Cargo.toml
447+
418448
# BAD-SVD two enumeratedValues have the same value
419449
# test_svd nrf52
420450

@@ -423,12 +453,18 @@ main() {
423453
;;
424454

425455
Nuvoton)
456+
echo '[dependencies.bare-metal]' >> $td/Cargo.toml
457+
echo 'version = "0.2.0"' >> $td/Cargo.toml
458+
426459
# OK
427460
test_svd M051_Series
428461
test_svd NUC100_Series
429462
;;
430463

431464
NXP)
465+
echo '[dependencies.bare-metal]' >> $td/Cargo.toml
466+
echo 'version = "0.2.0"' >> $td/Cargo.toml
467+
432468
# BAD-SVD two enumeratedValues have the same name
433469
# test_svd LPC11Exx_v5
434470
# test_svd LPC11Uxx_v7
@@ -465,6 +501,9 @@ main() {
465501
;;
466502

467503
SiliconLabs)
504+
echo '[dependencies.bare-metal]' >> $td/Cargo.toml
505+
echo 'version = "0.2.0"' >> $td/Cargo.toml
506+
468507
# #99 regression tests
469508
test_svd SIM3C1x4_SVD
470509
test_svd SIM3C1x6_SVD
@@ -481,6 +520,9 @@ main() {
481520
;;
482521

483522
Spansion)
523+
echo '[dependencies.bare-metal]' >> $td/Cargo.toml
524+
echo 'version = "0.2.0"' >> $td/Cargo.toml
525+
484526
# OK
485527
test_svd MB9AF12xK
486528
test_svd MB9AF12xL
@@ -576,6 +618,9 @@ main() {
576618
;;
577619

578620
STMicro)
621+
echo '[dependencies.bare-metal]' >> $td/Cargo.toml
622+
echo 'version = "0.2.0"' >> $td/Cargo.toml
623+
579624
# OK
580625
test_svd STM32F030
581626
test_svd STM32F031x
@@ -626,6 +671,9 @@ main() {
626671
;;
627672

628673
Toshiba)
674+
echo '[dependencies.bare-metal]' >> $td/Cargo.toml
675+
echo 'version = "0.2.0"' >> $td/Cargo.toml
676+
629677
# BAD-SVD resetValue is bigger than the register size
630678
# test_svd M365
631679
# test_svd M367

src/generate/device.rs

+14-20
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use Target;
99
use generate::{interrupt, peripheral};
1010

1111
/// Whole device generation
12-
pub fn render(d: &Device, target: &Target, nightly: bool) -> Result<Vec<Tokens>> {
12+
pub fn render(d: &Device, target: &Target, nightly: bool, device_x: &mut String) -> Result<Vec<Tokens>> {
1313
let mut out = vec![];
1414

1515
let doc = format!(
@@ -27,7 +27,7 @@ pub fn render(d: &Device, target: &Target, nightly: bool) -> Result<Vec<Tokens>>
2727
});
2828
}
2929

30-
if *target != Target::None {
30+
if *target != Target::None && *target != Target::CortexM {
3131
out.push(quote! {
3232
#![cfg_attr(feature = "rt", feature(global_asm))]
3333
#![cfg_attr(feature = "rt", feature(use_extern_macros))]
@@ -37,15 +37,19 @@ pub fn render(d: &Device, target: &Target, nightly: bool) -> Result<Vec<Tokens>>
3737

3838
out.push(quote! {
3939
#![doc = #doc]
40-
#![allow(private_no_mangle_statics)]
4140
#![deny(missing_docs)]
4241
#![deny(warnings)]
4342
#![allow(non_camel_case_types)]
44-
#![feature(const_fn)]
45-
#![feature(try_from)]
4643
#![no_std]
4744
});
4845

46+
if *target != Target::CortexM {
47+
out.push(quote! {
48+
#![feature(const_fn)]
49+
#![feature(try_From)]
50+
});
51+
}
52+
4953
if nightly {
5054
out.push(quote! {
5155
#![feature(untagged_unions)]
@@ -58,8 +62,6 @@ pub fn render(d: &Device, target: &Target, nightly: bool) -> Result<Vec<Tokens>>
5862
extern crate cortex_m;
5963
#[cfg(feature = "rt")]
6064
extern crate cortex_m_rt;
61-
#[cfg(feature = "rt")]
62-
pub use cortex_m_rt::{default_handler, exception};
6365
});
6466
}
6567
Target::Msp430 => {
@@ -98,7 +100,7 @@ pub fn render(d: &Device, target: &Target, nightly: bool) -> Result<Vec<Tokens>>
98100
});
99101
}
100102

101-
out.extend(interrupt::render(d, target, &d.peripherals)?);
103+
out.extend(interrupt::render(target, &d.peripherals, device_x)?);
102104

103105
const CORE_PERIPHERALS: &[&str] = &[
104106
"CBP", "CPUID", "DCB", "DWT", "FPB", "FPU", "ITM", "MPU", "NVIC", "SCB", "SYST", "TPIU"
@@ -111,18 +113,10 @@ pub fn render(d: &Device, target: &Target, nightly: bool) -> Result<Vec<Tokens>>
111113
pub use cortex_m::peripheral::Peripherals as CorePeripherals;
112114
});
113115

114-
// NOTE re-export only core peripherals available on *all* Cortex-M devices
115-
// (if we want to re-export all core peripherals available for the target then we are going
116-
// to need to replicate the `#[cfg]` stuff that cortex-m uses and that would require all
117-
// device crates to define the custom `#[cfg]`s that cortex-m uses in their build.rs ...)
118116
out.push(quote! {
119-
pub use cortex_m::peripheral::CPUID;
120-
pub use cortex_m::peripheral::DCB;
121-
pub use cortex_m::peripheral::DWT;
122-
pub use cortex_m::peripheral::MPU;
123-
pub use cortex_m::peripheral::NVIC;
124-
pub use cortex_m::peripheral::SCB;
125-
pub use cortex_m::peripheral::SYST;
117+
pub use cortex_m::peripheral::{
118+
CBP, CPUID, DCB, DWT, FPB, FPU, ITM, MPU, NVIC, SCB, SYST, TPIU,
119+
};
126120
});
127121
}
128122

@@ -132,7 +126,6 @@ pub fn render(d: &Device, target: &Target, nightly: bool) -> Result<Vec<Tokens>>
132126
continue;
133127
}
134128

135-
136129
out.extend(peripheral::render(p, &d.peripherals, &d.defaults, nightly)?);
137130

138131
if p.registers
@@ -180,6 +173,7 @@ pub fn render(d: &Device, target: &Target, nightly: bool) -> Result<Vec<Tokens>>
180173
// NOTE `no_mangle` is used here to prevent linking different minor versions of the device
181174
// crate as that would let you `take` the device peripherals more than once (one per minor
182175
// version)
176+
#[allow(private_no_mangle_statics)]
183177
#[no_mangle]
184178
static mut DEVICE_PERIPHERALS: bool = false;
185179

0 commit comments

Comments
 (0)