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