Can Not Find Examples for USBHostSerial!

I am trying to use a GlobalSat BU-353-S4 USB GPS puck that attaches through USBHost port and can not seem to find any examples that show how to use usbserial. Also dont see any examples on how to use USBHid in a generic way - only see mouse, keyboard

Any ideas or examples floating around.

Here is the sketch:

// Simple test for receiving data from Serial
// like BU-353S4
//
// This example is in the public domain

#include <Arduino_USBHostMbed5.h>

USBHostSerial userial;
static const uint32_t GPSBaud = 4800;

#include <TinyGPSPlus.h>

TinyGPSPlus gps;


static void smartdelay(unsigned long ms);
static void print_float(float val, float invalid, int len, int prec);
static void print_int(unsigned long val, unsigned long invalid, int len);
static void print_date(TinyGPSPlus &gps);
static void print_str(const char *str, int len);

void setup() {
  pinMode(13, OUTPUT);
  while (!Serial && (millis() < 5000))
    ;  // wait for Arduino Serial Monitor

  pinMode(PA_15, OUTPUT); //enable the USB-A port
  digitalWrite(PA_15, HIGH);

  while (!userial.connect()) {
      //while (!port.connected()) {
      delay(1000);
  }
  Serial.println("\n\nUSB Host Testing - Serial");


  Serial.println(F("FullExample.ino"));
  Serial.println(F("An extensive example of many interesting TinyGPSPlus features"));
  Serial.print(F("Testing TinyGPSPlus library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
  Serial.println(F("by Mikal Hart"));
  Serial.println();
  Serial.println(F("Sats HDOP  Latitude   Longitude   Fix  Date       Time     Date Alt    Course Speed Card  Distance Course Card  Chars Sentences Checksum"));
  Serial.println(F("           (deg)      (deg)       Age                      Age  (m)    --- from GPS ----  ---- to London  ----  RX    RX        Fail"));
  Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------------"));
}

void loop()
{
  //if(userial.available()) {
    static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;

    printInt(gps.satellites.value(), gps.satellites.isValid(), 5);
    printFloat(gps.hdop.hdop(), gps.hdop.isValid(), 6, 1);
    printFloat(gps.location.lat(), gps.location.isValid(), 11, 6);
    printFloat(gps.location.lng(), gps.location.isValid(), 12, 6);
    printInt(gps.location.age(), gps.location.isValid(), 5);
    printDateTime(gps.date, gps.time);
    printFloat(gps.altitude.meters(), gps.altitude.isValid(), 7, 2);
    printFloat(gps.course.deg(), gps.course.isValid(), 7, 2);
    printFloat(gps.speed.kmph(), gps.speed.isValid(), 6, 2);
    printStr(gps.course.isValid() ? TinyGPSPlus::cardinal(gps.course.deg()) : "*** ", 6);

    unsigned long distanceKmToLondon =
      (unsigned long)TinyGPSPlus::distanceBetween(
        gps.location.lat(),
        gps.location.lng(),
        LONDON_LAT, 
        LONDON_LON) / 1000;
    printInt(distanceKmToLondon, gps.location.isValid(), 9);

    double courseToLondon =
      TinyGPSPlus::courseTo(
        gps.location.lat(),
        gps.location.lng(),
        LONDON_LAT, 
        LONDON_LON);

    printFloat(courseToLondon, gps.location.isValid(), 7, 2);

    const char *cardinalToLondon = TinyGPSPlus::cardinal(courseToLondon);

    printStr(gps.location.isValid() ? cardinalToLondon : "*** ", 6);

    printInt(gps.charsProcessed(), true, 6);
    printInt(gps.sentencesWithFix(), true, 10);
    printInt(gps.failedChecksum(), true, 9);
    Serial.println();
    
    smartDelay(1000);

    if (millis() > 5000 && gps.charsProcessed() < 10)
      Serial.println(F("No GPS data received: check wiring"));
  //}
}

// This custom version of delay() ensures that the gps object
// is being "fed".
static void smartDelay(unsigned long ms)
{
  unsigned long start = millis();
  do 
  {
    while (userial.available())
      gps.encode(userial.read());
  } while (millis() - start < ms);
}

static void printFloat(float val, bool valid, int len, int prec)
{
  if (!valid)
  {
    while (len-- > 1)
      Serial.print('*');
    Serial.print(' ');
  }
  else
  {
    Serial.print(val, prec);
    int vi = abs((int)val);
    int flen = prec + (val < 0.0 ? 2 : 1); // . and -
    flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
    for (int i=flen; i<len; ++i)
      Serial.print(' ');
  }
  smartDelay(0);
}

static void printInt(unsigned long val, bool valid, int len)
{
  char sz[32] = "*****************";
  if (valid)
    sprintf(sz, "%ld", val);
  sz[len] = 0;
  for (int i=strlen(sz); i<len; ++i)
    sz[i] = ' ';
  if (len > 0) 
    sz[len-1] = ' ';
  Serial.print(sz);
  smartDelay(0);
}

static void printDateTime(TinyGPSDate &d, TinyGPSTime &t)
{
  if (!d.isValid())
  {
    Serial.print(F("********** "));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
    Serial.print(sz);
  }
  
  if (!t.isValid())
  {
    Serial.print(F("******** "));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
    Serial.print(sz);
  }

  printInt(d.age(), d.isValid(), 5);
  smartDelay(0);
}

static void printStr(const char *str, int len)
{
  int slen = strlen(str);
  for (int i=0; i<len; ++i)
    Serial.print(i<slen ? str[i] : ' ');
  smartDelay(0);
}
1 Like

Hi @Merlin513.

I found something inexplicably mashed into the keyboard host example of the beta phase "USBHostGiga" library:

Unfortunately I didn't have any success. When I connect a common USB to serial adapter (FT232R, CP2104, CH340) to my GIGA R1 WiFi board, the sketch hangs at the ser.begin() call. I uncommented this line:

//REDIRECT_STDOUT_TO(Serial)

to get some information. I see something like this:

USB Device Connected
USB Device Reset Completed
PID: ea60h
VID: 10c4h
Address (#1) assigned.
Manufacturer : Silicon Labs
Product : CP2104 USB to UART Bridge Controller
Serial Number : 02857D7C
Enumeration done.
This device has only 1 configuration.
Default configuration set.
No registered class for this device.

If I connect an UNO board the the ser.begin() call does return and I get this more promising output instead:

USB Device Connected
USB Device Reset Completed
PID: 43h
VID: 2341h
Address (#1) assigned.
Manufacturer : Arduino (www.arduino.cc)
Product : N/A
Serial Number : 95032303537351D0F001
Enumeration done.
This device has only 1 configuration.
Default configuration set.
Switching to Interface (#0)
Class    : 2h
SubClass : 2h
Protocol : 1h
CDC class started.

but still didn't manage to receive anything from the board. I tried it with a simple sketch like this running on the UNO:

void setup() {
  Serial.begin(115200);
}
void loop() {
  Serial.println("hello");
  delay(1000);
}

And also with the UNO configured as a "loopback" adapter, where I jumpered pins 0 and 1 and added code to the GIGA R1 WiFi sketch to periodically send data via ser.Println(),

1 Like

The quick look at the comments, sounds like only support for CDC... I might try taking a look and see how hard it would be to integrated some of the stuff we added to USBHost_t36. I had support for a few different types, like FTDI, CH, Prolific...

Note: with several/most of these it is keyed by VID:PID and we have ways to try to force it... But been awhile since I looked.

Do you know which chipset this one uses?

Thanks for checking this out - actually forgot there was the USBHostGiga library :slight_smile: - ps doesnt seem to be in library manager.

I did run the sketch with the redirect commented out and it showed:

USB Device Connected
USB Device Reset Completed
PID: 2303h
VID: 67bh
Address (#1) assigned.
Manufacturer : Prolific Technology Inc. 
Product : USB-Serial Controller D
Serial Number : N/A
Enumeration done.
This device has only 1 configuration.
Default configuration set.
No registered class for this device.

As @KurtE mentioned don't think its supported currently, only cdc which limits the devices that you can use.

Do you one better heres the thread from the Teensy forum we were playing around with that particular device:
Teensy 3.6 USB host hangs on userial.begin() if device already plugged in (pjrc.com) - bring back memories

EDIT: went back and looks like the sketch is returning the correct PID/VID

*** Device USERIAL1 67b:2303 - connected ***
  manufacturer: Prolific Technology Inc.

Thanks for pointing that out. To be honest, I never knew that there was this low level technical difference between the dedicated USB to serial converter chips compared to a microcontroller running a USB CDC firmware.

This is intentional. The readme describes its state (which is actually classified as "alpha" rather than "beta" as I incorrectly claimed in my previous reply) as:

The APIs are very minimal ans subject to change; please just use for evaluation purposes.

If we are having trouble spelling the word "and" right in the readme, you can guess the state of the code! But I joke :wink:. I doubt there is much of a correlation between the quality of the two things since I've seen lots of projects that have excellent code but documentation in a terrible condition.

All this is to say that library isn't considered ready for widespread distribution to average users via Library Manager

1 Like

It might take me awhile to understand this library. Also wondering on why it is not the USBHost_MBed5 (sp).

Not sure which approaches Arduino prefers to do.

For example with the Teensy code base, the sketch can add a USBSerial object like:
USBSerial userial(myusb); // works only for those Serial devices who transfer <=64 bytes (like T3.x, FTDI...)

And it should work with almost all of the serial objects. There is one exception, we also have a variant of this object: USBSerial_BigBuffer. Why? Almost all of the adapters connect as USB FS - which defaults to 64 byte packets. But there are now other devices that may want to connect using USB HS with 512 byte packets. Example Teensy 4.x. But I believe we hit this with an FTDI object.

With some of these devices we support (Teensy stuff) Our current VID/PID table:

/************************************************************/
//  Define mapping VID/PID - to Serial Device type.
/************************************************************/
USBSerialBase::product_vendor_mapping_t USBSerialBase::pid_vid_mapping[] = {
	// FTDI mappings. 
	{0x0403, 0x6001, USBSerialBase::FTDI, 0},
	{0x0403, 0x8088, USBSerialBase::FTDI, 1},  // 2 devices try to claim at interface level
	{0x0403, 0x6010, USBSerialBase::FTDI, 1},  // Also Dual Serial, so claim at interface level

	// PL2303
	{0x67B,0x2303, USBSerialBase::PL2303, 0}, 

	// CH341
	{0x4348, 0x5523, USBSerialBase::CH341, 0},
	{0x1a86, 0x7523, USBSerialBase::CH341, 0 },
	{0x1a86, 0x5523, USBSerialBase::CH341, 0 },

	// Silex CP210...
	{0x10c4, 0xea60, USBSerialBase::CP210X, 0 },
	{0x10c4, 0xea70, USBSerialBase::CP210X, 0 }
};

With some of these devices we claim the whole device, other times, we enumerate the interfaces and claim it at the interface level.

And as you can see the VID:PID you mentioned is mapped to PL2303.

Note: each of these adapters may require a different set of initialization messages.

Then there is the USBHost Shield 2 code base. In their code base they have specific objects for specific adapters: So if the object you are wanting to use, uses the PL2303 like some GPS.

Looking at their examples you will see classes like:

USB     Usb;
//USBHub     Hub(&Usb);
PLAsyncOper  AsyncOper;
PL2303       Pl(&Usb, &AsyncOper);
TinyGPS gps;

Now to try to figure out what to do...

P.S. - Sorry for rambling here

I only know what is given in the readme:

https://github.com/arduino-libraries/USBHostGiga#readme

This library has been created to overcome the limitations of GitHub - arduino-libraries/Arduino_USBHostMbed5 when it's time to talk with USB Low Speed devices like keyboards and mice.

1 Like

Thanks @ptillisch,

Thanks, I saw that in the readme,

But what limitations? It appears like the Mbed5 has support for Keyboards, Mice and Serial... Or at least the code and config file give that impression.

@ptillisch @facchinm - Sorry, it may just be me, but I don't understand when I should use the GIGA library version? Part of it is the sentence in the readme you mentioned:

talk with USB Low Speed devices like keyboards and mice

While working on another USBHost setup, I noticed very few devices that ran at USB LS (1.5 MBits), most of them ran at USB FS (12Mbits) and a few at USB HS (480 MBits). I am guessing that this supports probably support both LS and FS keyboards and mice.

Maybe I just need to experiment a bit with the USBHostMbed5 and see what happens. Things like, does it work for some of the keyboards or mice, or serial adtapters I have? is it a closed system or is there a way for sketch or external library to add support for additional devices... probably covered somewhere in their documentation.

Back to playing

@KurtE - @ptillisch
Besides playing with SDRAM and Partitioning of USB Sticks (gave up for now since looks like not currently supported but looks like its supported for SDCards and QSPI) started poking aroung mbedOS for joysticks/gamepads.

Did find that there are libraries available for both:

  1. USB Joystick Device | Mbed which looks like @facchinm started playing with: facchinm/USBJoystick: USB Joystick library for mbed PluggableUSBHID (github.com)
  2. xbox wireless: Xbox 360 Wireless Controller | Mbed
  3. Generic Gamepad: USBHostGamepad - Add USB HID Gamepad hosting support to mbed board… | Mbed and mbed_gamepad_example - USBHostGamepad library usage example | Mbed
    Edit: USBHostGamepad - Add USB HID Gamepad hosting support to mbed board… | Mbed

all this may help to develop additional device drivers

1 Like

Sorry I know slightly off topic of Serial... But tried keyboard.

So far a quick and dirty version for the MBED5...

/*
  USBHost Keyboard test


  The circuit:
   - Arduino GIGA

  This example code is in the public domain.
*/

#include <Arduino_USBHostMbed5.h>
#include <USBHostHID/USBHostKeyboard.h>
USBHostKeyboard kbd;

// If you are using a Portenta Machine Control uncomment the following line
// mbed::DigitalOut otg(PB_14, 0);

void setup()
{
    Serial.begin(115200);
    while (!Serial) {}

    Serial.println("Starting Keyboard test...");

    // Enable the USBHost 
    pinMode(PA_15, OUTPUT);
    //digitalWrite(PA_15, HIGH);

    // if you are using a Max Carrier uncomment the following line
    // start_hub();
    kbd.attach(&kbd_key_cb);
    kbd.attach(&kbd_keycode_cb);

    while (!kbd.connect()) {
      Serial.println("No keyboard connected");        
        delay(5000);
    }
}

void loop()
{
    delay(1000);
}

void kbd_key_cb(uint8_t key) {
  Serial.print("Key pressed: ");
  Serial.print(key, HEX);
  Serial.print("(");
  if ((key >= ' ') && (key <= '~')) Serial.write(key);
  Serial.println(")");
}

void kbd_keycode_cb(uint8_t keycode, uint8_t mod) {
  Serial.print("Keycode: ");
  Serial.print(keycode, HEX);
  Serial.print(" mod: ");
  Serial.println(mod, HEX);
}

Is not seeing either of the two Dell keyboards I tried. Maybe I am missing some step to intialize the system... Although don't see much different in the Directory list example...

I also tried it with the KeyboardGiga.ino example and it sees one of the two keyboards. The one that it sees (Using HID device sketch I have for teensy.....):

USB HID Device Info Program

This Sketch shows information about plugged in HID devices

*** You can control the output by simple character input to Serial ***
R - Turns on or off showing the raw data
C - Toggles showing changed data only on or off
<anything else> - toggles showing the Hid formatted breakdown of the data


USBDeviceInfo claim this=2000CF64

****************************************
** Device Level **
  vid=413C
  pid=2113
  bDeviceClass = 0
  bDeviceSubClass = 0
  bDeviceProtocol = 0
09 04 00 00 01 03 01 01 00 09 21 11 01 00 01 22 41 00 07 05 81 03 08 00 18 09 04 01 00 01 03 00
00 00 09 21 11 01 00 01 22 6D 00 07 05 82 03 08 00 30 

USBDeviceInfo claim this=2000CF64

****************************************
** Interface Level **
09 04 00 00 01 03 01 01 00 09 21 11 01 00 01 22 41 00 07 05 81 03 08 00 18 09 04 01 00 01 03 00
00 00 09 21 11 01 00 01 22 6D 00 07 05 82 03 08 00 30 
 bInterfaceNumber = 0
 number end points = 1
 bInterfaceClass =    3
 bInterfaceSubClass = 1
    HID (BOOT)
 bInterfaceProtocol = 1
    Keyboard
report descriptor size = 65
  endpoint = 81
    attributes = 3 Interrupt
    size = 8
    interval = 24

USBDeviceInfo claim this=2000CF64

****************************************
** Interface Level **
09 04 01 00 01 03 00 00 00 09 21 11 01 00 01 22 6D 00 07 05 82 03 08 00 30 
 bInterfaceNumber = 1
 number end points = 1
 bInterfaceClass =    3
 bInterfaceSubClass = 0
    HID
 bInterfaceProtocol = 0
    None
report descriptor size = 109
  endpoint = 82
    attributes = 3 Interrupt
    size = 8
    interval = 48
*** Device HID1 413c:2113 - connected ***
  product: Dell KB216 Wired Keyboard
*** Device HID2 413c:2113 - connected ***
  product: Dell KB216 Wired Keyboard
HIDDumpController(1 : 0x20004220 : 0x20009680) Claim: 413c:2113 usage: 10006 SubClass: 1 Protocol: 1 - Yes
>> Boot Keyboard - Send SET_IDLE <<

HID Report Descriptor (0x20009a18) size: 65
  05 01	// Usage Page(1) - Generic Desktop
  09 06	// Usage(6) -(Keyboard)
  A1 01	// Collection(1) top Usage(10000)
    05 07	// Usage Page(7) - Keycode
    19 E0	// Usage Minimum(e0) - (Left Control)
    29 E7	// Usage Maximum(e7) - (Right GUI)
    15 00	// Logical Minimum(0)
    25 01	// Logical maximum(1)
    75 01	// Report Size(1)
    95 08	// Report Count(8)
    81 02	// Input(2)	// (Data, Variable, Absolute)
    95 01	// Report Count(1)
    75 08	// Report Size(8)
    81 01	// Input(1)	// (Constant, Array, Absolute)
    95 03	// Report Count(3)
    75 01	// Report Size(1)
    05 08	// Usage Page(8) - LEDs
    19 01	// Usage Minimum(1) - 
    29 03	// Usage Maximum(3) - 
    91 02	// Output(2)	// (Data, Variable, Absolute)
    95 01	// Report Count(1)
    75 05	// Report Size(5)
    91 01	// Output(1)	// (Constant, Array, Absolute)
    95 06	// Report Count(6)
    75 08	// Report Size(8)
    15 00	// Logical Minimum(0)
    26 FF 00	// Logical maximum(ff)
    05 07	// Usage Page(7) - Keycode
    19 00	// Usage Minimum(0) - (Keycode 0)
    2A FF 00	// Usage Maximum(ff) - (Keycode 255)
    81 00	// Input(0)	// (Data, Array, Absolute)
    C0	// End Collection
*** HID Device hdc1 413c: 2113 - connected ***
  product: Dell KB216 Wired Keyboard
HIDDumpController(1 : 0x20004220 : 0x20009dc0) Claim: 413c:2113 usage: 10080 SubClass: 0 Protocol: 0 - NO (Usage: 10006)
HIDDumpController(2 : 0x20005300 : 0x20009dc0) Claim: 413c:2113 usage: 10080 SubClass: 0 Protocol: 0 - Yes

HID Report Descriptor (0x2000a158) size: 109
  05 01	// Usage Page(1) - Generic Desktop
  09 80	// Usage(80) -(?)
  A1 01	// Collection(1) top Usage(10080)
    85 01	// Report ID(1)
    19 81	// Usage Minimum(81) - (System Power Down)
    29 83	// Usage Maximum(83) - (System Wake Up)
    15 00	// Logical Minimum(0)
    25 01	// Logical maximum(1)
    75 01	// Report Size(1)
    95 03	// Report Count(3)
    81 02	// Input(2)	// (Data, Variable, Absolute)
    75 05	// Report Size(5)
    95 01	// Report Count(1)
    81 01	// Input(1)	// (Constant, Array, Absolute)
    C0	// End Collection
  05 0C	// Usage Page(c) - Consumer
  09 01	// Usage(1) -(Consumer Controls)
  A1 01	// Collection(1) top Usage(c0000)
    85 02	// Report ID(2)
    0A B5 00	// Usage(b5) -(Scan Next Track)
    0A B6 00	// Usage(b6) -(Scan Previous Track)
    0A B7 00	// Usage(b7) -(Stop)
    0A 83 01	// Usage(183) -(AL Consumer Control Configuration)
    0A CD 00	// Usage(cd) -(Pause/Continue)
    0A E9 00	// Usage(e9) -(Volume Up)
    0A EA 00	// Usage(ea) -(Volume Down)
    0A E2 00	// Usage(e2) -(Mute)
    0A 24 02	// Usage(224) -(AC Back)
    0A 8A 01	// Usage(18a) -(AL Email Reader)
    0A 25 02	// Usage(225) -(AC Forward)
    0A 23 02	// Usage(223) -(AC Home)
    0A 21 02	// Usage(221) -(AC Search)
    0A 26 02	// Usage(226) -(AC Stop)
    0A 27 02	// Usage(227) -(AC Refresh)
    0A 2A 02	// Usage(22a) -(AC Bookmarks)
    0A 92 01	// Usage(192) -(AL Calculator)
    0A 94 01	// Usage(194) -(AL Local Machine Browser)
    09 B8	// Usage(b8) -(Eject)
    0A A7 01	// Usage(1a7) -(?)
    75 01	// Report Size(1)
    95 14	// Report Count(14)
    81 02	// Input(2)	// (Data, Variable, Absolute)
    75 01	// Report Size(1)
    95 04	// Report Count(4)
    81 01	// Input(1)	// (Constant, Array, Absolute)
    C0	// End Collection
HIDDumpController(1 : 0x20004220 : 0x20009dc0) Claim: 413c:2113 usage: c0001 SubClass: 0 Protocol: 0 - NO (Usage: 10006)
HIDDumpController(2 : 0x20005300 : 0x20009dc0) Claim: 413c:2113 usage: c0001 SubClass: 0 Protocol: 0 - NO (Usage: 10080)
HIDDumpController(3 : 0x200063e0 : 0x20009dc0) Claim: 413c:2113 usage: c0001 SubClass: 0 Protocol: 0 - Yes

HID Report Descriptor (0x2000a158) size: 109
  05 01	// Usage Page(1) - Generic Desktop
  09 80	// Usage(80) -(?)
  A1 01	// Collection(1) top Usage(10080)
    85 01	// Report ID(1)
    19 81	// Usage Minimum(81) - (System Power Down)
    29 83	// Usage Maximum(83) - (System Wake Up)
    15 00	// Logical Minimum(0)
    25 01	// Logical maximum(1)
    75 01	// Report Size(1)
    95 03	// Report Count(3)
    81 02	// Input(2)	// (Data, Variable, Absolute)
    75 05	// Report Size(5)
    95 01	// Report Count(1)
    81 01	// Input(1)	// (Constant, Array, Absolute)
    C0	// End Collection
  05 0C	// Usage Page(c) - Consumer
  09 01	// Usage(1) -(Consumer Controls)
  A1 01	// Collection(1) top Usage(c0000)
    85 02	// Report ID(2)
    0A B5 00	// Usage(b5) -(Scan Next Track)
    0A B6 00	// Usage(b6) -(Scan Previous Track)
    0A B7 00	// Usage(b7) -(Stop)
    0A 83 01	// Usage(183) -(AL Consumer Control Configuration)
    0A CD 00	// Usage(cd) -(Pause/Continue)
    0A E9 00	// Usage(e9) -(Volume Up)
    0A EA 00	// Usage(ea) -(Volume Down)
    0A E2 00	// Usage(e2) -(Mute)
    0A 24 02	// Usage(224) -(AC Back)
    0A 8A 01	// Usage(18a) -(AL Email Reader)
    0A 25 02	// Usage(225) -(AC Forward)
    0A 23 02	// Usage(223) -(AC Home)
    0A 21 02	// Usage(221) -(AC Search)
    0A 26 02	// Usage(226) -(AC Stop)
    0A 27 02	// Usage(227) -(AC Refresh)
    0A 2A 02	// Usage(22a) -(AC Bookmarks)
    0A 92 01	// Usage(192) -(AL Calculator)
    0A 94 01	// Usage(194) -(AL Local Machine Browser)
    09 B8	// Usage(b8) -(Eject)
    0A A7 01	// Usage(1a7) -(?)
    75 01	// Report Size(1)
    95 14	// Report Count(14)
    81 02	// Input(2)	// (Data, Variable, Absolute)
    75 01	// Report Size(1)
    95 04	// Report Count(4)
    81 01	// Input(1)	// (Constant, Array, Absolute)
    C0	// End Collection
*** HID Device hdc2 413c: 2113 - connected ***
  product: Dell KB216 Wired Keyboard
*** HID Device hdc3 413c: 2113 - connected ***
  product: Dell KB216 Wired Keyboard

Side notes on testing with this keyboard:
1)If I unplug this device from the GIGA, after the sketch starts, will crash the MBED OS...
2) Does not respond to any of the multimedia or system keys
3) Does not handle things like capslock and likewise the led states.

The one that the GIGA keyboard sketch does not respond to:

*** Device Hub1 413c:1004 - connected ***
  manufacturer: Dell
  product: Dell USB Keyboard Hub

USBDeviceInfo claim this=2000CF64

****************************************
** Device Level **
  vid=413C
  pid=2006
  bDeviceClass = 0
  bDeviceSubClass = 0
  bDeviceProtocol = 0
09 04 00 00 01 03 01 01 02 09 21 10 01 00 01 22 41 00 07 05 81 03 08 00 0A 09 04 01 00 01 03 00
00 02 09 21 10 01 00 01 22 8E 00 07 05 82 03 04 00 FF 
*** Device HID1 413c:2006 - connected ***
  manufacturer: Dell
  product: Dell USB Keyboard Hub
*** Device HID2 413c:2006 - connected ***
  manufacturer: Dell
  product: Dell USB Keyboard Hub
HIDDumpController(1 : 0x20004220 : 0x20009680) Claim: 413c:2006 usage: 10006 SubClass: 1 Protocol: 1 - Yes
>> Boot Keyboard - Send SET_IDLE <<

HID Report Descriptor (0x20009a18) size: 65
  05 01	// Usage Page(1) - Generic Desktop
  09 06	// Usage(6) -(Keyboard)
  A1 01	// Collection(1) top Usage(10000)
    05 07	// Usage Page(7) - Keycode
    19 E0	// Usage Minimum(e0) - (Left Control)
    29 E7	// Usage Maximum(e7) - (Right GUI)
    15 00	// Logical Minimum(0)
    25 01	// Logical maximum(1)
    75 01	// Report Size(1)
    95 08	// Report Count(8)
    81 02	// Input(2)	// (Data, Variable, Absolute)
    95 01	// Report Count(1)
    75 08	// Report Size(8)
    81 01	// Input(1)	// (Constant, Array, Absolute)
    95 05	// Report Count(5)
    75 01	// Report Size(1)
    05 08	// Usage Page(8) - LEDs
    19 01	// Usage Minimum(1) - 
    29 05	// Usage Maximum(5) - 
    91 02	// Output(2)	// (Data, Variable, Absolute)
    95 01	// Report Count(1)
    75 03	// Report Size(3)
    91 01	// Output(1)	// (Constant, Array, Absolute)
    95 06	// Report Count(6)
    75 08	// Report Size(8)
    15 00	// Logical Minimum(0)
    26 FF 00	// Logical maximum(ff)
    05 07	// Usage Page(7) - Keycode
    19 00	// Usage Minimum(0) - (Keycode 0)
    2A FF 00	// Usage Maximum(ff) - (Keycode 255)
    81 00	// Input(0)	// (Data, Array, Absolute)
    C0	// End Collection
*** HID Device hdc1 413c: 2006 - connected ***
  manufacturer: Dell
  product: Dell USB Keyboard Hub
HIDDumpController(1 : 0x20004220 : 0x20009dc0) Claim: 413c:2006 usage: c0001 SubClass: 0 Protocol: 0 - NO (Usage: 10006)
HIDDumpController(2 : 0x20005300 : 0x20009dc0) Claim: 413c:2006 usage: c0001 SubClass: 0 Protocol: 0 - Yes

HID Report Descriptor (0x2000a158) size: 142
  05 0C	// Usage Page(c) - Consumer
  09 01	// Usage(1) -(Consumer Controls)
  A1 01	// Collection(1) top Usage(c0000)
    85 01	// Report ID(1)
    09 E0	// Usage(e0) -(Volume)
    15 E8	// Logical Minimum(e8)
    25 18	// Logical maximum(18)
    75 07	// Report Size(7)
    95 01	// Report Count(1)
    81 06	// Input(6)	// (Data, Variable, Relative)
    15 00	// Logical Minimum(0)
    25 01	// Logical maximum(1)
    75 01	// Report Size(1)
    09 E2	// Usage(e2) -(Mute)
    81 06	// Input(6)	// (Data, Variable, Relative)
    C0	// End Collection
  05 01	// Usage Page(1) - Generic Desktop
  09 80	// Usage(80) -(?)
  A1 01	// Collection(1) top Usage(10080)
    85 02	// Report ID(2)
    15 00	// Logical Minimum(0)
    25 01	// Logical maximum(1)
    75 01	// Report Size(1)
    95 03	// Report Count(3)
    09 82	// Usage(82) -(System Sleep)
    09 82	// Usage(82) -(System Sleep)
    09 82	// Usage(82) -(System Sleep)
    81 06	// Input(6)	// (Data, Variable, Relative)
    95 05	// Report Count(5)
    81 01	// Input(1)	// (Constant, Array, Absolute)
    C0	// End Collection
  05 0C	// Usage Page(c) - Consumer
  09 01	// Usage(1) -(Consumer Controls)
  A1 01	// Collection(1) top Usage(c0000)
    85 03	// Report ID(3)
    15 00	// Logical Minimum(0)
    25 01	// Logical maximum(1)
    75 01	// Report Size(1)
    95 01	// Report Count(1)
    0A 24 02	// Usage(224) -(AC Back)
    81 06	// Input(6)	// (Data, Variable, Relative)
    0A 25 02	// Usage(225) -(AC Forward)
    81 06	// Input(6)	// (Data, Variable, Relative)
    0A 26 02	// Usage(226) -(AC Stop)
    81 06	// Input(6)	// (Data, Variable, Relative)
    0A 27 02	// Usage(227) -(AC Refresh)
    81 06	// Input(6)	// (Data, Variable, Relative)
    0A 23 02	// Usage(223) -(AC Home)
    81 06	// Input(6)	// (Data, Variable, Relative)
    0A 8A 01	// Usage(18a) -(AL Email Reader)
    81 06	// Input(6)	// (Data, Variable, Relative)
    0A 94 01	// Usage(194) -(AL Local Machine Browser)
    81 06	// Input(6)	// (Data, Variable, Relative)
    0A 92 01	// Usage(192) -(AL Calculator)
    81 06	// Input(6)	// (Data, Variable, Relative)
    09 B5	// Usage(b5) -(Scan Next Track)
    81 06	// Input(6)	// (Data, Variable, Relative)
    09 B6	// Usage(b6) -(Scan Previous Track)
    81 06	// Input(6)	// (Data, Variable, Relative)
    09 CD	// Usage(cd) -(Pause/Continue)
    81 06	// Input(6)	// (Data, Variable, Relative)
    09 B7	// Usage(b7) -(Stop)
    81 06	// Input(6)	// (Data, Variable, Relative)
    0A 83 01	// Usage(183) -(AL Consumer Control Configuration)
    81 06	// Input(6)	// (Data, Variable, Relative)
    95 0B	// Report Count(b)
    81 01	// Input(1)	// (Constant, Array, Absolute)
    C0	// End Collection
HIDDumpController(1 : 0x20004220 : 0x20009dc0) Claim: 413c:2006 usage: 10080 SubClass: 0 Protocol: 0 - NO (Usage: 10006)
HIDDumpController(2 : 0x20005300 : 0x20009dc0) Claim: 413c:2006 usage: 10080 SubClass: 0 Protocol: 0 - NO (Usage: c0001)
HIDDumpController(3 : 0x200063e0 : 0x20009dc0) Claim: 413c:2006 usage: 10080 SubClass: 0 Protocol: 0 - Yes

HID Report Descriptor (0x2000a158) size: 142
  05 0C	// Usage Page(c) - Consumer
  09 01	// Usage(1) -(Consumer Controls)
  A1 01	// Collection(1) top Usage(c0000)
    85 01	// Report ID(1)
    09 E0	// Usage(e0) -(Volume)
    15 E8	// Logical Minimum(e8)
    25 18	// Logical maximum(18)
    75 07	// Report Size(7)
    95 01	// Report Count(1)
    81 06	// Input(6)	// (Data, Variable, Relative)
    15 00	// Logical Minimum(0)
    25 01	// Logical maximum(1)
    75 01	// Report Size(1)
    09 E2	// Usage(e2) -(Mute)
    81 06	// Input(6)	// (Data, Variable, Relative)
    C0	// End Collection
  05 01	// Usage Page(1) - Generic Desktop
  09 80	// Usage(80) -(?)
  A1 01	// Collection(1) top Usage(10080)
    85 02	// Report ID(2)
    15 00	// Logical Minimum(0)
    25 01	// Logical maximum(1)
    75 01	// Report Size(1)
    95 03	// Report Count(3)
    09 82	// Usage(82) -(System Sleep)
    09 82	// Usage(82) -(System Sleep)
    09 82	// Usage(82) -(System Sleep)
    81 06	// Input(6)	// (Data, Variable, Relative)
    95 05	// Report Count(5)
    81 01	// Input(1)	// (Constant, Array, Absolute)
    C0	// End Collection
  05 0C	// Usage Page(c) - Consumer
  09 01	// Usage(1) -(Consumer Controls)
  A1 01	// Collection(1) top Usage(c0000)
    85 03	// Report ID(3)
    15 00	// Logical Minimum(0)
    25 01	// Logical maximum(1)
    75 01	// Report Size(1)
    95 01	// Report Count(1)
    0A 24 02	// Usage(224) -(AC Back)
    81 06	// Input(6)	// (Data, Variable, Relative)
    0A 25 02	// Usage(225) -(AC Forward)
    81 06	// Input(6)	// (Data, Variable, Relative)
    0A 26 02	// Usage(226) -(AC Stop)
    81 06	// Input(6)	// (Data, Variable, Relative)
    0A 27 02	// Usage(227) -(AC Refresh)
    81 06	// Input(6)	// (Data, Variable, Relative)
    0A 23 02	// Usage(223) -(AC Home)
    81 06	// Input(6)	// (Data, Variable, Relative)
    0A 8A 01	// Usage(18a) -(AL Email Reader)
    81 06	// Input(6)	// (Data, Variable, Relative)
    0A 94 01	// Usage(194) -(AL Local Machine Browser)
    81 06	// Input(6)	// (Data, Variable, Relative)
    0A 92 01	// Usage(192) -(AL Calculator)
    81 06	// Input(6)	// (Data, Variable, Relative)
    09 B5	// Usage(b5) -(Scan Next Track)
    81 06	// Input(6)	// (Data, Variable, Relative)
    09 B6	// Usage(b6) -(Scan Previous Track)
    81 06	// Input(6)	// (Data, Variable, Relative)
    09 CD	// Usage(cd) -(Pause/Continue)
    81 06	// Input(6)	// (Data, Variable, Relative)
    09 B7	// Usage(b7) -(Stop)
    81 06	// Input(6)	// (Data, Variable, Relative)
    0A 83 01	// Usage(183) -(AL Consumer Control Configuration)
    81 06	// Input(6)	// (Data, Variable, Relative)
    95 0B	// Report Count(b)
    81 01	// Input(1)	// (Constant, Array, Absolute)
    C0	// End Collection
HIDDumpController(1 : 0x20004220 : 0x20009dc0) Claim: 413c:2006 usage: c0001 SubClass: 0 Protocol: 0 - NO (Usage: 10006)
HIDDumpController(2 : 0x20005300 : 0x20009dc0) Claim: 413c:2006 usage: c0001 SubClass: 0 Protocol: 0 - Yes
*** HID Device hdc2 413c: 2006 - connected ***
  manufacturer: Dell
  product: Dell USB Keyboard Hub
*** HID Device hdc3 413c: 2006 - connected ***
  manufacturer: Dell
  product: Dell USB Keyboard Hub

Now I remember, this keyboard has a built-in HUB, and the actual keyboard object is logically connected to one of the ports of the internal hub.

But now probably should try some Serial objects, to see how they are supported. As that is the title of this thread.

A bit more info - looking at the Joystick a bit more that just sets things up to make the Giga look like a joystick - not for reading a joystick - now off to gamepad

1 Like

Tried Serial test trying to plug in Arduino UNO R4 MINIMA into the GIGA, programmed with real simple sketch:

#include <elapsedMillis.h> 

elapsedMillis emLastOutput;

void setup() {
  while (!Serial) {}
  Serial.begin(115200);
  pinMode(2, INPUT_PULLUP);
  emLastOutput = 0;
  Serial.println("Simple Echo USB Back test");

}

int loop_count;
void loop() {
  int ch;
  while ((ch = Serial.read()) != -1) {
    Serial.write(ch);
  }

  if (!digitalRead(2)  && emLastOutput > 5000) {
    emLastOutput = 0;
    Serial.print("Loop Count: ");
    Serial.println(++loop_count, DEC);
  }
}

It is not echoing any Serial output to the USB port using GIGA keyboard example sketch mentioned in previous post, nor is it connecting to a similar sketch as the keyboard one in previous post:

#define USBHOST_OTHER
#include <Arduino_USBHostMbed5.h>

USBHostSerial userial;

void setup() {
  Serial.begin(115200);
  while (!Serial) {}

  Serial.println("Starting Serial test...");

  // Enable the USBHost
  pinMode(PA_15, OUTPUT);
  digitalWrite(PA_15, HIGH);

  while (!userial.connect()) {
    Serial.println("No USB Serial device connected");
    delay(5000);
  }
}

void loop() {
  // print characters received
  while (userial.available()) {
    Serial.write(userial.getc());
  }

  delay(1000);
}

Note: The one place I saw a sort of an Serial example sketch:
Mbed OS5 - Nucleo USB host Serial - Mbed OS - Arm Mbed OS support forum

EDIT: I just noticed the comment line about seeing debug data:
REDIRECT_STDOUT_TO(Serial)

With this in the KeyboardGiga.ino sketch:

USB Device Connected
USB Device Reset Completed
PID: 69h
VID: 2341h
Address (#1) assigned.
Manufacturer : Arduino
Product : UNO R4 Minima
Serial Number : 37192C3059333032A08733324B572E63
Enumeration done.
This device has only 1 configuration.
Default configuration set.
DEBUG : Cannot Find the interface for Communication Interface Class.
Device not supporting CDC class.

Looks like it is not supported

EDIT 2:

Tried with Teensy 3.2 with same sketch:
It sort of liked it:

USB Device Connected
USB Device Reset Completed
PID: 483h
VID: 16c0h
Address (#1) assigned.
Manufacturer : Teensyduino
Product : USB Serial
Serial Number : 1550130
Enumeration done.
This device has only 1 configuration.
Default configuration set.
Switching to Interface (#0)
Class : 2h
SubClass : 2h
Protocol : 1h
CDC class started.
ERROR: Control error: CDC: Device Get Line Coding configuration failed
ERROR: Control error: CDC: Device Get Line Coding configuration failed
ERROR: Control error: CDC: Device Get Line Coding configuration failed
!!! it kept repeating the error output !!!

Tried porting over the USBHostGamepad library but only got as far as it being able to connect.
PS4:

Starting Gamepad test...
No gamepad connected
VID: 54C, PID: 5C4

New Gamepad device: VID:054c PID:05c4 [dev: 0x2400c6bc - intf: 0]Dev connected
Gamepad connected

Xbox - doesnt seem to recognize it

VID: 54C, PID: 9CC
No gamepad connected

Nintendo Switch:

VID: 57E, PID: 2009
New Gamepad device: VID:057e PID:2009 [dev: 0x2400c6bc - intf: 0]Dev connected
Gamepad connected

The library uses attachevent to capture gamepad data but the callback does not seem to firing at all.

The primary sketch looks like:

#include <Arduino_USBHostMbed5.h>
#include <LibPrintf.h>
#include "USBHostGamepad.h"

USBHostGamepad gamepad;

void onGamepadEvent(uint8_t x, uint8_t y, uint8_t z, uint8_t rz, uint16_t buttons) {
    printf("x: %02X, y: %02X, z: %02X, rz: %02X, buttons: %04X\r\n", x, y, z, rz, buttons);
}

void setup()
{
    Serial.begin(115200);
    while (!Serial) {}

    Serial.println("Starting Gamepad test...");

    // Enable the USBHost 
    pinMode(PA_15, OUTPUT);
    digitalWrite(PA_15, HIGH);

    while (!gamepad.connect()) {
      Serial.println("No gamepad connected");        
        delay(5000);
    }

    Serial.println("Gamepad connected");
    gamepad.attachEvent(onGamepadEvent);

}

void loop()
{

}

here is the whole things
GamePad-231028a.zip (3.5 KB)

1 Like

I might try something similar for one of the USB Serial adapters and see if it helps me to understand more of this (mbed5) library.

So far it looks, like it is up to the sketch to say connect me to a device if there is one... Versus other libraries work like, here is a set of devices my code is interested in, and when a new device is inserted (or at startup), the usb enumeration code will walk through each of the device objects that are registered and see if one wants it...

Now time to play.

@KurtE
Two things. You can turn debug on in dbg.h in the USBHost directory if interested. Just did that:

Starting Gamepad test...
[USB_DBG: d:\Users\Merli\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:937]dev: 0x2400c6bc nb_intf: 0
[USB_DBG: d:\Users\Merli\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:938]dev: 0x2400c6bc nb_intf_attached: 0
[USB_DBG: d:\Users\Merli\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:944]Enumerate dev: 0x2400c6bc
[USB_DBG: d:\Users\Merli\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:959]CLASS: 00 	 VID: 054C 	 PID: 05C4
[USB_INFO: D:\Users\Merli\Documents\Arduino\Arduino Giga\GamePad\USBHostGamepad.cpp:124]VID: 54C, PID: 5C4


VID: 54C, PID: 5C4

[USB_DBG: d:\Users\Merli\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:876]TOTAL_LENGTH: 41 	 NUM_INTERF: 1
[USB_DBG: d:\Users\Merli\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:969]CONFIGURATION DESCRIPTOR:

09 02 29 00 01 01 00 C0 FA 09 04 00 00 02 03 00 00 00 09 21 11 01 00 01 22 F3 01 07 05 84 03 40 00 05 07 05 03 03 40 00 05 

[USB_DBG: d:\Users\Merli\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:1021]dev: 0x2400c6bc has 1 intf
[USB_DBG: d:\Users\Merli\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:1030]ADD INTF 0 on device 0x2400c6bc: class: 3, subclass: 0, proto: 0
[USB_DBG: d:\Users\Merli\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:610]USBEndpoint created (0x2400c0ac): type: 3, dir: 2, size: 64, addr: 4, state: USB_TYPE_IDLE
[USB_DBG: d:\Users\Merli\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:1049]ADD USBEndpoint 0x2400c0ac, on interf 0 on device 0x2400c6bc
[USB_DBG: d:\Users\Merli\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:982]Set configuration 1 on dev: 0x2400c6bc
[USB_DBG: d:\Users\Merli\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:995]dev 0x2400c6bc is enumerated

[USB_INFO: D:\Users\Merli\Documents\Arduino\Arduino Giga\GamePad\USBHostGamepad.cpp:69]New Gamepad device: VID:054c PID:05c4 [dev: 0x2400c6bc - intf: 0]
New Gamepad device: VID:054c PID:05c4 [dev: 0x2400c6bc - intf: 0]
[USB_DBG: d:\Users\Merli\Documents\Arduino\libraries\Arduino_USBHostMbed5\src/USBHost/USBHost.h:170]register driver for dev: 0x2400c6bc on intf: 0
Dev connected
Gamepad connected

Just show event is not being triggered.

EDIT: Wonder if should downgrade to 0.0.3

1 Like

I found that debug setting as well... Helped to edit the right copy of the file.... (I have two versions on my machine).
When I plug in FTDI to my serial test above, I see:

Starting Serial test...

No USB Serial device connected
No USB Serial device connected
No USB Serial device connected
No USB Serial device connected
No USB Serial device connected
No USB Serial device connected
Starting Serial test...
[USB_DBG: c:\Users\kurte\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBDeviceConnected.cpp:88]init dev: 0x2400d5dc
[USB_DBG: c:\Users\kurte\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:610]USBEndpoint created (0x2400cf34): type: 0, dir: 1, size: 8, addr: 0, state: USB_TYPE_IDLE
[USB_DBG: c:\Users\kurte\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:623]Resetting hub 0, port 1
[USB_DBG: c:\Users\kurte\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:150]usb_thread read device descriptor on dev: 0x2400d5dc
[USB_DBG: c:\Users\kurte\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:169]Address of 0x2400d5dc: 1
[USB_INFO: c:\Users\kurte\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:189]New device connected: 0x2400d5dc [hub: 0 - port: 1]
[USB_DBG: c:\Users\kurte\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:937]dev: 0x2400d5dc nb_intf: 0
[USB_DBG: c:\Users\kurte\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:938]dev: 0x2400d5dc nb_intf_attached: 0
[USB_DBG: c:\Users\kurte\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:944]Enumerate dev: 0x2400d5dc
[USB_DBG: c:\Users\kurte\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:959]CLASS: 00 VID: 0103 PID: 0000
[USB_DBG: c:\Users\kurte\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:876]TOTAL_LENGTH: 32 NUM_INTERF: 1
[USB_DBG: c:\Users\kurte\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:969]CONFIGURATION DESCRIPTOR:

09 02 20 00 01 01 00 A0 FF 02 07 05 81 02 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

[USB_DBG: c:\Users\kurte\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:1021]dev: 0x2400d5dc has 1 intf

And that is it.

Note: with many of these devices, I believe we needed to send out specific messages in order to get them to start sending data.

@Merlin513 (and @ptillisch)

The Arduino_USBHostMbed5 library is driving me nuts!

I thought I would hack up a Serial object to try to handle some of the USB To Serial adapters like FTDI, PL2303, etc...

I started from @Merlin513 sketch to try to get some gamepads to work.
Note it is a WIP, and uses things like my own Memory dump library (although not actually made it far enough in the code to actually get called... But in case anyone is curious...

USBHost_FTDI_plus-231029a.zip (4.4 KB)

I first tried an FTDI USB to Serial adapter, like
FTDI Cable 5V - DEV-09718 - SparkFun Electronics

It does not get very far at all. The first thing I would need to do is to debug why the system is getting the wrong Vendor and Product IDS. Mainly: VID: 0103 PID: 0000
Which I know should be:
vid=403 pid=6001 bDeviceClass = 0 bDeviceSubClass = 0 bDeviceProtocol = 0
Which I see on Teensy, Windows, Linux...

PL2303
So then I tried the GPS device mentioned early in this thread, which uses a PL2303 chipset
{ 0x67B, 0x2303, USBHostFTDI::PL2303, 0 },
I receive the correct VID:PID for this one.

Some of the changes I made from the gamepad sketch to this one, is the gamepad sketch was setup to handle one ENDPOINT which is INTERRUPT and IN.

Most of these Serial adapters appear to have 3 interfaces. The first being an IN Interrupt, which in other code base we ignore, then the have to BULK end points, one IN the other OUT.

The sketch class code checks for the endpoints like:

/*virtual*/ bool USBHostFTDI::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir)  //Must return true if the endpoint will be used
{
  USB_INFO("USBHostFTDI::useEndpoint(%u, %u, %u\n\r", intf_nb, type, dir);
  printf("USBHostFTDI::useEndpoint(%u, %u, %u\n\r", intf_nb, type, dir);
  if (intf_nb == intf_SerialDevice) {
    //if (type == INTERRUPT_ENDPOINT && dir == IN) return true; // see if we can ignore it later

    if (type == BULK_ENDPOINT && dir == IN) {
      hser_device_found = true;
      return true;
    }
    if (type == BULK_ENDPOINT && dir == OUT) {
      hser_device_found = true;
      return true;
    }
  }
  return false;
}

Debug output from here shows:

USBHostFTDI::useEndpoint(0, 3, 2

[USB_INFO: C:\Users\kurte\Documents\Arduino\Arduino_GIGA\USBHost_FTDI_plus\USBHostFTDI.cpp:176]USBHostFTDI::useEndpoint(0, 2, 1


USBHostFTDI::useEndpoint(0, 2, 1

[USB_DBG: c:\Users\kurte\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:610]USBEndpoint created (0x2400c16c): type: 2, dir: 1, size: 64, addr: 2, state: USB_TYPE_IDLE
[USB_DBG: c:\Users\kurte\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:1059]ADD USBEndpoint 0x2400c16c, on interf 0 on device 0x2400c77c
[USB_INFO: C:\Users\kurte\Documents\Arduino\Arduino_GIGA\USBHost_FTDI_plus\USBHostFTDI.cpp:176]USBHostFTDI::useEndpoint(0, 2, 2


USBHostFTDI::useEndpoint(0, 2, 2

[USB_DBG: c:\Users\kurte\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:610]USBEndpoint created (0x2400c204): type: 2, dir: 2, size: 64, addr: 3, state: USB_TYPE_IDLE
[USB_DBG: c:\Users\kurte\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:1059]ADD USBEndpoint 0x2400c204, on interf 0 on device 0x2400c77c
[USB_DBG: c:\Users\kurte\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:992]Set configuration 1 on dev: 0x2400c77c
[USB_DBG: c:\Users\kurte\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBHost.cpp:1005]dev 0x2400c77c is enumerated

The connect code then tries to get the Endpoints like:

      printf("\tconnect hser_device_found\n\r");

      bulk_in = d->getEndpoint(intf_SerialDevice, BULK_ENDPOINT, IN);
      USB_INFO("bulk in:%p", bulk_in);

      bulk_out = d->getEndpoint(intf_SerialDevice, BULK_ENDPOINT, OUT);
      USB_INFO(" out:%p\r\n", bulk_out);

The getEndpoint call faults and I get the RED blinking lights.

I instrumented the code, hoped that maybe NULL ptr so added test... Still faults:

USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index) {
    USB_DBG("getEndpoint(%u %u %u %u %p", intf_nb, type, dir, index);
    if (intf_nb >= MAX_INTF) {
        return NULL;
    }
    for (int i = 0; i < MAX_ENDPOINT_PER_INTERFACE; i++) {
        USB_DBG("index: %d %p", i, intf[intf_nb].ep[i]);
        if ( intf[intf_nb].ep[i] == nullptr) continue; // don't walk through NULL
        if ((intf[intf_nb].ep[i]->getType() == type) && (intf[intf_nb].ep[i]->getDir() == dir)) {
            if(index) {
                index--;
            } else {
                return intf[intf_nb].ep[i];
            }
        }
    }
    return NULL;
}

connect hser_device_found

[USB_DBG: c:\Users\kurte\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBDeviceConnected.cpp:104]getEndpoint(0 2 2 0 0x2

[USB_DBG: c:\Users\kurte\Documents\Arduino\libraries\Arduino_USBHostMbed5\src\USBHost\USBDeviceConnected.cpp:109]index: 0 0xffff

So the pointer has the value 0xffff...

I have not tried to debug this yet. Could it be because the code is configured for a max of 2 endpoints, but these have 3? Could it be bulk versus not interrupt? Or random memory error...
Or something in my sketch which is not correct...

PID 0000 makes me think back to when FTDI made a Windows driver release that changed the PID on counterfeit FT232R chips from the normal 6001 to 0000:

The versions of the driver since that time don't change the PID, but any chips which were "bricked" by the previous driver release will continue to have the same PID. There were some workarounds for adding driver support for the device with the 0000 PID, so those who made those workarounds might have been using the FT232R ever since that time with the 0000 PID (instead of using the FT_Prog tool to change the PID back to 6001).

However, that wouldn't explain the VID of 0103. The driver release only changed the PID of the counterfeit chips.

After reading your GitHub issue, I see I misunderstood the "Which I see on Teensy, Windows, Linux..." part. I had the impression you were getting the 0103:0000 VID/PID on all platforms, but now I understand that the incorrect VID/PID is specific to the GIGA R1 WiFi and you are getting the correct one on all the other platforms, so it is definitely nothing to do with the FTDI driver situation I mentioned in my previous reply.

1 Like

Thanks,

I created an issue

Wondering if more generic issue, maybe the control endpoint is not getting the size updated.