Skip to content

Light-sleep CPU/TOP power-down for ESP32-C6 and ESP32-H2 - #5874

Draft
JurajSadel wants to merge 8 commits into
esp-rs:mainfrom
JurajSadel:sleep-cpu
Draft

Light-sleep CPU/TOP power-down for ESP32-C6 and ESP32-H2#5874
JurajSadel wants to merge 8 commits into
esp-rs:mainfrom
JurajSadel:sleep-cpu

Conversation

@JurajSadel

@JurajSadel JurajSadel commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Mostly AI-generated experiment towards #5808 - adds optional CPU and TOP power-domain power-down for light sleep on ESP32-C6 and ESP32-H2, with register retention so execution can resume after wake.

Changelog

esp-hal

  • Added: ESP32-C6, ESP32-H2: CPU and TOP power-down in light sleep, with opt-in register retention for UART, I2C and SPI.

@JurajSadel
JurajSadel force-pushed the sleep-cpu branch 2 times, most recently from 7a8b0aa to 6d21431 Compare July 10, 2026 13:58
Comment thread esp-hal/src/rtc_cntl/retention.rs
Comment thread esp-metadata/devices/esp32c6/soc.toml Outdated
@github-actions

Copy link
Copy Markdown

New commits in main have made this PR unmergeable. Please resolve the conflicts.

@github-actions github-actions Bot added the merge-conflict Merge conflict detected. Automatically added/removed by CI. label Jul 14, 2026
@github-actions github-actions Bot removed the merge-conflict Merge conflict detected. Automatically added/removed by CI. label Jul 20, 2026
@bugadani

Copy link
Copy Markdown
Contributor

What's the plan with this PR, is this ever coming out of draft?

@JurajSadel
JurajSadel marked this pull request as ready for review July 27, 2026 09:09
Comment thread esp-hal/src/rtc_cntl/retention/esp32c6.rs Outdated
Comment thread esp-hal/src/rtc_cntl/retention/esp32c6.rs Outdated
Comment on lines +131 to +139
// I2C: ESP-IDF v5.4 `i2c_periph.c` `i2c0_regs_retention`, `i2c_reg.h`.
pub(super) const I2C_SCL_LOW_PERIOD_OFF: u32 = 0x00; // I2C_SCL_LOW_PERIOD_REG: ADDR_MAP window base
pub(super) const I2C_CTR_OFF: u32 = 0x04; // I2C_CTR_REG
pub(super) const I2C_FSM_RST: u32 = 1 << 10; // I2C_FSM_RST (value == mask)
pub(super) const I2C_CONF_UPGATE: u32 = 1 << 11; // I2C_CONF_UPGATE (value == mask)
/// Registers retained (set bits in [`I2C_REGS_MAP`]).
pub(super) const I2C_RETENTION_REGS_CNT: u32 = 18;
/// `i2c0_regs_map[4]`: config registers in the `SCL_LOW_PERIOD..SCL_STRETCH_CONF` window.
pub(super) const I2C_REGS_MAP: [u32; 4] = [0xc03f_345b, 0x3, 0, 0];

@bugadani bugadani Jul 28, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am annoyed by this. We're defining a bunch of constants, so that common code can build up a presumed-common chain of operations for a peripheral. What we really want, is a per-chip, per-peripheral operation chain, just like the sys operations are. Nothing ensures peripherals have the same shape.

Also, I'd prefer, however long, explicitly spelling out the registers we back up. That binary map is impossible to read or write.

Comment thread esp-hal/src/rtc_cntl/retention/esp32c6.rs Outdated
Comment thread esp-hal/src/rtc_cntl/retention/esp32c6.rs Outdated
count: 18,
}, // HP_SYSTEM ..= HP_SYSTEM_MEM_TEST_CONF_REG (+0x44)
// PRI_5: console UART0.
Uart { base: 0x6000_0000 },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annoying. IDK what we should do about UART0 and SYSTIMER. SYSTIMER can be considered a system peripheral I guess, but we can also just reconfigure it fully on wakeup, we don't necessarily need to save it. UART is annoying because the user may not even be using it for println, so we likely just waste time and memory, but if they do use it, it needs to be saved. Once we resolve #4666 I guess it needs to be configured separately, but then we'll make it easy to configure half of the system only :(

Comment thread esp-hal/src/rtc_cntl/retention/esp32h2.rs Outdated
Comment thread esp-hal/src/rtc_cntl/cpu_retention.rs Outdated
};
}

noncritical_csrs! {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the riscv(-rt?) CSR access functions, and we should define the missing registers in esp-riscv-rt.

@github-actions

Copy link
Copy Markdown

New commits in main have made this PR unmergeable. Please resolve the conflicts.

@github-actions github-actions Bot removed the merge-conflict Merge conflict detected. Automatically added/removed by CI. label Jul 31, 2026
Comment thread esp-metadata/devices/esp32c6/soc.toml Outdated
Comment thread qa-test/src/bin/sleep_timer_powerdown.rs Outdated
@JurajSadel
JurajSadel force-pushed the sleep-cpu branch 2 times, most recently from 4866ca1 to bde5821 Compare July 31, 2026 13:58
Comment thread esp-metadata/src/cfg.rs Outdated
Comment thread esp-metadata/src/cfg.rs
@github-actions github-actions Bot added the merge-conflict Merge conflict detected. Automatically added/removed by CI. label Aug 5, 2026
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

New commits in main have made this PR unmergeable. Please resolve the conflicts.

@github-actions github-actions Bot removed the merge-conflict Merge conflict detected. Automatically added/removed by CI. label Aug 7, 2026
Comment thread esp-hal/Cargo.toml

[target.'cfg(target_arch = "riscv32")'.dependencies]
riscv = { version = "0.16.1" }
riscv = { version = "0.16.1", git = "https://github.com/JurajSadel/riscv.git", branch = "test" }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened a bunch of PRs to the riscv upstream - test branch has all PRs changes merged.

@bugadani

bugadani commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

If we're waiting on not only a bunch of PAC changes but the embedded working group, I don't see this getting merged any time soon. Let's put it back to draft, and not waste CI time on it.

@bugadani
bugadani marked this pull request as draft August 7, 2026 15:14
@bugadani bugadani added the status:blocked Unable to progress - dependent on another task label Aug 7, 2026
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

New commits in main have made this PR unmergeable. Please resolve the conflicts.

@github-actions github-actions Bot added the merge-conflict Merge conflict detected. Automatically added/removed by CI. label Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-conflict Merge conflict detected. Automatically added/removed by CI. status:blocked Unable to progress - dependent on another task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants