Page 1 of 2

enumarating USB device

Posted: Fri May 30, 2008 1:35 am
by naiksidd_85
hi all,

can any one please help me as to how can I enumerate and interact with the USB devices?

I have gone through the wiki it says that I will have to read the HID but i have no idea as to how it should be done also I am in process of detecting all the devices. For rest of the devices I have used the port information to validate the presence by sending commands to the port.
but as the USB works on shared bus I have no idea how it should be don

Posted: Fri May 30, 2008 2:00 am
by JamesM
As I understand it, USB is extremely difficult and not many hobbyists have it working.

I believe that Dex has it, but was unwilling to share code/information due to it being so difficult and it's what sets his OS apart from the rest. I totally understand this view, and no doubt would feel the same had I implemented it!

I suggest a thorough read of the manuals and specifications, along with packet sniffing maybe. Tutorials won't help you here! :twisted:

Posted: Fri May 30, 2008 2:57 am
by jal
JamesM wrote:As I understand it, USB is extremely difficult and not many hobbyists have it working.
I think that's just an urban myth started by those who have created a USB stack and propagated by those too lazy to try. But that's just my take, I admit to not having tried it myself.

I really doubt whether USB is "extremely difficult" compared to all the other difficult stuff you have to deal with when coding an OS. The most difficult part comes, I think, in designing a proper stack, with proper driver layering etc., and integrating that with the other drivers (e.g. USB drive vs. ATA, USB keyboard vs. PS/2, etc.).


JAL

Posted: Fri May 30, 2008 3:39 am
by AJ
jal wrote:I think that's just an urban myth started by those who have created a USB stack and propagated by those too lazy to try.
That's pretty much my opinion too. As I understand it, you need one of two drivers installed to interface with one of the common USB chipsets. After that, it's 'just' a matter of sending packets to communicate with the devices. For common device classes such as HID and Mass Storage, I don't see why this isn't possible in a basic hobby OS.

Cheers,
Adam

Posted: Fri May 30, 2008 6:12 am
by bontanu
Yes, USB is pretty easy to be done.

Once I started coding it was done in 2 (two) weekend days.

And my OS (Sol_OS) has it now, Menuet has it now... Octa OS had it a long time ago .... hence it is not so hard for a "hobby" OS ...

Start coding!
(and read the documentations/specifications very carefully...every comma...)

Posted: Fri May 30, 2008 6:20 am
by distantvoices
*shrugs*

I reckon that's something I'm gonna do on one of the days of free time which are to approach ...

I'll dissect the visopsys source and take a Look at what andy mclaughlin has done in order to learn.

Just have no time currently with ongoing studying and onstanding diploma thesis.

Posted: Fri May 30, 2008 7:31 am
by bontanu
To help the OP...

The brief sequence of operations is like this:

1) Find Host controller type and info and IO addr via PCI enumeration
2) Reset Host , reset Port
3) Check Port status to detect device insertion, enable port.

4) Get Device Descriptor of device
5) Get Config Descriptor of Device
6) Set Address of device
7) Set Configuration of Device

8) Device is ready to accept communications. Protocol depends on device type.

From now on commands depend on device type but are sent and received in the same way as used in step 4,5,6,7.

For those steps (starting from 4) you will have to setup Queue Heads and Transfer Descriptors linked lists in memory and populate them with valid data and inform the Host controller about them in order to make an USB transaction work.

Specific detail might depend on Host controller type: OHCI UHCI EHCI. My advice: start with UHCI.

For Mass Storage device (USB memory stick) you will have to send specific commands wrapped in CBW and CBS structures.

In this case you also have to check the SCSI commands: Inquiry, Get_Capacity and Read_10 or Write_10.

Posted: Fri May 30, 2008 1:40 pm
by jal
bontanu wrote:The brief sequence of operations is like this:
This text may be a good stub for the Wiki...


JAL

Posted: Sat May 31, 2008 10:37 am
by Dex
Here my two cents,
First i would say that the USB stack is one of the hardest thing a Hobby OS maker would need to code, dew in part to lack of good info (eg: the main doc are encrypted and have been written by a committees).
Example of this is that the OS's mentioned eg: menuet, sol_OS, Octa are made by the most experienced OS Dev's.

Second, i did not release the code because DexOS was closed source (as are most of the above OS's).
But now DexOS is open source, there is some start USB code, that will get coders started on my web Site and has been there for some weeks.
http://dex4u.com/download.htm
Its called USB.zip
And other than the USB doc you will find this link usefull http://www.usbmadesimple.co.uk/index.html

PS: Linux codes know there stuff, how long as it took to get good USB support on linux ? and why if its so easy.

Posted: Sat May 31, 2008 10:46 am
by lukem95
WIKI it ;)

Posted: Sun Jun 01, 2008 2:07 pm
by jal
Dex wrote:PS: Linux codes know there stuff, how long as it took to get good USB support on linux ? and why if its so easy.
Because in the early days, USB was far from standard, and many devices didn't adhere to the standards. Nowadays, all devices adhere, and are far easier to communicate with (or so I've been told). Making a proper USB stack is difficult, just as making a proper networking stack is, or a proper VFS (and I mean a proper one), as it's about OS design, not implementation. But simple communication with a USB device, that's not the most difficult thing ever.


JAL

Posted: Sun Jun 01, 2008 10:53 pm
by naiksidd_85
thanks for the help guys....

bontanu's comments are really helpfull I think I will definately get a lead from it.

will try to write a code and if completed properly will surely add it in wiki .

Posted: Thu Jun 05, 2008 3:30 am
by naiksidd_85
ok I went through USB 2.0 specs. I think i should first try to communicate with the USB controller. Also I a have gone through the Data structures and register process.
I want to know how do i find the base address or rather the memory area where USB is mapped.

I also went through the DEX code but am afraid did not understand much.

I know this is very childish question but need to complete it at any cost and want to contribute atleast some thing on this forum

Posted: Thu Jun 05, 2008 3:53 am
by JamesM
I want to know how do i find the base address or rather the memory area where USB is mapped.
IIRC the USB host controller hangs off the PCI bus, so PCI probing is what you need to do.

Posted: Thu Jun 05, 2008 12:19 pm
by bewing
You almost always find base addresses in the BARs of the PCI devices, which you get from the PCI Configuration Space of that device -- which you read by enumerating the PCI bus, first. Information on doing that is available in the wiki, and on the 'Net.