Skip to content
Snippets Groups Projects
Commit e443b908 authored by kYc0o's avatar kYc0o Committed by GitHub
Browse files

Merge pull request #5452 from locicontrols/find-tty

Adjust find-tty.sh to return all matches, then use it in boards/cc2538dk
parents 51a4fee9 9faf55a2
No related branches found
No related tags found
No related merge requests found
...@@ -2,8 +2,12 @@ ...@@ -2,8 +2,12 @@
export CPU = cc2538 export CPU = cc2538
export CPU_MODEL ?= cc2538nf53 export CPU_MODEL ?= cc2538nf53
# the SmartRF06 Evaluation Board serial numbers all begin with "06EB":
export PROGRAMMER_SERIAL ?= 06EB
# setup serial terminal # setup serial terminal
PORT_LINUX ?= $(firstword $(wildcard /dev/serial/by-id/*XDS100v3*if01* /dev/ttyUSB1)) # the debug UART is always the second tty with the matching serial number:
PORT_LINUX ?= $(word 2,$(shell $(RIOTBASE)/dist/tools/usb-serial/find-tty.sh '^$(PROGRAMMER_SERIAL)'))
PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbserial*))) PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbserial*)))
include $(RIOTBOARD)/Makefile.include.serial include $(RIOTBOARD)/Makefile.include.serial
......
...@@ -76,10 +76,10 @@ ifeq ($(PORT),) ...@@ -76,10 +76,10 @@ ifeq ($(PORT),)
# try to find tty name by serial number, only works on Linux currently. # try to find tty name by serial number, only works on Linux currently.
ifeq ($(OS),Linux) ifeq ($(OS),Linux)
ifneq ($(PROGRAMMER_SERIAL),) ifneq ($(PROGRAMMER_SERIAL),)
PORT := $(shell $(RIOTBASE)/dist/tools/usb-serial/find-tty.sh '^$(PROGRAMMER_SERIAL)$$') PORT := $(firstword $(shell $(RIOTBASE)/dist/tools/usb-serial/find-tty.sh '^$(PROGRAMMER_SERIAL)$$'))
else else
# find-tty.sh will return the first USB tty if no serial is given. # find-tty.sh will return the first USB tty if no serial is given.
PORT := $(shell $(RIOTBASE)/dist/tools/usb-serial/find-tty.sh) PORT := $(firstword $(shell $(RIOTBASE)/dist/tools/usb-serial/find-tty.sh))
endif endif
else ifeq ($(OS),Darwin) else ifeq ($(OS),Darwin)
ifneq ($(PROGRAMMER_SERIAL),) ifneq ($(PROGRAMMER_SERIAL),)
......
...@@ -34,7 +34,7 @@ include $(RIOTBOARD)/$(BOARD)/Makefile.dep ...@@ -34,7 +34,7 @@ include $(RIOTBOARD)/$(BOARD)/Makefile.dep
# Usage: SERIAL="0200..." BOARD="pba-d-01-kw2x" make flash # Usage: SERIAL="0200..." BOARD="pba-d-01-kw2x" make flash
ifneq (,$(SERIAL)) ifneq (,$(SERIAL))
export OPENOCD_EXTRA_INIT += "-c cmsis_dap_serial $(SERIAL)" export OPENOCD_EXTRA_INIT += "-c cmsis_dap_serial $(SERIAL)"
SERIAL_TTY = $(shell $(RIOTBASE)/dist/tools/usb-serial/find-tty.sh $(SERIAL)) SERIAL_TTY = $(firstword $(shell $(RIOTBASE)/dist/tools/usb-serial/find-tty.sh $(SERIAL)))
ifeq (,$(SERIAL_TTY)) ifeq (,$(SERIAL_TTY))
$(error Did not find a device with serial $(SERIAL)) $(error Did not find a device with serial $(SERIAL))
endif endif
......
...@@ -17,7 +17,7 @@ include $(RIOTBOARD)/Makefile.include.serial ...@@ -17,7 +17,7 @@ include $(RIOTBOARD)/Makefile.include.serial
# Usage: SERIAL="ATML..." BOARD="samr21-xpro" make flash # Usage: SERIAL="ATML..." BOARD="samr21-xpro" make flash
ifneq (,$(SERIAL)) ifneq (,$(SERIAL))
export OPENOCD_EXTRA_INIT += "-c cmsis_dap_serial $(SERIAL)" export OPENOCD_EXTRA_INIT += "-c cmsis_dap_serial $(SERIAL)"
SERIAL_TTY = $(shell $(RIOTBASE)/dist/tools/usb-serial/find-tty.sh $(SERIAL)) SERIAL_TTY = $(firstword $(shell $(RIOTBASE)/dist/tools/usb-serial/find-tty.sh $(SERIAL)))
ifeq (,$(SERIAL_TTY)) ifeq (,$(SERIAL_TTY))
$(error Did not find a device with serial $(SERIAL)) $(error Did not find a device with serial $(SERIAL))
endif endif
......
...@@ -13,15 +13,15 @@ List all currently connected USB to serial adapters by searching through ...@@ -13,15 +13,15 @@ List all currently connected USB to serial adapters by searching through
./find-tty.sh [serial_regex1] [serial_regex2] ... [serial_regexZ] ./find-tty.sh [serial_regex1] [serial_regex2] ... [serial_regexZ]
Write to `stdout` the first tty connected to the chosen programmer. Write to `stdout` all ttys connected to the chosen programmer.
`serial_regexN` are extended regular expressions (as understood by `egrep`) `serial_regexN` are extended regular expressions (as understood by `egrep`)
containing a pattern matched against the USB device serial number. Each of the containing a pattern matched against the USB device serial number. Each of the
given expressions are tested, against each serial number until a match has been given expressions are tested, against each serial number, and matching ttys are
found. output (one tty per line).
In order to search for an exact match against the device serial, use In order to search for an exact match against the device serial, use
'^serialnumber$' as the pattern. If no pattern is given, `find-tty.sh` returns '^serialnumber$' as the pattern. If no pattern is given, `find-tty.sh` returns
the first found USB tty (in an arbitrary order, this is not guaranteed to be all found USB ttys (in an arbitrary order, this is not guaranteed to be
the `/dev/ttyUSBX` with the lowest number). the `/dev/ttyUSBX` with the lowest number).
Serial strings from all connected USB ttys can be found from the list generated Serial strings from all connected USB ttys can be found from the list generated
...@@ -45,7 +45,7 @@ solution): ...@@ -45,7 +45,7 @@ solution):
ifeq ($(PORT),) ifeq ($(PORT),)
# try to find tty name by serial number, only works on Linux currently. # try to find tty name by serial number, only works on Linux currently.
ifeq ($(OS),Linux) ifeq ($(OS),Linux)
PORT := $(shell $(RIOTBASE)/dist/tools/usb-serial/find-tty.sh "^$(PROGRAMMER_SERIAL)$$") PORT := $(firstword $(shell $(RIOTBASE)/dist/tools/usb-serial/find-tty.sh "^$(PROGRAMMER_SERIAL)$$"))
endif endif
endif endif
endif endif
...@@ -53,7 +53,7 @@ solution): ...@@ -53,7 +53,7 @@ solution):
# Fallback PORT if no serial was specified or if the specified serial was not found # Fallback PORT if no serial was specified or if the specified serial was not found
ifeq ($(PORT),) ifeq ($(PORT),)
ifeq ($(OS),Linux) ifeq ($(OS),Linux)
PORT := $(shell $(RIOTBASE)/dist/tools/usb-serial/find-tty.sh) PORT := $(firstword $(shell $(RIOTBASE)/dist/tools/usb-serial/find-tty.sh))
else ifeq ($(OS),Darwin) else ifeq ($(OS),Darwin)
PORT := $(shell ls -1 /dev/tty.SLAB_USBtoUART* | head -n 1) PORT := $(shell ls -1 /dev/tty.SLAB_USBtoUART* | head -n 1)
endif endif
......
...@@ -9,35 +9,38 @@ ...@@ -9,35 +9,38 @@
# #
# Find all USB to serial devices # Find all USB to serial devices
# default error status code
status=1
# iterate over usb-tty devices: # iterate over usb-tty devices:
for basedev in $(find /sys/bus/usb/devices/ -regex "/sys/bus/usb/devices/[0-9]+[^:/]*" -maxdepth 2 -follow 2>/dev/null); do for basedev in $(find /sys/bus/usb/devices/ -regex "/sys/bus/usb/devices/[0-9]+[^:/]*" -maxdepth 2 -follow 2>/dev/null); do
ttydirs=$(find ${basedev} -regex "${basedev}/[^/]*:.*" -mindepth 2 -maxdepth 3 -name tty -follow 2>/dev/null) ttydirs=$(find ${basedev} -regex "${basedev}/[^/]*:.*" -mindepth 2 -maxdepth 3 -name tty -follow 2>/dev/null)
if [ -z "${ttydirs}" ]; then if [ -z "${ttydirs}" ]; then
continue continue
fi fi
# See if the device has any tty devices assigned to it, get the first match # See if the device has any tty devices assigned to it
tty=$(find ${ttydirs} -maxdepth 1 -mindepth 1 -printf '%f\n' | head -n 1 2>/dev/null) for tty in $(find ${ttydirs} -maxdepth 1 -mindepth 1 -printf '%f\n' 2>/dev/null); do
if [ -z "${tty}" ]; then parent=$(echo ${basedev} | sed -e 's%\(/sys/bus/usb/devices/[^/]*\)/.*%\1%')
continue serial=$(cat "${parent}/serial" 2>/dev/null)
fi # split results into array
parent=$(echo ${basedev} | sed -e 's%\(/sys/bus/usb/devices/[^/]*\)/.*%\1%')
serial=$(cat "${parent}/serial" 2>/dev/null)
# split results into array
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
# No arguments given, return first found tty # No arguments given, return all ttys
echo "/dev/${tty}"
exit 0
fi
# else: Match any of the given serials
for s in "${@}"; do
echo "${serial}" | egrep -e "${s}" -q
if [ $? -eq 0 ]; then
# return first tty
echo "/dev/${tty}" echo "/dev/${tty}"
exit 0 status=0
continue
fi fi
# else: Match any of the given serials
for s in "${@}"; do
echo "${serial}" | egrep -e "${s}" -q
if [ $? -eq 0 ]; then
# return tty
echo "/dev/${tty}"
status=0
fi
done
done done
done done
# not found
exit 1; exit $status;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment