Add -e/--erase option
Erases the flash memory without any programming. Mutually exclusive with providing a file to flash.
This commit is contained in:
		| @ -144,6 +144,15 @@ class StcGal: | |||||||
|         self.protocol.program_options() |         self.protocol.program_options() | ||||||
|         self.protocol.disconnect() |         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): |     def run(self): | ||||||
|         """Run programmer, main entry point.""" |         """Run programmer, main entry point.""" | ||||||
|  |  | ||||||
| @ -190,7 +199,9 @@ class StcGal: | |||||||
|         try: |         try: | ||||||
|             if self.opts.code_image: |             if self.opts.code_image: | ||||||
|                 self.program_mcu() |                 self.program_mcu() | ||||||
|                 return 0 |             elif self.opts.erase: | ||||||
|  |                 self.erase_mcu() | ||||||
|  |             else: | ||||||
|                 self.protocol.disconnect() |                 self.protocol.disconnect() | ||||||
|             return 0 |             return 0 | ||||||
|         except NameError as ex: |         except NameError as ex: | ||||||
| @ -223,8 +234,10 @@ def cli(): | |||||||
|     parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, |     parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, | ||||||
|                                      description="stcgal {} - an STC MCU ISP flash tool\n".format(stcgal.__version__) + |                                      description="stcgal {} - an STC MCU ISP flash tool\n".format(stcgal.__version__) + | ||||||
|                                                  "(C) 2014-2018 Grigori Goronzy and others\nhttps://github.com/grigorig/stcgal") |                                                  "(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='?') |     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("-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("-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)", |     parser.add_argument("-P", "--protocol", help="protocol version (default: auto)", | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user