Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ Note: When normal mode COUNT is 0, it will switch to the next PM state where COU

Note: During light sleep, overall current consumption of board should drop from 18mA (without any system load) to 1 mA on ESP32-C3 DevkitM-1.

To save power without using sleep modes, lowering the clock speed is another approach. For dynamic frequency scaling
``CONFIG_ESPRESSIF_DFS`` option needs to enabled and minimum CPU frequency needs to set under ``CONFIG_ESPRESSIF_MIN_CPU_FREQ`` option.
With these options, the device scales the CPU clock according to workload.

pwm
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ Note: When normal mode COUNT is 0, it will switch to the next PM state where COU
Note: During light sleep, overall current consumption of board should drop from 22mA (without any system load) to 1.3 mA on ESP32-C6 DevkitC-1.
During deep sleep, current consumption of module (ESP32-C6-WROOM-1) should drop from 22mA (without any system load) to 48 μA.

To save power without using sleep modes, lowering the clock speed is another approach. For dynamic frequency scaling
``CONFIG_ESPRESSIF_DFS`` option needs to enabled and minimum CPU frequency needs to set under ``CONFIG_ESPRESSIF_MIN_CPU_FREQ`` option.
With these options, the device scales the CPU clock according to workload.

pwm
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ Note: When normal mode COUNT is 0, it will switch to the next PM state where COU
Note: During light sleep, overall current consumption of board should drop from 14mA (without any system load) to 880 μA on ESP32-H2 DevkitM-1.
During deep sleep, current consumption of module (ESP32-H2-MINI-1) should drop from 9mA (without any system load) to 8 μA.

To save power without using sleep modes, lowering the clock speed is another approach. For dynamic frequency scaling
``CONFIG_ESPRESSIF_DFS`` option needs to enabled and minimum CPU frequency needs to set under ``CONFIG_ESPRESSIF_MIN_CPU_FREQ`` option.
With these options, the device scales the CPU clock according to workload.

pwm
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ System switch to the PM sleep mode, you need to enter::
nsh> pmconfig relax normal
nsh> pmconfig relax normal

To save power without using sleep modes, lowering the clock speed is another approach. For dynamic frequency scaling
``CONFIG_ESPRESSIF_DFS`` option needs to enabled and minimum CPU frequency needs to set under ``CONFIG_ESPRESSIF_MIN_CPU_FREQ`` option.
With these options, the device scales the CPU clock according to workload.

pwm
---

Expand Down
2 changes: 1 addition & 1 deletion arch/risc-v/src/common/espressif/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ if(DEFINED ENV{ESP_HAL_3RDPARTY_VERSION})
CACHE STRING "ESP HAL 3rdparty version")
else()
set(ESP_HAL_3RDPARTY_VERSION
b7e51db97a3f9dc82d3b3524d2bad298ba1e2647
2209449c9864c6d83a0ee2295f5b5299a2c6fb39
CACHE STRING "ESP HAL 3rdparty version")
endif()

Expand Down
92 changes: 92 additions & 0 deletions arch/risc-v/src/common/espressif/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ config ESPRESSIF_CPU_FREQ_MHZ
default 360 if ESPRESSIF_CPU_FREQ_360
default 400 if ESPRESSIF_CPU_FREQ_400

config ESPRESSIF_DFS
bool "Enable DFS (Dynamic Frequency Scaling)"
select PM
default n

config ESPRESSIF_REGION_PROTECTION
bool "Enable region protection"
default y
Expand Down Expand Up @@ -162,6 +167,93 @@ config ESPRESSIF_SOC_RTC_MEM_SUPPORTED
bool
default n

menu "Espressif DFS Options"
depends on ESPRESSIF_DFS

choice ESPRESSIF_MIN_CPU_FREQ
prompt "Minimum CPU frequency"
default ESPRESSIF_MIN_CPU_FREQ_40 if ARCH_CHIP_ESP32P4 && ESPRESSIF_IDF_ENV_FPGA
default ESPRESSIF_MIN_CPU_FREQ_96 if ARCH_CHIP_ESP32H2
default ESPRESSIF_MIN_CPU_FREQ_160 if ARCH_CHIP_ESP32C3 || ARCH_CHIP_ESP32C6
default ESPRESSIF_MIN_CPU_FREQ_360 if ARCH_CHIP_ESP32P4 && ESP32P4_SELECTS_REV_LESS_V3
default ESPRESSIF_MIN_CPU_FREQ_400 if ARCH_CHIP_ESP32P4 && !ESP32P4_SELECTS_REV_LESS_V3
---help---
Minimum CPU frequency to be scale.

