-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RPi zero Support for USB Gadget Mode (pi shows up as keyboard, disk, net, camera etc) #1212
Comments
That would also allow you to code on the Pi Zero with only a single cable (for power and network) to a PC. |
Apparently the data pins on the port used for power aren't connnected to the SoC: http://raspberrypi.stackexchange.com/questions/8587/can-you-transfer-data-through-the-microusb |
I'm not talking about using the port that is for power only. This is specifically for the second usb micro port on the RPi zero that does have the data pins connected (you usually use an OTG cable to connect to it in host mode). I'm wanting to use that same port in gadget mode. |
It looks like the RPi can be powered over that second port (the one we want to use in gadget mode). So @imbens idea for allowing us to code with a single cable seems valid. |
For most OTG supported ports, it depends on what you plug into it that decides if the port is in host mode or gadget mode. We just need to get confirmation that the RPi zero port is wired the same way for the port that has it's usb data pins connected (not the one dedicated to power). The RPi zero USB_OTGID pin should be grounded by the cable when using a micro-A / OTG cable and is hopefully left floating otherwise. That way we can the more common micro-B cable for providing power and connecting the usb data pins to a computer. Here is a RPi zero mechanical diagram, that shows the two usb micro ports for the RPi zero in bottom right: I couldn't find wiring schematics for RPi zero, so I pulled these from the RPi A This is the usb micro port used for power: (no data pins) This is the RPi-A USB-A port (note that the USB_OTGID pin on the usb controller is grounded). On the RPi zero, this connector is a micro-b port, and shouldn't have the USB_OTGID pin grounded, as that is usually done by the cable to distinguish between OTG/Host mode and usb gadget mode. I suspect that if we connect a normal usb A to Micro-B cable that doesn't ground out the USB_OTGID pin on the RPi zero, that we can accomplish the correct physical connections without any modifications, but we may need the kernel changes mentioned in this comment on #881 |
@ladyada provides a really nice picture of the port in questions: We want to use the USB micro port on the left, not the POWER IN port on the right. |
I agree it would be great to see this working. I don't have a PiZero myself yet, and this doesn't directly relate to the linux driver mentioned here (so apologies if this is slightly off-topic) but I experimented earlier in the year (or maybe it was last year) and was able to get https://github.com/raspberrypi/tools/tree/master/usbboot to work with a Raspberry Pi Model A, when either no SD card was inserted, or when start.elf (I think - or maybe it was bootcode.bin) was renamed. I.e. if I logged into the Model A over the serial terminal, renamed /boot/start.elf on the SD card, ran rpiboot on my PC and used the serial terminal to reboot the Pi, then I was able to access the Model A's SD card on the PC as a MassStorageDevice. |
I've just been playing around in GIMP with the lovely hi-res images from https://learn.adafruit.com/introducing-the-raspberry-pi-zero by following the traces across the top and bottom sides of the PCB :-) |
Any chance we could then use Chromecast Ethernet Adapter (https://store.google.com/product/ethernet_adapter_for_chromecast) to both charge & get RJ45 socket in one cable then? That would be great solution for RPi zero |
Interesting idea. I did a bit of googling and found https://productforums.google.com/forum/#!topic/chromecast/xo_NDh5CZA8 which says "the Chromecast kernel includes only one driver (asix.ko / USB_NET_AX8817X)" so that's obviously the driver needed for the official chromecast adaptor, and the asix.ko driver is already well supported on Linux. |
Well, that's what I initially thought but there might be some more subtle consideration on that adapter. I used AX8817X dongles and Y OTG cable to charge/ethernet both Chromecast and some Android tablets, all sharing the same well known driver indeed. |
Anyone seen this post from Dom about gadget mode on the PiZero on the forum? |
From Dom's post:
Looks like at some point it was decided to force the port into host mode, gusbcfg.b.force_host_mode = 1 to gusbcfg.b.force_host_mode = 0 Anyone want to compile and test this?
I'm still trying to get one to test with.
Looking forward to some momentum here. |
Based on @popcornmix 's commit comment of "Force host mode to fix incorrect compute module boards" and looking at the compute module schematics it sounds like some (lots?) of people have made modules for the CM to plug into, and I'm guessing they forgot to ground the USB_OTGID pin but they actually wanted the USB to be in host mode, so the driver was modified to always only support host mode (since due to the FIQ stuff it currently doesn't support gadget mode anyway); which saves people having to create another iteration of their CM host PCBs, or always using a custom-compiled kernel. Well that's my best guess anyway ;-) |
The mainline dwc2 driver which does work on the Pi in host mode, has otg mode as well. Maybe worth trying. I haven't got an A or Zero so I can't try it myself. This config change:
which also enables this:
coupled with this overlay
will switch to using the dwc2 driver in host mode. Enabling CONFIG_USB_GADGET seems to be necessary to to enable otg mode in the dwc2 driver.
The next step seems to be to set the dr_mode DT property to otg (see binding doc). The reason we are currently using dwc_otg instead of dwc2, is that it can use a non-maskable fiq interrupt to increase throughput, but lowered throughput probably isn't such an issue in otg mode. https://www.kernel.org/doc/Documentation/devicetree/bindings/usb/dwc2.txt |
@notro thanks for the info! i'm pretty new to working with device trees, but i thought i would give it a shot. i tried it with
the pi would boot, but it won't show up on my OS X machine as a device. |
Do you get anything related to usb in the kernel log: dmesg |
You also need to enable the gadget drivers you want (I have never done this before): http://www.linux-usb.org/gadget/ |
i think the issue is here:
here's the full log from that boot: https://gist.github.com/toddtreece/88965370a4d84877edf7 |
Thanks for the tip about device tree. The upstream driver seems to be working in host mode, but I get a warning about insufficient fifo memory. |
@ED6E0F17 you get the warning in otg mode, right? drivers/usb/dwc2/gadget.c#L3566 int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
{
...
/* Dump fifo information */
dev_dbg(dev, "NonPeriodic TXFIFO size: %d\n",
hsotg->g_np_g_tx_fifo_sz);
dev_dbg(dev, "RXFIFO size: %d\n", hsotg->g_rx_fifo_sz);
for (i = 0; i < MAX_EPS_CHANNELS; i++)
dev_dbg(dev, "Periodic TXFIFO%2d size: %d\n", i,
hsotg->g_tx_fifo_sz[i]); A similar error on rockchip was solved like this: torvalds/linux@ec32bd9 |
just poking in to say im gonna try compiling this too, cuz why not :) |
@ED6E0F17 hey i tried just the default arch/arm/rpi_defconfig in the 4.4.0-rc5 branch and couldnt get the kernel to boot, just rainbowscreen. im compiling for the zero (BCM2708) and saw you're compiling for BCM2709 - but are you using the default defconfig? |
@notro - that looks like the right fix for fifo sizes. The warning occurs on loading the driver, but it is coming from the gadget driver. @ladyada - I am working from a heavily modified config, but from defconfig you will need to enable the Upstream driver, and disable the Downstream driver, and also patch the device tree. DT patch: My rpi-4.4 config: |
I have used otg mode on a B+ with some intrumentation to look at the fifo sizes. The board never comes fully up, but I do get the numbers. @P33M can you have a look?
|
@notro i just realized i was tweaking |
No, we're using bcmrpi_defconfig. |
@notro ok. thanks |
@notro : I don`t know if the gadget fifos should sum to 1024 or 4096, but it is coming up in gadget mode on model A with this device tree : I need to make up a cable before I test further. |
soooo if i were going to desolder the 0ohm in this picture right above the printing "PWR IN" but will it work without a vcc connection? |
For what it's worth, I actually have run a Pi 1 Model B fully stable from USB ports on a computer before. They were USB 3.0 ports designed for charging phones (which is part of the USB 3.0 standard, and they can source 2A at 5V usually, occasionally up to 2.1A), which are becoming more and more common these days. The other problem with running from a PC USB port is that they aren't consistent (just like the USB PSU's). I've seen some that can run a Pi just fine, perfectly stable, 100% load 24/7 for weeks with no issues. I've also seen some that are so strictly compliant with the USB standards (which require devices to draw minimum current until they negotiate higher power consumption) that you can't even hope to boot a Pi powered from them. Most fall somewhere in-between, and start to lose voltage once you get to around 450mA of current draw, but will still let you draw the full 500mA without negotiation (because there are so many USB 'gadgets' that make no data connection and just use the port as a power source). |
i was lucky to have bought a y-cable as i thought this could be usefull .. now it is, i only have to connect both ends when powering it from the PC and 2 seperate wire when powering it from the PSU while connected to the PC |
Tying the grounds together can be dangerous as well. The computer should have protection to handle this, but some don't, and I'm almost certain the Pi doesn't. Unless the devices are electrically grounded to the same ground plane, they will almost certainly have variance in voltage (usually it's millivolts, but sometimes it's more, and that can be problematic). This is why so many standards for communications require a ground line in addition to the data lines. |
As I said this will kill your device and/or PC X_x Edit: Desoldering the 0 ohm could be an idea though. But this would break usb host devices without a powered hub. But a powered hub should be used anyways. So can anyone verify that this 0ohm really connects those 2 vccs together? |
i measured it with two usb cable and there are several guides in the web stating the same, and also which parts you would have to add to make the OTG regulator part working also i want to work headless with it, just the data port as an easy access ssh via network in parallel with mass storage for easy file transfer from my laptop or tablet (if i get the driver working) ... hope the next batch of rpi zeros will be deployed soon and i get a hold of one or two more -.- |
What have you tested? That the lines are correctly separated if you remove the resistor? Assumed you broke the resistor and it works as described: As Host: |
i desoldered the resistor and the data port Vcc wasn't connected anymore with this rsistorsize and pad distance you can easily bridge it back with just some solder if required with OTG regulator i mean the left out parts right above the resistor bridge, if you just google it for a second you get the part list containing everythign you need to make the data port a real OTG port with power limitation and short circuit and overcurrent protection, but you also only get the very limited power supply of around 40mA or so, so you still need to use an active hub rendering the whole circuit a bit useless ... or i miss the technical benefit or this circuit in this particular case |
That sounds nice, if the regulator can detect vcc inputs via usb and then safely disconnects the pis vcc. It would at least work to connect an usb stick (as this is the original intention of otg for smartphones etc). I could not find anything online. It would be highly appreciated if you could post further information on that. It'd be also cool to know what the other unused, exposed pads (on the bottom) do. |
the pads for the connector at the bottom is a jtag interface (J5).. but guess what the site i got my info from is missing or offline, i can't find it anymore XD but the heck i don't find the site anymore for the regulator just found another intersting source looks like exactly the same circuit and also named U13 |
I have managed to make Pi Zero work with Windows as an USB Ethernet gadget: I can ssh into it and then from the Pi I can access the internet. I am having much less luck making this work with Ubuntu 16.04: I can SSH into it alright, but it just does not want to connect to the Internet. Is there a way to make it work with Ubuntu just like it works with Windows? |
...and looks like some of the info is out of date, but there's also https://help.ubuntu.com/community/Internet/ConnectionSharing |
DISREGARD MY POST ABOVE when using the 1.3 version with camera connector you can not disconnect em anymore, they are now connected by a pretty fat line |
@lurch, thank for the suggestions. Here is how I made it work:
After that was done, I was able to ping my router and google servers by IP. |
Anyone knows how to make DNS work in Pi Zero when it is connected to a Ubuntu PC? I can ping any website from the pi, but cannot figure out how to make name resolution work... Update: my firewall (ufw) was blocking routed packets. |
I don't know if it's the "proper" way, but I was able to get name resolution working by finding out the IP address of my router's DNS server (I got this from the "Network Manager -> Connection Information" dialog on Ubuntu, and in my case it's 192.168.2.1) and on the Pi Zero (over the SSH connection) I did |
I've knocked up a simple script to automatically setup internet access for a USB-network-connected PiZero: |
@lurch, once you ssh into the gadget for the first time you can use |
@lurch Have you tested the script. I am unable to get it to run even when i follow all instructions on your blog post and from your script
Am i missing some step? |
I only tested on Ubuntu 14.04, but I can see a couple of small errors in what you've done above:
BTW I'm actually a different Andrew than @gbaman (who wrote the blog article) ;-) |
@hh has your issue been resolved? If so, please close this issue. Thanks. |
@ladyada do you have info on the kernel you used for https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget/serial-gadget Do you know if any patches required for it to work were merged into any branches under https://github.com/raspberrypi/linux ? |
@hh that method described in the Adafruit guide is rather old and long out of date now. Raspbian now ships with all you need. Plus, is now even possible to configure everything needed by editing just config.txt and cmdline.txt on the FAT32 partition using another computer without the Pi ever being booted. Wrote it all up a while back after stumbling across the cmdline.txt parameter - http://blog.gbaman.info/?p=791 |
Beautiful! Thanks @gbaman and everyone else! (I still haven't gotten any pizero's yet) |
hey cool @gbaman thx for the notice! the guide has been updated :) |
Can someone test and tell me the performance of the mass storage capability? According to the Tizen documentation, it does support ISO mounting and I'd like to weigh out my options. Thanks! |
[ Upstream commit 0b8d907 ] Fix wraparound bug which could lead to memory exhaustion when adding an x.x.x.x-255.255.255.255 range to any hash:*net* types. Fixes Netfilter's bugzilla id #1212, reported by Thomas Schwark. Fixes: 48596a8 ("netfilter: ipset: Fix adding an IPv4 range containing more than 2^31 addresses") Signed-off-by: Jozsef Kadlecsik <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
Having a $5 usb gadget that could function as a combination of anything in https://github.com/torvalds/linux/tree/master/drivers/usb/gadget/function would be pretty grand.
Think about your phone, how it works to connect a micro-B to charge and connect to it as a gadget to your computer, then when you connect a micro-A cable you plug mice, keyboard, and thumb drives into your phone.
As a usb host, you can plug a phone into it (just like you do your dekstop or laptop) and flash it. Format a usb drive, or bootstrap embedded devices like intel edison.
As a usb gadet, you can plug it into a computer and have it show up as a usb keyboard, disk, network, and other interesting things. (send some keystrokes to hit F12, and boot to a usb installation disk).
I'm looking to see if we can't get the RPi zero to function as both.
It looks like it may have worked at one point: #881 (comment)
I just wanted to gauge the interest.
The text was updated successfully, but these errors were encountered: