Skip to content

Commit b2a1190

Browse files
Adds additional Armv8-R AArch64 example programs, along with a single-core critical section implementation. The examples expand upon the existing Hello, World example and demonstrate the use of the Arm Generic Interrupt Controller and logging using defmt via the PL011 UART.
Using https://review.trustedfirmware.org/c/arm-firmware-crates/arm-fvp-base-pac/+/49345/2 as a patch to arm-fvp-base-pac, temporarily.
1 parent 5ad8c0b commit b2a1190

18 files changed

Lines changed: 836 additions & 4 deletions

File tree

.github/workflows/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ jobs:
9191
- run: cargo clippy --target=${{ matrix.target }}
9292

9393
armv8r-examples:
94-
runs-on: ubuntu-latest
9594
name: Build Armv8-R Examples
9695
steps:
9796
- uses: actions/checkout@v6

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ exclude = [
2121

2222
[dependencies]
2323
tock-registers = { version = "0.10.0", default-features = false } # Use it as interface-only library.
24+
critical-section = { version = "1.2.0", features = ["restore-state-u8"], optional = true }
25+
26+
[features]
27+
critical-section-single-core = ["critical-section"]

examples/armv8-r/.cargo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ runner = "FVP_BaseR_AEMv8R -f fvp_cfg.txt"
66

77
[unstable]
88
build-std = ["core", "compiler_builtins"]
9+
10+
[env]
11+
DEFMT_LOG = "info"

examples/armv8-r/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
!/Cargo.lock
2+
/uart0.out

examples/armv8-r/Cargo.lock

Lines changed: 252 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/armv8-r/Cargo.toml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@ name = "armv8-r"
55
publish = false
66

77
[dependencies]
8-
aarch64-rt = { version = "=0.4.0", default-features = false }
9-
aarch64-cpu.path = "../.."
8+
aarch64-rt = { version = "=0.4.0", default-features = false, features = [
9+
"exceptions",
10+
] }
11+
# NB: Point this at Github once https://review.trustedfirmware.org/c/arm-firmware-crates/arm-fvp-base-pac/+/49345 is accepted
12+
arm-fvp-base-pac = { git = "https://review.trustedfirmware.org/arm-firmware-crates/arm-fvp-base-pac", rev = "refs/changes/45/49345/2", default-features = false, features = [
13+
"swapped-memory-layout",
14+
] }
15+
arm-gic = "0.7.2"
16+
aarch64-cpu = { path = "../..", features = ["critical-section-single-core"] }
17+
critical-section = "1.2.0"
18+
defmt = "1.0.1"
1019
semihosting = { version = "0.1.24", default-features = false, features = [
1120
"panic-handler",
1221
"stdio",

examples/armv8-r/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ This folder contains example programs for the Armv8-R AArch64 architecture.
1818

1919
[1]: https://developer.arm.com/Tools%20and%20Software/Fixed%20Virtual%20Platforms/Arm%20Architecture%20FVPs
2020

21+
* (Optional) `defmt-print` to decode the defmt logs produced by some examples.
22+
The tool can be installed with the following command:
23+
24+
``` console
25+
$ cargo install defmt-print --version 1.0.0 --locked
26+
```
27+
2128
## Running the examples
2229

2330
All commands in this section are meant to be executed using this directory as the working directory.
@@ -33,6 +40,54 @@ Hello, world! running from EL2
3340
static variables: X=0, Y=1
3441
```
3542

43+
### `interrupts`
44+
45+
This program showcases nested interrupt handling.
46+
47+
``` console
48+
$ cargo run --bin interrupts
49+
start of main
50+
> irq_current()
51+
Handling SGI 1
52+
SGI1 handler
53+
before raising SGI0
54+
> irq_current()
55+
Handling SGI 0
56+
SGI0 handler
57+
Handled SGI 0
58+
< irq_current()
59+
after raising SGI0
60+
Handled SGI 1
61+
< irq_current()
62+
end of main
63+
```
64+
65+
### `defmt`
66+
67+
This program showcases defmt logging.
68+
The defmt logs are output via UART0 (serial port 0) and not printed to the console.
69+
70+
``` console
71+
$ cargo run --bin defmt
72+
before defmt log
73+
before raise SGI0
74+
after raise SGI0
75+
> irq_current()
76+
Handling SGI 0
77+
Handled SGI 0
78+
< irq_current()
79+
after defmt log
80+
```
81+
82+
The FVP will create a file named `uart0.out` in the current directory that contains the UART0 output of the program.
83+
This file is defmt-encoded and can be decoded with the following command:
84+
85+
``` console
86+
$ cat uart0.out | defmt-print -e target/aarch64v8r-unknown-none/debug/defmt
87+
INFO >>> 42 <<<
88+
INFO SGI0 handler
89+
```
90+
3691
## License
3792

3893
Licensed under either of

0 commit comments

Comments
 (0)