hp-core: Sleep after action

Signed-off-by: Thomas Klaehn <thomas.klaehn@perinet.io>
This commit is contained in:
Thomas Klaehn 2025-02-12 09:05:57 +01:00
parent 0d40a0e884
commit 18610940f4

View File

@ -19,6 +19,7 @@ use esp_hal::{
gpio::lp_io::LowPowerOutput, gpio::lp_io::LowPowerOutput,
load_lp_code, load_lp_code,
lp_core::{LpCore, LpCoreWakeupSource}, lp_core::{LpCore, LpCoreWakeupSource},
rtc_cntl::{Rtc, sleep::WakeFromLpCoreWakeupSource},
main, main,
}; };
use esp_println::{print, println}; use esp_println::{print, println};
@ -28,12 +29,14 @@ fn main() -> ! {
let peripherals = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
// configure GPIO 1 as LP output pin // configure GPIO 1 as LP output pin
let lp_pin = LowPowerOutput::new(peripherals.GPIO1); let lp_pin = LowPowerOutput::new(peripherals.GPIO1);
let mut rtc = Rtc::new(peripherals.LPWR);
let reason = WakeFromLpCoreWakeupSource::default();
let mut lp_core = LpCore::new(peripherals.LP_CORE); let mut lp_core = LpCore::new(peripherals.LP_CORE);
lp_core.stop(); lp_core.stop();
println!("lp core stopped"); println!("lp-core -> stop");
// load code to LP core // load code to LP core
let lp_core_code = let lp_core_code =
@ -41,12 +44,19 @@ fn main() -> ! {
// start LP core // start LP core
lp_core_code.run(&mut lp_core, LpCoreWakeupSource::HpCpu, lp_pin); lp_core_code.run(&mut lp_core, LpCoreWakeupSource::HpCpu, lp_pin);
println!("lpcore run"); println!("lpcore -> run");
let mut last: u32 = 0;
let data = (0x5000_2000) as *mut u32; let data = (0x5000_2000) as *mut u32;
loop { loop {
print!("Current {:x} \u{000d}", unsafe { let read = unsafe {
data.read_volatile() data.read_volatile()
}); };
if last != read {
print!("Current {:x} \u{000d}", read);
last = read;
}
println!("hp-core -> deep sleep");
rtc.sleep_light(&[&reason]);
} }
} }