nucleo-l053r8/examples/logging.rs
2025-04-28 11:53:13 +02:00

54 lines
1.4 KiB
Rust
Executable file

#![no_main]
#![no_std]
use defmt::{debug, error, info, println, trace, warn};
use panic_probe as _;
use defmt_rtt as _; // global logger
use cortex_m_rt::entry;
use hal::{pac, prelude::*, rcc::Config};
// same panicking *behavior* as `panic-probe` but doesn't print a panic message
// this prevents the panic message being printed *twice* when `defmt::panic` is invoked
#[defmt::panic_handler]
fn panic() -> ! {
cortex_m::asm::udf()
}
#[entry]
fn main() -> ! {
let dp = pac::Peripherals::take().unwrap();
let cp = cortex_m::Peripherals::take().unwrap();
// Configure the clock.
let mut rcc = dp.RCC.freeze(Config::hsi16());
// Acquire the GPIOA peripheral. This also enables the clock for GPIOA in
// the RCC register.
let gpioa = dp.GPIOA.split(&mut rcc);
// Configure PA5 as output.
let mut led = gpioa.pa5.into_push_pull_output();
// Get the delay provider.
let mut delay = cp.SYST.delay(rcc.clocks);
#[allow(clippy::never_loop)]
loop {
println!("Hello World!");
trace!("trace log");
debug!("debug log");
info!("info log");
warn!("warn log");
error!("error log");
led.set_high().unwrap();
delay.delay_ms(500_u16);
led.set_low().unwrap();
delay.delay_ms(500_u16);
panic!("This will use the defmt panic handler too");
}
}