Need USB advice and direction

EddieLeo

Member
I am starting a project using a Teensy 4.1 and ILI9341 to create a user interface to a radio transceiver via USB.
I have the basic UI graphics and user touch screen inputs for the display working satisfactorily and am ready to
move on to the USB connection. However, I am new to the details of USB, and even though I have spent hours and hours reading
information and trying to learn what it's all about, it's like drinking from a firehose.
The radio is not a "well known" device from the USB perspective, i.e. not like a mouse or keyboard - at least for the microcontroller world.
It has a simple and well defined communications protocol using very short command messages and data requests. There are drivers available
for the PC and Arm platforms, so I guess what I need to do is basically create a driver for the Teensy.
The Teensy will operate as a Host, with the radio responding to commands and data requests.
But....I am lost in how to get started communicating with it via USB and need direction.
First of all, is the USBHost_t36 the correct library to be using for the 4.1? In looking through its code, I see references to Teensy 3.6.
I compiled and loaded the serial.ino example from this library and connected to the radio device, but the enumeration did not return anything.
To make sure my Teensy and the software was working, I connected a mouse, and the enumeration did return expected information, so I
have a functioning platform. Also, I know the radio device is functional, as I am able to communicate with it via commercially available software
on a PC and on a RPi.
I have been unable to find a high level description of the whole process of connecting USB devices and how to communicate with them.
With all due respect to the author of the examples in the library, and the tremendous effort to create them, I don't find them very useful
due to the lack of comments and description of what's going on in them. Also, they are written in "elegant" code, which can be difficult for
an amateur programmer to follow and decipher.
I have reached out to the radio manufacturer for information on Device Descriptor Vendor and Product ID, Configuration Descriptor, Interface Descriptor, Endpoint Descriptor, etc. but have not received any response yet.
So....sorry for the long intro - a newbie to this whole USB world could use some guidance!!
Any suggestions? Thanks!
 
To connect the USBHost_t36 would be the starting point, but will need custom code/driver for it to work.

Is there a link to the actual device?
 
I am confused ... installed the Arduino package and Teensyduino afterwards like described in the PJRC website and thought that is all I need for programming all of the devices including USB on Teensy4.1 PCB.
Why using that USBHost_t36 ... have to check what it is ....
I am struggling since months with the USB serial now.
USB serial with the Arduino IDE works fine .. but I want to use the communication with a standard terminal program, that fails.
I read almost the full EHCI and a lot of USB 2.0 spec because Paul strongly recommended that but to find the right code in the package is a challange really.
I even dont know if all I need is in folder teensy4 or if I need additional code in upper core folder and/or in one of the 4 subfolders.
I agree it is a tremendous work to implement that complex specification but is there an overview which user api functions I need to run e.g. a serial communication via standard COM.
In startup are usb_pll_start and usb_init ... but what else has to be initialised besides the definition of USB_SERIAL.
Any hint for some more info to read ?
 
Last edited:
USB has 3 roles: host, device, and hub. A USB system has only 1 host which controls all communication. The devices only communicate with the host, or through the hubs to the host.

Teensy 4.1 has 2 USB ports. The main port is for USB device, which typically communicates with your PC (a USB host). The 2nd Teensy port is for USB host, which lets you connect USB devices like keyboards, mice, musical instruments or even other Teensy boards (in USB device).

If you want to plug some USB device into Teensy, as msg #1 talks about doing with a USB radio, you would need to connect it to the 2nd USB port and use the USBHost_t36 library. But that library lacks the specific driver, so quite a lot of work would be needed.

If you want to plug Teensy into your (Windows) PC and have it appear as a COM port, you would use the main USB port. In that case, you just use the ordinary Arduino Serial functions, like Serial.println("something"). Documentation on those functions can be found here:

https://www.pjrc.com/teensy/td_serial.html

USB serial with the Arduino IDE works fine .. but I want to use the communication with a standard terminal program, that fails.

If it's working with Arduino Serial Monitor, and Tools > USB Type was set to Serial (the default setting) when you uploaded, it really should work with almost any terminal emulator.

Probably best to start a new thread specifically about how to get your terminal emulator software to work with Teensy. Start that thread by showing that Arduino IDE serial monitor is working and be specific about exactly which terminal emulator program you're using. If it's a free download, give a link, so anyone here can try to help without guessing which program to download. A screenshot would probably also help, so we can see what's on your screen and which specific settings you're using in that program.
 
To connect the USBHost_t36 would be the starting point, but will need custom code/driver for it to work.

Is there a link to the actual device?

Yes, writing the custom driver to get the devices to communicate is exactly what I need to do. The specific device in question is a Yaesu FT-891 radio transceiver, although knowing that is of little help in advising me how to move forward. As I said, the protocol is simple and well defined (see links below). I need guidance on the specific steps and sequence of events required to establish the communications link over USB.
It seems there is immediate thread drift with Ghostfighter6's response and Pauls' response which has nothing to do with my OP.
Paul - there is nothing your response that I don't already know.
To put it simply, I need to know where to find how to write the code necessary for the Teensy 4.1 to act as a Host via its second USB port to a serial device that is not already supported with common interfaces.
I have not been able to find any resources for this kind of information for this type of situation.
Is this not really feasible or practical to expect to accomplish?

Here is a link to a description of the radio
https://yaesu.com/indexVS.cfm?cmd=D...E999EAF928B5B6A1A7&DivisionID=65&isArchived=0
and here is a link to a page where the protocol document can be found
https://yaesu.com/indexVS.cfm?cmd=D...E999EAF928B5B6A1A7&DivisionID=65&isArchived=0
on that page, select FT-891 CAT Operation Reference Book
 
Perhaps I'm too ignorant to understand how that helps. I don't want to connect using a PC (been there, done that). Yaesu provides a driver for use with a PC.
What am I missing?

THat was just a tidbit from having gone and looked it up. Perhaps 'virtual serial port connection (VCP)' would mean somehting to others that didn't go that far ...
 
My guess is that the device might use some communications chip like FTDI, or PL2303 or...

If it were me trying this out, some of the steps that I would probably try include:

a) Plug it into the USBHost on the T4.1 and have USBHost_t36 compiled with debug enabled.
Look into the directory for the USBHost code and edit the file usbhost_t36.h
for the lines:
Code:
// Uncomment this line to see lots of debugging info!
//#define USBHOST_PRINT_DEBUG
and as mentioned uncomment the define.

Have the teensy running with a Serial monitor and then plug in your device and see what all we print out about it.
You might try it with the Serial example sketch or the HIDDeviceInfo. But one of the main things to see is what the Product ID is and the Vendor ID.... And what interfaces does it expose.

If we are lucky it would turn out it is using one of those other chips, in which case, you hopefully can simply edit The Serial.cpp code in USBHost and add the Vendor ID/Product ID to the mapping table near the top of the file. And see if something works.

Hopefully the debug outputs will give us some additional information about the device.

Hopefully it is as simple as that. And not that this device is expecting some magic handshake to get started.
 
and here is a link to a page where the protocol document can be found
https://yaesu.com/indexVS.cfm?cmd=D...E999EAF928B5B6A1A7&DivisionID=65&isArchived=0
on that page, select FT-891 CAT Operation Reference Book

On the Files tab, hovering my mouse over the "FT-891 USB Driver Virtual COM Port Driver (Windows 11/10) ( 216.45 KB )" link, I can see part of the URL is "FileName=CP210x_Universal_Windows_Driver.zip".

Seems like a good sign they just used an ordinary CP2102 or CP2104 chip, which very likely will be recognized automatically by the USBHost_t36 serial driver.

Probably start with the File > Examples > USBHost_t36 > Serial example.

Looking at that example.... for future versions of USBHost_t36 we should probably create a Serial folder with at least a couple examples, probably one named "Basic" or "Simple" having less than 50 lines where the loop() function just copies data back and forth from a single USB Serial device to the Arduino Serial Monitor, with a fixed baud rate and extra options like word format are all just defaults to keep the code simple. For the not-so-simple example we have now, at the very least comments should be added to explain how to use it, and specifically which USB device all that "ax12" code on lines 165-326 is meant to use.
 
Of course, once the serial communication is working, knowing what sort of data it transmits and what commands it expects you to send is the major work. Maybe one of those documents on the Files tab says? I looked at only 1 of them "SCU-17 USB Interface Unit Instruction Manual rev. 2018" which seems to only document how to physically connect the cables. Maybe one of the others gives the actual data and command format?
 
