Commit 2aca4ef0 authored by Sylvio Alves's avatar Sylvio Alves Committed by Chris Friedt
Browse files

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: default avatarSylvio Alves <sylvio.alves@espressif.com>
parent d0355025
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -10,3 +10,6 @@ zephyr_sources(
zephyr_include_directories(.)

zephyr_sources_ifndef(CONFIG_BOOTLOADER_MCUBOOT hw_init.c)

zephyr_library_sources_ifdef(CONFIG_PM power.c)
zephyr_library_sources_ifdef(CONFIG_POWEROFF poweroff.c)
+2 −0
Original line number Diff line number Diff line
@@ -12,6 +12,8 @@ config SOC_SERIES_ESP32C2
	select RISCV_ISA_EXT_C
	select RISCV_ISA_EXT_ZICSR
	select HAS_ESPRESSIF_HAL
	select HAS_PM
	select HAS_POWEROFF

if SOC_SERIES_ESP32C2

+44 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr/pm/pm.h>
#include <zephyr/irq.h>
#include <esp_sleep.h>

#include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(soc, CONFIG_SOC_LOG_LEVEL);

/* Invoke Low Power/System Off specific Tasks */
void pm_state_set(enum pm_state state, uint8_t substate_id)
{
	ARG_UNUSED(substate_id);

	switch (state) {
	case PM_STATE_STANDBY:
		/* Nothing to do. */
		break;
	default:
		LOG_DBG("Unsupported power state %u", state);
		break;
	}
}

/* Handle SOC specific activity after Low Power Mode Exit */
void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id)
{
	ARG_UNUSED(substate_id);

	switch (state) {
	case PM_STATE_STANDBY:
		irq_unlock(MSTATUS_IEN);
		__asm__ volatile("wfi");
		esp_light_sleep_start();
		break;
	default:
		LOG_DBG("Unsupported power state %u", state);
		break;
	}
}
+15 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr/sys/poweroff.h>

#include <esp_sleep.h>

void z_sys_poweroff(void)
{
	/* Forces RTC domain to be always on */
	esp_sleep_pd_config(ESP_PD_DOMAIN_XTAL, ESP_PD_OPTION_ON);
	esp_deep_sleep_start();
}