Skip to content

Commit

Permalink
Make itm use log::info as println to avoid logger arg
Browse files Browse the repository at this point in the history
  • Loading branch information
usbalbin committed Dec 16, 2023
1 parent 1bfa6d1 commit 089d6d7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions examples/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ fn EXTI15_10() {

#[entry]
fn main() -> ! {
utils::logger::init();

let mut dp = stm32::Peripherals::take().expect("cannot take peripherals");
let mut rcc = dp.RCC.constrain();
let mut syscfg = dp.SYSCFG.constrain();
Expand Down
2 changes: 2 additions & 0 deletions examples/flash_with_rtic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ mod app {

#[init]
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
crate::utils::logger::init();

let dp = cx.device;
let cp = cx.core;

Expand Down
2 changes: 2 additions & 0 deletions examples/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use utils::logger::println;

#[entry]
fn main() -> ! {
utils::logger::init();

println!("Hello, STM32G4!");

#[allow(clippy::empty_loop)]
Expand Down
2 changes: 1 addition & 1 deletion examples/independent_watchdog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use utils::logger::info;

#[entry]
fn main() -> ! {
//utils::logger::init();
utils::logger::init();
let dp = Peripherals::take().unwrap();

let mut watchdog = IndependentWatchdog::new(dp.IWDG);
Expand Down
2 changes: 2 additions & 0 deletions examples/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub fn exit() -> ! {

#[cortex_m_rt::entry]
fn main() -> ! {
utils::logger::init();

logger::info!("main");

panic!("Something bad");
Expand Down
13 changes: 11 additions & 2 deletions examples/utils/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ cfg_if::cfg_if! {
use log::LevelFilter;

pub use cortex_m_log::log::Logger;
pub use cortex_m_log::println;

use cortex_m_log::{
destination::Itm as ItmDest,
Expand All @@ -26,7 +25,7 @@ cfg_if::cfg_if! {
};

lazy_static! {
static ref LOGGER: Logger<ItmSync<InterruptFree>> = Logger {
pub static ref LOGGER: Logger<ItmSync<InterruptFree>> = Logger {
level: LevelFilter::Info,
inner: unsafe {
InterruptSync::new(
Expand All @@ -38,6 +37,16 @@ cfg_if::cfg_if! {
};
}

#[allow(unused_macros)]
macro_rules! println {
($($tt:tt)*) => {
log::info!($($tt,)*);
};
}

#[allow(unused_imports)]
pub(crate) use println;

#[allow(dead_code)]
pub fn init() {
cortex_m_log::log::init(&LOGGER).unwrap();
Expand Down

0 comments on commit 089d6d7

Please sign in to comment.