Looking at that example.... for future versions of USBHost_t36 we should probably create a Serial folder with at least a couple examples, probably one named "Basic" or "Simple" having less than 50 lines where the loop() function just copies data back and forth from a single USB Serial device to the Arduino Serial Monitor, with a fixed baud rate and extra options like word format are all just defaults to keep the code simple. For the not-so-simple example we have now, at the very least comments should be added to explain how to use it, and specifically which USB device all that "ax12" code on lines 165-326 is meant to use.

If someone wishes to try out different usb host serial sketches, here is one I have used to try out both the Host Serial or Serial Emulation.
It is setup to use the Serial with bigbuffer as I was testing it with devuces that included a teensy 4.x with large transfers.

On my Machine it is named USBHostSerialEmu_Test
Code:
// USBSerialEMU - Simple USBSerial or USBSerialEmu echo to SerialUSB1...
// This sketch requires Serial type of either Dual or Tripple Serial
//
// This example is in the public domain

#include <USBHost_t36.h>

USBHost myusb;
USBHub hub1(myusb);
USBHIDParser hid1(myusb);
USBHIDParser hid2(myusb);
USBSerial_BigBuffer userial(myusb, 1);  // USB Serial  big or little... 
USBSerialEmu seremu(myusb);

#if !defined(USB_TRIPLE_SERIAL) && !defined(USB_DUAL_SERIAL)
#error Program uses SerialUSB1 so needs Dual or Tripple Serial
#endif

USBDriver *drivers[] = {&hub1, &hid1, &hid2, &userial};
#define CNT_DEVICES (sizeof(drivers)/sizeof(drivers[0]))
const char * driver_names[CNT_DEVICES] = {"Hub1", "HID1", "HID2", "USerial"};
bool driver_active[CNT_DEVICES] = {false, false};

// Lets also look at HID Input devices
USBHIDInput *hiddrivers[] = {&seremu};
#define CNT_HIDDEVICES (sizeof(hiddrivers)/sizeof(hiddrivers[0]))
const char * hid_driver_names[CNT_DEVICES] = {"seremu"};
bool hid_driver_active[CNT_DEVICES] = {false, false};

Stream *debug_stream = nullptr;

elapsedMillis emBlink = 0;

void setup()
{
  pinMode(13, OUTPUT);
  Serial.begin(2000000);
  while (!Serial) ; // wait for Arduino Serial Monitor
  Serial.println("\n\nUSB Serial Emulation Device Test Program");

  myusb.begin();
}


char buffer[512];


void loop()
{
  if (emBlink > 500) {
    emBlink = 0;
    digitalToggleFast(13);
  }
  myusb.Task();
  CheckHostDevicesChanged();
  processSerialStreams();
}


void CheckHostDevicesChanged()
{
  for (uint8_t i = 0; i < CNT_DEVICES; i++) {
    if (*drivers[i] != driver_active[i]) {
      if (driver_active[i]) {
        Serial.printf("*** Device % s - disconnected ***\n", driver_names[i]);
        driver_active[i] = false;
      } else {
        Serial.printf("*** Device % s % x: % x - connected ***\n", driver_names[i], drivers[i]->idVendor(), drivers[i]->idProduct());
        driver_active[i] = true;

        const uint8_t *psz = drivers[i]->manufacturer();
        if (psz && *psz) Serial.printf("  manufacturer: % s\n", psz);
        psz = drivers[i]->product();
        if (psz && *psz) Serial.printf("  product: % s\n", psz);
        psz = drivers[i]->serialNumber();
        if (psz && *psz) Serial.printf("  Serial: % s\n", psz);
      }
    }
  }
  for (uint8_t i = 0; i < CNT_HIDDEVICES; i++) {
    if (*hiddrivers[i] != hid_driver_active[i]) {
      if (hid_driver_active[i]) {
        Serial.printf("*** HID Device %s - disconnected ***\n", hid_driver_names[i]);
        hid_driver_active[i] = false;
      } else {
        Serial.printf("*** HID Device %s %x:%x - connected ***\n", hid_driver_names[i], hiddrivers[i]->idVendor(), hiddrivers[i]->idProduct());
        hid_driver_active[i] = true;

        const uint8_t *psz = hiddrivers[i]->manufacturer();
        if (psz && *psz) Serial.printf("  manufacturer: %s\n", psz);
        psz = hiddrivers[i]->product();
        if (psz && *psz) Serial.printf("  product: %s\n", psz);
        psz = hiddrivers[i]->serialNumber();
        if (psz && *psz) Serial.printf("  Serial: %s\n", psz);
      }
    }
  }
}

