esp-hal/esp32s3-hal/examples/debug_assist.rs
Björn Quentin ab79b142f7
Add DEBUG-ASSIST functionality (#484)
* Add DEBUG-ASSIST functionality

* Reformat `lib.rs`

* Reformat ESP32-C2 example
2023-04-20 07:38:55 -07:00

96 lines
2.3 KiB
Rust

//! This shows debug-assist
//!
//! Uncomment the functionality you want to test
#![no_std]
#![no_main]
use core::cell::RefCell;
use critical_section::Mutex;
use esp32s3_hal::{
assist_debug::DebugAssist,
clock::ClockControl,
interrupt,
peripherals::{self, Peripherals},
prelude::*,
timer::TimerGroup,
Rtc,
};
use esp_backtrace as _;
use esp_println::println;
static DA: Mutex<RefCell<Option<DebugAssist>>> = Mutex::new(RefCell::new(None));
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let mut system = peripherals.SYSTEM.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt = timer_group0.wdt;
let mut rtc = Rtc::new(peripherals.RTC_CNTL);
// Disable MWDT and RWDT (Watchdog) flash boot protection
wdt.disable();
rtc.rwdt.disable();
let mut da = DebugAssist::new(
peripherals.ASSIST_DEBUG,
&mut system.peripheral_clock_control,
);
// uncomment the functionality you want to test
da.enable_region0_monitor(0x3fcce000, 0x3fcce100, true, true);
// da.enable_region1_monitor(0x3fcce000, 0x3fcce100, true, true);
critical_section::with(|cs| DA.borrow_ref_mut(cs).replace(da));
interrupt::enable(
peripherals::Interrupt::ASSIST_DEBUG,
interrupt::Priority::Priority3,
)
.unwrap();
eat_up_stack(0);
loop {}
}
#[allow(unconditional_recursion)]
fn eat_up_stack(v: u32) {
println!("Iteration {v}");
eat_up_stack(v + 1);
}
#[interrupt]
fn ASSIST_DEBUG() {
critical_section::with(|cs| {
println!("\n\nDEBUG_ASSIST interrupt");
let mut da = DA.borrow_ref_mut(cs);
let da = da.as_mut().unwrap();
if da.is_region0_monitor_interrupt_set() {
println!("REGION0 MONITOR TRIGGERED");
da.clear_region0_monitor_interrupt();
let pc = da.get_region_monitor_pc();
println!("PC = 0x{:x}", pc);
}
if da.is_region1_monitor_interrupt_set() {
println!("REGION1 MONITOR TRIGGERED");
da.clear_region1_monitor_interrupt();
let pc = da.get_region_monitor_pc();
println!("PC = 0x{:x}", pc);
}
loop {}
});
}