-
Notifications
You must be signed in to change notification settings - Fork 220
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
Allow setting external 32khz quartz for slow rtc clock #2032
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
eb3af04
allow setting external 32khz quartz
Szybet 836ee48
Merge remote-tracking branch 'notfork/main' into 32khz-quartz and rem…
Szybet ef6d813
clean out the rest
Szybet b497622
clean out the rest even more
Szybet 3d5b8ff
another implementation of choosing the 32khz quartz
Szybet 55c2d08
rename variable
Szybet eb79d6a
Update examples/src/bin/32khz_xtal.rs
Szybet e1abea4
fallback to default rtc clock
Szybet 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//! This turns on the 32 khz xtal and then just prints hello world to UART. Requires a special bootloader | ||
//! | ||
//! You can see the output with `espflash` if you provide the `--monitor` | ||
//! option. | ||
|
||
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 | ||
|
||
#![no_std] | ||
#![no_main] | ||
|
||
use core::fmt::Write; | ||
|
||
use esp_backtrace as _; | ||
use esp_hal::{delay::Delay, gpio::Io, prelude::*, uart::Uart, RtcSlowClock}; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
let mut conf = esp_hal::Config::default(); | ||
conf.rtc_slow_clock = RtcSlowClock::RtcSlowClock32kXtal; | ||
let (peripherals, clocks) = esp_hal::init(conf); | ||
|
||
let delay = Delay::new(&clocks); | ||
|
||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); | ||
|
||
// Default pins for Uart/Serial communication | ||
cfg_if::cfg_if! { | ||
if #[cfg(feature = "esp32")] { | ||
let (mut tx_pin, mut rx_pin) = (io.pins.gpio1, io.pins.gpio3); | ||
} else if #[cfg(feature = "esp32c2")] { | ||
let (mut tx_pin, mut rx_pin) = (io.pins.gpio20, io.pins.gpio19); | ||
} else if #[cfg(feature = "esp32c3")] { | ||
let (mut tx_pin, mut rx_pin) = (io.pins.gpio21, io.pins.gpio20); | ||
} else if #[cfg(feature = "esp32c6")] { | ||
let (mut tx_pin, mut rx_pin) = (io.pins.gpio16, io.pins.gpio17); | ||
} else if #[cfg(feature = "esp32h2")] { | ||
let (mut tx_pin, mut rx_pin) = (io.pins.gpio24, io.pins.gpio23); | ||
} else if #[cfg(any(feature = "esp32s2", feature = "esp32s3"))] { | ||
let (mut tx_pin, mut rx_pin) = (io.pins.gpio43, io.pins.gpio44); | ||
} | ||
} | ||
|
||
let mut uart0 = | ||
Uart::new_with_default_pins(peripherals.UART0, &clocks, &mut tx_pin, &mut rx_pin).unwrap(); | ||
|
||
loop { | ||
writeln!(uart0, "Hello world!").unwrap(); | ||
delay.delay(1.secs()); | ||
} | ||
} |
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.
I don't see the value in this test. For one, what's "a special bootloader" that is required for it? Next, what does this example show, that changing the clock source doesn't break the whole system?
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.
The bootloader needs to be build with
CONFIG_RTC_CLK_SRC_EXT_CRYS=y
Well yes, also allows to measure the sine wave with an osciloscope
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.
Can we select the clock source here, instead of relying on the bootloader?
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.
Not without losing some optimization https://github.com/espressif/esp-idf/blob/59e18382702b6986be3d3f55e9ac7763c1397cf7/components/bootloader_support/src/bootloader_clock_init.c#L82-L90
And maybe something more is behind it, I don't know
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.
if (!rtc_clk_32k_enabled()) {
Unless that takes long to decide, this is safe to do. If the bootloader enabled the clock source, and the user selects in in esp-hap, we can skip initialization. Otherwise, in the future we might allow other bootloaders which may or may not set up the clock source, so I'd say let's enable the clock ourselves, if it's not done already.
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.
Please note it's inside the macro statement
#if CONFIG_ESP_SYSTEM_RTC_EXT_XTAL
Well maybe it is safe but we lose some optimization, I don't think we should lose any performance because at default we don't control the bootloader fully. In the future we probably will by using a rust based bootloader so it will work the same just like now, but without the hassle of recompiling it
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.
Let's prefer the option that works by default. If the user has problems with the startup time, they can use a custom bootloader.
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.
Making it work only in the application would require changing the code for it to wait to start up, not only is it not efficient but also I don't know how to do it, I looked at a lot of esp-idf code and haven't really found anything that waits for it, I ques booting the bootloader is enough time for it to start after all. Using a fixed time is also bad, would require cpu dependent testing to optimize it.
This is simply not the way to do it...
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.
Fine. At least please print a warning or panic if the bootloader forgot to enable the clock source.
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.
Ok, I will try to find a way to detect it (probably just failing the calibration step)