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 STM32 Monotonic for peripherals with only two Clock Compare modules #960

Merged
merged 5 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion examples/stm32g030f6_periodic_prints/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
# TODO(2) replace `$CHIP` with your chip's name (see `probe-run --list-chips` output)
runner = "probe-run --chip STM32G030F6Px"
runner = "probe-rs run --chip STM32G030F6Px"
rustflags = [
"-C", "linker=flip-link",
"-C", "link-arg=-Tlink.x",
Expand Down
56 changes: 28 additions & 28 deletions examples/stm32g030f6_periodic_prints/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions examples/stm32g030f6_periodic_prints/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ version = "0.1.0"

[dependencies.rtic]
path = "../../rtic"
version = "2.0.1"
version = "2.1.1"
features = ["thumbv6-backend"]

[dependencies.rtic-monotonics]
path = "../../rtic-monotonics"
version = "2.0.0"
version = "2.0.1"
features = ["stm32g030f6", "stm32_tim3"]


[dependencies]
cortex-m = { version = "0.7.7", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7.3"
defmt = "0.3.4"
defmt-rtt = "0.4.0"
defmt = "0.3.8"
defmt-rtt = "0.4.1"
fugit = "0.3.7"
panic-probe = { version = "0.3.1", features = ["print-defmt"] }
panic-probe = { version = "0.3.2", features = ["print-defmt"] }
portable-atomic = { version = "1", features = ["unsafe-assume-single-core"] }

stm32g0xx-hal = { version = "0.2.0", features = ["rt", "stm32g030"] }
Expand Down
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 `stm32` monotonic for timer peripherals with only two clock compare modules

## v2.0.1 - 2024-06-02

### Changed
Expand Down
2 changes: 1 addition & 1 deletion rtic-monotonics/src/rp2040.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl TimerQueueBackend for TimerBackend {

// Since the timer may or may not overflow based on the requested compare val, we check
// how many ticks are left.
// `wrapping_sup` takes care of the u64 integer overflow special case.
// `wrapping_sub` takes care of the u64 integer overflow special case.
let val = if instant.wrapping_sub(now) <= MAX {
instant & MAX
} else {
Expand Down
10 changes: 5 additions & 5 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(0).write(|r| r.set_ccr(($bits::MAX - ($bits::MAX >> 1)).into()));
$timer.dier().modify(|r| r.set_ccie(0, true));

// Trigger an update event to load the prescaler value to the clock.
$timer.egr().write(|r| r.set_ug(true));
Expand Down Expand Up @@ -282,7 +282,7 @@ macro_rules! make_timer {
let now = Self::now();

// Since the timer may or may not overflow based on the requested compare val, we check how many ticks are left.
// `wrapping_sup` takes care of the u64 integer overflow special case.
// `wrapping_sub` takes care of the u64 integer overflow special case.
let val = if instant.wrapping_sub(now) <= ($bits::MAX as u64) {
instant as $bits
} else {
Expand Down Expand Up @@ -317,8 +317,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(0) {
$timer.sr().modify(|r| r.set_ccif(0, false));
let prev = $overflow.fetch_add(1, Ordering::Relaxed);
assert!(prev % 2 == 0, "Monotonic must have missed an interrupt!");
}
Expand Down