Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

USB storage devices, such as USB sticks and harddrives, are common to attach external storage to any kind of computer. How can the Raspberry Pi emulate an USB storage? The easiest application was to directly access the SD card via USB, but one could also provide acccess to files via Ethernet. I thought about the following layout for an "USB cloud stick":

Computer <---USB---> |Raspberry Pi| <---Ethernet---> Cloud, NAS etc.

The computer should only see a normal USB stick to read and write files from. The Raspberry Pi would act as programmable bridge that map directory listings and file accesss to request to a cloud storage. You could access cloud storage hosters with any computer (including black box media players) via USB without having to install any additional software on the computer. The Raspberry Pi USB bridge should also be able to encrypt/decrypt files on the fly, so one could store files encrypted in the cloud and access them on any device like a normal USB drive.

Edit: Existing products with similar but limited functionality include Wireless Media Stick and USB-over-Network. Access to files in the cloud may be possible by mounting virtual storage with cloud drive or similar software and encryption with TrueCrypt or EncFS - passwords would be stored on the SD card of Raspberry Pi only but one could access the storage with any computer without having to type in a passphrase on a untrusted machine.

share|improve this question
    
So all you want is a method of sharing files between the Pi and Computer? –  Jivings Jul 15 '12 at 23:39
    
I think what he wants is to have a partition or shared folder on his Pi that is mountable via USB on other machines. The idea being that you could plug the raspi into any computer and that folder/partion acts like a flash drive and can be written to without any additional software. –  wmarbut Jul 16 '12 at 2:30
1  
The Pi should only act as gateway between any computer, including black boxes, and for instance Amazon cloud. The gateway could also encrypt the files on the fly. –  Jakob Jul 16 '12 at 6:57
1  
Scrap that - this would be perfect! –  Alex Chamberlain Jul 17 '12 at 8:22
1  
Looks interesting ... –  ppumkin Nov 13 '12 at 11:59

8 Answers 8

The problem is that the Pi's USB connection to the PC doesn't have the data pins connected - only the power pins. So you can't use this to speak USB because it's not wired up.

Your only option with the Pi would be to 'bit bang' USB using the GPIO pins, but this is very slow and potentially unreliable. I suspect you would only really be able to emulate a keyboard or mouse - anything higher bandwidth would probably be too much for the CPU to cope with, given the tight timing requirements of bit banging something like USB.

Another alternative would be to find a device that lets you connect two computers together via USB, to make a kind of network. But then you may as well just use the Ethernet connection...

share|improve this answer
1  
I've previously played with a GP32 which can behave like a host even when plugged in a hub as a client. If the Raspberry can behave like a host on the USB-ports (not the power one) then a similar trick should be possible there too. Perhaps USB-to-go can do it? –  Thorbjørn Ravn Andersen Aug 1 '12 at 22:06
    
@ThorbjørnRavnAndersen: Definitely worth investigating, although per the below answer it may prevent the Ethernet from working, if you mean to switch the hardware port to OTG. Unless OTG supports a hub with the downstream ports going both ways? –  Malvineous Aug 2 '12 at 1:51
    
I don't know. Hopefully somebody will just try and see what happens –  Thorbjørn Ravn Andersen Aug 2 '12 at 2:54
1  
Huh? You are mistaken by the micro usb port used for the power adapter. What about the 2 proper USB ports? With some emulation software it would be possible to plug that usb into a PC and emulate Storage - eg - Android phone when you plug in usb. - But there is not reason for that because you plug the Pi into your network, share your "cloud" folder via samba or whatever(wifi or lan)- and also at the same time do your cloud synching whatever it is you want to do. LAN can handle many request on various ports –  ppumkin Nov 13 '12 at 11:08
1  
@ppumkin: Why am I mistaken by the micro USB port? The data pins aren't connected, so you can't send data across it. The downstream "proper" USB ports are 'host' ports, so it is not possible to plug them into a PC without some kind of converter device in the middle. Software emulation is not enough, because of the way the USB protocol works. You might be thinking of Ethernet where you can plug any two devices together, but USB doesn't work like this. If you don't believe me, have a read of the USB specification, especially the parts about USB hosts vs peripherals. –  Malvineous Nov 13 '12 at 23:49

Based on a quick perusal of the BCM2835 data sheet (http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf) chapter 15, it looks like USB OTG is supported in HW, so theoretically, it might just be a matter of SW to support the proposed scheme. I'm not a USB protocol expert (or even novice, really), but it would be pretty cool to have this functionality.

