Skip to content

Commit a2da38b

Browse files
Merge #111
111: Add DCB::enable_trace() and DCB::disable_trace() r=korken89 a=kellerkindt This is required for the cycle counter of DWT to work, if the power supply has been unplugged since the last time it has been flashed japaric/stm32f103xx-hal/issues/76. See bit 24 here http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0337e/CEGHJDCF.html Corresponding PR in stm32f103xx-hal: japaric/stm32f103xx-hal/pull/94 Co-authored-by: kellerkindt <[email protected]> Co-authored-by: Michael Watzko <[email protected]>
2 parents 278ab0d + 9b74fda commit a2da38b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/peripheral/dcb.rs

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

5+
use peripheral::DCB;
6+
7+
const DCB_DEMCR_TRCENA: u32 = 1 << 24;
8+
59
/// Register block
610
#[repr(C)]
711
pub struct RegisterBlock {
@@ -14,3 +18,20 @@ pub struct RegisterBlock {
1418
/// Debug Exception and Monitor Control
1519
pub demcr: RW<u32>,
1620
}
21+
22+
impl DCB {
23+
/// Enables TRACE. This is for example required by the
24+
/// `peripheral::DWT` cycle counter to work properly.
25+
/// As by STM documentation, this flag is not reset on
26+
/// soft-reset, only on power reset.
27+
pub fn enable_trace(&mut self) {
28+
// set bit 24 / TRCENA
29+
unsafe { self.demcr.modify(|w| w | DCB_DEMCR_TRCENA); }
30+
}
31+
32+
/// Disables TRACE. See `DCB::enable_trace()` for more details
33+
pub fn disable_trace(&mut self) {
34+
// unset bit 24 / TRCENA
35+
unsafe { self.demcr.modify(|w| w & !DCB_DEMCR_TRCENA); }
36+
}
37+
}

0 commit comments

Comments
 (0)