diff options
author | 2021-12-15 10:59:45 -0800 | |
---|---|---|
committer | 2021-12-19 12:13:47 -0800 | |
commit | cd66d339cce732e6cea18441c7ae414209091340 (patch) | |
tree | 864128b7bfb65e253d8fe33c34fb53eceee3fe61 /src/peripheral/dwt.rs | |
parent | 67835ae2270c82650423524518047e37c8922be3 (diff) | |
download | cortex-m-cd66d339cce732e6cea18441c7ae414209091340.tar.gz cortex-m-cd66d339cce732e6cea18441c7ae414209091340.tar.zst cortex-m-cd66d339cce732e6cea18441c7ae414209091340.zip |
SBZ fields as needed, check if block supports cycle count compare
Diffstat (limited to '')
-rw-r--r-- | src/peripheral/dwt.rs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/peripheral/dwt.rs b/src/peripheral/dwt.rs index 4101860..a45032f 100644 --- a/src/peripheral/dwt.rs +++ b/src/peripheral/dwt.rs @@ -82,11 +82,17 @@ bitfield! { #[repr(C)] #[derive(Copy, Clone)] /// Comparator FUNCTIONn register. + /// + /// See C1.8.17 "Comparator Function registers, DWT_FUNCTIONn" pub struct Function(u32); u8, function, set_function: 3, 0; emitrange, set_emitrange: 5; cycmatch, set_cycmatch: 7; datavmatch, set_datavmatch: 8; + lnk1ena, set_lnk1ena: 9; + u8, datavsize, set_datavsize: 2, 10; + u8, datavaddr0, set_datavaddr0: 4, 12; + u8, datavaddr1, set_datavaddr1: 4, 16; matched, _: 24; } @@ -372,8 +378,6 @@ pub struct CycleCountSettings { pub emit: EmitOption, /// The cycle count value to compare against. pub compare: u32, - /// The cycle count mask value to use. - pub mask: u32, } /// The available functions of a DWT comparator. @@ -383,6 +387,8 @@ pub enum ComparatorFunction { /// Compare accessed memory addresses. Address(ComparatorAddressSettings), /// Compare cycle count & target value. + /// + /// **NOTE**: only supported by comparator 0. See C1.8.1. CycleCount(CycleCountSettings), } @@ -392,12 +398,14 @@ pub enum ComparatorFunction { pub enum DwtError { /// Invalid combination of [AccessType] and [EmitOption]. InvalidFunction, + /// The DWT block does not implement cycle count capabilities. + NoCycleCount, } impl Comparator { /// Configure the function of the comparator #[allow(clippy::missing_inline_in_public_items)] - pub fn configure(&self, settings: ComparatorFunction) -> Result<(), DwtError> { + pub fn configure(&self, dwt: &DWT, settings: ComparatorFunction) -> Result<(), DwtError> { match settings { ComparatorFunction::Address(settings) => { // FUNCTION, EMITRANGE @@ -446,6 +454,10 @@ impl Comparator { } } ComparatorFunction::CycleCount(settings) => { + if !dwt.has_cycle_counter() { + return Err(DwtError::NoCycleCount); + } + let function = match &settings.emit { EmitOption::PCData => 0b0001, EmitOption::WatchpointDebugEvent => 0b0100, @@ -462,11 +474,16 @@ impl Comparator { r.set_datavmatch(false); // compare cyccnt r.set_cycmatch(true); + // SBZ as needed, see Page 784/C1-724 + r.set_datavsize(0); + r.set_datavaddr0(0); + r.set_datavaddr1(0); + r }); self.comp.write(settings.compare); - self.mask.write(settings.mask); + self.mask.write(0); // SBZ, see Page 784/C1-724 } } } |