Skip to content
Snippets Groups Projects
Commit 3208194d authored by Per Lindgren's avatar Per Lindgren
Browse files

ip, ipln, sp, spln

parent 3ef41518
Branches cortex-m-4
No related tags found
No related merge requests found
...@@ -6,8 +6,9 @@ ...@@ -6,8 +6,9 @@
macro_rules! ip { macro_rules! ip {
($s:expr) => { ($s:expr) => {
{ {
let p = cortex_m::Peripherals::take().unwrap(); extern crate cortex_m;
let mut itm = p.ITM; #[allow(unsafe_code)]
let itm = unsafe { &mut *cortex_m::peripheral::ITM::ptr() };
cortex_m::itm::write_str( cortex_m::itm::write_str(
&mut itm.stim[0], &mut itm.stim[0],
...@@ -19,8 +20,10 @@ macro_rules! ip { ...@@ -19,8 +20,10 @@ macro_rules! ip {
{ {
extern crate cortex_m; extern crate cortex_m;
#[allow(unsafe_code)] #[allow(unsafe_code)]
let itm = unsafe { &mut *cortex_m::peripheral::ITM::ptr() };
cortex_m::itm::write_fmt( cortex_m::itm::write_fmt(
unsafe { &mut itm.stim[0] }, &mut itm.stim[0],
format_args!($($arg)*) format_args!($($arg)*)
); );
} }
...@@ -42,26 +45,27 @@ macro_rules! ipln { ...@@ -42,26 +45,27 @@ macro_rules! ipln {
}; };
} }
/// Macro for sending a formatted string over semihosting, with a newline. /// Macro for sending a formatted string over semihosting.
#[macro_export] #[macro_export]
macro_rules! sprintln { macro_rules! sp {
($($e:tt)*) => { ($($e:tt)*) => {
{ {
extern crate cortex_m_semihosting; extern crate cortex_m_semihosting;
use core::fmt::Write; use core::fmt::Write;
writeln!(cortex_m_semihosting::hio::hstdout().unwrap(), $($e)*).unwrap(); write!(cortex_m_semihosting::hio::hstdout().unwrap(), $($e)*).unwrap();
} }
} }
} }
/// Macro for sending a formatted string over semihosting. /// Macro for sending a formatted string over semihosting, with a newline.
#[macro_export] #[macro_export]
macro_rules! sprint { macro_rules! spln {
($($e:tt)*) => { ($($e:tt)*) => {
{ {
extern crate cortex_m_semihosting; extern crate cortex_m_semihosting;
use core::fmt::Write; use core::fmt::Write;
write!(cortex_m_semihosting::hio::hstdout().unwrap(), $($e)*).unwrap(); writeln!(cortex_m_semihosting::hio::hstdout().unwrap(), $($e)*).unwrap();
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment