-
Notifications
You must be signed in to change notification settings - Fork 7.6k
/
Copy pathSerial_All_CPU_Freqs.ino
75 lines (65 loc) · 2.17 KB
/
Serial_All_CPU_Freqs.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
Simple Sketch for testing HardwareSerial with different CPU Frequencies
Changing the CPU Frequency may affect peripherals and Wireless functionality
In ESP32 Arduino, UART shall work correctly in order to let the user see DGB info
and other application messages.
CPU Frequency is usually lowered in sleep modes
and some other Low Power configurations
*/
int cpufreqs[6] = {240, 160, 80, 40, 20, 10};
#define NUM_CPU_FREQS (sizeof(cpufreqs) / sizeof(int))
void setup() {
Serial.begin(115200);
delay(1000);
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);
// ESP32-C3 and other RISC-V target may not support 240MHz
#ifdef CONFIG_IDF_TARGET_ESP32C3
uint8_t firstFreq = 1;
#else
uint8_t firstFreq = 0;
#endif
// testing HardwareSerial for all possible CPU/APB Frequencies
for (uint8_t i = firstFreq; i < NUM_CPU_FREQS; 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");
if (i < NUM_CPU_FREQS - 1) {
Serial.println("Moving to the next frequency after a pause of 2 seconds.");
delay(2000);
}
}
Serial.println("\n-------------------\n");
Serial.println("End of testing...");
Serial.println("\n-------------------\n");
}
void loop() {
// Nothing here so far
}