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

Add xtal frequency configuration #3054

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

bugadani
Copy link
Contributor

@bugadani bugadani commented Jan 29, 2025

This PR adds ESP_HAL_CONFIG_XTAL_FREQUENCY - although only 32 and C2 have meaningful configurability. THe point of this PR is to allow const-propagating xtal_freq wherever possible, mostly affecting esp_hal::time::now() and indirectly embassy-time.

We could probably double-check in Clocks::init that the configured frequency matches what we measure, I don't know how badly we would want that, though.


Running a modified embassy_executor_benchmark on the S2 (no time queue tasks, Task1 reading current time in every loop):

Test case main PR
no-op count=483798, cycles=24803/100 count=483791, cycles=24804/100
now() count=357079, cycles=33606/100 count=373770, cycles=32105/100
black_box(now()) count=279690, cycles=42904/100 count=330518, cycles=36306/100
  • count: iterations in 500ms, higher is better
  • cycles: CPU clock cycles per iteration (x100), lower is better

@bugadani bugadani changed the title Try to avoid pointer read in time conversion Add xtal frequency configuration Jan 31, 2025
@bugadani bugadani marked this pull request as ready for review January 31, 2025 14:24
(
"xtal-frequency",
"The frequency of the crystal oscillator, in MHz. Set to `auto` to automatically detect the frequency. `auto` may not be able to identify the clock frequency in some cases. Also, configuring a specific frequency may increase performance slightly.",
Value::String(match device_name {
Copy link
Member

@MabezDev MabezDev Jan 31, 2025

Choose a reason for hiding this comment

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

Are we going to run into issues if someone wants to set this config but also support multiple different chips in the same project?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We won't, but they will

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess #3020 will support this scenario better

esp-hal/src/clock/mod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@bjoernQ bjoernQ left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants