-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not reset
UsbSerialJtag
peripheral (#1961)
* Fix typos * Add a function to detect debugger connection * Do not reset USB peripheral * Changelog * Fix different register names * Reuse xtensa_lx::is_debugger_attached
- Loading branch information
Showing
7 changed files
with
97 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//! Debugger utilities | ||
|
||
/// Checks if a debugger is connected. | ||
pub fn debugger_connected() -> bool { | ||
#[cfg(xtensa)] | ||
{ | ||
xtensa_lx::is_debugger_attached() | ||
} | ||
|
||
#[cfg(riscv)] | ||
{ | ||
use crate::peripherals::ASSIST_DEBUG; | ||
let assist_debug = unsafe { &*ASSIST_DEBUG::ptr() }; | ||
#[cfg(feature = "esp32c2")] | ||
{ | ||
assist_debug | ||
.core_0_debug_mode() | ||
.read() | ||
.core_0_debug_module_active() | ||
.bit_is_set() | ||
} | ||
#[cfg(not(feature = "esp32c2"))] | ||
{ | ||
assist_debug | ||
.c0re_0_debug_mode() | ||
.read() | ||
.core_0_debug_module_active() | ||
.bit_is_set() | ||
} | ||
} | ||
|
||
#[cfg(not(any(xtensa, riscv)))] | ||
{ | ||
false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//! USB Serial JTAG tests | ||
|
||
//% CHIPS: esp32c3 esp32c6 esp32h2 esp32s3 | ||
|
||
#![no_std] | ||
#![no_main] | ||
|
||
#[cfg(test)] | ||
#[embedded_test::tests] | ||
mod tests { | ||
use defmt_rtt as _; | ||
use esp_backtrace as _; | ||
use esp_hal::{ | ||
clock::ClockControl, | ||
peripherals::Peripherals, | ||
system::SystemControl, | ||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer}, | ||
usb_serial_jtag::UsbSerialJtag, | ||
}; | ||
|
||
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html | ||
macro_rules! mk_static { | ||
($t:ty,$val:expr) => {{ | ||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); | ||
#[deny(unused_attributes)] | ||
let x = STATIC_CELL.uninit().write(($val)); | ||
x | ||
}}; | ||
} | ||
|
||
#[test] | ||
fn creating_peripheral_does_not_break_debug_connection() { | ||
let peripherals = Peripherals::take(); | ||
let system = SystemControl::new(peripherals.SYSTEM); | ||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); | ||
|
||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); | ||
let timer0: ErasedTimer = timg0.timer0.into(); | ||
let timers = [OneShotTimer::new(timer0)]; | ||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers); | ||
esp_hal_embassy::init(&clocks, timers); | ||
|
||
_ = UsbSerialJtag::new_async(peripherals.USB_DEVICE).split(); | ||
} | ||
} |