@@ -237,7 +237,7 @@ def main(args: argparse.Namespace):
237
237
handler = SerialHandler (port = args .port )
238
238
239
239
if args .function == "flash" :
240
- flash (handler , args .hexfile )
240
+ flash (pslab . ScienceLab ( args . port ) , args .hexfile )
241
241
return
242
242
243
243
if args .function == "collect" :
@@ -525,28 +525,34 @@ def add_install_args(subparser: argparse._SubParsersAction):
525
525
)
526
526
527
527
528
- def flash (handler : SerialHandler , hexfile : str ):
528
+ def flash (psl : pslab . ScienceLab , hexfile : str ):
529
529
"""Flash firmware over USB.
530
530
531
531
PSLab must be in bootloader mode.
532
532
"""
533
+ if psl .interface .baudrate == 1000000 :
534
+ psl .interface .timeout = 5
535
+ psl .enter_bootloader ()
536
+
533
537
try :
534
- bootattrs = mcbootflash .get_boot_attrs (handler )
538
+ bootattrs = mcbootflash .get_boot_attrs (psl )
535
539
except struct .error :
536
540
print ("Flashing failed: PSLab is not in bootloader mode." )
541
+ return
537
542
538
- mcbootflash .erase_flash (handler , bootattrs .memory_range , bootattrs .erase_size )
543
+ mcbootflash .erase_flash (psl , bootattrs .memory_range , bootattrs .erase_size )
539
544
total_bytes , chunks = mcbootflash .chunked (hexfile , bootattrs )
540
545
written = 0
541
546
542
547
for chunk in chunks :
543
- mcbootflash .write_flash (handler , chunk )
544
- mcbootflash .checksum (handler , chunk )
548
+ mcbootflash .write_flash (psl , chunk )
549
+ mcbootflash .checksum (psl , chunk )
545
550
written += len (chunk .data )
546
551
print (f"{ written } /{ total_bytes } bytes flashed." , end = "\r " )
547
552
548
553
print ("" , end = "\n " )
549
- mcbootflash .self_verify (handler )
554
+ mcbootflash .self_verify (psl )
555
+ mcbootflash .reset (psl )
550
556
551
557
552
558
def add_flash_args (subparser : argparse ._SubParsersAction ):
0 commit comments