Skip to content

Commit 2ff4735

Browse files
committed
Update is_debugger_attached so as not to clear S_RESET_ST and S_RETIRE_ST
1 parent 2a15caa commit 2ff4735

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/peripheral/dcb.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use volatile_register::{RW, WO};
44

5+
use core::ptr;
56
use peripheral::DCB;
67

78
const DCB_DEMCR_TRCENA: u32 = 1 << 24;
@@ -26,26 +27,31 @@ impl DCB {
2627
/// soft-reset, only on power reset.
2728
pub fn enable_trace(&mut self) {
2829
// set bit 24 / TRCENA
29-
unsafe { self.demcr.modify(|w| w | DCB_DEMCR_TRCENA); }
30+
unsafe {
31+
self.demcr.modify(|w| w | DCB_DEMCR_TRCENA);
32+
}
3033
}
3134

3235
/// Disables TRACE. See `DCB::enable_trace()` for more details
3336
pub fn disable_trace(&mut self) {
3437
// unset bit 24 / TRCENA
35-
unsafe { self.demcr.modify(|w| w & !DCB_DEMCR_TRCENA); }
38+
unsafe {
39+
self.demcr.modify(|w| w & !DCB_DEMCR_TRCENA);
40+
}
3641
}
3742

38-
/// Is there a debugger attached? (see notes)
43+
/// Is there a debugger attached? (see note)
3944
///
40-
/// Note 1: This function is [reported not to
45+
/// Note: This function is [reported not to
4146
/// work](http://web.archive.org/web/20180821191012/https://community.nxp.com/thread/424925#comment-782843)
4247
/// on Cortex-M0 devices. Per the ARM v6-M Architecture Reference Manual, "Access to the DHCSR
4348
/// from software running on the processor is IMPLEMENTATION DEFINED". Indeed, from the
4449
/// [Cortex-M0+ r0p1 Technical Reference Manual](http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0484c/BABJHEIG.html), "Note Software cannot access the debug registers."
45-
///
46-
/// Note 2: This function reads the DHCSR register, and therefore clears S_RESET_ST and
47-
/// S_RETIRE_ST.
4850
pub fn is_debugger_attached() -> bool {
49-
unsafe { (*Self::ptr()).dhcsr.read() & 0x1 == 1 }
51+
unsafe {
52+
// do an 8-bit read of the 32-bit DHCSR register, and get the LSB
53+
let value = ptr::read_volatile(Self::ptr() as *const u8);
54+
value & 0x1 == 1
55+
}
5056
}
5157
}

0 commit comments

Comments
 (0)