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

Merge pull request #94 from bmx/patch-1

old read mode for v307 targets
parents 97094d89 be1b6e09
No related branches found
No related tags found
No related merge requests found
......@@ -17,11 +17,9 @@ struct LinkEProgrammerStruct
};
// For non-ch32v003 chips.
#if 0
static int LEReadBinaryBlob( void * d, uint32_t offset, uint32_t amount, uint8_t * readbuff );
static int InternalLinkEHaltMode( void * d, int mode );
static int LEWriteBinaryBlob( void * d, uint32_t address_to_write, uint32_t len, uint8_t * blob );
#endif
//static int LEWriteBinaryBlob( void * d, uint32_t address_to_write, uint32_t len, uint8_t * blob );
#define WCHTIMEOUT 5000
#define WCHCHECK(x) if( (status = x) ) { fprintf( stderr, "Bad USB Operation on " __FILE__ ":%d (%d)\n", __LINE__, status ); exit( status ); }
......@@ -232,6 +230,14 @@ static int LESetupInterface( void * d )
fprintf(stderr, "link error, nothing connected to linker\n");
return -1;
}
uint32_t target_chip_type = ( rbuff[4] << 4) + (rbuff[5] >> 4);
fprintf(stderr, "Chip Type: %03x\n", target_chip_type);
if( target_chip_type == 0x307 )
{
fprintf( stderr, "CH32V307 Detected. Allowing old-flash-mode for operation.\n" );
//MCF.WriteBinaryBlob = LEWriteBinaryBlob;
MCF.ReadBinaryBlob = LEReadBinaryBlob;
}
// 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.
......@@ -253,17 +259,6 @@ static int LESetupInterface( void * d )
fprintf( stderr, "PFlags : %02x-%02x-%02x-%02x\n", rbuff[12], rbuff[13], rbuff[14], rbuff[15] );
fprintf( stderr, "Part Type (B): %02x-%02x-%02x-%02x\n", rbuff[16], rbuff[17], rbuff[18], rbuff[19] );
if( rbuff[2] == 0x05 && rbuff[3] == 0x06 )
{
// fprintf( stderr, "CH32V307 Detected. Allowing old-flash-mode for operation.\n" );
// MCF.WriteBinaryBlob = LEWriteBinaryBlob;
// MCF.ReadBinaryBlob = LEReadBinaryBlob;
}
else
{
// No need to use these and the propreitary blob.
}
return 0;
}
......@@ -388,6 +383,7 @@ const uint8_t * bootloader = (const uint8_t*)
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
int bootloader_len = 512;
#endif
static int InternalLinkEHaltMode( void * d, int mode )
{
......@@ -472,6 +468,7 @@ static int LEReadBinaryBlob( void * d, uint32_t offset, uint32_t amount, uint8_t
return 0;
}
#if 0
static int LEWriteBinaryBlob( void * d, uint32_t address_to_write, uint32_t len, uint8_t * blob )
{
libusb_device_handle * dev = ((struct LinkEProgrammerStruct*)d)->devh;
......
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