nikthefix / ESP32-S3-USB-HOST

General issues with USB Host options
0 stars 0 forks source link

Thread migrated from Lilygo github #1

Open nikthefix opened 7 months ago

nikthefix commented 7 months ago

Thread migrated from Lilygo github....

momosh13 commented yesterday • Hi nikthefix If you're still in this forum, I have a question for you, if I may? I don't know anybody, who my help me, but you:) I'm working on this project many months and almost no progress, I'm trying to send HEX command from Arduino / USB Host to USB device to control some functions. I tried it, Teensy 4.1 with https://github.com/PaulStoffregen/USBHost_t36 library, and Arduino USB Host Shield 2.0 with https://github.com/felis/USB_Host_Shield_2.0 library, no luck. I need to send this HEX

1b 00 a0 24 08 16 0a d7 ff ff 00 00 00 00 09 00 00 03 00 17 00 02 03 53 00 00 00 00 40 00 40 48 48 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 08 48 08 08 48 08 00 40 00 08 48 08 00 40 00 08 48 08 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 08 48 08 00 40 00 00 40 00 00 40 48

to (Vendor Specific) USB Device. I got the HEX, by sniffing communication between Windows control software and the device, with Wireshark. Please, maybe you can help me again. Thank you

@nikthefix nikthefix commented 15 hours ago • @momosh13 I have some of these USB host boards so I can look into it with you. Which board are you using? There is the Uno shield and the smaller design from here:

https://circuitsathome.com/usb-host-shield-for-arduino-pro-mini/

There are cheap clones of the 'mini' circuits at home design version which are slightly different in the power delivery department. A small hardware mod is necessary to bring the clones in-line with the original. Details can be found here:

https://geekhack.org/index.php?topic=80421.0

What does the vendor specific device enumerate as in your computer device manager? Does it use a custom USB driver or is it class compliant?

I have the host shield working fine with the CDC USB of my laser cutter GRBL controller, and I've had it working well with keyboard / mouse and also FTDI.

These host boards are usually limited to driving only devices catered for in the libraries - CDC, keyboard, joystick, MSD etc. For custom devices (non-class compliant) you may have to write your own driver. But the Arduino lib you mention does have many device profiles - not all standard class compliant - so it's possible you could adapt one of these profiles.

I suspect that your device is USB-HID generic. If so then that's a good thing.

