1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 07:32:45 +01:00
RIOT/dist/tools/usb-serial
Marian Buschsieweke 86b7159e37
dist/tools/usb-serial/ttys.py: return error on empty list
If no TTY serial (matching the given filters, if any) was found, use
the exit code `1`. The idea is that simple shell scripts falling back
to alternative variants of a board can be used via

```.sh
ttys.py --most-recent --model Fooboard --vendor Footronic || \
    ttys.py --most-recent --model Barboard --vendor Bartronic
```

Just adding a regex that would accept both vendors and models would
have different semantics: If both a Fooboard and a Barboard are
attached, it would pick the most recently connected of both. The shell
expression above would always prefer a Fooboard over a Borboard.

The use case cheap Arduino clones that replace the ATmega16U2 used
as USB UART bridge with cheap single purpose chips. The original
ATmega16U2 has the advantage that it provides identification data
unique the specific Arduino board, while the clones cannot be told
apart from standalone USB UART bridges or Arduino clones of other
models. Hence, we want to pick the genuine Arduino board if connected,
and only fall back to matching cheap USB UART bridges if no genuine
Arduino board is connected.
2022-12-09 13:00:54 +01:00
..
find-tty.sh dist: tools: let find-tty.sh return all matches, not just the first 2016-05-18 15:33:01 -04:00
list-ttys.sh usb-serial/list-ttys: Resolve shellcheck issues 2020-10-30 16:13:05 +01:00
README.md tools/usb-serial: do not advise people to export PORT. 2019-06-03 16:31:31 +02:00
ttys.py dist/tools/usb-serial/ttys.py: return error on empty list 2022-12-09 13:00:54 +01:00

USB to serial adapter tools

Tools for finding connected USB to serial adapter devices.

Usage

./list-ttys.sh

List all currently connected USB to serial adapters by searching through /sys/bus/usb/devices/.

./find-tty.sh [serial_regex1] [serial_regex2] ... [serial_regexZ]

Write to stdout all ttys connected to the chosen programmer. serial_regexN are extended regular expressions (as understood by egrep) containing a pattern matched against the USB device serial number. Each of the given expressions are tested, against each serial number, and matching ttys are output (one tty per line).

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 all found USB ttys (in an arbitrary order, this is not guaranteed to be the /dev/ttyUSBX with the lowest number).

Serial strings from all connected USB ttys can be found from the list generated by list-ttys.sh.

Exit codes

find-tty.sh returns 0 if a match is found, 1 otherwise.

Makefile example usage

The script find-tty.sh is designed for use from within a board Makefile.include. An example section is shown below (for an OpenOCD based solution):

# Add serial matching command
ifneq ($(PROGRAMMER_SERIAL),)
  OOCD_BOARD_FLAGS += -c 'ftdi_serial $(PROGRAMMER_SERIAL)'
endif

PORT_LINUX_EXACT = $(if $(PROGRAMMER_SERIAL),$(firstword $(shell $(RIOTTOOLS)/usb-serial/find-tty.sh "^$(PROGRAMMER_SERIAL)$$")),)

PORT_LINUX = $(if $(PORT_LINUX_EXACT),$(PORT_LINUX_EXACT),$(firstword $(shell $(RIOTTOOLS)/usb-serial/find-tty.sh)))

PORT_DARWIN = $(shell ls -1 /dev/tty.SLAB_USBtoUART* | head -n 1)

Limitations

Only tested on Linux, and probably only works on Linux.