Skip to content
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

Change CPU frequency #579

Closed
pablotix20 opened this issue Jul 20, 2015 · 2 comments
Closed

Change CPU frequency #579

pablotix20 opened this issue Jul 20, 2015 · 2 comments

Comments

@pablotix20
Copy link
Contributor

Add ESP library command for system_update_cpu_freq

@igrr
Copy link
Member

igrr commented Aug 5, 2015

CPU frequency is set automatically depending on what is chosen in Tools > CPU Frequency menu in the IDE. If you want to override this behaviour for some reasons, you may provide an alternative implementation for preloop_update_frequency function inside your sketch. This function is declared as weak, so you can override it without modifying the library.
Also if you need to call system_update_cpu_freq, just include user_interface.h and call it directly. I think this function doesn't need a wrapper.

@igrr igrr closed this as completed Aug 5, 2015
@dadler
Copy link

dadler commented May 19, 2017

I've noticed that after using the Arduino IDE to set rate to 160 MHZ and then back to 80 MHZ, it doesn't properly return to 80 MHZ until I cycle power. Recompiling properly rebuilds with F_CPU set to 80 MHZ but preloop_update_frequency doesn't clear the clock frequency bit. Note that it's a no-op when F_CPU isn't 160 MHZ:

void preloop_update_frequency() {
#if defined(F_CPU) && (F_CPU == 160000000L)
REG_SET_BIT(0x3ff00014, BIT(0));
ets_update_cpu_frequency(160);
#endif
}

That caused pulseIn() to return values twice as large as it should (until I power cycled).

dok-net added a commit to dok-net/arduino-esp8266 that referenced this issue Apr 11, 2020
devyte pushed a commit that referenced this issue Apr 15, 2020
* At least the F_CPU define in host mock.h is needed by host Arduino.h - need to include Arduino.h further down in mock.h for this to work.

* Geting the include order right

* Prepare for runtime CPU clock rate selection

* Fix compile for not defined F_CPU

If defined F_CPU, make getCpuFreqMHz() a constexpr

* Use defines for register CPU2X instead of hex value

* Fix build for host - getCpuFreqMHz there was also in conflict with getCycleCount, using F_CPU:

tests/host/common/mock.h:#define F_CPU 80000000 (!)

* Asymmetrical includes and defines on host

* Support restart switch from 160MHz to 80MHz, e.g for OTA. Fixes #579
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants