Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
low-power-stm32f103c8
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Per Lindgren
low-power-stm32f103c8
Commits
16d62134
Commit
16d62134
authored
6 years ago
by
Per
Browse files
Options
Downloads
Patches
Plain Diff
0.036mA
parent
809b11df
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/sleep_stop.rs
+72
-19
72 additions, 19 deletions
examples/sleep_stop.rs
with
72 additions
and
19 deletions
examples/sleep_stop.rs
+
72
−
19
View file @
16d62134
...
...
@@ -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
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment