Skip to content

Commit

Permalink
Merge pull request #455 from monte-monte/master
Browse files Browse the repository at this point in the history
Fix unitialized WCH-LinkE errors
  • Loading branch information
cnlohr authored Nov 29, 2024
2 parents 5a4c4d8 + 6279c4c commit 8d096b0
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions minichlink/pgm-wch-linke.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,24 @@ int LEWriteReg32( void * dev, uint8_t reg_7_bit, uint32_t command )
wch_link_command( devh, req, sizeof(req), &resplen, resp, sizeof(resp) );
if( resplen != 9 || resp[8] == 0x02 || resp[8] == 0x03 ) //|| resp[3] != reg_7_bit )
{
fprintf( stderr, "Error setting write reg. Tell cnlohr. Maybe we should allow retries here?\n" );
fprintf( stderr, "RR: %d :", resplen );
int i;
for( i = 0; i < resplen; i++ )
struct InternalState *iss = (struct InternalState *)( ( (struct ProgrammerStructBase *)dev )->internal );
if ( !iss->target_chip_id && !iss->statetag )
{
fprintf( stderr, "%02x ", resp[i] );
fprintf( stderr, "Programmer wasn't initialized? Fixing\n" );
wch_link_command( devh, "\x81\x0d\x01\x02", 4, &resplen, resp, sizeof( resp ) );
iss->statetag = STTAG( "INIT" );
}
else
{
fprintf( stderr, "Error setting write reg. Tell cnlohr. Maybe we should allow retries here?\n" );
fprintf( stderr, "RR: %d :", resplen );
int i;
for ( i = 0; i < resplen; i++ )
{
fprintf( stderr, "%02x ", resp[i] );
}
fprintf( stderr, "\n" );
}
fprintf( stderr, "\n" );
}
return 0;
}
Expand All @@ -264,14 +274,24 @@ int LEReadReg32( void * dev, uint8_t reg_7_bit, uint32_t * commandresp )
*commandresp = ( rbuff[4]<<24 ) | (rbuff[5]<<16) | (rbuff[6]<<8) | (rbuff[7]<<0);
if( transferred != 9 || rbuff[8] == 0x02 || rbuff[8] == 0x03 ) //|| rbuff[3] != reg_7_bit )
{
fprintf( stderr, "Error setting write reg. Tell cnlohr. Maybe we should allow retries here?\n" );
fprintf( stderr, "RR: %d :", transferred );
int i;
for( i = 0; i < transferred; i++ )
struct InternalState *iss = (struct InternalState *)( ( (struct ProgrammerStructBase *)dev )->internal );
if ( !iss->target_chip_id && !iss->statetag )
{
fprintf( stderr, "%02x ", rbuff[i] );
fprintf( stderr, "Programmer wasn't initialized? Fixing\n" );
wch_link_command( devh, "\x81\x0d\x01\x02", 4, (int *)&transferred, rbuff, sizeof( rbuff ) );
iss->statetag = STTAG( "INIT" );
}
else
{
fprintf( stderr, "Error setting read reg. Tell cnlohr. Maybe we should allow retries here?\n" );
fprintf( stderr, "RR: %d :", transferred );
int i;
for ( i = 0; i < transferred; i++ )
{
fprintf( stderr, "%02x ", rbuff[i] );
}
fprintf( stderr, "\n" );
}
fprintf( stderr, "\n" );
}
/*
printf( "RR: %d :", transferred );
Expand Down

0 comments on commit 8d096b0

Please sign in to comment.