fix: remove trailing semicolon

This commit is contained in:
Rotzbua 2024-04-23 23:15:26 +02:00 committed by Victor
parent 9aecdb738b
commit 39b3dc5782

View file

@ -2,8 +2,8 @@
# rdwr_phy62x2.py 11.01.2024 pvvx # # rdwr_phy62x2.py 11.01.2024 pvvx #
import serial; import serial
import time; import time
import argparse import argparse
import io import io
import os import os
@ -88,15 +88,15 @@ class phyflasher:
self.hexf.sec.extend(bytearray(struct.pack('<IIII', phy_head[secn][0], size, addr, 0xffffffff))) self.hexf.sec.extend(bytearray(struct.pack('<IIII', phy_head[secn][0], size, addr, 0xffffffff)))
return self.hexf return self.hexf
def write_cmd(self, pkt): def write_cmd(self, pkt):
self._port.write(pkt.encode()); self._port.write(pkt.encode())
read = self._port.read(6); read = self._port.read(6)
return read == b'#OK>>:' return read == b'#OK>>:'
def SendResetCmd(self): def SendResetCmd(self):
return self._port.write(str.encode('reset ')); return self._port.write(str.encode('reset '))
def read_reg(self, addr): def read_reg(self, addr):
pkt = 'rdreg%08x' % addr; pkt = 'rdreg%08x' % addr
sent = self._port.write(pkt.encode()); sent = self._port.write(pkt.encode())
read = self._port.read(17); read = self._port.read(17)
if len(read) == 17 and read[0:3] == b'=0x' and read[11:17] == b'#OK>>:': if len(read) == 17 and read[0:3] == b'=0x' and read[11:17] == b'#OK>>:':
return int(read[1:11], 16) return int(read[1:11], 16)
return None return None
@ -124,13 +124,13 @@ class phyflasher:
if mbit > 0: if mbit > 0:
regcmd = regcmd | 0x40000 regcmd = regcmd | 0x40000
if dummy > 0: if dummy > 0:
regcmd = regcmd | (dummy << 7); regcmd = regcmd | (dummy << 7)
if not self.write_reg(0x4000c890, regcmd | 1): if not self.write_reg(0x4000c890, regcmd | 1):
print('Error write Flash Command Register!') print('Error write Flash Command Register!')
return False return False
return True return True
def flash_wait_idle(self): def flash_wait_idle(self):
i = 5; i = 5
while i > 0: while i > 0:
r = self.read_reg(0x4000c890) r = self.read_reg(0x4000c890)
if r == None: if r == None:
@ -179,9 +179,9 @@ class phyflasher:
return self.wr_flash_cmd(6) and self.wr_flash_cmd(1, 0, 1) return self.wr_flash_cmd(6) and self.wr_flash_cmd(1, 0, 1)
def ReadRevision(self): def ReadRevision(self):
#0x001364c8 6222M005 #OK>>: #0x001364c8 6222M005 #OK>>:
self._port.write(str.encode('rdrev+ ')); self._port.write(str.encode('rdrev+ '))
self._port.timeout = 0.1 self._port.timeout = 0.1
read = self._port.read(26); read = self._port.read(26)
if len(read) == 26 and read[0:2] == b'0x' and read[20:26] == b'#OK>>:': if len(read) == 26 and read[0:2] == b'0x' and read[20:26] == b'#OK>>:':
print('Revision:', read[2:19]) print('Revision:', read[2:19])
if read[11:15] != b'6222': if read[11:15] != b'6222':
@ -196,9 +196,9 @@ class phyflasher:
def SetBaud(self, baud): def SetBaud(self, baud):
if self._port.baudrate != baud: if self._port.baudrate != baud:
print ('Reopen %s port %i baud...' % (self.port, baud), end = ' '), print ('Reopen %s port %i baud...' % (self.port, baud), end = ' '),
self._port.write(str.encode("uarts%i" % baud)); self._port.write(str.encode("uarts%i" % baud))
self._port.timeout = 1 self._port.timeout = 1
read = self._port.read(3); read = self._port.read(3)
if read == b'#OK': if read == b'#OK':
print ('ok') print ('ok')
self.baud = baud self.baud = baud
@ -227,12 +227,12 @@ class phyflasher:
self._port.setDTR(False) #TM (hi) self._port.setDTR(False) #TM (hi)
self._port.setRTS(False) #RSTN (hi) self._port.setRTS(False) #RSTN (hi)
self._port.timeout = 0.04 self._port.timeout = 0.04
ttcl = 50; ttcl = 50
fct_mode = False fct_mode = False
pkt = 'UXTDWU' # UXTL16 UDLL48 UXTDWU pkt = 'UXTDWU' # UXTL16 UDLL48 UXTDWU
while ttcl > 0: while ttcl > 0:
sent = self._port.write(pkt.encode()); sent = self._port.write(pkt.encode())
read = self._port.read(6); read = self._port.read(6)
if read == b'cmd>>:' : if read == b'cmd>>:' :
break break
if read == b'fct>>:' : if read == b'fct>>:' :
@ -317,7 +317,7 @@ class phyflasher:
def cmd_erase_all_flash(self): def cmd_erase_all_flash(self):
print ('Erase All Chip Flash...', end = ' '), print ('Erase All Chip Flash...', end = ' '),
if self.wr_flash_cmd(6) and self.wr_flash_cmd(0x60): #Write Enable, Chip Erase if self.wr_flash_cmd(6) and self.wr_flash_cmd(0x60): #Write Enable, Chip Erase
i = 77; i = 77
while i > 0: while i > 0:
r = self.flash_read_status() r = self.flash_read_status()
if r == None: if r == None:
@ -387,7 +387,7 @@ class phyflasher:
return False return False
data = stream.read(size) data = stream.read(size)
self._port.write(data) self._port.write(data)
read = self._port.read(23); #'checksum is: 0x00001d1e' read = self._port.read(23) #'checksum is: 0x00001d1e'
#print ('%s' % read), #print ('%s' % read),
if read[0:15] != b'checksum is: 0x': if read[0:15] != b'checksum is: 0x':
print ('error!') print ('error!')
@ -510,14 +510,14 @@ def arg_auto_int(x):
def main(): def main():
parser = argparse.ArgumentParser(description='%s version %s' % (__progname__, __version__), prog = __filename__) parser = argparse.ArgumentParser(description='%s version %s' % (__progname__, __version__), prog = __filename__)
parser.add_argument('--port', '-p', help = 'Serial port device', default='COM1'); parser.add_argument('--port', '-p', help = 'Serial port device', default='COM1')
parser.add_argument('--baud', '-b', help = 'Set Port Baud (115200, 250000, 500000, 1000000)', type = arg_auto_int, default = DEF_RUN_BAUD); parser.add_argument('--baud', '-b', help = 'Set Port Baud (115200, 250000, 500000, 1000000)', type = arg_auto_int, default = DEF_RUN_BAUD)
parser.add_argument('--allerase', '-a', action='store_true', help = 'Pre-processing: All Chip Erase'); parser.add_argument('--allerase', '-a', action='store_true', help = 'Pre-processing: All Chip Erase')
parser.add_argument('--erase', '-e', action='store_true', help = 'Pre-processing: Erase Flash work area'); parser.add_argument('--erase', '-e', action='store_true', help = 'Pre-processing: Erase Flash work area')
parser.add_argument('--reset', '-r', action='store_true', help = 'Post-processing: Reset'); parser.add_argument('--reset', '-r', action='store_true', help = 'Post-processing: Reset')
parser.add_argument('--start', '-s', help = 'Application start address for hex writer (default: 0x%08x)' % DEF_START_RUN_APP_ADDR, type = arg_auto_int, default = DEF_START_RUN_APP_ADDR); parser.add_argument('--start', '-s', help = 'Application start address for hex writer (default: 0x%08x)' % DEF_START_RUN_APP_ADDR, type = arg_auto_int, default = DEF_START_RUN_APP_ADDR)
parser.add_argument('--write', '-w', help = 'Flash starting address for hex writer (default: 0x%08x)' % DEF_START_WR_FLASH_ADDR, type = arg_auto_int, default = DEF_START_WR_FLASH_ADDR); parser.add_argument('--write', '-w', help = 'Flash starting address for hex writer (default: 0x%08x)' % DEF_START_WR_FLASH_ADDR, type = arg_auto_int, default = DEF_START_WR_FLASH_ADDR)
subparsers = parser.add_subparsers( subparsers = parser.add_subparsers(
dest='operation', dest='operation',
@ -596,7 +596,7 @@ def main():
#filename = "r%08x-%08x.bin" % (addr, length) #filename = "r%08x-%08x.bin" % (addr, length)
if args.size == 0: if args.size == 0:
print("Read Size = 0!" ) print("Read Size = 0!" )
exit(1); exit(1)
try: try:
ff = open(args.filename, "wb") ff = open(args.filename, "wb")
except: except:
@ -634,7 +634,7 @@ def main():
sys.exit(1) sys.exit(1)
aerase = args.operation == 'we' aerase = args.operation == 'we'
if args.erase == True or args.allerase == True: if args.erase == True or args.allerase == True:
aerase = False; aerase = False
if args.allerase == True: if args.allerase == True:
if not phy.cmd_erase_all_flash(): if not phy.cmd_erase_all_flash():
stream.close() stream.close()
@ -672,7 +672,7 @@ def main():
print ('----------------------------------------------------------') print ('----------------------------------------------------------')
aerase = True aerase = True
if args.erase == True or args.allerase == True: if args.erase == True or args.allerase == True:
aerase = False; aerase = False
if args.allerase == True: if args.allerase == True:
if not phy.cmd_erase_all_flash(): if not phy.cmd_erase_all_flash():
stream.close() stream.close()