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
515cede0
Commit
515cede0
authored
1 year ago
by
Jannis Konrad
Browse files
Options
Downloads
Patches
Plain Diff
expand and cleanup example
parent
10a33cb3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/struct_gpio/struct_gpio.c
+22
-12
22 additions, 12 deletions
examples/struct_gpio/struct_gpio.c
with
22 additions
and
12 deletions
examples/struct_gpio/struct_gpio.c
+
22
−
12
View file @
515cede0
...
...
@@ -17,7 +17,12 @@ int main()
// Enable GPIOs
RCC
->
APB2PCENR
|=
RCC_APB2Periph_GPIOD
|
RCC_APB2Periph_GPIOC
;
// GPIO D0, D4 Push-Pull
Delay_Ms
(
100
);
// all floating inputs before
printf
(
"CFGLR: %lX
\n
"
,
GPIOD
->
CFGLR
);
// -> CFGLR: 44444444
// GPIO D0, D4 Push-Pull, D1/SWIO floating, default analog input
GPIOD
->
CFGLR_bits
=
(
struct
CFGLR_t
)
{
.
MODE0
=
GPIO_CFGLR_MODE_OUT_10MHz
,
.
CNF0
=
GPIO_CFGLR_CNF_OUT_PP
,
...
...
@@ -27,31 +32,36 @@ int main()
.
CNF4
=
GPIO_CFGLR_CNF_OUT_PP
,
};
// GPIO C0 Push-Pull
GPIOC
->
CFGLR_bits
=
(
struct
CFGLR_t
)
{
.
MODE0
=
GPIO_CFGLR_MODE_OUT_10MHz
,
.
CNF0
=
GPIO_CFGLR_CNF_OUT_PP
,
};
// all unconfigured pins are not 0b0000, aka analog inputs with TTL Schmitttrigger disabled
printf
(
"CFGLR: %lX
\n
"
,
GPIOD
->
CFGLR
);
// -> CFGLR: 10041
// GPIO C0 Push-Pull with 2 volatile writes
GPIOC
->
CFGLR_bits
.
MODE0
=
GPIO_CFGLR_MODE_OUT_10MHz
;
GPIOC
->
CFGLR_bits
.
CNF0
=
GPIO_CFGLR_CNF_OUT_PP
;
// read modify write
struct
CFGLR_t
ioc
=
GPIOC
->
CFGLR_bits
;
ioc
.
MODE1
=
GPIO_CFGLR_MODE_IN
;
// not volatile
ioc
.
CNF1
=
GPIO_CNF_IN_ANALOG
;
// not volatile
GPIOC
->
CFGLR_bits
=
ioc
;
// this should be one volatile write
while
(
1
)
{
// Turn
on GPIOs, set in BSHR
// Turn
D0 on and D4 off at the same time
GPIOD
->
BSHR_bits
=
(
struct
BSHR_t
)
{
.
BS0
=
1
,
.
B
S
4
=
1
,
.
B
R
4
=
1
,
};
GPIOC
->
BSHR_bits
.
BS0
=
1
;
printf
(
"+%lu
\n
"
,
count
++
);
Delay_Ms
(
100
);
// Turn off
GPIODs, clear in BSHR
// Turn
D0
off
and D4 on at the same time
GPIOD
->
BSHR_bits
=
(
struct
BSHR_t
)
{
.
BR0
=
1
,
.
B
R
4
=
1
,
.
B
S
4
=
1
,
};
// or clear in BCR
GPIOC
->
BCR_bits
.
BR0
=
1
;
printf
(
"-%lu
\n
"
,
count
++
);
Delay_Ms
(
100
);
}
}
...
...
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