config ESPRESSIF_MIN_CPU_FREQ_40
bool "40 MHz"
depends on ARCH_CHIP_ESP32C3 || ARCH_CHIP_ESP32C6 || ARCH_CHIP_ESP32P4
---help---
Set the minimum CPU frequency to 40 MHz.

config ESPRESSIF_MIN_CPU_FREQ_48
bool "48 MHz"
depends on ARCH_CHIP_ESP32H2
---help---
Set the minimum CPU frequency to 48 MHz.

config ESPRESSIF_MIN_CPU_FREQ_64
bool "64 MHz"
depends on ARCH_CHIP_ESP32H2
---help---
Set the minimum CPU frequency to 64 MHz.

config ESPRESSIF_MIN_CPU_FREQ_80
bool "80 MHz"
depends on ARCH_CHIP_ESP32C3 || ARCH_CHIP_ESP32C6
---help---
Set the minimum CPU frequency to 80 MHz.

config ESPRESSIF_MIN_CPU_FREQ_96
bool "96 MHz"
depends on ARCH_CHIP_ESP32H2
---help---
Set the minimum CPU frequency to 96 MHz.

config ESPRESSIF_MIN_CPU_FREQ_160
bool "160 MHz"
depends on ARCH_CHIP_ESP32C3 || ARCH_CHIP_ESP32C6
---help---
Set the minimum CPU frequency to 160 MHz.

config ESPRESSIF_MIN_CPU_FREQ_360
bool "360 MHz"
depends on ARCH_CHIP_ESP32P4 && ESP32P4_SELECTS_REV_LESS_V3
---help---
Set the minimum CPU frequency to 360 MHz.

config ESPRESSIF_MIN_CPU_FREQ_400
bool "400 MHz"
depends on ARCH_CHIP_ESP32P4 && !ESP32P4_SELECTS_REV_LESS_V3
---help---
Set the minimum CPU frequency to 400 MHz.

endchoice # ESPRESSIF_MIN_CPU_FREQ

config ESPRESSIF_MAX_CPU_FREQ_MHZ
int
default 40 if ESPRESSIF_MAX_CPU_FREQ_40
default 48 if ESPRESSIF_MAX_CPU_FREQ_48
default 64 if ESPRESSIF_MAX_CPU_FREQ_64
default 80 if ESPRESSIF_MAX_CPU_FREQ_80
default 96 if ESPRESSIF_MAX_CPU_FREQ_96
default 160 if ESPRESSIF_MAX_CPU_FREQ_160
default 360 if ESPRESSIF_MAX_CPU_FREQ_360
default 400 if ESPRESSIF_MAX_CPU_FREQ_400

config ESPRESSIF_MIN_CPU_FREQ_MHZ
int
default 40 if ESPRESSIF_MIN_CPU_FREQ_40
default 48 if ESPRESSIF_MIN_CPU_FREQ_48
default 64 if ESPRESSIF_MIN_CPU_FREQ_64
default 80 if ESPRESSIF_MIN_CPU_FREQ_80
default 96 if ESPRESSIF_MIN_CPU_FREQ_96
default 160 if ESPRESSIF_MIN_CPU_FREQ_160
default 360 if ESPRESSIF_MIN_CPU_FREQ_360
default 400 if ESPRESSIF_MIN_CPU_FREQ_400

endmenu #

menu "Espressif Log Level"
visible if DEBUG_FEATURES

Expand Down
2 changes: 1 addition & 1 deletion arch/risc-v/src/common/espressif/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ endif

ESP_HAL_3RDPARTY_REPO = esp-hal-3rdparty
ifndef ESP_HAL_3RDPARTY_VERSION
ESP_HAL_3RDPARTY_VERSION = b7e51db97a3f9dc82d3b3524d2bad298ba1e2647
ESP_HAL_3RDPARTY_VERSION = 2209449c9864c6d83a0ee2295f5b5299a2c6fb39
endif

