Skip to content

Read xtal freq directly from PCR#1005

Merged
bugadani merged 1 commit intomainfrom
c5-xtal
Feb 11, 2026
Merged

Read xtal freq directly from PCR#1005
bugadani merged 1 commit intomainfrom
c5-xtal

Conversation

@bugadani
Copy link
Contributor

The previous algorithm estimated a very inaccurate 0 as the xtal freq.

Copilot AI review requested due to automatic review settings February 11, 2026 07:52
Copy link
Member

@SergioGasquez SergioGasquez left a comment

Choose a reason for hiding this comment

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

LGTM! Should we keep the 40Mhz branch?

Comment on lines +910 to +912
const PCR_SYSCLK_CONF_REG: u32 = 0x6009_6110; // PCR_BASE_REG + 0x110
const PCR_CLK_XTAL_FREQ_MASK: u32 = 0x7F;
const PCR_CLK_XTAL_FREQ_SHIFT: u32 = 24;
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I just read this out of the TRM, but sure we can say it comes from esptool :D

Comment on lines 918 to 922
let norm_xtal = if est_xtal > 45 {
XtalFrequency::_48Mhz
} else {
XtalFrequency::_40Mhz
};
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we still need this if we only support 48Mhz

Copy link

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

Improves ESP32-C5 crystal frequency detection by reading the XTAL frequency field directly from the PCR sysclock configuration register, avoiding the prior UART-divisor-based estimate that could yield incorrect results (e.g., 0).

Changes:

  • Update ESP32-C5 xtal_frequency() detection to read PCR_SYSCLK_CONF_REG and derive the XTAL frequency from its encoded field.
  • Minor formatting change to the flash_target re-exports.
  • Add an unreleased changelog entry for the ESP32-C5 crystal-frequency reporting fix.

Reviewed changes

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

File Description
espflash/src/target/mod.rs Reads XTAL frequency for ESP32-C5 from PCR sysclock config register instead of estimating via UART clock divider.
CHANGELOG.md Documents the fix under “Unreleased → Fixed”.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bugadani
Copy link
Contributor Author

I think we might want to keep the 40MHz branch just in case, I'm also not sure if there are preproduction chips floating around that should at least not be misreported.

@bugadani bugadani enabled auto-merge February 11, 2026 08:05
@bugadani bugadani disabled auto-merge February 11, 2026 08:18
@bugadani bugadani added this pull request to the merge queue Feb 11, 2026
Merged via the queue into main with commit 81bdf6a Feb 11, 2026
50 checks passed
@bugadani bugadani deleted the c5-xtal branch February 11, 2026 08:55
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.

2 participants