Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add initial support for RMT in ESP32-H2 (#556)
- Add a fn to poll DMA transfers
- Add initial support for LEDC in ESP32-H2 (#560)
- Add initial support for ASSIST_DEBUG in ESP32-H2 (#566)

### Changed

Expand Down
2 changes: 1 addition & 1 deletion esp-hal-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ esp32 = { version = "0.23.0", features = ["critical-section"], optional = true
esp32c2 = { version = "0.11.0", features = ["critical-section"], optional = true }
esp32c3 = { version = "0.14.0", features = ["critical-section"], optional = true }
esp32c6 = { version = "0.4.0", features = ["critical-section"], optional = true }
esp32h2 = { git = "https://github.com/esp-rs/esp-pacs", rev = "687a383", package = "esp32h2", features = ["critical-section"], optional = true }
esp32h2 = { git = "https://github.com/esp-rs/esp-pacs", rev = "8903688", package = "esp32h2", features = ["critical-section"], optional = true }
esp32s2 = { version = "0.14.0", features = ["critical-section"], optional = true }
esp32s3 = { version = "0.18.0", features = ["critical-section"], optional = true }

Expand Down
6 changes: 4 additions & 2 deletions esp-hal-common/devices/esp32h2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ peripherals = [
# Peripherals available in the PAC:
"aes",
"apb_saradc",
# "assist_debug",
"assist_debug",
# "ds",
# "ecc",
"efuse",
Expand All @@ -30,7 +30,7 @@ peripherals = [
# "lp_timer",
"lp_wdt",
"mcpwm0",
# "mem_monitor",
"mem_monitor",
# "modem_lpcon",
# "modem_syscon",
# "otp_debug",
Expand All @@ -57,6 +57,8 @@ peripherals = [
"uart1",
# "uhci0",
"usb_device",
"assist_debug_sp_monitor",
"assist_debug_region_monitor",

# Additional peripherals defined by us (the developers):
"adc",
Expand Down
4 changes: 2 additions & 2 deletions esp-hal-common/src/soc/esp32h2/peripherals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub(crate) use self::peripherals::*;
crate::peripherals! {
AES => true,
APB_SARADC => true,
// ASSIST_DEBUG => true,
ASSIST_DEBUG => true,
// DS => true,
// ECC => true,
EFUSE => true,
Expand All @@ -32,7 +32,7 @@ crate::peripherals! {
// LP_TIMER => true,
LP_WDT => true,
MCPWM0 => true,
// MEM_MONITOR => true,
MEM_MONITOR => true,
// MODEM_LPCON => true,
// MODEM_SYSCON => true,
// OTP_DEBUG => true,
Expand Down
124 changes: 124 additions & 0 deletions esp32h2-hal/examples/debug_assist.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//! This shows debug-assist
//!
//! Uncomment the functionality you want to test

#![no_std]
#![no_main]

use core::cell::RefCell;

use critical_section::Mutex;
use esp32h2_hal::{
assist_debug::DebugAssist,
clock::ClockControl,
interrupt,
peripherals::{self, Peripherals},
prelude::*,
riscv,
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.PCR.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

let mut rtc = Rtc::new(peripherals.LP_CLKRST);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt0 = timer_group0.wdt;
let timer_group1 = TimerGroup::new(
peripherals.TIMG1,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt1 = timer_group1.wdt;

// Disable watchdog timers
rtc.swd.disable();
rtc.rwdt.disable();
wdt0.disable();
wdt1.disable();

let mut da = DebugAssist::new(
peripherals.ASSIST_DEBUG,
&mut system.peripheral_clock_control,
);

// Uncomment the functionality you want to test
// We use a 0x1200 wide SP and 0x100 regions, and RAM ends at 0x40850000

// Monitor the SP so as to prevent stack overflow or erroneous push/pop. When
// the SP exceeds the minimum or maximum threshold, the module will record the
// PC pointer and generate an interrupt
// da.enable_sp_monitor(0x4084ee00, 0x40850000);

// Monitor reads/writes performed by the CPU over data bus and peripheral bus
// in a certain address space, i.e., memory region. Whenever the bus reads or
// writes in the specified address space, an interrupt will be triggered
// da.enable_region0_monitor(0x4084ee00, 0x4084ef00, true, true);
da.enable_region1_monitor(0x4084ee00, 0x4084ef00, true, true);

critical_section::with(|cs| DA.borrow_ref_mut(cs).replace(da));

interrupt::enable(
peripherals::Interrupt::ASSIST_DEBUG,
interrupt::Priority::Priority3,
)
.unwrap();

unsafe {
riscv::interrupt::enable();
}

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_sp_monitor_interrupt_set() {
println!("SP MONITOR TRIGGERED");
da.clear_sp_monitor_interrupt();
let pc = da.get_sp_monitor_pc();
println!("PC = 0x{:x}", pc);
}

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 {}
});
}