Commit 16d62134 authored by Per's avatar Per

0.036mA

parent 809b11df
......@@ -18,6 +18,34 @@ use rt::ExceptionFrame;
use cortex_m::peripheral::Peripherals;
fn analog_input() {
#[allow(non_snake_case)]
let GPIOC = unsafe { &*stm32f40x::GPIOC::ptr() };
#[allow(non_snake_case)]
let GPIOD = unsafe { &*stm32f40x::GPIOD::ptr() };
#[allow(non_snake_case)]
let GPIOE = unsafe { &*stm32f40x::GPIOE::ptr() };
// #[allow(non_snake_case)]
// let GPIOF = unsafe { &*stm32f40x::GPIOF::ptr() };
// #[allow(non_snake_case)]
// let GPIOG = unsafe { &*stm32f40x::GPIOG::ptr() };
// #[allow(non_snake_case)]
// let GPIOH = unsafe { &*stm32f40x::GPIOH::ptr() };
// #[allow(non_snake_case)]
// let GPIOI = unsafe { &*stm32f40x::GPIOI::ptr() };
let r1 = GPIOC.moder.read().bits();
GPIOC.moder.write(|w| unsafe { w.bits(0xFFFF_FFFF) }); // analog mode
GPIOD.moder.write(|w| unsafe { w.bits(0xFFFF_FFFF) }); // analog mode
GPIOE.moder.write(|w| unsafe { w.bits(0xFFFF_FFFF) }); // analog mode
// GPIOF.moder.write(|w| unsafe { w.bits(0xFFFF_FFFF) }); // analog mode
// GPIOG.moder.write(|w| unsafe { w.bits(0xFFFF_FFFF) }); // analog mode
// GPIOH.moder.write(|w| unsafe { w.bits(0xFFFF_FFFF) }); // analog mode
// GPIOI.moder.write(|w| unsafe { w.bits(0xFFFF_FFFF) }); // analog mode
let r2 = GPIOC.moder.read().bits();
// asm::bkpt();
}
// set the MCU in debug sleepdeep mode on WFI/WFE
// debugging is possible even if sleeping
fn dbg_enable() {
......@@ -36,14 +64,16 @@ fn dbg_enable() {
.trace_ioen()
.set_bit()
});
// GPIOB.moder.reset();
// GPIOA.moder.reset();
// GPIOB.pupdr.reset();
// GPIOA.pupdr.reset();
GPIOA.moder.reset();
GPIOA.pupdr.reset();
GPIOB.moder.reset();
GPIOB.pupdr.reset();
}
// set the MCU in true sleepdeep mode on WFI/WFE
// debugging is disabled (until re-enabled)
fn dbg_disable() {
#[allow(non_snake_case)]
let DBG = unsafe { &*stm32f40x::DBG::ptr() };
......@@ -67,10 +97,17 @@ fn dbg_disable() {
// let _b_moder_ = GPIOB.moder.read().bits();
// let _a_pupdr_ = GPIOA.pupdr.read().bits();
// let _b_pupdr_ = GPIOB.pupdr.read().bits();
// GPIOB.moder.write(|w| unsafe { w.bits(0) });
// GPIOA.moder.write(|w| unsafe { w.bits(0) });
// GPIOB.pupdr.write(|w| unsafe { w.bits(0) });
// GPIOA.pupdr.write(|w| unsafe { w.bits(0) });
// 0.142 mA without manipulating GPIO/GPIOB
GPIOA.moder.write(|w| unsafe { w.bits(0xFFFF_FFFF) }); // PA, analog
GPIOA.moder.modify(|_, w| w.moder1().input_mode()); // PA1, input_mode
GPIOB.pupdr.write(|w| unsafe { w.bits(0) }); // PA, floating
GPIOA.pupdr.modify(|_, w| w.pupdr1().pull_up()); // PA1, pull up
GPIOB.moder.write(|w| unsafe { w.bits(0xFFFF_FFFF) }); // PB, analog
GPIOB.pupdr.write(|w| unsafe { w.bits(0) }); // PB, floating
// let _a_moder = GPIOA.moder.read().bits();
// let _b_moder = GPIOB.moder.read().bits();
// let _a_pupdr = GPIOA.pupdr.read().bits();
......@@ -87,28 +124,43 @@ fn main() -> ! {
// enable the EXTI1 interrupt
p.NVIC.enable(Interrupt::EXTI1);
// enable gpioa (input mode on reset)
r.RCC
.ahb1enr
.modify(|_, w| w.gpioaen().set_bit().gpioben().set_bit());
// enable gpioa, gpiob
r.RCC.ahb1enr.modify(|_, w| {
w.gpioaen()
.set_bit()
.gpioben()
.set_bit()
.gpiocen()
.set_bit()
.gpioden()
.set_bit()
.gpioeen()
.set_bit()
.gpiofen()
.set_bit()
});
// asm::bkpt();
analog_input();
// asm::bkpt();
let mut read: u32 = 0;
r.GPIOA.pupdr.modify(|r, w| {
read = r.bits();
w.pupdr1().pull_up()
});
// PA1 pull up
r.GPIOA.pupdr.modify(|r, w| w.pupdr1().pull_up());
#[allow(non_snake_case)]
let GPIOA = unsafe { &*stm32f40x::GPIOA::ptr() };
asm::nop();
// SYSCFG.exti1 is PAx (0000) by reset
// SYSCFG.exti1 is PAx (0000) by reset, so we don't change it
// enbable masking of EXTI line 1
r.EXTI.imr.modify(|_, w| w.mr1().set_bit());
// trigger on falling edge
r.EXTI.ftsr.modify(|_, w| w.tr1().set_bit());
// clear triggering event
r.EXTI.pr.modify(|_, w| w.pr1().set_bit());
asm::bkpt();
p.SCB.set_sleepdeep();
// enable pwr
r.RCC.apb1enr.modify(|_, w| w.pwren().set_bit());
......@@ -123,10 +175,11 @@ fn main() -> ! {
// r.PWR
// .cr
// .modify(|_, w| w.pdds().clear_bit().lpds().clear_bit());
blink();
// blink();
// p.NVIC.set_pending(Interrupt::EXTI1);
asm::bkpt();
loop {
asm::nop(); // put gdb breakpoint here, the MCU and gdb will detect breakpoint
dbg_disable();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment