hippy wrote: ↑
Thu Dec 13, 2018 5:55 pm
A Pi can only be a host or slave USB device, not both together. You can use two Pi and link them via serial or other means, or add extra hardware to allow host and device ports, but you would likely still have problems trying to have two sides accessing the same Mass Storage Device file system.
Zero/zeroW can swap modes without a reboot just by unplugging the otg cable and plugging in a standard micro USB cable from the host. Provided that the zero has its own PSU.
A/A+ can swap modes by unloading and reloading the dwc2 module with an apropriate dr_mode parameter to force the mode. 3A+ is probably the same but as I don't have one I can't confirm that.
The trick is having physical access to the Pi and knowing when it's safe to do either of the above.
For remote access on the hardware side you could do what I believe the CM dev board does and use a USB multiplexer/switch to handle the change in device connection but that doesn't overcome the safety issue.
That tutorial is flawed as it changes the contents of the MSD gagdet's storage while it's online with the host and forces a disconnect/reconnect on the host regardless of what the host is doing at the time.
It's quite clear in the g_mass_storage docs that "The only safe way to share the backing storage between the host and the gadget's operating system at the same time is to make it read-only on both sides." (see http://www.linux-usb.org/gadget/file_storage.html
). The safe way to write to it is to unmount the otherside first.