Exchanging user defined data via the USB protocol stack with the MBED

05 Mar 2012

Greetings MBED hackers,

I am sorry, I could not come up with a title that could convey exactly what I want. But roughly what I am trying to do:

I am using the USBMSD interface to use my MBED as a USBDevice and provide access to an SD card as a USB mass storage device. (the code I have used is here: http://mbed.org/handbook/USBMSD).

But now I want to exchange some custom out-of-band information with the host side through the USB interface. But I am not sure where that code should go in the MBED side for that. Of course, this will require some changes on the driver on the host side. But I would like to first figure it out on the MBED side and from then go on to the host driver side. I don't have much knowledge of the USB protocol so any ideas/pointers would be welcome.

Seemanta

05 Mar 2012

Hi Seemantha,

In my opinion, the easiest way to exchange raw data with the host is to use the USBHID class. As all OS have a built-in HID driver, there is no need to develop a specific driver. You can directly exchange raw data with a custom program running on the host. You can find some examples on the USBHID bindings webpage.

Sam

05 Mar 2012

Hi Sam, Thanks for your advice. However, I was looking for a mechanism to transfer custom data at the USBDevice level itself. By incorporating the USBHID class, I am going out of scope of USBMSD.

I am trying to make a custom USBMSD implementation that will have a capability to exchange some user defined strings. So, it would be nice to encapsulate that within the USBMSD or its parent classes, right ? I mean that makes the design clean.

No doubt, using the USBHID class seems like a workable solution, but my first priority would be to get everything done within the domain of USBMSD. What do you say ?

Thanks as always, Seemanta

05 Mar 2012

Hello Seemanta,

do You mean to have mbed acting as USBMSD device with capability to send and recieve data? I think You mean composite device? Composite USB devices include more than one interface ( for example mbed can be mouse and keyboard at the same time for host).

So are You looking to make device which is USBMSD and RAW HID or CDC at the same time? The mbed's USB interface is like USBMSD and USBCDC. If You connect mbed to PC it shows up as flashdisk and virtual serial COM port for serial communication (with terminal for example).

If You are interested in USB CDC & MSD You can take look here http://mbed.org/users/okini3939/notebook/USB_Device/

Composite USB devices can have more than one or two "interfaces" and can act as more than one or two usb devices at the same time.

For each device must be properly written descriptors and report descriptors to get USB host know what USB device it is and how communicates.

Write more Your questions here.

05 Mar 2012

I am not sure if a composite device is really what I want. Think of this scenario: I want to assign some kind of unique ID to my USBMSD device. This can be hardcoded in my MBED source code.

When the USBMSD is plugged in, the driver on the host side will query the MBED device for its unique ID. But I need a way on my USBDevice implementation on the MBED to provide this unique ID to the host side. This is exactly what I am trying to achieve. I believe this can be done within the USBDevice implementation itself, without involving a composite USB device, am I right ?

Thanks again for patiently responding to my questions.

Seemanta

05 Mar 2012

Hello Seemanta,

do You mean that You want USB host(PC) to understand that two or more devices (USBMSD in Your case?) with same VID and PID are different real devices?

USB offers iSerial string which is hardcoded in device and host on PC is able to check this string and differs more devices with same VID and PID.

It is like serial number of device.

If this is what You want, post here and we can try to get it work together.

05 Mar 2012

Hi llumpu, Unique ID is just an example. What I would want is to exchange *any* data I want, or more generally a data buffer of say, length 512 bytes. Will the iSerial interface help me in this case? Also, how do I use this iSerial class? On the host side, how would I extract the data from this buffer?

Sorry for asking a lot of questions but at this point, I am somewhat lost. I am again very grateful and thankful to you for your help. I wish I could buy you a beer or something.

Also another important thing is that this transfer should be both ways: the host should be able to transfer an arbitrary buffer of data to the USBDevice and the USBDevice should be able to transder an arbitrary data buffer to the host.

Seemanta

05 Mar 2012

A common solution is to use SCSI pass through requests with custom commands.

05 Mar 2012

Igor Skochinsky wrote:

A common solution is to use SCSI pass through requests with custom commands.

Can you explain more on this? I am sorry as I am new to USB, this might be a stupid question. I do understand that the the USBMSD appears as a SCSI device. But which part of the MBED USBDevice library should I be looking at in order to implement these custom SCSI commands ?

05 Mar 2012

Okay, so I did some more research into custom SCSI commands. From http://en.wikipedia.org/wiki/SCSI_command I got a list of all SCSI commands. Out of this list, I am looking at ATA COMMAND PASS THROUGH (12) and ATA COMMAND PASS THROUGH (16).

So all I need to figure out is a way to send these commands from the host driver and a way to handle these at the USBMSD.cpp file on the MBED side, right ? Is that what you were referring to ?

Seemanta

05 Mar 2012

Hello Igor,

I am interested in SCSI pass through requests with custom commands too. Can You please explain it more or point any www link?

05 Mar 2012

On Windows, you can use IOCTL_SCSI_PASS_THROUGH to send custom commands. In USBMSD, it seems that they're handled in USBMSD::CBWDecode().

Here's a little info about SCSI support in MSD: http://www.lvr.com/mass_storage_faq.htm

05 Mar 2012

Hi Igor, Can this be done in Linux too? Seems like SCSI pass through interface is available only on windows. Would it be possible to send a SCSI pass through command from a Linux host?

Thanks, Seemanta

Please log in to post a reply.