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
Suggested feature: add a second USB serial port for remote control features #7532
Comments
Hi @kentindell, |
You can check out my patch here: https://github.com/kentindell/canhack/blob/master/pico/micropython/v1.16.patch You can create a second instance of a serial port, which you can then open to the host as a normal port - exactly as you want. |
Thank you for the patch, now i got two serial devices on the host: /dev/ttyACM0 and /dev/ttyACM1 👍 |
Actually, I never wrote any Python code for USB serial: what I wrote is a new MicroPython class that wraps up the MIN protocol C library (https://github.com/min-protocol/min), adding C calls directly to the USB serial handler in the MicroPython firmware. The existing Python serial API should work but I'm not sure how to address the port: sys.stdin is the REPL port. Probably it's a case of adding a new symbol into the sys class to name it, but I'm not that familiar with the MicroPython serial API. Any hints @dpgeorge? |
also been looking for a side-channel for piping data to/from the target |
The current design doesn't have concurrency control between the streams so my patch only works if REPL isn't sending anything. For MIN that's OK because it's invoked from REPL so that's quiescent. Obviously the proper fix is multiple buffers with concurrency control and ideally dynamic USB endpoint/buffer allocation. But I think that's a fairly big chunk of work. |
Noted that circuitpython has support to dynamically enable more CDC's making it easy to add a bi-directional "command-channel" |
btw, do you have any examples or projects where you setup two ports + min for cmds in the 2nd? ...wouldn't it be possible to pass the min encoded commands through the repl? a bit like filesystem commands work!? |
I used MIN with the CANPico to turn it into a CAN adapter, giving a host a Python API. I used to use REPL in raw mode on the PyBoard for this but binary data kept generating spurious CTRL- commands, and it was really a mess to get a clean and robust solution that didn't also ruin REPL sessions. |
Run updated pre-commit
My modification to add a second CDC endpoint doesn't work since the refactoring to move TinyUSB configurations to the top level I've done a quick hack to the single file When firmware boots there are no
|
Applies patch from micropython#7532 (comment) Config descriptor looks OK, SETCONFIGURATION fails.
@kentindell This code is 99% of the way there, in addition you need to set Here's a diff that registers /dev/ttyACM0 and /dev/ttyACM1 on Linux: On the general point of this feature request, once #9497 eventually lands then it should be possible to add extra CDC serial ports without writing any C code at all, unless you want to. So it should be easy to write an example for this use case. USB debugging story for future referenceFWIW, I didn't see this immediately either, only noticed once I started digging at where the failure occurred. When I spun up your original patch there were two clues that sent me that way:dmesg:
Suggests the descriptors are parsed OK (this is why The other one is usbmon module + Wireshark. Amazing for debugging USB without needing any external hardware. This let me both look at the descriptors on-the-wire (looked alright), but then confirm the device was rejecting the SET CONFIGURATION request from the host: I started looking in the tinyusbd CDC driver to see how it interacts with the configuration request, and that's when I noticed |
Thank you so much for this! I shall get straight on to it tomorrow. The USB debugging story is fascinating: I wouldn't have guessed at how to track down the bug. I would like to know more about USB at the lowest levels so that Wireshark tip is great. |
Oh, and I just saw what I wrote here two years ago: "I hardwired the second port by bumping CFG_TUD_CDC to 2 in tusb_config.h". D'oh! |
I have a fork of the firmware for the CANPico boards and have added a second USB serial port for use by MIN (a reliable serial transport protocol) to send and receive remote control commands from a host (in my case, pushing CAN frames received to a host to see in Wireshark). It's a lot more robust than trying to multiplex the REPL serial port into raw mode.
I hardwired the second port by bumping CFG_TUD_CDC to 2 in tusb_config.h and the table usbd_desc_cfg in tusb_port.c.
The text was updated successfully, but these errors were encountered: