@@ -440,7 +440,7 @@ pub enum DwtError {
440
440
441
441
impl < SupportedFunctions : ComparatorSupportedFunctions > Comparator < SupportedFunctions > {
442
442
/// Private function for configuring address compare on any [`Comparator`] since they all support this.
443
- /// Utilized publicly through [`Comparator::configure`]
443
+ /// Utilized publicly through [`Comparator::configure`].
444
444
fn configure_address_compare (
445
445
& self ,
446
446
settings : ComparatorAddressSettings ,
@@ -510,12 +510,19 @@ impl Comparator<NoCycleCompare> {
510
510
}
511
511
512
512
impl Comparator < HasCycleCompare > {
513
- /// Configure the function of the [`Comparator`]. Has support for cycle count comparison.
513
+ /// Configure the function of the [`Comparator`]. Has support for cycle count comparison
514
+ /// and checks [`DWT::has_cycle_counter`] for hardware support if
515
+ /// [`CycleCount`](ComparatorFunction::CycleCount) is requested.
514
516
#[ allow( clippy:: missing_inline_in_public_items) ]
515
517
pub fn configure ( & self , settings : ComparatorFunction ) -> Result < ( ) , DwtError > {
516
518
match settings {
517
519
ComparatorFunction :: Address ( settings) => self . configure_address_compare ( settings) ,
518
520
ComparatorFunction :: CycleCount ( settings) => {
521
+ // Check if the HW advertises that it has the cycle counter or not
522
+ if !DWT :: has_cycle_counter ( ) {
523
+ return Err ( DwtError :: UnsupportedFunction ) ;
524
+ }
525
+
519
526
let function = match & settings. emit {
520
527
EmitOption :: PCData => 0b0001 ,
521
528
EmitOption :: WatchpointDebugEvent => 0b0100 ,
0 commit comments