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

update to CC430 BSL script

parent df7f0f00
......@@ -12,14 +12,14 @@
<!-- Target configuration -->
<targetConf>
<obsIds>001 002 003 004 006 007 008 010 011 013 015 016 018 019 020 022 023 024 025 026 027 028 031 032 033</obsIds>
<obsIds>001 002 003 004 006 007 008 010 011 013 015 016 017 018 019 020 022 023 024 025 026 027 028 031 032 033</obsIds>
<voltage>3.3</voltage>
<embeddedImageId>STM32L433</embeddedImageId>
</targetConf>
<!-- Serial Service configuration -->
<serialConf>
<obsIds>001 002 003 004 006 007 008 010 011 013 015 016 018 019 020 022 023 024 025 026 027 028 031 032 033</obsIds>
<obsIds>001 002 003 004 006 007 008 010 011 013 015 016 017 018 019 020 022 023 024 025 026 027 028 031 032 033</obsIds>
<port>serial</port>
<baudrate>115200</baudrate>
<mode>ascii</mode>
......@@ -28,7 +28,7 @@
<!-- GPIO Tracing Service configuration -->
<gpioTracingConf>
<obsIds>001 002 003 004 006 007 008 010 011 013 015 016 018 019 020 022 023 024 025 026 027 028 031 032 033</obsIds>
<obsIds>001 002 003 004 006 007 008 010 011 013 015 016 017 018 019 020 022 023 024 025 026 027 028 031 032 033</obsIds>
<pinConf>
<pin>INT1</pin>
<edge>both</edge>
......@@ -58,7 +58,7 @@
<!-- GPIO Actuation Service configuration -->
<!--<gpioActuationConf>
<obsIds>001 002 003 004 006 007 008 010 011 013 015 016 018 019 020 022 023 024 025 026 027 028 031 032 033</obsIds>
<obsIds>001 002 003 004 006 007 008 010 011 013 015 016 017 018 019 020 022 023 024 025 026 027 028 031 032 033</obsIds>
<pinConf>
<pin>SIG1</pin>
<level>low</level>
......
......@@ -24,7 +24,14 @@ import time
resetAfterProgram = True
def getFirstPort(printPorts):
def listAvailablePorts():
print("available serial ports:")
ports = [p for p in serial.tools.list_ports.comports()]
for p in sorted(ports):
print("%s" % p)
def getDPPDevBoardPort(printPorts):
ports = [p for p in serial.tools.list_ports.comports() if "Dual RS232" in p[1]]
if printPorts:
for p in sorted(ports):
......@@ -34,6 +41,16 @@ def getFirstPort(printPorts):
return sorted(ports)[1][0]
def getMSPFETPort(printPorts):
ports = [p for p in serial.tools.list_ports.comports() if "MSP Debug" in p[1]]
if printPorts:
for p in sorted(ports):
print("%s" % p)
if ports is None or len(ports) == 0:
return None
return sorted(ports)[0][0]
def checkSerialPort(serialPort):
try:
ser = serial.Serial(port=serialPort, baudrate=115200)
......@@ -59,7 +76,31 @@ def resetMCU(serialPort):
print("failed to connect to serial port " + serialPort)
def programWithMSPFET(serialPort, fileName):
if "LD_LIBRARY_PATH" in os.environ:
cmd = "mspdebug tilib 'prog " + fileName + "' --allow-fw-update"
if serialPort:
cmd += " -d " + serialPort
ret = subprocess.call(cmd, shell=True)
if ret == 0:
return True
print("failed")
else:
print("can't use MSP-FET, LD_LIBRARY_PATH not defined")
return False
def programWithBSL(serialPort, fileName):
print("connecting to serial port %s" % serialPort)
ret = subprocess.call(['python', '-m', 'msp430.bsl5.uart', '-p', serialPort, '--invert-reset', '-e', '-S', '-s', '115200' , '-P', fileName, '-V'])
if ret == 0:
return True
print("failed")
return False
if __name__ == "__main__":
# check arguments
if len(sys.argv) < 2:
print("no filename provided\r\nusage: ./" + os.path.basename(__file__) + " [filename] [port (optional)]")
sys.exit()
......@@ -67,18 +108,30 @@ if __name__ == "__main__":
if not os.path.isfile(fileName):
print("file '%s' not found" % fileName)
sys.exit()
# determine the serial port
if len(sys.argv) > 2:
# 2nd argument is supposed to be the serial port
serialPort = sys.argv[2]
else:
serialPort = getFirstPort(False)
# prefer the MSP-FET
serialPort = getMSPFETPort(False)
if serialPort is None:
print("no DPP2 DevBoard found")
sys.exit()
if not checkSerialPort(serialPort):
sys.exit()
print("connecting to serial port %s" % serialPort)
subprocess.call(['python', '-m', 'msp430.bsl5.uart', '-p', serialPort, '--invert-reset', '-e', '-S', '-s', '115200' , '-P', fileName])
# no MSP-FET found, try to find a DPP DevBoard
serialPort = getDPPDevBoardPort(False)
if serialPort is None:
print("no connected device found")
listAvailablePorts()
sys.exit() # abort
# do the target programming
if "USB" in serialPort:
if checkSerialPort(serialPort):
if not programWithBSL(serialPort, fileName):
listAvailablePorts()
# reset the target
if resetAfterProgram:
resetMCU(serialPort)
else:
if not programWithMSPFET(serialPort, fileName):
listAvailablePorts()
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