From fdac725d8c0393f04731b8fa50089733627da2fa Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Tue, 5 Nov 2024 13:21:16 +0100 Subject: [PATCH] makefiles/serial: better MOST_RECENT_PORT=1 for CDC ACM - Allow specifying an alternative board filter for the bootloader TTY, as this will present different vendor, model, and serial than RIOT's USB implementation. - Allow specifying the serial. This is useful when multiple CDC ACM devices are present. --- boards/wemos-zero/Makefile.include | 10 +-------- makefiles/tools/serial.inc.mk | 34 +++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/boards/wemos-zero/Makefile.include b/boards/wemos-zero/Makefile.include index 5e5b9a8673..a28a208e1e 100644 --- a/boards/wemos-zero/Makefile.include +++ b/boards/wemos-zero/Makefile.include @@ -5,12 +5,4 @@ include $(RIOTBOARD)/common/arduino-zero/Makefile.include # Depending on whether the board is running RIOT or the bootloader, it has # registers using a different vendor and model. We try to detect either. TTY_BOARD_FILTER := --model $(BOARD) --vendor 'RIOT-os\.org' -PROG_TTY_BOARD_FILTER := --vendor 'Arduino LLC' --model 'Arduino Zero' -TTY_SELECT_CMD := $(RIOTTOOLS)/usb-serial/ttys.py \ - --most-recent \ - --format path serial \ - $(TTY_BOARD_FILTER) || \ - $(RIOTTOOLS)/usb-serial/ttys.py \ - --most-recent \ - --format path serial \ - $(PROG_TTY_BOARD_FILTER_CLONE) +PROG_TTY_BOARD_FILTER := --vendor 'Arduino LLC' --model '(Arduino|Genuino) Zero' diff --git a/makefiles/tools/serial.inc.mk b/makefiles/tools/serial.inc.mk index 93a135429d..1332bd5f17 100644 --- a/makefiles/tools/serial.inc.mk +++ b/makefiles/tools/serial.inc.mk @@ -1,15 +1,29 @@ # Select the most recently attached tty interface ifeq (1,$(MOST_RECENT_PORT)) - ifneq (,$(filter stdio_cdc_acm,$(USEMODULE))) - TTY_SELECT_CMD ?= $(RIOTTOOLS)/usb-serial/ttys.py \ - --most-recent \ - --format path serial \ - --model '$(BOARD)' --vendor 'RIOT-os\.org' - else - TTY_SELECT_CMD ?= $(RIOTTOOLS)/usb-serial/ttys.py \ - --most-recent \ - --format path serial \ - $(TTY_BOARD_FILTER) + ifeq (,$(TTY_SELECT_CMD)) + ifneq (,$(filter stdio_cdc_acm,$(USEMODULE))) + TTY_SELECT_CMD := $(RIOTTOOLS)/usb-serial/ttys.py \ + --most-recent \ + --format path serial \ + --model '$(BOARD)' --vendor 'RIOT-os\.org' + # Allow matching board by RIOT serial + ifneq (,$(SERIAL)) + TTY_SELECT_CMD += --serial "$(SERIAL)" + endif + # Allow matching the bootloader TTY as well, if not running RIOT but + # but the bootloader + ifneq (,$(PROG_TTY_BOARD_FILTER)) + TTY_SELECT_CMD += || $(RIOTTOOLS)/usb-serial/ttys.py \ + --most-recent \ + --format path serial \ + $(PROG_TTY_BOARD_FILTER) + endif + else + TTY_SELECT_CMD := $(RIOTTOOLS)/usb-serial/ttys.py \ + --most-recent \ + --format path serial \ + $(TTY_BOARD_FILTER) + endif endif TTY_DETECTED := $(shell $(TTY_SELECT_CMD) || echo 'no-tty-detected no-serial-detected') PORT_DETECTED := $(firstword $(TTY_DETECTED))