From 2edf532f8d8ce048137990bf74b07759428ed7c1 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Thu, 18 Aug 2022 01:38:58 -0400 Subject: [PATCH] Move rtos-trace example to a separate project to simplify Cargo.toml --- examples/nrf-rtos-trace/.cargo/config.toml | 9 +++ examples/nrf-rtos-trace/Cargo.toml | 51 ++++++++++++++ examples/nrf-rtos-trace/build.rs | 36 ++++++++++ examples/nrf-rtos-trace/memory.x | 7 ++ .../src/bin/rtos_trace.rs | 0 examples/nrf/Cargo.toml | 67 ++++--------------- examples/nrf/build.rs | 1 - 7 files changed, 115 insertions(+), 56 deletions(-) create mode 100644 examples/nrf-rtos-trace/.cargo/config.toml create mode 100644 examples/nrf-rtos-trace/Cargo.toml create mode 100644 examples/nrf-rtos-trace/build.rs create mode 100644 examples/nrf-rtos-trace/memory.x rename examples/{nrf => nrf-rtos-trace}/src/bin/rtos_trace.rs (100%) diff --git a/examples/nrf-rtos-trace/.cargo/config.toml b/examples/nrf-rtos-trace/.cargo/config.toml new file mode 100644 index 00000000..8ca28df3 --- /dev/null +++ b/examples/nrf-rtos-trace/.cargo/config.toml @@ -0,0 +1,9 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +# replace nRF82840_xxAA with your chip as listed in `probe-run --list-chips` +runner = "probe-run --chip nRF52840_xxAA" + +[build] +target = "thumbv7em-none-eabi" + +[env] +DEFMT_LOG = "trace" diff --git a/examples/nrf-rtos-trace/Cargo.toml b/examples/nrf-rtos-trace/Cargo.toml new file mode 100644 index 00000000..9c749a38 --- /dev/null +++ b/examples/nrf-rtos-trace/Cargo.toml @@ -0,0 +1,51 @@ +[package] +edition = "2021" +name = "embassy-nrf-examples" +version = "0.1.0" + +[features] +default = ["log", "nightly"] +nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-nrf/unstable-traits", "embassy-usb", "embassy-usb-serial", "embassy-usb-hid", "embassy-usb-ncm", "embedded-io/async", "embassy-net"] +log = [ + "dep:log", + "embassy-util/log", + "embassy-executor/log", + "embassy-nrf/log", + "embassy-net/log", + "embassy-usb-ncm/log", + # Currently broken: + # "embassy-usb/log", + # "embassy-usb-serial/log", + # "embassy-usb-hid/log", +] + +[dependencies] +embassy-util = { version = "0.1.0", path = "../../embassy-util" } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features=["rtos-trace", "rtos-trace-interrupt"] } +embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } +embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["tcp", "dhcpv4", "medium-ethernet", "pool-16"], optional = true } +embassy-usb = { version = "0.1.0", path = "../../embassy-usb", optional = true } +embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", optional = true } +embassy-usb-hid = { version = "0.1.0", path = "../../embassy-usb-hid", optional = true } +embassy-usb-ncm = { version = "0.1.0", path = "../../embassy-usb-ncm", optional = true } +embedded-io = "0.3.0" + +cortex-m = "0.7.3" +cortex-m-rt = "0.7.0" +panic-probe = { version = "0.3" } +futures = { version = "0.3.17", default-features = false, features = ["async-await"] } +rand = { version = "0.8.4", default-features = false } +embedded-storage = "0.3.0" +usbd-hid = "0.5.2" +serde = { version = "1.0.136", default-features = false } +rtos-trace = "0.1.3" +systemview-target = { version = "0.1.1", features = ["callbacks-app", "callbacks-os", "log", "cortex-m"] } +log = { version = "0.4.17", optional = true } + +[[bin]] +name = "rtos_trace" +required-features = ["nightly"] + +[patch.crates-io] +rtos-trace = { git = "https://gitlab.com/quentinmit/rtos-trace.git", branch = "build-fix" } +systemview-target = { git = "https://gitlab.com/quentinmit/rtos-trace.git", branch = "build-fix" } diff --git a/examples/nrf-rtos-trace/build.rs b/examples/nrf-rtos-trace/build.rs new file mode 100644 index 00000000..36cdb65a --- /dev/null +++ b/examples/nrf-rtos-trace/build.rs @@ -0,0 +1,36 @@ +//! This build script copies the `memory.x` file from the crate root into +//! a directory where the linker can always find it at build time. +//! For many projects this is optional, as the linker always searches the +//! project root directory -- wherever `Cargo.toml` is. However, if you +//! are using a workspace or have a more complicated build setup, this +//! build script becomes required. Additionally, by requesting that +//! Cargo re-run the build script whenever `memory.x` is changed, +//! updating `memory.x` ensures a rebuild of the application with the +//! new memory settings. + +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::PathBuf; + +fn main() { + // Put `memory.x` in our output directory and ensure it's + // on the linker search path. + let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); + File::create(out.join("memory.x")) + .unwrap() + .write_all(include_bytes!("memory.x")) + .unwrap(); + println!("cargo:rustc-link-search={}", out.display()); + + // By default, Cargo will re-run a build script whenever + // any file in the project changes. By specifying `memory.x` + // here, we ensure the build script is only re-run when + // `memory.x` is changed. + println!("cargo:rerun-if-changed=memory.x"); + + println!("cargo:rustc-link-arg-bins=--nmagic"); + println!("cargo:rustc-link-arg-bins=-Tlink.x"); + #[cfg(feature = "defmt")] + println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); +} diff --git a/examples/nrf-rtos-trace/memory.x b/examples/nrf-rtos-trace/memory.x new file mode 100644 index 00000000..9b04edec --- /dev/null +++ b/examples/nrf-rtos-trace/memory.x @@ -0,0 +1,7 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + /* These values correspond to the NRF52840 with Softdevices S140 7.0.1 */ + FLASH : ORIGIN = 0x00000000, LENGTH = 1024K + RAM : ORIGIN = 0x20000000, LENGTH = 256K +} diff --git a/examples/nrf/src/bin/rtos_trace.rs b/examples/nrf-rtos-trace/src/bin/rtos_trace.rs similarity index 100% rename from examples/nrf/src/bin/rtos_trace.rs rename to examples/nrf-rtos-trace/src/bin/rtos_trace.rs diff --git a/examples/nrf/Cargo.toml b/examples/nrf/Cargo.toml index 8704f27c..91edbd36 100644 --- a/examples/nrf/Cargo.toml +++ b/examples/nrf/Cargo.toml @@ -4,71 +4,28 @@ name = "embassy-nrf-examples" version = "0.1.0" [features] -default = ["defmt", "nightly"] +default = ["nightly"] nightly = ["embassy-executor/nightly", "embassy-nrf/nightly", "embassy-nrf/unstable-traits", "embassy-usb", "embassy-usb-serial", "embassy-usb-hid", "embassy-usb-ncm", "embedded-io/async", "embassy-net"] -defmt = [ - "dep:defmt", - "dep:defmt-rtt", - "embassy-util/defmt", - "embassy-executor/defmt", - "embassy-executor/defmt-timestamp-uptime", - "embassy-nrf/defmt", - "embassy-net/defmt", - "embassy-usb/defmt", - "embassy-usb-serial/defmt", - "embassy-usb-hid/defmt", - "embassy-usb-ncm/defmt", - "panic-probe/print-defmt", -] -log = [ - "dep:log", - "embassy-util/log", - "embassy-executor/log", - "embassy-nrf/log", - "embassy-net/log", - "embassy-usb-ncm/log", - # Currently broken: - # "embassy-usb/log", - # "embassy-usb-serial/log", - # "embassy-usb-hid/log", -] -rtos-trace = [ - "dep:rtos-trace", - "dep:systemview-target", - "embassy-executor/rtos-trace", - "embassy-executor/rtos-trace-interrupt", -] [dependencies] -embassy-util = { version = "0.1.0", path = "../../embassy-util" } -embassy-executor = { version = "0.1.0", path = "../../embassy-executor" } -embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } -embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["tcp", "dhcpv4", "medium-ethernet", "pool-16"], optional = true } -embassy-usb = { version = "0.1.0", path = "../../embassy-usb", optional = true } -embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", optional = true } -embassy-usb-hid = { version = "0.1.0", path = "../../embassy-usb-hid", optional = true } -embassy-usb-ncm = { version = "0.1.0", path = "../../embassy-usb-ncm", optional = true } +embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } +embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime"] } +embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } +embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "pool-16"], optional = true } +embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"], optional = true } +embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"], optional = true } +embassy-usb-hid = { version = "0.1.0", path = "../../embassy-usb-hid", features = ["defmt"], optional = true } +embassy-usb-ncm = { version = "0.1.0", path = "../../embassy-usb-ncm", features = ["defmt"], optional = true } embedded-io = "0.3.0" -defmt = { version = "0.3", optional = true } -defmt-rtt = { version = "0.3", optional = true } +defmt = "0.3" +defmt-rtt = "0.3" cortex-m = "0.7.3" cortex-m-rt = "0.7.0" -panic-probe = { version = "0.3" } +panic-probe = { version = "0.3", features = ["print-defmt"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] } rand = { version = "0.8.4", default-features = false } embedded-storage = "0.3.0" usbd-hid = "0.5.2" serde = { version = "1.0.136", default-features = false } -rtos-trace = { version = "0.1.3", optional = true } -systemview-target = { version = "0.1.1", optional = true, features = ["callbacks-app", "callbacks-os", "log", "cortex-m"] } -log = { version = "0.4.17", optional = true } - -[[bin]] -name = "rtos_trace" -required-features = ["nightly", "rtos-trace"] - -[patch.crates-io] -rtos-trace = { git = "https://gitlab.com/quentinmit/rtos-trace.git", branch = "build-fix" } -systemview-target = { git = "https://gitlab.com/quentinmit/rtos-trace.git", branch = "build-fix" } diff --git a/examples/nrf/build.rs b/examples/nrf/build.rs index 36cdb65a..30691aa9 100644 --- a/examples/nrf/build.rs +++ b/examples/nrf/build.rs @@ -31,6 +31,5 @@ fn main() { println!("cargo:rustc-link-arg-bins=--nmagic"); println!("cargo:rustc-link-arg-bins=-Tlink.x"); - #[cfg(feature = "defmt")] println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); }