Skip to content

Commit e211476

Browse files
committed
Remove ESP_HAL_CONFIG_XTAL_FREQUENCY
1 parent 1bd319b commit e211476

File tree

3 files changed

+17
-72
lines changed

3 files changed

+17
-72
lines changed

esp-hal/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3434

3535
### Removed
3636

37+
- The `ESP_HAL_CONFIG_XTAL_FREQUENCY` configuration option has been removed (#4517)
3738

3839
## [v1.0.0] - 2025-10-30
3940

esp-hal/esp_config.yml

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,6 @@ options:
2727
default:
2828
- value: false
2929

30-
# Ideally, we should be able to set any clock frequency for any chip. However,
31-
# currently only the 32 and C2 implements any sort of configurability, and
32-
# the rest have a fixed clock frequency.
33-
- name: xtal-frequency
34-
description: "The frequency of the crystal oscillator, in MHz. Set to `auto` to
35-
automatically detect the frequency. `auto` may not be able to identify the clock
36-
frequency in some cases. Also, configuring a specific frequency may increase
37-
performance slightly."
38-
default:
39-
- if: 'chip == "esp32" || chip == "esp32c2"'
40-
value: '"auto"'
41-
- if: 'chip == "esp32c3" || chip == "esp32c6" || chip == "esp32s2" || chip == "esp32s3"'
42-
value: '"40"'
43-
- if: 'chip == "esp32h2"'
44-
value: '"32"'
45-
constraints:
46-
- if: 'chip == "esp32" || chip == "esp32c2"'
47-
type:
48-
validator: enumeration
49-
value:
50-
- 'auto'
51-
- '26'
52-
- '40'
53-
- if: 'chip == "esp32c3" || chip == "esp32c6" || chip == "esp32s2" || chip == "esp32s3"'
54-
type:
55-
validator: enumeration
56-
value:
57-
- '40'
58-
- if: 'chip == "esp32h2"'
59-
type:
60-
validator: enumeration
61-
value:
62-
- '32'
63-
active: 'chip == "esp32" || chip == "esp32c2"'
64-
6530
- name: spi-address-workaround
6631
description: "Enables a workaround for the issue where SPI in
6732
half-duplex mode incorrectly transmits the address on a single line if the

esp-hal/src/clock/mod.rs

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,51 +1116,30 @@ impl Clocks {
11161116
#[cfg(systimer)]
11171117
#[inline]
11181118
pub(crate) fn xtal_freq() -> Rate {
1119-
if esp_config::esp_config_str!("ESP_HAL_CONFIG_XTAL_FREQUENCY") == "auto"
1120-
&& let Some(clocks) = Self::try_get()
1121-
{
1119+
if let Some(clocks) = Self::try_get() {
11221120
return clocks.xtal_clock;
11231121
}
11241122

11251123
Self::measure_xtal_frequency().frequency()
11261124
}
11271125

1128-
#[cfg(not(esp32))] // unused
1129-
const fn xtal_frequency_from_config() -> Option<XtalClock> {
1130-
let frequency_conf = esp_config::esp_config_str!("ESP_HAL_CONFIG_XTAL_FREQUENCY");
1131-
1132-
for_each_soc_xtal_options!(
1133-
(all $( ($freq:literal) ),*) => {
1134-
paste::paste! {
1135-
return match frequency_conf.as_bytes() {
1136-
b"auto" => None,
1126+
#[cfg(not(esp32))]
1127+
fn measure_xtal_frequency() -> XtalClock {
1128+
cfg_if::cfg_if! {
1129+
if #[cfg(esp32h2)] {
1130+
XtalClock::_32M
1131+
} else if #[cfg(not(esp32c2))] {
1132+
XtalClock::_40M
1133+
} else {
1134+
// TODO: we should be able to read from a retention register, but probe-rs flashes a
1135+
// bootloader that assumes a frequency, instead of choosing a matching one.
1136+
let mhz = RtcClock::estimate_xtal_frequency();
11371137

1138-
// If the frequency is a pre-set value for the chip, return the associated enum variant.
1139-
$( _ if esp_config::esp_config_int_parse!(u32, frequency_conf) == $freq => Some(XtalClock::[<_ $freq M>]), )*
1138+
debug!("Working with a {}MHz crystal", mhz);
11401139

1141-
_ => None,
1142-
};
1143-
}
1144-
};
1145-
);
1146-
}
1147-
1148-
#[cfg(not(esp32))] // unused - the build-time config can be removed in favour of explicit configuration via esp_hal::init
1149-
fn measure_xtal_frequency() -> XtalClock {
1150-
if let Some(clock) = const { Self::xtal_frequency_from_config() } {
1151-
// Use the configured frequency
1152-
clock
1153-
} else if esp_config::esp_config_str!("ESP_HAL_CONFIG_XTAL_FREQUENCY") == "auto" {
1154-
// TODO: we should be able to read from a retention register, but probe-rs flashes a
1155-
// bootloader that assumes a frequency, instead of choosing a matching one.
1156-
let mhz = RtcClock::estimate_xtal_frequency();
1157-
1158-
debug!("Working with a {}MHz crystal", mhz);
1159-
1160-
// Try to guess the closest possible crystal value.
1161-
XtalClock::closest_from_mhz(mhz)
1162-
} else {
1163-
unreachable!("Invalid crystal frequency configured, this should not be possible.")
1140+
// Try to guess the closest possible crystal value.
1141+
XtalClock::closest_from_mhz(mhz)
1142+
}
11641143
}
11651144
}
11661145
}

0 commit comments

Comments
 (0)