aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Hope <michael.hope@linaro.org>2010-09-29 20:01:10 +1300
committerMichael Hope <michael.hope@linaro.org>2010-09-29 20:01:10 +1300
commit1169dc6e3b34daf85e5b30183b8fc2979ab952ca (patch)
treea46df903bba9c4d6fabd7f93cd7edc5ed1583c07
parent208e35e7d704467cb04b054e3fc32acf82be9e49 (diff)
downloadlibrambutan-1169dc6e3b34daf85e5b30183b8fc2979ab952ca.tar.gz
librambutan-1169dc6e3b34daf85e5b30183b8fc2979ab952ca.zip
Added auto detection of the USB to serial port under Linux and MacOS.
-rwxr-xr-xsupport/stm32loader.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/support/stm32loader.py b/support/stm32loader.py
index f717c9a..d8e1f9f 100755
--- a/support/stm32loader.py
+++ b/support/stm32loader.py
@@ -25,6 +25,7 @@
import sys, getopt
import serial
import time
+import glob
try:
from progressbar import *
@@ -314,7 +315,7 @@ def usage():
-v Verify
-r Read
-l length Length of read
- -p port Serial port (default: /dev/tty.usbserial-ftCYPMYJ)
+ -p port Serial port (default: first USB-like port in /dev)
-b baud Baud speed (default: 115200)
-a addr Target address
@@ -334,7 +335,7 @@ if __name__ == "__main__":
pass
conf = {
- 'port': '/dev/tty.usbserial-FTD3TMCH',
+ 'port': 'auto',
'baud': 115200,
'address': 0x08000000,
'erase': 0,
@@ -386,6 +387,20 @@ if __name__ == "__main__":
else:
assert False, "unhandled option"
+ # Try and find the port automatically
+ if conf['port'] == 'auto':
+ ports = []
+
+ # Get a list of all USB-like names in /dev
+ for name in ['tty.usbserial', 'ttyUSB']:
+ ports.extend(glob.glob('/dev/%s*' % name))
+
+ ports = sorted(ports)
+
+ if ports:
+ # Found something - take it
+ conf['port'] = ports[0]
+
cmd = CommandInterface()
cmd.open(conf['port'], conf['baud'])
mdebug(10, "Open port %(port)s, baud %(baud)d" % {'port':conf['port'], 'baud':conf['baud']})