Skip to content

Commit e064949

Browse files
bors[bot]sekineh
andcommitted
Merge #128
128: Add qemu example and run in CI r=japaric a=sekineh As @japaric has suggested I ported `lm3s6965evb/src/main.rs` into `example/qemu.rs`. All errors were fixed, ~but qemu never exits automatically~ `qemu` prints text and exits. ``` sekineh@sekineh-VirtualBox:~/cortex-m-rt_me$ cargo run --example qemu --target thumbv7m-none-eabi Compiling cortex-m-rt v0.6.3 (file:///home/sekineh/cortex-m-rt_me) Finished dev [unoptimized + debuginfo] target(s) in 0.17s Running `qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel target/thumbv7m-none-eabi/debug/examples/qemu` x = 42 sekineh@sekineh-VirtualBox:~/cortex-m-rt_me$ ``` ## supported targets - thumbv6m-none-eabi - thumbv7m-none-eabi ## code size ~code size is 0, which is apparently wrong:~ ``` sekineh@sekineh-VirtualBox:~/cortex-m-rt_me$ size target/thumbv7m-none-eabi/debug/examples/qemu text data bss dec hex filename 10776 0 0 10776 2a18 target/thumbv7m-none-eabi/debug/examples/qemu ``` ## code size (original) (deleted; different compiler version) Co-authored-by: Hideki Sekine <[email protected]>
2 parents cad55f6 + f1f5176 commit e064949

File tree

7 files changed

+94
-31
lines changed

7 files changed

+94
-31
lines changed

cortex-m-rt/.cargo/config

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[target.thumbv7m-none-eabi]
2+
# uncomment this to make `cargo run` execute programs on QEMU
3+
runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"
4+
5+
[target.thumbv6m-none-eabi]
6+
# uncomment this to make `cargo run` execute programs on QEMU
7+
# For now, we use cortex-m3 instead of cortex-m0 which are not supported by QEMU
8+
runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"
9+
10+
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
11+
# uncomment ONE of these three option to make `cargo run` start a GDB session
12+
# which option to pick depends on your system
13+
# runner = "arm-none-eabi-gdb -q -x openocd.gdb"
14+
# runner = "gdb-multiarch -q -x openocd.gdb"
15+
# runner = "gdb -q -x openocd.gdb"
16+
17+
rustflags = [
18+
# LLD (shipped with the Rust toolchain) is used as the default linker
19+
"-C", "link-arg=-Tlink.x",
20+
21+
# if you run into problems with LLD switch to the GNU linker by commenting out
22+
# this line
23+
# "-C", "linker=arm-none-eabi-ld",
24+
25+
# if you need to link to pre-compiled C libraries provided by a C toolchain
26+
# use GCC as the linker by commenting out both lines above and then
27+
# uncommenting the three lines below
28+
# "-C", "linker=arm-none-eabi-gcc",
29+
# "-C", "link-arg=-Wl,-Tlink.x",
30+
# "-C", "link-arg=-nostartfiles",
31+
]

cortex-m-rt/.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ before_install: set -e
4646

4747
install:
4848
- bash ci/install.sh
49-
- export PATH="$PATH:$PWD/gcc/bin"
49+
- export PATH="$PATH:$PWD/gcc/bin:$PWD/qemu"
5050

5151
script:
5252
- bash ci/script.sh

cortex-m-rt/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
authors = ["Jorge Aparicio <[email protected]>"]
2+
authors = ["Jorge Aparicio <[email protected]>", "Hideki Sekine <[email protected]>"]
33
categories = ["embedded", "no-std"]
44
description = "Minimal runtime / startup for Cortex-M microcontrollers"
55
documentation = "https://rust-embedded.github.io/cortex-m-rt/"
@@ -17,6 +17,7 @@ cortex-m-rt-macros = { path = "macros", version = "0.1.1" }
1717
[dev-dependencies]
1818
cortex-m = "0.5.4"
1919
panic-halt = "0.2.0"
20+
cortex-m-semihosting = "0.3.1"
2021

2122
[dev-dependencies.rand]
2223
default-features = false

cortex-m-rt/ci/install.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ main() {
88
mkdir gcc
99

1010
curl -L https://developer.arm.com/-/media/Files/downloads/gnu-rm/7-2018q2/gcc-arm-none-eabi-7-2018-q2-update-linux.tar.bz2?revision=bc2c96c0-14b5-4bb4-9f18-bceb4050fee7?product=GNU%20Arm%20Embedded%20Toolchain,64-bit,,Linux,7-2018-q2-update | tar --strip-components=1 -C gcc -xj
11+
12+
mkdir qemu
13+
curl -L https://github.com/japaric/qemu-bin/raw/master/14.04/qemu-system-arm-2.12.0 > qemu/qemu-system-arm
14+
chmod +x qemu/qemu-system-arm
1115
}
1216

1317
main

cortex-m-rt/ci/script.sh

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ main() {
2020
minimal
2121
override-exception
2222
pre_init
23+
qemu
2324
rand
2425
state
2526
unsafe-default-handler
@@ -34,54 +35,51 @@ main() {
3435
# linking with GNU LD
3536
for ex in "${examples[@]}"; do
3637
cargo rustc --target $TARGET --example $ex -- \
37-
-C linker=arm-none-eabi-ld \
38-
-C link-arg=-Tlink.x
38+
-C linker=arm-none-eabi-ld
3939

4040
cargo rustc --target $TARGET --example $ex --release -- \
41-
-C linker=arm-none-eabi-ld \
42-
-C link-arg=-Tlink.x
41+
-C linker=arm-none-eabi-ld
4342
done
4443
for ex in "${fail_examples[@]}"; do
4544
! cargo rustc --target $TARGET --example $ex -- \
46-
-C linker=arm-none-eabi-ld \
47-
-C link-arg=-Tlink.x
45+
-C linker=arm-none-eabi-ld
4846

4947
! cargo rustc --target $TARGET --example $ex --release -- \
50-
-C linker=arm-none-eabi-ld \
51-
-C link-arg=-Tlink.x
48+
-C linker=arm-none-eabi-ld
5249
done
5350

5451
cargo rustc --target $TARGET --example device --features device -- \
55-
-C linker=arm-none-eabi-ld \
56-
-C link-arg=-Tlink.x
52+
-C linker=arm-none-eabi-ld
5753

5854
cargo rustc --target $TARGET --example device --features device --release -- \
59-
-C linker=arm-none-eabi-ld \
60-
-C link-arg=-Tlink.x
55+
-C linker=arm-none-eabi-ld
6156

6257
# linking with rustc's LLD
6358
for ex in "${examples[@]}"; do
64-
cargo rustc --target $TARGET --example $ex -- \
65-
-C link-arg=-Tlink.x
66-
67-
cargo rustc --target $TARGET --example $ex --release -- \
68-
-C link-arg=-Tlink.x
59+
cargo rustc --target $TARGET --example $ex
60+
cargo rustc --target $TARGET --example $ex --release
6961
done
7062
for ex in "${fail_examples[@]}"; do
71-
! cargo rustc --target $TARGET --example $ex -- \
72-
-C link-arg=-Tlink.x
73-
74-
! cargo rustc --target $TARGET --example $ex --release -- \
75-
-C link-arg=-Tlink.x
63+
! cargo rustc --target $TARGET --example $ex
64+
! cargo rustc --target $TARGET --example $ex --release
7665
done
7766

78-
cargo rustc --target $TARGET --example device --features device -- \
79-
-C link-arg=-Tlink.x
80-
81-
cargo rustc --target $TARGET --example device --features device --release -- \
82-
-C link-arg=-Tlink.x
67+
cargo rustc --target $TARGET --example device --features device
68+
cargo rustc --target $TARGET --example device --features device --release
8369
fi
8470

71+
case $TARGET in
72+
thumbv6m-none-eabi|thumbv7m-none-eabi)
73+
# linking with GNU LD
74+
env RUSTFLAGS="-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x" cargo run --target $TARGET --example qemu | grep "x = 42"
75+
env RUSTFLAGS="-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x" cargo run --target $TARGET --example qemu --release | grep "x = 42"
76+
77+
# linking with rustc's LLD
78+
cargo run --target $TARGET --example qemu | grep "x = 42"
79+
cargo run --target $TARGET --example qemu --release | grep "x = 42"
80+
;;
81+
esac
82+
8583
if [ $TARGET = x86_64-unknown-linux-gnu ]; then
8684
./check-blobs.sh
8785
fi

cortex-m-rt/examples/qemu.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// #![feature(stdsimd)]
2+
#![no_main]
3+
#![no_std]
4+
5+
extern crate cortex_m;
6+
7+
extern crate cortex_m_rt as rt;
8+
extern crate cortex_m_semihosting as semihosting;
9+
extern crate panic_halt;
10+
11+
use core::fmt::Write;
12+
use cortex_m::asm;
13+
use rt::entry;
14+
15+
#[entry]
16+
fn main() -> ! {
17+
let x = 42;
18+
19+
loop {
20+
asm::nop();
21+
22+
// write something through semihosting interface
23+
let mut hstdout = semihosting::hio::hstdout().unwrap();
24+
write!(hstdout, "x = {}\n", x);
25+
26+
// exit from qemu
27+
semihosting::debug::exit(semihosting::debug::EXIT_SUCCESS);
28+
}
29+
}

cortex-m-rt/memory.x

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ MEMORY
77
{
88
/* FLASH and RAM are mandatory memory regions */
99
/* Update examples/data_overflow.rs if you change these sizes. */
10-
FLASH : ORIGIN = 0x08000000, LENGTH = 64K
11-
RAM : ORIGIN = 0x20000000, LENGTH = 20K
10+
FLASH : ORIGIN = 0x00000000, LENGTH = 256K
11+
RAM : ORIGIN = 0x20000000, LENGTH = 64K
1212

1313
/* More memory regions can declared: for example this is a second RAM region */
1414
/* CCRAM : ORIGIN = 0x10000000, LENGTH = 8K */

0 commit comments

Comments
 (0)