va416xx-rs/va416xx-hal/examples/rtt-log.rs

39 lines
1.1 KiB
Rust
Raw Normal View History

2024-06-11 23:59:09 +02:00
//! Code to test RTT logger functionality.
2024-06-11 13:48:42 +02:00
#![no_main]
#![no_std]
use cortex_m_rt::entry;
2024-06-11 23:59:09 +02:00
use panic_rtt_target as _;
2024-06-11 13:48:42 +02:00
use rtt_target::{rprintln, rtt_init_print};
use va416xx as _;
2024-06-11 23:59:09 +02:00
use va416xx_hal::pac;
// Mask for the LED
const LED_PG5: u32 = 1 << 5;
2024-06-11 13:48:42 +02:00
#[entry]
fn main() -> ! {
2024-06-11 23:59:09 +02:00
// SAFETY: Peripherals are only stolen once here.
let dp = unsafe { pac::Peripherals::steal() };
// Enable all peripheral clocks
dp.sysconfig
.peripheral_clk_enable()
.modify(|_, w| unsafe { w.bits(0xffffffff) });
dp.portg.dir().modify(|_, w| unsafe { w.bits(LED_PG5) });
dp.portg
.datamask()
.modify(|_, w| unsafe { w.bits(LED_PG5) });
2024-06-11 13:48:42 +02:00
rtt_init_print!();
rprintln!("-- RTT Demo --");
let mut counter = 0;
loop {
rprintln!("{}: Hello, world!", counter);
2024-06-11 23:59:09 +02:00
// Still toggle LED. If there are issues with the RTT log, the LED
// blinking ensures that the application is actually running.
dp.portg.togout().write(|w| unsafe { w.bits(LED_PG5) });
2024-06-11 13:48:42 +02:00
counter += 1;
2024-06-11 23:59:09 +02:00
cortex_m::asm::delay(10_000_000);
2024-06-11 13:48:42 +02:00
}
}