Extract mix-ins for STC12 and STC12A options
This simplifies code down the line. No functional change intended.
This commit is contained in:
parent
979d7f513f
commit
d6ef028dc7
@ -529,7 +529,37 @@ class Stc89Protocol(StcBaseProtocol):
|
|||||||
print("done")
|
print("done")
|
||||||
|
|
||||||
|
|
||||||
class Stc12AProtocol(Stc89Protocol):
|
class Stc12AOptionsMixIn:
|
||||||
|
def program_options(self):
|
||||||
|
print("Setting options: ", end="")
|
||||||
|
sys.stdout.flush()
|
||||||
|
msr = self.options.get_msr()
|
||||||
|
packet = bytes([0x8d, msr[0], msr[1], msr[2], 0xff, msr[3]])
|
||||||
|
packet += struct.pack(">I", int(self.mcu_clock_hz))
|
||||||
|
packet += bytes([msr[3]])
|
||||||
|
packet += bytes([0xff, msr[0], msr[1], 0xff, 0xff, 0xff, 0xff, msr[2]])
|
||||||
|
packet += bytes([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])
|
||||||
|
packet += struct.pack(">I", int(self.mcu_clock_hz))
|
||||||
|
packet += bytes([0xff, 0xff, 0xff])
|
||||||
|
|
||||||
|
self.write_packet(packet)
|
||||||
|
response = self.read_packet()
|
||||||
|
if response[0] != 0x80:
|
||||||
|
raise StcProtocolException("incorrect magic in option packet")
|
||||||
|
|
||||||
|
# XXX: this is done by STC-ISP on newer parts. not sure why, but let's
|
||||||
|
# just replicate it, just to be sure.
|
||||||
|
if self.bsl_version >= 0x66:
|
||||||
|
packet = bytes([0x50])
|
||||||
|
self.write_packet(packet)
|
||||||
|
response = self.read_packet()
|
||||||
|
if response[0] != 0x10:
|
||||||
|
raise StcProtocolException("incorrect magic in option packet")
|
||||||
|
|
||||||
|
print("done")
|
||||||
|
|
||||||
|
|
||||||
|
class Stc12AProtocol(Stc12AOptionsMixIn, Stc89Protocol):
|
||||||
|
|
||||||
"""countdown value for flash erase"""
|
"""countdown value for flash erase"""
|
||||||
ERASE_COUNTDOWN = 0x0d
|
ERASE_COUNTDOWN = 0x0d
|
||||||
@ -650,37 +680,34 @@ class Stc12AProtocol(Stc89Protocol):
|
|||||||
raise StcProtocolException("incorrect magic in erase packet")
|
raise StcProtocolException("incorrect magic in erase packet")
|
||||||
print("done")
|
print("done")
|
||||||
|
|
||||||
|
|
||||||
|
class Stc12OptionsMixIn:
|
||||||
def program_options(self):
|
def program_options(self):
|
||||||
print("Setting options: ", end="")
|
print("Setting options: ", end="")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
msr = self.options.get_msr()
|
msr = self.options.get_msr()
|
||||||
packet = bytes([0x8d, msr[0], msr[1], msr[2], 0xff, msr[3]])
|
# XXX: it's not 100% clear if the index of msr[3] is consistent
|
||||||
packet += struct.pack(">I", int(self.mcu_clock_hz))
|
# between devices, so write it to both indices.
|
||||||
packet += bytes([msr[3]])
|
packet = bytes([0x8d, msr[0], msr[1], msr[2], msr[3],
|
||||||
packet += bytes([0xff, msr[0], msr[1], 0xff, 0xff, 0xff, 0xff, msr[2]])
|
0xff, 0xff, 0xff, 0xff, msr[3], 0xff,
|
||||||
packet += bytes([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff])
|
||||||
packet += struct.pack(">I", int(self.mcu_clock_hz))
|
|
||||||
packet += bytes([0xff, 0xff, 0xff])
|
|
||||||
|
|
||||||
|
packet += struct.pack(">I", int(self.mcu_clock_hz))
|
||||||
self.write_packet(packet)
|
self.write_packet(packet)
|
||||||
response = self.read_packet()
|
response = self.read_packet()
|
||||||
if response[0] != 0x80:
|
if response[0] != 0x50:
|
||||||
raise StcProtocolException("incorrect magic in option packet")
|
raise StcProtocolException("incorrect magic in option packet")
|
||||||
|
|
||||||
# XXX: this is done by STC-ISP on newer parts. not sure why, but let's
|
|
||||||
# just replicate it, just to be sure.
|
|
||||||
if self.bsl_version >= 0x66:
|
|
||||||
packet = bytes([0x50])
|
|
||||||
self.write_packet(packet)
|
|
||||||
response = self.read_packet()
|
|
||||||
if response[0] != 0x10:
|
|
||||||
raise StcProtocolException("incorrect magic in option packet")
|
|
||||||
|
|
||||||
print("done")
|
print("done")
|
||||||
|
|
||||||
|
# If UID wasn't sent with erase acknowledge, it should be in this packet
|
||||||
|
if not self.uid:
|
||||||
|
self.uid = response[18:25]
|
||||||
|
|
||||||
class Stc12Protocol(StcBaseProtocol):
|
print("Target UID: %s" % Utils.hexstr(self.uid))
|
||||||
"""Protocol handler for STC 10/11/12 series"""
|
|
||||||
|
|
||||||
|
class Stc12BaseProtocol(StcBaseProtocol):
|
||||||
|
"""Base class for STC 10/11/12 series protocol handlers"""
|
||||||
|
|
||||||
"""block size for programming flash"""
|
"""block size for programming flash"""
|
||||||
PROGRAM_BLOCKSIZE = 128
|
PROGRAM_BLOCKSIZE = 128
|
||||||
@ -742,6 +769,8 @@ class Stc12Protocol(StcBaseProtocol):
|
|||||||
self.mcu_bsl_version = "%d.%d%s" % (bl_version >> 4, bl_version & 0x0f,
|
self.mcu_bsl_version = "%d.%d%s" % (bl_version >> 4, bl_version & 0x0f,
|
||||||
chr(bl_stepping))
|
chr(bl_stepping))
|
||||||
|
|
||||||
|
self.bsl_version = bl_version
|
||||||
|
|
||||||
def calculate_baud(self):
|
def calculate_baud(self):
|
||||||
"""Calculate MCU baudrate setting.
|
"""Calculate MCU baudrate setting.
|
||||||
|
|
||||||
@ -877,28 +906,13 @@ class Stc12Protocol(StcBaseProtocol):
|
|||||||
raise StcProtocolException("incorrect magic in finish packet")
|
raise StcProtocolException("incorrect magic in finish packet")
|
||||||
print("done")
|
print("done")
|
||||||
|
|
||||||
def program_options(self):
|
|
||||||
print("Setting options: ", end="")
|
|
||||||
sys.stdout.flush()
|
|
||||||
msr = self.options.get_msr()
|
|
||||||
# XXX: it's not 100% clear if the index of msr[3] is consistent
|
|
||||||
# between devices, so write it to both indices.
|
|
||||||
packet = bytes([0x8d, msr[0], msr[1], msr[2], msr[3],
|
|
||||||
0xff, 0xff, 0xff, 0xff, msr[3], 0xff,
|
|
||||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff])
|
|
||||||
|
|
||||||
packet += struct.pack(">I", int(self.mcu_clock_hz))
|
class Stc12Protocol(Stc12OptionsMixIn, Stc12BaseProtocol):
|
||||||
self.write_packet(packet)
|
"""STC 10/11/12 series protocol handler"""
|
||||||
response = self.read_packet()
|
|
||||||
if response[0] != 0x50:
|
|
||||||
raise StcProtocolException("incorrect magic in option packet")
|
|
||||||
print("done")
|
|
||||||
|
|
||||||
# If UID wasn't sent with erase acknowledge, it should be in this packet
|
def __init__(self, port, handshake, baud):
|
||||||
if not self.uid:
|
Stc12BaseProtocol.__init__(self, port, handshake, baud)
|
||||||
self.uid = response[18:25]
|
|
||||||
|
|
||||||
print("Target UID: %s" % Utils.hexstr(self.uid))
|
|
||||||
|
|
||||||
|
|
||||||
class Stc15AProtocol(Stc12Protocol):
|
class Stc15AProtocol(Stc12Protocol):
|
||||||
|
Loading…
Reference in New Issue
Block a user