Looking at a description of the BeagleBone (http://elinux.org/BeagleBone), it appears to support something similar, although there is specific mention of a connector that supports this mode. It would be unfortunate if the Raspberry Pi is limited due only to connector selection.

Hope this is helpful.

share|improve this answer
1  
Even if the SOC supports it, the LAN9512 hub device on a model B probably gets in the way of running the USB port "backwards" in device mode. On a model A (or if you remove that and install R37 & R38) you could get the SOCs USB port to the external jack - but then you would not have ethernet, and would only have the sdcard for potential storage. –  Chris Stratton Jul 31 '12 at 0:08

Unfortunately though this seems simple, as best as I can tell, it hasn't been done. See this thread and very detailed answer for more details

http://unix.stackexchange.com/questions/2683/serve-files-over-usb

And a Pi specific answer here: http://www.raspberrypi.org/phpBB3/viewtopic.php?f=8&t=4938

share|improve this answer
1  
Thanks for the links. Looks like this device may do part of what I want, but its proprietary and only works in one direction (virtual read-only USB storage). –  Jakob Jul 17 '12 at 6:58

If you aren't particularly concerned about performance, you could probably get a USB capable microcontroller with USB mass storage code (you could for example reprogram the STM32F103 debug interface on a $10 STM32F0 discovery eval module), carefully connect that to the pi's serial port as a back end, and run at several hundred kilobaud.

Better performance would likely be had by interfacing to the client PC via ethernet, but that would require a custom driver or different presentation to the host operating system - ie, you'd be a network attached storage device or share server.

Off the shelf file transfer cables were I believe already mentioned, but that would require appropriate software for the client PC and source-level linux driver support for the pi end.

share|improve this answer
    
Yup. See also olimex.com/Products/AVR/Proto/AVR-USB-162 –  greggo Jan 6 '13 at 19:11

This comes down to how USB works, you see whenever two things are connected with USB there is all ways a USB host and a USB device and never the twain shall switch places. A USB host does all kinds of things that USB devices cannot do mostly to sync up data transfer between all devices connected to the USB bus. Check out the USB wikipedia page for more info.

What you're talking about doing is forcing two USB hosts (the Raspberry Pi and a computer) to communicate which unfortunately is simply not supported by the USB standard. There are some devices which can fake a data transfer between two USB hosts but as Malvineous mentioned you'd be better off using ethernet.

Your question specifically mentions using the Raspberry Pi to emulate USB storage but have you considered setting up the Raspberry Pi as a NAS? Using the Raspberry Pi as a NAS box basically does exactly what you asked for but instead of using USB it would be using your network. Here are great instructions on how to do this if you are interested.

share|improve this answer
    
Thanks for the pointers. So my questions is about how to implement a USB device using a Raspberry Pi. A NAS, however is not an answer to this question. –  Jakob Jul 25 '12 at 7:12
3  
If you want the Raspberry Pi to have the ability to be a USB device I suggest you investigate the products at ftdichip.com more than likely you'll be able to wire up a board that uses the Pi's GPIO pins to interface with an FTDI chip and that will give you USB device capability. You'll probably also need to write a driver to communicate with the FTDI device. –  Dan B Jul 25 '12 at 13:36
    
Except that "the twain shall switch places" if they are USB OTG devices... –  Chris Stratton Jul 31 '12 at 0:10

I found out that Arduino can emulate a USB device, the Arduino Leonardo even out of the box. The LUFA USB stack can be used on Arduino and it implements a USB mass storage device driver (see this tutorial). This setup could be used to map USB to SCSI commands such as understood by the SD card reader. I don't know enough about SCSI but it looks like the SD card on Raspberry Pi and the USB-via-Arduino could be used together on the same bus. Sure this idea is not a full solution...

share|improve this answer
    
-1 Since the topic is about the Raspberry Pi and not Arduino. –  Bryan Dunsmore Aug 1 '12 at 23:03
1  
I know, this answer is no full solution! I hope that that questions about Raspberry Pi as a tool instead of an an end in itself are on-topic and broadening the view to related project helps. In this case I found this tutorial how to use an SD card as USB mass storage device. Maybe one could use an Arduino or another ATMEGA32U4 to get USB to the SIP bus which is also available on Raspberry Pi? –  Jakob Aug 2 '12 at 8:13
2  
No, you can't really share access to the sdcard, other than by electrical switching. Only one host can "mount" a given filesystem at a time (for the types of filesystems used on cards - network filesystems are different in this respect). –  Chris Stratton Aug 2 '12 at 12:47

I can do it with my old Nokia N900 Phone using the usb gadget driver included with the stock Nokia kernel. The emulated device behaves exactly like a real one, you can even boot a PC from it.

share|improve this answer
1  
Could you provide some details? You don't talk about just providing the storage at your phone via USB like most other smartphones can do, do you? As far as I understand, a USB gadget driver only provides a mapping from SCSI to USB, so one would still need to map SCSI to some cloud storage API. –  Jakob Nov 13 '12 at 8:59

The USB standard are host based. That means that one device has to controll all communication with the connected devices. Clients can be a simple device or a hub. The hub is a host proxy for the clients connected to the hub, and communicates with the host (or hub) it's connected to.

As the original design of USB looks, you can't connect two hosts together (your PC and the RPi).

There are extentions though, USB On-The-Go, which allow a USB connection to see if it is connected to a host or a client, and adjust it's role depending on that. To this to work, you have to have support in the hardware. I don't belive the RPi is designed to do that.

For more information, look att http://www.usb.org/home or even http://en.wikipedia.org/wiki/Universal_Serial_Bus

In short, I don't belive that it can be done.

share|improve this answer
    
Another answer contradicts your lack of OTG support remark. –  Alex Chamberlain Jul 26 '12 at 19:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.