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

boards/arduino-mega2560: add TTY_BOARD_FILTER #19012

Merged
merged 3 commits into from
Dec 11, 2022

Conversation

maribu
Copy link
Member

@maribu maribu commented Dec 5, 2022

Contribution description

This allows automatically selecting TTY actually belonging to an
Arduino Mega2560 if MOST_RECENT_PORT=1 is set.

Testing procedure

make BOARD=arduino-mega2560 MOST_RECENT_PORT=1 -C examples/default flash term

Should automatically select the TTY of the most recently connected Arduino Mega2560, even if a board of a different type is connect more recently.

Issues/PRs references

@maribu maribu added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation State: waiting for other PR State: The PR requires another PR to be merged first CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Dec 5, 2022
@github-actions github-actions bot added Area: boards Area: Board ports Area: tools Area: Supplementary tools labels Dec 5, 2022
@maribu
Copy link
Member Author

maribu commented Dec 5, 2022

(This should be super quick in Murdock, as can_fast_ci_run.py should detect that only one board was changed. Hence, no harm in already having this in the CI.)

@benpicco benpicco added State: waiting for other PR State: The PR requires another PR to be merged first and removed State: waiting for other PR State: The PR requires another PR to be merged first labels Dec 5, 2022
@riot-ci
Copy link

riot-ci commented Dec 5, 2022

Murdock results

✔️ PASSED

dadf22f boards/arduino-mega2560: add TTY_BOARD_FILTER

Success Failures Total Runtime
2006 0 2006 04m:41s

Artifacts

@gschorcht
Copy link
Contributor

The test fails for me. First I thought that I had to install pyudev. But also with pyudev, I get the following error:

avrdude -c stk500v2 -p m2560 -P  -D -U flash:w:examples/default/bin/arduino-mega2560/default.h

avrdude: ser_open(): can't open device "-D": No such file or directory

It seems that the port isn't defined.

@gschorcht
Copy link
Contributor

Ah ok, maybe I have to try it on top of PR #19011

@gschorcht
Copy link
Contributor

Ah ok, maybe I have to try it on top of PR #19011

No, same error.

@maribu
Copy link
Member Author

maribu commented Dec 7, 2022

Hmm, what is the output of make list-ttys?

@gschorcht
Copy link
Contributor

gschorcht commented Dec 7, 2022

Hmm, what is the output of make list-ttys?

path         | driver | vendor       | model                                | model_db                                             | serial | ctime    | iface_num
-------------|--------|--------------|--------------------------------------|------------------------------------------------------|--------|----------|----------
/dev/ttyUSB1 | ch341  | 1a86         | USB2.0-Serial                        | HL-340 USB-Serial adapter                            | None   | 16:58:16 | 0        
/dev/ttyUSB0 | cp210x | Silicon Labs | CP2102 USB to UART Bridge Controller | CP2102/CP2109 UART Bridge Controller [CP210x family] | 0001   | 16:57:27 | 0        
Obviously my Arduino MEGA 2560 board is a Chineese clone that doesn't use an ATMEGA16U2 for the USB interface but an CH341 USB-Serial adapter 😟 No wonder that the board isn't detected. I had anywhere an original Arduino MEGA ADK, but I don't know where.

@benpicco benpicco removed the State: waiting for other PR State: The PR requires another PR to be merged first label Dec 7, 2022
@github-actions github-actions bot removed the Area: tools Area: Supplementary tools label Dec 8, 2022
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.
@github-actions github-actions bot added Area: build system Area: Build system Area: doc Area: Documentation Area: tools Area: Supplementary tools labels Dec 9, 2022
@maribu maribu requested a review from chrysn December 9, 2022 12:04
@maribu
Copy link
Member Author

maribu commented Dec 9, 2022

I updated the PR a bit to also allow adding custom commands to detect the TTYs instead of just a TTY_BOARD_FILTER and extended the ttys.py to return an error code if no TTY was found. This allows chaining the ttys.py command in shell e.g. like

ttys.py --filter-genuine || ttys.py --filter-clones

And for the Arduino Mega 2560 I now overwrite the shell command to fall back to detecting cheap USB UART bridges when no genuine Arduino Mega 2560 board was found. I think this is the best compromise, as it still reliably detects a genuine Arduino Mega 2560 (which we can tell apart by the UDEV data from other USB UART bridges), but won't break usage for clone boards.

doc/doxygen/src/flashing.md Outdated Show resolved Hide resolved
@gschorcht
Copy link
Contributor

And for the Arduino Mega 2560 I now overwrite the shell command to fall back to detecting cheap USB UART bridges when no genuine Arduino Mega 2560 board was found. I think this is the best compromise, as it still reliably detects a genuine Arduino Mega 2560 (which we can tell apart by the UDEV data from other USB UART bridges), but won't break usage for clone boards.

But of course this only works if the Arduino Mega 2560 Clone was connected last.

doc/doxygen/src/flashing.md Outdated Show resolved Hide resolved
@gschorcht
Copy link
Contributor

bors merge

bors bot added a commit that referenced this pull request Dec 11, 2022
19012: boards/arduino-mega2560: add TTY_BOARD_FILTER r=gschorcht a=maribu

### Contribution description

This allows automatically selecting TTY actually belonging to an
Arduino Mega2560 if `MOST_RECENT_PORT=1` is set.

### Testing procedure

```
make BOARD=arduino-mega2560 MOST_RECENT_PORT=1 -C examples/default flash term
```

Should automatically select the TTY of the most recently connected Arduino Mega2560, even if a board of a different type is connect more recently.

### Issues/PRs references

- [x] depends on (and includes) #19011

Co-authored-by: Marian Buschsieweke <marian.buschsieweke@ovgu.de>
Co-authored-by: Marian Buschsieweke <maribu@users.noreply.github.com>
Allow overriding the shell command used to auto-detect the TTY of a
board with `MOST_RECENT_PORT=1` via the `TTY_SELECT_CMD` variable.
The use case is to also detect Arduino Mega 2560 clones with cheap
USB UART bridges (for which the filter command may yield false
positives) while preferring genuine Arduino Mega 2560 boards (if
found) over the clones (as the filter for genuine boards does not yield
false positives).
This allows automatically selecting TTY actually belonging to an
Arduino Mega2560 if `MOST_RECENT_PORT=1` is set.

Note: Unless `ARDUINO_MEGA2560_COMPAT_WITH_CLONES` is set to `0`,
this will fall back to detecting any cheap USB UART bridge typically
found in Arduino Mega 2560 clones if no genuine Arduino Mega is found.
@bors
Copy link
Contributor

bors bot commented Dec 11, 2022

Canceled.

@maribu
Copy link
Member Author

maribu commented Dec 11, 2022

Squashed.

bors retry

@bors
Copy link
Contributor

bors bot commented Dec 11, 2022

🕐 Waiting for PR status (GitHub check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set.

@maribu
Copy link
Member Author

maribu commented Dec 11, 2022

bors retry

@bors
Copy link
Contributor

bors bot commented Dec 11, 2022

Build succeeded:

@bors bors bot merged commit 268e931 into RIOT-OS:master Dec 11, 2022
@maribu
Copy link
Member Author

maribu commented Dec 11, 2022

Thx :)

@maribu maribu deleted the boards/arduino-mega2560 branch December 11, 2022 20:54
@gschorcht gschorcht added CI: full build disable CI build filter CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: full build disable CI build filter labels Dec 12, 2022
@gschorcht
Copy link
Contributor

Oops, I accidentally restarted a full build in the wrong browser window for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports Area: build system Area: Build system Area: doc Area: Documentation Area: tools Area: Supplementary tools Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants