improvements to semestralka 2
This commit is contained in:
@@ -20,7 +20,7 @@ use dma_gpio::config::{
|
||||
use dma_gpio::hw_uart_pc::{driver::uart_task, usart1};
|
||||
use dma_gpio::wakeup::iwdg::{clear_wakeup_flags, init_watchdog};
|
||||
use dma_gpio::sleep::shutdown::enter_shutdown;
|
||||
use dma_gpio::sleep::standby::enter_standby_with_sram2_retention;
|
||||
use dma_gpio::sleep::standby;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
@@ -70,7 +70,9 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
loop {
|
||||
info!("entering shutdown");
|
||||
enter_standby_with_sram2_retention();
|
||||
// enter_shutdown();
|
||||
info!("shutdown");
|
||||
standby::enter_standby_with_sram2_full();
|
||||
cortex_m::asm::wfi();
|
||||
yield_now().await;
|
||||
}
|
||||
|
||||
@@ -12,12 +12,17 @@ pub fn enter_standby() -> ! {
|
||||
cortex_m::asm::udf(); // never happen marker
|
||||
}
|
||||
|
||||
pub fn enter_standby_with_sram2_retention() -> ! {
|
||||
sram2_retention();
|
||||
pub fn enter_standby_with_sram2_8kb() -> ! {
|
||||
sram2_8kb_retention();
|
||||
enter_standby();
|
||||
}
|
||||
|
||||
pub fn sram2_retention() {
|
||||
pub fn enter_standby_with_sram2_full() -> ! {
|
||||
sram2_full_retention();
|
||||
enter_standby();
|
||||
}
|
||||
|
||||
pub fn sram2_full_retention() {
|
||||
unsafe extern "C" {
|
||||
fn HAL_PWREx_EnableSRAM2ContentStandbyRetention(sram2_pages: u32);
|
||||
}
|
||||
@@ -25,18 +30,29 @@ pub fn sram2_retention() {
|
||||
unsafe {
|
||||
// 0x60 = PWR_SRAM2_FULL_STANDBY = PWR_CR1_RRSB1 | PWR_CR1_RRSB2
|
||||
// See: STM32U5xx HAL: stm32u5xx_hal_pwr_ex.h line 227
|
||||
// CMSIS: PWR_CR1_RRSB1=0x20, PWR_CR1_RRSB2=0x40
|
||||
// PWR_CR1_RRSB1=0x20, PWR_CR1_RRSB2=0x40
|
||||
HAL_PWREx_EnableSRAM2ContentStandbyRetention(0x60);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disable_sram2_retention() {
|
||||
pub fn sram2_8kb_retention() {
|
||||
unsafe extern "C" {
|
||||
fn HAL_PWREx_EnableSRAM2ContentStandbyRetention(sram2_pages: u32);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
// 0x40 = PWR_SRAM2_PAGE1_STANDBY = PWR_CR1_RRSB2
|
||||
// 8KB retention only
|
||||
HAL_PWREx_EnableSRAM2ContentStandbyRetention(0x40);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disable_sram2_full_retention() {
|
||||
unsafe extern "C" {
|
||||
fn HAL_PWREx_DisableSRAM2ContentStandbyRetention(sram2_pages: u32);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
// Disable full SRAM2 retention
|
||||
HAL_PWREx_DisableSRAM2ContentStandbyRetention(0x60);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use embassy_stm32::wdg::IndependentWatchdog;
|
||||
use embassy_stm32::Peri;
|
||||
use embassy_time::{Duration, Timer};
|
||||
use embassy_stm32::pac;
|
||||
use crate::sleep::standby;
|
||||
|
||||
use crate::config::WATCHDOG_TIMEOUT_US;
|
||||
|
||||
@@ -20,6 +21,7 @@ use crate::config::WATCHDOG_TIMEOUT_US;
|
||||
/// - `PWR_SR` — Power Control / Status
|
||||
pub fn clear_wakeup_flags() {
|
||||
info!("Clearing wakeup flags...");
|
||||
standby::disable_sram2_full_retention();
|
||||
|
||||
// Clear reset flags
|
||||
// let rcc = unsafe { &*pac::RCC::ptr() };
|
||||
|
||||
Reference in New Issue
Block a user