Skip to content

Commit

Permalink
Add preliminary support for dropping to bootloader
Browse files Browse the repository at this point in the history
  • Loading branch information
bessman committed Nov 14, 2023
1 parent b310d85 commit da62fa9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
36 changes: 20 additions & 16 deletions pslab/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,12 @@ def main(args: argparse.Namespace):
install(args)
return

handler = SerialHandler(port=args.port)

if args.function == "flash":
flash(args)
flash(handler, args.hexfile)
return

handler = SerialHandler(port=args.port)

if args.function == "collect":
collect(handler, args)
elif args.function == "wave":
Expand Down Expand Up @@ -524,15 +524,18 @@ def add_install_args(subparser: argparse._SubParsersAction):
)


def flash(args: argparse.Namespace):
"""Flash firmware over USB.
def flash(handler: SerialHandler, hexfile: str):
"""Flash firmware over USB."""
handler.drop_to_boot()
bootattrs = mcbootflash.get_boot_attrs(handler)
mcbootflash.erase_flash(handler, bootattrs.memory_range, bootattrs.erase_size)

Parameters
----------
args : :class:`argparse.Namespace`
Parsed arguments.
"""
mcbootflash.flash(args)
for chunk in mcbootflash.chunked(hexfile, bootattrs):
mcbootflash.write_flash(handler, chunk)
mcbootflash.checksum(handler, chunk)

mcbootflash.self_verify(handler)
mcbootflash.reset(handler)


def add_flash_args(subparser: argparse._SubParsersAction):
Expand All @@ -543,8 +546,9 @@ def add_flash_args(subparser: argparse._SubParsersAction):
subparser : :class:`argparse._SubParsersAction`
SubParser to add other arguments related to flash function.
"""
parser = mcbootflash.get_parser()
parser.prog = "pslab"
parser.usage = "Flash firmware to PSLab v6."
parser.add_argument("-b", "--baudrate", default=460800, help=argparse.SUPPRESS)
subparser.add_parser("flash", parents=[parser], add_help=False)
flash = subparser.add_parser("flash")
flash.add_argument(
"hexfile",
type=str,
help="an Intel HEX file containing application firmware",
)
3 changes: 3 additions & 0 deletions pslab/serial_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@ def wait_for_data(self, timeout: float = 0.2) -> bool:

return False

def drop_to_boot(self):
self.send_int(0xB007)


RECORDED_TRAFFIC = iter([])
"""An iterator returning (request, response) pairs.
Expand Down

0 comments on commit da62fa9

Please sign in to comment.