Skip to content

Minor TIMG tweaks#5256

Merged
bugadani merged 3 commits intoesp-rs:mainfrom
bugadani:timg
Mar 26, 2026
Merged

Minor TIMG tweaks#5256
bugadani merged 3 commits intoesp-rs:mainfrom
bugadani:timg

Conversation

@bugadani
Copy link
Copy Markdown
Contributor

Closes #1366 - everything is modelled, and maybe the default clock source could be changed from XTAL to PLL/APB where possible.

Besides converting the driver to use State/Info, to use PeripheralGuard, to allow actually configuring the clock sources, there isn't much to do. The active source clock frequency should be cached because a bunch of operations (like now!) take a critical section.

Copilot AI review requested due to automatic review settings March 25, 2026 13:21
@bugadani bugadani added the skip-changelog No changelog modification needed label Mar 25, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates TIMG clock/peripheral handling and metadata to better model timer-group clocking and remove unconditional “keep enabled” behavior for TIMG0 on several chips.

Changes:

  • Remove keep_enabled = true from Timg0 peripheral clock entries in multiple esp-metadata/devices/*.toml files.
  • Refactor esp-hal’s TIMG driver to use a Peripheral accessor per instance and inline clock-tree interactions for WDT clock configuration/gating.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
esp-metadata/devices/esp32s3.toml Drop keep_enabled from Timg0 peripheral clock entry.
esp-metadata/devices/esp32s2.toml Drop keep_enabled from Timg0 peripheral clock entry.
esp-metadata/devices/esp32h2.toml Drop keep_enabled from Timg0 peripheral clock entry.
esp-metadata/devices/esp32c61.toml Drop keep_enabled from Timg0 peripheral clock entry.
esp-metadata/devices/esp32c6.toml Drop keep_enabled from Timg0 peripheral clock entry.
esp-metadata/devices/esp32c5.toml Drop keep_enabled from Timg0 peripheral clock entry.
esp-metadata/devices/esp32c3.toml Drop keep_enabled from Timg0 peripheral clock entry.
esp-metadata/devices/esp32c2.toml Drop keep_enabled from Timg0 peripheral clock entry.
esp-hal/src/timer/timg.rs Update TIMG instance trait to expose Peripheral, adjust enable/reset logic, and rework WDT clock configuration/gating calls.
Comments suppressed due to low confidence (1)

esp-hal/src/timer/timg.rs:86

  • PeripheralGuard is imported but not used anywhere in this module. With cargo clippy -D warnings this will fail CI; either use PeripheralGuard (e.g., for the refcounted enable/reset path) or remove the import until it’s needed.
    system::PeripheralClockControl,
    time::{Duration, Instant, Rate},

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.

@JurajSadel JurajSadel added this pull request to the merge queue Mar 26, 2026
@bugadani bugadani removed this pull request from the merge queue due to a manual request Mar 26, 2026
@bugadani
Copy link
Copy Markdown
Contributor Author

Tests look broken

@bugadani bugadani marked this pull request as draft March 26, 2026 13:22
@bugadani bugadani force-pushed the timg branch 2 times, most recently from 4db887d to 694d28a Compare March 26, 2026 14:45
@bugadani
Copy link
Copy Markdown
Contributor Author

I'll have to come back to the idea of not keeping TIMG0 running. There is some funky behaviour going on on S2 and S3 around that...

@bugadani bugadani marked this pull request as ready for review March 26, 2026 15:26
Copilot AI review requested due to automatic review settings March 26, 2026 15:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings March 26, 2026 16:10
}

if !enable {
unsafe { Self::reset_racey(peripheral) };
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This goes because resetting TIMG0 enables its WDT, and that's just a source of frustration.

@bugadani
Copy link
Copy Markdown
Contributor Author

/hil full

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

esp-hal/src/system.rs:205

  • PeripheralClockControl::disable is documented as resetting the peripheral before disabling, but the reset-on-disable logic was removed from enable_forced_with_counts. Either update the doc comment to match the new behavior, or reintroduce a reset if callers rely on peripherals being reset when the refcount reaches 0.

        true
    }

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 26, 2026

Triggered full HIL run for #5256.

Run: https://github.com/esp-rs/esp-hal/actions/runs/23605168776

Status update: ❌ HIL (full) run failed (conclusion: failure).

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@bugadani bugadani enabled auto-merge March 26, 2026 17:54
@bugadani bugadani added this pull request to the merge queue Mar 26, 2026
Merged via the queue into esp-rs:main with commit 89b9d24 Mar 26, 2026
52 of 62 checks passed
@bugadani bugadani deleted the timg branch March 26, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog No changelog modification needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TIMG: Not all timer clock sources are set correctly

4 participants