mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-10-02 06:40:47 +00:00
Support ESP32-C2 with 26MHz Xtal
This commit is contained in:
parent
cfe83827cf
commit
dc8963c0a8
@ -63,6 +63,9 @@ esp32c3 = ["esp32c3/rt", "riscv"]
|
||||
esp32s2 = ["esp32s2/rt", "xtensa", "xtensa-lx/esp32s2", "xtensa-lx-rt/esp32s2", "esp-synopsys-usb-otg", "usb-device"]
|
||||
esp32s3 = ["esp32s3/rt", "xtensa", "xtensa-lx/esp32s3", "xtensa-lx-rt/esp32s3", "lock_api", "esp-synopsys-usb-otg", "usb-device"]
|
||||
|
||||
esp32c2_40mhz = []
|
||||
esp32c2_26mhz = []
|
||||
|
||||
# Implement the `embedded-hal==1.0.0-alpha.x` traits
|
||||
eh1 = ["embedded-hal-1", "embedded-hal-nb"]
|
||||
|
||||
|
@ -12,6 +12,13 @@ fn main() {
|
||||
n => panic!("Exactly 1 chip must be enabled via its Cargo feature, {n} provided"),
|
||||
}
|
||||
|
||||
if cfg!(feature = "esp32c2")
|
||||
&& cfg!(feature = "esp32c2_40mhz")
|
||||
&& cfg!(feature = "esp32c2_26mhz")
|
||||
{
|
||||
panic!("Only one xtal speed feature can be selected");
|
||||
}
|
||||
|
||||
// Define all required configuration symbols for the enabled chip.
|
||||
//
|
||||
// When adding a new device, at the bare minimum the following symbols MUST be
|
||||
|
@ -227,7 +227,8 @@ impl ClockControl {
|
||||
/// Use what is considered the default settings after boot.
|
||||
#[allow(unused)]
|
||||
pub fn boot_defaults(clock_control: SystemClockControl) -> ClockControl {
|
||||
ClockControl {
|
||||
#[cfg(feature = "esp32c2_40mhz")]
|
||||
return ClockControl {
|
||||
_private: (),
|
||||
desired_rates: RawClocks {
|
||||
cpu_clock: HertzU32::MHz(80),
|
||||
@ -235,14 +236,28 @@ impl ClockControl {
|
||||
xtal_clock: HertzU32::MHz(40),
|
||||
i2c_clock: HertzU32::MHz(40),
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
#[cfg(feature = "esp32c2_26mhz")]
|
||||
return ClockControl {
|
||||
_private: (),
|
||||
desired_rates: RawClocks {
|
||||
cpu_clock: HertzU32::MHz(80),
|
||||
apb_clock: HertzU32::MHz(40),
|
||||
xtal_clock: HertzU32::MHz(26),
|
||||
i2c_clock: HertzU32::MHz(26),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/// Configure the CPU clock speed.
|
||||
#[allow(unused)]
|
||||
pub fn configure(clock_control: SystemClockControl, cpu_clock_speed: CpuClock) -> ClockControl {
|
||||
let apb_freq;
|
||||
#[cfg(feature = "esp32c2_40mhz")]
|
||||
let xtal_freq = XtalClock::RtcXtalFreq40M;
|
||||
#[cfg(feature = "esp32c2_26mhz")]
|
||||
let xtal_freq = XtalClock::RtcXtalFreq26M;
|
||||
let pll_freq = PllClock::Pll480MHz;
|
||||
|
||||
if cpu_clock_speed.mhz() <= xtal_freq.mhz() {
|
||||
|
@ -59,10 +59,16 @@ pub(crate) fn init() {
|
||||
}
|
||||
|
||||
pub(crate) fn configure_clock() {
|
||||
#[cfg(feature = "esp32c2_40mhz")]
|
||||
assert!(matches!(
|
||||
RtcClock::get_xtal_freq(),
|
||||
XtalClock::RtcXtalFreq40M
|
||||
));
|
||||
#[cfg(feature = "esp32c2_26mhz")]
|
||||
assert!(
|
||||
matches!(RtcClock::get_xtal_freq(), XtalClock::RtcXtalFreq26M),
|
||||
"Did you flash the right bootloader configured for 26MHz xtal?"
|
||||
);
|
||||
|
||||
RtcClock::set_fast_freq(RtcFastClock::RtcFastClock8m);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
[target.xtensa-esp32-none-elf]
|
||||
runner = "espflash --monitor"
|
||||
runner = "espflash flash --monitor"
|
||||
|
||||
[build]
|
||||
rustflags = [
|
||||
|
@ -1,12 +1,12 @@
|
||||
[target.riscv32imc-unknown-none-elf]
|
||||
runner = "espflash --monitor"
|
||||
runner = "espflash flash --monitor"
|
||||
rustflags = [
|
||||
"-C", "link-arg=-Tlinkall.x"
|
||||
]
|
||||
|
||||
# for testing: you can specify this target to see atomic emulation in action
|
||||
[target.riscv32imac-unknown-none-elf]
|
||||
runner = "espflash --monitor"
|
||||
runner = "espflash flash --monitor"
|
||||
rustflags = [
|
||||
"-C", "link-arg=-Tlinkall.x"
|
||||
]
|
||||
|
@ -46,7 +46,7 @@ ssd1306 = "0.7.1"
|
||||
static_cell = "1.0.0"
|
||||
|
||||
[features]
|
||||
default = ["rt", "vectored"]
|
||||
default = ["rt", "vectored", "xtal40mhz"]
|
||||
direct-boot = []
|
||||
eh1 = ["esp-hal-common/eh1", "dep:embedded-hal-1", "dep:embedded-hal-nb"]
|
||||
rt = ["riscv-rt"]
|
||||
@ -55,7 +55,9 @@ vectored = ["esp-hal-common/vectored"]
|
||||
async = ["esp-hal-common/async", "embedded-hal-async"]
|
||||
embassy = ["esp-hal-common/embassy"]
|
||||
embassy-time-systick = ["esp-hal-common/embassy-time-systick", "embassy-time/tick-hz-16_000_000"]
|
||||
embassy-time-timg0 = ["esp-hal-common/embassy-time-timg0", "embassy-time/tick-hz-1_000_000"]
|
||||
embassy-time-timg0 = ["esp-hal-common/embassy-time-timg0", "embassy-time/tick-hz-1_000_000"]
|
||||
xtal40mhz = ["esp-hal-common/esp32c2_40mhz"]
|
||||
xtal26mhz = ["esp-hal-common/esp32c2_26mhz"]
|
||||
|
||||
[[example]]
|
||||
name = "spi_eh1_loopback"
|
||||
|
@ -2,6 +2,8 @@ use std::{env, fs::File, io::Write, path::PathBuf};
|
||||
|
||||
#[cfg(feature = "direct-boot")]
|
||||
fn main() {
|
||||
check_features();
|
||||
|
||||
// Put the linker script somewhere the linker can find it
|
||||
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
||||
|
||||
@ -36,6 +38,8 @@ fn main() {
|
||||
|
||||
#[cfg(not(feature = "direct-boot"))]
|
||||
fn main() {
|
||||
check_features();
|
||||
|
||||
// Put the linker script somewhere the linker can find it
|
||||
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
||||
File::create(out.join("memory.x"))
|
||||
@ -62,6 +66,12 @@ fn main() {
|
||||
add_defaults();
|
||||
}
|
||||
|
||||
fn check_features() {
|
||||
if cfg!(feature = "xtal40mhz") && cfg!(feature = "xtal26mhz") {
|
||||
panic!("Only one xtal speed feature can be selected");
|
||||
}
|
||||
}
|
||||
|
||||
fn add_defaults() {
|
||||
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
||||
File::create(out.join("hal-defaults.x"))
|
||||
|
@ -1,12 +1,12 @@
|
||||
[target.riscv32imc-unknown-none-elf]
|
||||
runner = "espflash --monitor"
|
||||
runner = "espflash flash --monitor"
|
||||
rustflags = [
|
||||
"-C", "link-arg=-Tlinkall.x"
|
||||
]
|
||||
|
||||
# for testing: you can specify this target to see atomic emulation in action
|
||||
[target.riscv32imac-unknown-none-elf]
|
||||
runner = "espflash --monitor"
|
||||
runner = "espflash flash --monitor"
|
||||
rustflags = [
|
||||
"-C", "link-arg=-Tlinkall.x"
|
||||
]
|
||||
|
@ -1,5 +1,5 @@
|
||||
[target.xtensa-esp32s2-none-elf]
|
||||
runner = "espflash --monitor"
|
||||
runner = "espflash flash --monitor"
|
||||
|
||||
[build]
|
||||
rustflags = [
|
||||
|
@ -1,5 +1,5 @@
|
||||
[target.xtensa-esp32s3-none-elf]
|
||||
runner = "espflash --monitor"
|
||||
runner = "espflash flash --monitor"
|
||||
|
||||
[build]
|
||||
rustflags = [
|
||||
|
Loading…
x
Reference in New Issue
Block a user