Skip to content
Snippets Groups Projects
Commit 49e75d02 authored by cnlohr's avatar cnlohr
Browse files

Fix a little OOO for ESP32S2 programmer + use 64-byte ops when it makes sense for flash writing.

parent ae422f12
No related branches found
No related tags found
No related merge requests found
...@@ -1052,23 +1052,31 @@ int DefaultWriteBinaryBlob( void * dev, uint32_t address_to_write, uint32_t blob ...@@ -1052,23 +1052,31 @@ int DefaultWriteBinaryBlob( void * dev, uint32_t address_to_write, uint32_t blob
{ {
MCF.ReadBinaryBlob( dev, base, 64, tempblock ); MCF.ReadBinaryBlob( dev, base, 64, tempblock );
MCF.Erase( dev, base, 64, 0 );
MCF.WriteWord( dev, 0x40022010, CR_PAGE_PG ); // THIS IS REQUIRED, (intptr_t)&FLASH->CTLR = 0x40022010
MCF.WriteWord( dev, 0x40022010, CR_BUF_RST | CR_PAGE_PG ); // (intptr_t)&FLASH->CTLR = 0x40022010
// Permute tempblock // Permute tempblock
int tocopy = end_o_plus_one_in_block - offset_in_block; int tocopy = end_o_plus_one_in_block - offset_in_block;
memcpy( tempblock + offset_in_block, blob + rsofar, tocopy ); memcpy( tempblock + offset_in_block, blob + rsofar, tocopy );
rsofar += tocopy; rsofar += tocopy;
int j; if( MCF.BlockWrite64 )
for( j = 0; j < 16; j++ )
{ {
MCF.WriteWord( dev, j*4+base, *(uint32_t*)(tempblock + j * 4) ); int r = MCF.BlockWrite64( dev, base, tempblock );
rsofar += 4; if( r ) return r;
}
else
{
MCF.Erase( dev, base, 64, 0 );
MCF.WriteWord( dev, 0x40022010, CR_PAGE_PG ); // THIS IS REQUIRED, (intptr_t)&FLASH->CTLR = 0x40022010
MCF.WriteWord( dev, 0x40022010, CR_BUF_RST | CR_PAGE_PG ); // (intptr_t)&FLASH->CTLR = 0x40022010
int j;
for( j = 0; j < 16; j++ )
{
MCF.WriteWord( dev, j*4+base, *(uint32_t*)(tempblock + j * 4) );
rsofar += 4;
}
MCF.WriteWord( dev, 0x40022014, base ); //0x40022014 -> FLASH->ADDR
MCF.WriteWord( dev, 0x40022010, CR_PAGE_PG|CR_STRT_Set ); // 0x40022010 -> FLASH->CTLR
} }
MCF.WriteWord( dev, 0x40022014, base ); //0x40022014 -> FLASH->ADDR
MCF.WriteWord( dev, 0x40022010, CR_PAGE_PG|CR_STRT_Set ); // 0x40022010 -> FLASH->CTLR
if( MCF.WaitForFlash && MCF.WaitForFlash( dev ) ) goto timedout; if( MCF.WaitForFlash && MCF.WaitForFlash( dev ) ) goto timedout;
} }
else else
......
...@@ -256,6 +256,7 @@ int ESPBlockWrite64( void * dev, uint32_t address_to_write, uint8_t * data ) ...@@ -256,6 +256,7 @@ int ESPBlockWrite64( void * dev, uint32_t address_to_write, uint8_t * data )
if( timeout > 1000 ) if( timeout > 1000 )
{ {
fprintf( stderr, "Error: Timed out block-writing 64\n" ); fprintf( stderr, "Error: Timed out block-writing 64\n" );
return -49;
} }
} while( eps->replylen < 2 ); } while( eps->replylen < 2 );
...@@ -364,7 +365,8 @@ int ESPPollTerminal( void * dev, uint8_t * buffer, int maxlen, uint32_t leavefla ...@@ -364,7 +365,8 @@ int ESPPollTerminal( void * dev, uint8_t * buffer, int maxlen, uint32_t leavefla
int rlen = eps->reply[0]; int rlen = eps->reply[0];
if( rlen < 1 ) return -8; if( rlen < 1 ) return -8;
/*
#if 0
int i; int i;
printf( "RESP (ML %d): %d\n", maxlen,eps->reply[0] ); printf( "RESP (ML %d): %d\n", maxlen,eps->reply[0] );
...@@ -375,7 +377,8 @@ int ESPPollTerminal( void * dev, uint8_t * buffer, int maxlen, uint32_t leavefla ...@@ -375,7 +377,8 @@ int ESPPollTerminal( void * dev, uint8_t * buffer, int maxlen, uint32_t leavefla
if( (i % 16) == 15 ) printf( "\n" ); if( (i % 16) == 15 ) printf( "\n" );
} }
printf( "\n" ); printf( "\n" );
*/ #endif
int errc = eps->reply[1]; int errc = eps->reply[1];
if( errc > 7 ) return -7; if( errc > 7 ) return -7;
......
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