stop0 working

This commit is contained in:
Priec
2025-12-14 11:56:09 +01:00
parent 58561ec392
commit 49cc8dcc71
5 changed files with 44 additions and 1 deletions

View File

@@ -37,6 +37,8 @@ fn main() {
build.file(hal_driver.join("Src").join(src)); build.file(hal_driver.join("Src").join(src));
} }
build.file("src/c_ll/stop0_ll.c");
build build
.include(hal_driver.join("Inc")) .include(hal_driver.join("Inc"))
.include(device.join("Include")) .include(device.join("Include"))

View File

@@ -0,0 +1,8 @@
#include "stm32u5xx_ll_pwr.h"
void rust_LL_PWR_SetPowerMode(unsigned int mode)
{
// Configure STOP0
LL_PWR_SetPowerMode(mode);
}

View File

@@ -40,6 +40,7 @@ pub struct StopModeConfig {
#[derive(Debug, Clone, Copy, PartialEq, Eq, defmt::Format)] #[derive(Debug, Clone, Copy, PartialEq, Eq, defmt::Format)]
pub enum StopMode { pub enum StopMode {
Stop0,
Stop1, Stop1,
Stop2, Stop2,
Stop3, Stop3,
@@ -80,17 +81,26 @@ pub async fn uart_cmd_task() {
b'3' => CMD_CH.send(LowPowerCmd::Standby).await, b'3' => CMD_CH.send(LowPowerCmd::Standby).await,
b'4' => CMD_CH.send(LowPowerCmd::Shutdown).await, b'4' => CMD_CH.send(LowPowerCmd::Shutdown).await,
b'5' => { b'5' => {
let _ = PIPE_HW_TX.write(b"Enter Stop mode number (1-3): ").await; let _ = PIPE_HW_TX.write(b"Enter Stop mode number (0-3): ").await;
b.fill(0); b.fill(0);
let n = PIPE_HW_RX.read(&mut b).await; let n = PIPE_HW_RX.read(&mut b).await;
if n == 0 { print_menu().await; continue; } if n == 0 { print_menu().await; continue; }
let stop_mode = match b[0] { let stop_mode = match b[0] {
b'0' => StopMode::Stop0,
b'1' => StopMode::Stop1, b'1' => StopMode::Stop1,
b'2' => StopMode::Stop2, b'2' => StopMode::Stop2,
b'3' => StopMode::Stop3, b'3' => StopMode::Stop3,
_ => { print_menu().await; continue; } _ => { print_menu().await; continue; }
}; };
if matches!(stop_mode, StopMode::Stop0) {
CMD_CH.send(LowPowerCmd::StopMode(StopModeConfig {
mode: stop_mode,
entry: StopEntry::Wfi, // to tu je, lebo nejdem prepisovat kod, kvoli
// posratemu halu co si nevie urobit konzistentnost
})).await;
continue;
}
let _ = PIPE_HW_TX.write(b"Enter entry method (1=WFI,2=WFE,3=WFE no clear): ").await; let _ = PIPE_HW_TX.write(b"Enter entry method (1=WFI,2=WFE,3=WFE no clear): ").await;
b.fill(0); b.fill(0);
let n = PIPE_HW_RX.read(&mut b).await; let n = PIPE_HW_RX.read(&mut b).await;

View File

@@ -49,6 +49,7 @@ pub async fn execute_low_power(
init_watchdog_reset(wdg).await; init_watchdog_reset(wdg).await;
} }
match mode { match mode {
StopMode::Stop0 => enter_stop0(),
StopMode::Stop1 => enter_stop1(entry), StopMode::Stop1 => enter_stop1(entry),
StopMode::Stop2 => enter_stop2(entry), StopMode::Stop2 => enter_stop2(entry),
StopMode::Stop3 => enter_stop3(entry), StopMode::Stop3 => enter_stop3(entry),

View File

@@ -1,5 +1,9 @@
// src/sleep/stop.rs // src/sleep/stop.rs
use cortex_m::peripheral::SCB;
use cortex_m::Peripherals;
use cortex_m::asm;
/// How to enter STOPx mode (STOP0STOP3) /// How to enter STOPx mode (STOP0STOP3)
#[derive(Debug, Clone, Copy, PartialEq, Eq, defmt::Format)] #[derive(Debug, Clone, Copy, PartialEq, Eq, defmt::Format)]
pub enum StopEntry { pub enum StopEntry {
@@ -18,6 +22,24 @@ impl From<StopEntry> for u8 {
} }
} }
pub fn enter_stop0() -> ! {
unsafe extern "C" {
fn rust_LL_PWR_SetPowerMode(mode: u32);
}
const LL_PWR_STOP0_MODE: u32 = 0; //stm32u5xx_ll_pwr.h
unsafe {
rust_LL_PWR_SetPowerMode(LL_PWR_STOP0_MODE);
let mut core = Peripherals::steal();
core.SCB.set_sleepdeep();
asm::wfi();
}
cortex_m::asm::udf();
}
pub fn enter_stop1(entry: StopEntry) -> ! { pub fn enter_stop1(entry: StopEntry) -> ! {
unsafe extern "C" { unsafe extern "C" {
fn HAL_PWREx_EnterSTOP1Mode(entry: u8); fn HAL_PWREx_EnterSTOP1Mode(entry: u8);