Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Taming FleaFPGAs USB host
02-22-2014, 11:43 PM (This post was last modified: 02-22-2014 11:44 PM by Fleasystems.)
Post: #1
Taming FleaFPGAs USB host
[Image: FleaFPGA_USB_Mouse_small.jpg]

Hello again :-)

I have been meaning to look at the USB Host (i.e. CH376) in more detail, with the goal of getting it to do more than merely service USB flash drives through a simplified command set etc.

However, given the level of responses I've received to the Hackaday article on FleaFPGA I decided not to put it off any longer..

Today, I have decided this posting will be all about the CH376 and to what extent I've managed to decode the demo HID sources provided by wch-ic.com (since they have not yet published the extended command set for their CH376 to date, which is unfortunate in my opinion but anyway..).

Thankfully, I was able to fairly easily translate the comments to English. Within a few short days I was able to extract all the extended commands needed for low-level USB device management by the CH376 (note this also included time to revise some of my USB knowledge as well).

OK. Now that I have the story out of the way, here are my (successful) results around getting the CH376 receiving position data from a Logitech M100 USB mouse.

For simplicity's sake, I am using the CH376's own UART to interrogate it from a host PC. So my test setup basically looks like this (sorry about the ASCII diagram):

** Desktop PC **........*** FleaFPGA Board ***........**** USB Device ****
[ USB COM Port ] <-> [ FT232 ] <-> [ CH376 ] <-> [ Logitech M100 Mouse ]

On the PC comms side, I use the excellent Hercules terminal program from http://www.hw-group.com. Hercules is great because it allows sending of custom hex-formatted packets over a serial connection. Following is a screenshot of Hercules in action:

[Image: CH376_Diagnostics_small.jpg]

Following is a breakdown of all the data requests/responses between the PC and the CH376 USB Host chip as shown in the above pic (Note [] = Byte from PC->CH376 while {} = Byte from CH376 to PC):

Note: The CH376 UART is set for 9600 Baud by default on Reset.

[57][AB][15][07] {51} ; Reset USB Device
[57][AB][15][06] {51}{15} ; Reset USB Host
[57][AB][02][03][CC] ; Command packet --> CH376, Set UART for 115.2KBaud. Note: Don't forget to change your terminal baud-rate accordingly after sending this command
[57][AB][0B][17][D8] ; Set USB Host for low-speed 1.5MBit/sec

*** (Device Descriptor retrieval from USB device skipped!)

[57][AB][45][05] {14} ; Set Host-end USB device address
[57][AB][13][05] ; Set slave-end USB device address

*** (Config Descriptor retrieval from USB device skipped!)

[57][AB][49][01] {14} ; Select configuration profile for USB device

