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
0ef88546
Unverified
Commit
0ef88546
authored
1 year ago
by
CNLohr
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #86 from bmx/master
Better wch managment and bits
parents
5646947e
6ee88e3a
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
minichlink/minichlink.c
+10
-6
10 additions, 6 deletions
minichlink/minichlink.c
minichlink/pgm-wch-linke.c
+24
-2
24 additions, 2 deletions
minichlink/pgm-wch-linke.c
with
34 additions
and
8 deletions
minichlink/minichlink.c
+
10
−
6
View file @
0ef88546
...
@@ -23,22 +23,22 @@ void * MiniCHLinkInitAsDLL( struct MiniChlinkFunctions ** MCFO )
...
@@ -23,22 +23,22 @@ void * MiniCHLinkInitAsDLL( struct MiniChlinkFunctions ** MCFO )
void
*
dev
=
0
;
void
*
dev
=
0
;
if
(
(
dev
=
TryInit_WCHLinkE
())
)
if
(
(
dev
=
TryInit_WCHLinkE
())
)
{
{
fprintf
(
stderr
,
"Found WCH Link
E
\n
"
);
fprintf
(
stderr
,
"Found WCH Link
\n
"
);
}
}
else
if
(
(
dev
=
TryInit_ESP32S2CHFUN
())
)
else
if
(
(
dev
=
TryInit_ESP32S2CHFUN
())
)
{
{
fprintf
(
stderr
,
"Found ESP32S2 Programmer
\n
"
);
fprintf
(
stderr
,
"Found ESP32S2 Programmer
\n
"
);
}
}
else
if
((
dev
=
TryInit_NHCLink042
()))
else
if
((
dev
=
TryInit_NHCLink042
()))
{
{
fprintf
(
stderr
,
"Found NHC-Link042 Programmer
\n
"
);
fprintf
(
stderr
,
"Found NHC-Link042 Programmer
\n
"
);
}
}
else
else
{
{
fprintf
(
stderr
,
"Error: Could not initialize any supported programmers
\n
"
);
fprintf
(
stderr
,
"Error: Could not initialize any supported programmers
\n
"
);
return
0
;
return
0
;
}
}
SetupAutomaticHighLevelFunctions
(
dev
);
SetupAutomaticHighLevelFunctions
(
dev
);
if
(
MCFO
)
if
(
MCFO
)
{
{
...
@@ -50,6 +50,10 @@ void * MiniCHLinkInitAsDLL( struct MiniChlinkFunctions ** MCFO )
...
@@ -50,6 +50,10 @@ void * MiniCHLinkInitAsDLL( struct MiniChlinkFunctions ** MCFO )
#if !defined( MINICHLINK_AS_LIBRARY ) && !defined( MINICHLINK_IMPORT )
#if !defined( MINICHLINK_AS_LIBRARY ) && !defined( MINICHLINK_IMPORT )
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
if
(
argv
[
1
][
0
]
==
'-'
&&
argv
[
1
][
1
]
==
'h'
)
{
goto
help
;
}
void
*
dev
=
MiniCHLinkInitAsDLL
(
0
);
void
*
dev
=
MiniCHLinkInitAsDLL
(
0
);
if
(
!
dev
)
if
(
!
dev
)
{
{
...
...
This diff is collapsed.
Click to expand it.
minichlink/pgm-wch-linke.c
+
24
−
2
View file @
0ef88546
...
@@ -197,16 +197,38 @@ static int LESetupInterface( void * d )
...
@@ -197,16 +197,38 @@ static int LESetupInterface( void * d )
uint32_t
transferred
=
0
;
uint32_t
transferred
=
0
;
// This puts the processor on hold to allow the debugger to run.
// This puts the processor on hold to allow the debugger to run.
wch_link_command
(
dev
,
"
\x81\x0d\x01\x03
"
,
4
,
0
,
0
,
0
);
// Reply: Ignored, 820d050900300500
wch_link_command
(
dev
,
"
\x81\x0d\x01\x03
"
,
4
,
(
int
*
)
&
transferred
,
rbuff
,
1024
);
// Reply: Ignored, 820d050900300500
// Place part into reset.
// Place part into reset.
wch_link_command
(
dev
,
"
\x81\x0d\x01\x01
"
,
4
,
(
int
*
)
&
transferred
,
rbuff
,
1024
);
// Reply is: "\x82\x0d\x04\x02\x08\x02\x00"
wch_link_command
(
dev
,
"
\x81\x0d\x01\x01
"
,
4
,
(
int
*
)
&
transferred
,
rbuff
,
1024
);
// Reply is: "\x82\x0d\x04\x02\x08\x02\x00"
switch
(
rbuff
[
5
])
{
case
1
:
fprintf
(
stderr
,
"WCH Programmer is CH549 version %d.%d
\n
"
,
rbuff
[
3
],
rbuff
[
4
]);
break
;
case
2
:
fprintf
(
stderr
,
"WCH Programmer is CH32V307 version %d.%d
\n
"
,
rbuff
[
3
],
rbuff
[
4
]);
break
;
case
3
:
fprintf
(
stderr
,
"WCH Programmer is CH32V203 version %d.%d
\n
"
,
rbuff
[
3
],
rbuff
[
4
]);
break
;
case
4
:
fprintf
(
stderr
,
"WCH Programmer is LinkB version %d.%d
\n
"
,
rbuff
[
3
],
rbuff
[
4
]);
break
;
default:
fprintf
(
stderr
,
"Unknown WCH Programmer %02x
\n
"
,
rbuff
[
5
]);
return
-
1
;
}
// TODO: What in the world is this? It doesn't appear to be needed.
// TODO: What in the world is this? It doesn't appear to be needed.
wch_link_command
(
dev
,
"
\x81\x0c\x02\x09\x01
"
,
5
,
0
,
0
,
0
);
//Reply is: 820c0101
wch_link_command
(
dev
,
"
\x81\x0c\x02\x09\x01
"
,
5
,
0
,
0
,
0
);
//Reply is: 820c0101
// This puts the processor on hold to allow the debugger to run.
// This puts the processor on hold to allow the debugger to run.
wch_link_command
(
dev
,
"
\x81\x0d\x01\x02
"
,
4
,
0
,
0
,
0
);
// Reply: Ignored, 820d050900300500
wch_link_command
(
dev
,
"
\x81\x0d\x01\x02
"
,
4
,
(
int
*
)
&
transferred
,
rbuff
,
1024
);
// Reply: Ignored, 820d050900300500
if
(
rbuff
[
0
]
==
0x81
&&
rbuff
[
1
]
==
0x55
&&
rbuff
[
2
]
==
0x01
&&
rbuff
[
3
]
==
0x01
)
{
fprintf
(
stderr
,
"link error, nothing connected to linker
\n
"
);
return
-
1
;
}
// For some reason, if we don't do this sometimes the programmer starts in a hosey mode.
// For some reason, if we don't do this sometimes the programmer starts in a hosey mode.
MCF
.
WriteReg32
(
d
,
DMCONTROL
,
0x80000001
);
// Make the debug module work properly.
MCF
.
WriteReg32
(
d
,
DMCONTROL
,
0x80000001
);
// Make the debug module work properly.
...
...
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