Skip to content

Commit 2aca4ef

Browse files
sylvioalvescfriedt
authored andcommitted
soc: espressif: esp32c2: Enable deep sleep support
Adds support for deep sleep mode on the ESP32-C2 SoC, allowing significant power savings. Signed-off-by: Sylvio Alves <[email protected]>
1 parent d035502 commit 2aca4ef

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

soc/espressif/esp32c2/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/esp32c2/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ config SOC_SERIES_ESP32C2
1212
select RISCV_ISA_EXT_C
1313
select RISCV_ISA_EXT_ZICSR
1414
select HAS_ESPRESSIF_HAL
15+
select HAS_PM
16+
select HAS_POWEROFF
1517

1618
if SOC_SERIES_ESP32C2
1719

soc/espressif/esp32c2/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/esp32c2/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)