1
0
forked from M-Labs/kirdy

use RTT for PanicInfo

This commit is contained in:
topquark12 2022-10-22 21:00:17 +08:00
parent 6a76536248
commit e562b822dc
3 changed files with 26 additions and 8 deletions

View File

@ -1,4 +1,4 @@
use super::{gpio, log_setup, sys_timer, usb};
use super::{gpio, sys_timer, usb};
use crate::laser_diode::current_sources::*;
use fugit::ExtU32;
use log::info;
@ -15,9 +15,6 @@ const WATCHDOG_PERIOD: u32 = 1000;
const WATCHDOG_PERIOD: u32 = 30000;
pub fn bootup(mut core_perif: CorePeripherals, perif: Peripherals) -> IndependentWatchdog {
log_setup::init_log();
info!("Kirdy init");
core_perif.SCB.enable_icache();
core_perif.SCB.enable_dcache(&mut core_perif.CPUID);

View File

@ -9,9 +9,7 @@ pub fn init_log() {
#[cfg(feature = "RTT")]
pub fn init_log() {
use super::rtt_logger;
use rtt_target::rtt_init_print;
static RTT_LOGGER: rtt_logger::Logger = rtt_logger::Logger;
rtt_init_print!();
let _ = log::set_logger(&RTT_LOGGER);
log::set_max_level(log::LevelFilter::Debug);
}

View File

@ -3,15 +3,38 @@
use cortex_m_rt::entry;
use log::info;
use panic_halt as _;
use stm32f4xx_hal::pac::{CorePeripherals, Peripherals};
mod device;
mod laser_diode;
use device::{boot::bootup, sys_timer};
use device::{boot::bootup, log_setup, sys_timer};
// If RTT is used, print panic info through RTT
#[cfg(feature = "RTT")]
use {
core::panic::PanicInfo,
rtt_target::{rprintln, rtt_init_print},
};
#[cfg(feature = "RTT")]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
rprintln!("{}", info);
loop {}
}
// Otherwise use panic halt
#[cfg(not(feature = "RTT"))]
use panic_halt as _;
#[entry]
fn main() -> ! {
// RTT does not rely on any peripherals, can be set up immidiately
#[cfg(feature = "RTT")]
rtt_init_print!();
log_setup::init_log();
info!("Kirdy init");
let core_perif = CorePeripherals::take().unwrap();
let perif = Peripherals::take().unwrap();