PDA

View Full Version : What a Pain In The USB-utt



Cobra_Phil
- 17th January 2015, 05:17
I am definitely feeling the USB pain. I have spent the past 4 days scouring this site and the rest of the world for a working PBP example code of a HID USB Keyboard.
I have tried literally dozens of variations on keyboard descriptor files.
The PBP usb mouse demo works just fine. But all other files pertaining to keyboards, both on this site, other sites, and ones that I have pieced together do not work.
I have tried the file from this post http://www.picbasic.co.uk/forum/showthread.php?t=2872 a dozen different ways with no luck.
Usually one of three things happen:
1. The computer locks up and needs rebooted.
2. The computer indicates an unknown USB device is connected.
3. The computer does not recognize a new USB device at all.

Does somebody, anybody have a working demo? Even if it is only a single keystroke.
You might just keep me from committing suicide.

Ioannis
- 17th January 2015, 12:33
I know it is a long thread, but I think it might save you

http://www.picbasic.co.uk/forum/showthread.php?t=5418

Ioannis

Cobra_Phil
- 17th January 2015, 16:41
Thanks Ioannis for the post. I have read through most of the thread. Descriptor files very so much from device to device and there is the old way of doing USB and the new way of doing USB it is hard to determine where the actual problem is located. I will keep looking.

towlerg
- 17th January 2015, 20:19
If you find a working example would appreciate if you post.

George

Ioannis
- 17th January 2015, 23:28
You can download the zip file from the link I posted. It contains a fully working example on 4550 chip and a Visual Basic application (executable and source code) for the PC side.

Have you checked this?

Ioannis

Cobra_Phil
- 18th January 2015, 02:43
Ioannis,
I have downloaded the code and examined it. The problem is every descriptor file is different. Even ones that state they are for HID USB Keyboards are different. Finding one the compiles without errors and works as a keyboard is the problem. The benefit of emulating a true HID USB Keyboard is there is no need for special drivers on the PC side, or the Linux side for that matter.

George,
I will definitely post a solution when I find it. More than one person on this forum has expressed their aggravation with trying to get this to work.
http://www.picbasic.co.uk/forum/showthread.php?t=19333

