-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Second USB CDC (serial) channel #4215
Conversation
from my experience, the ttyACM/COM numbering (0, 1) will swap around and could cause a bit of confusion 😃 |
I have a silly question. If I disable the REPL CDC, on my build , will the index of the other CDC change in |
This has not happened to me (yet!): I tested on Linux, WIndows, and MacOS, and they were always assigned in sequential order. I did have a problem in which I left |
Do you mean you would set Is that because this will not otherwise work on SAMD21? You could disable MIDI and regain enough endpoints, and still have the REPL. Eventually we will have dynamic USB descriptors, but I was able to avoid all that implementation work because there were just enough endpoints on many boards. |
yeah, It will be good on testing, and then decide to confuse us when we want to do something more stable. Just kidding, in case of issue e.g with ACM0 it will come back as ACM2 then we have ACM1 & ACM2. It can stay like that, and thing can be confusing on our support for which ACM for REPL. But it is really minor to those who want dual CDCs. Just make sure we have some note to user :) |
It would be nice to be able to identify the CDC channels by the string ID's:
Do you know of a relatively platform-independent way to get those, or even an easy way on each platform? I look at the Qt stuff that Mu uses, but could not find a way to access these. That would assure that Mu is finding the REPL CDC, not the other one. RIght now it just looks for the first one. That was actually the testing I did; I wanted to make sure this wasn't going to completely confuse Mu right away. |
Yes, that's what I meant.
No, it's not to free an endpoint, it's to avoid confusing end users. One of my specific cases is a stenotype, which is a serial device. Once I have all the code for it developed, I will disable all endpoints except for the CDC, so that when you connect it, it's obvious which device to choose in the Plover app. I expect a lot of people who try to make useful gadgets, as opposed to just playing with things, will want to disable the unnecessary endpoints (and, when dynamic endpoints are a thing, possibly enable them but only when a button is pressed at startup, similar to mounting the filesystem). |
Here is a related issue for getting allowed by Chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=1169000 (Will review later.) |
pyserial exposes the port's string ID like this. That's on Mac but I think pyserial might provide that across platforms ? import serial.tools.list_ports
for port in serial.tools.list_ports.comports():
print(port.device,port.interface)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this! Nothing major. Just a couple questions.
bea3a98
to
985e020
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Thank you!
It looks like this broke builds with
|
This can be worked around by always adding |
I looks like we should set |
If you figure this out in general way a PR would be welcome. Thanks! I did not test all the possibilities. |
#4283 should fix it |
Is the usb_cdc.data possible with the SAMD21? "The exception is SAMD21, which has some bug that requires separate MSC endpoints for IN and OUT, instead of a pair" |
@louisfrederic That turned out not to be true. |
Implements a second CDC channel on boards where it is possible.
usb_cdc
.usb_cdc.serials[0]
is the REPL channel;usb_cdc.serials[1]
is the new secondary channel. Both are pre-created instances ofusb_cdc.Serial
.usb_cdc.Serial
is more strictly likepyserial
than the current stream implementation. New pyserial-compatibility flags added to enable this, for use withusb_cdc
:read()
defaults to reading one character.readinto()
does not take a secondlength
argument. This was already implemented forbusio.UART
.read()
andreadinto()
never returnNone
, justb''
and 0, respectively.usb_cdc.Serial
implementsread()
,readinto()
,readline()
,readlines()
,write()
,.in_waiting
,.out_waiting
,.reset_input_buffer
,.reset_output_buffer
, and.timeout
. These parallel what is inpyserial
. Also.connected
is added, which is not inpyserial
.Other changes done during the implementation of
usb_cdc
:USB_DEVICES
andUSB_HID_DEVICES
compile time options are removed. Instead, there are nowCIRCUITPY_USB_MSC
,CIRCUITPY_USB_AUDIO
,CIRCUITPY_USB_MIDI
, etc. flags. Similarly for HID, there are now separate flags for each possible device:CIRCUITPY_USB_MOUSE
,CIRCUITPY_USB_KEYBOARD
, etc. The makefiles take care of passing the right info to the Python script that generates the descriptors.supervisor.runtime
common-hal
routines is made consistent with the generalcommon-hal
naming scheme.?=
, and better indentation.tools/gen_usb_descriptor.py
is black-formatted, and slightly cleaned up. It supports one extra CDC channel.usb_descriptor
is updated to its latest version, which fixes the issue of skipping an endpoint.Most chips with 8 endpoint pairs or more support
usb_cdc
.The exception is SAMD21, which has some bug that requires separate MSC endpoints for IN and OUT, instead of a pair.(EDIT: this turned out not to be true, and was fixed later.) Most stm32 chips do not have enough endpoints. ESP32-S2 and Spresense only have 5 endpoint pairs.Tested on Metro M4 and on RPI Pico.
Fixes #231.
Fixes #4216.