enumarating USB device

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
naiksidd_85
Member
Member
Posts: 76
Joined: Thu Jan 17, 2008 1:15 am

enumarating USB device

Post 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
Learning a lot these days THANKS to OSdev users
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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:
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Post 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
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post 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
bontanu
Member
Member
Posts: 134
Joined: Thu Aug 18, 2005 11:00 pm
Location: Sol. Earth. Europe. Romania. Bucuresti
Contact:

Post 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...)
Ambition is a lame excuse for the ones not brave enough to be lazy; Solar_OS http://www.oby.ro/os/
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Post 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.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
bontanu
Member
Member
Posts: 134
Joined: Thu Aug 18, 2005 11:00 pm
Location: Sol. Earth. Europe. Romania. Bucuresti
Contact:

Post 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.
Ambition is a lame excuse for the ones not brave enough to be lazy; Solar_OS http://www.oby.ro/os/
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Post by jal »

bontanu wrote:The brief sequence of operations is like this:
This text may be a good stub for the Wiki...


JAL
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post 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.
User avatar
lukem95
Member
Member
Posts: 536
Joined: Fri Aug 03, 2007 6:03 am
Location: Cambridge, UK

Post by lukem95 »

WIKI it ;)
~ Lukem95 [ Cake ]
Release: 0.08b
Image
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Post 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
User avatar
naiksidd_85
Member
Member
Posts: 76
Joined: Thu Jan 17, 2008 1:15 am

Post 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 .
Learning a lot these days THANKS to OSdev users
User avatar
naiksidd_85
Member
Member
Posts: 76
Joined: Thu Jan 17, 2008 1:15 am

Post 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
Learning a lot these days THANKS to OSdev users
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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.
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post 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.
Post Reply