@@ -452,7 +452,7 @@ pub enum DwtError {
452452
453453impl < SupportedFunctions : ComparatorSupportedFunctions > Comparator < SupportedFunctions > {
454454 /// 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`].
456456 fn configure_address_compare (
457457 & self ,
458458 settings : ComparatorAddressSettings ,
@@ -522,12 +522,19 @@ impl Comparator<NoCycleCompare> {
522522}
523523
524524impl 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.
526528 #[ allow( clippy:: missing_inline_in_public_items) ]
527529 pub fn configure ( & self , settings : ComparatorFunction ) -> Result < ( ) , DwtError > {
528530 match settings {
529531 ComparatorFunction :: Address ( settings) => self . configure_address_compare ( settings) ,
530532 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+
531538 let function = match & settings. emit {
532539 EmitOption :: PCData => 0b0001 ,
533540 EmitOption :: WatchpointDebugEvent => 0b0100 ,
0 commit comments