Move rtos-trace example to a separate project to simplify Cargo.toml
This commit is contained in:
9
examples/nrf-rtos-trace/.cargo/config.toml
Normal file
9
examples/nrf-rtos-trace/.cargo/config.toml
Normal file
@ -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"
|
51
examples/nrf-rtos-trace/Cargo.toml
Normal file
51
examples/nrf-rtos-trace/Cargo.toml
Normal file
@ -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" }
|
36
examples/nrf-rtos-trace/build.rs
Normal file
36
examples/nrf-rtos-trace/build.rs
Normal file
@ -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");
|
||||
}
|
7
examples/nrf-rtos-trace/memory.x
Normal file
7
examples/nrf-rtos-trace/memory.x
Normal file
@ -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
|
||||
}
|
69
examples/nrf-rtos-trace/src/bin/rtos_trace.rs
Normal file
69
examples/nrf-rtos-trace/src/bin/rtos_trace.rs
Normal file
@ -0,0 +1,69 @@
|
||||
#![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;
|
||||
#[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}
|
||||
|
||||
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 {
|
||||
#[cfg(feature = "log")]
|
||||
info!("DING DONG");
|
||||
#[cfg(not(feature = "log"))]
|
||||
rtos_trace::trace::marker(13);
|
||||
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();
|
||||
#[cfg(feature = "log")]
|
||||
{
|
||||
::log::set_logger(&LOGGER).ok();
|
||||
::log::set_max_level(::log::LevelFilter::Trace);
|
||||
}
|
||||
|
||||
spawner.spawn(run1()).unwrap();
|
||||
spawner.spawn(run2()).unwrap();
|
||||
spawner.spawn(run3()).unwrap();
|
||||
}
|
Reference in New Issue
Block a user