PORTS Forum

Ports and Interfaces => USB => Topic started by: akanksha112 on October 21, 2011, 06:45:19 am

Title: Regarding USB Mass Storage Device
Post by: akanksha112 on October 21, 2011, 06:45:19 am
Dear Jan

Please help me out in the issues mentioned below

1. In the Device Manager, my USB 2.0 mass storage device is being detected but with a yellow exclamation mark.

2. In the details tab

Under Devnode flags

I get the following
DN_HAS_PROBLEM
DN_DISABLEABLE
DN_REMOVABLE
DN_NT_ENUMERATOR
DN_NT_DRIVER

The current power state is
D3

It does recognise the hardware and other device instance,compatible and matching device ids.

when I tried plugging in the device to another hst, there the device was successfully detected with power state as D0.

Also there under DevnodeFlags
I observed
DN_DRIVER_LOADED
DN_Started
DN_DISABLEABLE
DN_REMOVABLE
DN_NT_ENUMERATOR
DN_NT_DRIVER

Also if you could throw some light on power state mappings for usb mass storage devices.

Once you tell me about this, I would be in a better position to explain my design problem.

Looking forward to your reply.

Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on October 21, 2011, 09:51:45 am
It's possible that the host has put the device in the Suspend state because it failed enumeration. A hardware protocol analyzer will show what is happening on the bus. If you don't have an analyzer, use whatever debugging tools you have to monitor the communications on attachment.

Jan
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on October 24, 2011, 02:27:11 am
Dear Jan

Thanks so much for reverting. I would now like to elaborate my problem.
Well, I am working on a USB 2.0 Bridge implementation using an FPGA such that any communication between the HOST and the USB Mass Storage Device happens via the USB Bridge. Now I use a Mixed signal Oscilloscope to observe the D+ and D- USB lines of both the device as well as the HOST.Also I am using a Logic Analyser to observe the ULPI interface of the PHY at both host and device end.

My observations :-

1. Oscilloscope observation
   As I plug in the mass storage device, after the initial VBUS steps and full speed pullups and stuff,terminations,I observe the Chirp K signal on the D- line of the device. Then the HOST initiates the KJ sequence after which I have some communication happening on both the sides.
2.After this the chirp K from the device repeats.I assume this is after the device descriptor is read by the HOST and the HOST issues a reset.(Please correct me if I am wrong).Following this there is some more communication happening between the Host and the device. Now the behaviour post this is variable.Sometimes after a little communication, the Chirp K sequence fiollowed by JK from the HOST repeats.Sometimes it does not. After a little communication , the D+ line of the HOST remains high and sometimes USB device is not recognised and sometimes detected with the yellow exclamation mark.



Observations made on the Logic Analyser.

1. The SOF repeating after every 125 us on the HOST as well as the DEvice side
2.18 bytes of device descriptor read with all stages of control transfer successfully happening. Following this a reset happens. After this I have  a Set address happening.
3. Post this I am not able to tweak immediately after Set Address what happens. But eventually I have  a successful Get device descriptor followed by Get Configuration Descriptor,Get String Descriptor, Get Configuration(this  time config followed by interfasce and endpoint).

4. Post this I have been struggling to tweak Set Configuration or even Get Configuration for that matter .But I have not been able to do so as yet.

Now what I wanted to know what is the yellow exclamation mark in terms of enumeration means till what stage has it reached?

Also post Set Configuration do I have the BULK TRANSFERS initaied or before that?

Also if this is some power related issue , could you highlight what could be the problem.

Any help/suggestion from your side is going to help me immensely to channelize in the direction.


Looking forward to your early reply.


PFA the waveforms observed on the USB interface both on teh device as well as the HOST side.


here

yellow D- device
blue D+  device
green D- host
pink D+  host

Please see that the D+ line goes high in the last.

There is one more file which I wanted to attach but cannot do so because of the limited 128 kb size.
Is there any way I acn send it across.Its 160 Kb after compression.


Warm Regards
Akanksha Jain



 




[attachment deleted by admin]
Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on October 24, 2011, 10:18:23 am
The exclamation point means Windows had a problem communicating. It can be just about anything.

If you don't received Set Configuration, there is likely something the host doesn't like about the descriptors. A hardware USB protocol analyzer will show the traffic on the bus and may offer a clue. If you post the descriptors here, someone might see something.

The host won't use bulk transfers until enumeration is complete.

I've increased the max size of attachments on the forum.

Jan
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on October 25, 2011, 12:43:50 am
Dear Jan

As suggested by you, I am mentioning all the descriptors.
Please see if you could figure out something.

DEVICE DESCRIPTOR   :   18 byte device descriptor + LAST TWO CRC -16 BYTES

4B/12/01/00/02/00/00/00/40/64/85/00/10/00/11/01/02/03/01/3D/05


Configuration Descriptor    : 9 byte Configuration Descriptor + crc-16


4B/09/02/20/00/01/01/00/80/FA/E2/FB


String Descriptor               :   + crc 16

4B/04/03/09/04/09/78

Also PFA the waveform with the color conventions same as that mentioned in the previous post.

[attachment deleted by admin]
Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on October 25, 2011, 10:35:53 am
There should also be endpoint descriptors.

If you want folks to examine the descriptors, you might want to decode them rather than just presenting the raw data.

Jan
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on October 28, 2011, 02:17:42 pm
Hi Everyone
I didnt mean to forget it, I am clueless as to how I missed it,because I remember typing it the first.

Anyways here it is

4B    /09/02/20/00/01/01/00/80/FA/09/04/00/00/02/08/06/50/00/07/05/81/02/00/02/FF/07/05/02/02/00/02/FF/C3/29

In one case the last byte of config descriptor is 32 instead of FA but I still get the sameproblem of yellow exclamation mark. I mean I did decode this byte to find out any power related stuff.

Please help me in getting any clue.

Also Jan if you could tell me how would be Beagle USB 480� protocol analyzer for debugging my problem? Any other protocol analyser you would like to suggest? Actually I cannot initiate the purchase of some expensive one at this juncture so please if you could tell some good one in an affordable range. I would be really grateful to you.

Other than  that if you could download the snapshot of the USB lines I had posted, the HOST D+ line goes high and the detection goes for a toss.I deally when the device is successfully detected what is state of the USB lines both on the Device and the HOST side.


One more query which i had was hwhat happens after Set Configuration request being successfully carried out? I mean post this what are teh steps in the device enumeration? When does the device start receiving the class specific requests?

Sorry for writing in late.

Looking forward to your reply anxiously!!!
Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on October 28, 2011, 06:38:55 pm
The host is detecting the device. Otherwise it wouldn't attempt to enumerate it.

When the device returns ACK to a Set Configuration request for a configuration > 0, enumeration is complete.

I have links to protocol analyzers here:

http://www.lvr.com/development_tools.htm#analyzers

The Beagle and Ellisys are good. I haven't used them all.

To find any problems in the descriptors, you need to decode them to verify that you are using the values you intended.   

Jan

Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on October 29, 2011, 12:41:27 am
Hi Jan

Thanks for reverting.

"To find any problems in the descriptors, you need to decode them to verify that you are using the values you intended.  "
Could you please elaborate on this.I did not get you.

Akanksha

Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on October 29, 2011, 12:04:15 pm
You posted the descriptors as hex codes. To look for errors in the descriptors, it's helpful to list each code and its meaning. For example:

12 descriptor length
01 descriptor type - device

etc.

Jan
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on October 31, 2011, 12:48:47 am
Hi Jan

I also wanted to know when does the HOST start sending the Class Specific Request? I mean is it immediately initiated after Set Configuration Request?
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on October 31, 2011, 01:29:00 am
Hi Jan

DEVICE DESCRIPTOR   :   18 byte device descriptor + LAST TWO CRC -16 BYTES

4B    DATA1 PACKET 
   
12     -   bLength       18 BYTE DESCRIPTOR

01     -   bDescriptorType    --   device descriptor type

00     -   bcdUSB


02     -   bcdUSB

00   -    bDeviceClass


00    -  bDeviceSubClass


00    -   bDeviceProtocol


40    -  bMaxPacketSize0   64 BYTES


64    - idVendor


85    - idVendor


00   -  idProduct


10   -  idProduct


00   -  bcdDevice

11   - bcdDevice

01   -  iManufacturer

02   -  iProduct

03 -  iSerialNumber

01 -   bNumConfigurations
3D   -  CRC
05   -   CRC
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on October 31, 2011, 01:38:06 am
  Configuration Descriptor


Configuration Descriptor    : 9 byte Configuration Descriptor + crc-16


4B   data1 packet

09     bLength  9 byte descriptor


02    bDescriptorType   Configuration descriptor


20     wTotalLength    ( Total length of data returned for this
configuration. Includes the combined length
of all descriptors (configuration, interface,
endpoint, and class- or vendor-specific)
returned for this configuration.)



00   wTotalLength


01   bNumInterfaces
 

01   bConfigurationValue


00   iConfiguration


80      bmAttributes(Configuration characteristics

D7: Reserved (set to one)
D6: Self-powered
D5: Remote Wakeup
D4...0: Reserved (reset to zero)
D7 is reserved and must be set to one for
historical reasons.
A device configuration that uses power from
the bus and a local source reports a non-zero
value in bMaxPower to indicate the amount of
bus power required and sets D6. The actual
power source at runtime may be determined
using the GetStatus(DEVICE) request (see
Section 9.4.5).
If a device configuration supports remote
wakeup, D5 is set to one.)


FA   bMaxPower

E2    crc

FB   crc
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on October 31, 2011, 01:44:55 am
 

STRING DESCRIPTOR


4B    DATA1 packet

04   blength   ie 4 bytes

03    bdescriptor type is   String Descriptor 

09      Wlang ID     LSB byte

04      Wlang ID   MSB byte     --   Supported Language Code Zero  US English

09   CRC

78    CRC
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on October 31, 2011, 02:11:54 am
Complete Configuration Descriptor:    9+9+7+7= 32 byte descriptor  + crc 16

4B    DATA1 PACKET

09     Blength   ie 9 bytes of config desc

02      desc type  ie Config Descriptor

20    wTotalLength

00    wTotalLength

01    bNumInterfaces


01    bConfigurationValue



00    iConfiguration

80     bmAttributes

FA    bMaxPower



09   blength ie   9 bytes of Interface desc

