@@ -237,7 +237,7 @@ def main(args: argparse.Namespace):
237237 handler = SerialHandler (port = args .port )
238238
239239 if args .function == "flash" :
240- flash (handler , args .hexfile )
240+ flash (pslab . ScienceLab ( args . port ) , args .hexfile )
241241 return
242242
243243 if args .function == "collect" :
@@ -525,28 +525,34 @@ def add_install_args(subparser: argparse._SubParsersAction):
525525 )
526526
527527
528- def flash (handler : SerialHandler , hexfile : str ):
528+ def flash (psl : pslab . ScienceLab , hexfile : str ):
529529 """Flash firmware over USB.
530530
531531 PSLab must be in bootloader mode.
532532 """
533+ if psl .interface .baudrate == 1000000 :
534+ psl .interface .timeout = 5
535+ psl .enter_bootloader ()
536+
533537 try :
534- bootattrs = mcbootflash .get_boot_attrs (handler )
538+ bootattrs = mcbootflash .get_boot_attrs (psl )
535539 except struct .error :
536540 print ("Flashing failed: PSLab is not in bootloader mode." )
541+ return
537542
538- mcbootflash .erase_flash (handler , bootattrs .memory_range , bootattrs .erase_size )
543+ mcbootflash .erase_flash (psl , bootattrs .memory_range , bootattrs .erase_size )
539544 total_bytes , chunks = mcbootflash .chunked (hexfile , bootattrs )
540545 written = 0
541546
542547 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 )
545550 written += len (chunk .data )
546551 print (f"{ written } /{ total_bytes } bytes flashed." , end = "\r " )
547552
548553 print ("" , end = "\n " )
549- mcbootflash .self_verify (handler )
554+ mcbootflash .self_verify (psl )
555+ mcbootflash .reset (psl )
550556
551557
552558def add_flash_args (subparser : argparse ._SubParsersAction ):
0 commit comments