From fa7e2702ded407c5f22cb82d5d11a3fcf7f4f76d Mon Sep 17 00:00:00 2001 From: banyanshade-software Date: Sat, 4 Jan 2025 11:25:24 +0100 Subject: [PATCH] added onechar_itm feature for issue #571 --- cortex-m/Cargo.toml | 1 + cortex-m/src/itm.rs | 19 +++++++++++++++++++ panic-itm/Cargo.toml | 3 +++ 3 files changed, 23 insertions(+) diff --git a/cortex-m/Cargo.toml b/cortex-m/Cargo.toml index d90dc376..6fc851b7 100644 --- a/cortex-m/Cargo.toml +++ b/cortex-m/Cargo.toml @@ -34,6 +34,7 @@ cm7-r0p1 = ["cm7"] linker-plugin-lto = [] std = [] critical-section-single-core = ["critical-section/restore-state-bool"] +onechar_itm = [] [package.metadata.docs.rs] targets = [ diff --git a/cortex-m/src/itm.rs b/cortex-m/src/itm.rs index 905aefb8..50177770 100644 --- a/cortex-m/src/itm.rs +++ b/cortex-m/src/itm.rs @@ -73,6 +73,7 @@ impl fmt::Write for Port<'_> { pub struct Aligned(pub T); /// Writes `buffer` to an ITM port. +#[cfg(not(feature="onechar_itm"))] #[allow(clippy::missing_inline_in_public_items)] pub fn write_all(port: &mut Stim, buffer: &[u8]) { unsafe { @@ -122,6 +123,24 @@ pub fn write_all(port: &mut Stim, buffer: &[u8]) { } } + +/// Writes `buffer` to an ITM port. +/// with onechar_itm features, this write a single byte in ITM u32 register +/// making ascii trace readable on Eclipse/STM32CubeIDE SWV monitor +#[cfg(feature="onechar_itm")] +#[allow(clippy::missing_inline_in_public_items)] +pub fn write_all(port: &mut Stim, buffer: &[u8]) { + for c in buffer { + while !port.is_fifo_ready() {} + port.write_u8(*c); + } +} + + + + + + /// Writes a 4-byte aligned `buffer` to an ITM port. /// /// # Examples diff --git a/panic-itm/Cargo.toml b/panic-itm/Cargo.toml index 1cf45ad1..7dd2299e 100644 --- a/panic-itm/Cargo.toml +++ b/panic-itm/Cargo.toml @@ -13,5 +13,8 @@ repository = "https://github.com/rust-embedded/cortex-m" version = "0.4.2" edition = "2018" +[features] +onechar_itm = [] + [dependencies] cortex-m = { path = "../cortex-m", version = ">= 0.5.8, < 0.8" }