void processSerialStreams() 
{
  //==============================================
  //  Debug stream stuff
  if (seremu) debug_stream = &seremu;
  else if (userial) debug_stream = &userial;
  else debug_stream = nullptr;

  uint16_t avail;
  uint16_t avail_for_write;
  if (debug_stream) {
    if ((avail = debug_stream->available())) {
      avail_for_write = SerialUSB1.availableForWrite();
      if (avail > avail_for_write) avail = avail_for_write;
      if (avail > sizeof(buffer)) avail = sizeof(buffer);
      debug_stream->readBytes(buffer, avail);
      SerialUSB1.write(buffer, avail);
    }

    if ((avail = SerialUSB1.available())) {
      avail_for_write = debug_stream->availableForWrite();
      if (avail > avail_for_write) avail = avail_for_write;
      if (avail > sizeof(buffer)) avail = sizeof(buffer);
      SerialUSB1.readBytes(buffer, avail);
      debug_stream->write(buffer, avail);
      Serial.printf("USB1->");
      Serial.write(buffer, avail);
    }
  }
}
And it echoes to and from SerialUSB1. One obviously could change it to simply go to and from Serial. Also could remove SEREMU support in it.

As for the other current Serial sketch. Feel free to remove all of the AX serial stuff. It was a good test case when we were working on the USBHost stuff
as I had several different boards which were Dynamixel Servo controllers, which included different teensy boards, An Atmega board done by Trossen Robotics, some different Robotis boards, which include OpenCM, OpenCR, .. But these days not really doing anything in the servos area nor in the USBHost Serial code.
 
Paul, Kurt, - Thanks for the suggestions - that is helpful and I will perform some additional tests. Glad to hear you recognize a common chip in use.
As I said in the OP, I have already tried connection using the serial.ino example in the library, with no result other than the first message on the serial monitor that indicates the program is starting the process - then nothing. However, connection a mouse or keyboard does provide expected results.
If I can establish the communication, then getting the data back and forth should be straightforward - the second document link I gave provides all the details of the communications protocol - all simple, short command messages. What is referred to as "CAT commands" and CAT communications is extremely common for this class of devices (radios), although each manufacturer and model generally has unique protocols - but all very similar in general nature and operation.
I'll get the debug in the library active and try again to see what happens.
Thanks.
 
Here is a minimalist Serial sketch.
Code:
#include "USBHost_t36.h"
#define USBBAUD 115200
USBHost myusb;
USBSerial u(myusb);

void setup() {
  myusb.begin();
  u.begin(115200);
  Serial.begin(115200);
}

void loop() {
  if (u) {
    int c;
    if ((c = u.read()) != -1) Serial.write(c);
    if ((c = Serial.read()) != -1) u.write(c);
  }
}

Edit:
KurtE said:
As for the other current Serial sketch. Feel free to remove all of the AX serial stuff. It was a good test case when we were working on the USBHost stuff
as I had several different boards which were Dynamixel Servo controllers, which included different teensy boards, An Atmega board done by Trossen Robotics, some different Robotis boards, which include OpenCM, OpenCR, .. But these days not really doing anything in the servos area nor in the USBHost Serial code.

I did a quick and dirty update that removed this, plus debug IO pins stuff... I did not change other functionality like to use Serial instead of Serial1 and left in the ability to experiment changing the baud rate and format to see if it works, but... PR #118
 
Last edited:
On the Files tab, hovering my mouse over the "FT-891 USB Driver Virtual COM Port Driver (Windows 11/10) ( 216.45 KB )" link, I can see part of the URL is "FileName=CP210x_Universal_Windows_Driver.zip".

Seems like a good sign they just used an ordinary CP2102 or CP2104 chip, which very likely will be recognized automatically by the USBHost_t36 serial driver.
...

Indeed, going back later there is no protocol/command list to download I saw on the files tab - did see this as the driver to install:
Code:
RELEASE NOTES
=============
Silicon Labs Virtual COM Port (VCP) Universal Driver for Windows 10 and later

