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
70ba010f
Commit
70ba010f
authored
1 year ago
by
Jannis Konrad
Browse files
Options
Downloads
Patches
Plain Diff
struct_direct_gpio for comparison
parent
200c4df9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/struct_direct_gpio/Makefile
+9
-0
9 additions, 0 deletions
examples/struct_direct_gpio/Makefile
examples/struct_direct_gpio/struct_direct_gpio.c
+65
-0
65 additions, 0 deletions
examples/struct_direct_gpio/struct_direct_gpio.c
with
74 additions
and
0 deletions
examples/struct_direct_gpio/Makefile
0 → 100644
+
9
−
0
View file @
70ba010f
all
:
flash
TARGET
:=
struct_direct_gpio
include
../../ch32v003fun/ch32v003fun.mk
flash
:
cv_flash
clean
:
cv_clean
This diff is collapsed.
Click to expand it.
examples/struct_direct_gpio/struct_direct_gpio.c
0 → 100644
+
65
−
0
View file @
70ba010f
// This tries to do exactly the same as direct_gpio but with structs
// Could be defined here, or in the processor defines.
#define SYSTEM_CORE_CLOCK 48000000
#include
"ch32v003fun.h"
#include
<stdio.h>
#define APB_CLOCK SYSTEM_CORE_CLOCK
uint32_t
count
;
int
main
()
{
SystemInit48HSI
();
// Enable GPIOs
RCC
->
APB2PCENR
|=
RCC_APB2Periph_GPIOC
;
// GPIO D0, D4 Push-Pull, D1/SWIO floating, default analog input
GPIOC
->
CFGLR_bits
=
(
const
struct
CFGLR_t
)
{
// GPIO C1 Push-Pull
.
MODE1
=
GPIO_CFGLR_MODE_OUT_10MHz
,
.
CNF1
=
GPIO_CFGLR_CNF_OUT_PP
,
// GPIO C2 Push-Pull
.
MODE2
=
GPIO_CFGLR_MODE_OUT_10MHz
,
.
CNF2
=
GPIO_CFGLR_CNF_OUT_PP
,
// GPIO C4 Push-Pull
.
MODE4
=
GPIO_CFGLR_MODE_OUT_10MHz
,
.
CNF4
=
GPIO_CFGLR_CNF_OUT_PP
,
};
while
(
1
)
{
// Use low bits of BSHR to SET output
GPIOC
->
BSHR_bits
=
(
const
struct
BSHR_t
)
{
.
BS1
=
1
,
};
GPIOC
->
BSHR_bits
=
(
const
struct
BSHR_t
)
{
.
BS2
=
1
,
};
// Modify the OUTDR register directly to SET output
GPIOC
->
OUTDR_bits
.
ODR4
=
1
;
Delay_Ms
(
950
);
// Use upper bits of BSHR to RESET output
GPIOC
->
BSHR_bits
=
(
const
struct
BSHR_t
)
{
.
BR1
=
1
,
};
// Use BCR to RESET output
GPIOC
->
BCR_bits
=
(
const
struct
BCR_t
)
{
.
BR2
=
1
,
};
// Modify the OUTDR register directly to CLEAR output
GPIOC
->
OUTDR_bits
.
ODR4
=
0
;
Delay_Ms
(
50
);
count
++
;
}
}
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