Skip to content

Commit 4d8daf9

Browse files
authored
Merge pull request #2 from Neotron-Compute/more-apps
Add a fancy panic handler, and some more samples.
2 parents 0a4973e + 671aae1 commit 4d8daf9

File tree

21 files changed

+227
-38
lines changed

21 files changed

+227
-38
lines changed

.github/workflows/build.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ jobs:
1818
- name: Add targets
1919
run: |
2020
rustup target add thumbv6m-none-eabi
21+
rustup target add thumbv7m-none-eabi
22+
rustup target add thumbv7em-none-eabi
23+
rustup component add llvm-tools
24+
cargo install cargo-binutils
2125
2226
- name: Build lib (native)
2327
run: |
@@ -27,10 +31,14 @@ jobs:
2731
run: |
2832
cargo test --verbose
2933
30-
- name: Build lib (Cortex-M0), OS mode
34+
- name: Build samples (Cortex-M0)
3135
run: |
32-
cargo build --verbose --target=thumbv6m-none-eabi --features=os
36+
cd samples && ./build.sh thumbv6m-none-eabi
3337
34-
- name: Build samples (Cortex-M0)
38+
- name: Build samples (Cortex-M3)
39+
run: |
40+
cd samples && ./build.sh thumbv7m-none-eabi
41+
42+
- name: Build samples (Cortex-M4)
3543
run: |
36-
cd samples && cargo build --verbose --target=thumbv6m-none-eabi
44+
cd samples && ./build.sh thumbv7em-none-eabi

Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,5 @@ neotron-ffi = "0.1"
1212
neotron-api = "0.1"
1313

1414
[features]
15-
# Enables functions the OS needs but an application does not
16-
os = []
17-
# Enables functions an application needs but the OS does not
18-
application = []
15+
# Prints panic info. Costs you about 14K of code.
16+
fancy-panic = []

samples/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
target
1+
*.bin
2+

samples/Cargo.toml

Lines changed: 0 additions & 8 deletions
This file was deleted.

samples/README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Build the application as follows:
88

99
```console
1010
$ cargo build --release --target=thumbv6m-none-eabi
11-
$ cargo objcopy --release --target=thumbv6m-none-eabi -- -O binary hello.bin
11+
$ rust-objcopy -O binary ./target/thumbv6m-none-eabi/release/hello hello.bin
1212
```
1313

1414
Then copy the resulting `hello.bin` file to an SD card and insert it into your Neotron system. You can load the application with something like:
@@ -18,10 +18,10 @@ Then copy the resulting `hello.bin` file to an SD card and insert it into your N
1818
> run
1919
```
2020

21-
If you don't have `cargo-binutils` installed (which adds the `objcopy` sub-command), install it with:
21+
If you don't have `rust-objcopy` installed, install it with:
2222

2323
```console
24-
$ cargo install cargo-binutils
24+
$ rustup component add llvm-tools
2525
```
2626

2727
## List of Sample Applications
@@ -30,3 +30,10 @@ $ cargo install cargo-binutils
3030

3131
This is a basic "Hello World" application. It prints the string "Hello, world" to *standard output* and then exits with an exit code of 0.
3232

33+
## [`panic`](./panic)
34+
35+
This application panics, printing a nice panic message.
36+
37+
## [`fault`](./fault)
38+
39+
This application generates a Hard Fault.

samples/build.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
TARGET=${1:-thumbv6m-none-eabi}
6+
7+
echo "Building for ${TARGET}"
8+
for program in panic hello fault; do
9+
( cd ${program} && cargo build --target=${TARGET} --release )
10+
rust-objcopy -O binary ./${program}/target/${TARGET}/release/${program} ${program}.bin
11+
done

samples/fault/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

samples/fault/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "fault"
3+
version = "0.1.0"
4+
edition = "2021"
5+
license = "MIT OR Apache-2.0"
6+
authors = ["Jonathan 'theJPster' Pallant <[email protected]>"]
7+
description = "Hello World for Neotron systems"
8+
9+
[dependencies]
10+
neotron-sdk = { path = "../.." }
11+
12+
[profile.dev]
13+
panic = "abort"
14+
15+
[profile.release]
16+
panic = "unwind"
17+
opt-level = "z"
18+
lto = "fat"

samples/fault/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Fault
2+
3+
A basic *faulting* application for Neotron systems. This program will jump to
4+
the address 0xDEADC0DE, which will cause a Hard Fault.
5+
6+
See the general sample application [README](../README.md) for compilation instructions.
7+
8+
## Licence
9+
10+
Copyright (c) The Neotron Developers, 2023
11+
12+
Licensed under either [MIT](../../LICENSE-MIT) or [Apache-2.0](../../LICENSE-APACHE) at
13+
your option.
14+
15+
## Contribution
16+
17+
Unless you explicitly state otherwise, any contribution intentionally submitted
18+
for inclusion in the work by you shall be licensed as above, without any
19+
additional terms or conditions.

samples/fault/build.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use std::env;
2+
use std::fs::File;
3+
use std::io::Write;
4+
use std::path::PathBuf;
5+
6+
fn main() {
7+
// Put `neotron-cortex-m.ld` in our output directory and ensure it's
8+
// on the linker search path.
9+
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
10+
File::create(out.join("neotron-cortex-m.ld"))
11+
.unwrap()
12+
.write_all(include_bytes!("../neotron-cortex-m.ld"))
13+
.unwrap();
14+
println!("cargo:rustc-link-search={}", out.display());
15+
16+
// By default, Cargo will re-run a build script whenever
17+
// any file in the project changes. By specifying `neotron-cortex-m.ld`
18+
// here, we ensure the build script is only re-run when
19+
// `neotron-cortex-m.ld` is changed.
20+
println!("cargo:rerun-if-changed=../neotron-cortex-m.ld");
21+
}

0 commit comments

Comments
 (0)