Skip to content

Commit

Permalink
added onechar_itm feature for issue rust-embedded#571
Browse files Browse the repository at this point in the history
  • Loading branch information
banyanshade-software committed Jan 4, 2025
1 parent 9177271 commit fa7e270
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions cortex-m/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
19 changes: 19 additions & 0 deletions cortex-m/src/itm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl fmt::Write for Port<'_> {
pub struct Aligned<T: ?Sized>(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 {
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions panic-itm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

0 comments on commit fa7e270

Please sign in to comment.