use rtt logging

This commit is contained in:
Robert Jördens 2021-05-12 19:02:15 +02:00
parent 76b9be6d93
commit 5b616a2874
4 changed files with 64 additions and 45 deletions

68
Cargo.lock generated
View File

@ -133,17 +133,6 @@ dependencies = [
"volatile-register", "volatile-register",
] ]
[[package]]
name = "cortex-m-log"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e202d2eac4e34adf7524a563e36623bae6f69cc0a73ef9bd22a4c93a5a806fa"
dependencies = [
"cortex-m 0.7.2",
"cortex-m-semihosting",
"log",
]
[[package]] [[package]]
name = "cortex-m-rt" name = "cortex-m-rt"
version = "0.6.13" version = "0.6.13"
@ -191,15 +180,6 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "cortex-m-semihosting"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6bffa6c1454368a6aa4811ae60964c38e6996d397ff8095a8b9211b1c1f749bc"
dependencies = [
"cortex-m 0.7.2",
]
[[package]] [[package]]
name = "derive_miniconf" name = "derive_miniconf"
version = "0.1.0" version = "0.1.0"
@ -538,13 +518,13 @@ dependencies = [
] ]
[[package]] [[package]]
name = "panic-semihosting" name = "panic-rtt-target"
version = "0.5.6" version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d55dedd501dfd02514646e0af4d7016ce36bc12ae177ef52056989966a1eec" checksum = "0d6ab67bc881453e4c90f958c657c1303670ea87bc1a16e87fd71a40f656dce9"
dependencies = [ dependencies = [
"cortex-m 0.7.2", "cortex-m 0.7.2",
"cortex-m-semihosting", "rtt-target 0.3.1",
] ]
[[package]] [[package]]
@ -646,6 +626,35 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "rtt-logger"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d082d3a20a5d4f69ad509720de1777fe5aa2092ea1af51b254ff79113d46d2ea"
dependencies = [
"log",
"rtt-target 0.2.2",
]
[[package]]
name = "rtt-target"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0869b4c5b6a6d8c5583fc473f9eb3423a170f77626b8c8a7fb18eddcda5770e2"
dependencies = [
"cortex-m 0.6.7",
"ufmt-write",
]
[[package]]
name = "rtt-target"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "065d6058bb1204f51a562a67209e1817cf714759d5cf845aa45c75fa7b0b9d9b"
dependencies = [
"ufmt-write",
]
[[package]] [[package]]
name = "rustc_version" name = "rustc_version"
version = "0.2.3" version = "0.2.3"
@ -746,7 +755,6 @@ dependencies = [
"ad9959", "ad9959",
"asm-delay", "asm-delay",
"cortex-m 0.6.7", "cortex-m 0.6.7",
"cortex-m-log",
"cortex-m-rt", "cortex-m-rt",
"cortex-m-rtic", "cortex-m-rtic",
"dsp", "dsp",
@ -759,8 +767,10 @@ dependencies = [
"miniconf", "miniconf",
"minimq", "minimq",
"nb 1.0.0", "nb 1.0.0",
"panic-semihosting", "panic-rtt-target",
"paste", "paste",
"rtt-logger",
"rtt-target 0.2.2",
"serde", "serde",
"serde-json-core", "serde-json-core",
"shared-bus", "shared-bus",
@ -822,6 +832,12 @@ version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06"
[[package]]
name = "ufmt-write"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e87a2ed6b42ec5e28cc3b94c09982969e9227600b2e3dcbc1db927a84c06bd69"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
version = "0.2.1" version = "0.2.1"

View File

@ -30,9 +30,10 @@ members = ["ad9959", "dsp"]
[dependencies] [dependencies]
cortex-m = { version = "0.6", features = ["const-fn"] } cortex-m = { version = "0.6", features = ["const-fn"] }
cortex-m-rt = { version = "0.6", features = ["device"] } cortex-m-rt = { version = "0.6", features = ["device"] }
cortex-m-log = { version = "0.7", features = ["log-integration"] } log = { version = "0.4", features = ["max_level_trace", "release_max_level_info"] }
log = "0.4" rtt-target = { version = "0.2.1", features = ["cortex-m"], optional = true }
panic-semihosting = { version = "0.5", optional = true } panic-rtt-target = { version = "0.1.1", features = ["cortex-m"], optional = true }
rtt-logger = { version = "0.1", optional = true }
serde = { version = "1.0", features = ["derive"], default-features = false } serde = { version = "1.0", features = ["derive"], default-features = false }
heapless = { version = "0.6", features = ["serde"] } heapless = { version = "0.6", features = ["serde"] }
cortex-m-rtic = "0.5.6" cortex-m-rtic = "0.5.6"
@ -69,7 +70,7 @@ git = "https://github.com/quartiq/minimq.git"
rev = "d2ec3e8" rev = "d2ec3e8"
[features] [features]
semihosting = ["panic-semihosting", "cortex-m-log/semihosting"] rtt = [ "rtt-target", "panic-rtt-target", "rtt-logger" ]
bkpt = [ ] bkpt = [ ]
nightly = ["cortex-m/inline-asm", "dsp/nightly"] nightly = ["cortex-m/inline-asm", "dsp/nightly"]
pounder_v1_1 = [ ] pounder_v1_1 = [ ]

View File

@ -145,19 +145,21 @@ pub fn setup(
.pll2_q_ck(100.mhz()) .pll2_q_ck(100.mhz())
.freeze(vos, &device.SYSCFG); .freeze(vos, &device.SYSCFG);
#[cfg(feature = "semihosting")] #[cfg(feature = "rtt")]
{ {
use cortex_m_log::log::{init as init_log, Logger}; // Enable debug during WFE/WFI-induced sleep
use cortex_m_log::printer::semihosting::{hio::HStdout, InterruptOk}; device.DBGMCU.cr.modify(|_, w| w.dbgsleep_d1().set_bit());
use log::LevelFilter;
static mut LOGGER: Option<Logger<InterruptOk<HStdout>>> = None;
let logger = Logger {
inner: InterruptOk::<_>::stdout().unwrap(),
level: LevelFilter::Info,
};
let logger = unsafe { LOGGER.get_or_insert(logger) };
init_log(logger).unwrap(); use log::LevelFilter;
use rtt_logger::RTTLogger;
use rtt_target::rtt_init_print;
static LOGGER: RTTLogger = RTTLogger::new(LevelFilter::Info);
rtt_init_print!(NoBlockSkip, 1024);
log::set_logger(&LOGGER)
.map(|()| log::set_max_level(log::LevelFilter::Trace))
.unwrap();
log::info!("Setup...");
} }
// Set up the system timer for RTIC scheduling. // Set up the system timer for RTIC scheduling.

View File

@ -4,9 +4,6 @@ use stm32h7xx_hal as hal;
// Re-export for the DigitalInputs below: // Re-export for the DigitalInputs below:
pub use embedded_hal::digital::v2::InputPin; pub use embedded_hal::digital::v2::InputPin;
#[cfg(feature = "semihosting")]
use panic_semihosting as _;
mod adc; mod adc;
mod afe; mod afe;
mod configuration; mod configuration;
@ -57,9 +54,12 @@ pub type EthernetPhy = hal::ethernet::phy::LAN8742A<hal::ethernet::EthernetMAC>;
pub use configuration::{setup, PounderDevices, StabilizerDevices}; pub use configuration::{setup, PounderDevices, StabilizerDevices};
#[cfg(feature = "rtt")]
use panic_rtt_target as _;
#[inline(never)] #[inline(never)]
#[panic_handler] #[panic_handler]
#[cfg(all(not(feature = "semihosting")))] #[cfg(all(not(feature = "rtt")))]
fn panic(_info: &core::panic::PanicInfo) -> ! { fn panic(_info: &core::panic::PanicInfo) -> ! {
let gpiod = unsafe { &*hal::stm32::GPIOD::ptr() }; let gpiod = unsafe { &*hal::stm32::GPIOD::ptr() };
// Turn on both red LEDs, FP_LED_1, FP_LED_3 // Turn on both red LEDs, FP_LED_1, FP_LED_3