Commit eb965fe5 authored by Reto Da Forno's avatar Reto Da Forno
Browse files

scripts updated

parent 106541dc
#!/usr/bin/env python3
'''
Print the serial output of the CC430 MCU.
last update: 2018-09-24
author: rdaforno
Print the DPP serial output.
'''
......@@ -45,7 +42,7 @@ def serial_read(serialPort):
try:
ser = serial.Serial(port=serialPort, baudrate=baudRate, timeout=None)
if ser.isOpen():
print "connected to " + ser.portstr + " (" + str(ser.baudrate) + ")"
print("connected to " + ser.portstr + " (" + str(ser.baudrate) + ")")
ser.setRTS(True) # pull TEST / BSL entry line
ser.setDTR(False) # release reset line
ser.flushInput() # flush input and output buffers
......@@ -53,20 +50,17 @@ def serial_read(serialPort):
while True:
if ser.inWaiting() > 0:
line = ser.read(ser.inWaiting())
sys.stdout.write(line)
sys.stdout.write(line.decode('utf8'))
sys.stdout.flush()
time.sleep(0.01)
except SerialException:
print "device %s unavailable" % serialPort
print("device %s unavailable" % serialPort)
except ValueError:
print "invalid arguments"
print("invalid arguments")
except OSError:
print "device %s not found" % serialPort
print("device %s not found" % serialPort)
except KeyboardInterrupt:
print "aborted"
except:
type, value, tb = sys.exc_info()
print "error: %s (%s)" % (value.message, type)
print("aborted")
if ser.isOpen():
ser.close()
......@@ -76,10 +70,18 @@ if __name__ == "__main__":
# 1st argument is supposed to be the serial port
serialPort = sys.argv[1]
else:
serialPort = getFirstPort(False)
if serialPort is None:
print("no DPP2 DevBoard found")
sys.exit()
serialPort = getFirstPort(False)
if serialPort is None:
print("no DPP2 DevBoard found")
sys.exit(1)
if len(sys.argv) > 2:
try:
baudRate = int(sys.argv[2])
except:
print("invalid baudrate %s" % sys.argv[2])
sys.exit(1)
if not checkSerialPort(serialPort):
sys.exit()
sys.exit(1)
serial_read(serialPort)
......@@ -63,18 +63,46 @@ def programSTM32(fileName, serialPort):
loader.reset()
def convertFile(fileName):
f, ext = os.path.splitext(fileName)
if ext.lower() in ('.elf', '.exe', '.out'):
# 3rd argument (if provided) is the node ID -> can only be embedded into elf file
if len(sys.argv) > 3:
try:
nodeID = int(sys.argv[3])
# use tos-set-symbols to set the node ID and convert to Intel hex
if os.system("tos-set-symbols --objcopy objcopy --objdump objdump --target ihex %s %s.hex FLOCKLAB_NODE_ID=%d" % (fileName, fileName, nodeID)) != 0:
print("failed to set node ID (tos-set-symbols missing?)")
else:
print("node ID set to %d" % nodeID)
except:
print("invalid node ID %s" % sys.argv[3])
sys.exit(1)
else:
# convert to Intel hex
os.system("objcopy -O ihex %s %s.hex" % (fileName, fileName))
print("file converted to Intel hex format")
fileName = fileName + ".hex"
ext = ".hex"
if ext.lower() in ('.hex', '.ihex'):
hex2bin(fileName, fileName + ".binary")
fileName = fileName + ".binary"
print("file converted to binary format")
return fileName
if __name__ == "__main__":
if len(sys.argv) < 2:
print("no filename provided\r\nusage: ./" + os.path.basename(__file__) + " [filename] [port (optional)]")
sys.exit()
sys.exit(1)
fileName = sys.argv[1]
if not os.path.isfile(fileName):
print("file '%s' not found" % fileName)
sys.exit()
f, ext = os.path.splitext(fileName)
if "hex" in ext:
hex2bin(fileName, fileName + ".binary")
fileName = fileName + ".binary"
sys.exit(1)
fileName = convertFile(fileName)
if len(sys.argv) > 2:
# 2nd argument is supposed to be the serial port
......@@ -83,7 +111,8 @@ if __name__ == "__main__":
serialPort = getFirstPort(False)
if serialPort is None:
print("no DPP2 DevBoard found")
sys.exit()
sys.exit(1)
print("connecting to serial port %s" % serialPort)
programSTM32(fileName, serialPort)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment