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
f63b60ab
Commit
f63b60ab
authored
2 years ago
by
cnlohr
Browse files
Options
Downloads
Patches
Plain Diff
Add extra noe to self-modify code bit. And also playing with OC'ing on sandbox.
parent
5d6783a9
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/sandbox/Makefile
+6
-3
6 additions, 3 deletions
examples/sandbox/Makefile
examples/sandbox/sandbox.c
+35
-34
35 additions, 34 deletions
examples/sandbox/sandbox.c
examples/self_modify_code/self_modify_code.c
+4
-2
4 additions, 2 deletions
examples/self_modify_code/self_modify_code.c
with
45 additions
and
39 deletions
examples/sandbox/Makefile
+
6
−
3
View file @
f63b60ab
...
...
@@ -6,7 +6,7 @@ PREFIX:=riscv64-unknown-elf
GPIO_Toggle
:=
EXAM/GPIO/GPIO_Toggle/User
CH32V003FUN
:=
../../ch32v003
CH32V003FUN
CH32V003FUN
:=
../../ch32v003
fun
MINICHLINK
:=
../../minichlink
CFLAGS
:=
\
...
...
@@ -35,8 +35,11 @@ $(TARGET).bin : $(TARGET).elf
flash
:
$(TARGET).bin
make
-C
$(
MINICHLINK
)
all
$(
MINICHLINK
)
/minichlink
-w
$<
-r
$(
MINICHLINK
)
/minichlink
-w
$<
flash
-b
monitor
:
flash
$(
MINICHLINK
)
/minichlink
-T
clean
:
rm
-rf
$(
TARGET
)
.elf
$(
TARGET
)
.bin
$(
TARGET
)
.hex
$(
TARGET
)
.lst
$(
TARGET
)
.map
$(
TARGET
)
.hex
This diff is collapsed.
Click to expand it.
examples/sandbox/sandbox.c
+
35
−
34
View file @
f63b60ab
// Could be defined here, or in the processor defines.
#define SYSTEM_CORE_CLOCK 48000000
#define APB_CLOCK SYSTEM_CORE_CLOCK
/* Small example showing how to use the SWIO programming pin to
do printf through the debug interface */
#include
"ch32v00
x
.h"
#include
"ch32v00
3fun
.h"
#include
<stdio.h>
#include
<string.h>
// Working on WS2812 driving.
uint32_t
count
;
// Tell the compiler to put this code in the .data section. That
// will cause the startup code to copy it from flash into RAM where
// it can be easily modified at runtime.
void
SRAMCode
(
)
__attribute__
((
section
(
".data"
)))
__attribute__
((
noinline
))
__attribute__
((
noreturn
));
void
SRAMCode
(
)
{
asm
volatile
(
"li a0, 0x40011410
\n
"
"li a1, (1 | (1<<4))
\n
"
"li a2, (1 | (1<<4))<<16
\n
"
"1: c.sw a1, 0(a0)
\n
"
" c.sw a2, 0(a0)
\n
"
" j 1b
\n
"
);
}
int
main
()
{
SystemInit48HSI
();
Setup
UART
(
UART_BRR
);
Setup
DebugPrintf
(
);
int
k
;
// Boost CPU supply.
EXTEN
->
EXTEN_CTR
=
EXTEN_LDO_TRIM
;
// Enable GPIOD (for debugging)
RCC
->
APB2PCENR
|=
RCC_APB2Periph_GPIOD
;
// Enable GPIOs
RCC
->
APB2PCENR
|=
RCC_APB2Periph_GPIOD
|
RCC_APB2Periph_GPIOC
;
// GPIO D0 Push-Pull
GPIOD
->
CFGLR
&=
~
(
0xf
<<
(
4
*
0
));
GPIOD
->
CFGLR
|=
(
GPIO_Speed_10MHz
|
GPIO_CNF_OUT_PP
)
<<
(
4
*
0
);
GPIOD
->
BSHR
=
1
;
// Turn on GPIOD0
GPIOD
->
BSHR
=
1
<<
16
;
// Turn off GPIOD0
//DCSR
asm
volatile
(
"
\n
\
li t0, 0x4
\n
\
csrw 0x7B0, t0
\n
\
"
);
while
(
1
)
{
Delay_Ms
(
2
);
*
(
uint32_t
*
)(
0xe0000100
)
=
2
;
//Hopefully enable debug (dmcontrol .0) --> Doesn't work.
uint32_t
val
=
*
(
uint32_t
*
)
0xe00000f4
;
*
(
uint32_t
*
)
0xe00000f4
=
0xaabbccdd
;
// GPIO D4 Push-Pull
GPIOD
->
CFGLR
&=
~
(
0xf
<<
(
4
*
4
));
GPIOD
->
CFGLR
|=
(
GPIO_Speed_10MHz
|
GPIO_CNF_OUT_PP
)
<<
(
4
*
4
);
printf
(
"0xe00000f4: %08x %08x
\n
"
,
val
,
__get_dscratch0
()
);
// GPIO C0 Push-Pull
GPIOC
->
CFGLR
&=
~
(
0xf
<<
(
4
*
0
));
GPIOC
->
CFGLR
|=
(
GPIO_Speed_10MHz
|
GPIO_CNF_OUT_PP
)
<<
(
4
*
0
);
// Write to dscratch0
asm
volatile
(
"
\n
\
li t0, 0xa8b8c8d8
\n
\
csrw 0x7B2, t0
\n
\
csrw 0x7B3, t0
\n
\
"
);
}
SRAMCode
();
}
This diff is collapsed.
Click to expand it.
examples/self_modify_code/self_modify_code.c
+
4
−
2
View file @
f63b60ab
...
...
@@ -8,7 +8,9 @@
uint32_t
count
;
// Tell the compiler to put this code in the .data section. That
// will cause the startup code to copy it from flash into RAM where
// it can be easily modified at runtime.
uint32_t
ReadCSRSelfModify
(
uint16_t
whichcsr
)
__attribute__
((
section
(
".data"
)))
__attribute__
((
noinline
));
uint32_t
ReadCSRSelfModify
(
uint16_t
whichcsr
)
{
...
...
@@ -20,7 +22,7 @@ uint32_t ReadCSRSelfModify( uint16_t whichcsr )
// We have to put this here to "force" the compiler to order the
// instructions in this way. Otherwise, the compiler will try
// to optimize the code and inline the assembly int something where
// to optimize the code and inline the assembly int
o
something where
// our global handle into assembly code becomes meaningless.
// Annoyingly, it has to contain at least one instruction :(
asm
volatile
(
"nop"
);
...
...
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