Emulate USB mass storage device


14 posts
by NickstaDB » Wed Apr 18, 2012 8:07 pm
I'm not sure how USB and USB storage devices work under the hood but would it be possible to have the Pi act as a USB mass storage device when connected to my laptop via USB? If so can anyone point me towards any resources, code, libs etc that might help in achieving this?
Posts: 2
Joined: Wed Apr 18, 2012 6:49 pm
by nick.mccloud » Wed Apr 18, 2012 8:38 pm
Whilst this may be possible with some cunning software config, the Pi will only have local storage amounting to the space on the SD Card. Do you want to access this storage, if so there would be simpler ways.

Alternatively you could set it up as a file server and access it over the network, again with the limit of storage on the card.
User avatar
Posts: 797
Joined: Sat Feb 04, 2012 4:18 pm
by plugwash » Wed Apr 18, 2012 9:29 pm
The problem is that the Pi doesn't have any USB device ports (only USB host ports) so you can't connect it to your laptop over USB.

If you want an arm linux board that can act as a USB device you will have to look elsewhere (for example the beagleboard series).
Moderator
Moderator
Posts: 1967
Joined: Wed Dec 28, 2011 11:45 pm
by NickstaDB » Fri Apr 20, 2012 9:12 pm
Thanks for the responses. My idea only works if I can make the Pi look like a USB device (mass storage or otherwise) when connected to a PC/laptop via USB. I'm not after a specific board for that purpose though, just experimenting with my Pi :-)
Posts: 2
Joined: Wed Apr 18, 2012 6:49 pm
by jbeale » Fri Apr 20, 2012 9:29 pm
If you're willing to put up with USB "low speed" at 1.5 Mbit/sec it's actually possible to bit-bang that from software (at least with some architectures, not sure if it's ever been shown to work on a Linux/ARM system).  Of course that's meant for keyboard/mouse type devices, most people would consider this impractically slow, if you're transferring anything but small text files. And you'd still need a bit of hardware to connect a pair of GPIO pins into a USB-A jack.
User avatar
Posts: 1885
Joined: Tue Nov 22, 2011 11:51 pm
by hamjudo » Fri Apr 20, 2012 10:22 pm
The model B has a built in 2 port USB hub, which does not know how to act as a USB device. The model A directly connects the processor USB interface, which can be configured either as a USB device or USB host.

Obviously, that won't work until people have Model A's to develop on, and someone has the talent, the time, the inclination, and the documentation, to write the device driver.

Bit-banging a slow speed USB device over GPIO should be possible on the model B. This could be a simple port of one the many examples for 8 bit micro controllers. Emulating a USB mouse or keyboard is the classic first application. The timing constraints may not play well with the non-realtime stock Linux kernel on the R-Pi. But if you're just doing it to learn, you can treat the Pi as a micro controller. You can write a device driver that takes control of the hardware, and doesn't return control until it is done doing its timing critical parts. Old time Unix and Linux hackers are horrified by the thought of a device driver that disables the other interrupts, potentially breaking any open network connections, starving the graphics system, and corrupting the filesystem. This is horrifying on a machine that is being used for other things. Not a problem on an inexpensive system that isn't being used for anything else. Just back up your SD card before messing with the your own device driver. Locking up the system a few times is a sure thing. Corrupting the filesystem is just incredibly likely.
Posts: 58
Joined: Thu Nov 03, 2011 3:25 pm
by hippy » Fri Apr 20, 2012 10:22 pm
You could use a microcontroller which can present itself to the host as a USB mass storage device and interface to that via GPIO. It probably won't have maximal speed, could require a lot of effort to implement, but could be good enough for some applications.
Posts: 756
Joined: Fri Sep 09, 2011 10:34 pm
by jbeale » Fri Apr 20, 2012 10:59 pm
As an example, the Microchip PIC18F2550 has a USB interface (12 Mbps "Full Speed" USB 2.0), costs about US$4.50 in single quantity, and is reasonably easy to work with (28-pin DIP package).

http://dangerousprototypes.com.....ent-board/

http://www.microchip.com/wwwpr.....e=en010280

Microchip provides a USB stack, most of the work would probably be writing the device driver to communicate with it (SPI, maybe?) from the Linux side.
User avatar
Posts: 1885
Joined: Tue Nov 22, 2011 11:51 pm
by BertM » Sat Apr 21, 2012 1:45 am
If you can make the RPi talk the SD card protocol (the card side, to be precise) through its GPIO, you could just hook it up to any SD card reader you can get off eBay for $1.

Considering the Broadcom SoC can interrupt on every single GPIO pin and the clock is entirely provided by the card reader, this should not be too difficult to do, as long as you can talk the SD protocol.
Posts: 30
Joined: Wed Feb 08, 2012 4:12 pm
by Danbury Shakes » Mon Apr 30, 2012 2:53 pm
Ideas from a non technical bod who probably doesn't realise why the following is impossible but...

Would it be possible to use a microcontroller to be a slave of 2 computers, each one plugged in as a master.

The None Raspi comp sees this as a hard drive whilst the Pi has software monitors the middle man and manages any reguests for data?  Of course this would have a hit on the speed of transfer and also on the system speed but if the Raspi has a Slave Mode then it could suspend other functions in this mode.

I was thinking of something like a portable Media Player able to be plugged into a USB to upload/download audio/video.

Would it be possible to use Samba over a serial link in some way so the microcontoroller can then share it?

In fact is it possible to write a Samba client that would run in a microcontroller?

If yes would it then be possible to show that share as a USB drive?

Of course if that did work you could also do it the other way round - and use your PC as a usb drive for the Raspi :)
Posts: 15
Joined: Thu Apr 12, 2012 8:41 am
by smithtec@gmail.com » Mon Apr 30, 2012 5:21 pm
Posts: 1
Joined: Mon Apr 30, 2012 4:18 pm
by Danbury Shakes » Mon Apr 30, 2012 6:23 pm
Nice find - I bet that the big end has something soing a similar job to that which I garbbled out earlier.

