2
2
3
3
use volatile_register:: { RW , WO } ;
4
4
5
+ use core:: ptr;
5
6
use peripheral:: DCB ;
6
7
7
8
const DCB_DEMCR_TRCENA : u32 = 1 << 24 ;
@@ -26,26 +27,31 @@ impl DCB {
26
27
/// soft-reset, only on power reset.
27
28
pub fn enable_trace ( & mut self ) {
28
29
// 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
+ }
30
33
}
31
34
32
35
/// Disables TRACE. See `DCB::enable_trace()` for more details
33
36
pub fn disable_trace ( & mut self ) {
34
37
// 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
+ }
36
41
}
37
42
38
- /// Is there a debugger attached? (see notes )
43
+ /// Is there a debugger attached? (see note )
39
44
///
40
- /// Note 1 : This function is [reported not to
45
+ /// Note: This function is [reported not to
41
46
/// work](http://web.archive.org/web/20180821191012/https://community.nxp.com/thread/424925#comment-782843)
42
47
/// on Cortex-M0 devices. Per the ARM v6-M Architecture Reference Manual, "Access to the DHCSR
43
48
/// from software running on the processor is IMPLEMENTATION DEFINED". Indeed, from the
44
49
/// [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.
48
50
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
+ }
50
56
}
51
57
}
0 commit comments