From a3c1522ce64b00c6d310947ebc6dad9fe1e28d55 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Tue, 9 Aug 2022 16:25:42 -0400 Subject: [PATCH 01/10] Add support for rtos-trace behind a feature flag --- embassy-executor/Cargo.toml | 1 + embassy-executor/src/executor/raw/mod.rs | 35 +++++++++++++++++++ embassy-executor/src/lib.rs | 21 +++++++++++ .../src/macros/cortex_m_interrupt_take.rs | 8 ++++- 4 files changed, 64 insertions(+), 1 deletion(-) diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index d8ac4ac0..d10752b3 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml @@ -53,6 +53,7 @@ time-tick-16mhz = ["time"] [dependencies] defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } +rtos-trace = { version = "0.1.2", optional = true } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8", optional = true} diff --git a/embassy-executor/src/executor/raw/mod.rs b/embassy-executor/src/executor/raw/mod.rs index fb4cc628..c943ecd8 100644 --- a/embassy-executor/src/executor/raw/mod.rs +++ b/embassy-executor/src/executor/raw/mod.rs @@ -22,6 +22,8 @@ use core::{mem, ptr}; use atomic_polyfill::{AtomicU32, Ordering}; use critical_section::CriticalSection; +#[cfg(feature = "rtos-trace")] +use rtos_trace::trace; use self::run_queue::{RunQueue, RunQueueItem}; use self::util::UninitCell; @@ -306,6 +308,9 @@ impl Executor { /// - `task` must NOT be already enqueued (in this executor or another one). #[inline(always)] unsafe fn enqueue(&self, cs: CriticalSection, task: NonNull) { + #[cfg(feature = "rtos-trace")] + trace::task_ready_begin(task.as_ptr() as u32); + if self.run_queue.enqueue(cs, task) { (self.signal_fn)(self.signal_ctx) } @@ -323,6 +328,9 @@ impl Executor { pub(super) unsafe fn spawn(&'static self, task: NonNull) { task.as_ref().executor.set(self); + #[cfg(feature = "rtos-trace")] + trace::task_new(task.as_ptr() as u32); + critical_section::with(|cs| { self.enqueue(cs, task); }) @@ -365,9 +373,15 @@ impl Executor { return; } + #[cfg(feature = "rtos-trace")] + trace::task_exec_begin(p.as_ptr() as u32); + // Run the task task.poll_fn.read()(p as _); + #[cfg(feature = "rtos-trace")] + trace::task_exec_end(); + // Enqueue or update into timer_queue #[cfg(feature = "time")] self.timer_queue.update(p); @@ -381,6 +395,9 @@ impl Executor { let next_expiration = self.timer_queue.next_expiration(); driver::set_alarm(self.alarm, next_expiration.as_ticks()); } + + #[cfg(feature = "rtos-trace")] + trace::system_idle(); } /// Get a spawner that spawns tasks in this executor. @@ -425,3 +442,21 @@ pub(crate) unsafe fn register_timer(at: Instant, waker: &core::task::Waker) { let expires_at = task.expires_at.get(); task.expires_at.set(expires_at.min(at)); } + +#[cfg(feature = "rtos-trace")] +impl rtos_trace::RtosTraceOSCallbacks for Executor { + fn task_list() { + // We don't know what tasks exist, so we can't send them. + } + #[cfg(feature = "time")] + fn time() -> u64 { + Instant::now().as_micros() + } + #[cfg(not(feature = "time"))] + fn time() -> u64 { + 0 + } +} + +#[cfg(feature = "rtos-trace")] +rtos_trace::global_os_callbacks!{Executor} diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs index 69e4aeb4..dd99f9e5 100644 --- a/embassy-executor/src/lib.rs +++ b/embassy-executor/src/lib.rs @@ -19,4 +19,25 @@ pub use embassy_macros::{main, task}; /// Implementation details for embassy macros. DO NOT USE. pub mod export { pub use atomic_polyfill as atomic; + + #[cfg(feature = "rtos-trace")] + pub use rtos_trace::trace; + + /// Expands the given block of code when `embassy-executor` is compiled with + /// the `rtos-trace` feature. + #[doc(hidden)] + #[macro_export] + #[cfg(feature = "rtos-trace")] + macro_rules! rtos_trace { + ($($tt:tt)*) => { $($tt)* }; + } + + /// Does not expand the given block of code when `embassy-executor` is + /// compiled without the `rtos-trace` feature. + #[doc(hidden)] + #[macro_export] + #[cfg(not(feature = "rtos-trace"))] + macro_rules! rtos_trace { + ($($tt:tt)*) => {}; + } } diff --git a/embassy-macros/src/macros/cortex_m_interrupt_take.rs b/embassy-macros/src/macros/cortex_m_interrupt_take.rs index 133eb5c2..5431704d 100644 --- a/embassy-macros/src/macros/cortex_m_interrupt_take.rs +++ b/embassy-macros/src/macros/cortex_m_interrupt_take.rs @@ -19,7 +19,13 @@ pub fn run(name: syn::Ident) -> Result { let func = HANDLER.func.load(::embassy_executor::export::atomic::Ordering::Relaxed); let ctx = HANDLER.ctx.load(::embassy_executor::export::atomic::Ordering::Relaxed); let func: fn(*mut ()) = ::core::mem::transmute(func); - func(ctx) + ::embassy_executor::rtos_trace! { + ::embassy_executor::export::trace::isr_enter(); + } + func(ctx); + ::embassy_executor::rtos_trace! { + ::embassy_executor::export::trace::isr_exit(); + } } static TAKEN: ::embassy_executor::export::atomic::AtomicBool = ::embassy_executor::export::atomic::AtomicBool::new(false); From 145af0e4ab75d931cba401f1755f383bcc713892 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Wed, 10 Aug 2022 17:09:11 -0400 Subject: [PATCH 02/10] cargo fmt --- embassy-executor/src/executor/raw/mod.rs | 2 +- embassy-executor/src/lib.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/embassy-executor/src/executor/raw/mod.rs b/embassy-executor/src/executor/raw/mod.rs index c943ecd8..56220d10 100644 --- a/embassy-executor/src/executor/raw/mod.rs +++ b/embassy-executor/src/executor/raw/mod.rs @@ -459,4 +459,4 @@ impl rtos_trace::RtosTraceOSCallbacks for Executor { } #[cfg(feature = "rtos-trace")] -rtos_trace::global_os_callbacks!{Executor} +rtos_trace::global_os_callbacks! {Executor} diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs index dd99f9e5..32724c15 100644 --- a/embassy-executor/src/lib.rs +++ b/embassy-executor/src/lib.rs @@ -19,7 +19,6 @@ pub use embassy_macros::{main, task}; /// Implementation details for embassy macros. DO NOT USE. pub mod export { pub use atomic_polyfill as atomic; - #[cfg(feature = "rtos-trace")] pub use rtos_trace::trace; From 0bf178dd1b11d97f20cb93c5fdb0c779259be0f8 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Tue, 16 Aug 2022 00:42:08 -0400 Subject: [PATCH 03/10] Add separate feature flag to enable interrupt tracing --- embassy-executor/Cargo.toml | 3 +++ embassy-executor/src/lib.rs | 12 ++++++------ embassy-macros/src/macros/cortex_m_interrupt_take.rs | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index d10752b3..ca00f2e7 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml @@ -50,6 +50,9 @@ time-tick-1000hz = ["time"] time-tick-1mhz = ["time"] time-tick-16mhz = ["time"] +# Trace interrupt invocations with rtos-trace. +rtos-trace-interrupt = ["rtos-trace"] + [dependencies] defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs index 32724c15..47c0c1d6 100644 --- a/embassy-executor/src/lib.rs +++ b/embassy-executor/src/lib.rs @@ -23,20 +23,20 @@ pub mod export { pub use rtos_trace::trace; /// Expands the given block of code when `embassy-executor` is compiled with - /// the `rtos-trace` feature. + /// the `rtos-trace-interrupt` feature. #[doc(hidden)] #[macro_export] - #[cfg(feature = "rtos-trace")] - macro_rules! rtos_trace { + #[cfg(feature = "rtos-trace-interrupt")] + macro_rules! rtos_trace_interrupt { ($($tt:tt)*) => { $($tt)* }; } /// Does not expand the given block of code when `embassy-executor` is - /// compiled without the `rtos-trace` feature. + /// compiled without the `rtos-trace-interrupt` feature. #[doc(hidden)] #[macro_export] - #[cfg(not(feature = "rtos-trace"))] - macro_rules! rtos_trace { + #[cfg(not(feature = "rtos-trace-interrupt"))] + macro_rules! rtos_trace_interrupt { ($($tt:tt)*) => {}; } } diff --git a/embassy-macros/src/macros/cortex_m_interrupt_take.rs b/embassy-macros/src/macros/cortex_m_interrupt_take.rs index 5431704d..62249807 100644 --- a/embassy-macros/src/macros/cortex_m_interrupt_take.rs +++ b/embassy-macros/src/macros/cortex_m_interrupt_take.rs @@ -19,11 +19,11 @@ pub fn run(name: syn::Ident) -> Result { let func = HANDLER.func.load(::embassy_executor::export::atomic::Ordering::Relaxed); let ctx = HANDLER.ctx.load(::embassy_executor::export::atomic::Ordering::Relaxed); let func: fn(*mut ()) = ::core::mem::transmute(func); - ::embassy_executor::rtos_trace! { + ::embassy_executor::rtos_trace_interrupt! { ::embassy_executor::export::trace::isr_enter(); } func(ctx); - ::embassy_executor::rtos_trace! { + ::embassy_executor::rtos_trace_interrupt! { ::embassy_executor::export::trace::isr_exit(); } } From c1d8c8cf36e3d13daf0eb93b56d8e149acf55b27 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Tue, 16 Aug 2022 01:17:28 -0400 Subject: [PATCH 04/10] Add example of rtos-trace / SystemView --- examples/nrf/Cargo.toml | 68 ++++++++++++++++++++++++------ examples/nrf/build.rs | 1 + examples/nrf/src/bin/rtos_trace.rs | 64 ++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 12 deletions(-) create mode 100644 examples/nrf/src/bin/rtos_trace.rs diff --git a/examples/nrf/Cargo.toml b/examples/nrf/Cargo.toml index 91edbd36..2f877b6a 100644 --- a/examples/nrf/Cargo.toml +++ b/examples/nrf/Cargo.toml @@ -4,28 +4,72 @@ name = "embassy-nrf-examples" version = "0.1.0" [features] -default = ["nightly"] +default = ["defmt", "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", + "log", + "embassy-executor/rtos-trace", + "embassy-executor/rtos-trace-interrupt", +] [dependencies] -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 } +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 } embedded-io = "0.3.0" -defmt = "0.3" -defmt-rtt = "0.3" +defmt = { version = "0.3", optional = true } +defmt-rtt = { version = "0.3", optional = true } cortex-m = "0.7.3" cortex-m-rt = "0.7.0" -panic-probe = { version = "0.3", features = ["print-defmt"] } +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 = { 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", "log"] + +[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 30691aa9..36cdb65a 100644 --- a/examples/nrf/build.rs +++ b/examples/nrf/build.rs @@ -31,5 +31,6 @@ 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"); } diff --git a/examples/nrf/src/bin/rtos_trace.rs b/examples/nrf/src/bin/rtos_trace.rs new file mode 100644 index 00000000..8b4f5b75 --- /dev/null +++ b/examples/nrf/src/bin/rtos_trace.rs @@ -0,0 +1,64 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use core::task::Poll; + +use embassy_executor::executor::Spawner; +use embassy_executor::time::{Duration, Instant, Timer}; +use embassy_nrf::Peripherals; + +// N.B. systemview_target cannot be used at the same time as defmt_rtt. + +use rtos_trace; +use systemview_target::SystemView; +use panic_probe as _; +use log::*; + +static LOGGER: systemview_target::SystemView = systemview_target::SystemView::new(); +rtos_trace::global_trace!{SystemView} + +struct TraceInfo(); + +impl rtos_trace::RtosTraceApplicationCallbacks for TraceInfo { + fn system_description() {} + fn sysclock() -> u32 { + 64000000 + } +} +rtos_trace::global_application_callbacks!{TraceInfo} + +#[embassy_executor::task] +async fn run1() { + loop { + info!("DING DONG"); + Timer::after(Duration::from_ticks(16000)).await; + } +} + +#[embassy_executor::task] +async fn run2() { + loop { + Timer::at(Instant::from_ticks(0)).await; + } +} + +#[embassy_executor::task] +async fn run3() { + futures::future::poll_fn(|cx| { + cx.waker().wake_by_ref(); + Poll::<()>::Pending + }) + .await; +} + +#[embassy_executor::main] +async fn main(spawner: Spawner, _p: Peripherals) { + LOGGER.init(); + ::log::set_logger(&LOGGER).ok(); + ::log::set_max_level(::log::LevelFilter::Trace); + + spawner.spawn(run1()).unwrap(); + spawner.spawn(run2()).unwrap(); + spawner.spawn(run3()).unwrap(); +} From cd561b19ef411c296c86afc6f0df4f39caa1c9e9 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Tue, 16 Aug 2022 01:20:07 -0400 Subject: [PATCH 05/10] Allow rtos_trace example to be used without log --- examples/nrf/Cargo.toml | 3 +-- examples/nrf/src/bin/rtos_trace.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/nrf/Cargo.toml b/examples/nrf/Cargo.toml index 2f877b6a..8704f27c 100644 --- a/examples/nrf/Cargo.toml +++ b/examples/nrf/Cargo.toml @@ -35,7 +35,6 @@ log = [ rtos-trace = [ "dep:rtos-trace", "dep:systemview-target", - "log", "embassy-executor/rtos-trace", "embassy-executor/rtos-trace-interrupt", ] @@ -68,7 +67,7 @@ log = { version = "0.4.17", optional = true } [[bin]] name = "rtos_trace" -required-features = ["nightly", "rtos-trace", "log"] +required-features = ["nightly", "rtos-trace"] [patch.crates-io] rtos-trace = { git = "https://gitlab.com/quentinmit/rtos-trace.git", branch = "build-fix" } diff --git a/examples/nrf/src/bin/rtos_trace.rs b/examples/nrf/src/bin/rtos_trace.rs index 8b4f5b75..461e174c 100644 --- a/examples/nrf/src/bin/rtos_trace.rs +++ b/examples/nrf/src/bin/rtos_trace.rs @@ -13,6 +13,7 @@ use embassy_nrf::Peripherals; use rtos_trace; use systemview_target::SystemView; use panic_probe as _; +#[cfg(feature = "log")] use log::*; static LOGGER: systemview_target::SystemView = systemview_target::SystemView::new(); @@ -31,7 +32,10 @@ rtos_trace::global_application_callbacks!{TraceInfo} #[embassy_executor::task] async fn run1() { loop { + #[cfg(feature = "log")] info!("DING DONG"); + #[cfg(not(feature = "log"))] + rtos_trace::trace::marker(13); Timer::after(Duration::from_ticks(16000)).await; } } @@ -55,8 +59,11 @@ async fn run3() { #[embassy_executor::main] async fn main(spawner: Spawner, _p: Peripherals) { LOGGER.init(); - ::log::set_logger(&LOGGER).ok(); - ::log::set_max_level(::log::LevelFilter::Trace); + #[cfg(feature = "log")] + { + ::log::set_logger(&LOGGER).ok(); + ::log::set_max_level(::log::LevelFilter::Trace); + } spawner.spawn(run1()).unwrap(); spawner.spawn(run2()).unwrap(); From 7dfe119fe0c7b99d7a6d73af6ac3fc6f7cef9d12 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Tue, 16 Aug 2022 01:47:18 -0400 Subject: [PATCH 06/10] Run cargo fmt --- examples/nrf/src/bin/rtos_trace.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/examples/nrf/src/bin/rtos_trace.rs b/examples/nrf/src/bin/rtos_trace.rs index 461e174c..5699fe8e 100644 --- a/examples/nrf/src/bin/rtos_trace.rs +++ b/examples/nrf/src/bin/rtos_trace.rs @@ -7,17 +7,15 @@ use core::task::Poll; use embassy_executor::executor::Spawner; use embassy_executor::time::{Duration, Instant, Timer}; use embassy_nrf::Peripherals; - -// N.B. systemview_target cannot be used at the same time as defmt_rtt. - -use rtos_trace; -use systemview_target::SystemView; -use panic_probe as _; #[cfg(feature = "log")] use log::*; +use panic_probe as _; +// N.B. systemview_target cannot be used at the same time as defmt_rtt. +use rtos_trace; +use systemview_target::SystemView; static LOGGER: systemview_target::SystemView = systemview_target::SystemView::new(); -rtos_trace::global_trace!{SystemView} +rtos_trace::global_trace! {SystemView} struct TraceInfo(); @@ -27,7 +25,7 @@ impl rtos_trace::RtosTraceApplicationCallbacks for TraceInfo { 64000000 } } -rtos_trace::global_application_callbacks!{TraceInfo} +rtos_trace::global_application_callbacks! {TraceInfo} #[embassy_executor::task] async fn run1() { From 2edf532f8d8ce048137990bf74b07759428ed7c1 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Thu, 18 Aug 2022 01:38:58 -0400 Subject: [PATCH 07/10] 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"); } From 5ce18f49158e23a2a3c775343126d9670f212fc5 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Fri, 19 Aug 2022 00:54:53 -0400 Subject: [PATCH 08/10] Fix package name for the new nrf-rtos-trace example --- examples/nrf-rtos-trace/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/nrf-rtos-trace/Cargo.toml b/examples/nrf-rtos-trace/Cargo.toml index dad74235..bdf49f57 100644 --- a/examples/nrf-rtos-trace/Cargo.toml +++ b/examples/nrf-rtos-trace/Cargo.toml @@ -1,6 +1,6 @@ [package] edition = "2021" -name = "embassy-nrf-examples" +name = "embassy-nrf-rtos-trace-examples" version = "0.1.0" [features] From 0c7ad547935fa684b32c6fc59ac9d911f2e021a3 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Fri, 19 Aug 2022 11:58:45 -0400 Subject: [PATCH 09/10] Fetch systemview-target from upstream git --- examples/nrf-rtos-trace/Cargo.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/nrf-rtos-trace/Cargo.toml b/examples/nrf-rtos-trace/Cargo.toml index bdf49f57..52b4bb7e 100644 --- a/examples/nrf-rtos-trace/Cargo.toml +++ b/examples/nrf-rtos-trace/Cargo.toml @@ -35,5 +35,4 @@ 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" } +systemview-target = { git = "https://gitlab.com/bern-rtos/tools/rtos-trace.git", rev = "3f68ec60f07aa87c191628568263f57073aa3dab" } From 614b894ff871add9f0394fcf9ef220f133c4aae4 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Sat, 20 Aug 2022 14:16:06 -0400 Subject: [PATCH 10/10] Switch to crates.io version of systemview-target --- examples/nrf-rtos-trace/Cargo.toml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/examples/nrf-rtos-trace/Cargo.toml b/examples/nrf-rtos-trace/Cargo.toml index 52b4bb7e..b0907f92 100644 --- a/examples/nrf-rtos-trace/Cargo.toml +++ b/examples/nrf-rtos-trace/Cargo.toml @@ -27,12 +27,9 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa rand = { version = "0.8.4", default-features = false } 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"] } +systemview-target = { version = "0.1.2", 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] -systemview-target = { git = "https://gitlab.com/bern-rtos/tools/rtos-trace.git", rev = "3f68ec60f07aa87c191628568263f57073aa3dab" }