diff options
| author | Quentin Smith <[email protected]> | 2022-08-16 01:17:28 -0400 |
|---|---|---|
| committer | Quentin Smith <[email protected]> | 2022-08-16 01:17:28 -0400 |
| commit | c1d8c8cf36e3d13daf0eb93b56d8e149acf55b27 (patch) | |
| tree | 5f76e21edc00dd58fefa36bfd9bd90eeaac89db2 /examples | |
| parent | 0bf178dd1b11d97f20cb93c5fdb0c779259be0f8 (diff) | |
Add example of rtos-trace / SystemView
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/nrf/Cargo.toml | 68 | ||||
| -rw-r--r-- | examples/nrf/build.rs | 1 | ||||
| -rw-r--r-- | examples/nrf/src/bin/rtos_trace.rs | 64 |
3 files changed, 121 insertions, 12 deletions
diff --git a/examples/nrf/Cargo.toml b/examples/nrf/Cargo.toml index 91edbd36d..2f877b6a1 100644 --- a/examples/nrf/Cargo.toml +++ b/examples/nrf/Cargo.toml | |||
| @@ -4,28 +4,72 @@ name = "embassy-nrf-examples" | |||
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | 5 | ||
| 6 | [features] | 6 | [features] |
| 7 | default = ["nightly"] | 7 | default = ["defmt", "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"] | 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 | defmt = [ | ||
| 10 | "dep:defmt", | ||
| 11 | "dep:defmt-rtt", | ||
| 12 | "embassy-util/defmt", | ||
| 13 | "embassy-executor/defmt", | ||
| 14 | "embassy-executor/defmt-timestamp-uptime", | ||
| 15 | "embassy-nrf/defmt", | ||
| 16 | "embassy-net/defmt", | ||
| 17 | "embassy-usb/defmt", | ||
| 18 | "embassy-usb-serial/defmt", | ||
| 19 | "embassy-usb-hid/defmt", | ||
| 20 | "embassy-usb-ncm/defmt", | ||
| 21 | "panic-probe/print-defmt", | ||
| 22 | ] | ||
| 23 | log = [ | ||
| 24 | "dep:log", | ||
| 25 | "embassy-util/log", | ||
| 26 | "embassy-executor/log", | ||
| 27 | "embassy-nrf/log", | ||
| 28 | "embassy-net/log", | ||
| 29 | "embassy-usb-ncm/log", | ||
| 30 | # Currently broken: | ||
| 31 | # "embassy-usb/log", | ||
| 32 | # "embassy-usb-serial/log", | ||
| 33 | # "embassy-usb-hid/log", | ||
| 34 | ] | ||
| 35 | rtos-trace = [ | ||
| 36 | "dep:rtos-trace", | ||
| 37 | "dep:systemview-target", | ||
| 38 | "log", | ||
| 39 | "embassy-executor/rtos-trace", | ||
| 40 | "embassy-executor/rtos-trace-interrupt", | ||
| 41 | ] | ||
| 9 | 42 | ||
| 10 | [dependencies] | 43 | [dependencies] |
| 11 | embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } | 44 | embassy-util = { version = "0.1.0", path = "../../embassy-util" } |
| 12 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime"] } | 45 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor" } |
| 13 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } | 46 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } |
| 14 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "pool-16"], optional = true } | 47 | embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["tcp", "dhcpv4", "medium-ethernet", "pool-16"], optional = true } |
| 15 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"], optional = true } | 48 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", optional = true } |
| 16 | embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"], optional = true } | 49 | embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", optional = true } |
| 17 | embassy-usb-hid = { version = "0.1.0", path = "../../embassy-usb-hid", features = ["defmt"], optional = true } | 50 | embassy-usb-hid = { version = "0.1.0", path = "../../embassy-usb-hid", optional = true } |
| 18 | embassy-usb-ncm = { version = "0.1.0", path = "../../embassy-usb-ncm", features = ["defmt"], optional = true } | 51 | embassy-usb-ncm = { version = "0.1.0", path = "../../embassy-usb-ncm", optional = true } |
| 19 | embedded-io = "0.3.0" | 52 | embedded-io = "0.3.0" |
| 20 | 53 | ||
| 21 | defmt = "0.3" | 54 | defmt = { version = "0.3", optional = true } |
| 22 | defmt-rtt = "0.3" | 55 | defmt-rtt = { version = "0.3", optional = true } |
| 23 | 56 | ||
| 24 | cortex-m = "0.7.3" | 57 | cortex-m = "0.7.3" |
| 25 | cortex-m-rt = "0.7.0" | 58 | cortex-m-rt = "0.7.0" |
| 26 | panic-probe = { version = "0.3", features = ["print-defmt"] } | 59 | panic-probe = { version = "0.3" } |
| 27 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 60 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 28 | rand = { version = "0.8.4", default-features = false } | 61 | rand = { version = "0.8.4", default-features = false } |
| 29 | embedded-storage = "0.3.0" | 62 | embedded-storage = "0.3.0" |
| 30 | usbd-hid = "0.5.2" | 63 | usbd-hid = "0.5.2" |
| 31 | serde = { version = "1.0.136", default-features = false } | 64 | serde = { version = "1.0.136", default-features = false } |
| 65 | rtos-trace = { version = "0.1.3", optional = true } | ||
| 66 | systemview-target = { version = "0.1.1", optional = true, features = ["callbacks-app", "callbacks-os", "log", "cortex-m"] } | ||
| 67 | log = { version = "0.4.17", optional = true } | ||
| 68 | |||
| 69 | [[bin]] | ||
| 70 | name = "rtos_trace" | ||
| 71 | required-features = ["nightly", "rtos-trace", "log"] | ||
| 72 | |||
| 73 | [patch.crates-io] | ||
| 74 | rtos-trace = { git = "https://gitlab.com/quentinmit/rtos-trace.git", branch = "build-fix" } | ||
| 75 | 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 30691aa97..36cdb65a8 100644 --- a/examples/nrf/build.rs +++ b/examples/nrf/build.rs | |||
| @@ -31,5 +31,6 @@ fn main() { | |||
| 31 | 31 | ||
| 32 | println!("cargo:rustc-link-arg-bins=--nmagic"); | 32 | println!("cargo:rustc-link-arg-bins=--nmagic"); |
| 33 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); | 33 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); |
| 34 | #[cfg(feature = "defmt")] | ||
| 34 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | 35 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); |
| 35 | } | 36 | } |
diff --git a/examples/nrf/src/bin/rtos_trace.rs b/examples/nrf/src/bin/rtos_trace.rs new file mode 100644 index 000000000..8b4f5b755 --- /dev/null +++ b/examples/nrf/src/bin/rtos_trace.rs | |||
| @@ -0,0 +1,64 @@ | |||
| 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 | |||
| 11 | // N.B. systemview_target cannot be used at the same time as defmt_rtt. | ||
| 12 | |||
| 13 | use rtos_trace; | ||
| 14 | use systemview_target::SystemView; | ||
| 15 | use panic_probe as _; | ||
| 16 | use log::*; | ||
| 17 | |||
| 18 | static LOGGER: systemview_target::SystemView = systemview_target::SystemView::new(); | ||
| 19 | rtos_trace::global_trace!{SystemView} | ||
| 20 | |||
| 21 | struct TraceInfo(); | ||
| 22 | |||
| 23 | impl rtos_trace::RtosTraceApplicationCallbacks for TraceInfo { | ||
| 24 | fn system_description() {} | ||
| 25 | fn sysclock() -> u32 { | ||
| 26 | 64000000 | ||
| 27 | } | ||
| 28 | } | ||
| 29 | rtos_trace::global_application_callbacks!{TraceInfo} | ||
| 30 | |||
| 31 | #[embassy_executor::task] | ||
| 32 | async fn run1() { | ||
| 33 | loop { | ||
| 34 | info!("DING DONG"); | ||
| 35 | Timer::after(Duration::from_ticks(16000)).await; | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | #[embassy_executor::task] | ||
| 40 | async fn run2() { | ||
| 41 | loop { | ||
| 42 | Timer::at(Instant::from_ticks(0)).await; | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | #[embassy_executor::task] | ||
| 47 | async fn run3() { | ||
| 48 | futures::future::poll_fn(|cx| { | ||
| 49 | cx.waker().wake_by_ref(); | ||
| 50 | Poll::<()>::Pending | ||
| 51 | }) | ||
| 52 | .await; | ||
| 53 | } | ||
| 54 | |||
| 55 | #[embassy_executor::main] | ||
| 56 | async fn main(spawner: Spawner, _p: Peripherals) { | ||
| 57 | LOGGER.init(); | ||
| 58 | ::log::set_logger(&LOGGER).ok(); | ||
| 59 | ::log::set_max_level(::log::LevelFilter::Trace); | ||
| 60 | |||
| 61 | spawner.spawn(run1()).unwrap(); | ||
| 62 | spawner.spawn(run2()).unwrap(); | ||
| 63 | spawner.spawn(run3()).unwrap(); | ||
| 64 | } | ||
