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
d20c0a23
Commit
d20c0a23
authored
1 year ago
by
Jannis Konrad
Browse files
Options
Downloads
Patches
Plain Diff
gpio struct with example
parent
ab3581a2
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
ch32v003fun/ch32v003fun.h
+118
-6
118 additions, 6 deletions
ch32v003fun/ch32v003fun.h
examples/struct_gpio/Makefile
+9
-0
9 additions, 0 deletions
examples/struct_gpio/Makefile
examples/struct_gpio/debugprintfdemo.c
+59
-0
59 additions, 0 deletions
examples/struct_gpio/debugprintfdemo.c
with
186 additions
and
6 deletions
ch32v003fun/ch32v003fun.h
+
118
−
6
View file @
d20c0a23
...
...
@@ -196,15 +196,127 @@ typedef struct
}
OB_TypeDef
;
/* General Purpose I/O */
typedef
enum
{
GPIO_CFGLR_MODE_IN
,
GPIO_CFGLR_MODE_OUT_10MHz
,
GPIO_CFGLR_MODE_OUT_2MHz
,
GPIO_CFGLR_MODE_OUT_50MHz
}
GPIO_MODE_TypeDef
;
typedef
enum
{
GPIO_CFGLR_CNF_IN_ANALOG
=
0
,
GPIO_CFGLR_CNF_IN_FLOAT
=
1
,
GPIO_CFGLR_CNF_IN_PULL_UP_DOWN
=
2
,
GPIO_CFGLR_CNF_OUT_PP
=
0
,
GPIO_CFGLR_CNF_OUT_OD
=
1
,
GPIO_CFGLR_CNF_OUT_AF_PP
=
2
,
GPIO_CFGLR_CNF_OUT_AF_OD
=
3
,
}
GPIO_CNF_TypeDef
;
typedef
struct
{
__IO
uint32_t
CFGLR
;
__IO
union
{
uint32_t
CFGLR
;
struct
CFGLR_t
{
GPIO_MODE_TypeDef
MODE0
:
2
;
GPIO_CNF_TypeDef
CNF0
:
2
;
GPIO_MODE_TypeDef
MODE1
:
2
;
GPIO_CNF_TypeDef
CNF1
:
2
;
GPIO_MODE_TypeDef
MODE2
:
2
;
GPIO_CNF_TypeDef
CNF2
:
2
;
GPIO_MODE_TypeDef
MODE3
:
2
;
GPIO_CNF_TypeDef
CNF3
:
2
;
GPIO_MODE_TypeDef
MODE4
:
2
;
GPIO_CNF_TypeDef
CNF4
:
2
;
GPIO_MODE_TypeDef
MODE5
:
2
;
GPIO_CNF_TypeDef
CNF5
:
2
;
GPIO_MODE_TypeDef
MODE6
:
2
;
GPIO_CNF_TypeDef
CNF6
:
2
;
GPIO_MODE_TypeDef
MODE7
:
2
;
GPIO_CNF_TypeDef
CNF7
:
2
;
}
CFGLR_bits
;
};
__IO
uint32_t
CFGHR
;
__IO
uint32_t
INDR
;
__IO
uint32_t
OUTDR
;
__IO
uint32_t
BSHR
;
__IO
uint32_t
BCR
;
__IO
uint32_t
LCKR
;
__IO
union
{
uint32_t
INDR
;
struct
INDR_t
{
uint32_t
IDR0
:
1
;
uint32_t
IDR1
:
1
;
uint32_t
IDR2
:
1
;
uint32_t
IDR3
:
1
;
uint32_t
IDR4
:
1
;
uint32_t
IDR5
:
1
;
uint32_t
IDR6
:
1
;
uint32_t
IDR7
:
1
;
uint32_t
:
24
;
}
INDR_bits
;
};
__IO
union
{
uint32_t
OUTDR
;
struct
OUTDR_t
{
uint32_t
ODR0
:
1
;
uint32_t
ODR1
:
1
;
uint32_t
ODR2
:
1
;
uint32_t
ODR3
:
1
;
uint32_t
ODR4
:
1
;
uint32_t
ODR5
:
1
;
uint32_t
ODR6
:
1
;
uint32_t
ODR7
:
1
;
uint32_t
:
24
;
}
OUTDR_bits
;
};
__IO
union
{
uint32_t
BSHR
;
struct
BSHR_t
{
uint32_t
BS0
:
1
;
uint32_t
BS1
:
1
;
uint32_t
BS2
:
1
;
uint32_t
BS3
:
1
;
uint32_t
BS4
:
1
;
uint32_t
BS5
:
1
;
uint32_t
BS6
:
1
;
uint32_t
BS7
:
1
;
uint32_t
:
8
;
uint32_t
BR0
:
1
;
uint32_t
BR1
:
1
;
uint32_t
BR2
:
1
;
uint32_t
BR3
:
1
;
uint32_t
BR4
:
1
;
uint32_t
BR5
:
1
;
uint32_t
BR6
:
1
;
uint32_t
BR7
:
1
;
uint32_t
:
8
;
}
BSHR_bits
;
};
__IO
union
{
uint32_t
BCR
;
struct
BCR_t
{
uint32_t
BR0
:
1
;
uint32_t
BR1
:
1
;
uint32_t
BR2
:
1
;
uint32_t
BR3
:
1
;
uint32_t
BR4
:
1
;
uint32_t
BR5
:
1
;
uint32_t
BR6
:
1
;
uint32_t
BR7
:
1
;
uint32_t
:
24
;
}
BCR_bits
;
};
__IO
union
{
uint32_t
LCKR
;
struct
LCKR_t
{
uint32_t
LCK0
:
1
;
uint32_t
LCK1
:
1
;
uint32_t
LCK2
:
1
;
uint32_t
LCK3
:
1
;
uint32_t
LCK4
:
1
;
uint32_t
LCK5
:
1
;
uint32_t
LCK6
:
1
;
uint32_t
LCK7
:
1
;
uint32_t
LCKK
:
1
;
uint32_t
:
23
;
}
LCK_bits
;
};
}
GPIO_TypeDef
;
/* Alternate Function I/O */
...
...
This diff is collapsed.
Click to expand it.
examples/struct_gpio/Makefile
0 → 100644
+
9
−
0
View file @
d20c0a23
all
:
flash
TARGET
:=
debugprintfdemo
include
../../ch32v003fun/ch32v003fun.mk
flash
:
cv_flash
clean
:
cv_clean
This diff is collapsed.
Click to expand it.
examples/struct_gpio/debugprintfdemo.c
0 → 100644
+
59
−
0
View file @
d20c0a23
/* Small example showing how to use the SWIO programming pin to
do printf through the debug interface */
#define SYSTEM_CORE_CLOCK 48000000
#include
"ch32v003fun.h"
#include
<stdio.h>
#define APB_CLOCK SYSTEM_CORE_CLOCK
uint32_t
count
;
int
main
()
{
SystemInit48HSI
();
SetupDebugPrintf
();
// Enable GPIOs
RCC
->
APB2PCENR
|=
RCC_APB2Periph_GPIOD
|
RCC_APB2Periph_GPIOC
;
// GPIO D0, D4 Push-Pull
GPIOD
->
CFGLR_bits
=
(
struct
CFGLR_t
)
{
.
MODE0
=
GPIO_CFGLR_MODE_OUT_10MHz
,
.
CNF0
=
GPIO_CFGLR_CNF_OUT_PP
,
.
MODE1
=
GPIO_CFGLR_MODE_IN
,
.
CNF1
=
GPIO_CFGLR_CNF_IN_FLOAT
,
.
MODE4
=
GPIO_CFGLR_MODE_OUT_10MHz
,
.
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
,
};
while
(
1
)
{
// Turn on GPIOs, set in BSHR
GPIOD
->
BSHR_bits
=
(
struct
BSHR_t
)
{
.
BS0
=
1
,
.
BS4
=
1
,
};
GPIOC
->
BSHR_bits
.
BS0
=
1
;
printf
(
"+%lu
\n
"
,
count
++
);
Delay_Ms
(
100
);
// Turn off GPIODs, clear in BSHR
GPIOD
->
BSHR_bits
=
(
struct
BSHR_t
)
{
.
BR0
=
1
,
.
BR4
=
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