I suggest initially testing your hardware by trying the USB Keyboard profile - just to make sure that the 500ma power requirements are met, or at least sufficient to drive your device (assuming it's bus powered).

The ESP32-S3 can also act as host natively - bypassing the need for SPI comms.

https://github.com/tanakamasayuki/EspUsbHost

I've been using this solution myself and it's neat as it uses no extra hardware. You just need a dev board with 2 usb ports and a wire jumper to bridge 5v to the host port and a USB OTG cable.

nik

@momosh13 momosh13 commented 3 hours ago Thank you for reply I have two hardwere otions and i have no problem connecting to my device and read the info from it, the device is USB-HID.

i have teensy 4.1 board, please see the picture IMG_3169 and with https://github.com/PaulStoffregen/USBHost_t36 library, example HIDDeviceInfo the serial monitor giving me this T4 1 info

then i have Arduino USB Host Shield 2.0 with theensy 4.0, please see the picture IMG_3173 whit this one, https://github.com/felis/USB_Host_Shield_2.0 library, exsample USB_desc, i'm geting this

T4 0 info

So, my problem is, i don't now how to send the HEX command to my device, i have no idea.

About the HEX in the previous post. in the Wireshark, i see this

1

2 3 4 5 6 7 8 9 10 11

@momosh13 momosh13 commented 1 hour ago I just got one of this to, if you thing, this will make it easier

51LRBUCGc+L AC_SL1050

@nikthefix nikthefix commented 27 minutes ago • @momosh13

OK all that info really helps.

First I'd try the Teensy setup and run the example:

https://github.com/PaulStoffregen/USBHost_t36/tree/master/examples/RawHID/RawHIDtoUSBHostRawHID

Copy the VID and PID from your HIDDeviceInfo dump into the example sketch and start experimenting with Report Descriptors from there.

Here's a useful tool for Windows which will allow you to test data strings to confirm functionality:

https://www.researchgate.net/figure/HID-terminal-program-used-to-send-commands-to-micro-controller_fig11_268323254

I think it's important to establish working HID comms between PC and Device using the HID terminal before migrating to the MCU as it'll probably save a lot of time in the end.

You'll probably also need vendor specific documentation for your device Report Descriptor format. This is not revealed in the HIDDeviceInfo dump so it's guesswork unless it's class compliant or you have documentation. However, you can reverse engineer it by looking closely at the HID terminal I/O while messing around.

Can I ask what the HID device product is? Also, all things being equal, do you need your final project to use Teensy or are you hoping to use ESP?

We should move this chat as it's not a Lilygo topic. I'll add a repo on my github (https://github.com/nikthefix). Let's carry on there.

nik

momosh13 commented 7 months ago

Thank you for all that info. Let me try to understand the HID-Terminal and the RawHIDtoUSBHostRawHID example, and I'll let you know as soon as possible. I like to use ESP32-S3, if possible, and I'm receiving my first ESP32-S3 on Friday.

nikthefix commented 7 months ago

@momosh13

Here's another useful link: https://github.com/touchgadget/esp32-usb-host-demos

nik

momosh13 commented 7 months ago

Hi nikthefix. I'm stock, lot's of problems.

  1. the device is NOT HID, in my computer Device Manager it showing up in Universal Serial Bus controllers.
  2. In two deferent Windows tools (YAT-2 and mikroC) this device not getting detected, when I'm connecting normal HID devices to this tools, they are insanely poping out in this tools as a HID devices, but not my device.
  3. I can't get ESP32-S2-DevKitC-1 or S3 to connect or get any information from it, with this library https://github.com/touchgadget/esp32-usb-host-demos with USB Host Shield 2.0 and with Teensy I was at list getting something from it. Please help me
nikthefix commented 7 months ago

@momosh13 If your device is showing up in 'Universal Serial Bus controllers' then it sounds like it is implementing a usb hub in addition to one or more HID or custom devices. The touchgadget code (as far as I'm aware) doesn't support a Hub in the pipeline. Can I ask what the device is - model / brand?

The USB_Host_Shield DOES support a hub in the pipeline so it looks like it would make be a better choice in your case. But check the FAQ: https://github.com/felis/USB_Host_Shield_2.0/tree/master Hub support must be included as follows:

////////////////////// FAQ When I plug my device into the USB connector nothing happens?

Try to connect a external power supply to the Arduino - this solves the problem in most cases. You can also use a powered hub between the device and the USB Host Shield. You should then include the USB hub library: #include and create the instance like so: USBHub Hub1(&Usb);. //////////////////////

Upon reflection, In many ways the combination of ESP32-S3 + USB Host Shield is a more flexible setup as it means that you can still use the native ESP USB for MSC, CDC, Midi, Mouse/keyboard emulation etc - features which would be stolen by the ESP USB HOST mode if used. One typical use case would be an HID keyboard re-mapper which takes the keyboard input and translates the keycodes before resending them using the ESP as a keyboard emulator. Or perhaps a QWERTY to Midi controller. You couldn't do this with a single ESP32-S3 unless you implemented an additional 'soft / bitbanged' USB device. Very slow.

nik

momosh13 commented 7 months ago

The device is this

https://decimator.com/Products/MultiViewers/DMON-16S%20MultiViewer/DMON-16S.html

here you have Brand, Model and USB Control Panel Windows Tool. Thank you

nikthefix commented 7 months ago

@momosh13 Blimey! That's a bit of kit!!! So it's obviously a USB composite device. Which endpoints are you wanting to establish comms with? Presumably an HID control / config endpoint? Do you have a datasheet for the supported USB Report Descriptors? If so then it's definitely doable. If not then it's gonna be a 'reverse engineering needle in a haystack nightmare'.

You have the PC control software but I assume you want to delegate that control to an MCU. Am I right? Is the PC software open source - can you examine the code?

If you have a datasheet of USB descriptors then please post them here.

If the project warrants it you can invest in USB Sniffer hardware which will allow you to intercept and monitor the USB traffic between device and PC transparently. Not cheap but very forensic - and vital if there's a lot of handshaking between host and device - in the absence of datasheets.

If you were doing a lot of work like this then it would be a good investment. I've made do with software USB analyzers but they always fall short as 'man in the middle' diagnostic tools.

But the best course of action right now is to get ESP32-S3 + USB HOST shield working with a USB keyboard and printing off to the Arduino serial monitor (and flashing the caps lock, scroll lock, num lock leds - it's a good test).

Until that's working to your satisfaction then there's no point in venturing into unknown territory with your device.

Let me know what you think.

nik

momosh13 commented 7 months ago
  1. Before posting about this project, I was trying get little info from maker, but, they don't want to talk to any body about this,
    this there reply image

  2. About USB Hardware to monitor the traffic, like I show you above HEX, I got that by sniffing communication between USB Control Panel Windows Tool and the device, with Wireshark. I think that is the HEX we need, Maybe.

  3. Right now I'm trying to establish communication between ESP32 and keyboard. I'll let you know.

Thank you

nikthefix commented 7 months ago

@momosh13

  1. Yeah I thought it would be 'closed' in terms of publicly documented API. Not a surprise and understandable.

  2. If Wireshark can accurately capture the handshaking communication between PC and device then that's all you need - but this approach has never worked for me. To really see what's going you might need something like these: http://www.summitsoftconsulting.com/UsbAnalyzers.htm

  3. In addition to the USB HOST shield 2.0 library and the native ESP HOST library talked about above, you might want to also check out the USB HOST implementation in Adafruit TinyUSB. It now supports the HOST shield and they have their own (superior?) version of the hardware: https://www.adafruit.com/product/5858

It will work with ESP32-S3 but the TinyUSB library doesn't have the huge range of device support that the USB HOST shield 2.0 library offers. Still, it could be a useful diagnostic tool and is in active development.

nik

momosh13 commented 7 months ago

Hi I'm having problem connecting ESP32 to this device, so I wanna go back to Teensy, it's works fine, I have a question about that, in your repay, you said this

Pasted Graphic 8

This is my vid=215F and pid=6000 , please help me to import this to RawHIDtoUSBHostRawHID.ino example sketch. Thank you

momosh13 commented 7 months ago

Hi One more question. About Terminals. I tested it this tree terminals (free) https://learn.adafruit.com/windows-tools-for-the-electrical-engineer/serial-terminal https://sourceforge.net/projects/y-a-terminal/ https://www.mikroe.com/mikroc-pic they're not connecting to this device, maybe because it's not HID that's why, so maybe you can recommend different terminal, for me, so can test the HEX commands, I got from Wireshark? Thank you

nikthefix commented 7 months ago

@momosh13

Try these: https://www.softpedia.com/get/Others/Miscellaneous/USB-HID-Terminal.shtml https://www.softpedia.com/get/Programming/Other-Programming-Files/IDE-for-PIC18F-USB-HID-Terminal.shtml https://www.researchgate.net/figure/HID-terminal-program-used-to-send-commands-to-micro-controller_fig11_268323254

Which Teensy do you have?

nik

momosh13 commented 7 months ago

I have a Teensy 4.1 image

Thank you for your help

nikthefix commented 6 months ago

@momosh13

Ah OK,

I don't have that board myself but I've read about it and looked at Paul's code. So maybe run the keyboard example (which I'm sure you've already done) and if all has gone as expected run any of his examples which give a detailed serial output of the device descriptors presented to the host at enumeration.

Connect your device and make a note of the the Report Descriptor size and any other device specific attributes displayed. Upload his HostRawHid example and substitute vid=215F and pid=6000 into the code.

From here on you're dealing with a black box as you have no documented protocol. Be warned that if the device has a USB HID accessed bootloader then you could brick the device by sending random packets. I don't think you'll get very far without documentation or a protocol analyzer.

Is there any open source software available designed to communicate with this device? If so then you can simply look at the code to extract the protocol. I could help with that.

If not then I'm afraid you're up against the 'intellectual property' brick wall. It's understandable that device manufacturers sometimes need to keep their devices 'closed' as the support software is often at least half the product.

What are you trying to achieve? Is it possible that the packaged software allows for scripting? If integration into a wider system is your goal then I'd look at scripting via a possible command line interface.

nik

momosh13 commented 6 months ago

Thank you again. Please take a lock at this

https://github.com/Stuart-Burton/DeciMate?tab=readme-ov-file

This guy, is doing it, I think, but on Raspberry Pi, and there is a example code for it, maybe you can get some thing out of these, to make Arduino code. so i can test it.

momosh13 commented 6 months ago

One more thing. This device has Multi View video display output, with there PC control software very easy to configure that output to show 5 X Windows View , 6 X Windows View, 7 X Windows View and 8 X Windows View. When I'm switching this options, with control software, in Wireshark, I'm getting these hex's for 5, 6, and 7 widows,

5 x windows

1b 00 a0 24 08 16 0a d7 ff ff 00 00 00 00 09 00 00 03 00 17 00 02 03 53 00 00 00 00 40 00 40 48 48 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 08 48 08 08 48 08 00 40 00 08 48 08 00 40 00 08 48 08 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 08 48 08 00 40 00 00 40 00 00 40 48

6 x windows

1b 00 60 5a 43 1c 0a d7 ff ff 00 00 00 00 09 00 00 03 00 17 00 02 03 53 00 00 00 00 40 00 40 48 48 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 08 48 08 08 48 08 00 40 00 08 48 08 00 40 00 08 48 08 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 08 48 08 00 40 00 08 48 08 00 40 48

7 x windows

1b 00 20 4a 36 18 0a d7 ff ff 00 00 00 00 09 00 00 03 00 17 00 02 03 53 00 00 00 00 40 00 40 48 48 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 08 48 08 08 48 08 00 40 00 08 48 08 00 40 00 08 48 08 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 00 40 00 08 48 08 08 48 08 00 40 00 00 40 48

if you lock at this hex's , there is a similarity between them, maybe this will give you little idea about the protocol?

My goal / dream is to do this switching with Arduino, that's it, noting more than that.

momosh13 commented 6 months ago

And maybe this will give you little info about the hex's

image

image

image

image

image

image

image

image

image

image

image

nikthefix commented 6 months ago

@momosh13

So possibly Stuart-Burton's project has the info you need. If it's designed to work with your specific device then then codes you need will be in there. Give me a while to look over his files.

momosh13 commented 5 months ago

Hi nik Long time no talk. Do you any news for me? Thank you

nikthefix commented 5 months ago

@momosh13

Hello again. Yes I looked at Stuart's project and it appears to use usb virtual network comms (Remote Network Driver Interface Specification - RNDIS) rather than usb HID. I suspect the Decimator has well documented support for this alternative control method so it might be a more realistic approach for your project.

https://en.wikipedia.org/wiki/RNDIS#:~:text=The%20Remote%20Network%20Driver%20Interface,Linux%2C%20and%20FreeBSD%20operating%20systems.

Do you have a RPi to test Stuart's code?

For ESP32-S3 RNDIS support code can be found here: https://github.com/espressif/esp-iot-solution/tree/master/examples/usb/device/usb_dongle

I'll see if I can find a more Arduino friendly example.

BTW there are other usb-network standards: USB/RNDIS USB/CDC/ECM USB/CDC/EEM and USB/CDC/NCM

Check the Decimator docs to see which one is employed.

nik

momosh13 commented 4 months ago

Hi, All this time, I was trying to do something about this, but I realized, 0 chance for me to do this, so you think, you can do simply code for esp32 or teensy boards, so I can some how start / try to sending commands to Decimator? Sorry, and Thank you for everything

nikthefix commented 4 months ago

@momosh13

Hi momosh. Yes, like I mentioned above, unless you have access to the product specific protocols it's almost impossible to engineer a custom controller. You made it clear that the manufacturer wouldn't share the information - which is fair as they need to protect their IP. A hardware based USB (man-in-the-middle) protocol analyser is the only way I can see to reverse engineer the comms. Unfortunately I have neither an analyser nor the Decimator product so It's not something I could do either.

But if you wish to persevere then Stuart's project above looks like the viable route. Get it up and running on the RPi and it may be possible to port some of the functionality to a microcontroller.