Add dtr_inverted and rts_inverted as parameters to -A
This commit is contained in:
parent
38dfb08d98
commit
8467229e79
@ -22,8 +22,7 @@ options:
|
|||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-e, --erase only erase flash memory
|
-e, --erase only erase flash memory
|
||||||
-a, --autoreset cycle power automatically by asserting DTR
|
-a, --autoreset cycle power automatically by asserting DTR
|
||||||
-i, --invertreset invert pin reset logic
|
-A {dtr,rts,dtr_inverted,rts_inverted}, --resetpin {dtr,rts,dtr_inverted,rts_inverted}
|
||||||
-A {dtr,rts}, --resetpin {dtr,rts}
|
|
||||||
pin to hold down when using --autoreset (default: DTR)
|
pin to hold down when using --autoreset (default: DTR)
|
||||||
-r RESETCMD, --resetcmd RESETCMD
|
-r RESETCMD, --resetcmd RESETCMD
|
||||||
shell command for board power-cycling (instead of DTR
|
shell command for board power-cycling (instead of DTR
|
||||||
|
@ -183,7 +183,7 @@ class StcGal:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.protocol.connect(autoreset=self.opts.autoreset, resetcmd=self.opts.resetcmd, resetpin=self.opts.resetpin, invertreset=self.opts.invertreset)
|
self.protocol.connect(autoreset=self.opts.autoreset, resetcmd=self.opts.resetcmd, resetpin=self.opts.resetpin)
|
||||||
if isinstance(self.protocol, StcAutoProtocol):
|
if isinstance(self.protocol, StcAutoProtocol):
|
||||||
if not self.protocol.protocol_name:
|
if not self.protocol.protocol_name:
|
||||||
raise StcProtocolException("cannot detect protocol")
|
raise StcProtocolException("cannot detect protocol")
|
||||||
@ -263,8 +263,7 @@ def cli():
|
|||||||
exclusives.add_argument("-e", "--erase", help="only erase flash memory", action="store_true")
|
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("-A", "--resetpin", help="pin to hold down when using --autoreset (default: DTR)",
|
parser.add_argument("-A", "--resetpin", help="pin to hold down when using --autoreset (default: DTR)",
|
||||||
choices=["dtr", "rts"], default="dtr")
|
choices=["dtr", "rts", "dtr_inverted", "rts_inverted"], default="dtr")
|
||||||
parser.add_argument("-i", "--invertreset", help="invert autoreset pin logic", 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)",
|
||||||
choices=["stc89", "stc89a", "stc12a", "stc12b", "stc12", "stc15a", "stc15", "stc8", "stc8d", "stc8g", "usb15", "auto"], default="auto")
|
choices=["stc89", "stc89a", "stc12a", "stc12b", "stc12", "stc15a", "stc15", "stc8", "stc8d", "stc8g", "usb15", "auto"], default="auto")
|
||||||
|
@ -269,21 +269,26 @@ class StcBaseProtocol(ABC):
|
|||||||
if not resetcmd:
|
if not resetcmd:
|
||||||
print("Cycling power: ", end="")
|
print("Cycling power: ", end="")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
# If invertreset is enabled, start with pin at low
|
|
||||||
pin_state = False if invertreset else True
|
|
||||||
|
|
||||||
if resetpin == "rts":
|
if resetpin == "rts":
|
||||||
self.ser.setRTS(pin_state)
|
self.ser.setRTS(True)
|
||||||
else:
|
elif resetpin == "dtr":
|
||||||
self.ser.setDTR(pin_state)
|
self.ser.setDTR(True)
|
||||||
|
elif resetpin == "rts_inverted":
|
||||||
|
self.ser.setRTS(False)
|
||||||
|
else: # dtr_inverted
|
||||||
|
self.ser.setDTR(False)
|
||||||
|
|
||||||
time.sleep(0.25)
|
time.sleep(0.25)
|
||||||
|
|
||||||
if resetpin == "rts":
|
if resetpin == "rts":
|
||||||
self.ser.setRTS(not pin_state)
|
self.ser.setRTS(False)
|
||||||
else:
|
elif resetpin == "dtr":
|
||||||
self.ser.setDTR(not pin_state)
|
self.ser.setDTR(False)
|
||||||
|
elif resetpin == "rts_inverted":
|
||||||
|
self.ser.setRTS(True)
|
||||||
|
else: # dtr_inverted
|
||||||
|
self.ser.setDTR(True)
|
||||||
|
|
||||||
time.sleep(0.030)
|
time.sleep(0.030)
|
||||||
print("done")
|
print("done")
|
||||||
@ -294,7 +299,7 @@ class StcBaseProtocol(ABC):
|
|||||||
print("Waiting for MCU: ", end="")
|
print("Waiting for MCU: ", end="")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
def connect(self, autoreset=False, resetcmd=False, resetpin=False, invertreset=False):
|
def connect(self, autoreset=False, resetcmd=False, resetpin=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.
|
||||||
@ -313,7 +318,7 @@ class StcBaseProtocol(ABC):
|
|||||||
self.ser.flushInput()
|
self.ser.flushInput()
|
||||||
|
|
||||||
if autoreset:
|
if autoreset:
|
||||||
self.reset_device(resetcmd, resetpin, invertreset)
|
self.reset_device(resetcmd, resetpin)
|
||||||
else:
|
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