Skip to content
Snippets Groups Projects
Unverified Commit 0ef88546 authored by CNLohr's avatar CNLohr Committed by GitHub
Browse files

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
...@@ -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 LinkE\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 )
{ {
......
...@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment