stop3 working properly well

This commit is contained in:
Filipriec
2025-12-09 16:02:09 +01:00
parent 55398e8459
commit 72a731abef
4 changed files with 79 additions and 3 deletions

View File

@@ -2,3 +2,4 @@
pub mod standby;
pub mod shutdown;
pub mod stop3;

View File

@@ -0,0 +1,39 @@
// src/sleep/stop3.rs
// #define PWR_STOPENTRY_WFI (0x01U) //*!< Wait For Interruption instruction to enter Stop mode */
// #define PWR_STOPENTRY_WFE (0x02U) //*!< Wait For Event instruction to enter Stop mode */
// #define PWR_STOPENTRY_WFE_NO_EVT_CLEAR (0x03U)
/// How to enter STOP3 mode
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StopEntry {
Wfi,
Wfe,
WfeNoEventClear,
}
impl From<StopEntry> for u8 {
fn from(value: StopEntry) -> Self {
match value {
StopEntry::Wfi => 0x01,
StopEntry::Wfe => 0x02,
StopEntry::WfeNoEventClear => 0x03,
}
}
}
pub fn enter_stop3(stop_entry: StopEntry) -> ! {
unsafe extern "C" {
fn HAL_PWREx_EnterSTOP3Mode(stop_entry: u8);
}
unsafe {
HAL_PWREx_EnterSTOP3Mode(stop_entry.into());
}
cortex_m::asm::udf(); //panic
}
// Example usage:
// enter_stop3(StopEntry::Wfi);
// enter_stop3(StopEntry::Wfe);
// enter_stop3(StopEntry::WfeNoEventClear);