1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

makefiles/tools/serial.inc.mk: Allow detection of debug adapter

Boards with an integrated debugger/programmer that also provides the
serial as UART <--> USB adapter, the TTY serial matches the serial of
the programmer.

This adapts the `serial.inc.mk` to set the `DEBUG_ADAPTER_ID` to the
TTY serial if (and only if) `MOST_RECENT_PORT` *and*
`DEBUG_ADAPTER_ID_IS_TTY_SERIAL` both have a value of `1`. Boards with
an integrated programmer are expected to set
`DEBUG_ADAPTER_ID_IS_TTY_SERIAL` to `1` in their `Makefile.include`.
This commit is contained in:
Marian Buschsieweke 2023-01-10 09:32:35 +01:00
parent 48a02d60e2
commit 015ee050f2
No known key found for this signature in database
GPG Key ID: CB8E3238CE715A94
3 changed files with 17 additions and 12 deletions

View File

@ -25,11 +25,11 @@ ARDUINO_MEGA2560_COMPAT_WITH_CLONES ?= 1
ifeq (1,$(ARDUINO_MEGA2560_COMPAT_WITH_CLONES))
TTY_SELECT_CMD := $(RIOTTOOLS)/usb-serial/ttys.py \
--most-recent \
--format path \
--format path serial \
$(TTY_BOARD_FILTER) || \
$(RIOTTOOLS)/usb-serial/ttys.py \
--most-recent \
--format path \
--format path serial \
$(TTY_BOARD_FILTER_CLONE)
endif

View File

@ -478,20 +478,20 @@ In most cases, just adding a simple `TTY_BOARD_FILTER` is sufficient. If we
however have wildly different flavors of the same board (e.g. genuine Arduino
Mega 2560 with an ATmega16U2 and clones with a cheap USB to UART bridge) that we
all want to support, we have to instead provide a `TTY_SELECT_CMD` that prints
the path to the TTY and exists with `0` if a TTY was found, or that exists with
`1` and prints nothing when no TTY was found. We can still use the `ttys.py`
script to detect all Arduino Mega 2560 versions: We first try to detect a
genuine Arduino Mega and fall back to selecting cheap USB UART bridges when that
fails using the `||` shell operator:
the path to and the serial of the TTY (separated by a space) and exists with
`0` if a TTY was found, or that exists with `1` and prints nothing when no TTY
was found. We can still use the `ttys.py` script to detect all Arduino Mega
2560 versions: We first try to detect a genuine Arduino Mega and fall back to
selecting cheap USB UART bridges when that fails using the `||` shell operator:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TTY_SELECT_CMD := $(RIOTTOOLS)/usb-serial/ttys.py \
--most-recent \
--format path \
--format path serial \
--vendor 'Arduino' \
--model-db 'Mega 2560|Mega ADK' || \
$(RIOTTOOLS)/usb-serial/ttys.py \
--most-recent \
--format path \
--format path serial \
--driver 'cp210x'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -5,10 +5,15 @@ ifeq (1,$(MOST_RECENT_PORT))
endif
TTY_SELECT_CMD ?= $(RIOTTOOLS)/usb-serial/ttys.py \
--most-recent \
--format path \
--format path serial \
$(TTY_BOARD_FILTER)
PORT_DETECTED := $(shell $(TTY_SELECT_CMD) || echo 'no-tty-detected')
PORT ?= $(PORT_DETECTED)
TTY_DETECTED := $(shell $(TTY_SELECT_CMD) || echo 'no-tty-detected no-serial-detected')
PORT_DETECTED := $(firstword $(TTY_DETECTED))
PORT_SERIAL_DETECTED := $(lastword $(TTY_DETECTED))
PORT ?= $(firstword $(TTY_DETECTED))
ifeq (1,$(DEBUG_ADAPTER_ID_IS_TTY_SERIAL))
DEBUG_ADAPTER_ID ?= $(PORT_SERIAL_DETECTED)
endif
endif
# Otherwise, use as default the most commonly used ports on Linux and OSX
PORT_LINUX ?= /dev/ttyACM0