Skip to content

Commit

Permalink
Fix unaligned (start address) writes.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlohr committed Nov 16, 2024
1 parent d91e473 commit f364f46
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion minichlink/microgdbstub.h
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ void MicroGDBStubSendReply( const void * data, int len, int docs )

if( listenMode == 2 )
{
//printf( ">>>>%s<<<<(%d)\n", data );
//printf( ">>>>%s<<<<\n", data );
send( serverSocket, data, len, MSG_NOSIGNAL );
}
}
Expand Down
3 changes: 1 addition & 2 deletions minichlink/minichlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1439,13 +1439,13 @@ int DefaultWriteBinaryBlob( void * dev, uint32_t address_to_write, uint32_t blob
for( i = 0; i < sectorsize/64; i++ )
{
int r = MCF.BlockWrite64( dev, base + i*64, blob + rsofar+i*64 );
rsofar += 64;
if( r )
{
fprintf( stderr, "Error writing block at memory %08x (error = %d)\n", base, r );
return r;
}
}
rsofar += sectorsize;
}
else // Block Write not avaialble
{
Expand Down Expand Up @@ -1547,7 +1547,6 @@ int DefaultWriteBinaryBlob( void * dev, uint32_t address_to_write, uint32_t blob
MCF.WriteWord( dev, j*4+base, *(uint32_t*)(tempblock + j * 4) );

// On the v2xx, v3xx, you also need to make sure FLASH->STATR & 2 is not set. This is only an issue when running locally.
rsofar += 4;
}

if( iss->target_chip_type == CHIP_CH32V20x || iss->target_chip_type == CHIP_CH32V30x )
Expand Down
18 changes: 12 additions & 6 deletions minichlink/pgm-esp32s2-ch32xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ int ESPReadAllCPURegisters( void * dev, uint32_t * regret )
}

int DefaultReadBinaryBlob( void * dev, uint32_t address_to_read_from, uint32_t read_size, uint8_t * blob );
int ESPReadBinaryBlob( void * dev, uint32_t address_to_read_from, uint32_t read_size, uint8_t * blob )
int ESPReadBinaryBlob( void * dev, uint32_t address_to_read_from, uint32_t read_size_in, uint8_t * blob )
{
int read_size = read_size_in;
struct ESP32ProgrammerStruct * eps = (struct ESP32ProgrammerStruct *)dev;

uint32_t address_to_read_from_2 = address_to_read_from;
uint8_t * blob_2 = blob;
int r = 0;
Expand All @@ -157,6 +157,11 @@ int ESPReadBinaryBlob( void * dev, uint32_t address_to_read_from, uint32_t read_
read_size -= nrb2r;
}

if( read_size <= 0 )
{
return 0;
}

int words = read_size / 4;

ESPFlushLLCommands( dev );
Expand All @@ -172,7 +177,7 @@ int ESPReadBinaryBlob( void * dev, uint32_t address_to_read_from, uint32_t read_
read_size -= 4;
words_this_group++;
}
if( ( SRemain( eps ) < 7 ) || w == words )
if( ( SRemain( eps ) < 8 ) || ( words_this_group * 5 > eps->replysize - 4 ) || w == words )
{
ESPFlushLLCommands( dev );
uint8_t * resp = eps->reply + 1;
Expand All @@ -184,16 +189,17 @@ int ESPReadBinaryBlob( void * dev, uint32_t address_to_read_from, uint32_t read_
resp += 5;
blob_2 += 4;
}
words_this_group = 0;
}
w++;
}

if( read_size )
if( read_size > 0 )
{
r = DefaultReadBinaryBlob( dev, address_to_read_from_2, read_size, blob_2 );
if( r ) return r;
}

return 0;
}

Expand All @@ -213,7 +219,7 @@ int ESPFlushLLCommands( void * dev )
int r;

eps->commandbuffer[0] = 0xad; // Key report ID
eps->commandbuffer[eps->commandplace] = 0xff;
memset( eps->commandbuffer + eps->commandplace, 0xff, eps->commandbuffersize - eps->commandplace - 1 );

#if 0
int i;
Expand Down

0 comments on commit f364f46

Please sign in to comment.