2222
2323#if CONFIG_IDF_TARGET_ESP32H2
2424#define WAKEUP_GPIO GPIO_NUM_7 // Only RTC IO are allowed
25+ #define TARGET_FREQ 32
2526#else
2627#define WAKEUP_GPIO GPIO_NUM_4 // Only RTC IO are allowed
28+ #define TARGET_FREQ 40
2729#endif
2830
29- RTC_DATA_ATTR int bootCount = 0 ;
31+ RTC_DATA_ATTR int boot_count = 0 ;
32+ uint32_t orig_freq = 0 ;
3033
3134void print_wakeup_reason () {
3235 esp_sleep_wakeup_cause_t wakeup_reason;
@@ -86,17 +89,17 @@ void setup_uart() {
8689 esp_sleep_enable_uart_wakeup (UART_NUM_0);
8790}
8891
89-
90-
9192void setup () {
9293 Serial.begin (115200 );
9394 while (!Serial) {
9495 delay (10 );
9596 }
9697
98+ orig_freq = getCpuFrequencyMhz ();
99+
97100 // Increment boot number and print it every reboot
98- ++bootCount ;
99- Serial.println (" Boot number: " + String (bootCount ));
101+ boot_count++ ;
102+ Serial.println (" Boot number: " + String (boot_count ));
100103
101104 // Print the wakeup reason for ESP32
102105 print_wakeup_reason ();
@@ -138,6 +141,10 @@ void loop() {
138141 } else if (command == " timer_light" ) {
139142 // Test timer wakeup from light sleep
140143 setup_timer ();
144+ } else if (command == " timer_freq_light" ) {
145+ // Test timer wakeup from light sleep while changing CPU frequency
146+ setCpuFrequencyMhz (TARGET_FREQ);
147+ setup_timer ();
141148 } else if (command == " touchpad_light" ) {
142149 // Test touchpad wakeup from light sleep
143150 setup_touchpad ();
@@ -163,5 +170,6 @@ void loop() {
163170 print_wakeup_reason ();
164171 Serial.flush ();
165172 gpio_hold_dis (WAKEUP_GPIO);
173+ setCpuFrequencyMhz (orig_freq);
166174 }
167175}
0 commit comments