Skip to content

setCpuFrequencyMhz() changes Serial bauds if frequency<80Mhz  #7182

Closed
@savejeff

Description

@savejeff

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

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

change CPU freq to 240
⸮Bŭk⸮⸮⸮
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⸮⸮⸮`��~⸮⸮
change my_bauds to 230400
Serial set to 230400
CPU Freq = 40 MHz
my_bauds = 230400

change CPU freq to 20
�f⸮⸮⸮`��~⸮⸮
change my_bauds to 460800
Serial set to 460800
CPU Freq = 20 MHz
my_bauds = 460800

change CPU freq to 10
�f⸮⸮⸮`��~⸮⸮
change my_bauds to 921600
Serial set to 921600
CPU Freq = 10 MHz
my_bauds = 921600

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

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions