forked from M-Labs/kirdy
use RTT for PanicInfo
This commit is contained in:
parent
6a76536248
commit
e562b822dc
|
@ -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 crate::laser_diode::current_sources::*;
|
||||||
use fugit::ExtU32;
|
use fugit::ExtU32;
|
||||||
use log::info;
|
use log::info;
|
||||||
|
@ -15,9 +15,6 @@ const WATCHDOG_PERIOD: u32 = 1000;
|
||||||
const WATCHDOG_PERIOD: u32 = 30000;
|
const WATCHDOG_PERIOD: u32 = 30000;
|
||||||
|
|
||||||
pub fn bootup(mut core_perif: CorePeripherals, perif: Peripherals) -> IndependentWatchdog {
|
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_icache();
|
||||||
core_perif.SCB.enable_dcache(&mut core_perif.CPUID);
|
core_perif.SCB.enable_dcache(&mut core_perif.CPUID);
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,7 @@ pub fn init_log() {
|
||||||
#[cfg(feature = "RTT")]
|
#[cfg(feature = "RTT")]
|
||||||
pub fn init_log() {
|
pub fn init_log() {
|
||||||
use super::rtt_logger;
|
use super::rtt_logger;
|
||||||
use rtt_target::rtt_init_print;
|
|
||||||
static RTT_LOGGER: rtt_logger::Logger = rtt_logger::Logger;
|
static RTT_LOGGER: rtt_logger::Logger = rtt_logger::Logger;
|
||||||
rtt_init_print!();
|
|
||||||
let _ = log::set_logger(&RTT_LOGGER);
|
let _ = log::set_logger(&RTT_LOGGER);
|
||||||
log::set_max_level(log::LevelFilter::Debug);
|
log::set_max_level(log::LevelFilter::Debug);
|
||||||
}
|
}
|
||||||
|
|
27
src/main.rs
27
src/main.rs
|
@ -3,15 +3,38 @@
|
||||||
|
|
||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
use log::info;
|
use log::info;
|
||||||
use panic_halt as _;
|
|
||||||
use stm32f4xx_hal::pac::{CorePeripherals, Peripherals};
|
use stm32f4xx_hal::pac::{CorePeripherals, Peripherals};
|
||||||
|
|
||||||
mod device;
|
mod device;
|
||||||
mod laser_diode;
|
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]
|
#[entry]
|
||||||
fn main() -> ! {
|
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 core_perif = CorePeripherals::take().unwrap();
|
||||||
let perif = Peripherals::take().unwrap();
|
let perif = Peripherals::take().unwrap();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue