1
0
Fork 0
kirdy-firmware/src/device/log_setup.rs

35 lines
1.1 KiB
Rust
Raw Normal View History

2022-10-22 20:20:49 +08:00
#[cfg(not(any(feature = "semihosting", feature = "RTT")))]
2022-10-20 20:57:24 +08:00
pub fn init_log() {
2022-10-22 20:20:49 +08:00
use super::usb;
2022-10-20 20:57:24 +08:00
static USB_LOGGER: usb::Logger = usb::Logger;
let _ = log::set_logger(&USB_LOGGER);
// log::set_max_level(log::LevelFilter::Debug);
log::set_max_level(log::LevelFilter::Trace);
2022-10-20 20:57:24 +08:00
}
2022-10-22 20:20:49 +08:00
#[cfg(feature = "RTT")]
pub fn init_log() {
2022-10-23 16:59:15 +08:00
use rtt_target::rtt_init_print;
use super::rtt_logger;
2022-10-22 20:20:49 +08:00
static RTT_LOGGER: rtt_logger::Logger = rtt_logger::Logger;
2022-10-23 16:59:15 +08:00
rtt_init_print!();
2022-10-22 20:20:49 +08:00
let _ = log::set_logger(&RTT_LOGGER);
log::set_max_level(log::LevelFilter::Debug);
}
2022-10-20 20:57:24 +08:00
#[cfg(feature = "semihosting")]
2022-10-20 15:17:43 +08:00
pub fn init_log() {
use cortex_m_log::{log::{init, Logger},
printer::semihosting::{hio::HStdout, InterruptOk}};
2022-10-20 15:17:43 +08:00
use log::LevelFilter;
static mut LOGGER: Option<Logger<InterruptOk<HStdout>>> = None;
let logger = Logger {
inner: InterruptOk::<_>::stdout().expect("semihosting stdout"),
level: LevelFilter::Info,
};
2022-10-22 15:49:01 +08:00
let logger = unsafe { LOGGER.get_or_insert(logger) };
2022-10-20 15:17:43 +08:00
init(logger).expect("set logger");
}