espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.65k stars 7.42k forks source link

getApbFrequency() return 80MHz even though CPU < 80 MHz on ESP32-S3 #7086

Open ehong-tl opened 2 years ago

ehong-tl commented 2 years ago

Board

ESP32-S3-DevKitC-1-N8R8

Device Description

None

Hardware Configuration

None

Version

v2.0.3

IDE Name

Arduino IDE

Operating System

Windows 10

Flash frequency

80MHz

PSRAM enabled

no

Upload speed

921600

Description

getApbFrequency() return 80 MHz even though CPU frequency is less than 80 MHz, which makes this UART changes ineffective for ESP32-S3. I have to manually multiply the baudrate during Serial.begin(desired baudrate * multiplier). I didn't encounter such issue on older ESP32 and ESP32-S2.

Sketch

uint32_t Freq = 0;

void setup() {
  setCpuFrequencyMhz(10);

  Serial.begin(115200 * 8);  // Have to manually multiply the baudrate based on CPU frequency

  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() {

}

Debug Message

11:16:52.749 -> ESP-ROM:esp32s3-20210327
11:16:52.749 -> Build:Mar 27 2021
11:16:52.749 -> rst:0x1 (POWERON),boot:0x9 (SPI_FAST_FLASH_BOOT)
11:16:52.770 -> SPIWP:0xee
11:16:52.770 -> mode:DIO, clock div:1
11:16:52.770 -> load:0x3fcd0108,len:0x43c
11:16:52.770 -> load:0x403b6000,len:0xbd0
11:16:52.770 -> load:0x403ba000,len:0x29c8
11:16:52.770 -> SHA-256 comparison failed:
11:16:52.770 -> Calculated: 0bb45b01207a4a9e9fca8880ddfc0f79112bfa4d004bd1e6b2eaa75c5323b19d
11:16:52.770 -> Expected: 6eb14ec480aff4f05e39378c41406102ac163573741e63b6cfd73509ef44e3bd
11:16:52.770 -> Attempting to boot anyway...
11:16:52.816 -> entry 0x403b61d8
11:16:52.863 -> CPU Freq = 10 MHz
11:16:52.863 -> XTAL Freq = 40 MHz
11:16:52.863 -> APB Freq = 80000000 Hz

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

Jason2866 commented 2 years ago

Have you verified the wanted changed clock speed has been realy changed (osci)?

ehong-tl commented 2 years ago

I've checked the signal pattern with oscilloscope by running continuous digitalWrite HIGH to LOW, and the result for 10 MHz is about 1/24 of when CPU is 240 MHz which is to be expected, but the getApbFrequency() still return 80 MHz even when CPU is 10 MHz.