-
Notifications
You must be signed in to change notification settings - Fork 378
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
Teensy3 usb triple serial #438
Teensy3 usb triple serial #438
Conversation
When processing CDC_SET_CONTROL_LINE_STATE and CDC_SET_LINE_CODING requests, wIndex is ignored. Hence if the CDC Status Interface is enabled, these requests are always processed, even when not destined for the actual serial status interface. Fix this by adding a check to ensure that wIndex matches the CDC status interface. Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
- usb_serial_class::readBytes() calls millis(), hence it should include "core_pins.h", - usb_serial_flush_callback() is a public function, but is not declared in the header file. Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
When including "core_pins.h": teensy3/usb_dev.c: In function '_reboot_Teensyduino_': teensy3/usb_dev.c:899:1: warning: 'noreturn' function does return Fix this by adding a call to __builtin_unreachable(). Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Include <usb_serial.h> instead of duplicating the needed forward declarations. Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Create a macro to emit all values for the various CDC descriptors, and use it. Note that this does not include the CDC Interface Association Descriptor, as the latter is needed only for composite USB devices. This will avoid duplication when adding support for multiple USB serial interfaces. Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Create a macro to emit all values for a CDC Interface Association Descriptor, and use it. This will avoid duplication when adding support for multiple USB serial interfaces. Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Extract core USB serial functionality in a new usb_serial_port C class, to allow creating multiple USB serial instances without duplicating all code. The original API is retained by creating static inline functions and preprocessor macros using the old names, which are wrappers around the new usb_serial_port functions and data members. Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Add preprocessor macros to control the naming of functions, structures and classes, to ease the creation of multiple USB serial instances. Name generation for each instance is controlled using the USB_SERIAL_SUFFIX and SERIAL_CLASS_SUFFIX defines. Move the preprocessor macro wrappers around the usb_serial_port data members to usb_serial.h, as preprocessor macro names cannot be parameterized. Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Add support for a dual serial port configuration (USB_DUAL_SERIAL), providing a composite USB device, comprised of two serial ports. The second serial port is called usb_serial2 (C) or SerialA (C++). Note that no dummy C++ class is created if USB_DISABLED is defined, unlike for the first port. This increases binary size by ca. 1.2 KiB (720 bytes for USB buffers). Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Add support for a triple serial port configuration (USB_TRIPLE_SERIAL), providing a composite USB device, comprised of three serial ports. The third serial port is called usb_serial3 (C) or SerialB (C++). Note that no dummy C++ class is created if USB_DISABLED is defined, unlike for the first port. This increases binary size by ca. 0.5 KiB (despite needing 720 more bytes for USB buffers, as gcc-5.4.1 no longer decides to unroll a loop over all endpoints in usb_isr()). Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Wow, that might be extremely useful for debugging if you need Serial for normal communication to the PC. I gave it a quick try, it compiles without issues and generates the second port (WIN10) which appears in the device manager. Edit: TyCommander does not recognize a Teensy having two ports. So, reprogramming needs the button, but that can probably be fixed. |
Changing -DUSB_SERIAL to -DUSB_DUAL_SERIAL should be sufficient. TBH, I'm not using the Arduino environment, but C and Makefiles, so I may be missing a minor detail. |
So do I... Found it, was my fault I changed the define in the makefile but forgot to do the same change in the intellisense config. So, vsCode marked SerialA as not defined and I believed it. Silly me... Everything runs out of the box, the only issue I see at the moment is the compatibility to the uploaders. Tried TyCommander which gets confused. I'll give teensy.exe a go later. |
Same with Teensy.exe, after resetting, it looses the board. Pressing the programming button works of course. |
I really do appreciate that you've contributed this code back to the core library. But much the macro trickery appears to be incompatible with the Arduino IDE. I need to undo some of that work. Just wanted to let you know... it's not that I don't appreciate everything you've done here. This needs to work with the Arduino IDE (appears that was never tested). Just wanted to let you know why I have to undo parts of this. |
Np. What exactly is failing? |
I've just pushed the reverts. This broke things very badly for building with the Arduino IDE. I'm going through it now to manually part parts back in. But this sort of tricky preprocessor usage, while elegant, it utterly incompatible with the Arduino IDE. We just can't use it like this. |
Thanks, I'll hope to have a closer look at the issues tomorrow. |
I'm working now to convert it to a large, not-nearly-so-pretty expansion of the macros, so it can build with Arduino. Should have it in a few hours... |
It's not pretty and it duplicates (triplicates) a lot of code, but compiles with Arduino IDE. |
Great, do you plan to make Teensy.exe compatible to this? |
Yes, but I may release a first 1.52 beta before updating the tools to properly deal with these 2 new USB types. |
Fixing the code so there aren't compile errors was of course the most urgent thing. Can't start a beta with code that's not compiling in Arduino. |
Sure, just tested the new version with Win10 and Arduino 1.8.5. Works perfectly. |
Thanks, that looks pretty similar to what I had before introducing serial_port and the macros for deduplication. BTW, I can confirm commit 7f3222c ("Allow any of the Daul & Triple serial to request reboot") fixes automatic reboot for programming for me. Thanks! |
Hi Paul,
So I gave it a try in the Arduino IDE (replaced cores in installed teensyduino by this repo, and added dual/triple serial defs to teensy/avr/boards.txt). It turns out the sole offender in my macros is However, I'm not 100% confident this fixes all issues. USB serial operation and programming from the Arduino IDE (arduino-1.8.10+teensyduino-1.48) seems to be very unreliable and unpredictable for me. Note that that is even the case when using a cores version from before you merged my branch, so these issues may be completely unrelated. Thanks! |
I ported this to Teensy 4.0. I'm going to make one more change before releasing a beta test. Arduino's naming convention seems to be SerialUSB. We already support SerialUSB as an alias for Serial (and I believe Arduino does too on their board where they are the same). So I'm going to go with SerialUSB1 and SerialUSB2 rather than SerialA and SerialB. Hopefully that's not too painful at this point. |
Make SerialUSB0 an alias for the original SerialUSB, too? |
Nice!
That makes perfect sense. I wasn't aware of SerialUSB, so that's why I went with A and B, to avoid interfering with the hardware serial numbering. BTW, shouldn't usb_serial2* and usb_serial3* be renamed to usb_serial1* and usb_serial2*, too, to preserve consistency. Right now we have: |
I'm ok with the internal names not being consistent with the Arduino API names. At this point, I'm pretty happy with "ain't broke, don't fix". @WestfW - Does Arduino use SerialUSB0, or Serial0, or "0" on the end of any of the port names for their boards? I do want the public API names to be consistent with the conventions Arduino is using. |
Kind of curious now that someone pointed this discussion out to me - but what changes are necessary to boards.txt to get it to work if I wanted to give it a test? Or is it too early to ask. UPDATE: Forget I asked - figured it out dummy that I am. It works with T4 by the way. |
JFTR, for Teensy 3.1/3.2, add to hardware/teensy/avr/boards.txt:
|
Yep - that's pretty much what I had done, except used Serial2 - Serial3 after usb. |
Add support for dual (USB_DUAL_SERIAL) and triple (USB_TRIPLE_SERIAL) serial port configurations, providing a composite USB device, comprised of two or three serial ports.
The second serial port is called usb_serial2 (C) or SerialA (C++).
The third serial port is called usb_serial3 (C) or SerialB (C++).