Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example-code/native/stdout/src/bin/8_syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! Requires `RUSTFLAGS="-C panic=abort -lc"` (and nightly Rust for Linux targets).
//!
//! Runs on Aarch64 macOS, Aarch64 Linux and x86-64 Linux.
//! Runs on AArch64 macOS, AArch64 Linux and x86-64 Linux.

#![no_std]
#![no_main]
Expand Down
2 changes: 1 addition & 1 deletion example-code/nrf52/criticalup.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
manifest-version = 1

[products.ferrocene]
release = "stable-25.05.0"
release = "stable-26.05.0"
packages = [
"rustc-${rustc-host}",
"rust-std-${rustc-host}",
Expand Down
2 changes: 1 addition & 1 deletion example-code/qemu-aarch32v8r/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ runner = [
"--cpu",
"cortex-r52",
"--log-format",
"{[{L}]%bold} {s} {({ff}:{l:1})%dimmed}"
"oneline"
]

[build]
Expand Down
66 changes: 21 additions & 45 deletions example-code/qemu-aarch32v8r/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 38 additions & 26 deletions example-code/qemu-aarch32v8r/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ This repository contains a small example application that can be built using the

## Supported Platforms

Ferrocene is supported on *x86-64 Linux (glibc)*
(`x86_64-unknown-linux-gnu`) as the host platform, and *Armv8-R bare-metal*
(`armv8r-none-eabihf`) as a cross-compilation target.
Ferrocene is supported on [a number of host platforms]. We are using *Armv8-R
AArch32 bare-metal* (`armv8r-none-eabihf`) as a cross-compilation target.

[a number of host platforms]: https://public-docs.ferrocene.dev/main/user-manual/targets/index.html

You must first install Ferrocene by executing `criticalup install` inside this
folder. This will require a valid CriticalUp token - please see the [CriticalUp
Expand All @@ -21,44 +22,55 @@ option for `cargo`. You may also want a `rust-toolchain.toml` file to set
`ferrocene` as the default toolchain for this directory. You can copy
`rust-toolchain.toml.ferrocene` as a starting point.

This demo will also build with standard Rust. You can use `rustup` to obtain the
`armv8r-none-eabihf` target.

## Demo contents

This demo provides a few simple applications, designed to run inside a QEMU
virtual machine that is emulating an Aarch32 Arm Cortex-R system.
virtual machine that is emulating an AArch32 Arm Cortex-R system.

There are five binaries in `./src/bin`:

* `defmt` prints some demt logs at different levels
* `global_uart` sets up a UART as a global variable and prints to it
* `panic` shows the panic handling
* `uart` prints to the first UART
* `with_heap` sets up a heap allocator and uses the `format!` macro to generate
- `defmt` prints some demt logs at different levels
- `global_uart` sets up a UART as a global variable and prints to it
- `panic` shows the panic handling
- `uart` prints to the first UART
- `with_heap` sets up a heap allocator and uses the `format!` macro to generate
heap-allocated strings, which it then prints.

All binaries use defmt to print logging information.

## Building and Running with `cargo`

Ferrocene compiles standard Rust source code, and so this project has also been
set up as a valid Rust project. The [`.cargo/config.toml`](./.cargo/config.toml)
file configures the default target as `armv8r-none-eabihf`. It also sets up the
linker arguments to ensure that [`./memory.x`](./memory.x) is used to supplement
the standard [`aarch32-rt`](https://crates.io/crates/aarch32-rt) linker
script.
Ferrocene compiles standard Rust source code, and so this project has also
been set up as a valid Rust project.

Before the build, `cargo` will compile and execute `build.rs`, which will copy
the linker script to the `cargo` temporary output directory where the linker
will look for it.

The compiled outputs will go into `./target/armv8r-none-eabihf/<profile>`, where
and `<profile>` is `debug` or `release`. The package contains multiple binary
crates, and the output binary name will match the name of the source file in
`./src/bin` that was compiled.
- The [`.cargo/config.toml`](./.cargo/config.toml) file configures the default
target as `armv8r-none-eabihf`.
- The [build script](./build.rs) sets up the linker arguments to ensure that the
`aarch32-rt` crate's `./link.x` is used as the linker script, along with our
local [`memory.x`](./memory.x) definition of which memory region to use. It
also copies the linker scripts to the target folder so the linker can find
them.
- The compiled outputs will go into `./target/armv8r-none-eabihf/<profile>`,
where `<profile>` is `debug` or `release`.

You will need to install [qemu-run](https://crates.io/crates/qemu-run), which
handles starting `qemu-system-arm` and decoding the defmt logs sent over
semihosting.

```console
$ cargo run
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s
Running `qemu-run --machine mps3-an536 --cpu cortex-r52 --log-format oneline target/armv8r-none-eabihf/debug/defmt`
Hello, world!
[ERROR] This is an error log (defmt src/bin/defmt.rs:10)
[WARN ] This is a warn log (defmt src/bin/defmt.rs:11)
[INFO ] This is an info log (defmt src/bin/defmt.rs:12)
[ERROR] PANIC at src/bin/defmt.rs:18: Testing panic!() in fn main (qemu_aarch32v8r src/lib.rs:23)
```

Most of the examples will run as-is, however if want to access the virtual UART
over telnet, you need to add the `-- --uart-telnet` option to the `cargo run`
invocation.
Expand All @@ -67,10 +79,10 @@ invocation.

Licensed under either of

* Apache License, Version 2.0 ([LICENSE-APACHE](../LICENSE-APACHE) or
- Apache License, Version 2.0 ([LICENSE-APACHE](../LICENSE-APACHE) or
<http://www.apache.org/licenses/LICENSE-2.0>)
* MIT license ([LICENSE-MIT](../LICENSE-MIT) or
<http://opensource.org/licenses/MIT>) at your option.
- MIT license ([LICENSE-MIT](../LICENSE-MIT) or
<http://opensource.org/licenses/MIT>) at your option.

## Contribution

Expand Down
2 changes: 1 addition & 1 deletion example-code/qemu-aarch32v8r/criticalup.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
manifest-version = 1

[products.ferrocene]
release = "beta-26.05-2026-06-27"
release = "stable-26.05.0"
packages = [
"rustc-${rustc-host}",
"rust-std-${rustc-host}",
Expand Down
4 changes: 2 additions & 2 deletions example-code/qemu-aarch64v8a/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[target.aarch64-unknown-none]
# QEMU Aarch64 boots in EL1 by default
# QEMU AArch64 boots in EL1 by default
runner = [
"qemu-run",
"--machine",
Expand All @@ -8,7 +8,7 @@ runner = [
"cortex-a57",
"--aarch64",
"--log-format",
"{[{L}]%bold} {s} {({ff}:{l:1})%dimmed}"
"oneline"
]

[build]
Expand Down
Loading
Loading