04   bDescriptorType   interface Descriptor Type


00   bInterfaceNumber


00   bAlternateSetting


02   bNumEndpoints


08   bInterfaceClass


06     bInterfaceSubClass


50   bInterfaceProtocol


00   iInterface07   Endpoint Descriptor

05   bDescriptorType   ENDPOINT Descriptor Type


81   IN ENDPOINT WITH ENDPOINT NUMBER 0001


02   bmAttributes     Bulk endpoint  with no synchronization



00   wMaxPacketSize



02   wMaxPacketSize


FF    bInterval
07   Endpoint Descriptor

05   bDescriptorType    ENDPOINT Descriptor Type

02     out endpoint with endpoint number  02

02   bmAttributes     Bulk endpoint  with no synchronization

00   wMaxPacketSize


02   wMaxPacketSize


FF   bInterval

C3   CRC
29   CRC
Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on October 31, 2011, 11:21:08 am
The bulk endpoint descriptors each have two wMaxPacketSize fields:

00   wMaxPacketSize
02   wMaxPacketSize

Allowed max packet sizes for full speed are 8, 16, 32, and 64. Use 64 if at all possible. High-speed bulk max packet size must be 512.

Jan
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on October 31, 2011, 02:53:14 pm

Hi Jan
I did see that and was wondering too as to how is this possible.But I have no capacity to make any change as my Board just transarently passes the data between the HOST and the mass storage device. So i cannot alter the Wmaxpacket size.Whatever is sent is sent by the mass storage Device which goes via my FPGA through the PHYs to the HOST.

Also the WmaxPower ie the last byte of Config Descriptor
 once I got the value as 32 which is equivalent to 100 mA
and once I got the value FA  which is equivalent to 500 mA.
Now for 500mA , i vaguely remember having read it that after the device is configuredit draws a max of 500 mA current.
If you could please elaborate on this too.

Thanks for being such a patient listner and giving your valuable feedback.

Looking forward to your reply anxiously.
Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on October 31, 2011, 03:02:42 pm
Rereading this thread, I noticed that you say:

I am working on a USB 2.0 Bridge implementation using an FPGA such that any communication between the HOST and the USB Mass Storage Device happens via the USB Bridge.

What is the function of your Bridge? The USB spec assumes a single cable segment between the host and device (which may be a hub). If you're inserting circuits in the middle of the cable, have you considered the effect on the timing of the phases of the transactions?

Jan
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on November 01, 2011, 12:53:23 am
Hi Jan

Yes I would like to elaborate on those points.

1. The bridge essentially just passes the packets between the HOST and the Device.I mean whatever is sent bythe HOSt is given through the PHY(at HOST side) to the FPGA and the FPGA transparently passes it to the other PHY(at the device side) to the device through the second ULPI interface.The transmission does happen through storage in some memory.this happens in such a way that whatever is recieved by one PHY is transmitted by the other PHY.

 For this we have considered the Timing specification as per the ULPI and USB timings.I mean we have the FPGA with a ULPI interface with the PHYs who in turn are connected to the two USB ports ie the HOST and the Device.

We have considered the response time such that for an IN packet from the HOST the device generates a NAK or an DATA within 24 clock cycles ie 192 bit times for HS device.
However there is no such timing constraint between two independent packets  ie NAK (of the first IN )and then the second IN packet. Please correct me if I am wrong.

Also the SETUP, the 11 byte device request reaching the HOST is ensured to have  24 clock interpacket delay at the device side.

2. I also wanted to know one thing ..If the communication is not able to meet timing specification , then it should not proceed with the enumeration.Right ?
I mean say for the first request Get Device Descriptor if it is not able to meet timing specifications then it should not be proceeding with the Set Address. Please throw light on this.I mean is it possible that the timings are not met and still the HOST continues with the enumeration process?

3. say for any control transfer if the status stage is completed successfully then does that ensure that the transfer was successful and timings were also met?
Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on November 01, 2011, 10:25:16 am
You are correct; there is no time limit between the transactions in control transfers, but the phases within a transaction must meet timing requirements.

The host and device should comply with the specification's timing requirements when sending data and likely will be a little more liberal than required when receiving data. In other words, if data arrives a little late according to the spec, the host or device may still accept the data. If the receiver of the data returns ACK, the data was accepted.

A control write transfer (where the host sends data in the Data stage or where there is no Data stage) completes successfully when the device has ACKed the data in the Data stage and sends a ZLP in the Status stage and the host responds with ACK.

A control read transfer (where the device sends data in the Data stage) completes successfully when the host has ACKed the data in the Data stage and sends a ZLP in the Status stage and the device responds with ACK.

The host can initiate other traffic to the device anytime after enumeration completes.

The double and suspicious values for wMaxPacketSize seem to indicate a problem in your link. Viewing the descriptors when the device is attached directly to a host would offer a clue.

Jan
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on November 01, 2011, 02:16:33 pm
Hey Jan

Thanks so much for reverting.
I would look again into the endpoint descriptor again with another mass storage device and see if I find any change.I am waiting for Beagle Protocol Analyser to arrive.Till then I am reading up on things.

Its really very sweet of you to respond in such detail.You have no idea how happy I am.Thanks again!!!

Would keep you posted of any updates.

