-
Notifications
You must be signed in to change notification settings - Fork 368
Udpate H2 and C6 clocks. Remove i2c_clock for all chips but ESP32 #592
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fd7755d
feat: ✨ Udpate H2 and C6 clocks. Remove i2c_clock for all chips but E…
SergioGasquez d6cb544
fix: 🐛 Fix cfg for i2c0
SergioGasquez 2a91e8d
docs: 📝 Update changelog
SergioGasquez bd52834
build: 📌 Pin pacs rev for c6
SergioGasquez 806d718
docs: 🎨 Fix changelog format
SergioGasquez d5ef5e4
feat: ✨ Add missing PLL clocks
SergioGasquez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,13 +160,6 @@ pub(crate) fn esp32h2_rtc_bbpll_enable() { | |
|
|
||
| pmu.imm_hp_ck_power | ||
| .modify(|_, w| w.tie_high_global_bbpll_icg().set_bit()); | ||
|
|
||
| let pcr = unsafe { &*crate::peripherals::PCR::PTR }; | ||
|
|
||
| // switch spimem to PLL 64Mhz clock | ||
| unsafe { | ||
| pcr.mspi_conf.modify(|_, w| w.mspi_clk_sel().bits(0b10)); | ||
| } | ||
| } | ||
|
|
||
| pub(crate) fn esp32h2_rtc_update_to_xtal(freq: XtalClock, _div: u8) { | ||
|
|
@@ -175,8 +168,7 @@ pub(crate) fn esp32h2_rtc_update_to_xtal(freq: XtalClock, _div: u8) { | |
| ets_update_cpu_frequency(freq.mhz()); | ||
| // Set divider from XTAL to APB clock. Need to set divider to 1 (reg. value 0) | ||
| // first. | ||
| pcr.ahb_freq_conf | ||
| .modify(|_, w| w.ahb_div_num().bits(_div - 1)); | ||
|
Comment on lines
-178
to
-179
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We were duplicating the |
||
| clk_ll_ahb_set_divider(_div as u32); | ||
|
|
||
| pcr.cpu_freq_conf | ||
| .modify(|_, w| w.cpu_div_num().bits(_div - 1)); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,29 +30,31 @@ pub trait Clock { | |
| /// CPU clock speed | ||
| #[derive(Debug, Clone, Copy)] | ||
| pub enum CpuClock { | ||
| #[cfg(not(esp32h2))] | ||
| Clock80MHz, | ||
| #[cfg(esp32h2)] | ||
| Clock96MHz, | ||
| #[cfg(esp32c2)] | ||
| Clock120MHz, | ||
| #[cfg(not(esp32c2))] | ||
| #[cfg(not(any(esp32c2, esp32h2)))] | ||
| Clock160MHz, | ||
| #[cfg(not(any(esp32c2, esp32c3, esp32c6)))] | ||
| #[cfg(not(any(esp32c2, esp32c3, esp32c6, esp32h2)))] | ||
| Clock240MHz, | ||
| } | ||
|
|
||
| #[allow(dead_code)] | ||
| impl Clock for CpuClock { | ||
| fn frequency(&self) -> HertzU32 { | ||
| match self { | ||
| #[cfg(not(esp32h2))] | ||
| CpuClock::Clock80MHz => HertzU32::MHz(80), | ||
| #[cfg(esp32h2)] | ||
| CpuClock::Clock96MHz => HertzU32::MHz(96), | ||
| #[cfg(esp32c2)] | ||
| CpuClock::Clock120MHz => HertzU32::MHz(120), | ||
| #[cfg(not(esp32c2))] | ||
| #[cfg(not(any(esp32c2, esp32h2)))] | ||
| CpuClock::Clock160MHz => HertzU32::MHz(160), | ||
| #[cfg(not(any(esp32c2, esp32c3, esp32c6)))] | ||
| #[cfg(not(any(esp32c2, esp32c3, esp32c6, esp32h2)))] | ||
| CpuClock::Clock240MHz => HertzU32::MHz(240), | ||
| } | ||
| } | ||
|
|
@@ -65,8 +67,9 @@ pub(crate) enum XtalClock { | |
| RtcXtalFreq24M, | ||
| #[cfg(any(esp32, esp32c2))] | ||
| RtcXtalFreq26M, | ||
| #[cfg(any(esp32c3, esp32s3, esp32h2))] | ||
| #[cfg(any(esp32c3, esp32h2, esp32s3))] | ||
| RtcXtalFreq32M, | ||
| #[cfg(not(esp32h2))] | ||
| RtcXtalFreq40M, | ||
| RtcXtalFreqOther(u32), | ||
| } | ||
|
|
@@ -78,8 +81,9 @@ impl Clock for XtalClock { | |
| XtalClock::RtcXtalFreq24M => HertzU32::MHz(24), | ||
| #[cfg(any(esp32, esp32c2))] | ||
| XtalClock::RtcXtalFreq26M => HertzU32::MHz(26), | ||
| #[cfg(any(esp32c3, esp32s3, esp32h2))] | ||
| #[cfg(any(esp32c3, esp32h2, esp32s3))] | ||
| XtalClock::RtcXtalFreq32M => HertzU32::MHz(32), | ||
| #[cfg(not(esp32h2))] | ||
| XtalClock::RtcXtalFreq40M => HertzU32::MHz(40), | ||
| XtalClock::RtcXtalFreqOther(mhz) => HertzU32::MHz(*mhz), | ||
| } | ||
|
|
@@ -89,23 +93,48 @@ impl Clock for XtalClock { | |
| #[allow(unused)] | ||
| #[derive(Debug, Clone, Copy)] | ||
| pub(crate) enum PllClock { | ||
| #[cfg(not(any(esp32c2, esp32c6)))] | ||
| #[cfg(esp32h2)] | ||
| Pll8MHz, | ||
| #[cfg(any(esp32c6, esp32h2))] | ||
| Pll48MHz, | ||
| #[cfg(esp32h2)] | ||
| Pll64MHz, | ||
| #[cfg(esp32c6)] | ||
| Pll80MHz, | ||
| #[cfg(esp32h2)] | ||
| Pll96MHz, | ||
| #[cfg(esp32c6)] | ||
| Pll120MHz, | ||
| #[cfg(esp32c6)] | ||
| Pll160MHz, | ||
| #[cfg(esp32c6)] | ||
| Pll240MHz, | ||
| #[cfg(not(any(esp32c2, esp32c6, esp32h2)))] | ||
| Pll320MHz, | ||
| #[cfg(not(esp32h2))] | ||
| Pll480MHz, | ||
| } | ||
|
|
||
| #[allow(unused)] | ||
| #[derive(Debug, Clone, Copy)] | ||
| pub(crate) enum ApbClock { | ||
| #[cfg(esp32h2)] | ||
| ApbFreq32MHz, | ||
| #[cfg(not(esp32h2))] | ||
| ApbFreq40MHz, | ||
| #[cfg(not(esp32h2))] | ||
| ApbFreq80MHz, | ||
| ApbFreqOther(u32), | ||
| } | ||
|
|
||
| impl Clock for ApbClock { | ||
| fn frequency(&self) -> HertzU32 { | ||
| match self { | ||
| #[cfg(esp32h2)] | ||
| ApbClock::ApbFreq32MHz => HertzU32::MHz(32), | ||
| #[cfg(not(esp32h2))] | ||
| ApbClock::ApbFreq40MHz => HertzU32::MHz(40), | ||
| #[cfg(not(esp32h2))] | ||
| ApbClock::ApbFreq80MHz => HertzU32::MHz(80), | ||
| ApbClock::ApbFreqOther(mhz) => HertzU32::MHz(*mhz), | ||
| } | ||
|
|
@@ -121,12 +150,13 @@ pub struct Clocks<'d> { | |
| pub cpu_clock: HertzU32, | ||
| pub apb_clock: HertzU32, | ||
| pub xtal_clock: HertzU32, | ||
| #[cfg(esp32)] | ||
| pub i2c_clock: HertzU32, | ||
| #[cfg(esp32)] | ||
| pub pwm_clock: HertzU32, | ||
| #[cfg(esp32s3)] | ||
| pub crypto_pwm_clock: HertzU32, | ||
| #[cfg(esp32c6)] | ||
| #[cfg(any(esp32c6, esp32h2))] | ||
| pub crypto_clock: HertzU32, | ||
| #[cfg(esp32h2)] | ||
| pub pll_48m_clock: HertzU32, | ||
|
|
@@ -148,12 +178,13 @@ impl<'d> Clocks<'d> { | |
| cpu_clock: raw_clocks.cpu_clock, | ||
| apb_clock: raw_clocks.apb_clock, | ||
| xtal_clock: raw_clocks.xtal_clock, | ||
| #[cfg(esp32)] | ||
| i2c_clock: raw_clocks.i2c_clock, | ||
| #[cfg(esp32)] | ||
| pwm_clock: raw_clocks.pwm_clock, | ||
| #[cfg(esp32s3)] | ||
| crypto_pwm_clock: raw_clocks.crypto_pwm_clock, | ||
| #[cfg(esp32c6)] | ||
| #[cfg(any(esp32c6, esp32h2))] | ||
| crypto_clock: raw_clocks.crypto_clock, | ||
| #[cfg(esp32h2)] | ||
| pll_48m_clock: raw_clocks.pll_48m_clock, | ||
|
|
@@ -166,12 +197,13 @@ pub struct RawClocks { | |
| pub cpu_clock: HertzU32, | ||
| pub apb_clock: HertzU32, | ||
| pub xtal_clock: HertzU32, | ||
| #[cfg(esp32)] | ||
| pub i2c_clock: HertzU32, | ||
| #[cfg(esp32)] | ||
| pub pwm_clock: HertzU32, | ||
| #[cfg(esp32s3)] | ||
| pub crypto_pwm_clock: HertzU32, | ||
| #[cfg(esp32c6)] | ||
| #[cfg(any(esp32c6, esp32h2))] | ||
| pub crypto_clock: HertzU32, | ||
| #[cfg(esp32h2)] | ||
| pub pll_48m_clock: HertzU32, | ||
|
|
@@ -281,7 +313,6 @@ impl<'d> ClockControl<'d> { | |
| cpu_clock: HertzU32::MHz(80), | ||
| apb_clock: HertzU32::MHz(40), | ||
| xtal_clock: HertzU32::MHz(40), | ||
| i2c_clock: HertzU32::MHz(40), | ||
| }, | ||
| }; | ||
|
|
||
|
|
@@ -292,7 +323,6 @@ impl<'d> ClockControl<'d> { | |
| cpu_clock: HertzU32::MHz(80), | ||
| apb_clock: HertzU32::MHz(40), | ||
| xtal_clock: HertzU32::MHz(26), | ||
| i2c_clock: HertzU32::MHz(26), | ||
| }, | ||
| }; | ||
| } | ||
|
|
@@ -328,7 +358,6 @@ impl<'d> ClockControl<'d> { | |
| cpu_clock: cpu_clock_speed.frequency(), | ||
| apb_clock: apb_freq.frequency(), | ||
| xtal_clock: xtal_freq.frequency(), | ||
| i2c_clock: HertzU32::MHz(40), | ||
| }, | ||
| } | ||
| } | ||
|
|
@@ -347,7 +376,6 @@ impl<'d> ClockControl<'d> { | |
| cpu_clock: HertzU32::MHz(80), | ||
| apb_clock: HertzU32::MHz(80), | ||
| xtal_clock: HertzU32::MHz(40), | ||
| i2c_clock: HertzU32::MHz(40), | ||
| }, | ||
| } | ||
| } | ||
|
|
@@ -380,7 +408,6 @@ impl<'d> ClockControl<'d> { | |
| cpu_clock: cpu_clock_speed.frequency(), | ||
| apb_clock: apb_freq.frequency(), | ||
| xtal_clock: xtal_freq.frequency(), | ||
| i2c_clock: HertzU32::MHz(40), | ||
| }, | ||
| } | ||
| } | ||
|
|
@@ -399,7 +426,6 @@ impl<'d> ClockControl<'d> { | |
| cpu_clock: HertzU32::MHz(80), | ||
| apb_clock: HertzU32::MHz(80), | ||
| xtal_clock: HertzU32::MHz(40), | ||
| i2c_clock: HertzU32::MHz(40), | ||
| crypto_clock: HertzU32::MHz(160), | ||
| }, | ||
| } | ||
|
|
@@ -433,7 +459,6 @@ impl<'d> ClockControl<'d> { | |
| cpu_clock: cpu_clock_speed.frequency(), | ||
| apb_clock: apb_freq.frequency(), | ||
| xtal_clock: xtal_freq.frequency(), | ||
| i2c_clock: HertzU32::MHz(40), | ||
| crypto_clock: HertzU32::MHz(160), | ||
| }, | ||
| } | ||
|
|
@@ -453,8 +478,8 @@ impl<'d> ClockControl<'d> { | |
| cpu_clock: HertzU32::MHz(96), | ||
| apb_clock: HertzU32::MHz(32), | ||
| xtal_clock: HertzU32::MHz(32), | ||
| i2c_clock: HertzU32::MHz(32), | ||
| pll_48m_clock: HertzU32::MHz(48), | ||
| crypto_clock: HertzU32::MHz(96), | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See |
||
| }, | ||
| } | ||
| } | ||
|
|
@@ -466,15 +491,15 @@ impl<'d> ClockControl<'d> { | |
| cpu_clock_speed: CpuClock, | ||
| ) -> ClockControl<'d> { | ||
| let apb_freq; | ||
| let xtal_freq = XtalClock::RtcXtalFreqOther(32); | ||
| let pll_freq = PllClock::Pll320MHz; | ||
| let xtal_freq = XtalClock::RtcXtalFreq32M; | ||
| let pll_freq = PllClock::Pll96MHz; | ||
|
|
||
| if cpu_clock_speed.mhz() <= xtal_freq.mhz() { | ||
| apb_freq = ApbClock::ApbFreqOther(cpu_clock_speed.mhz()); | ||
| clocks_ll::esp32h2_rtc_update_to_xtal(xtal_freq, 1); | ||
| clocks_ll::esp32h2_rtc_apb_freq_update(apb_freq); | ||
| } else { | ||
| apb_freq = ApbClock::ApbFreqOther(32); | ||
| apb_freq = ApbClock::ApbFreq32MHz; | ||
| clocks_ll::esp32h2_rtc_bbpll_enable(); | ||
| clocks_ll::esp32h2_rtc_bbpll_configure(xtal_freq, pll_freq); | ||
| clocks_ll::esp32h2_rtc_freq_to_pll_mhz(cpu_clock_speed); | ||
|
|
@@ -487,8 +512,8 @@ impl<'d> ClockControl<'d> { | |
| cpu_clock: cpu_clock_speed.frequency(), | ||
| apb_clock: apb_freq.frequency(), | ||
| xtal_clock: xtal_freq.frequency(), | ||
| i2c_clock: HertzU32::MHz(32), | ||
| pll_48m_clock: HertzU32::MHz(48), | ||
| crypto_clock: HertzU32::MHz(96), | ||
| }, | ||
| } | ||
| } | ||
|
|
@@ -507,7 +532,6 @@ impl<'d> ClockControl<'d> { | |
| cpu_clock: HertzU32::MHz(80), | ||
| apb_clock: HertzU32::MHz(80), | ||
| xtal_clock: HertzU32::MHz(40), | ||
| i2c_clock: HertzU32::MHz(80), | ||
| }, | ||
| } | ||
| } | ||
|
|
@@ -526,7 +550,6 @@ impl<'d> ClockControl<'d> { | |
| cpu_clock: cpu_clock_speed.frequency(), | ||
| apb_clock: HertzU32::MHz(80), | ||
| xtal_clock: HertzU32::MHz(40), | ||
| i2c_clock: HertzU32::MHz(40), | ||
| }, | ||
| } | ||
| } | ||
|
|
@@ -545,7 +568,6 @@ impl<'d> ClockControl<'d> { | |
| cpu_clock: HertzU32::MHz(80), | ||
| apb_clock: HertzU32::MHz(80), | ||
| xtal_clock: HertzU32::MHz(40), | ||
| i2c_clock: HertzU32::MHz(40), | ||
| crypto_pwm_clock: HertzU32::MHz(160), | ||
| }, | ||
| } | ||
|
|
@@ -565,7 +587,6 @@ impl<'d> ClockControl<'d> { | |
| cpu_clock: cpu_clock_speed.frequency(), | ||
| apb_clock: HertzU32::MHz(80), | ||
| xtal_clock: HertzU32::MHz(40), | ||
| i2c_clock: HertzU32::MHz(40), | ||
| crypto_pwm_clock: HertzU32::MHz(160), | ||
| }, | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this as @playfulFence and I couldn't find the source of this.
H2 and C6 are the same in esp-idf: