Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buid system: improve serial port selection #18167

Merged
merged 8 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions boards/common/cc26xx_cc13xx/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions boards/common/nucleo/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions boards/nrf52840dk/Makefile.include
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions boards/same54-xpro/Makefile.include
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions boards/samr21-xpro/Makefile.include
Original file line number Diff line number Diff line change
@@ -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
20 changes: 9 additions & 11 deletions dist/tools/usb-serial/ttys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -52,16 +53,6 @@ def filters_match(filters, tty):
return True


def shorten(string, length):
benpicco marked this conversation as resolved.
Show resolved Hide resolved
"""
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
Expand All @@ -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",
Expand All @@ -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 "
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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


Expand Down
3 changes: 2 additions & 1 deletion makefiles/tools/serial.inc.mk
Original file line number Diff line number Diff line change
@@ -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
Expand Down