@@ -82,11 +82,17 @@ bitfield! {
82
82
#[ repr( C ) ]
83
83
#[ derive( Copy , Clone ) ]
84
84
/// Comparator FUNCTIONn register.
85
+ ///
86
+ /// See C1.8.17 "Comparator Function registers, DWT_FUNCTIONn"
85
87
pub struct Function ( u32 ) ;
86
88
u8 , function, set_function: 3 , 0 ;
87
89
emitrange, set_emitrange: 5 ;
88
90
cycmatch, set_cycmatch: 7 ;
89
91
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 ;
90
96
matched, _: 24 ;
91
97
}
92
98
@@ -372,8 +378,6 @@ pub struct CycleCountSettings {
372
378
pub emit : EmitOption ,
373
379
/// The cycle count value to compare against.
374
380
pub compare : u32 ,
375
- /// The cycle count mask value to use.
376
- pub mask : u32 ,
377
381
}
378
382
379
383
/// The available functions of a DWT comparator.
@@ -383,6 +387,8 @@ pub enum ComparatorFunction {
383
387
/// Compare accessed memory addresses.
384
388
Address ( ComparatorAddressSettings ) ,
385
389
/// Compare cycle count & target value.
390
+ ///
391
+ /// **NOTE**: only supported by comparator 0. See C1.8.1.
386
392
CycleCount ( CycleCountSettings ) ,
387
393
}
388
394
@@ -392,12 +398,14 @@ pub enum ComparatorFunction {
392
398
pub enum DwtError {
393
399
/// Invalid combination of [AccessType] and [EmitOption].
394
400
InvalidFunction ,
401
+ /// The DWT block does not implement cycle count capabilities.
402
+ NoCycleCount ,
395
403
}
396
404
397
405
impl Comparator {
398
406
/// Configure the function of the comparator
399
407
#[ 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 > {
401
409
match settings {
402
410
ComparatorFunction :: Address ( settings) => {
403
411
// FUNCTION, EMITRANGE
@@ -446,6 +454,10 @@ impl Comparator {
446
454
}
447
455
}
448
456
ComparatorFunction :: CycleCount ( settings) => {
457
+ if !dwt. has_cycle_counter ( ) {
458
+ return Err ( DwtError :: NoCycleCount ) ;
459
+ }
460
+
449
461
let function = match & settings. emit {
450
462
EmitOption :: PCData => 0b0001 ,
451
463
EmitOption :: WatchpointDebugEvent => 0b0100 ,
@@ -462,11 +474,16 @@ impl Comparator {
462
474
r. set_datavmatch ( false ) ;
463
475
// compare cyccnt
464
476
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
+
465
482
r
466
483
} ) ;
467
484
468
485
self . comp . write ( settings. compare ) ;
469
- self . mask . write ( settings . mask ) ;
486
+ self . mask . write ( 0 ) ; // SBZ, see Page 784/C1-724
470
487
}
471
488
}
472
489
}
0 commit comments