Skip to content

Commit c6b2295

Browse files
Added wake_hp_core() functionality to S2/S3 ULP cores.
1 parent 42a097d commit c6b2295

File tree

4 files changed

+88
-3
lines changed

4 files changed

+88
-3
lines changed

esp-hal/src/rtc_cntl/sleep/esp32s2.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::{
22
Ext0WakeupSource,
33
Ext1WakeupSource,
44
TimerWakeupSource,
5+
UlpWakeupSource,
56
WakeSource,
67
WakeTriggers,
78
WakeupLevel,
@@ -73,6 +74,12 @@ pub const RTC_MEM_POWERUP_CYCLES: u8 = OTHER_BLOCKS_POWERUP;
7374
/// RTC memory wait cycles.
7475
pub const RTC_MEM_WAIT_CYCLES: u16 = OTHER_BLOCKS_WAIT;
7576

77+
impl WakeSource for UlpWakeupSource {
78+
fn apply(&self, _rtc: &Rtc<'_>, triggers: &mut WakeTriggers, _sleep_config: &mut RtcSleepConfig) {
79+
triggers.set_ulp(true);
80+
}
81+
}
82+
7683
impl WakeSource for TimerWakeupSource {
7784
fn apply(
7885
&self,

esp-hal/src/rtc_cntl/sleep/esp32s3.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::{
22
Ext0WakeupSource,
33
Ext1WakeupSource,
44
TimerWakeupSource,
5+
UlpWakeupSource,
56
WakeSource,
67
WakeTriggers,
78
WakeupLevel,
@@ -81,6 +82,13 @@ pub const RTC_MEM_POWERUP_CYCLES: u8 = OTHER_BLOCKS_POWERUP;
8182
/// RTC memory wait cycles.
8283
pub const RTC_MEM_WAIT_CYCLES: u16 = OTHER_BLOCKS_WAIT;
8384

85+
impl WakeSource for UlpWakeupSource {
86+
fn apply(&self, _rtc: &Rtc<'_>, triggers: &mut WakeTriggers, _sleep_config: &mut RtcSleepConfig) {
87+
triggers.set_ulp_fsm(true);
88+
triggers.set_ulp_riscv(true);
89+
}
90+
}
91+
8492
impl WakeSource for TimerWakeupSource {
8593
fn apply(
8694
&self,

esp-hal/src/rtc_cntl/sleep/mod.rs

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,29 @@ impl Default for WakeFromLpCoreWakeupSource {
348348
}
349349
}
350350

351+
/// ULP-FSM wakeup source
352+
///
353+
/// Wake up from ULP-FSM or ULP-RISCV interrupt.
354+
/// This wakeup source can be used to wake up from both light and deep sleep.
355+
/// Does not enable ULP-RISCV TRAP wake-up.
356+
#[cfg(any(esp32s2,esp32s3))]
357+
pub struct UlpWakeupSource {}
358+
359+
#[cfg(any(esp32s2,esp32s3))]
360+
impl UlpWakeupSource {
361+
/// Create a new instance of `WakeFromUlpWakeupSource`
362+
pub fn new() -> Self {
363+
Self {}
364+
}
365+
}
366+
367+
#[cfg(any(esp32s2,esp32s3))]
368+
impl Default for UlpWakeupSource {
369+
fn default() -> Self {
370+
Self::new()
371+
}
372+
}
373+
351374
/// GPIO wakeup source
352375
///
353376
/// Wake up from GPIO high or low level. Any pin can be used with this wake up
@@ -468,13 +491,15 @@ bitfield::bitfield! {
468491
pub uart1, set_uart1: 7;
469492
/// Touch wakeup
470493
pub touch, set_touch: 8;
471-
/// ULP-FSM wakeup
494+
/// ULP-FSM or ULP-RISCV wakeup
472495
pub ulp, set_ulp: 11;
496+
/// ULP-RISCV trap wakeup
497+
pub ulp_riscv_trap, set_ulp_riscv_trap: 13;
473498
/// USB wakeup
474499
pub usb, set_usb: 15;
475500
}
476501

477-
#[cfg(any(esp32, esp32c2, esp32c3, esp32s3))]
502+
#[cfg(esp32s3)]
478503
bitfield::bitfield! {
479504
/// Represents the wakeup triggers.
480505
#[derive(Default, Clone, Copy)]
@@ -498,7 +523,42 @@ bitfield::bitfield! {
498523
pub uart1, set_uart1: 7;
499524
/// Touch wakeup
500525
pub touch, set_touch: 8;
501-
/// ULP wakeup
526+
/// ULP-FSM wakeup
527+
pub ulp_fsm, set_ulp_fsm: 9;
528+
/// BT wakeup (light sleep only)
529+
pub bt, set_bt: 10;
530+
/// ULP-RISCV wakeup
531+
pub ulp_riscv, set_ulp_riscv: 11;
532+
/// ULP-RISCV trap wakeup
533+
pub ulp_riscv_trap, set_ulp_riscv_trap: 13;
534+
}
535+
536+
537+
#[cfg(any(esp32, esp32c2, esp32c3))]
538+
bitfield::bitfield! {
539+
/// Represents the wakeup triggers.
540+
#[derive(Default, Clone, Copy)]
541+
pub struct WakeTriggers(u16);
542+
impl Debug;
543+
/// EXT0 GPIO wakeup
544+
pub ext0, set_ext0: 0;
545+
/// EXT1 GPIO wakeup
546+
pub ext1, set_ext1: 1;
547+
/// GPIO wakeup (light sleep only)
548+
pub gpio, set_gpio: 2;
549+
/// Timer wakeup
550+
pub timer, set_timer: 3;
551+
/// SDIO wakeup (light sleep only)
552+
pub sdio, set_sdio: 4;
553+
/// MAC wakeup (light sleep only)
554+
pub mac, set_mac: 5;
555+
/// UART0 wakeup (light sleep only)
556+
pub uart0, set_uart0: 6;
557+
/// UART1 wakeup (light sleep only)
558+
pub uart1, set_uart1: 7;
559+
/// Touch wakeup
560+
pub touch, set_touch: 8;
561+
/// ULP-FSM wakeup
502562
pub ulp, set_ulp: 9;
503563
/// BT wakeup (light sleep only)
504564
pub bt, set_bt: 10;

esp-lp-hal/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ pub fn wake_hp_core() {
6565
.write(|w| w.lp_trigger_hp().set_bit());
6666
}
6767

68+
/// Wake up the HP core
69+
#[cfg(any(feature = "esp32s2", feature = "esp32s3"))]
70+
#[unsafe(link_section = ".init.rust")]
71+
#[unsafe(no_mangle)]
72+
pub fn wake_hp_core() {
73+
unsafe { &*pac::RTC_CNTL::PTR }
74+
.rtc_state0()
75+
.write(|w|w.rtc_sw_cpu_int().set_bit());
76+
}
77+
6878
#[cfg(feature = "esp32c6")]
6979
global_asm!(
7080
r#"

0 commit comments

Comments
 (0)