Author Topic: Regarding USB Mass Storage Device  (Read 59542 times)

akanksha112

  • Member
  • ***
  • Posts: 31
Re: Regarding USB Mass Storage Device
« Reply #30 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


Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Regarding USB Mass Storage Device
« Reply #31 on: November 15, 2011, 02:24:08 pm »
yes, see 8.5.1 in the USB 2.0 spec.

Jan

Pat Crowe

  • Member
  • ***
  • Posts: 39
Re: Regarding USB Mass Storage Device
« Reply #32 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.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Regarding USB Mass Storage Device
« Reply #33 on: November 15, 2011, 06:14:50 pm »
Pat's right of course.

Jan

akanksha112

  • Member
  • ***
  • Posts: 31
Re: Regarding USB Mass Storage Device
« Reply #34 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
device’s 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 aren’t 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 :) )


 

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Regarding USB Mass Storage Device
« Reply #35 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


 

akanksha112

  • Member
  • ***
  • Posts: 31
Re: Regarding USB Mass Storage Device
« Reply #36 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

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Regarding USB Mass Storage Device
« Reply #37 on: January 12, 2012, 04:09:03 pm »
In the USB 2.0 spec, search on

Idle state

Jan

akanksha112

  • Member
  • ***
  • Posts: 31
Re: Regarding USB Mass Storage Device
« Reply #38 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

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Regarding USB Mass Storage Device
« Reply #39 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


akanksha112

  • Member
  • ***
  • Posts: 31
Re: Regarding USB Mass Storage Device
« Reply #40 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


Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Regarding USB Mass Storage Device
« Reply #41 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

akanksha112

  • Member
  • ***
  • Posts: 31
Re: Regarding USB Mass Storage Device
« Reply #42 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

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Regarding USB Mass Storage Device
« Reply #43 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

akanksha112

  • Member
  • ***
  • Posts: 31
Re: Regarding USB Mass Storage Device
« Reply #44 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