Akanksha
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on November 01, 2011, 03:15:05 pm

Please let me know if there could be anything in the meanwhile I could tweak into .

Anything to do with the class specific requests.
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on November 02, 2011, 06:30:04 am

Hi Jan

I probed again in the endpoint decriptors and found out that the value is not wrong.
As per the specifications
wMaxPacket size is a 2 byte value which is being sent from LSB byte to the MSB byte so a value of 00 followed by 02 actually means

wMaxPacket   00  LSB
wMaxPacket  02   mSB

ie 0200  now out of this the break up as per USB 2.0 spec is
Bits 15-13 are erserved and set to '0' Bits 12,11 = "00" means 1 transactionm per microframe
and bits 10-0 indicate the no of bytes transferred for bulk data and it comes out to 512 which is in accordance with the HS spec.
So this possibility of wrong wMaxpacket is ruled out.

I also wanted to know when would the device go into suspend state.Is it when the HOST stops sending SOF.

Under normal circumstances the SOF should be repeated every 125 us for HS.Right?

I am really stuck and do not know how to proceed.
       
Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on November 02, 2011, 11:19:52 am
OK, that makes sense. Yes, the lack of SOF for 3 millisecs. means the host has suspended the device.

The protocol analyzer will be a big help. You will be able to compare what happens when the device connects directly to a host with what happens when your circuit is in between. Be sure to use very short cables when testing because you are already adding your circuit to the cable segment.

Jan
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on November 08, 2011, 12:51:31 pm
Hi Jan

I finally got  a Beagle Protocol 480 Analyser and could make the following observations.
The sequence has a Get String Descriptor (marked in yellow background)  with the following data
28 03 4D 00 61 00 73 00 73 00 20 00 53 00 74 00 6F 00 72 00 61 00 67 00…

I am missing out on the last bytes of the descriptor(proabably they didnt get exported well), but they were exactly the same as that when obtained by direct connnection ie minus my circuit.(would anyways mail them to u in my next response as I dont have the analyser with me now)


 but it has correct CRC its a 40 byte string descriptor




However the In token followed by DATA is not acknowledged by the HOST.But when i had connected the host and the mass storage device directly, the data from the device was acknowledged withou any problem,


Also the host keeps sending vendor specific requests in between say after set address and say device descriptor.These requests too go unacknowledged.

I am attaching the excel sheet of the captured data with the problem areas highlighted in yellow.



Please if could tweak into something and help me out.

Also if you could tell me wht is exactly a Tiny J and why does tht occur.and when after 1 st dev descriptor the HOST issues a request what exactly happens??
I mean sequence of events.I just wanted to know if I am doing the right thing.I meant this in terms of electrical specifiactions of Vbus and pullup and terminations to accordingly make PHY settings.

Looking forward to ur reply



Akanksha

[attachment deleted by admin]
Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on November 08, 2011, 01:49:39 pm
I haven't examined the data you uploaded, but as a general suggestion, now that you have an analyzer, compare the timing with and without your bridge attached.

If communications work OK without the bridge and the bridge doesn't change the data, timing is the natural place to look.

Jan
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on November 08, 2011, 01:55:47 pm
Hi Jan

I know you must be really busy and timing is the thing I am already looking into, but if could please spare sometime to look into it.It would really help me.

Also if you could reply to my other queries ,whenever you get a little time, I had mentioned in my last post.

Also the strange part is if timing is the case then it should be the same for all the descriptors.However even Set Configuration is successfully happening.

That is what is further puzzling me .!!!!!


Akanksha
Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on November 09, 2011, 12:44:48 pm
>Also the host keeps sending vendor specific requests in between say after set address and say device descriptor.These requests too go unacknowledged.

Are you sure they're vendor-specific requests and that they're directed to the mass-storage device?

>Also if you could tell me wht is exactly a Tiny J

Defined here:

http://www.totalphase.com/support/kb/10047/

>when after 1 st dev descriptor the HOST issues a request what exactly happens??
I mean sequence of events.I just wanted to know if I am doing the right thing.I meant this in terms of electrical specifiactions of Vbus and pullup and terminations to accordingly make PHY settings.

I have a description of enumeration here:

http://www.janaxelson.com/usbcenum.htm

If you want more detail, take a look at the USB spec.

Jan
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on November 15, 2011, 04:58:15 am
Hi Jan

I have been observing things closely but am yet to find out that trigger pointwhich could lead me to a  major clue.

I had some queries for which I wanted some pointers from you.

PART A - DIRECT Connection between the hOST and the device without my circuit.


1. Responding to Get Max LUN . Is the response device specific. By this I mean , a mass storage device successfully goes through all the stages of SETUP ,IN and OUT transcations.While the other one sends a STALL in response to the IN transaction(followed by Clear ENDPOINT feature). and the entire control transfer is repeated again. There is no data flow happening from the device to the HOST.


2. In other SCSI commands, say INQUIRY ,is it necessary that the device returns a NYET in the Command Transport Stage.I had two masss storage devices, one which returned and NYET and the other which returned an ACK.(this is without my circuit, direct connection between the host and the device through Beagle)



PART B   Connection between the HOST and the device through my circuit.




1. Could you please elaborate on the EXT packet ID . I did go through it in your book, but the book did not cover it in detail. Also what exactly is an LPM packet?
I am getting an EXT packet sometimes after Set Address(when I am connecting my circuit).But there is no LPM packet following it.


2. Regarding the vendor specific request, how do I know whether it is directed to the device or not.
I get the following

SETUP  --  2D / 01/ E8

DATA0    C3/40/B0/28/00/11/00/00/00/09/1B

After which there is no response from the device.
 PFA a snapshot of the same which might help you in looking at my query.


Looking forward to your reply.

Akanksha




[attachment deleted by admin]
Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on November 15, 2011, 01:17:05 pm
1. See 3.2 in the Mass Storage Class Bulk-Only Transport spec from usb.org.

2. NYET means not ready. If the endpoint is ready, it returns ACK.

1. EXT is used in power management. See the Link Power Management addendum to the USB 2.0 specification. I would check to verify that that is what the host is actually sending.

2. See 8.4.1 in the USB 2.0 spec.

Jan



Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on November 15, 2011, 02:04:57 pm
  Hi Jan

Had one more query ..

is this sequence possible, I mean is it in sync with the USB 2.0 specs

OUT -DATA0- NAK
PING- NAK
PING- NAK
PING-NAK
repeated for sometime
PING - NYET
PING- ACK  
OUT-DATA0- ACK
WHAT I MEAN TO SAY IS AFTER GETTING a Nak  FOR PREVIOUS PINGs is it possible to get an NYET as a response to a subsequent PING?If yes then is my subsequent interpretation correct. I have laready read what info was mentioned about PING in the USB 2.0 specs. Thats why am asking you :)

looking forward to ur reply

Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on November 15, 2011, 02:24:08 pm
yes, see 8.5.1 in the USB 2.0 spec.

Jan
Title: Re: Regarding USB Mass Storage Device
Post by: Pat Crowe on November 15, 2011, 03:50:33 pm
2. NYET means not ready. If the endpoint is ready, it returns ACK.
Just to clarify, NYET in response to a data packet means that the packet is accepted (the endpoint was ready), but the device is not yet ready for a further transaction. I have encountered 'approved' controllers which assume that NYET in this case means the same as NAK and result in a lockup, so the distinction is important.
Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on November 15, 2011, 06:14:50 pm
Pat's right of course.

Jan
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on January 12, 2012, 06:40:43 am
Hi Jan
Writing after a long time.  :)


Now I am stuck woth yet another thing to figure out and that is Device disconnect.

"The EOP field varies depending on the bus speed. For low- or full-speed buses, the EOP consists of an SE0 for two bit times. For high-speed buses, because the bus is at SE0 when it is idle, a different method is used to indicate the end of the packet. For high-speed, the transmitter induces a bit stuff error to indicate the end of the packet. So if the line state before the EOP is J, the transmitter will send 8-bits of K. The exception to this is the high-speed SOF EOP, in which case the high-speed EOP is extended to 40-bits long. This is done for bus disconnect detection."1.Over here, I want to know how with a 40 bit long SOF EOP , would a device disconnect option be deetrmined? As in, how would the D+ D- lines be monitored?
2. When a device is removed (without ejecting it safely from the system) abruptly, what should be the USB line status of D+ and D- on the HOST and the Device side?

In my setup, I have a transparent Bridge between the HOST(PC) and my device(usb 2.0 mass storage device). So now when I eject the mass storage device safely ,where should I be looking for SE0 State, on Host or on Device Side? ( I have provisions to monitor the D+ and D- lines at both the Host and the Device side).

3. What is the significance of Start/Stop Unit  as far as device disconnect is concerned? I have read it in ur book on mass storage devices, that "A host issues the START STOP UNIT command to request to change the
devices power condition to active, idle, or standby and to request the device
to load or eject its storage media. The command has no data-transport
phase. SBC devices arent required to support this command.

"
4. Is it necessary that each time the device is safely ejected from the system, the Start Stop command is sent by the HOST?

5. If I directly unplug the USB 2.0 storage device without safely ejecting it, I do not get any such command issued from the HOST side. Could you please explain that.

6. Also when I observe the D+ and D- lines of the USB device, on ejecting the media safely , the D+ line goes high and remains so until the device is plugged in again and the chirping and enumeration repeats.
 In this case , I am a lil confused as to where is the "SE0" state which should come on disconnecting the device.


Anxiously awaiting your reply. 

(PS: my system is working fine and the mass storage device gets detected with my logic implemented :) )


 
Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on January 12, 2012, 10:55:57 am
>1.Over here, I want to know how with a 40 bit long SOF EOP , would a device disconnect option be deetrmined? As in, how would the D+ D- lines be monitored?

I believe it's typically done in hardware.

>2. When a device is removed (without ejecting it safely from the system) abruptly, what should be the USB line status of D+ and D- on the HOST and the Device side?

See 7.1.7.3 in the USB 2.0 spec.

>3. What is the significance of Start/Stop Unit  as far as device disconnect is concerned?

The host uses the command to request a device with removable media to eject the media.

>4. Is it necessary that each time the device is safely ejected from the system, the Start Stop command is sent by the HOST?

If the host didn't request the action, it has no reason to send the command.

>5. If I directly unplug the USB 2.0 storage device without safely ejecting it, I do not get any such command issued from the HOST side. Could you please explain that.

See #4 above.

6. Also when I observe the D+ and D- lines of the USB device, on ejecting the media safely , the D+ line goes high and remains so until the device is plugged in again and the chirping and enumeration repeats.
 In this case , I am a lil confused as to where is the "SE0" state which should come on disconnecting the device.

See #2 above.

Jan


 
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on January 12, 2012, 02:32:44 pm
Also when I observe the D+ and D- lines of the USB device, on ejecting the media safely , the D+ line goes high and remains so until the device is plugged in again and the chirping and enumeration repeats.
 In this case , I am a lil confused as to where is the "SE0" state which should come on disconnecting the device.

See #2 above.

Jan


Hey Jan
I did read the specifications but could not follow the SE0 state concept as in whether it is on the device or the host side? Also there  is no mention of the pull up line ie D + going high for device disconnect. If you could please elaboarte on this .

Thanks so much

akanksha
Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on January 12, 2012, 04:09:03 pm
In the USB 2.0 spec, search on

Idle state

Jan
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on February 22, 2012, 06:43:47 am
Hi Jan

Writing to you after long.

Now I needed some info about class specific requests. M religiously referring to your book on USB Mass storage devices and must say , its very lucid in explanation.

However, there were few things I was unsure of and therefore I wish to clarify them with you.


1. what is Read Format Capacity? I could not follow the explanation in your book.

The READ FORMAT CAPACITIES command requests a structure containing
one or more descriptors that specify a number of blocks and a block
length that the media can be formatted for.  
Here which descriptors are we referring to ?



The device returns the structure in the data-transport phase. If the media is currently formatted, the first
descriptor in the structure contains the values in use.Which value in use here ?


 If the media is unformatted,the first descriptor in the structure contains the values that will
result in the maximum storage capacity. One or more alternate descriptors
with different values can follow. This command is optional for SBC devices.

If you could please elaboarte on this .


2. When I format a  device I mean say a flash drive, does the Format Unit block command come into picture? If yes, then what does it signify.
If no , then when does this command come into picture? I could not observe it on my protocol analyser.


3. Now my problem , once my mass storage device is detected, I wish to carry out transactions in such a way that while writing data into the mass storage device, I need to modify the data, before its is stored in the device. For this, what I could gather is that for each bulk read or write , there are three phases

Command Transport
Data Transport
Status Transport

In this , the actual data transfer happends in the data transport phase. So If i wish to modify the data before writing into the device, i need to fiddle with the data in this transport phase.
However , as I have not explored much about the class specific data transfers, I am not very sure if this would in anyway hinder with the other part of the communication. I would be however, passing the remaining data as it is.

But I just wanted to get your piece of advice on the same. Will stalling the  BULK IN endpoint or BULK OuT endpoint or for tht matter the normal control transfer in between(Clear Endpoint Feature) be affected because of it? 


Anxiously awaiting your reply.

Akanksha
Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on February 22, 2012, 11:10:39 am
>1. what is Read Format Capacity? I could not follow the explanation in your book.

>The READ FORMAT CAPACITIES command requests a structure containing
one or more descriptors that specify a number of blocks and a block
length that the media can be formatted for.  
>Here which descriptors are we referring to ?

Here are sources of more information on Read Format Capacities:

http://www.usb.org/developers/devclass_docs/usbmass-ufi10.pdf

http://en.wikipedia.org/wiki/MultiMedia_Commands (not free)

>2. When I format a  device I mean say a flash drive, does the Format Unit block command come into picture? If yes, then what does it signify.[/color]
If no , then when does this command come into picture? I could not observe it on my protocol analyser.

This might help:

http://en.wikipedia.org/wiki/Disk_formatting#High-level_formatting

>3. Now my problem , once my mass storage device is detected, I wish to carry out transactions in such a way that while writing data into the mass storage device, I need to modify the data, before its is stored in the device. For this, what I could gather is that for each bulk read or write , there are three phases

Command Transport
Data Transport
Status Transport

>In this , the actual data transfer happends in the data transport phase. So If i wish to modify the data before writing into the device, i need to fiddle with the data in this transport phase.
However , as I have not explored much about the class specific data transfers, I am not very sure if this would in anyway hinder with the other part of the communication. I would be however, passing the remaining data as it is.

>But I just wanted to get your piece of advice on the same. Will stalling the  BULK IN endpoint or BULK OuT endpoint or for tht matter the normal control transfer in between(Clear Endpoint Feature) be affected because of it? 

I don't know why you need to stall an endpoint to modify the data before writing it to the drive.

Jan

Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on February 22, 2012, 11:40:17 pm
Hi Jan

I do not want to stall the endpoint. However , what I meant by that statement was , when the device sends the data to the host which is less than tht specified in the dCBWDataTransferLength, in that case the device stalls the bulk IN endpoint and in the CSW of the status transport phase, accordingly returns the dCSWData Residue value .(Here once the bulk IN endpoint is stalled, then the HOST issues a Clear Feature Request too)

Now my question was will my modification of the data in the data transport phase affect any of these operations?

I hope now I am able to bring forth my point more clearly.


Akanksha

Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on February 23, 2012, 10:42:05 am
If your modification doesn't affect the USB transfer but just alters the data after receiving it, I don't see how it would cause a problem with the transfers.

