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
a39484bb
Commit
a39484bb
authored
1 year ago
by
cnlohr
Browse files
Options
Downloads
Patches
Plain Diff
Working on b003 flasher + add attempt at flash test (doesn't currently work)
parent
4f26016b
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/flashtest/Makefile
+9
-0
9 additions, 0 deletions
examples/flashtest/Makefile
examples/flashtest/flashtest.c
+75
-0
75 additions, 0 deletions
examples/flashtest/flashtest.c
minichlink/pgm-b003fun.c
+33
-11
33 additions, 11 deletions
minichlink/pgm-b003fun.c
with
117 additions
and
11 deletions
examples/flashtest/Makefile
0 → 100644
+
9
−
0
View file @
a39484bb
all
:
flash
TARGET
:=
flashtest
include
../../ch32v003fun/ch32v003fun.mk
flash
:
cv_flash
clean
:
cv_clean
This diff is collapsed.
Click to expand it.
examples/flashtest/flashtest.c
0 → 100644
+
75
−
0
View file @
a39484bb
// DOES NOT WORK HALP!!!!!!!!!!!!!!
#define SYSTEM_CORE_CLOCK 48000000
#include
"ch32v003fun.h"
#include
<stdio.h>
uint32_t
count
;
int
main
()
{
SystemInit48HSI
();
SetupDebugPrintf
();
Delay_Ms
(
100
);
printf
(
"Starting
\n
"
);
// Unkock flash - be aware you need extra stuff for the bootloader.
FLASH
->
KEYR
=
0x45670123
;
FLASH
->
KEYR
=
0xCDEF89AB
;
// For option bytes.
// FLASH->OBKEYR = 0x45670123;
// FLASH->OBKEYR = 0xCDEF89AB;
FLASH
->
MODEKEYR
=
0x45670123
;
FLASH
->
MODEKEYR
=
0xCDEF89AB
;
printf
(
"FLASH->CTLR = %08lx
\n
"
,
FLASH
->
CTLR
);
if
(
FLASH
->
CTLR
&
0x8080
)
{
printf
(
"Flash still locked
\n
"
);
while
(
1
);
}
uint32_t
*
ptr
=
(
uint32_t
*
)
0x08002700
;
printf
(
"Memory at: 0x08002710: %08lx %08lx
\n
"
,
ptr
[
0
],
ptr
[
1
]
);
//Erase Page
FLASH
->
CTLR
=
CR_PAGE_ER
;
FLASH
->
ADDR
=
(
intptr_t
)
ptr
;
FLASH
->
CTLR
=
CR_STRT_Set
|
CR_PAGE_ER
;
printf
(
"FLASH->STATR = %08lx %08x
\n
"
,
FLASH
->
STATR
,
FLASH_STATR_BSY
);
while
(
FLASH
->
STATR
&
FLASH_STATR_BSY
);
printf
(
"Erase complete
\n
"
);
// Clear buffer and prep for flashing.
FLASH
->
CTLR
=
CR_PAGE_PG
;
FLASH
->
CTLR
=
CR_BUF_RST
|
CR_PAGE_PG
;
// Note: It takes about 8 clock cycles for this to finish.
while
(
FLASH
->
STATR
&
FLASH_STATR_BSY
);
printf
(
"Memory at: 0x08002710: %08lx %08lx
\n
"
,
ptr
[
0
],
ptr
[
1
]
);
int
i
;
for
(
i
=
0
;
i
<
16
;
i
++
)
{
ptr
[
i
]
=
0xabcd1234
;
//Write to the memory
FLASH
->
CTLR
=
CR_PAGE_PG
|
FLASH_CTLR_BUF_LOAD
;
// Load the buffer.
printf
(
"(loop) FLASH->STATR = %08lx
\n
"
,
FLASH
->
STATR
);
while
(
FLASH
->
STATR
&
FLASH_STATR_BSY
);
}
FLASH
->
ADDR
=
(
intptr_t
)
ptr
;
FLASH
->
CTLR
=
CR_PAGE_PG
|
CR_STRT_Set
;
printf
(
"FLASH->STATR = %08lx
\n
"
,
FLASH
->
STATR
);
while
(
FLASH
->
STATR
&
FLASH_STATR_BSY
);
printf
(
"Memory at: 0x08002710: %08lx %08lx
\n
"
,
ptr
[
0
],
ptr
[
1
]
);
while
(
1
);
}
This diff is collapsed.
Click to expand it.
minichlink/pgm-b003fun.c
+
33
−
11
View file @
a39484bb
...
...
@@ -61,6 +61,14 @@ static const unsigned char word_wise_write_blob[] = { // size and address must b
0x14, 0xc1, 0x82, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 */
};
static
const
unsigned
char
write64_flash
[]
=
{
// size and address must be aligned by 4.
0x13
,
0x07
,
0x45
,
0x03
,
0x0c
,
0x43
,
0x13
,
0x86
,
0x05
,
0x04
,
0x5c
,
0x43
,
0xb7
,
0x02
,
0x05
,
0x00
,
0x14
,
0x47
,
0x94
,
0xc1
,
0x23
,
0xa0
,
0x57
,
0x00
,
0x91
,
0x05
,
0x11
,
0x07
,
0xe3
,
0xca
,
0xc5
,
0xfe
,
0xc1
,
0x65
,
0x93
,
0x85
,
0x05
,
0x04
,
0xcc
,
0xc3
,
0x8c
,
0xc3
,
0xfd
,
0x56
,
0x14
,
0xc1
,
0x82
,
0x80
};
static
const
unsigned
char
half_wise_write_blob
[]
=
{
// size and address must be aligned by 2
0x23
,
0xa0
,
0x05
,
0x00
,
0x13
,
0x07
,
0x45
,
0x03
,
0x0c
,
0x43
,
0x50
,
0x43
,
0x2e
,
0x96
,
0x21
,
0x07
,
0x16
,
0x23
,
0x96
,
0xa1
,
0x96
,
0x21
,
0x16
,
0xa3
,
...
...
@@ -433,19 +441,35 @@ static int B003FunBlockWrite64( void * dev, uint32_t address_to_write, uint8_t *
return
-
9
;
}
}
MCF
.
WriteWord
(
dev
,
0x40022010
,
CR_PAGE_PG
);
// THIS IS REQUIRED, (intptr_t)&FLASH->CTLR = 0x40022010
MCF
.
WriteWord
(
dev
,
0x40022010
,
CR_BUF_RST
|
CR_PAGE_PG
);
// (intptr_t)&FLASH->CTLR = 0x40022010
printf
(
"Preppinggg %08x
\n
"
,
address_to_write
);
// Not actually needed.
MCF
.
WriteWord
(
dev
,
0x40022010
,
CR_PAGE_PG
);
// (intptr_t)&FLASH->CTLR = 0x40022010
MCF
.
WriteWord
(
dev
,
0x40022010
,
CR_PAGE_PG
|
CR_BUF_RST
);
// (intptr_t)&FLASH->CTLR = 0x40022010
uint32_t
word1
,
word2
;
int
r
=
B003FunReadWord
(
dev
,
0x40022010
,
&
word1
);
r
|=
B003FunReadWord
(
dev
,
0x4002200c
,
&
word2
);
printf
(
"IN: WORD: %d %08x %08x
\n
"
,
r
,
word1
,
word2
);
ResetOp
(
eps
);
WriteOpArb
(
eps
,
write64_flash
,
sizeof
(
write64_flash
)
);
WriteOp4
(
eps
,
address_to_write
);
// Base address to write. @52
WriteOp4
(
eps
,
0x40022010
);
// FLASH base address. @ 56
memcpy
(
&
eps
->
commandbuffer
[
60
],
data
,
64
);
// @60
if
(
MCF
.
PrepForLongOp
)
MCF
.
PrepForLongOp
(
dev
);
// Give the programmer a headsup this next operation could take a while.
if
(
CommitOp
(
eps
)
)
return
-
5
;
r
=
B003FunReadWord
(
dev
,
0x40022010
,
&
word1
);
r
|=
B003FunReadWord
(
dev
,
0x4002200c
,
&
word2
);
printf
(
"WORD: %d %08x %08x
\n
"
,
r
,
word1
,
word2
);
}
int
ret
=
InternalB003FunWriteBinaryBlob
(
dev
,
address_to_write
,
64
,
data
);
if
(
IsAddressFlash
(
address_to_write
)
)
else
{
MCF
.
WriteWord
(
dev
,
0x40022014
,
address_to_write
);
//0x40022014 -> FLASH->ADDR
if
(
MCF
.
PrepForLongOp
)
MCF
.
PrepForLongOp
(
dev
);
// Give the programmer a headsup this next operation could take a while.
MCF
.
WriteWord
(
dev
,
0x40022010
,
CR_PAGE_PG
|
CR_STRT_Set
);
// 0x40022010 -> FLASH->CTLR
InternalMarkMemoryNotErased
(
iss
,
address_to_write
);
return
InternalB003FunWriteBinaryBlob
(
dev
,
address_to_write
,
64
,
data
);
}
return
ret
;
return
0
;
}
static
int
B003FunWriteHalfWord
(
void
*
dev
,
uint32_t
address_to_write
,
uint16_t
data
)
...
...
@@ -698,8 +722,6 @@ void * TryInit_B003Fun()
/* Run app blob
FLASH->BOOT_MODEKEYR = FLASH_KEY1;
FLASH->BOOT_MODEKEYR = FLASH_KEY2;
FLASH->STATR = 0; // 1<<14 is zero, so, boot user code.
...
...
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