Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 compatibility #5

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions stm32loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def cmdExtendedEraseMemory(self):
self.sp.write(chr(0x00))
tmp = self.sp.timeout
self.sp.timeout = 30
print "Extended erase (0x44), this can take ten seconds or more"
print ("Extended erase (0x44), this can take ten seconds or more")
self._wait_for_ask("0x44 erasing failed")
self.sp.timeout = tmp
mdebug(10, " Extended Erase memory done")
Expand Down Expand Up @@ -334,15 +334,12 @@ def writeMemory(self, addr, data):
mdebug(5, "Write %(len)d bytes at 0x%(addr)X" % {'addr': addr, 'len': 256})
self.cmdWriteMemory(addr, data[offs:offs+lng] + ([0xFF] * (256-lng)) )




def __init__(self) :
def __init__(self) :
pass


def usage():
print """Usage: %s [-hqVewvr] [-l length] [-p port] [-b baud] [-a addr] [-g addr] [file.bin]
print ("""Usage: %s [-hqVewvr] [-l length] [-p port] [-b baud] [-a addr] [-g addr] [file.bin]
-h This help
-q Quiet
-V Verbose
Expand All @@ -358,7 +355,7 @@ def usage():

./stm32loader.py -e -w -v example/main.bin

""" % sys.argv[0]
""" % sys.argv[0] )


if __name__ == "__main__":
Expand All @@ -367,7 +364,7 @@ def usage():
try:
import psyco
psyco.full()
print "Using Psyco..."
print ("Using Psyco...")
except ImportError:
pass

Expand All @@ -386,9 +383,9 @@ def usage():

try:
opts, args = getopt.getopt(sys.argv[1:], "hqVewvrp:b:a:l:g:")
except getopt.GetoptError, err:
except getopt.GetoptError as err:
# print help information and exit:
print str(err) # will print something like "option -a not recognized"
print (str(err)) # will print something like "option -a not recognized"
usage()
sys.exit(2)

Expand Down Expand Up @@ -430,7 +427,7 @@ def usage():
try:
cmd.initChip()
except:
print "Can't init. Ensure that BOOT0 is enabled and reset device"
print ("Can't init. Ensure that BOOT0 is enabled and reset device")


bootversion = cmd.cmdGet()
Expand All @@ -455,13 +452,13 @@ def usage():
if conf['verify']:
verify = cmd.readMemory(conf['address'], len(data))
if(data == verify):
print "Verification OK"
print ("Verification OK")
else:
print "Verification FAILED"
print str(len(data)) + ' vs ' + str(len(verify))
print ("Verification FAILED")
print (str(len(data)) + ' vs ' + str(len(verify)))
for i in xrange(0, len(data)):
if data[i] != verify[i]:
print hex(i) + ': ' + hex(data[i]) + ' vs ' + hex(verify[i])
print (hex(i) + ': ' + hex(data[i]) + ' vs ' + hex(verify[i]))

if not conf['write'] and conf['read']:
rdata = cmd.readMemory(conf['address'], conf['len'])
Expand Down