ifndef ESP_HAL_3RDPARTY_URL
Expand Down
63 changes: 61 additions & 2 deletions arch/risc-v/src/common/espressif/esp_gptimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
#include "periph_ctrl.h"
#include "soc/clk_tree_defs.h"
#include "esp_private/esp_clk_tree_common.h"
#ifdef CONFIG_PM
# include "include/esp_pm.h"
#endif

/****************************************************************************
* Pre-processor Definitions
Expand Down Expand Up @@ -77,6 +80,9 @@ struct esp_timer_lowerhalf_s
bool started; /* True: Timer has been started */
void *upper; /* Pointer to timer_upperhalf_s */
int group_id; /* Timer group number */
#ifdef CONFIG_PM
esp_pm_lock_handle_t pm_lock; /* Power management lock */
#endif
};

/****************************************************************************
Expand Down Expand Up @@ -122,15 +128,21 @@ static const struct timer_ops_s g_timer_ops =
static struct esp_timer_lowerhalf_s g_timer0_lowerhalf =
{
.ops = &g_timer_ops,
.group_id = 0
.group_id = 0,
#ifdef CONFIG_PM
.pm_lock = NULL,
#endif
};

/* TIMER1 lower-half */

static struct esp_timer_lowerhalf_s g_timer1_lowerhalf =
{
.ops = &g_timer_ops,
.group_id = 1
.group_id = 1,
#ifdef CONFIG_PM
.pm_lock = NULL,
#endif
};

/****************************************************************************
Expand Down Expand Up @@ -171,6 +183,13 @@ static int esp_timer_start(struct timer_lowerhalf_s *lower)

timer_hal_context_t *hal = &(priv->hal);

#ifdef CONFIG_PM
if (priv->pm_lock != NULL)
{
esp_pm_lock_acquire(priv->pm_lock);
}
#endif

/* Make sure the timer is stopped to avoid unpredictable behavior */

timer_ll_enable_intr(hal->dev, TIMER_LL_EVENT_ALARM(hal->timer_id),
Expand Down Expand Up @@ -282,6 +301,13 @@ static int esp_timer_stop(struct timer_lowerhalf_s *lower)
false);
timer_ll_enable_counter(hal->dev, hal->timer_id, false);

#ifdef CONFIG_PM
if (priv->pm_lock != NULL)
{
esp_pm_lock_release(priv->pm_lock);
}
#endif

priv->started = false;
priv->callback = NULL;

Expand Down Expand Up @@ -542,6 +568,11 @@ int esp_timer_initialize(int group_id)
char *devpath;
shared_periph_module_t periph;
int irq;
#ifdef CONFIG_PM
int ret;
bool need_pm_lock = true;
esp_pm_lock_type_t pm_lock_type = ESP_PM_NO_LIGHT_SLEEP;
#endif

switch (group_id)
{
Expand Down Expand Up @@ -590,6 +621,34 @@ int esp_timer_initialize(int group_id)

timer_hal_init(&lower->hal, lower->group_id, lower->hal.timer_id);

#ifdef CONFIG_PM
# if TIMER_LL_FUNC_CLOCK_SUPPORT_RC_FAST
if (GPTIMER_CLK_SRC_DEFAULT == GPTIMER_CLK_SRC_RC_FAST)
{
need_pm_lock = false;
}
# endif

# if TIMER_LL_FUNC_CLOCK_SUPPORT_APB
if (GPTIMER_CLK_SRC_DEFAULT == GPTIMER_CLK_SRC_APB)
{
pm_lock_type = ESP_PM_APB_FREQ_MAX;
}
# endif

if (need_pm_lock && lower->pm_lock == NULL)
{
ret = esp_pm_lock_create(pm_lock_type, 0,
"TIMER",
&lower->pm_lock);
if (ret != OK)
{
tmrerr("Failed to create GPTIMER PM lock\n");
return -ENOMEM;
}
}
#endif

/* Register the timer driver as /dev/timerX. If the registration goes
* right the returned value from timer_register is a pointer to
* timer_upperhalf_s that can be either used with timer_unregister()
Expand Down
Loading
Loading