Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ name = "demo"
version = "0.1.0"

[features]
default = ['semihosting']
semihosting = ['panic-semihosting', 'kern/klog-semihosting']
itm = ["panic-halt", "kern/klog-itm"]
semihosting = ["panic-semihosting", "kern/klog-semihosting"]

[dependencies]
cortex-m = "0.6.0"
Expand Down
13 changes: 12 additions & 1 deletion demo/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ target = "thumbv7em-none-eabihf"
path = "../demo"
name = "demo"
requires = {flash = 65536, ram = 4096}
features = ["semihosting"]
#
# For the kernel (and for any task that logs), we are required to enable
# either "itm" (denoting logging/panicking via ARM's Instrumentation Trace
# Macrocell) or "semihosting" (denoting logging/panicking via ARM
# semihosting). We are biased to ITM because semihosting is excruciatingly
# slow (it is breakpoint based) and has an undesirable failure mode if logging
# output is generated and debugger is not attached (namely, the target stops).
# If one does choose to change this to semihosting for purposes of
# development, be sure to also change it in every task of interest.
#
features = ["itm"]

[supervisor]
notification = 1
Expand All @@ -29,6 +39,7 @@ name = "task-jefe"
priority = 0
requires = {flash = 32768, ram = 1024}
start = true
features = ["itm"]

[tasks.rcc_driver]
path = "../drv/stm32f4-rcc"
Expand Down
3 changes: 2 additions & 1 deletion kern/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ authors = ["Cliff L. Biffle <[email protected]>"]
edition = "2018"

[features]
default = ["klog-semihosting"]
default = ["klog-itm"]
klog-semihosting = ["cortex-m-semihosting"]
klog-itm = []

[dependencies]
abi = {path = "../abi"}
Expand Down
33 changes: 31 additions & 2 deletions kern/src/arch/arm_m.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,42 @@ use crate::umem::USlice;
/// the kernel by a chain of `#[macro_use]` attributes, but its implementation
/// is very architecture-specific at the moment.
///
/// TODO: someday it might be nice to change how this works.
#[cfg(not(feature = "klog-semihosting"))]
/// At the moment, there are two (architecture-specific) ways to log: via
/// semihosting (configured via the "klog-semihosting" feature) or via the
/// ARM's Instrumentation Trace Macrocell (configured via the "klog-itm"
/// feature). If neither of these features is enabled, klog! will be stubbed
/// out.
///
/// In the future, we will likely want to add at least one more mechanism for
/// logging (one that can be presumably be made neutral with respect to
/// architecure), whereby kernel logs can be produced somewhere (e.g., a ring
/// buffer) from which they can be consumed by some entity for shipping
/// elsewhere.
///
#[cfg(not(any(feature = "klog-semihosting", feature = "klog-itm")))]
macro_rules! klog {
($s:expr) => { };
($s:expr, $($tt:tt)*) => { };
}

#[cfg(feature = "klog-itm")]
macro_rules! klog {
($s:expr) => {
#[allow(unused_unsafe)]
unsafe {
let stim = &mut (*cortex_m::peripheral::ITM::ptr()).stim[0];
cortex_m::iprintln!(stim, $s);
}
};
($s:expr, $($tt:tt)*) => {
#[allow(unused_unsafe)]
unsafe {
let stim = &mut (*cortex_m::peripheral::ITM::ptr()).stim[0];
cortex_m::iprintln!(stim, $s, $($tt)*);
}
};
}

#[cfg(feature = "klog-semihosting")]
macro_rules! klog {
($s:expr) => { let _ = cortex_m_semihosting::hprintln!($s); };
Expand Down
4 changes: 3 additions & 1 deletion task-jefe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ userlib = {path = "../userlib"}
stm32f4 = {version = "0.10.0", features = ["stm32f407"]}
zerocopy = "0.3.0"
cortex-m = "0.6.0"
cortex-m-semihosting = "0.3.3"
cortex-m-semihosting = {version = "0.3.3", optional = true}

[features]
default = ["standalone"]
standalone = []
itm = [ "userlib/log-itm" ]
semihosting = [ "cortex-m-semihosting", "userlib/log-semihosting" ]

# This section is here to discourage RLS/rust-analyzer from doing test builds,
# since test builds don't work for cross compilation.
Expand Down
7 changes: 3 additions & 4 deletions task-jefe/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
#![no_main]

use userlib::*;
use cortex_m_semihosting::hprintln;

#[export_name = "main"]
fn main() -> ! {
hprintln!("viva el jefe").ok();
sys_log!("viva el jefe");

// We'll have notification 0 wired up to receive information about task
// faults.
Expand All @@ -43,14 +42,14 @@ fn main() -> ! {
for i in 0..NUM_TASKS {
let s = kipc::read_task_status(i);
if let abi::TaskState::Faulted { fault, .. } = s {
hprintln!("Task #{} fault: {:?}", i, fault).ok();
sys_log!("Task #{} fault: {:?}", i, fault);
// Stand it back up.
kipc::restart_task(i, true);
}
}
} else {
// ...huh. A task has sent a message to us. That seems wrong.
hprintln!("Unexpected message from {}", msginfo.sender.0).ok();
sys_log!("Unexpected message from {}", msginfo.sender.0);
}
}
}
2 changes: 2 additions & 0 deletions userlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ edition = "2018"
[features]
default = ["panic-messages"]
panic-messages = []
log-itm = []
log-semihosting = []

[dependencies]
abi = {path = "../abi"}
Expand Down
47 changes: 47 additions & 0 deletions userlib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,53 @@ pub fn sys_panic(
}
}

#[cfg(feature = "log-itm")]
#[macro_export]
macro_rules! sys_log {
($s:expr) => {
#[allow(unused_unsafe)]
unsafe {
let stim = &mut (*cortex_m::peripheral::ITM::ptr()).stim[1];
cortex_m::iprintln!(stim, $s);
}
};
($s:expr, $($tt:tt)*) => {
#[allow(unused_unsafe)]
unsafe {
let stim = &mut (*cortex_m::peripheral::ITM::ptr()).stim[1];
cortex_m::iprintln!(stim, $s, $($tt)*);
}
};
}

#[cfg(feature = "log-semihosting")]
#[macro_export]
macro_rules! sys_log {
($s:expr) => {
let _ = cortex_m_semihosting::hprintln!($s);
};
($s:expr, $($tt:tt)*) => {
let _ = cortex_m_semihosting::hprintln!($s, $($tt)*);
};
}

#[cfg(not(any(feature = "log-semihosting", feature = "log-itm")))]
#[macro_export]
macro_rules! sys_log {
($s:expr) => {
compile_error!(concat!(
"to use sys_log! must enable either ",
"'log-semihosting' or 'log-itm' feature"
))
};
($s:expr, $($tt:tt)*) => {
compile_error!(concat!(
"to use sys_log! must enable either ",
"'log-semihosting' or 'log-itm' feature"
))
};
}

/// This is the entry point for the kernel. Its job is to set up our memory
/// before jumping to user-defined `main`.
#[doc(hidden)]
Expand Down