@@ -452,7 +452,7 @@ pub enum DwtError {
452
452
453
453
impl < SupportedFunctions : ComparatorSupportedFunctions > Comparator < SupportedFunctions > {
454
454
/// Private function for configuring address compare on any [`Comparator`] since they all support this.
455
- /// Utilized publicly through [`Comparator::configure`]
455
+ /// Utilized publicly through [`Comparator::configure`].
456
456
fn configure_address_compare (
457
457
& self ,
458
458
settings : ComparatorAddressSettings ,
@@ -522,12 +522,19 @@ impl Comparator<NoCycleCompare> {
522
522
}
523
523
524
524
impl Comparator < HasCycleCompare > {
525
- /// Configure the function of the [`Comparator`]. Has support for cycle count comparison.
525
+ /// Configure the function of the [`Comparator`]. Has support for cycle count comparison
526
+ /// and checks [`DWT::has_cycle_counter`] for hardware support if
527
+ /// [`CycleCount`](ComparatorFunction::CycleCount) is requested.
526
528
#[ allow( clippy:: missing_inline_in_public_items) ]
527
529
pub fn configure ( & self , settings : ComparatorFunction ) -> Result < ( ) , DwtError > {
528
530
match settings {
529
531
ComparatorFunction :: Address ( settings) => self . configure_address_compare ( settings) ,
530
532
ComparatorFunction :: CycleCount ( settings) => {
533
+ // Check if the HW advertises that it has the cycle counter or not
534
+ if !DWT :: has_cycle_counter ( ) {
535
+ return Err ( DwtError :: UnsupportedFunction ) ;
536
+ }
537
+
531
538
let function = match & settings. emit {
532
539
EmitOption :: PCData => 0b0001 ,
533
540
EmitOption :: WatchpointDebugEvent => 0b0100 ,
0 commit comments