Skip to content

Commit bbc5a83

Browse files
Raffael Rostagnojhedberg
authored andcommitted
soc: esp32h2: Power management support
Power management support for ESP32-H2. Signed-off-by: Raffael Rostagno <[email protected]>
1 parent 1f91cfe commit bbc5a83

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

soc/espressif/esp32h2/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ zephyr_sources(
1010
zephyr_include_directories(.)
1111

1212
zephyr_sources_ifndef(CONFIG_BOOTLOADER_MCUBOOT hw_init.c)
13+
14+
zephyr_library_sources_ifdef(CONFIG_PM power.c)
15+
zephyr_library_sources_ifdef(CONFIG_POWEROFF poweroff.c)

soc/espressif/esp32h2/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ config SOC_SERIES_ESP32H2
1414
select RISCV_ISA_EXT_ZICSR
1515
select RISCV_ISA_EXT_ZIFENCEI
1616
select HAS_ESPRESSIF_HAL
17+
select HAS_PM
18+
select HAS_POWEROFF

soc/espressif/esp32h2/power.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/pm/pm.h>
8+
#include <zephyr/irq.h>
9+
#include <esp_sleep.h>
10+
11+
#include <zephyr/logging/log.h>
12+
LOG_MODULE_DECLARE(soc, CONFIG_SOC_LOG_LEVEL);
13+
14+
/* Invoke Low Power/System Off specific Tasks */
15+
void pm_state_set(enum pm_state state, uint8_t substate_id)
16+
{
17+
ARG_UNUSED(substate_id);
18+
19+
switch (state) {
20+
case PM_STATE_STANDBY:
21+
/* Nothing to do. */
22+
break;
23+
default:
24+
LOG_DBG("Unsupported power state %u", state);
25+
break;
26+
}
27+
}
28+
29+
/* Handle SOC specific activity after Low Power Mode Exit */
30+
void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id)
31+
{
32+
ARG_UNUSED(substate_id);
33+
34+
switch (state) {
35+
case PM_STATE_STANDBY:
36+
irq_unlock(MSTATUS_IEN);
37+
__asm__ volatile("wfi");
38+
esp_light_sleep_start();
39+
break;
40+
default:
41+
LOG_DBG("Unsupported power state %u", state);
42+
break;
43+
}
44+
}

soc/espressif/esp32h2/poweroff.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <zephyr/sys/poweroff.h>
7+
8+
#include <esp_sleep.h>
9+
10+
void z_sys_poweroff(void)
11+
{
12+
/* Forces RTC domain to be always on */
13+
esp_sleep_pd_config(ESP_PD_DOMAIN_XTAL, ESP_PD_OPTION_ON);
14+
esp_deep_sleep_start();
15+
}

0 commit comments

Comments
 (0)