diff options
| author | Quentin Smith <[email protected]> | 2022-08-18 01:38:58 -0400 |
|---|---|---|
| committer | Quentin Smith <[email protected]> | 2022-08-18 01:38:58 -0400 |
| commit | 2edf532f8d8ce048137990bf74b07759428ed7c1 (patch) | |
| tree | 116b1401bb040c3f60fcd2e9c6e591e05f7272b0 /examples/nrf-rtos-trace | |
| parent | 7dfe119fe0c7b99d7a6d73af6ac3fc6f7cef9d12 (diff) | |
Move rtos-trace example to a separate project to simplify Cargo.toml
Diffstat (limited to 'examples/nrf-rtos-trace')
| -rw-r--r-- | examples/nrf-rtos-trace/.cargo/config.toml | 9 | ||||
| -rw-r--r-- | examples/nrf-rtos-trace/Cargo.toml | 51 | ||||
| -rw-r--r-- | examples/nrf-rtos-trace/build.rs | 36 | ||||
| -rw-r--r-- | examples/nrf-rtos-trace/memory.x | 7 | ||||
| -rw-r--r-- | examples/nrf-rtos-trace/src/bin/rtos_trace.rs | 69 |
5 files changed, 172 insertions, 0 deletions
diff --git a/examples/nrf-rtos-trace/.cargo/config.toml b/examples/nrf-rtos-trace/.cargo/config.toml new file mode 100644 index 000000000..8ca28df39 --- /dev/null +++ b/examples/nrf-rtos-trace/.cargo/config.toml | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
| 2 | # replace nRF82840_xxAA with your chip as listed in `probe-run --list-chips` | ||
| 3 | runner = "probe-run --chip nRF52840_xxAA" | ||
| 4 | |||
| 5 | [build] | ||
| 6 | target = "thumbv7em-none-eabi" | ||
| 7 | |||
| 8 | [env] | ||
| 9 | DEFMT_LOG = "trace" | ||
diff --git a/examples/nrf-rtos-trace/Cargo.toml b/examples/nrf-rtos-trace/Cargo.toml new file mode 100644 index 000000000..9c749a388 --- /dev/null +++ b/examples/nrf-rtos-trace/Cargo.toml | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | [package] | ||
| 2 | edition = "2021" | ||
| 3 | name = "embassy-nrf-examples" | ||
| 4 | version = "0.1.0" | ||
| 5 | |||
| 6 | [features] | ||
| 7 | default = ["log", "nightly"] | ||
| 8 | 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"] | ||
| 9 | log = [ | ||
| 10 | "dep:log", | ||
| 11 | "embassy-util/log", | ||
| 12 | "embassy-executor/log", | ||
| 13 | "embassy-nrf/log", | ||
| 14 | "embassy-net/log", | ||
| 15 | "embassy-usb-ncm/log", | ||
| 16 | # Currently broken: | ||
| 17 | # "embassy-usb/log", | ||
| 18 | # "embassy-usb-serial/log", | ||
| 19 | # "embassy-usb-hid/log", | ||
| 20 | ] | ||
| 21 | |||
| 22 | [dependencies] | ||
| 23 | embassy-util = { version = "0.1.0", path = "../../embassy-util" } | ||
| 24 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features=["rtos-trace", "rtos-trace-interrupt"] } | ||
| 25 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } | ||
| 26 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["tcp", "dhcpv4", "medium-ethernet", "pool-16"], optional = true } | ||
| 27 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", optional = true } | ||
| 28 | embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", optional = true } | ||
| 29 | embassy-usb-hid = { version = "0.1.0", path = "../../embassy-usb-hid", optional = true } | ||
| 30 | embassy-usb-ncm = { version = "0.1.0", path = "../../embassy-usb-ncm", optional = true } | ||
| 31 | embedded-io = "0.3.0" | ||
| 32 | |||
| 33 | cortex-m = "0.7.3" | ||
| 34 | cortex-m-rt = "0.7.0" | ||
| 35 | panic-probe = { version = "0.3" } | ||
| 36 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | ||
| 37 | rand = { version = "0.8.4", default-features = false } | ||
| 38 | embedded-storage = "0.3.0" | ||
| 39 | usbd-hid = "0.5.2" | ||
| 40 | serde = { version = "1.0.136", default-features = false } | ||
| 41 | rtos-trace = "0.1.3" | ||
| 42 | systemview-target = { version = "0.1.1", features = ["callbacks-app", "callbacks-os", "log", "cortex-m"] } | ||
| 43 | log = { version = "0.4.17", optional = true } | ||
| 44 | |||
| 45 | [[bin]] | ||
| 46 | name = "rtos_trace" | ||
| 47 | required-features = ["nightly"] | ||
| 48 | |||
| 49 | [patch.crates-io] | ||
| 50 | rtos-trace = { git = "https://gitlab.com/quentinmit/rtos-trace.git", branch = "build-fix" } | ||
| 51 | 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 000000000..36cdb65a8 --- /dev/null +++ b/examples/nrf-rtos-trace/build.rs | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | //! This build script copies the `memory.x` file from the crate root into | ||
| 2 | //! a directory where the linker can always find it at build time. | ||
| 3 | //! For many projects this is optional, as the linker always searches the | ||
| 4 | //! project root directory -- wherever `Cargo.toml` is. However, if you | ||
| 5 | //! are using a workspace or have a more complicated build setup, this | ||
| 6 | //! build script becomes required. Additionally, by requesting that | ||
| 7 | //! Cargo re-run the build script whenever `memory.x` is changed, | ||
| 8 | //! updating `memory.x` ensures a rebuild of the application with the | ||
| 9 | //! new memory settings. | ||
| 10 | |||
| 11 | use std::env; | ||
| 12 | use std::fs::File; | ||
| 13 | use std::io::Write; | ||
| 14 | use std::path::PathBuf; | ||
| 15 | |||
| 16 | fn main() { | ||
| 17 | // Put `memory.x` in our output directory and ensure it's | ||
| 18 | // on the linker search path. | ||
| 19 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| 20 | File::create(out.join("memory.x")) | ||
| 21 | .unwrap() | ||
| 22 | .write_all(include_bytes!("memory.x")) | ||
| 23 | .unwrap(); | ||
| 24 | println!("cargo:rustc-link-search={}", out.display()); | ||
| 25 | |||
| 26 | // By default, Cargo will re-run a build script whenever | ||
| 27 | // any file in the project changes. By specifying `memory.x` | ||
| 28 | // here, we ensure the build script is only re-run when | ||
| 29 | // `memory.x` is changed. | ||
| 30 | println!("cargo:rerun-if-changed=memory.x"); | ||
| 31 | |||
| 32 | println!("cargo:rustc-link-arg-bins=--nmagic"); | ||
| 33 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); | ||
| 34 | #[cfg(feature = "defmt")] | ||
| 35 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | ||
| 36 | } | ||
diff --git a/examples/nrf-rtos-trace/memory.x b/examples/nrf-rtos-trace/memory.x new file mode 100644 index 000000000..9b04edec0 --- /dev/null +++ b/examples/nrf-rtos-trace/memory.x | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | /* These values correspond to the NRF52840 with Softdevices S140 7.0.1 */ | ||
| 5 | FLASH : ORIGIN = 0x00000000, LENGTH = 1024K | ||
| 6 | RAM : ORIGIN = 0x20000000, LENGTH = 256K | ||
| 7 | } | ||
diff --git a/examples/nrf-rtos-trace/src/bin/rtos_trace.rs b/examples/nrf-rtos-trace/src/bin/rtos_trace.rs new file mode 100644 index 000000000..5699fe8e2 --- /dev/null +++ b/examples/nrf-rtos-trace/src/bin/rtos_trace.rs | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use core::task::Poll; | ||
| 6 | |||
| 7 | use embassy_executor::executor::Spawner; | ||
| 8 | use embassy_executor::time::{Duration, Instant, Timer}; | ||
| 9 | use embassy_nrf::Peripherals; | ||
| 10 | #[cfg(feature = "log")] | ||
| 11 | use log::*; | ||
| 12 | use panic_probe as _; | ||
| 13 | // N.B. systemview_target cannot be used at the same time as defmt_rtt. | ||
| 14 | use rtos_trace; | ||
| 15 | use systemview_target::SystemView; | ||
| 16 | |||
| 17 | static LOGGER: systemview_target::SystemView = systemview_target::SystemView::new(); | ||
| 18 | rtos_trace::global_trace! {SystemView} | ||
| 19 | |||
| 20 | struct TraceInfo(); | ||
| 21 | |||
| 22 | impl rtos_trace::RtosTraceApplicationCallbacks for TraceInfo { | ||
| 23 | fn system_description() {} | ||
| 24 | fn sysclock() -> u32 { | ||
| 25 | 64000000 | ||
| 26 | } | ||
| 27 | } | ||
| 28 | rtos_trace::global_application_callbacks! {TraceInfo} | ||
| 29 | |||
| 30 | #[embassy_executor::task] | ||
| 31 | async fn run1() { | ||
| 32 | loop { | ||
| 33 | #[cfg(feature = "log")] | ||
| 34 | info!("DING DONG"); | ||
| 35 | #[cfg(not(feature = "log"))] | ||
| 36 | rtos_trace::trace::marker(13); | ||
| 37 | Timer::after(Duration::from_ticks(16000)).await; | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | #[embassy_executor::task] | ||
| 42 | async fn run2() { | ||
| 43 | loop { | ||
| 44 | Timer::at(Instant::from_ticks(0)).await; | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | #[embassy_executor::task] | ||
| 49 | async fn run3() { | ||
| 50 | futures::future::poll_fn(|cx| { | ||
| 51 | cx.waker().wake_by_ref(); | ||
| 52 | Poll::<()>::Pending | ||
| 53 | }) | ||
| 54 | .await; | ||
| 55 | } | ||
| 56 | |||
| 57 | #[embassy_executor::main] | ||
| 58 | async fn main(spawner: Spawner, _p: Peripherals) { | ||
| 59 | LOGGER.init(); | ||
| 60 | #[cfg(feature = "log")] | ||
| 61 | { | ||
| 62 | ::log::set_logger(&LOGGER).ok(); | ||
| 63 | ::log::set_max_level(::log::LevelFilter::Trace); | ||
| 64 | } | ||
| 65 | |||
| 66 | spawner.spawn(run1()).unwrap(); | ||
| 67 | spawner.spawn(run2()).unwrap(); | ||
| 68 | spawner.spawn(run3()).unwrap(); | ||
| 69 | } | ||