Jan
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on March 01, 2012, 03:14:06 am
Hi Jan

I am here to bother you again.

Well I have two sets of queries. Let me bifurcate them neatly for you.


CRC related

1. For SETUP , 11 byte payload   if the data packet is corrupted ie it has a CRC error, the device would not be sending an ACK. In that case teh host would be resending the setup packet three times. After that too due to some reason , if the device does not respond, then what does the host do?

2. if the IN packet is corrupted or for that matter if out -data sequence has out or data packet corrupted, the device would not respond anmd after the time out period teh host would be resending the required packet. Now what I wanted to know is how many times would the HOST be checking the device before the communication dieing out.



CLASS Specific Related

I have read through the mass storage SCSI commands. Now this would be common for pen drive and flass drives and other masss torage devices. I want to modify the data which is written into/read from  the storage media. But I need to also ensure thtat the media is only mass storage one.So if I use a USB CD rom, I do not want to modify the data being read off it. However , usinga  protocol analyser, I probed the packets and in CD Rom case too the dCBWSignature was refelected and dCSWSignature too. I am not much aware of the CD ROM specific class requests.So if you could please throw some light on the distingusihing factor between a mass storage device (SCSI specific) and CD Rom -specific command .

I hope my query makes sense. If not I would try to elaborate.


Looking forward to your reply.


akanksha
Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on March 01, 2012, 09:55:16 am
1. Data errors should be rare. Three errors should be rarer still. The host can do what it wants, including resetting the port and re-enumerating.

2. See bInterfaceSubclass in the interface descriptor and the SCSI INQUIRY command.

Jan
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on March 07, 2012, 04:27:32 am
Hi Jan

Here I am with my next set of queries.

1. For Bulk write and specifically for mass storage devices, is there only Write(10) command sent by the Host to the device. Somewhere in your book it is mentioned that the specification recommends  migrating al code from from WRITE(6) to WRITE(10), but a Host might still attempt to use WRITE(6). However, while observing the protocol analyser I could not come across any Write(6). Now I wanted to know , is write (6) different from Write(10) only in terms of the opcode? I need to modify the bulk write data, so just giving tow possible opcodes corresponding to write(10) and write(6)b would suffice ?


2.  For bulk write transfers, there is a stalling exception wherein  the host expects to send say 10 blocks of data and the device however wishes to receive only 6 blocks of data. Now in your book it is mentioned that the device might accept the entire length of data sent by the host, and process only the required no. of bytes i.e 6 blocks.In this case would the device send a STALL after the 6th block is received from the HOST or is it after all the ten blocks have been sent by the host , in the status transport phase does it send bCSW Status as 02h

3. The reason why am i asking this is i need top modify the data coming from the host for sometime and I wish to to do this for the entire transfer length decoded from the CBW in the command transport phase. However, if  for bulk OUT transcations, stalling occurs before the transfer length, in that case i need to reset the counter value as the transaction owuld stop before the transfer length is completely executed. I could probe such a  situation practically so needed ur inputs as in your book you have mentioned that
"Staling the BULK Out endpoint can cause problems under Windows, so most devices accept the dCBW DataTransfer Length bytes and set the dCSWDataResidue to the appropriate value."


Looking forward to your reply.


Akanksha
Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on March 07, 2012, 10:59:29 am
See the SCSI Block Commands spec for complete definitions of the WRITE commands.

If the device accepts the data sent, the command completed successfully.

Jan
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on March 22, 2012, 02:40:07 am
Hi  Jan

Am again there to bother you :)
I have written the logic to modify the data being written into the pen drive. However now when i do bulk write operation , I see a lot of frame timing jitter for the SOFs. However I pass the SOFs just as it is without letting it pass through the modification block which could have possibly caused the delay. So I am unable to find out the reason for these jitters.

If you could throw some light on this, I would be really very grateful.

akanksha 
Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on March 23, 2012, 09:45:53 am
What your firmware does with already received data shouldn't affect SOFs on the bus. So I have no explanation from the information you've provided.

Jan
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on March 24, 2012, 01:53:34 am
Hi Jan

Ok Lemme elaborate.

In my previous case , the data coming from the host was stored in a buffer which was eventually read by the USB device.

Now with the intention of modifying the data, the data from the host is stored in the 1st buffer, from where it is read by the modification block. If the data is SOF, IN ,PING, SETUP etc, its just pushed into teh second buffer blindly. However if it is a bulk write data , then teh data is modified and then stored into teh second buffer from where now the data is eventually read by the device.


So now when I have any other class specific request, say read, read format capacity, mode sense, inquiry  etc, or for tht matter all control transfers, the SOFs come perfecly after 125 us.

However When I do bulk write operations, I observe a lot of SOF timing jitters ie SOFs inter gap of less than 125 us (which was not the case prior to addition of the second storage buffer)

However, it does not have any effect on read/ write operations.

So I wanted to know can this cause a serious issue . Also if you could tell me any possibility as to why it is happening.


Akanksha
Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on March 24, 2012, 10:26:45 am
Where is the buffer? If it's in the device, it shouldn't affect the USB traffic. If it's an external device between the host and the target device, I think it will be difficult to capture the data, modify it, and pass it to the device without timing issues.

