Closed
Description
Board
ESP32 Dev module
Device Description
ESP32 Dev module alone
Hardware Configuration
Nothing
Version
v2.0.1
IDE Name
Arduino IDE
Operating System
Ubuntu 20.04
Flash frequency
80Mhz
PSRAM enabled
no
Upload speed
921600
Description
When setting CPU frequency below 80Mhz, the serial monitor is garbage until I change the baud rate...
I manage to solve the problem by setting the Serial.begin(bauds) to : 80 / cpufreq * monitor_bauds
See sketch attached.
Sketch
uint32_t Freq = 0;
const int bauds = 115200;
int my_bauds;
int cpufreqs[6] = {240, 160, 80, 40, 20, 10};
int i = 0;
void setup() {
Freq = getCpuFrequencyMhz();
if (Freq < 80) {
my_bauds = 80 / Freq * bauds;
}
else {
my_bauds = bauds;
}
Serial.begin(my_bauds); // Attention dépend de la frequence CPU si elle est <80Mhz
delay(500);
//
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");
}
void loop() {
Serial.print("\nchange CPU freq to ");
Serial.println(cpufreqs[i]);
delay(1000);
setCpuFrequencyMhz(cpufreqs[i]);
Freq = getCpuFrequencyMhz();
Serial.print("Send to serial with my_bauds = ");
Serial.println(my_bauds);
Serial.print("CPU Freq = ");
Serial.print(Freq);
Serial.println(" MHz");
// Change bauds rate ?
if (Freq < 80) {
my_bauds = 80 / Freq * bauds;
}
else {
my_bauds = bauds;
}
Serial.end();
delay(1000);
Serial.begin(my_bauds);
delay(1000);
Serial.print("\nchange my_bauds to ");
Serial.println(my_bauds);
Serial.print("Serial set to ");
Serial.println(my_bauds);
Serial.print("CPU Freq = ");
Serial.print(Freq);
Serial.println(" MHz");
Serial.print("my_bauds = ");
Serial.println(my_bauds);
delay(1000);
i++;
i = i % 6;
}
Debug Message
No debug message, just monitor output set to 115200
CPU Freq = 240 MHz
XTAL Freq = 40 MHz
APB Freq = 80000000 Hz
change CPU freq to 240
Send to serial with my_bauds = 115200
CPU Freq = 240 MHz
change my_bauds to 115200
Serial set to 115200
CPU Freq = 240 MHz
my_bauds = 115200
change CPU freq to 160
Send to serial with my_bauds = 115200
CPU Freq = 160 MHz
change my_bauds to 115200
Serial set to 115200
CPU Freq = 160 MHz
my_bauds = 115200
change CPU freq to 80
Send to serial with my_bauds = 115200
CPU Freq = 80 MHz
change my_bauds to 115200
Serial set to 115200
CPU Freq = 80 MHz
my_bauds = 115200
change CPU freq to 40
�f⸮⸮⸮` AND OTHER GARBAGE
change my_bauds to 230400
Serial set to 230400
CPU Freq = 40 MHz
my_bauds = 230400
change CPU freq to 20
�f⸮⸮⸮` AND OTHER GARBAGE
change my_bauds to 460800
Serial set to 460800
CPU Freq = 20 MHz
my_bauds = 460800
change CPU freq to 10
�f⸮⸮⸮` AND OTHER GARBAGE
change my_bauds to 921600
Serial set to 921600
CPU Freq = 10 MHz
my_bauds = 921600
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.