fix dangling usb

This commit is contained in:
Mirabellensaft 2022-01-12 17:02:33 +01:00
parent fd03998fb7
commit 59f20c1c05
2 changed files with 20 additions and 0 deletions

View File

@ -6,5 +6,15 @@ use panic_probe as _;
// this prevents the panic message being printed *twice* when `defmt::panic` is invoked
#[defmt::panic_handler]
fn panic() -> ! {
unsafe {
// turn off the USB D+ pull-up before pausing the device with a breakpoint
// this disconnects the nRF device from the USB host so the USB host won't attempt further
// USB communication (and see an unresponsive device). probe-run will also reset the nRF's
// USBD peripheral when it sees the device in a halted state which has the same effect as
// this line but that can take a while and the USB host may issue a power cycle of the USB
// port / hub / root in the meantime, which can bring down the probe and break probe-run
const USBD_USBPULLUP: *mut u32 = 0x4002_7504 as *mut u32;
USBD_USBPULLUP.write_volatile(0)
}
cortex_m::asm::udf()
}

View File

@ -290,6 +290,16 @@ fn RTC0() {
/// Exits the application and prints a backtrace when the program is executed through the `probe-run`
/// Cargo runner
pub fn exit() -> ! {
unsafe {
// turn off the USB D+ pull-up before pausing the device with a breakpoint
// this disconnects the nRF device from the USB host so the USB host won't attempt further
// USB communication (and see an unresponsive device). probe-run will also reset the nRF's
// USBD peripheral when it sees the device in a halted state which has the same effect as
// this line but that can take a while and the USB host may issue a power cycle of the USB
// port / hub / root in the meantime, which can bring down the probe and break probe-run
const USBD_USBPULLUP: *mut u32 = 0x4002_7504 as *mut u32;
USBD_USBPULLUP.write_volatile(0)
}
defmt::println!("`dk::exit()` called; exiting ...");
// force any pending memory operation to complete before the BKPT instruction that follows
atomic::compiler_fence(Ordering::SeqCst);