-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
esp: make cpu frequency settable #9342
Conversation
Removing the error message and instead just jumping to the nearest frequency is also possible to save space. |
Option 1 sounds good to me.
What we do for peripherals like SPI is we do the fastest available speed that is at the given frequency or less. This way you don't end up faster than you intended. You read the value back to know what it was set to. I'd rather not have custom errors because that increases translation burden. |
I like the idea of automatically "rounding down" to the next lower supported frequency. As far as I can tell, overclocking is not supported by Regarding the size of the build: Instead of disabling the feature on C3 builds, would it be acceptable to modify the partition sizes to make the changes fit? |
Touching the partition tables will wipe every existing c3's filesystem on upgrade. |
As @bill88t points out, that's a breaking change. Instead, turn it off when |
Makes sense, I didn't realize that changing the partition table would be a breaking change. Does
Or did I misunderstand your suggestion @tannewt? |
@Sola85 It exists already. https://github.com/adafruit/circuitpython/blob/main/ports/espressif/mpconfigport.mk#L190 Your changes may be based on older CP though. It was just added with my deep sleep changes. |
I think both questions are solved now.
|
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 think it's as good as it can be considering the flash space constrains.
Tested on M5Stack cardputer (8MB flash).
The ADC bug is unaffected by CPU frequencies, and is reproducible even when running at 80Mhz.
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.
One question about sleep. Good otherwise. Thanks!
Does that mean all comments are resolved? Or is there anything I can still do? |
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.
Yup! Sorry I didn't merge immediately. I think the CI may have been going still.
This PR resolves #9305, making
microcontroller.cpu.frequency
settable on espressif boards. I followed micropython's implementation of the same feature.Question 1
This requires enabling
CONFIG_PM_ENABLE
in esp-idf, which is allows for a uniform API (see https://docs.espressif.com/projects/esp-idf/en/v5.2.2/esp32/api-reference/system/power_management.html) for changing the CPU frequency for all esp variants and internally ensures peripherals continue functioning. This means esp-idf contains many internal locations whereCONFIG_PM_ENABLE
is checked and extra logic has to be executed when power management is enabled.This means the circuitpython binary increases by ~3kB for all variants, which means we get
-464 bytes free in flash firmware space
for 1 board (lolin_c3_pico, japanese translation).These are the options I see:
cpu.frequency
settable on boards with limited space (which would these be? all C3 variants? or only certain C3 variants?)CONFIG_PM_ENABLE
, possibly leading to smaller code size. But I'm not sure what we lose by doing this. All those extra checks thatCONFIG_PM_ENABLE
induces surely are there for a reason.(Personally I would prefer option 1, as the code would be more maintainable than with option 2)
Question 2
I think it makes sense to inform the user about the possible frequencies that can be set, as there are not many valid ones (e.g. 20, 40, 80, 160, 240 MHz for the original ESP32).
For now I created a (rather long) new error message for each esp variant containing the valid frequencies, which is consistent with the settable frequency for
ports/mimxrt10xx/
.Does this make sense here? A more space-saving but less user-friendly approach would be a generic error message "Invalid Frequency" and a reference to the documentation.