aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bors[bot] <bors[bot]@users.noreply.github.com> 2018-09-06 08:34:01 +0000
committerGravatar bors[bot] <bors[bot]@users.noreply.github.com> 2018-09-06 08:34:01 +0000
commita2da38b0dced156c6fa78fb71d1fea2acb908c4d (patch)
tree462c70ab13f0535cee934942342120a319595286
parent278ab0d5b929dc23e6d9538faf1bc2ac633b9caa (diff)
parent9b74fda2bc8be68b34160609d3566bd8e3cde3d9 (diff)
downloadcortex-m-a2da38b0dced156c6fa78fb71d1fea2acb908c4d.tar.gz
cortex-m-a2da38b0dced156c6fa78fb71d1fea2acb908c4d.tar.zst
cortex-m-a2da38b0dced156c6fa78fb71d1fea2acb908c4d.zip
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 <michael@kellerkindt.com> Co-authored-by: Michael Watzko <michael@watzko.de>
-rw-r--r--src/peripheral/dcb.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/peripheral/dcb.rs b/src/peripheral/dcb.rs
index 02ec901..14dc75b 100644
--- a/src/peripheral/dcb.rs
+++ b/src/peripheral/dcb.rs
@@ -2,6 +2,10 @@
use volatile_register::{RW, WO};
+use peripheral::DCB;
+
+const DCB_DEMCR_TRCENA: u32 = 1 << 24;
+
/// Register block
#[repr(C)]
pub struct RegisterBlock {
@@ -14,3 +18,20 @@ pub struct RegisterBlock {
/// Debug Exception and Monitor Control
pub demcr: RW<u32>,
}
+
+impl DCB {
+ /// Enables TRACE. This is for example required by the
+ /// `peripheral::DWT` cycle counter to work properly.
+ /// As by STM documentation, this flag is not reset on
+ /// soft-reset, only on power reset.
+ pub fn enable_trace(&mut self) {
+ // set bit 24 / TRCENA
+ unsafe { self.demcr.modify(|w| w | DCB_DEMCR_TRCENA); }
+ }
+
+ /// Disables TRACE. See `DCB::enable_trace()` for more details
+ pub fn disable_trace(&mut self) {
+ // unset bit 24 / TRCENA
+ unsafe { self.demcr.modify(|w| w & !DCB_DEMCR_TRCENA); }
+ }
+}