Package version: 11.0.0
Release date:    2021-11-05

This package contains a Virtual COM Port Universal driver for Microsoft
Windows 10 and later versions of Windows for use with Silicon Labs VCP USB Serial Bridges.  These devices
include the CP2102N, CP2102, CP2103, CP2104, CP2105, CP2108, CP2109.

@KurtE - your first p#12 LONG sketch is awesome - plugging in a Teensy 4.1 to Host [built IDE 2 w/TD 1.58.1]:
USB_A:
Code:
USB Serial Emulation Device Test Program
*** Device USerial 16c0: 483 - connected ***
  manufacturer: Teensyduino
  product: USB Serial
  Serial: 13287511
USB_B:
Code:
C:\T_Drive\tCode\USB\SerialNumChange\SerialNumChange.ino Apr 15 2023 00:41:43
------
[0]=0x12 	 [1]=0x3
ii= 2: 31	49 ::1
ii= 3: 0	0 ::
... // TyComm output truncated with printed NULLs not copied

Same Teensy connected running shorter sketch p#14: Fails? :: Nothing shows in the SerMon

Same results on both with a second T_4.1 running sketch it already had:
SHORT p#14 - nothing.
Longer p#12:
USB_A:
Code:
USB Serial Emulation Device Test Program
*** Device USerial 16c0: 483 - connected ***
  manufacturer: Teensyduino
  product: USB Serial
  Serial: 9706370
USB_B:
Code:
...
count=27247428, lines/sec=159203
count=27247429, lines/sec=159203
count=27247430, lines/sec=159203
count=27247431, lines/sec=159203
count=27247432, lines/sec=159203
count=27247433, lines/sec=159203
count=27247434, lines/sec=159203
count=27247435, lines/sec=159203
count=27247436, lines/sec=159203
count=27247437, lines/sec=159203
count=27247438, lines/sec=159203
...
 
@KurtE ...
Got the Short example to work adding from Long example:
Code:
...
count=17474618, lines/sec=170489
count=17474619, lines/sec=170489
count=17474620, lines/sec=170489
...

Not sure which of this is good/essential boilerplate but it failed to connect to Teensy for above output until adding handling: USBSerial_BigBuffer userial(myusb, 1); // USB Serial big or little...
>Note I have a HUB and working without a HUB.
>Note using TD 1.58.1 and lots of build warning spew showing in IDE2
Code:
#include "USBHost_t36.h"
#define USBBAUD 115200
USBHost myusb;

USBSerialEmu seremu(myusb);
[B]USBSerial_BigBuffer userial(myusb, 1);  // USB Serial  big or little... [/B]

USBSerial u(myusb);
elapsedMillis emBlink = 0;

void setup() {
  pinMode(13, OUTPUT);
  digitalToggleFast(13);
  myusb.begin();
  u.begin(USBBAUD);
  Serial.begin(115200);
  if (CrashReport)
    Serial.print(CrashReport);
  digitalToggleFast(13);
}

void loop() {
  if (u) {
    int c;
    if ((c = u.read()) != -1) Serial.write(c);
    if ((c = Serial.read()) != -1) u.write(c);
  }
  if (seremu) {
    int c;
    if ((c = seremu.read()) != -1) Serial.write(c);
    if ((c = Serial.read()) != -1) seremu.write(c);
  }
[B]  if (userial) {
    int c;
    if ((c = userial.read()) != -1) Serial.write(c);
    if ((c = Serial.read()) != -1) userial.write(c);
  }
[/B]}

some build spew?:
Code:
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\11.3.1/arm/bin/arm-none-eabi-g++" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=158 -DARDUINO=10607 -DARDUINO_TEENSY41 -DF_CPU=528000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IC:\\Users\\Tim\\AppData\\Local\\Temp\\arduino\\sketches\\C9E2CF7B8D1F1299B472CA4EDEB1BCA8/pch" "-IC:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.58.1\\cores\\teensy4" "-Ic:\\T_Drive\\tCode\\libraries\\USBHost_t36" "-IC:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.58.1\\libraries\\SdFat\\src" "-IC:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.58.1\\libraries\\SPI" "-IC:\\T_Drive\\tCode\\libraries\\USBHost_t36\\utility" "c:\\T_Drive\\tCode\\libraries\\USBHost_t36\\mouse.cpp" -o "C:\\Users\\Tim\\AppData\\Local\\Temp\\arduino\\sketches\\C9E2CF7B8D1F1299B472CA4EDEB1BCA8\\libraries\\USBHost_t36\\mouse.cpp.o"
In file included from c:\T_Drive\tCode\libraries\USBHost_t36\midi.cpp:25:
c:\T_Drive\tCode\libraries\USBHost_t36\USBHost_t36.h: In member function 'USBFilesystem::operator bool()':
c:\T_Drive\tCode\libraries\USBHost_t36\USBHost_t36.h:2375:34: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
 2375 |                 Device_t *dev = *(Device_t * volatile *)&device;
      |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from c:\T_Drive\tCode\libraries\USBHost_t36\adk.cpp:26:
c:\T_Drive\tCode\libraries\USBHost_t36\USBHost_t36.h: In member function 'USBFilesystem::operator bool()':
c:\T_Drive\tCode\libraries\USBHost_t36\USBHost_t36.h:2375:34: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
 2375 |                 Device_t *dev = *(Device_t * volatile *)&device;
      |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\11.3.1/arm/bin/arm-none-eabi-g++" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=158 -DARDUINO=10607 -DARDUINO_TEENSY41 -DF_CPU=528000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IC:\\Users\\Tim\\AppData\\Local\\Temp\\arduino\\sketches\\C9E2CF7B8D1F1299B472CA4EDEB1BCA8/pch" "-IC:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.58.1\\cores\\teensy4" "-Ic:\\T_Drive\\tCode\\libraries\\USBHost_t36" "-IC:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.58.1\\libraries\\SdFat\\src" "-IC:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.58.1\\libraries\\SPI" "-IC:\\T_Drive\\tCode\\libraries\\USBHost_t36\\utility" "c:\\T_Drive\\tCode\\libraries\\USBHost_t36\\print.cpp" -o "C:\\Users\\Tim\\AppData\\Local\\Temp\\arduino\\sketches\\C9E2CF7B8D1F1299B472CA4EDEB1BCA8\\libraries\\USBHost_t36\\print.cpp.o"
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\11.3.1/arm/bin/arm-none-eabi-g++" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=158 -DARDUINO=10607 -DARDUINO_TEENSY41 -DF_CPU=528000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IC:\\Users\\Tim\\AppData\\Local\\Temp\\arduino\\sketches\\C9E2CF7B8D1F1299B472CA4EDEB1BCA8/pch" "-IC:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.58.1\\cores\\teensy4" "-Ic:\\T_Drive\\tCode\\libraries\\USBHost_t36" "-IC:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.58.1\\libraries\\SdFat\\src" "-IC:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.58.1\\libraries\\SPI" "-IC:\\T_Drive\\tCode\\libraries\\USBHost_t36\\utility" "c:\\T_Drive\\tCode\\libraries\\USBHost_t36\\serial.cpp" -o "C:\\Users\\Tim\\AppData\\Local\\Temp\\arduino\\sketches\\C9E2CF7B8D1F1299B472CA4EDEB1BCA8\\libraries\\USBHost_t36\\serial.cpp.o"
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\11.3.1/arm/bin/arm-none-eabi-g++" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=158 -DARDUINO=10607 -DARDUINO_TEENSY41 -DF_CPU=528000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IC:\\Users\\Tim\\AppData\\Local\\Temp\\arduino\\sketches\\C9E2CF7B8D1F1299B472CA4EDEB1BCA8/pch" "-IC:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.58.1\\cores\\teensy4" "-Ic:\\T_Drive\\tCode\\libraries\\USBHost_t36" "-IC:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.58.1\\libraries\\SdFat\\src" "-IC:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.58.1\\libraries\\SPI" "-IC:\\T_Drive\\tCode\\libraries\\USBHost_t36\\utility" "c:\\T_Drive\\tCode\\libraries\\USBHost_t36\\rawhid.cpp" -o "C:\\Users\\Tim\\AppData\\Local\\Temp\\arduino\\sketches\\C9E2CF7B8D1F1299B472CA4EDEB1BCA8\\libraries\\USBHost_t36\\rawhid.cpp.o"
In file included from c:\T_Drive\tCode\libraries\USBHost_t36\memory.cpp:25:
c:\T_Drive\tCode\libraries\USBHost_t36\USBHost_t36.h: In member function 'USBFilesystem::operator bool()':
c:\T_Drive\tCode\libraries\USBHost_t36\USBHost_t36.h:2375:34: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
 2375 |                 Device_t *dev = *(Device_t * volatile *)&device;
      |                                  ^~~~~~~~~~
 
