Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken rtic-monotonic stm32 behavior #958

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rtic-monotonics/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top!

## Unreleased

### Fixed

- Fix logic errors in `stm32.rs`

## v2.0.1 - 2024-06-02

### Changed
Expand Down
18 changes: 5 additions & 13 deletions rtic-monotonics/src/stm32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ macro_rules! make_timer {
$timer.dier().modify(|r| r.set_uie(true));

// Configure and enable half-period interrupt
$timer.ccr(2).write(|r| r.set_ccr(($bits::MAX - ($bits::MAX >> 1)).into()));
$timer.dier().modify(|r| r.set_ccie(2, true));
$timer.ccr(1).write(|r| r.set_ccr(($bits::MAX - ($bits::MAX >> 1)).into()));
$timer.dier().modify(|r| r.set_ccie(1, true));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modify to ccr(0). ccr(1) is already occupied.


// Trigger an update event to load the prescaler value to the clock.
$timer.egr().write(|r| r.set_ug(true));
Expand Down Expand Up @@ -294,21 +294,13 @@ macro_rules! make_timer {
}

fn clear_compare_flag() {
$timer.sr().modify(|r| r.set_ccif(1, false));
// Do nothing, because the flags are cleared below in on_interrupt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect, this flag is for the user triggered interrupt, the other one is for the half-overflow interrupt. Please do not remove this line.

}

fn pend_interrupt() {
cortex_m::peripheral::NVIC::pend(pac::Interrupt::$timer);
}

fn enable_timer() {
$timer.dier().modify(|r| r.set_ccie(1, true));
}

fn disable_timer() {
$timer.dier().modify(|r| r.set_ccie(1, false));
}

Copy link
Contributor

@Finomnis Finomnis Jul 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave this. It is used by ccr(1). It isn't absolutely crucial, but it does serve its purpose. It reduces the amount of interrupts fired in idle.

fn on_interrupt() {
// Full period
if $timer.sr().read().uif() {
Expand All @@ -317,8 +309,8 @@ macro_rules! make_timer {
assert!(prev % 2 == 1, "Monotonic must have missed an interrupt!");
}
// Half period
if $timer.sr().read().ccif(2) {
$timer.sr().modify(|r| r.set_ccif(2, false));
if $timer.sr().read().ccif(1) {
$timer.sr().modify(|r| r.set_ccif(1, false));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ccr(0) instead. ccr(1) is already used.

let prev = $overflow.fetch_add(1, Ordering::Relaxed);
assert!(prev % 2 == 0, "Monotonic must have missed an interrupt!");
}
Expand Down