Skip to content

Commit b808120

Browse files
committed
check DWT::has_cycle_counter when configuring a comparator for that function & some cleanup
1 parent 331b8df commit b808120

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/peripheral/dwt.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ pub enum DwtError {
440440

441441
impl<SupportedFunctions: ComparatorSupportedFunctions> Comparator<SupportedFunctions> {
442442
/// 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`].
444444
fn configure_address_compare(
445445
&self,
446446
settings: ComparatorAddressSettings,
@@ -510,12 +510,19 @@ impl Comparator<NoCycleCompare> {
510510
}
511511

512512
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.
514516
#[allow(clippy::missing_inline_in_public_items)]
515517
pub fn configure(&self, settings: ComparatorFunction) -> Result<(), DwtError> {
516518
match settings {
517519
ComparatorFunction::Address(settings) => self.configure_address_compare(settings),
518520
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+
519526
let function = match &settings.emit {
520527
EmitOption::PCData => 0b0001,
521528
EmitOption::WatchpointDebugEvent => 0b0100,

0 commit comments

Comments
 (0)