From c2fd3ab7109a538c1341e64067c6b66186cad5c5 Mon Sep 17 00:00:00 2001 From: Grigori Goronzy Date: Sun, 3 Jan 2021 19:57:50 +0100 Subject: [PATCH] Add -e/--erase option Erases the flash memory without any programming. Mutually exclusive with providing a file to flash. --- stcgal/frontend.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/stcgal/frontend.py b/stcgal/frontend.py index bc7ad76..627ead2 100644 --- a/stcgal/frontend.py +++ b/stcgal/frontend.py @@ -144,6 +144,15 @@ class StcGal: self.protocol.program_options() self.protocol.disconnect() + def erase_mcu(self): + """Erase MCU without programming""" + + code_size = self.protocol.model.code + + self.protocol.handshake() + self.protocol.erase_flash(code_size, code_size) + self.protocol.disconnect() + def run(self): """Run programmer, main entry point.""" @@ -190,8 +199,10 @@ class StcGal: try: if self.opts.code_image: self.program_mcu() - return 0 - self.protocol.disconnect() + elif self.opts.erase: + self.erase_mcu() + else: + self.protocol.disconnect() return 0 except NameError as ex: sys.stdout.flush() @@ -223,8 +234,10 @@ def cli(): parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, description="stcgal {} - an STC MCU ISP flash tool\n".format(stcgal.__version__) + "(C) 2014-2018 Grigori Goronzy and others\nhttps://github.com/grigorig/stcgal") - parser.add_argument("code_image", help="code segment file to flash (BIN/HEX)", type=argparse.FileType("rb"), nargs='?') + exclusives = parser.add_mutually_exclusive_group() + exclusives.add_argument("code_image", help="code segment file to flash (BIN/HEX)", type=argparse.FileType("rb"), nargs='?') parser.add_argument("eeprom_image", help="eeprom segment file to flash (BIN/HEX)", type=argparse.FileType("rb"), nargs='?') + exclusives.add_argument("-e", "--erase", help="only erase flash memory", action="store_true") parser.add_argument("-a", "--autoreset", help="cycle power automatically by asserting DTR", action="store_true") parser.add_argument("-r", "--resetcmd", help="shell command for board power-cycling (instead of DTR assertion)", action="store") parser.add_argument("-P", "--protocol", help="protocol version (default: auto)",