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

fixes UART at lower than 80MHz | S3 C3 #7496

Merged
merged 4 commits into from
Dec 13, 2022

Conversation

SuGlider
Copy link
Collaborator

Description of Change

This PR fixes UART baud rate when ESP32-S3 and ESP32-C3 are running under 80MHz.

Tests scenarios

Using ESP32, ESP32-S2, ESP32-S3 and ESP32-C3

Testing sketch:

uint32_t Freq = 0;
const int bauds = 115200;
uint8_t cpufreqs[] = {240, 160, 80, 40, 20, 10};
int i = 0;

void setup() {
  Freq = getCpuFrequencyMhz();

  Serial.begin(bauds);
  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.end();
  Serial.begin(bauds);

  Serial.print("Sending to serial with baud rate = ");
  Serial.println(bauds);
  Serial.print("CPU Freq = ");
  Serial.print(Freq);
  Serial.println(" MHz");

  delay(1000);
  i++;
  i = i % sizeof(cpufreqs);
}

Related links

Fix #7182

@SuGlider SuGlider added Chip: ESP32-C3 Issue is related to support of ESP32-C3 Chip Chip: ESP32-S3 Issue is related to support of ESP32-S3 Chip Area: Peripherals API Relates to peripheral's APIs. Peripheral: UART labels Nov 20, 2022
@SuGlider SuGlider added this to the 2.0.6 milestone Nov 20, 2022
@SuGlider SuGlider self-assigned this Nov 20, 2022
Copy link
Member

@P-R-O-C-H-Y P-R-O-C-H-Y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on all chips before/after changes. Fixes the UART baud rate for C3/S3.
Great fix @SuGlider, LGTM!

@aeonSolutions
Copy link

i confirm it is working for serial send , Serial.print() command

however it is not working for Serial.read()

I'm currently testing at 10MHz same ESP32 S3 with 8MB and no Serial.read()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Peripherals API Relates to peripheral's APIs. Chip: ESP32-C3 Issue is related to support of ESP32-C3 Chip Chip: ESP32-S3 Issue is related to support of ESP32-S3 Chip Peripheral: UART
Projects
Development

Successfully merging this pull request may close these issues.

setCpuFrequencyMhz() changes Serial bauds if frequency<80Mhz
4 participants