Yes T4.x plugged in would require big buffer. The regular one assumes 64 byte packets, the big buffer can handle the 512...
The extra 1 parameter is the minimum size packets it will accept. Was put in as maybe you have multiple Serial objects you wish to plug in and only one of them needs the big buffers which require more memory and you don't want this one taken up by the smaller transfer device.

For the minimalistic example I would probably simply use big buffer...
 
...
For the minimalistic example I would probably simply use big buffer...

Toward this for minimal functional? It works with Connect and Disconnect of one or alternate Teensy:
Code:
#include "USBHost_t36.h"
#define USBBAUD 115200
USBHost myusb;
USBSerialEmu seremu(myusb);
USBSerial_BigBuffer userial(myusb);  // USB Serial
USBSerial u(myusb);

void setup() {
  myusb.begin();
  u.begin(USBBAUD);
  Serial.begin(115200);
  if (CrashReport)
    Serial.print(CrashReport);
}

void loop() {
  int c;
  if (u) {
    if ((c = u.read()) != -1) Serial.write(c);
    if ((c = Serial.read()) != -1) u.write(c);
  }
  if (seremu) {
    if ((c = seremu.read()) != -1) Serial.write(c);
    if ((c = Serial.read()) != -1) seremu.write(c);
  }
  if (userial) {
    if ((c = userial.read()) != -1) Serial.write(c);
    if ((c = Serial.read()) != -1) userial.write(c);
  }
}
 
Thanks, I only did a quick and dirty test with one out of the bag of different USB to serial adapters I have.
 
Thanks, I only did a quick and dirty test with one out of the bag of different USB to serial adapters I have.

:cool: Was glad to see I could make it work! Not sure CrashReport is needed - but in my mucking around for the missing piece I got Crash from adding this is seemed: myusb.Task(); Maybe that is only useful for the one type?
> Having good examples to work with is important.

Not sure if CrashReport is helpful/needed for anyone using a simple sample to experiment?

Did a quick Mod to the TeensyTime example to ECHO input and still print the time, I had to hold a battery on T_4.0 RTC to unplug PC and put on T_4.1's USB Host to have the time survive - then sent over some Clipboard text:
Code:
...
12:37:35 25 4 2023
12:37:36 25 4 2023
    if ((c = userial.read()) != -1) Serial.write(c);     if ((c = Serial.read()) != -1) userial.write(c);
12:37:37 25 4 2023
12:37:38 25 4 2023
...
13:12:45 25 4 2023
13:12:46 25 4 2023
...

It continues to RUN!

Not sure if those three "IF (TYPE)" are all needed in loop(), or if they are all the possible? I didn't try RawHID (or other) that might work?

And I suppose it would fail if there were a HUB inline (for external power) with the Host? So not sure if adding USBHub hub1(myusb); would solve that?
 
Not 100% sure if the if was needed or not. It hopefully is checked as to not crash if you make the calls with no device attached.

Note: the small sketch I posted, started off more as a joke, on how small could it be. I originally had it as 4 lines:
Code:
#include <USBHost_t36.h>
USBHost myusb; USBSerial u(myusb);
void setup() {myusb.begin(); u.begin(115200); Serial.begin(115200); }
void loop() {if (u) { int c;if ((c = u.read()) != -1) Serial.write(c);if ((c = Serial.read()) != -1) u.write(c); }}

But I will probably convert it to something a little more user friendly ;)
 
Maybe I should put this on different thread, but did create a newer USB Serial example sketch plus some other changes, which I put up in a PR...

Some might want to play with it before and/or if integration.

From my PR: https://github.com/PaulStoffregen/USBHost_t36/pull/119
up in my fork/branch: https://github.com/KurtE/USBHost_t36/tree/USBSerial

I made a version of the USBtoSerial like teensy example that instead does USB Seruak to USBHost Serial.

Put in optional constructors and the like in comments to allow users to have more knowledge of the options.

I also now added in support to the serial objects, to be able to call begin earlier on (before we actually detect the USB Host serial object and specify the Baud rate. This was an issue in an earlier forum thread.

This sketch also looks at the current baud rate of the Serial object and tries to update the USBHost one. Note: I don't update if I find Serial object baud is 0, which I am seeing in the Arduino 2.1.0 Serial monitor.

I also added in optional support the USB Serial constructors to allow you to pass in a VID, PID, what it maps to and if on Interface or whole object, to allow people an easier time to try seeing if they can easily add in their device which underlying it might be a known Serial converter chip but with different VID/PID.

Have done some testing but probably can use more.

@PaulStoffregen @Defragster @mjs513

Now if you wish we can also move these two Example sketches to a sub-directory under examples.

Let me know what you think.
 
Got it to work - 200 lines of code and comments to read ... TLDR {... yet}
> commented #defines hidden in blocks - missed the one I wanted was in there for an extra rebuild or two.

Had to edit the code default 64 > 512 byte case : seems it would be better to default to : USBSerial_BigBuffer userial(myusb, 1); // Handles anything up to 512 bytes
> that will always work and user can downgrade later to the 64 byte case

Found a T_4.0 with battery pins so the RTC could survive the PC to T_4.1 transfer for ECHO test sketch.
> As USB==Serial: works to connect and reconnect!
> Rebuilt T_4.0 as USB==Raw HID :: Failed to show up?
Question:: Is there a way/interface for that to work?

This printed is nice feature:
Code:
[B]*** Device USERIAL1 16c0:483 - connected ***
  manufacturer: Teensyduino
  product: USB Serial
  Serial: 6052840
[/B]RTC has set the system time
13:31:01 26 4 2023
13:31:02 26 4 2023
...
Question:: does that show the info needed for the line below - or would it not connect?
//USBSerial_BigBuffer userial(myusb, 1, 0x10c4, 0xea60, USBSerialBase::CP210X, 0); // Handles anything up to 512 bytes
> based on error below it seems there is a supported list of 'work-a-likes' by name? Where are they?

NOTE: using the above CP210X line by mistake I got this error on building:
> Compilation error: 'USBSerialBase::sertype_t USBSerialBase::CP210X' is private within this context
> maybe this is because TD 1.58.1 is in use and not current WIP library?

Should probably put this on github - but formatting and entry is easier here ...
 
I should have mentioned, that the reason I did it as part of a Pull Request is that I added the ability to do things like:
USBSerial_BigBuffer userial(myusb, 1, 0x10c4, 0xea60, USBSerialBase::CP210X, 0);

And yes I had to move the defines for CP210X to be in public area of the base class.

I also added comments into the header file:
Code:
    // USBSerial_BigBuffer: handles devices that run at USB highspeed and can read and/or write up to 512 bytes per packet,
    // Parameters:
    //  host - reference to the main USB object
    //  min_rxtx - defaults to 65, set to 1 if you wish for it to also handle all USB to Serial objects
    //  vid_to_claim - Vendor ID Normally 0, but if you have device that is not supported you might specify it here.
    //  pid_to_claim - Product ID - only used with VID above
    //  vid_pid_sertype - Again not normally used unless pid, vid - then one of the following FTDI, PL2303, CH341, CP210X
    // void_pid_claim_at_type = like above but 0 if claim at interface (default)  or 1 claim whole device
    USBSerial_BigBuffer(USBHost &host, uint16_t min_rxtx = 65,
              uint16_t vid_to_claim = 0, uint16_t pid_to_claim = 0, 
              sertype_t vid_pid_sertype = USBSerial::UNKNOWN, int vid_pid_claim_at_type = 0) :
        USBSerialBase(host, bigbuffer, sizeof(bigbuffer), min_rxtx, 512, vid_to_claim, pid_to_claim, vid_pid_sertype, vid_pid_claim_at_type) {};
Which should show up in Hover text...
 
I should have mentioned, that the reason I did it as part of a Pull Request is that I added the ability to do things like:
...
Which should show up in Hover text...

IDE 2 Hover text is COOL - pulling the comment in with the proto info!

That seems good - didn't get to read the 200 lines yet, now lunch time ... will update and look again.

Any idea on Raw HID? Not that it is critical - just thought to try/ask ...maybe support is not there/needed.
 
Back
Top