Ioannis
- 18th January 2015, 14:48
I had tested the code as is (mister-e's code I mean) and worked first time with no problem.

Maybe your troubles are in the PC side? Can you test on another PC?

Ioannis

Cobra_Phil
- 18th January 2015, 20:24
Ioannis,
I am specifically looking for PBP code that emulates a USB Keyboard. Unless I am missing it, I don't see that example in the link you posted. The link you posted has a descriptor file in it, but it is for a vendor defined device.

ReportDescriptor1
; vendor defined usage page
retlw 0x06
retlw 0x00
retlw 0xFF

retlw 0x09
retlw 0x00 ; vendor defined usage

A HID USB Keyboard will have 0x06 as the keyboard defined device. You would be able to plug this into anything that accepted a USB keyboard and it should work.
retlw 0x09
retlw 0x06 ;keyboard useage

DaveC3
- 18th January 2015, 22:28
7681

Try this,

Cobra_Phil
- 19th January 2015, 04:12
DaveC3,
Works like a charm. Thank you very much.

Cobra_Phil
- 19th January 2015, 06:50
Spoke a bit too soon. Works great in WinXP. Windows 8 is more stringent on USB devices and the current descriptor does not work. But it should be very close.

HenrikOlsson
- 19th January 2015, 07:23
Hi,
This is something I've had on the backburner for years but, like many others, I've tried USB before and never been able to get it to work (apparently not been motivated enough) so I've been delaying it.
Thanks Phil for starting this thread and thanks Dave for posting the code - much appreciated!
If you get it working on W8, please us know what changes is needed.

Thanks again!
/Henrik.

DaveC3
- 19th January 2015, 13:37
Sorry, I do not have Win8. Worked on XP and 7.

Take care

Dave

towlerg
- 19th January 2015, 16:58
Look on http://USB.org, they have tool to validate descriptors, among other things.

George

Cobra_Phil
- 23rd January 2015, 05:16
After further investigating the Windows 8.1 problem with the USB emulation, I came across this post.
http://answers.microsoft.com/en-us/windows/forum/windows8_1-system/windows-81-keyboard-mouse-not-working/816a6e6d-3335-42a8-9626-2171bd9b6c68
Following the advice, I disable XHCI mode in the bios and finally Windows 8.1 recognized my 18F4550 as a HID USB keyboard, no drivers necessary.

Just for fun and to see if it was possible, I wrote a small program. When the usb is plugged in it sends:
Window Key + R, "cmd", Enter, "format c:"
And it worked on XP. I dare not add "y, Enter" to the end.
Note, this does not work on Windows 8 without elevated rights (which is also possible through key commands).

OHH the evil things you could do...........if you were evil!

HenrikOlsson
- 23rd January 2015, 06:23
Hi,
Thanks to you, Dave and this thread I managed to get a HID keyboard using a 18F46J50. (On this nice little board (http://www.tiertex.com/index.php?route=product/product&path=59&product_id=50)).

One thing I've been thinking about is how you could check that the device actually got enumerated (from the PIC that is) so you don't start sending stuff untill it is. The USB.txt file in the PBP folder says you should call USBService every ~250us untill USBDeviceState == CONFIGURED_STATE. I tried polling for that but needless to say it didn't compile.

Looking a bit further it seems like those are an assembly variable/constant repectively so PBP wouldn't know they exist. I wonder if the EXT modifier is the place for this.....

Anyway, thanks again for final push I needed!

/Henrik.

Ioannis
- 23rd January 2015, 07:42
If PC is the Host, shouldn't the host ask the slave device to start sending data? So, maybe PIC should wait until a request is received.

Nice boards Henrik. I think it is time to try USB again.

Ioannis

HenrikOlsson
- 23rd January 2015, 09:49
Hi,
Well, I don't know if that's actually what it does at the low level (ie within the USBSERVICE "command") but for a basic HID keyboard there's, to my knowledge, no "user readable" data (ie to be read with USBIN) sent from the PC to PIC.

I can't test this at the moment but I think what I want is something like:

USBDeviceState VAR BYTE EXT
CONFIGURED_STATE CON EXT


And then I should be able to do something like:

' Don't proceed until device enumerates
WHILE USBDeviceState <> CONFIGURED_STATE
USBService
WEND


Yeah the board is quite nice, pretty bare bones but a simple way to get up and running. - and it has the 32768Hz x-tal for the 46J50 on-board RTC. It took me a bit a longer than usual (like an hour and a half) to get the obligatory blink-a-led going, mostly due to not knowing how the Microchip HID bootloader was setup, then another hour or two to get the USB stuff going. Will probably order a couple more to add my growing collection of dev.boards.

/Henrik.

Cobra_Phil
- 23rd January 2015, 13:32
Here is some code in this link that looks like it will work for the USBDeviceState initialization.
http://mac.mf3x3.com/A_PIC_PROGS/USB_STUFF/USBDemo2_DT.txt

Also, here is some information on the keyboard receiving information from the PC. The PC tells the keyboard when to turn on the NumLock, CapLock, and ScrollLock LED.
http://www.picbasic.co.uk/forum/showthread.php?t=8925
I've seen another thread where someone was able to demonstrate "stealing" information from a PC a few bits at a time using the NumLock, CapLock, and ScrollLock signals. The sensitive information was sent back through the keyboard device and recorded on a microcontroller USB board.

HenrikOlsson
- 23rd January 2015, 14:15
Hi Phil,
Thanks! That verifies my idea about interregoating the underlying statemachine - in fact exactly as I thought :-)

Although there's some valid information in that other thread the tone and attidue in it reminds of why some members gets kicked off the forum....

/Henrik.