[57][AB][2C][08][21][0A][00][00][00][00][00][00] ; write SETUP token "Set USB idle mode" to CH376 control endpoint buffer
[57][AB][4E][00][0D] {14} ; Issue Synchronous Token (tell USB device to send status data to endpoint#1 upon mouse move or button event)

*** (HID Report Descriptor retrieval from USB device skipped!)

Once the above packets are sent to the CH376 (and a successful status byte code for each was received as shown), it is then simply a matter of continuously sending the following packets and waiting for the CH376 to respond to a mouse event:

[57][AB][4E][80][19] ; IN Transaction from data endpoint #1
[57][AB][27] ; Read data buffer

In the case of the Logitech M100, that response would be in the form of a 6-byte data packet containing movement/scroll-wheel offset counts and/or button toggle bit-fields. The response format would look something like this:

BYTE#1 = Mouse Buttons
BYTES#2 to 4 = X-Y movement offsets
BYTE#5 = Scroll Wheel offset


This is all fairly preliminary and heavily simplified. However, what this does prove is that the CH376 can be used for more than simply a USB flash drive interface i.e. it's most well-known feature..


Regards,
Valentin Angelovski
Find all posts by this user
Quote this message in a reply
02-23-2014, 08:05 AM
Post: #2
RE: Taming FleaFPGAs USB host
This is great news. It could also simplify future revisions of your board by allowing you to eliminate the PS2 socket. PS2 devices are becoming like hens' teeth. Everything seems to be going USB, for better or worse...

With USB connections for GPS devices, webcams, headphones... deciphering the CH376's general USB capabilities opens up a world of possibilities.

I tip my hat to you Valentin (or I would if I wore a hat). A while ago I had a quick look through the USB specs at http://www.usb.org and was put off by the sheer size -- about 600 pages for USB2.0, and that didn't even include host interfaces!

I've been meaning to get around to reading the more digestible documentation at
http://beyondlogic.org/usbnutshell/usb1.htm
...when I have a bit of spare time. Confused
Find all posts by this user
Quote this message in a reply
05-08-2014, 07:09 AM
Post: #3
RE: Taming FleaFPGAs USB host
The CH376 USB to FT230x serial pass firmware is not working for me. The serial port is showing up but I am not seeing anything in the terminal program and the usb mouse is not powering on. The LED blinks at a 1/2 second rate.
Find all posts by this user
Quote this message in a reply
05-08-2014, 04:45 PM (This post was last modified: 05-08-2014 08:05 PM by Fleasystems.)
Post: #4
RE: Taming FleaFPGAs USB host
(05-08-2014 07:09 AM)TimMcD0n41d Wrote:  The CH376 USB to FT230x serial pass firmware is not working for me. The serial port is showing up but I am not seeing anything in the terminal program and the usb mouse is not powering on. The LED blinks at a 1/2 second rate.

The USB passthru example works well for me as downloaded from my FleaFPGA projects site..

A few suggestions/comments:

1.) I did forget to mention that before you do anything with the USB host chip it is advisable to perform a cold-reset by pressing PB2 on the FleaFPGA board. This may help.

2.) Do NOT send either a CR or CR/LF (by pressing the return key), as the CH376 does not seem to like them I have found. You should only be sending ascii-hex formatted packets using the packet 'SEND' buttons as located at the bottom of the Hercules terminal window, as well as setup the terminal window to display hex-bytes as shown.

3.) There's also another serial terminal option - SmartCOM. Tried that today and that works well here too..

Regards Valentin
Find all posts by this user
Quote this message in a reply
05-09-2014, 08:36 PM
Post: #5
RE: Taming FleaFPGAs USB host
I did some testing and the problem is with the usb host connector it has 5V at the board but the pins inside the connector only show voltage if probed just rite. I can get the led in my mouse to light up if the USB connector is inserted just so far and even then its flaky losing connection if shifted slightly.

(05-08-2014 04:45 PM)Fleasystems Wrote:  
(05-08-2014 07:09 AM)TimMcD0n41d Wrote:  The CH376 USB to FT230x serial pass firmware is not working for me. The serial port is showing up but I am not seeing anything in the terminal program and the usb mouse is not powering on. The LED blinks at a 1/2 second rate.

The USB passthru example works well for me as downloaded from my FleaFPGA projects site..

A few suggestions/comments:

1.) I did forget to mention that before you do anything with the USB host chip it is advisable to perform a cold-reset by pressing PB2 on the FleaFPGA board. This may help.

2.) Do NOT send either a CR or CR/LF (by pressing the return key), as the CH376 does not seem to like them I have found. You should only be sending ascii-hex formatted packets using the packet 'SEND' buttons as located at the bottom of the Hercules terminal window, as well as setup the terminal window to display hex-bytes as shown.

3.) There's also another serial terminal option - SmartCOM. Tried that today and that works well here too..

Regards Valentin
Find all posts by this user
Quote this message in a reply
05-09-2014, 09:53 PM (This post was last modified: 05-10-2014 03:00 AM by Fleasystems.)
Post: #6
RE: Taming FleaFPGAs USB host
(05-09-2014 08:36 PM)TimMcD0n41d Wrote:  I did some testing and the problem is with the usb host connector it has 5V at the board but the pins inside the connector only show voltage if probed just rite. I can get the led in my mouse to light up if the USB connector is inserted just so far and even then its flaky losing connection if shifted slightly.

It is more likely that the LED in your USB mouse isn't turning on because the CH376 on your FleaFPGA board hasn't received a valid reset command packet via the UART.

For the record, I was the one who tested everyone's FleaFPGA boards (including the USB host port, of course). I can also say for the record that of all the tested USB ports, none exhibited the behaviour you describe above.

Before you go taking any pics of the connector itself etc, here's a simple test for you to try:

Configure your FleaFPGA with the new x86 soft-core that you've already tried and then download the following USB Flashdrive utility and save it to the SD card you've prepared for booting FreeDOS.

USB.EXE is a DOS utility that allows (8.3 format) files to be accessed from a USB Flash/pen-drive connected to the USB host port on FleaFPGA (Warning: For this test, it recommended that you use only a USB flash drive and SD card containing no valuable user data..).

To get help on how to run the utility, simply type "USB" at the command prompt and press enter.

To get a directory listing of your USB flashdrive (i.e. the one that you've connected to your FleaFPGA's host port ;-), type "USB DIR *" and then press Enter.

Let me know how that works for you. Thanks!

Regards Valentin
Find all posts by this user
Quote this message in a reply
05-14-2014, 09:01 AM
Post: #7
RE: Taming FleaFPGAs USB host
Took me a while to get a usb flash drive to try this because my flash drive is in hiding but today I picked a flash drive and tried as you suggested and it worked perfectly, so I was just faking my self out with the connector. I have been having fun with this board so far I have adapted blinky to count in binary to 15 over and over on the leds and am working on spinning my own vga adapter. Could you release the 68000 juggler demo and or the 2600 code?
(05-09-2014 09:53 PM)Fleasystems Wrote:  
(05-09-2014 08:36 PM)TimMcD0n41d Wrote:  I did some testing and the problem is with the usb host connector it has 5V at the board but the pins inside the connector only show voltage if probed just rite. I can get the led in my mouse to light up if the USB connector is inserted just so far and even then its flaky losing connection if shifted slightly.

It is more likely that the LED in your USB mouse isn't turning on because the CH376 on your FleaFPGA board hasn't received a valid reset command packet via the UART.

For the record, I was the one who tested everyone's FleaFPGA boards (including the USB host port, of course). I can also say for the record that of all the tested USB ports, none exhibited the behaviour you describe above.

Before you go taking any pics of the connector itself etc, here's a simple test for you to try:

Configure your FleaFPGA with the new x86 soft-core that you've already tried and then download the following USB Flashdrive utility and save it to the SD card you've prepared for booting FreeDOS.

USB.EXE is a DOS utility that allows (8.3 format) files to be accessed from a USB Flash/pen-drive connected to the USB host port on FleaFPGA (Warning: For this test, it recommended that you use only a USB flash drive and SD card containing no valuable user data..).

To get help on how to run the utility, simply type "USB" at the command prompt and press enter.

To get a directory listing of your USB flashdrive (i.e. the one that you've connected to your FleaFPGA's host port ;-), type "USB DIR *" and then press Enter.

Let me know how that works for you. Thanks!

Regards Valentin
Find all posts by this user
Quote this message in a reply
05-14-2014, 12:34 PM (This post was last modified: 05-14-2014 05:48 PM by Fleasystems.)
Post: #8
RE: Taming FleaFPGAs USB host
@TimMcD0n41d

Glad to hear your USB host port works for you and (above all) you're having fun with FleaFPGA! Smile

Regarding your other questions, those are off-topic in relation to the thread. Kindly re-post your 68K question in the existing thread for it, and/or create a new thread for your 2600 question and we'll take it from there. Thanks!

Regards Valentin
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 2 Guest(s)

Contact Us | Your Website | Return to Top | Return to Content | Lite (Archive) Mode | RSS Syndication