@@ -82,11 +82,17 @@ bitfield! {
8282 #[ repr( C ) ]
8383 #[ derive( Copy , Clone ) ]
8484 /// Comparator FUNCTIONn register.
85+ ///
86+ /// See C1.8.17 "Comparator Function registers, DWT_FUNCTIONn"
8587 pub struct Function ( u32 ) ;
8688 u8 , function, set_function: 3 , 0 ;
8789 emitrange, set_emitrange: 5 ;
8890 cycmatch, set_cycmatch: 7 ;
8991 datavmatch, set_datavmatch: 8 ;
92+ lnk1ena, set_lnk1ena: 9 ;
93+ u8 , datavsize, set_datavsize: 2 , 10 ;
94+ u8 , datavaddr0, set_datavaddr0: 4 , 12 ;
95+ u8 , datavaddr1, set_datavaddr1: 4 , 16 ;
9096 matched, _: 24 ;
9197}
9298
@@ -372,8 +378,6 @@ pub struct CycleCountSettings {
372378 pub emit : EmitOption ,
373379 /// The cycle count value to compare against.
374380 pub compare : u32 ,
375- /// The cycle count mask value to use.
376- pub mask : u32 ,
377381}
378382
379383/// The available functions of a DWT comparator.
@@ -383,6 +387,8 @@ pub enum ComparatorFunction {
383387 /// Compare accessed memory addresses.
384388 Address ( ComparatorAddressSettings ) ,
385389 /// Compare cycle count & target value.
390+ ///
391+ /// **NOTE**: only supported by comparator 0. See C1.8.1.
386392 CycleCount ( CycleCountSettings ) ,
387393}
388394
@@ -392,12 +398,14 @@ pub enum ComparatorFunction {
392398pub enum DwtError {
393399 /// Invalid combination of [AccessType] and [EmitOption].
394400 InvalidFunction ,
401+ /// The DWT block does not implement cycle count capabilities.
402+ NoCycleCount ,
395403}
396404
397405impl Comparator {
398406 /// Configure the function of the comparator
399407 #[ allow( clippy:: missing_inline_in_public_items) ]
400- pub fn configure ( & self , settings : ComparatorFunction ) -> Result < ( ) , DwtError > {
408+ pub fn configure ( & self , dwt : & DWT , settings : ComparatorFunction ) -> Result < ( ) , DwtError > {
401409 match settings {
402410 ComparatorFunction :: Address ( settings) => {
403411 // FUNCTION, EMITRANGE
@@ -446,6 +454,10 @@ impl Comparator {
446454 }
447455 }
448456 ComparatorFunction :: CycleCount ( settings) => {
457+ if !dwt. has_cycle_counter ( ) {
458+ return Err ( DwtError :: NoCycleCount ) ;
459+ }
460+
449461 let function = match & settings. emit {
450462 EmitOption :: PCData => 0b0001 ,
451463 EmitOption :: WatchpointDebugEvent => 0b0100 ,
@@ -462,11 +474,16 @@ impl Comparator {
462474 r. set_datavmatch ( false ) ;
463475 // compare cyccnt
464476 r. set_cycmatch ( true ) ;
477+ // SBZ as needed, see Page 784/C1-724
478+ r. set_datavsize ( 0 ) ;
479+ r. set_datavaddr0 ( 0 ) ;
480+ r. set_datavaddr1 ( 0 ) ;
481+
465482 r
466483 } ) ;
467484
468485 self . comp . write ( settings. compare ) ;
469- self . mask . write ( settings . mask ) ;
486+ self . mask . write ( 0 ) ; // SBZ, see Page 784/C1-724
470487 }
471488 }
472489 }
0 commit comments