Implement power-cycling via custom shell command
Sometimes instead of DTR line some custom way (e.g SoC gpio line) may be used to reset the device. This commit implements automated power-cycling using a a custom shell command that can be specified via -r option Signed-off-by: Andrew Andrianov <andrew@ncrmnt.org>
This commit is contained in:
parent
f1bafb1e0d
commit
ba4faf9c43
@ -132,8 +132,7 @@ class StcGal:
|
|||||||
"""Run programmer, main entry point."""
|
"""Run programmer, main entry point."""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.protocol.connect(autoreset=self.opts.autoreset)
|
self.protocol.connect(autoreset=self.opts.autoreset, resetcmd=self.opts.resetcmd)
|
||||||
|
|
||||||
if self.opts.protocol == "auto":
|
if self.opts.protocol == "auto":
|
||||||
if not self.protocol.protocol_name:
|
if not self.protocol.protocol_name:
|
||||||
raise StcProtocolException("cannot detect protocol")
|
raise StcProtocolException("cannot detect protocol")
|
||||||
@ -203,6 +202,7 @@ def cli():
|
|||||||
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("-a", "--autoreset", help="cycle power automatically by asserting DTR", action="store_true")
|
||||||
|
parser.add_argument("-r", "--resetcmd", help="Use this shell cmd for board power-cycling (instead of DTR assertion)", action="store")
|
||||||
parser.add_argument("-P", "--protocol", help="protocol version (default: auto)", choices=["stc89", "stc12a", "stc12b", "stc12", "stc15a", "stc15", "usb15", "auto"], default="auto")
|
parser.add_argument("-P", "--protocol", help="protocol version (default: auto)", choices=["stc89", "stc12a", "stc12b", "stc12", "stc15a", "stc15", "usb15", "auto"], default="auto")
|
||||||
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)
|
||||||
|
@ -241,7 +241,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, autoreset=False):
|
def connect(self, autoreset=False, resetcmd=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.
|
||||||
@ -260,6 +260,7 @@ class StcBaseProtocol:
|
|||||||
self.ser.flushInput()
|
self.ser.flushInput()
|
||||||
|
|
||||||
if autoreset:
|
if autoreset:
|
||||||
|
if not resetcmd:
|
||||||
print("Cycling power: ", end="")
|
print("Cycling power: ", end="")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
self.ser.setDTR(True)
|
self.ser.setDTR(True)
|
||||||
@ -268,6 +269,9 @@ class StcBaseProtocol:
|
|||||||
print("done")
|
print("done")
|
||||||
print("Waiting for MCU: ", end="")
|
print("Waiting for MCU: ", end="")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
else:
|
||||||
|
print("Cycling power via shell cmd: " + resetcmd)
|
||||||
|
os.system(resetcmd)
|
||||||
else:
|
else:
|
||||||
print("Waiting for MCU, please cycle power: ", end="")
|
print("Waiting for MCU, please cycle power: ", end="")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
@ -1504,7 +1508,7 @@ class StcUsb15Protocol(Stc15Protocol):
|
|||||||
host2dev = usb.util.CTRL_TYPE_VENDOR | usb.util.CTRL_RECIPIENT_DEVICE | usb.util.CTRL_OUT
|
host2dev = usb.util.CTRL_TYPE_VENDOR | usb.util.CTRL_RECIPIENT_DEVICE | usb.util.CTRL_OUT
|
||||||
self.dev.ctrl_transfer(host2dev, request, value, index, chunks)
|
self.dev.ctrl_transfer(host2dev, request, value, index, chunks)
|
||||||
|
|
||||||
def connect(self, autoreset=False):
|
def connect(self, autoreset=False, resetcmd=False):
|
||||||
"""Connect to USB device and read info packet"""
|
"""Connect to USB device and read info packet"""
|
||||||
|
|
||||||
# USB support is optional. Provide an error if pyusb is not available.
|
# USB support is optional. Provide an error if pyusb is not available.
|
||||||
|
Loading…
Reference in New Issue
Block a user