Jan
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on March 27, 2012, 08:18:15 am
Hi Jan

My next set of queries.

When the HOST issues an inquiry command or read capacity or read format capacity, before that does the HOST itself write that information to the device or this info is provided as one time writable info by the device manufacturer.

Why I am asking this , is while modifying the bulk write data, I observed that the data got modified in the device, However, after that , even though teh free space shown is 14 Gb , I am unable to write any data more than 5 Gb on it. This could obviosuly be due to some memory address being affected.

This really concerns me because according to me whatever info I modify using some logic for bulk write, the same innfo in bulk read , I would extract using the reverse logic. However, the erroneous behavior of the pen drive leaves me with a doubt that is it just the bulk read data which needs to be deciphered or is it also other commands like read capacity , read format capacity etc.


I went through almost all docs available for mass storage devices but could not find any info  regarding this.


So , had to bother you.


Lemme know if I need to clarify further.


akanksha




Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on March 27, 2012, 10:15:27 am
The device reports its capacity to the host.

Jan
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on June 04, 2012, 03:18:56 am
Hi Jan

Bothering you after a long time with my new set of queries.
Right now I am testing my bridge implementation. However , I wanted to know the reason behind few observations :-

1. For 2 GB of transfer data , the amount of time taken to write into the mass storage device(write operation) is always greater than the amount of time taken to read the same data from the mass storage device(Read operation). eg. if say write takes 12 min, Rea operation takes only 2 min.What could be the reason for such significant time difference?

2. Even while writing the data into the mass storage device, there are soem Read operations which happen along with the expected Write operations. This is once the mass storage device has been detected and the write operation has started. What could be the reason for this?

3. If we copy the contents of the pendrive, back into the pen drive what kind of operation is it ?


Anxiously awaiting your reply.

Regards

Akanksha Jain
Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on June 06, 2012, 09:39:48 am
A protocol analyzer can show exactly what operations, including what SCSI commands, are occurring and how much time each transaction takes and thus will help you understand what is happening.

Copying contents from and to a pen drive requires reading, then writing.

Jan



Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on September 14, 2012, 04:54:18 am
Hi Jan

I am writing in, after a very long time. Presently I am facing some hub related issue. Just to recapitulate, my design acts as a bridge between the USB 2.0 HS Host and USB 2.0 HS device. For the Host , I take direct connection from the motherboard so I never came across any HUBS . Now in some systems(newer ones I guess, usb ports are through an inbuilt hub and )my system probably fails due to this. I went through the USB 2.0 specs but could not significantly find any difference in the basic enumeration cycle in case the transmission happens through a hub.

Even with a Beagle protocol analyser, I could not observe any significant difference. The Chirk-j through direct connection was somewhere around 732 and with hub reduced to 41/42 kind. Other than that , I could not observe anything else.

If I need to modify my design to cater for the HUB incorporation, would the change be even at the data transfer level I mean the control and the bulk transfers or it would be at the basic device enumeration level?

I would be  really thankful if you could please reply to my queries.


Regards
Akanksha
 





Title: Re: Regarding USB Mass Storage Device
Post by: Barry Twycross on September 14, 2012, 01:19:33 pm
What does your device fail to do? You're talking about resets and chirps, does you device not get enumerated at high speed? If you need to debug things like chirps, an Oscilloscope is most useful, so you can see exactly what they look like. A protocol analyser will only signal its presence or absence, and other devices may disagree with this view.

I'm also not sure what your device is, what do you mean when you say its a "Bridge".
Title: Re: Regarding USB Mass Storage Device
Post by: akanksha112 on September 18, 2012, 07:51:18 am
Hi Barry

Yes, my device does not get detected through generic usb hub . However in direct connection between the USB host and the device or through Root hub, everything works fine.
 Before I can proceed  ahead to tell you the problem in detail, there are few things I need to check at my end.

Could you please tell me the basic difference between a root hub and a generic usb hub?
If they are different then for which hub does the hub specific request come into picture?

akanksha
Title: Re: Regarding USB Mass Storage Device
Post by: Jan Axelson on September 18, 2012, 11:56:32 am
A root hub performs the function of a hub inside the host. If the device is full speed, an external USB 2.0 hub also converts between full speed (downstream) and high speed (upstream).
Title: Re: Regarding USB Mass Storage Device
Post by: Barry Twycross on September 18, 2012, 01:23:25 pm
From a device standpoint the difference between a device attached to a root hub and an external hub should be nothing at all. As Jan mentions if the device is full (or low) speed, the device is now being talked to via split transaction via the hub, so the device will be talking to an EHCI controller, not an OHCI or UHCI controller as it was previously. The timing of transactions can be substantially different, but nothing that a device should not be able to handle.

So the first question, is your device full speed? (or high speed).

As I asked previously, what doesn't work? You've now mentioned "resets", "chirps', and "enumeration". Does you device:

1. get recognized as being attached? (so the host resets it)
2. get successfully reset? (so the host talks to it at the expected speed)
3. fail a subsequent control transaction?

There are lots of things which can go wrong, without knowing at what point your device fails, I couldn't give any advice.

I will say that when we introduced a hub on our motherboard, we didn't see many, if any devices fail. The only enumeration issue I can remember was to do with drive strength settings on the hub, I can't remember the details.