Skip to content

Commit ffa638c

Browse files
committed
check DWT::has_cycle_counter when configuring a comparator for that function & some cleanup
1 parent 916e494 commit ffa638c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/peripheral/dwt.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ pub enum DwtError {
452452

453453
impl<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

524524
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.
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

Comments
 (0)