1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Merge pull request #18167 from maribu/dist/tools/usb-serial/ttys.py

buid system: improve serial port selection
This commit is contained in:
Marian Buschsieweke 2022-06-07 07:20:02 +02:00 committed by GitHub
commit a34a4c7220
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 34 additions and 12 deletions

View File

@ -4,5 +4,10 @@ PROGRAMMER ?= uniflash
# uniflash and openocd programmers are supported
PROGRAMMERS_SUPPORTED += openocd uniflash
# If port selection via ttys.py is enabled by `MOST_RECENT_PORT=1`, filter
# USB serials to only select the UART bridge of XDS110 debuggers, which is the
# embedded debugger of these launchpad boards.
TTY_BOARD_FILTER := --model XDS110 --iface-num 0
OPENOCD_CONFIG ?= $(RIOTBOARD)/common/cc26xx_cc13xx/dist/openocd.cfg
UNIFLASH_CONFIG ?= $(RIOTBOARD)/common/cc26xx_cc13xx/dist

View File

@ -7,6 +7,10 @@ INCLUDES += -I$(RIOTBOARD)/common/stm32/include
# Setup of programmer and serial is shared between STM32 based boards
include $(RIOTMAKE)/boards/stm32.inc.mk
# If port selection via ttys.py is enabled by `MOST_RECENT_PORT=1`, filter
# USB serials to only select the UART bridge of embedded STLink debuggers.
TTY_BOARD_FILTER := --model 'STM32 STLink'
# variable needed by cpy2remed PROGRAMMER
# it contains name of ST-Link removable media

View File

@ -1 +1,5 @@
# If port selection via ttys.py is enabled by `MOST_RECENT_PORT=1`, filter
# USB serials to only select the UART bridge of integrated J-Link debugger.
TTY_BOARD_FILTER := --model J-Link
include $(RIOTBOARD)/common/nrf52xxxdk/Makefile.include

View File

@ -1 +1,6 @@
# If port selection via ttys.py is enabled by `MOST_RECENT_PORT=1`, filter
# USB serials to only select the UART bridge of the embedded EDBG CMSIS-DAP
# debugger.
TTY_BOARD_FILTER := --model 'EDBG CMSIS-DAP'
include $(RIOTMAKE)/boards/sam0.inc.mk

View File

@ -1 +1,6 @@
# If port selection via ttys.py is enabled by `MOST_RECENT_PORT=1`, filter
# USB serials to only select the UART bridge of the embedded EDBG CMSIS-DAP
# debugger.
TTY_BOARD_FILTER := --model 'EDBG CMSIS-DAP'
include $(RIOTMAKE)/boards/sam0.inc.mk

View File

@ -36,6 +36,7 @@ def tty2dict(dev):
result["model_db"] = dev.get("ID_MODEL_FROM_DATABASE")
result["vendor"] = unescape(dev.get("ID_VENDOR_ENC"))
result["vendor_db"] = dev.get("ID_VENDOR_FROM_DATABASE")
result["iface_num"] = str(int(dev.get("ID_USB_INTERFACE_NUM")))
return result
@ -52,16 +53,6 @@ def filters_match(filters, tty):
return True
def shorten(string, length):
"""
Shorten the given string to the given length, if needed
"""
if len(string) > length:
return string[:length - 3] + "..."
return string
def parse_args(args):
"""
Parse the given command line style arguments with argparse
@ -78,6 +69,7 @@ def parse_args(args):
"model_db",
"driver",
"ctime",
"iface_num",
}
parser = argparse.ArgumentParser(description=desc)
parser.add_argument("--most-recent", action="store_true",
@ -103,6 +95,9 @@ def parse_args(args):
parser.add_argument("--vendor-db", default=None, type=str,
help="Print only devices with a vendor matching this "
"regex (DB entry)")
parser.add_argument("--iface-num", default=None, type=str,
help="Print only devices with a USB interface number "
"matching this regex (DB entry)")
parser.add_argument("--exclude-serial", type=str, nargs='*', default=None,
help="Ignore devices with these serial numbers. "
+ "Environment variable EXCLUDE_TTY_SERIAL can "
@ -165,7 +160,7 @@ def print_results(args, ttys):
tty["ctime"] = time.strftime("%H:%M:%S",
time.localtime(tty["ctime"]))
headers = ["path", "driver", "vendor", "model", "model_db", "serial",
"ctime"]
"ctime", "iface_num"]
print_table(ttys, headers)
return
@ -198,6 +193,9 @@ def generate_filters(args):
if args.vendor_db is not None:
result.append(("vendor_db", re.compile(args.vendor_db)))
if args.iface_num is not None:
result.append(("iface_num", re.compile(args.iface_num)))
return result

View File

@ -1,6 +1,7 @@
# Select the most recently attached tty interface
ifeq (1,$(MOST_RECENT_PORT))
PORT ?= $(shell $(RIOTTOOLS)/usb-serial/ttys.py --most-recent --format path)
TTYS_FLAGS := --most-recent --format path $(TTY_BOARD_FILTER)
PORT ?= $(shell $(RIOTTOOLS)/usb-serial/ttys.py $(TTYS_FLAGS))
endif
# Otherwise, use as default the most commonly used ports on Linux and OSX
PORT_LINUX ?= /dev/ttyACM0