-
Notifications
You must be signed in to change notification settings - Fork 7.6k
setCpuFrequencyMhz() changes Serial bauds if frequency<80Mhz #7182
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
Comments
I see that it has not been implemented for C3. That's the issue. |
What do you mean "for C3" ? About the I2C and SPI issue: i have only tested this on the C3. S3 and S might also have the same issues |
Just a quick question... Are you using any ESP at lower than 80MHz? Please explain the usage. We will verify it for all SoC. C3 is RISC V and has a different internal structure regarding CPU Frequency. S2 and S3, the same regarding different internal structure. Therefore, I'm not sure if it is possible to solve this issue |
In general i don't think there needs to be an specific application when we talk about low level functions like these. they should IMHO work as expected to allow fast and reliable development without pitfalls. But I have in fact an actual application: My device is battery-powered to record data. between recordings, the device moves into a standby mode where everything essential is kept running but with reduced power consumption. so i reduce the esp clock as low as possible where still the important measurements can be performed. at the start of the next recording, the clock is increased and everything runs on full steam again.
Why would it not be possible? the code above is a working fix for all architectures.
needs to be used. SPI is even simpler. SPI.beginTransaction receives the desired clock rate in the SPISettings parameter. so analog to the Serial fix, a simple correction of the clock speed would be sufficient I think. I2C (at least on the C3 where i tested it) does not display slowdown in low CPU freqs So a change below 80Mhz would look like this:
|
@savejeff - I use Arduino Core 2.0.4 and tested this sketch with ESP32, ESP32-S2, ESP32-S3 and ESP32-C3: void setup() {
int cpufreqs[6] = {240, 160, 80, 40, 20, 10};
Serial.begin(115200); // Attention dépend de la frequence CPU si elle est <80Mhz
delay(1000); // just a second to make sure that we will get all messages in the Serial Terminal
Serial.println("\n Starting...\n");
Serial.flush();
// initial information
uint32_t Freq = getCpuFrequencyMhz();
Serial.print("CPU Freq = ");
Serial.print(Freq);
Serial.println(" MHz");
Freq = getXtalFrequencyMhz();
Serial.print("XTAL Freq = ");
Serial.print(Freq);
Serial.println(" MHz");
Freq = getApbFrequency();
Serial.print("APB Freq = ");
Serial.print(Freq);
Serial.println(" Hz");
delay(500);
#ifdef CONFIG_IDF_TARGET_ESP32C3
uint8_t firstFreq = 1;
#else
uint8_t firstFreq = 0;
#endif
for (uint8_t i = firstFreq; i < sizeof(cpufreqs) / sizeof(int); i++) {
Serial.printf("\n------- Trying CPU Freq = %d ---------\n", cpufreqs[i]);
Serial.flush(); // wait to empty the UART FIFO before changing the CPU Freq.
setCpuFrequencyMhz(cpufreqs[i]);
Serial.updateBaudRate(115200);
//
Freq = getCpuFrequencyMhz();
Serial.print("CPU Freq = ");
Serial.print(Freq);
Serial.println(" MHz");
Freq = getXtalFrequencyMhz();
Serial.print("XTAL Freq = ");
Serial.print(Freq);
Serial.println(" MHz");
Freq = getApbFrequency();
Serial.print("APB Freq = ");
Serial.print(Freq);
Serial.println(" Hz");
Serial.println("Moving to the fext frequency ... after pause of 2 seconds.");
delay(2000);
}
Serial.println("\n-------------------\n");
Serial.println("End of testing...");
Serial.println("\n-------------------\n");
}
void loop() {
}
Results:It works perfectly fine with ESP32 and ESP32-S2. |
It is necessary to check what is the source of Clock for SPI, I2C and others, in order to make sure it works fine under APB Freq (80MHz). Thanks. |
As per the example above used for testing, this exactly how it will work for the UART peripheral. |
I think the most important thing is that Serial works as expected. i2C and SPI has a clock speed determined by the master, so the communication is not broken, just slowed down. A fix here would of course be best. When i find time I'll check by what factor SPI is slowed down. maybe its as simple as with Serial. Thanks for taking up the issue |
Board
ESP32-S3 DevKitC-1, ESP32-C3 NodeMCU, ESP32DevKit
Device Description
plane ESP32-S3 DevKitC-1 with nothing attached
plane ESP32-C3 NodeMCU board
plane ESP32DevKit board
Hardware Configuration
.
Version
v2.0.4
IDE Name
Arduini IDE
Operating System
Windows 10
Flash frequency
80Mhz
PSRAM enabled
no
Upload speed
921600
Description
the Issued described in this issue is still not fixed for (at least) the ESP32-S3.
EDIT: i tested this with the ESP32DevKit and the same behavior can be observed but it somehow seems to be even worse.
EDIT2: i tested this with the ESP32-C3 and the same behavior can be observed.
The problem is with every CPU Freq below 80Mhz, the Baudrate must be adjusted up to compensate for slower clock speeds.
Sketch
Debug Message
Other Bus Speeds
I2C and SPI might also be slowed down. This should be checked as well.
EDIT: I2C (on ESP32-C3) maintains clock speed. SPI does not. it slows down as the serial does
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: