@@ -259,7 +259,7 @@ def flash_begin(self, *, size=0, offset=0):
259259 number of blocks requred."""
260260 if self ._chipfamily == ESP32 :
261261 self .check_command (ESP_SPI_ATTACH , bytes ([0 ] * 8 ))
262- # We are harcoded for 4MB flash on ESP32
262+ # We are hardcoded for 4MB flash on ESP32
263263 buffer = struct .pack (
264264 "<IIIIII" , 0 , self ._flashsize , 0x10000 , 4096 , 256 , 0xFFFF
265265 )
@@ -270,7 +270,7 @@ def flash_begin(self, *, size=0, offset=0):
270270 erase_size = self .get_erase_size (offset , size )
271271 else :
272272 erase_size = size
273- timeout = 5
273+ timeout = 13
274274 stamp = time .monotonic ()
275275 buffer = struct .pack (
276276 "<IIII" , erase_size , num_blocks , self .FLASH_WRITE_SIZE , offset
@@ -303,7 +303,7 @@ def check_command(
303303 else :
304304 if len (data ) in (2 , 4 ):
305305 status_len = len (data )
306- if len (data ) < status_len :
306+ if data is None or len (data ) < status_len :
307307 raise RuntimeError ("Didn't get enough status bytes" )
308308 status = data [- status_len :]
309309 data = data [:- status_len ]
@@ -372,7 +372,10 @@ def get_response(self, opcode, timeout=0.1): # pylint: disable=too-many-branche
372372 packet_length = reply [3 ] + (reply [4 ] << 8 )
373373 if len (reply ) == packet_length + 10 :
374374 break
375- else :
375+ # Check to see if we have a complete packet. If not, we timed out.
376+ if len (reply ) != packet_length + 10 :
377+ if self ._debug :
378+ print ("Timed out after {} seconds" .format (timeout ))
376379 return (None , None )
377380 if self ._debug :
378381 print ("Packet:" , [hex (i ) for i in reply ])
@@ -464,7 +467,7 @@ def sync(self):
464467 ESP ROM bootloader, we will retry a few times"""
465468 self .reset (True )
466469
467- for _ in range (3 ):
470+ for _ in range (5 ):
468471 if self ._sync ():
469472 time .sleep (0.1 )
470473 return True
0 commit comments