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
05c5e405
Commit
05c5e405
authored
1 year ago
by
CNLohr
Browse files
Options
Downloads
Patches
Plain Diff
Update systick examples to reflect new sysclk usage.
parent
78121972
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/systick_irq/Makefile
+0
-2
0 additions, 2 deletions
examples/systick_irq/Makefile
examples/systick_irq/systick_irq.c
+19
-27
19 additions, 27 deletions
examples/systick_irq/systick_irq.c
with
19 additions
and
29 deletions
examples/systick_irq/Makefile
+
0
−
2
View file @
05c5e405
...
...
@@ -2,8 +2,6 @@ all : flash
TARGET
:=
systick_irq
CFLAGS
+=
-DSTDOUT_UART
include
../../ch32v003fun/ch32v003fun.mk
flash
:
cv_flash
...
...
This diff is collapsed.
Click to expand it.
examples/systick_irq/systick_irq.c
+
19
−
27
View file @
05c5e405
/*
* Example for using SysTick with IRQs
* 03-25-2023 E. Brombaugh
* 05-12-2023 C. Lohr (Modified to reflect updated sysclk)
*/
// Could be defined here, or in the processor defines.
#define SYSTEM_CORE_CLOCK 48000000
#define SYSTICK_USE_HCLK
#define APB_CLOCK SYSTEM_CORE_CLOCK
#include
"ch32v003fun.h"
...
...
@@ -31,9 +33,6 @@ void systick_init(void)
/* enable the SysTick IRQ */
NVIC_EnableIRQ
(
SysTicK_IRQn
);
/* Clear any existing IRQ */
SysTick
->
SR
&=
~
SYSTICK_SR_CNTIF
;
/* Set the tick interval to 1ms for normal op */
SysTick
->
CMP
=
(
SYSTEM_CORE_CLOCK
/
1000
)
-
1
;
...
...
@@ -41,9 +40,9 @@ void systick_init(void)
SysTick
->
CNT
=
0
;
systick_cnt
=
0
;
/* Enable SysTick counter, IRQ, HCLK/1
, auto reload
*/
SysTick
->
CTLR
=
SYSTICK_CTLR_STE
|
SYSTICK_CTLR_STIE
|
SYSTICK_CTLR_STCLK
|
SYSTICK_CTLR_STRE
;
/* Enable SysTick counter, IRQ, HCLK/1 */
SysTick
->
CTLR
=
SYSTICK_CTLR_STE
|
SYSTICK_CTLR_STIE
|
SYSTICK_CTLR_STCLK
;
}
/*
...
...
@@ -53,25 +52,19 @@ void systick_init(void)
void
SysTick_Handler
(
void
)
__attribute__
((
interrupt
));
void
SysTick_Handler
(
void
)
{
// move the compare further ahead in time.
// as a warning, if more than this length of time
// passes before triggering, you may miss your
// interrupt.
SysTick
->
CMP
+=
(
SYSTEM_CORE_CLOCK
/
1000
);
/* clear IRQ */
SysTick
->
SR
&
=
0
;
SysTick
->
SR
=
0
;
/* update counter */
systick_cnt
++
;
}
/*
* Millisecond delay routine
*/
void
systick_delay_ms
(
uint32_t
milliseconds
)
{
/* compute end time */
uint32_t
etime
=
systick_cnt
+
milliseconds
;
/* wait for current time == end time */
while
(
systick_cnt
!=
etime
);
}
/*
* entry
*/
...
...
@@ -81,8 +74,7 @@ int main()
SystemInit48HSI
();
// start serial @ default 115200bps
SetupUART
(
UART_BRR
);
SetupDebugPrintf
();
printf
(
"
\r\r\n\n
systick_irq example
\n\r
"
);
// init systick @ 1ms rate
...
...
@@ -109,13 +101,13 @@ int main()
while
(
1
)
{
GPIOD
->
BSHR
=
1
|
(
1
<<
4
);
// Turn on GPIOs
systick_d
elay_
m
s
(
250
);
D
elay_
M
s
(
250
);
GPIOC
->
BSHR
=
1
;
systick_d
elay_
m
s
(
250
);
D
elay_
M
s
(
250
);
GPIOD
->
BSHR
=
(
1
<<
16
)
|
(
1
<<
(
16
+
4
));
// Turn off GPIODs
systick_d
elay_
m
s
(
250
);
D
elay_
M
s
(
250
);
GPIOC
->
BSHR
=
(
1
<<
16
);
systick_d
elay_
m
s
(
250
);
printf
(
"Count: %lu
\n\r
"
,
count
++
);
D
elay_
M
s
(
250
);
printf
(
"Count:
%lu / Milliseconds:
%lu
\n\r
"
,
count
++
,
systick_cnt
);
}
}
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