Add autoreset feature via DTR control line
This is inspired by Arduino. Directly before connect, DTR is asserted for 0.5 seconds and then deasserted again. With a small external circuit, the MCU can be power-cycled with this control signal. In case the MCU draws very little power, it may even be possible to supply power directly from the DTR pin.
This commit is contained in:
parent
41cabb587b
commit
372f854c77
@ -117,7 +117,7 @@ class StcGal:
|
|||||||
self.protocol.disconnect()
|
self.protocol.disconnect()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
try: self.protocol.connect()
|
try: self.protocol.connect(autoreset=self.opts.autoreset)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
sys.stdout.flush();
|
sys.stdout.flush();
|
||||||
print("interrupted")
|
print("interrupted")
|
||||||
@ -174,6 +174,7 @@ def cli():
|
|||||||
description="stcgal %s - an STC MCU ISP flash tool\n(C) 2014-2015 Grigori Goronzy\nhttps://github.com/grigorig/stcgal" %stcgal.__version__)
|
description="stcgal %s - an STC MCU ISP flash tool\n(C) 2014-2015 Grigori Goronzy\nhttps://github.com/grigorig/stcgal" %stcgal.__version__)
|
||||||
parser.add_argument("code_image", help="code segment file to flash (BIN/HEX)", type=argparse.FileType("rb"), nargs='?')
|
parser.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='?')
|
||||||
|
parser.add_argument("-a", "--autoreset", help="cycle power automatically by asserting DTR", action="store_true")
|
||||||
parser.add_argument("-P", "--protocol", help="protocol version", choices=["stc89", "stc12a", "stc12", "stc15a", "stc15"], default="stc12")
|
parser.add_argument("-P", "--protocol", help="protocol version", choices=["stc89", "stc12a", "stc12", "stc15a", "stc15"], default="stc12")
|
||||||
parser.add_argument("-p", "--port", help="serial port device", default="/dev/ttyUSB0")
|
parser.add_argument("-p", "--port", help="serial port device", default="/dev/ttyUSB0")
|
||||||
parser.add_argument("-b", "--baud", help="transfer baud rate (default: 19200)", type=BaudType(), default=19200)
|
parser.add_argument("-b", "--baud", help="transfer baud rate (default: 19200)", type=BaudType(), default=19200)
|
||||||
|
@ -728,7 +728,7 @@ class StcBaseProtocol:
|
|||||||
def set_option(self, name, value):
|
def set_option(self, name, value):
|
||||||
self.options.set_option(name, value)
|
self.options.set_option(name, value)
|
||||||
|
|
||||||
def connect(self):
|
def connect(self, autoreset=False):
|
||||||
"""Connect to MCU and initialize communication.
|
"""Connect to MCU and initialize communication.
|
||||||
|
|
||||||
Set up serial port, send sync sequence and get part info.
|
Set up serial port, send sync sequence and get part info.
|
||||||
@ -746,6 +746,16 @@ class StcBaseProtocol:
|
|||||||
# avoid glitches if there is something in the input buffer
|
# avoid glitches if there is something in the input buffer
|
||||||
self.ser.flushInput()
|
self.ser.flushInput()
|
||||||
|
|
||||||
|
if autoreset:
|
||||||
|
print("Cycling power: ", end="")
|
||||||
|
sys.stdout.flush()
|
||||||
|
self.ser.setDTR(True)
|
||||||
|
time.sleep(0.5)
|
||||||
|
self.ser.setDTR(False)
|
||||||
|
print("done")
|
||||||
|
print("Waiting for MCU: ", end="")
|
||||||
|
sys.stdout.flush()
|
||||||
|
else:
|
||||||
print("Waiting for MCU, please cycle power: ", end="")
|
print("Waiting for MCU, please cycle power: ", end="")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user