diff --git a/examples/wifi/power_save/main/Kconfig.projbuild b/examples/wifi/power_save/main/Kconfig.projbuild index 96e28d0b99..70c87c86b1 100644 --- a/examples/wifi/power_save/main/Kconfig.projbuild +++ b/examples/wifi/power_save/main/Kconfig.projbuild @@ -14,7 +14,7 @@ config WIFI_PASSWORD choice POWER_SAVE_MODE prompt "power save mode" - default POWER_SAVE_NONE + default POWER_SAVE_MODEM help Power save mode for the esp32 to use. diff --git a/examples/wifi/power_save/main/power_save.c b/examples/wifi/power_save/main/power_save.c index dae26fb9a5..f1d665fb91 100644 --- a/examples/wifi/power_save/main/power_save.c +++ b/examples/wifi/power_save/main/power_save.c @@ -17,6 +17,7 @@ #include "esp_wifi.h" #include "esp_log.h" #include "esp_event_loop.h" +#include "esp_pm.h" #include "nvs_flash.h" /*set the ssid and password via "make menuconfig"*/ @@ -89,5 +90,17 @@ void app_main() } ESP_ERROR_CHECK( ret ); +#if CONFIG_PM_ENABLE + // Configure dynamic frequency scaling: maximum frequency is set in sdkconfig, + // minimum frequency is XTAL. + rtc_cpu_freq_t max_freq; + rtc_clk_cpu_freq_from_mhz(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ, &max_freq); + esp_pm_config_esp32_t pm_config = { + .max_cpu_freq = max_freq, + .min_cpu_freq = RTC_CPU_FREQ_XTAL + }; + ESP_ERROR_CHECK( esp_pm_configure(&pm_config) ); +#endif // CONFIG_PM_ENABLE + wifi_power_save(); } diff --git a/examples/wifi/power_save/sdkconfig.defaults b/examples/wifi/power_save/sdkconfig.defaults new file mode 100644 index 0000000000..0c212b1df6 --- /dev/null +++ b/examples/wifi/power_save/sdkconfig.defaults @@ -0,0 +1,6 @@ +# Use lower CPU frequency +CONFIG_ESP32_DEFAULT_CPU_FREQ_80=y +# Enable support for power management +CONFIG_PM_ENABLE=y +# Use RTC timer as reference +CONFIG_PM_USE_RTC_TIMER_REF=y