Skip to content
Snippets Groups Projects
Commit 0cb4cf61 authored by Per's avatar Per
Browse files

itm packaging according to CMSIS

parent 4eb02a2c
Branches itm
No related tags found
No related merge requests found
...@@ -7,7 +7,7 @@ keywords = ["arm", "cortex-m", "register", "peripheral"] ...@@ -7,7 +7,7 @@ keywords = ["arm", "cortex-m", "register", "peripheral"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
name = "cortex-m" name = "cortex-m"
repository = "https://github.com/japaric/cortex-m" repository = "https://github.com/japaric/cortex-m"
version = "0.3.1" version = "0.3.2"
[dependencies] [dependencies]
aligned = "0.1.1" aligned = "0.1.1"
......
//! Instrumentation Trace Macrocell //! Instrumentation Trace Macrocell
use core::{fmt, mem, ptr, slice}; use core::{fmt, ptr, slice};
use aligned::Aligned; use aligned::Aligned;
...@@ -27,47 +27,52 @@ impl<'p> fmt::Write for Port<'p> { ...@@ -27,47 +27,52 @@ impl<'p> fmt::Write for Port<'p> {
/// Writes a `buffer` to the ITM `port` /// Writes a `buffer` to the ITM `port`
pub fn write_all(port: &Stim, buffer: &[u8]) { pub fn write_all(port: &Stim, buffer: &[u8]) {
unsafe { for d in buffer {
let mut len = buffer.len();
let mut ptr = buffer.as_ptr();
if len == 0 {
return;
}
// 0x01 OR 0x03
if ptr as usize % 2 == 1 {
while !port.is_fifo_ready() {} while !port.is_fifo_ready() {}
port.write_u8(*ptr); port.write_u32(*d as u32);
}
// 0x02 OR 0x04 // unsafe {
ptr = ptr.offset(1); // let mut len = buffer.len();
len -= 1; // let mut ptr = buffer.as_ptr();
} //
// if len == 0 {
// 0x02 // return;
if ptr as usize % 4 == 2 { // }
if len > 1 { //
// at least 2 bytes //
while !port.is_fifo_ready() {} // // 0x01 OR 0x03
port.write_u16(ptr::read(ptr as *const u16)); // if ptr as usize % 2 == 1 {
// while !port.is_fifo_ready() {}
// 0x04 // port.write_u8(*ptr);
ptr = ptr.offset(2); //
len -= 2; // // 0x02 OR 0x04
} else { // ptr = ptr.offset(1);
if len == 1 { // len -= 1;
// last byte // }
while !port.is_fifo_ready() {} //
port.write_u8(*ptr); // // 0x02
} // if ptr as usize % 4 == 2 {
// if len > 1 {
return; // // at least 2 bytes
} // while !port.is_fifo_ready() {}
} // port.write_u16(ptr::read(ptr as *const u16));
//
write_aligned(port, mem::transmute(slice::from_raw_parts(ptr, len))); // // 0x04
} // ptr = ptr.offset(2);
// len -= 2;
// } else {
// if len == 1 {
// // last byte
// while !port.is_fifo_ready() {}
// port.write_u8(*ptr);
// }
//
// return;
// }
// }
//
// write_aligned(port, mem::transmute(slice::from_raw_parts(ptr, len)));
// }
} }
/// Writes a 4-byte aligned `buffer` to the ITM `port` /// Writes a 4-byte aligned `buffer` to the ITM `port`
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment