diff --git a/.vscode/launch.json b/.vscode/launch.json index c47ee0726c74eab0ac5e52df74a343c2d42c5267..294073f9d79def05bd65af060231b456d5e1c897 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -82,6 +82,31 @@ }, "cwd": "${workspaceRoot}" }, + { + "type": "cortex-debug", + "request": "launch", + "servertype": "openocd", + "name": "standby (release)", + "executable": "./target/thumbv7em-none-eabihf/release/examples/standby", + "configFiles": [ + "interface/stlink.cfg", + "target/stm32f4x.cfg" + ], + "swoConfig": { + "enabled": true, + "cpuFrequency": 8000000, + "swoFrequency": 2000000, // you may try 1000000 if not working + "source": "probe", + "decoders": [ + { + "type": "console", + "label": "Name", + "port": 0 + } + ] + }, + "cwd": "${workspaceRoot}" + }, { "type": "cortex-debug", "request": "launch", diff --git a/examples/standby.rs b/examples/standby.rs index fac69fa2479a60c6f59244b0f2dfcbe269be5c88..b15f67670eaf6d6ebba298ab5898b34b10809ced 100644 --- a/examples/standby.rs +++ b/examples/standby.rs @@ -34,16 +34,54 @@ extern crate stm32f40x; extern crate cortex_m_rt as rt; // makes `panic!` print messages to the host stderr using semihosting -extern crate panic_semihosting; - +// extern crate panic_semihosting; +extern crate panic_abort; use cortex_m::asm; use rt::ExceptionFrame; +use cortex_m::peripheral::{Peripherals, SCB}; +use stm32f40x::DBG; + // the program entry point is ... entry!(main); // ... this never ending function fn main() -> ! { + // let scb = p.core.SCB; + asm::bkpt(); + + let mut p = Peripherals::take().unwrap(); + p.SCB.set_sleepdeep(); + + let mut r = stm32f40x::Peripherals::take().unwrap(); + + let v = r.DBG.dbgmcu_cr.read(); + r.DBG.dbgmcu_cr.modify(|_, w| { + w.dbg_sleep() + .clear_bit() + .dbg_stop() + .clear_bit() + .dbg_standby() + .clear_bit() + }); + + let v1 = r.DBG.dbgmcu_cr.read(); + asm::bkpt(); + + // enable pwr + r.RCC.apb1enr.modify(|_, w| w.pwren().set_bit()); + + // standby mode + r.PWR + .cr + .modify(|_, w| w.pdds().set_bit().cwuf().clear_bit()); + // // pwr.cr.modify(|_, w| w.lpds().clear_bit()); // regulator in normal mode + // pwr.cr.modify(|_, w| w.lpds().set_bit()); // regulator in low power mode + // exti.pr.write(|w| unsafe { w.bits(0) }); // clear pending register + // pwr.csr.modify(|_, w| w.ewup().set_bit()); // clear pending wake up + + asm::bkpt(); + loop { asm::wfi(); asm::bkpt();