I rethought my earlier idea and have come up with something more thoufht our (but equally vague).

Word of advice - when at work DONT mumble to yourself about Slaves, multiple masters or bindings. I now have a meeting with my manager - who is totally nontech ;)
Posts: 15
Joined: Thu Apr 12, 2012 8:41 am
by Krytle » Sun Jun 24, 2012 10:36 am
hamjudo wrote:The model B has a built in 2 port USB hub, which does not know how to act as a USB device. The model A directly connects the processor USB interface, which can be configured either as a USB device or USB host.

Obviously, that won't work until people have Model A's to develop on, and someone has the talent, the time, the inclination, and the documentation, to write the device driver.

Bit-banging a slow speed USB device over GPIO should be possible on the model B. This could be a simple port of one the many examples for 8 bit micro controllers. Emulating a USB mouse or keyboard is the classic first application. The timing constraints may not play well with the non-realtime stock Linux kernel on the R-Pi. But if you're just doing it to learn, you can treat the Pi as a micro controller. You can write a device driver that takes control of the hardware, and doesn't return control until it is done doing its timing critical parts. Old time Unix and Linux hackers are horrified by the thought of a device driver that disables the other interrupts, potentially breaking any open network connections, starving the graphics system, and corrupting the filesystem. This is horrifying on a machine that is being used for other things. Not a problem on an inexpensive system that isn't being used for anything else. Just back up your SD card before messing with the your own device driver. Locking up the system a few times is a sure thing. Corrupting the filesystem is just incredibly likely.


If I want to make a GPIO usb device, could I resolve filesystem corruption with realtime linux?
Any ideas where to start reading if I want to do this?

Using a microcontroller eg PIC18F... , do they allow me to control all aspects of the communication like a GPIO-connection would? (I mean, can I dynamically change the device id etc or do I have to flash it each time?)

Btw, I read that USB uses pull up resistors, can I simulate these with GPIO or will I have to create some kind of circuit for this?

Thanks! //Krytle
Posts: 1
Joined: Sun Jun 24, 2012 10:25 am
by markosjal » Sat Mar 02, 2013 4:36 pm
You may want to look at the Wifi SD cards that pretty much do this for a Camera already. I think with some hacking it could make a great combination for the RPi and might even allow it to boot from a network????

there are some hacks I have seen for the EyeFi cards
http://magiclantern.wikia.com/wiki/Eye-Fi

as well as Chinese versions of these cards.

http://www.aliexpress.com/item/Ez-share ... 29820.html

http://www.aliexpress.com/item/Free-shi ... 69930.html


I think this would then leave the USB port on the model A for Device mode (if Possible) while still offering access to the files over wifi and not negating the need to boot from SD card.


UPDATE
Just found this interesting tidbit
http://dave-hansen.blogspot.mx/2012/08/ ... ry-pi.html
Posts: 7
Joined: Sun Mar 18, 2012 3:03 pm