Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
ch32v003fun
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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Andreas Horn
ch32v003fun
Commits
de1cdace
Commit
de1cdace
authored
1 year ago
by
recallmenot
Browse files
Options
Downloads
Patches
Plain Diff
standby + auto-wakeup example
parent
435aff8a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/standby/Makefile
+11
-0
11 additions, 0 deletions
examples/standby/Makefile
examples/standby/README.md
+19
-0
19 additions, 0 deletions
examples/standby/README.md
examples/standby/standby.c
+71
-0
71 additions, 0 deletions
examples/standby/standby.c
with
101 additions
and
0 deletions
examples/standby/Makefile
0 → 100644
+
11
−
0
View file @
de1cdace
all
:
flash
TARGET
:=
standby
CFLAGS
+=
-DSTDOUT_UART
include
../../ch32v003fun/ch32v003fun.mk
flash
:
cv_flash
clean
:
cv_clean
This diff is collapsed.
Click to expand it.
examples/standby/README.md
0 → 100644
+
19
−
0
View file @
de1cdace
# the deepest slumber
This example serves to show how to put the CH32V003 into its lowest power state (standby) and have it wake periodically.
Power consumption should be around 10uA.
The MCU only toggles the LED and prints a message, then it goes to sleep.
The LED staying on demonstrates that GPIO keeps its state even when the rest of the mcu is in a coma.
Based on the groundwork of Marek M.
## time calculations
The autowakeup delay can be calculated by:
`t = AWUWR / (fLSI / AWUPSC)`
Where AWUWR can be 1 to 63, fLSI is always 128000 and AWUPSC, for practical purposes is 2048, 4096, 10240 or 61440, though lower values are possible.
The maximum autowakeup delay is 30s.
This diff is collapsed.
Click to expand it.
examples/standby/standby.c
0 → 100644
+
71
−
0
View file @
de1cdace
// based on https://paste.sr.ht/blob/b9b4fb45cbc70f2db7e31a77a6ef7dd2a7f220fb
// Could be defined here, or in the processor defines.
#define SYSTEM_CORE_CLOCK 48000000
#include
"../../ch32v003fun/ch32v003fun.h"
#include
<stdio.h>
#define APB_CLOCK SYSTEM_CORE_CLOCK
/* somehow this ISR won't get called??
void AWU_IRQHandler( void ) __attribute__((interrupt));
void AWU_IRQHandler( void ) {
GPIOD->OUTDR ^= (1 << 4);
}
*/
int
main
()
{
SystemInit48HSI
();
SetupUART
(
UART_BRR
);
printf
(
"
\r\n\r\n
low power example
\r\n\r\n
"
);
RCC
->
APB2PCENR
|=
RCC_APB2Periph_GPIOD
;
// GPIO D4 Push-Pull
GPIOD
->
CFGLR
&=
~
(
0xf
<<
(
4
*
4
));
GPIOD
->
CFGLR
|=
(
GPIO_Speed_10MHz
|
GPIO_CNF_OUT_PP
)
<<
(
4
*
4
);
GPIOD
->
OUTDR
|=
(
1
<<
4
);
// give the user time to open the terminal connection
//Delay_Ms(5000);
printf
(
"5000ms wait over
\r\n
"
);
// enable power interface module clock
RCC
->
APB1PCENR
|=
RCC_APB1Periph_PWR
;
// enable low speed oscillator (LSI)
RCC
->
RSTSCKR
|=
RCC_LSION
;
while
((
RCC
->
RSTSCKR
&
RCC_LSIRDY
)
==
0
)
{}
// enable AutoWakeUp event
EXTI
->
EVENR
|=
EXTI_Line9
;
EXTI
->
FTENR
|=
EXTI_Line9
;
// configure AWU prescaler
PWR
->
AWUPSC
|=
PWR_AWU_Prescaler_4096
;
// configure AWU window comparison value
PWR
->
AWUWR
&=
~
0x3f
;
PWR
->
AWUWR
|=
63
;
// enable AWU
PWR
->
AWUCSR
|=
(
1
<<
1
);
// select standby on power-down
PWR
->
CTLR
|=
PWR_CTLR_PDDS
;
// peripheral interrupt controller send to deep sleep
PFIC
->
SCTLR
|=
(
1
<<
2
);
uint16_t
counter
=
0
;
printf
(
"entering sleep loop
\r\n
"
);
for
(;;)
{
__WFE
();
// restore clock to full speed
SystemInit48HSI
();
printf
(
"
\r\n
awake, %u
\r\n
"
,
counter
++
);
GPIOD
->
OUTDR
^=
(
1
<<
4
);
}
}
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