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

Closed
hh opened this Issue Dec 3, 2015 · 90 comments

Comments

Projects
None yet
@hh

hh commented Dec 3, 2015

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.

@imbens

This comment has been minimized.

Show comment
Hide comment
@imbens

imbens Dec 4, 2015

That would also allow you to code on the Pi Zero with only a single cable (for power and network) to a PC.

imbens commented Dec 4, 2015

That would also allow you to code on the Pi Zero with only a single cable (for power and network) to a PC.

@harjoc

This comment has been minimized.

Show comment
Hide comment
@harjoc

harjoc Dec 4, 2015

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

harjoc commented Dec 4, 2015

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

@hh

This comment has been minimized.

Show comment
Hide comment
@hh

hh Dec 5, 2015

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.

hh commented Dec 5, 2015

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.

@hh

This comment has been minimized.

Show comment
Hide comment
@hh

hh Dec 5, 2015

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.

hh commented Dec 5, 2015

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.

@hh

This comment has been minimized.

Show comment
Hide comment
@hh

hh Dec 5, 2015

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).

"A device with a micro-A plug inserted becomes an OTG A-device, and a device with a micro-B plug inserted becomes a B-device. The type of plug inserted is detected by the state of the pin ID ."

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:

image

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)

image

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.

image

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

hh commented Dec 5, 2015

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).

"A device with a micro-A plug inserted becomes an OTG A-device, and a device with a micro-B plug inserted becomes a B-device. The type of plug inserted is detected by the state of the pin ID ."

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:

image

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)

image

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.

image

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

@hh hh changed the title from Support for USB Gadget Mode (pi shows up as keyboard, disk, net, camera etc) to RPi zero Support for USB Gadget Mode (pi shows up as keyboard, disk, net, camera etc) Dec 5, 2015

@hh

This comment has been minimized.

Show comment
Hide comment
@hh

hh Dec 5, 2015

@ladyada provides a really nice picture of the port in questions:

RPi zero photo from ladyada

We want to use the USB micro port on the left, not the POWER IN port on the right.

hh commented Dec 5, 2015

@ladyada provides a really nice picture of the port in questions:

RPi zero photo from ladyada

We want to use the USB micro port on the left, not the POWER IN port on the right.

@lurch

This comment has been minimized.

Show comment
Hide comment
@lurch

lurch Dec 14, 2015

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.

lurch commented Dec 14, 2015

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.

@lurch

This comment has been minimized.

Show comment
Hide comment
@lurch

lurch Dec 14, 2015

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 :-)
It looks like the USB_OTGID pin connects from the MicroUSB to the SOC, and also connects to PP40 on the underside of the board.
And the 5V from the "PWR IN" MicroUSB port is connected to the 5V on the "USB" MicroUSB port via the black component with a yellow circle on it - which might be a zero-ohm resistor?

lurch commented Dec 14, 2015

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 :-)
It looks like the USB_OTGID pin connects from the MicroUSB to the SOC, and also connects to PP40 on the underside of the board.
And the 5V from the "PWR IN" MicroUSB port is connected to the 5V on the "USB" MicroUSB port via the black component with a yellow circle on it - which might be a zero-ohm resistor?

@macmpi

This comment has been minimized.

Show comment
Hide comment
@macmpi

macmpi Dec 14, 2015

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
Usure it would require additional driver though: can't tell which chipset it is using.

macmpi commented Dec 14, 2015

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
Usure it would require additional driver though: can't tell which chipset it is using.

@lurch

This comment has been minimized.

Show comment
Hide comment
@lurch

lurch Dec 15, 2015

Any chance we could then use Chromecast Ethernet Adapter

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.

lurch commented Dec 15, 2015

Any chance we could then use Chromecast Ethernet Adapter

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.

@macmpi

This comment has been minimized.

Show comment
Hide comment
@macmpi

macmpi Dec 15, 2015

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.
I then bought the Chromecast Ethernet Adapter for the same, but it does only work with Chromecast for some mysterious reason...(other chipset, wierd cabling? ...)
Would love to see it working with Pi Zero, as it would provide elegant solution for that tiny board.
I hope this effort will bring it closer: I do not intend to hijack the thread more with this.

macmpi commented Dec 15, 2015

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.
I then bought the Chromecast Ethernet Adapter for the same, but it does only work with Chromecast for some mysterious reason...(other chipset, wierd cabling? ...)
Would love to see it working with Pi Zero, as it would provide elegant solution for that tiny board.
I hope this effort will bring it closer: I do not intend to hijack the thread more with this.

@procount

This comment has been minimized.

Show comment
Hide comment
@procount

procount Dec 15, 2015

Anyone seen this post from Dom about gadget mode on the PiZero on the forum?
https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=127003&p=850028&hilit=pi+zero+gadget#p850028
It provides a bit of insight about what is necessary.

procount commented Dec 15, 2015

Anyone seen this post from Dom about gadget mode on the PiZero on the forum?
https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=127003&p=850028&hilit=pi+zero+gadget#p850028
It provides a bit of insight about what is necessary.

@hh

This comment has been minimized.

Show comment
Hide comment
@hh

hh Dec 16, 2015

From Dom's post:

On Pi Zero the OTG line is used and makes the linux driver choose
host/gadget mode. However as most people want host mode, and
non-OTG cables make the Pi Zero boot in gadget mode, we ignore this.

Looks like at some point it was decided to force the port into host mode,
because the original Pi only had a host port. Would it make sense at this
point to just revert this commit globally:

gusbcfg.b.force_host_mode = 1

to

gusbcfg.b.force_host_mode = 0

Anyone want to compile and test this?

Yes, in theory USB OTG and using the Pi Zero as a host or gadget is possible
(just as it is on model A and CM). Not sure if anyone has got that working?

I'm still trying to get one to test with.

However that is not sufficient. The USB driver hasn't been tested in gadget mode
by us for about 3 years, and certainly some of the FIQ stuff doesn't work with gadget
mode. Some some hacking would be needed (starting with disabling the fiq) to make
this work. Volunteers are welcome!

Looking forward to some momentum here.

hh commented Dec 16, 2015

From Dom's post:

On Pi Zero the OTG line is used and makes the linux driver choose
host/gadget mode. However as most people want host mode, and
non-OTG cables make the Pi Zero boot in gadget mode, we ignore this.

Looks like at some point it was decided to force the port into host mode,
because the original Pi only had a host port. Would it make sense at this
point to just revert this commit globally:

gusbcfg.b.force_host_mode = 1

to

gusbcfg.b.force_host_mode = 0

Anyone want to compile and test this?

Yes, in theory USB OTG and using the Pi Zero as a host or gadget is possible
(just as it is on model A and CM). Not sure if anyone has got that working?

I'm still trying to get one to test with.

However that is not sufficient. The USB driver hasn't been tested in gadget mode
by us for about 3 years, and certainly some of the FIQ stuff doesn't work with gadget
mode. Some some hacking would be needed (starting with disabling the fiq) to make
this work. Volunteers are welcome!

Looking forward to some momentum here.

@lurch

This comment has been minimized.

Show comment
Hide comment
@lurch

lurch Dec 16, 2015

Would it make sense at this point to just revert this commit globally:

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 ;-)

lurch commented Dec 16, 2015

Would it make sense at this point to just revert this commit globally:

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 ;-)

@notro

This comment has been minimized.

Show comment
Hide comment
@notro

notro Dec 16, 2015

Contributor

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:

CONFIG_USB_DWC2=y

which also enables this:

CONFIG_USB_DWC2_HOST=y

coupled with this overlay

/dts-v1/;
/plugin/;

/{
    compatible = "brcm,bcm2835";

    fragment@0 {
        target = <&usb>;
        __overlay__ {
            compatible = "brcm,bcm2835-usb";
            reg = <0x7e980000 0x10000>;
            interrupts = <1 9>;
        };
    };
};

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.
From drivers/usb/dwc2/Kconfig:

choice
        bool "DWC2 Mode Selection"
        default USB_DWC2_DUAL_ROLE if (USB && USB_GADGET)
        default USB_DWC2_HOST if (USB && !USB_GADGET)
        default USB_DWC2_PERIPHERAL if (!USB && USB_GADGET)

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
http://lxr.free-electrons.com/source/drivers/usb/dwc2/

Contributor

notro commented Dec 16, 2015

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:

CONFIG_USB_DWC2=y

which also enables this:

CONFIG_USB_DWC2_HOST=y

coupled with this overlay

/dts-v1/;
/plugin/;

/{
    compatible = "brcm,bcm2835";

    fragment@0 {
        target = <&usb>;
        __overlay__ {
            compatible = "brcm,bcm2835-usb";
            reg = <0x7e980000 0x10000>;
            interrupts = <1 9>;
        };
    };
};

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.
From drivers/usb/dwc2/Kconfig:

choice
        bool "DWC2 Mode Selection"
        default USB_DWC2_DUAL_ROLE if (USB && USB_GADGET)
        default USB_DWC2_HOST if (USB && !USB_GADGET)
        default USB_DWC2_PERIPHERAL if (!USB && USB_GADGET)

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
http://lxr.free-electrons.com/source/drivers/usb/dwc2/

@toddtreece

This comment has been minimized.

Show comment
Hide comment
@toddtreece

toddtreece Dec 16, 2015

@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 USB_DWC2_DUAL_ROLE enabled, but i am still not having any luck. i'm not sure what to use for the clocks parameter. this is the overlay i compiled and enabled:

/dts-v1/;
/plugin/;

/{
    compatible = "brcm,bcm2835";

    fragment@0 {
        target = <&usb>;
        #address-cells = <1>;
        #size-cells = <1>;
        __overlay__ {
            compatible = "brcm,bcm2835-usb";
            reg = <0x7e980000 0x10000>;
            interrupts = <1 9>;
            dr_mode = "otg";
            clocks = <&clk_core>;
            clock-names = "otg";
        };
    };
};

the pi would boot, but it won't show up on my OS X machine as a device.

toddtreece commented Dec 16, 2015

@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 USB_DWC2_DUAL_ROLE enabled, but i am still not having any luck. i'm not sure what to use for the clocks parameter. this is the overlay i compiled and enabled:

/dts-v1/;
/plugin/;

/{
    compatible = "brcm,bcm2835";

    fragment@0 {
        target = <&usb>;
        #address-cells = <1>;
        #size-cells = <1>;
        __overlay__ {
            compatible = "brcm,bcm2835-usb";
            reg = <0x7e980000 0x10000>;
            interrupts = <1 9>;
            dr_mode = "otg";
            clocks = <&clk_core>;
            clock-names = "otg";
        };
    };
};

the pi would boot, but it won't show up on my OS X machine as a device.

@notro

This comment has been minimized.

Show comment
Hide comment
@notro

notro Dec 16, 2015

Contributor

Do you get anything related to usb in the kernel log: dmesg

Contributor

notro commented Dec 16, 2015

Do you get anything related to usb in the kernel log: dmesg

@notro

This comment has been minimized.

Show comment
Hide comment
@notro

notro Dec 16, 2015

Contributor

You also need to enable the gadget drivers you want (I have never done this before):
http://lxr.free-electrons.com/source/drivers/usb/gadget/Kconfig (also try enabling the debug options)

http://www.linux-usb.org/gadget/
https://www.kernel.org/doc/Documentation/usb/ (gadget_*.txt)

Contributor

notro commented Dec 16, 2015

You also need to enable the gadget drivers you want (I have never done this before):
http://lxr.free-electrons.com/source/drivers/usb/gadget/Kconfig (also try enabling the debug options)

http://www.linux-usb.org/gadget/
https://www.kernel.org/doc/Documentation/usb/ (gadget_*.txt)

@toddtreece

This comment has been minimized.

Show comment
Hide comment
@toddtreece

toddtreece Dec 16, 2015

i think the issue is here:

Dec 16 20:27:16 raspberrypi kernel: [    2.022050] dwc2 20980000.usb: Mode Mismatch Interrupt: currently in Device mode

here's the full log from that boot: https://gist.github.com/toddtreece/88965370a4d84877edf7

toddtreece commented Dec 16, 2015

i think the issue is here:

Dec 16 20:27:16 raspberrypi kernel: [    2.022050] dwc2 20980000.usb: Mode Mismatch Interrupt: currently in Device mode

here's the full log from that boot: https://gist.github.com/toddtreece/88965370a4d84877edf7

@ED6E0F17

This comment has been minimized.

Show comment
Hide comment
@ED6E0F17

ED6E0F17 Dec 17, 2015

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.

dmesg.txt

ED6E0F17 commented Dec 17, 2015

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.

dmesg.txt

@notro

This comment has been minimized.

Show comment
Hide comment
@notro

notro Dec 17, 2015

Contributor

@ED6E0F17 you get the warning in otg mode, right?
Enabling DEBUG will print the fifo sizes used. @P33M can probably tell if they're valid or not.

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

Contributor

notro commented Dec 17, 2015

@ED6E0F17 you get the warning in otg mode, right?
Enabling DEBUG will print the fifo sizes used. @P33M can probably tell if they're valid or not.

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

@ladyada

This comment has been minimized.

Show comment
Hide comment
@ladyada

ladyada Dec 17, 2015

just poking in to say im gonna try compiling this too, cuz why not :)
im working off of https://github.com/raspberrypi/linux/tree/rpi-4.4.y, will edit/post with whatever i find!

ladyada commented Dec 17, 2015

just poking in to say im gonna try compiling this too, cuz why not :)
im working off of https://github.com/raspberrypi/linux/tree/rpi-4.4.y, will edit/post with whatever i find!

@ladyada

This comment has been minimized.

Show comment
Hide comment
@ladyada

ladyada Dec 18, 2015

@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?

ladyada commented Dec 18, 2015

@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?

@ED6E0F17

This comment has been minimized.

Show comment
Hide comment
@ED6E0F17

ED6E0F17 Dec 18, 2015

@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:
patch.txt

My rpi-4.4 config:
config.txt

ED6E0F17 commented Dec 18, 2015

@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:
patch.txt

My rpi-4.4 config:
config.txt

@notro

This comment has been minimized.

Show comment
Hide comment
@notro

notro Dec 18, 2015

Contributor

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?

[    0.000000] Linux version 4.4.0-rc5+ (pi@raspi2) (gcc version 4.8.3 20140106 (prerelease) (crosstool-NG linaro-1.13.1-4.8-2014.01 - Linaro GCC 2013.11) ) #3 PREEMPT Fri Dec 18 20:36:34 CET 2015

[    2.359432] dwc2 20980000.usb: NonPeriodic TXFIFO size: 1024
[    2.365268] dwc2 20980000.usb: RXFIFO size: 2048
[    2.370075] dwc2 20980000.usb: Periodic TXFIFO 0 size: 0
[    2.375530] dwc2 20980000.usb: Periodic TXFIFO 1 size: 256
[    2.381208] dwc2 20980000.usb: Periodic TXFIFO 2 size: 256
[    2.386891] dwc2 20980000.usb: Periodic TXFIFO 3 size: 256
[    2.392518] dwc2 20980000.usb: Periodic TXFIFO 4 size: 256
[    2.398183] dwc2 20980000.usb: Periodic TXFIFO 5 size: 768
[    2.403813] dwc2 20980000.usb: Periodic TXFIFO 6 size: 768
[    2.409482] dwc2 20980000.usb: Periodic TXFIFO 7 size: 768
[    2.419758] dwc2 20980000.usb: Periodic TXFIFO 8 size: 768
[    2.430063] dwc2 20980000.usb: Periodic TXFIFO 9 size: 0
[    2.440137] dwc2 20980000.usb: Periodic TXFIFO10 size: 0
[    2.450151] dwc2 20980000.usb: Periodic TXFIFO11 size: 0
[    2.460074] dwc2 20980000.usb: Periodic TXFIFO12 size: 0
[    2.469798] dwc2 20980000.usb: Periodic TXFIFO13 size: 0
[    2.479572] dwc2 20980000.usb: Periodic TXFIFO14 size: 0
[    2.489276] dwc2 20980000.usb: Periodic TXFIFO15 size: 0
[    2.536754] dwc2 20980000.usb: resetting core
[    2.545373] dwc2 20980000.usb: reset successful

(the 4080 number is hsotg->fifo_mem)
[    2.554109] dwc2 20980000.usb: EPs: 8, dedicated fifos, 4080 entries in SPRAM
[    2.565613] dwc2 20980000.usb: GRXFSIZ=0x00001000, GNPTXFSIZ=0x00201000

[    2.576598] dwc2_hsotg_init_fifo(): hsotg->fifo_mem=4080 (0xff0)

(addr = hsotg->g_rx_fifo_sz + hsotg->g_np_g_tx_fifo_sz == 2048 + 1024 == 3072)

[    2.586691] addr=3072 (0xc00), hsotg->g_tx_fifo_sz[1]=256
[    2.596327] addr=3328 (0xd00), hsotg->g_tx_fifo_sz[2]=256
[    2.605928] addr=3584 (0xe00), hsotg->g_tx_fifo_sz[3]=256

[    2.615489] ------------[ cut here ]------------
[    2.624272] WARNING: CPU: 0 PID: 1 at drivers/usb/dwc2/gadget.c:215 dwc2_hsotg_init_fifo+0x1a8/0x23c()
[    2.637788] insufficient fifo memory
[    2.641291] Modules linked in:
[    2.652782] CPU: 0 PID: 1 Comm: swapper Not tainted 4.4.0-rc5+ #3
[    2.663120] Hardware name: BCM2708

[    2.733156] [<c045bea4>] (dwc2_hsotg_init_fifo) from [<c045bfe4>] (dwc2_hsotg_init+0xac/0x110)
[    2.746312] [<c045bfe4>] (dwc2_hsotg_init) from [<c045f91c>] (dwc2_gadget_init+0x3c0/0x890)
[    2.759225] [<c045f91c>] (dwc2_gadget_init) from [<c0451604>] (dwc2_driver_probe+0x254/0x2e4)
[    2.772314] [<c0451604>] (dwc2_driver_probe) from [<c03b3008>] (platform_drv_probe+0x44/0x7c)

[    2.944490] ---[ end trace bf843f4c4ca2ef38 ]---

[    2.954026] addr=3840 (0xf00), hsotg->g_tx_fifo_sz[4]=256
[    2.964436] addr=4096 (0x1000), hsotg->g_tx_fifo_sz[5]=768
[    2.974923] addr=4864 (0x1300), hsotg->g_tx_fifo_sz[6]=768
[    2.985261] addr=5632 (0x1600), hsotg->g_tx_fifo_sz[7]=768
[    2.995696] addr=6400 (0x1900), hsotg->g_tx_fifo_sz[8]=768
Contributor

notro commented Dec 18, 2015

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?

[    0.000000] Linux version 4.4.0-rc5+ (pi@raspi2) (gcc version 4.8.3 20140106 (prerelease) (crosstool-NG linaro-1.13.1-4.8-2014.01 - Linaro GCC 2013.11) ) #3 PREEMPT Fri Dec 18 20:36:34 CET 2015

[    2.359432] dwc2 20980000.usb: NonPeriodic TXFIFO size: 1024
[    2.365268] dwc2 20980000.usb: RXFIFO size: 2048
[    2.370075] dwc2 20980000.usb: Periodic TXFIFO 0 size: 0
[    2.375530] dwc2 20980000.usb: Periodic TXFIFO 1 size: 256
[    2.381208] dwc2 20980000.usb: Periodic TXFIFO 2 size: 256
[    2.386891] dwc2 20980000.usb: Periodic TXFIFO 3 size: 256
[    2.392518] dwc2 20980000.usb: Periodic TXFIFO 4 size: 256
[    2.398183] dwc2 20980000.usb: Periodic TXFIFO 5 size: 768
[    2.403813] dwc2 20980000.usb: Periodic TXFIFO 6 size: 768
[    2.409482] dwc2 20980000.usb: Periodic TXFIFO 7 size: 768
[    2.419758] dwc2 20980000.usb: Periodic TXFIFO 8 size: 768
[    2.430063] dwc2 20980000.usb: Periodic TXFIFO 9 size: 0
[    2.440137] dwc2 20980000.usb: Periodic TXFIFO10 size: 0
[    2.450151] dwc2 20980000.usb: Periodic TXFIFO11 size: 0
[    2.460074] dwc2 20980000.usb: Periodic TXFIFO12 size: 0
[    2.469798] dwc2 20980000.usb: Periodic TXFIFO13 size: 0
[    2.479572] dwc2 20980000.usb: Periodic TXFIFO14 size: 0
[    2.489276] dwc2 20980000.usb: Periodic TXFIFO15 size: 0
[    2.536754] dwc2 20980000.usb: resetting core
[    2.545373] dwc2 20980000.usb: reset successful

(the 4080 number is hsotg->fifo_mem)
[    2.554109] dwc2 20980000.usb: EPs: 8, dedicated fifos, 4080 entries in SPRAM
[    2.565613] dwc2 20980000.usb: GRXFSIZ=0x00001000, GNPTXFSIZ=0x00201000

[    2.576598] dwc2_hsotg_init_fifo(): hsotg->fifo_mem=4080 (0xff0)

(addr = hsotg->g_rx_fifo_sz + hsotg->g_np_g_tx_fifo_sz == 2048 + 1024 == 3072)

[    2.586691] addr=3072 (0xc00), hsotg->g_tx_fifo_sz[1]=256
[    2.596327] addr=3328 (0xd00), hsotg->g_tx_fifo_sz[2]=256
[    2.605928] addr=3584 (0xe00), hsotg->g_tx_fifo_sz[3]=256

[    2.615489] ------------[ cut here ]------------
[    2.624272] WARNING: CPU: 0 PID: 1 at drivers/usb/dwc2/gadget.c:215 dwc2_hsotg_init_fifo+0x1a8/0x23c()
[    2.637788] insufficient fifo memory
[    2.641291] Modules linked in:
[    2.652782] CPU: 0 PID: 1 Comm: swapper Not tainted 4.4.0-rc5+ #3
[    2.663120] Hardware name: BCM2708

[    2.733156] [<c045bea4>] (dwc2_hsotg_init_fifo) from [<c045bfe4>] (dwc2_hsotg_init+0xac/0x110)
[    2.746312] [<c045bfe4>] (dwc2_hsotg_init) from [<c045f91c>] (dwc2_gadget_init+0x3c0/0x890)
[    2.759225] [<c045f91c>] (dwc2_gadget_init) from [<c0451604>] (dwc2_driver_probe+0x254/0x2e4)
[    2.772314] [<c0451604>] (dwc2_driver_probe) from [<c03b3008>] (platform_drv_probe+0x44/0x7c)

[    2.944490] ---[ end trace bf843f4c4ca2ef38 ]---

[    2.954026] addr=3840 (0xf00), hsotg->g_tx_fifo_sz[4]=256
[    2.964436] addr=4096 (0x1000), hsotg->g_tx_fifo_sz[5]=768
[    2.974923] addr=4864 (0x1300), hsotg->g_tx_fifo_sz[6]=768
[    2.985261] addr=5632 (0x1600), hsotg->g_tx_fifo_sz[7]=768
[    2.995696] addr=6400 (0x1900), hsotg->g_tx_fifo_sz[8]=768
@toddtreece

This comment has been minimized.

Show comment
Hide comment
@toddtreece

toddtreece Dec 18, 2015

@notro i just realized i was tweaking bcmrpi_defconfig to test dwc2. should i be using bcm2835_defconfig?

toddtreece commented Dec 18, 2015

@notro i just realized i was tweaking bcmrpi_defconfig to test dwc2. should i be using bcm2835_defconfig?

@notro

This comment has been minimized.

Show comment
Hide comment
@notro

notro Dec 18, 2015

Contributor

No, we're using bcmrpi_defconfig.

Contributor

notro commented Dec 18, 2015

No, we're using bcmrpi_defconfig.

@toddtreece

This comment has been minimized.

Show comment
Hide comment
@toddtreece

toddtreece commented Dec 18, 2015

@notro ok. thanks

@ED6E0F17

This comment has been minimized.

Show comment
Hide comment
@ED6E0F17

ED6E0F17 Dec 19, 2015

@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 :
dtpatch.txt

I need to make up a cable before I test further.

ED6E0F17 commented Dec 19, 2015

@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 :
dtpatch.txt

I need to make up a cable before I test further.

@notro

This comment has been minimized.

Show comment
Hide comment
@notro

notro Dec 20, 2015

Contributor

I don`t know if the gadget fifos should sum to 1024 or 4096

4080 it seeems.

The driver gets the number of entries here:

static int dwc2_hsotg_hw_cfg(struct dwc2_hsotg *hsotg)
{
    cfg = dwc2_readl(hsotg->regs + GHWCFG3);
    hsotg->fifo_mem = (cfg >> GHWCFG3_DFIFO_DEPTH_SHIFT);

    dev_info(hsotg->dev, "EPs: %d, %s fifos, %d entries in SPRAM\n",
         hsotg->num_of_eps,
         hsotg->dedicated_fifos ? "dedicated" : "shared",
         hsotg->fifo_mem);

which is 4080:

dwc2 20980000.usb: EPs: 8, dedicated fifos, 4080 entries in SPRAM

Set up hw fifos:

static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg)
{

    /* set RX/NPTX FIFO sizes */
    dwc2_writel(hsotg->g_rx_fifo_sz, hsotg->regs + GRXFSIZ);
    dwc2_writel((hsotg->g_rx_fifo_sz << FIFOSIZE_STARTADDR_SHIFT) |
        (hsotg->g_np_g_tx_fifo_sz << FIFOSIZE_DEPTH_SHIFT),
        hsotg->regs + GNPTXFSIZ);

    /* start at the end of the GNPTXFSIZ, rounded up */
    addr = hsotg->g_rx_fifo_sz + hsotg->g_np_g_tx_fifo_sz;

    /*
     * Configure fifos sizes from provided configuration and assign
     * them to endpoints dynamically according to maxpacket size value of
     * given endpoint.
     */
    for (ep = 1; ep < MAX_EPS_CHANNELS; ep++) {
        if (!hsotg->g_tx_fifo_sz[ep])
            continue;
        val = addr;
        val |= hsotg->g_tx_fifo_sz[ep] << FIFOSIZE_DEPTH_SHIFT;
        WARN_ONCE(addr + hsotg->g_tx_fifo_sz[ep] > hsotg->fifo_mem,
              "insufficient fifo memory");
        addr += hsotg->g_tx_fifo_sz[ep];

        dwc2_writel(val, hsotg->regs + DPTXFSIZN(ep));
    }

fifo_mem (4080) is used for the overflow check.

I found these numbers in the BCM2835 datasheet:

Total Data FIFO RAM Depth 4096

Largest Rx Data FIFO Depth 4096

Largest Non-periodic Tx Data FIFO Depth 4096

Largest Device Mode IN Endpoint Tx FIFOn Depth (n = 0 to 15) when using dynamic FIFO sizing
0=32
1..5=512
6,7=768
Contributor

notro commented Dec 20, 2015

I don`t know if the gadget fifos should sum to 1024 or 4096

4080 it seeems.

The driver gets the number of entries here:

static int dwc2_hsotg_hw_cfg(struct dwc2_hsotg *hsotg)
{
    cfg = dwc2_readl(hsotg->regs + GHWCFG3);
    hsotg->fifo_mem = (cfg >> GHWCFG3_DFIFO_DEPTH_SHIFT);

    dev_info(hsotg->dev, "EPs: %d, %s fifos, %d entries in SPRAM\n",
         hsotg->num_of_eps,
         hsotg->dedicated_fifos ? "dedicated" : "shared",
         hsotg->fifo_mem);

which is 4080:

dwc2 20980000.usb: EPs: 8, dedicated fifos, 4080 entries in SPRAM

Set up hw fifos:

static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg)
{

    /* set RX/NPTX FIFO sizes */
    dwc2_writel(hsotg->g_rx_fifo_sz, hsotg->regs + GRXFSIZ);
    dwc2_writel((hsotg->g_rx_fifo_sz << FIFOSIZE_STARTADDR_SHIFT) |
        (hsotg->g_np_g_tx_fifo_sz << FIFOSIZE_DEPTH_SHIFT),
        hsotg->regs + GNPTXFSIZ);

    /* start at the end of the GNPTXFSIZ, rounded up */
    addr = hsotg->g_rx_fifo_sz + hsotg->g_np_g_tx_fifo_sz;

    /*
     * Configure fifos sizes from provided configuration and assign
     * them to endpoints dynamically according to maxpacket size value of
     * given endpoint.
     */
    for (ep = 1; ep < MAX_EPS_CHANNELS; ep++) {
        if (!hsotg->g_tx_fifo_sz[ep])
            continue;
        val = addr;
        val |= hsotg->g_tx_fifo_sz[ep] << FIFOSIZE_DEPTH_SHIFT;
        WARN_ONCE(addr + hsotg->g_tx_fifo_sz[ep] > hsotg->fifo_mem,
              "insufficient fifo memory");
        addr += hsotg->g_tx_fifo_sz[ep];

        dwc2_writel(val, hsotg->regs + DPTXFSIZN(ep));
    }

fifo_mem (4080) is used for the overflow check.

I found these numbers in the BCM2835 datasheet:

Total Data FIFO RAM Depth 4096

Largest Rx Data FIFO Depth 4096

Largest Non-periodic Tx Data FIFO Depth 4096

Largest Device Mode IN Endpoint Tx FIFOn Depth (n = 0 to 15) when using dynamic FIFO sizing
0=32
1..5=512
6,7=768
@ED6E0F17

This comment has been minimized.

Show comment
Hide comment
@ED6E0F17

ED6E0F17 Dec 20, 2015

With debug logging enabled I get two obvious errors:
"cannot get otg clock", which is something that should be set in the device tree; and
"dwc2_hsotg_complete_setup: failed -104"

log highlights:

debuglog.txt

ED6E0F17 commented Dec 20, 2015

With debug logging enabled I get two obvious errors:
"cannot get otg clock", which is something that should be set in the device tree; and
"dwc2_hsotg_complete_setup: failed -104"

log highlights:

debuglog.txt

@Dave-0

This comment has been minimized.

Show comment
Hide comment
@Dave-0

Dave-0 Dec 20, 2015

I've got this to work on a Pi Zero using ED6E0F17's device tree patch and selecting gadget only mode. I tried duel mode first but couldn't get that to work.

My kernel config is below:

config.txt

I'm using the serial gadget and I can run a terminal session over the connection. I've not done extensive testing but it seems stable. I'll post again when I've done more testing.

Dave-0 commented Dec 20, 2015

I've got this to work on a Pi Zero using ED6E0F17's device tree patch and selecting gadget only mode. I tried duel mode first but couldn't get that to work.

My kernel config is below:

config.txt

I'm using the serial gadget and I can run a terminal session over the connection. I've not done extensive testing but it seems stable. I'll post again when I've done more testing.

@Dave-0

This comment has been minimized.

Show comment
Hide comment
@Dave-0

Dave-0 Dec 21, 2015

One thing to add: I changed config.txt for my testing. This seems to be important because with the default raspbian one it hangs at "Uncompressing Linux... done, booting the kernel.".

config.txt

Dave-0 commented Dec 21, 2015

One thing to add: I changed config.txt for my testing. This seems to be important because with the default raspbian one it hangs at "Uncompressing Linux... done, booting the kernel.".

config.txt

@Dave-0

This comment has been minimized.

Show comment
Hide comment
@Dave-0

Dave-0 Dec 21, 2015

I've tried this with dual mode again and got it to work this time, I must have made a mistake somewhere the first time. It switches between host and gadget mode correctly depending on the cable type.

Dave-0 commented Dec 21, 2015

I've tried this with dual mode again and got it to work this time, I must have made a mistake somewhere the first time. It switches between host and gadget mode correctly depending on the cable type.

@martinbrook

This comment has been minimized.

Show comment
Hide comment
@martinbrook

martinbrook Dec 21, 2015

Great, could you confirm which kernel branch you are using and which dt patch, I see two in the tread.

martinbrook commented Dec 21, 2015

Great, could you confirm which kernel branch you are using and which dt patch, I see two in the tread.

@Dave-0

This comment has been minimized.

Show comment
Hide comment
@Dave-0

Dave-0 Dec 21, 2015

@martinbrook:
I'm using the 4.4.y branch and the dtpatch is this one.

Dave-0 commented Dec 21, 2015

@martinbrook:
I'm using the 4.4.y branch and the dtpatch is this one.

@ladyada

This comment has been minimized.

Show comment
Hide comment
@ladyada

ladyada Dec 24, 2015

@ED6E0F17 @notro heya thanks for the help! turns out i was missing the mkknlimg step >.<
got everything working and have a kernel with gaddet modules and a tutorial here
https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget/
i'll update the kernel-o-matic and make a set of .deb files for easier install some time later this week

merry xmas!

ladyada commented Dec 24, 2015

@ED6E0F17 @notro heya thanks for the help! turns out i was missing the mkknlimg step >.<
got everything working and have a kernel with gaddet modules and a tutorial here
https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget/
i'll update the kernel-o-matic and make a set of .deb files for easier install some time later this week

merry xmas!

@gbaman

This comment has been minimized.

Show comment
Hide comment
@gbaman

gbaman Dec 25, 2015

@ED6E0F17 @notro Can also confirm have also been able to get this working, @Dave-0's post over on the forums was a great help too.

@ladyada Looks like I wasn't the only one working over Christmas Eve on this, my write is here.

Now over course, the big question is can we get this working with normal USB within the same kernels, without having to break it? Something like being able to enable/disable the mode from the cmdline.txt file? (not my idea, @ghollingworth's idea).
That would then mean, users could enable it from another computer by editing the fat32 partition, opening up a huge range of possibilities!

gbaman commented Dec 25, 2015

@ED6E0F17 @notro Can also confirm have also been able to get this working, @Dave-0's post over on the forums was a great help too.

@ladyada Looks like I wasn't the only one working over Christmas Eve on this, my write is here.

Now over course, the big question is can we get this working with normal USB within the same kernels, without having to break it? Something like being able to enable/disable the mode from the cmdline.txt file? (not my idea, @ghollingworth's idea).
That would then mean, users could enable it from another computer by editing the fat32 partition, opening up a huge range of possibilities!

@notro

This comment has been minimized.

Show comment
Hide comment
@notro

notro Dec 25, 2015

Contributor

I have a Zero now and got it working with g_serial. I'm trying g_multi and do get a usb drive, but the serial and ethernet device isn't supported by windows and since I got Windows 8, it won't install the unsigned Documentation/usb/linux-cdc-acm.inf and Documentation/usb/linux.inf "drivers".
I need to reboot and disable this restraint, but have too many things running on my machine to just do a reboot now.

Regarding getting it to work with normal kernels, this isn't a problem, dwc2 and dwc_otg can coexist. We can use a Device Tree overlay to enable dwc2 instead of dwc_otg:

/dts-v1/;
/plugin/;

/{
    compatible = "brcm,bcm2708";

    fragment@0 {
        target = <&usb>;
        #address-cells = <1>;
        #size-cells = <1>;
        __overlay__ {
            compatible = "brcm,bcm2835-usb";
            reg = <0x7e980000 0x10000>;
            interrupts = <1 9>;
            dr_mode = "otg";
            g-np-tx-fifo-size = <32>;
            g-rx-fifo-size = <256>;
            g-tx-fifo-size = <256 128 128 64 64 64 32>;
        };
    };
};

dwc2 can probably be built as a module as well to save memory for those that don't use it.

But maybe an even better idea than an overlay is to give the Zero a dtb of it's own and make dwc2 the default.
Currently it uses the B+ dtb:

~$ sudo vcdbg log msg
001289.085: Loading 'bcm2708-rpi-b-plus.dtb' from SD card

I haven't tried dwc2 in host mode on Zero yet, but it did work on B+. A DT overlay can be made to enable dwc_otg for those that need the extra performance.

Adding to this, Raspian could get a systemd service that when it detects that usb is in device/peripheral mode, loads the g_serial module and fires up a console on it.

This way we can just download a regular raspian image put it on the Zero, connect it to a computer and get a usb serial console.
And if a keyboard is connected instead, the dwc2 driver acts in host mode as normal and no module is loaded (I wonder if hotswapping between device/host mode is supported by dwc2).

On top of this, raspi-config could have an option to enable loading of g_multi module instead and provide an usb drive that has the necessary signed inf files (Windows) to get serial and ethernet working at the same time.

Contributor

notro commented Dec 25, 2015

I have a Zero now and got it working with g_serial. I'm trying g_multi and do get a usb drive, but the serial and ethernet device isn't supported by windows and since I got Windows 8, it won't install the unsigned Documentation/usb/linux-cdc-acm.inf and Documentation/usb/linux.inf "drivers".
I need to reboot and disable this restraint, but have too many things running on my machine to just do a reboot now.

Regarding getting it to work with normal kernels, this isn't a problem, dwc2 and dwc_otg can coexist. We can use a Device Tree overlay to enable dwc2 instead of dwc_otg:

/dts-v1/;
/plugin/;

/{
    compatible = "brcm,bcm2708";

    fragment@0 {
        target = <&usb>;
        #address-cells = <1>;
        #size-cells = <1>;
        __overlay__ {
            compatible = "brcm,bcm2835-usb";
            reg = <0x7e980000 0x10000>;
            interrupts = <1 9>;
            dr_mode = "otg";
            g-np-tx-fifo-size = <32>;
            g-rx-fifo-size = <256>;
            g-tx-fifo-size = <256 128 128 64 64 64 32>;
        };
    };
};

dwc2 can probably be built as a module as well to save memory for those that don't use it.

But maybe an even better idea than an overlay is to give the Zero a dtb of it's own and make dwc2 the default.
Currently it uses the B+ dtb:

~$ sudo vcdbg log msg
001289.085: Loading 'bcm2708-rpi-b-plus.dtb' from SD card

I haven't tried dwc2 in host mode on Zero yet, but it did work on B+. A DT overlay can be made to enable dwc_otg for those that need the extra performance.

Adding to this, Raspian could get a systemd service that when it detects that usb is in device/peripheral mode, loads the g_serial module and fires up a console on it.

This way we can just download a regular raspian image put it on the Zero, connect it to a computer and get a usb serial console.
And if a keyboard is connected instead, the dwc2 driver acts in host mode as normal and no module is loaded (I wonder if hotswapping between device/host mode is supported by dwc2).

On top of this, raspi-config could have an option to enable loading of g_multi module instead and provide an usb drive that has the necessary signed inf files (Windows) to get serial and ethernet working at the same time.

@pelwell

This comment has been minimized.

Show comment
Hide comment
@pelwell

pelwell Jan 7, 2016

Contributor

Yes, that card has been problematic for some people. I have one on my desk (the packaging says TS32GUSDI1E) that so far has been OK, but I have a Verbatim card that fails for me. I'm not saying these are bad cards, but there is something about them that the sdhost driver doesn't like/understand.

Contributor

pelwell commented Jan 7, 2016

Yes, that card has been problematic for some people. I have one on my desk (the packaging says TS32GUSDI1E) that so far has been OK, but I have a Verbatim card that fails for me. I'm not saying these are bad cards, but there is something about them that the sdhost driver doesn't like/understand.

@procount

This comment has been minimized.

Show comment
Hide comment
@procount

procount Jan 7, 2016

I tried using Gadget mode for the first time today. My first attempt used Meltwater's Pi-Kitchen to install it with NOOBS, but I got the same SD card corruption as Nico. I think that version used LadyAda's build.
AFAIK my card is an Integral 16GB. In Ubuntu disk utility it shows up as a 'Generic STORAGE DEVICE'. The markings on it indicate it is SDHC IU1 (where the 1 is inside the U)
So I tried again using this build https://dl.dropboxusercontent.com/u/1122948/temp/PiOTG-Test/PiZeroCombined.tar.gz (from Gbaman?) and it worked. I only loaded the g_ether module, but I got ssh and vnc working.with Ubutu14.04 running in Vmware on a Win7x64 laptop. (I couldn't install the correct g_ether driver under win7x64 for some reason)
Another problem I had though was that the Ubuntu usb0 device kept losing its ip address. In a separate terminal I had to type 'sudo ifconfig 192.168.4.1 netmask 255.255.255.0 up' and then the vnc and ssh connections would spring into life again from where they left off. This repeatedly happened at a rate of less than 1 minute intervals.

procount commented Jan 7, 2016

I tried using Gadget mode for the first time today. My first attempt used Meltwater's Pi-Kitchen to install it with NOOBS, but I got the same SD card corruption as Nico. I think that version used LadyAda's build.
AFAIK my card is an Integral 16GB. In Ubuntu disk utility it shows up as a 'Generic STORAGE DEVICE'. The markings on it indicate it is SDHC IU1 (where the 1 is inside the U)
So I tried again using this build https://dl.dropboxusercontent.com/u/1122948/temp/PiOTG-Test/PiZeroCombined.tar.gz (from Gbaman?) and it worked. I only loaded the g_ether module, but I got ssh and vnc working.with Ubutu14.04 running in Vmware on a Win7x64 laptop. (I couldn't install the correct g_ether driver under win7x64 for some reason)
Another problem I had though was that the Ubuntu usb0 device kept losing its ip address. In a separate terminal I had to type 'sudo ifconfig 192.168.4.1 netmask 255.255.255.0 up' and then the vnc and ssh connections would spring into life again from where they left off. This repeatedly happened at a rate of less than 1 minute intervals.

@ED6E0F17

This comment has been minimized.

Show comment
Hide comment
@ED6E0F17

ED6E0F17 Jan 7, 2016

@procount - I had the same issue running Linux 4.3 on Ubuntu; an upgrade to 4.4 fixed it.

ED6E0F17 commented Jan 7, 2016

@procount - I had the same issue running Linux 4.3 on Ubuntu; an upgrade to 4.4 fixed it.

@NicoHood

This comment has been minimized.

Show comment
Hide comment
@NicoHood

NicoHood Jan 7, 2016

I tried again with @gbaman s tutorial. It should be noted that you need to add this after step 6 of its tutorial. Otherwise it will overwrite the setting again. it now seems to work and i can start playing with this.

Edit:
Works great, I can just use all stuff with my pi. Just open the network options of ubuntu and select "shared network" under ip v4. I used nmap to find the device and now i can ssh into it. only usb is connected. Its also powered via usb. Awesome!

nmap -T4 -F 10.42.0.255/24
ssh pi@10.42.0.x

# or if avahi-daemon is installed:
ssh pi@raspberrypi.local

If i copy a file to my pi via ssh (scp) it transmits at 6mb/s which is totally fine for me.

Another question:
If i power the pi zero via extern power supply (like you are used to), does it hurt if the laptop also powers the pi via the OTG usb port? Is there any protection between those two inputs? Otherwise I have to power my pi only via usb otg (meaning i cannot simply replug a keyboard on the fly).

NicoHood commented Jan 7, 2016

I tried again with @gbaman s tutorial. It should be noted that you need to add this after step 6 of its tutorial. Otherwise it will overwrite the setting again. it now seems to work and i can start playing with this.

Edit:
Works great, I can just use all stuff with my pi. Just open the network options of ubuntu and select "shared network" under ip v4. I used nmap to find the device and now i can ssh into it. only usb is connected. Its also powered via usb. Awesome!

nmap -T4 -F 10.42.0.255/24
ssh pi@10.42.0.x

# or if avahi-daemon is installed:
ssh pi@raspberrypi.local

If i copy a file to my pi via ssh (scp) it transmits at 6mb/s which is totally fine for me.

Another question:
If i power the pi zero via extern power supply (like you are used to), does it hurt if the laptop also powers the pi via the OTG usb port? Is there any protection between those two inputs? Otherwise I have to power my pi only via usb otg (meaning i cannot simply replug a keyboard on the fly).

@procount

This comment has been minimized.

Show comment
Hide comment
@procount

procount Jan 7, 2016

@ED6E0F17 - But the Rapbian kernel I downloaded for Gadget mode is already 4.4.0-rc6=#14 and Ubuntu on my PC is 3.3. I also got Nico's SD card errors again after a reboot with this kernel, so it's not totally solved. But after another reboot it worked fine. So it's not SDcard corruption, but an intermittent access problem.

procount commented Jan 7, 2016

@ED6E0F17 - But the Rapbian kernel I downloaded for Gadget mode is already 4.4.0-rc6=#14 and Ubuntu on my PC is 3.3. I also got Nico's SD card errors again after a reboot with this kernel, so it's not totally solved. But after another reboot it worked fine. So it's not SDcard corruption, but an intermittent access problem.

@NicoHood

This comment has been minimized.

Show comment
Hide comment
@NicoHood

NicoHood Jan 7, 2016

Have you addeed the patch dtoverlay=mmc after applying the kernel? Because this will overwrite config.txt. I had to rewrite it again. Now it works fine for some time now. I'd really like to see this (without the sd card patch XD) in the official release.

NicoHood commented Jan 7, 2016

Have you addeed the patch dtoverlay=mmc after applying the kernel? Because this will overwrite config.txt. I had to rewrite it again. Now it works fine for some time now. I'd really like to see this (without the sd card patch XD) in the official release.

@procount

This comment has been minimized.

Show comment
Hide comment
@procount

procount Jan 7, 2016

No, but I have now, so we'll see how it goes.

procount commented Jan 7, 2016

No, but I have now, so we'll see how it goes.

@ED6E0F17

This comment has been minimized.

Show comment
Hide comment
@ED6E0F17

ED6E0F17 Jan 8, 2016

I have no issues with the RPI kernel, but I get errors on the host end. (x86-64 Ubuntu 14.04.3 with linux 4.4-rc8) :

[224599.070811] cdc_ether 1-1:1.0 usb0: register 'cdc_ether' at usb-0000:00:1d.7-1, CDC Ethernet Device, 8e:f6:a8:3e:1e:9f
[224599.072720] cdc_acm 1-1:1.2: ttyACM0: USB ACM device
[224599.216681] cdc_ether 1-1:1.0 usb0: kevent 12 may have been dropped
[224599.218452] cdc_ether 1-1:1.0 usb0: kevent 12 may have been dropped

Before upgrading from linux 4.3.0 the dropped events continued after the physical connection, and the network connection was unstable.

ED6E0F17 commented Jan 8, 2016

I have no issues with the RPI kernel, but I get errors on the host end. (x86-64 Ubuntu 14.04.3 with linux 4.4-rc8) :

[224599.070811] cdc_ether 1-1:1.0 usb0: register 'cdc_ether' at usb-0000:00:1d.7-1, CDC Ethernet Device, 8e:f6:a8:3e:1e:9f
[224599.072720] cdc_acm 1-1:1.2: ttyACM0: USB ACM device
[224599.216681] cdc_ether 1-1:1.0 usb0: kevent 12 may have been dropped
[224599.218452] cdc_ether 1-1:1.0 usb0: kevent 12 may have been dropped

Before upgrading from linux 4.3.0 the dropped events continued after the physical connection, and the network connection was unstable.

@procount

This comment has been minimized.

Show comment
Hide comment
@procount

procount Jan 21, 2016

Pleased to report I fixed my loss of IP address in Ununtu. Despite setting an ip address with ifconfig, dhclient insisted on trying to get another one, and when it didn't get a dhcp response it reset the ip address. Setting a static ip address in interfaces and rebooting fixed it.

procount commented Jan 21, 2016

Pleased to report I fixed my loss of IP address in Ununtu. Despite setting an ip address with ifconfig, dhclient insisted on trying to get another one, and when it didn't get a dhcp response it reset the ip address. Setting a static ip address in interfaces and rebooting fixed it.

@NicoHood

This comment has been minimized.

Show comment
Hide comment
@NicoHood

NicoHood Mar 30, 2016

Is there any information about how the power rails are wired on the PCB?

Because connecting the PI to the usb host only via usb (device mode) is not a good idea, as you might want to unplug the device (but will lose the power then). So you want to self power the raspi. The question is, if the current power circuit protects against that. Connecting both VCCs would be a bad idea.

If not it might be a good idea for @ladyada or @nseidle to sell Micro USB Data Only cables where the 5V VCC is left out (very simple) or broken out as 2nd cable.

With an additional power in selector cable (like on an arduino board) you could connect the 2nd power cable and an external power supply. Like on an Arduino the highest voltage would be used. But the first solution would be more simple (and cheap) for mass production.

Other solutions would be to create a pcb with a 2nd micro usb port that filters vcc as i described it (and adds an external power supply). However it would make more sense to have a simple cable without vcc.

So does anyone has an idea about this?

NicoHood commented Mar 30, 2016

Is there any information about how the power rails are wired on the PCB?

Because connecting the PI to the usb host only via usb (device mode) is not a good idea, as you might want to unplug the device (but will lose the power then). So you want to self power the raspi. The question is, if the current power circuit protects against that. Connecting both VCCs would be a bad idea.

If not it might be a good idea for @ladyada or @nseidle to sell Micro USB Data Only cables where the 5V VCC is left out (very simple) or broken out as 2nd cable.

With an additional power in selector cable (like on an arduino board) you could connect the 2nd power cable and an external power supply. Like on an Arduino the highest voltage would be used. But the first solution would be more simple (and cheap) for mass production.

Other solutions would be to create a pcb with a 2nd micro usb port that filters vcc as i described it (and adds an external power supply). However it would make more sense to have a simple cable without vcc.

So does anyone has an idea about this?

@mindforger

This comment has been minimized.

Show comment
Hide comment
@mindforger

mindforger Apr 11, 2016

as far as i have looked into the board and tested around, both ports vcc are shorted by a 0Ohm resistor but there are pads for a circuitry that may help and i have read about this circuitry already somewhere in the web but can't remember where or what

what exactly would be "bad" when i power the pi zero from a powerbank or a powerplug and then connect it directly to the computer USB ? And by the way i am missing on how to"configure" the g_multi mode ... it's only stated "you can" but not "how" .. sorry i am a noob to this still :)

mindforger commented Apr 11, 2016

as far as i have looked into the board and tested around, both ports vcc are shorted by a 0Ohm resistor but there are pads for a circuitry that may help and i have read about this circuitry already somewhere in the web but can't remember where or what

what exactly would be "bad" when i power the pi zero from a powerbank or a powerplug and then connect it directly to the computer USB ? And by the way i am missing on how to"configure" the g_multi mode ... it's only stated "you can" but not "how" .. sorry i am a noob to this still :)

@NicoHood

This comment has been minimized.

Show comment
Hide comment
@NicoHood

NicoHood Apr 11, 2016

Why it is dangerous? Point 5:
http://electronics.stackexchange.com/questions/67149/what-are-the-most-common-ways-to-fry-an-arduino

Because they can have different potential. Or they always have. And this way you destroy either the pi, the pc or the pi PSU. Or all together. It may take some time to see an actual effect, but I did that once. NEVER connect Vccs together.

Thatshwy this question is essential when using the USB Device mode. Currentlz we can only use it, when powered via the PC HOST and not attached to normal PSU. But connecting to the PC does not give us enough current to run the pi stable. At least we should not do it like that.

NicoHood commented Apr 11, 2016

Why it is dangerous? Point 5:
http://electronics.stackexchange.com/questions/67149/what-are-the-most-common-ways-to-fry-an-arduino

Because they can have different potential. Or they always have. And this way you destroy either the pi, the pc or the pi PSU. Or all together. It may take some time to see an actual effect, but I did that once. NEVER connect Vccs together.

Thatshwy this question is essential when using the USB Device mode. Currentlz we can only use it, when powered via the PC HOST and not attached to normal PSU. But connecting to the PC does not give us enough current to run the pi stable. At least we should not do it like that.

@mindforger

This comment has been minimized.

Show comment
Hide comment
@mindforger

mindforger Apr 11, 2016

soooo if i were going to desolder the 0ohm in this picture right above the printing "PWR IN"
https://learn.adafruit.com/assets/28756
the data port should not have an vcc connection, only ground and should be safe?

but will it work without a vcc connection?

mindforger commented Apr 11, 2016

soooo if i were going to desolder the 0ohm in this picture right above the printing "PWR IN"
https://learn.adafruit.com/assets/28756
the data port should not have an vcc connection, only ground and should be safe?

but will it work without a vcc connection?

@Ferroin

This comment has been minimized.

Show comment
Hide comment
@Ferroin

Ferroin Apr 11, 2016

Contributor

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).

Contributor

Ferroin commented Apr 11, 2016

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).

@mindforger

This comment has been minimized.

Show comment
Hide comment
@mindforger

mindforger Apr 11, 2016

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

mindforger commented Apr 11, 2016

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

@Ferroin

This comment has been minimized.

Show comment
Hide comment
@Ferroin

Ferroin Apr 11, 2016

Contributor

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.

Contributor

Ferroin commented Apr 11, 2016

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.

@NicoHood

This comment has been minimized.

Show comment
Hide comment
@NicoHood

NicoHood Apr 11, 2016

As I said this will kill your device and/or PC X_x
Also Y Cables are bad practice in general too.

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?

NicoHood commented Apr 11, 2016

As I said this will kill your device and/or PC X_x
Also Y Cables are bad practice in general too.

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?

@mindforger

This comment has been minimized.

Show comment
Hide comment
@mindforger

mindforger Apr 11, 2016

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 -.-

mindforger commented Apr 11, 2016

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 -.-

@NicoHood

This comment has been minimized.

Show comment
Hide comment
@NicoHood

NicoHood Apr 11, 2016

What have you tested? That the lines are correctly separated if you remove the resistor?
I don't get the OTG question. OTG is a 5th pin that is grounded by the OTG cable and has nothing to do with the power supply.

Assumed you broke the resistor and it works as described:
As Device:
It is self powered

As Host:
Use an active hub.

NicoHood commented Apr 11, 2016

What have you tested? That the lines are correctly separated if you remove the resistor?
I don't get the OTG question. OTG is a 5th pin that is grounded by the OTG cable and has nothing to do with the power supply.

Assumed you broke the resistor and it works as described:
As Device:
It is self powered

As Host:
Use an active hub.

@mindforger

This comment has been minimized.

Show comment
Hide comment
@mindforger

mindforger Apr 12, 2016

i desoldered the resistor and the data port Vcc wasn't connected anymore
in fact i did not find any part (so far) of the board that was connected to the USB data port's Vcc
it looks to me that it is completely isolated then

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

mindforger commented Apr 12, 2016

i desoldered the resistor and the data port Vcc wasn't connected anymore
in fact i did not find any part (so far) of the board that was connected to the USB data port's Vcc
it looks to me that it is completely isolated then

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

@NicoHood

This comment has been minimized.

Show comment
Hide comment
@NicoHood

NicoHood Apr 12, 2016

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.

NicoHood commented Apr 12, 2016

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.

@mindforger

This comment has been minimized.

Show comment
Hide comment
@mindforger

mindforger Apr 12, 2016

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
the other pads are several testing points
https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=89522
https://docs.google.com/spreadsheets/d/15kHcow993d_2CS6rZxQMq0wAWlgWNaHU_go1Hyf08ck/edit#gid=0

but the heck i don't find the site anymore for the regulator

just found another intersting source
http://hackaday.com/2015/04/06/more-power-for-raspberry-pi-usb-ports/

looks like exactly the same circuit and also named U13

mindforger commented Apr 12, 2016

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
the other pads are several testing points
https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=89522
https://docs.google.com/spreadsheets/d/15kHcow993d_2CS6rZxQMq0wAWlgWNaHU_go1Hyf08ck/edit#gid=0

but the heck i don't find the site anymore for the regulator

just found another intersting source
http://hackaday.com/2015/04/06/more-power-for-raspberry-pi-usb-ports/

looks like exactly the same circuit and also named U13

@fantom-x

This comment has been minimized.

Show comment
Hide comment
@fantom-x

fantom-x Jun 6, 2016

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?

fantom-x commented Jun 6, 2016

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?

@lurch

This comment has been minimized.

Show comment
Hide comment
@lurch

This comment has been minimized.

Show comment
Hide comment
@lurch

lurch Jun 6, 2016

...and looks like some of the info is out of date, but there's also https://help.ubuntu.com/community/Internet/ConnectionSharing

lurch commented Jun 6, 2016

...and looks like some of the info is out of date, but there's also https://help.ubuntu.com/community/Internet/ConnectionSharing

@mindforger

This comment has been minimized.

Show comment
Hide comment
@mindforger

mindforger Jun 6, 2016

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

mindforger commented Jun 6, 2016

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

@fantom-x

This comment has been minimized.

Show comment
Hide comment
@fantom-x

fantom-x Jun 6, 2016

@lurch, thank for the suggestions. Here is how I made it work:

  1. NetworkManager in Ubuntu creates a new connection "Wired Connection 1" or another number: on IPv4 tab chose "Link-Local Only". Once a connection is established, the pi can be accessed by ssh pi@raspberry.local
  2. Use ifconfig to get the address of this new connection 169.254.X.X; in my case it was 169.254.202.41
  3. On the host run echo 1 > /proc/sys/net/ipv4/ip_forward
  4. On the host run iptables -t nat -A POSTROUTING -s 169.254.0.0/16 -o br0 -j MASQUERADE. Replace br0 with your interface name.
  5. SSH into pi and add a default route: route add default gw 169.254.202.41 usb0. The gateway is the IP address of the host link (see item 2 above)

After that was done, I was able to ping my router and google servers by IP.

fantom-x commented Jun 6, 2016

@lurch, thank for the suggestions. Here is how I made it work:

  1. NetworkManager in Ubuntu creates a new connection "Wired Connection 1" or another number: on IPv4 tab chose "Link-Local Only". Once a connection is established, the pi can be accessed by ssh pi@raspberry.local
  2. Use ifconfig to get the address of this new connection 169.254.X.X; in my case it was 169.254.202.41
  3. On the host run echo 1 > /proc/sys/net/ipv4/ip_forward
  4. On the host run iptables -t nat -A POSTROUTING -s 169.254.0.0/16 -o br0 -j MASQUERADE. Replace br0 with your interface name.
  5. SSH into pi and add a default route: route add default gw 169.254.202.41 usb0. The gateway is the IP address of the host link (see item 2 above)

After that was done, I was able to ping my router and google servers by IP.

@fantom-x

This comment has been minimized.

Show comment
Hide comment
@fantom-x

fantom-x Jun 7, 2016

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.

fantom-x commented Jun 7, 2016

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.

@lurch

This comment has been minimized.

Show comment
Hide comment
@lurch

lurch Jun 7, 2016

Anyone knows how to make DNS work in Pi Zero when it is connected to a Ubuntu PC?

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
echo "nameserver 192.168.2.1" | sudo resolvconf -a usb0
and I can then successfully run apt-get update etc. :-)

lurch commented Jun 7, 2016

Anyone knows how to make DNS work in Pi Zero when it is connected to a Ubuntu PC?

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
echo "nameserver 192.168.2.1" | sudo resolvconf -a usb0
and I can then successfully run apt-get update etc. :-)

@lurch

This comment has been minimized.

Show comment
Hide comment
@lurch

lurch Jun 8, 2016

I've knocked up a simple script to automatically setup internet access for a USB-network-connected PiZero:
https://gist.github.com/lurch/ad939bbce48064cffdb215268eac9f62

lurch commented Jun 8, 2016

I've knocked up a simple script to automatically setup internet access for a USB-network-connected PiZero:
https://gist.github.com/lurch/ad939bbce48064cffdb215268eac9f62

@fantom-x

This comment has been minimized.

Show comment
Hide comment
@fantom-x

fantom-x Jun 8, 2016

@lurch, once you ssh into the gadget for the first time you can use arp -n to get your host's IP address. In this case your script could become a one liner...

fantom-x commented Jun 8, 2016

@lurch, once you ssh into the gadget for the first time you can use arp -n to get your host's IP address. In this case your script could become a one liner...

@hex007

This comment has been minimized.

Show comment
Hide comment
@hex007

hex007 Jun 22, 2016

@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

  1. Flashed Jesse lite

  2. Edited 2 files in boot partition

  3. from ubuntu 15.10 x64:

    a. Changed the connection to link-local only
    b. Interface is called: enx96fcc47029dc (strange name)
    c. Pi connected. Can ssh successfully
    d. echo 1 > /proc/sys/net/ipv4/ip_forward
    e. sudo iptables -t nat -A POSTROUTING -s 169.254.0.0/16 -o br0 -j MASQUERADE
    f. SSH into Pi

  4. From pi:

    a.sudo route add default gw 169.254.9.197 usb0; echo \"nameserver 192.168.0.1\" | sudo resolvconf -a usb0
    b. ping 8.8..8.8 ---> nothing, all packets dropped

Am i missing some step?

hex007 commented Jun 22, 2016

@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

  1. Flashed Jesse lite

  2. Edited 2 files in boot partition

  3. from ubuntu 15.10 x64:

    a. Changed the connection to link-local only
    b. Interface is called: enx96fcc47029dc (strange name)
    c. Pi connected. Can ssh successfully
    d. echo 1 > /proc/sys/net/ipv4/ip_forward
    e. sudo iptables -t nat -A POSTROUTING -s 169.254.0.0/16 -o br0 -j MASQUERADE
    f. SSH into Pi

  4. From pi:

    a.sudo route add default gw 169.254.9.197 usb0; echo \"nameserver 192.168.0.1\" | sudo resolvconf -a usb0
    b. ping 8.8..8.8 ---> nothing, all packets dropped

Am i missing some step?

@lurch

This comment has been minimized.

Show comment
Hide comment
@lurch

lurch Jun 22, 2016

I only tested on Ubuntu 14.04, but I can see a couple of small errors in what you've done above:

  1. I assume you did step 3d as the root user?
  2. Your iptables command should probably be using eth0 or wlan0 rather than br0
  3. In step 4a make sure you're giving the IP address of the PC-side of the USB-network connection and not the IP address of the Pi-side of the USB-network connection
  4. If running the commands directly on the Pi itself, you don't want to escape the quotes, so change it to echo "nameserver 192.168.0.1" | sudo resolvconf -a usb0

BTW I'm actually a different Andrew than @gbaman (who wrote the blog article) ;-)
As you'll see in one of my comments on http://blog.gbaman.info/?p=791 I recommend configuring the Zero to assign static MAC addresses to both sides of the USB-network device, so that you don't have to keep reconfiguring the PC-side network device every time you reboot the Zero. My script makes no 'permanent' changes, so you need to run it each time you reboot your PC or Pi Zero.

lurch commented Jun 22, 2016

I only tested on Ubuntu 14.04, but I can see a couple of small errors in what you've done above:

  1. I assume you did step 3d as the root user?
  2. Your iptables command should probably be using eth0 or wlan0 rather than br0
  3. In step 4a make sure you're giving the IP address of the PC-side of the USB-network connection and not the IP address of the Pi-side of the USB-network connection
  4. If running the commands directly on the Pi itself, you don't want to escape the quotes, so change it to echo "nameserver 192.168.0.1" | sudo resolvconf -a usb0

BTW I'm actually a different Andrew than @gbaman (who wrote the blog article) ;-)
As you'll see in one of my comments on http://blog.gbaman.info/?p=791 I recommend configuring the Zero to assign static MAC addresses to both sides of the USB-network device, so that you don't have to keep reconfiguring the PC-side network device every time you reboot the Zero. My script makes no 'permanent' changes, so you need to run it each time you reboot your PC or Pi Zero.

@Ruffio

This comment has been minimized.

Show comment
Hide comment
@Ruffio

Ruffio Aug 17, 2016

@hh has your issue been resolved? If so, please close this issue. Thanks.

Ruffio commented Aug 17, 2016

@hh has your issue been resolved? If so, please close this issue. Thanks.

@hh

This comment has been minimized.

Show comment
Hide comment
@hh

hh Aug 17, 2016

@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 commented Aug 17, 2016

@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 ?

@gbaman

This comment has been minimized.

Show comment
Hide comment
@gbaman

gbaman Aug 17, 2016

@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

gbaman commented Aug 17, 2016

@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

@hh

This comment has been minimized.

Show comment
Hide comment
@hh

hh Aug 17, 2016

Beautiful! Thanks @gbaman and everyone else! (I still haven't gotten any pizero's yet)

hh commented Aug 17, 2016

Beautiful! Thanks @gbaman and everyone else! (I still haven't gotten any pizero's yet)

@hh hh closed this Aug 17, 2016

@ladyada

This comment has been minimized.

Show comment
Hide comment
@ladyada

ladyada Aug 22, 2016

hey cool @gbaman thx for the notice! the guide has been updated :)
https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget
(serial gadget still requires a tiny bit of commands to kick off the getty service)

ladyada commented Aug 22, 2016

hey cool @gbaman thx for the notice! the guide has been updated :)
https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget
(serial gadget still requires a tiny bit of commands to kick off the getty service)

@techhelper1

This comment has been minimized.

Show comment
Hide comment
@techhelper1

techhelper1 Sep 5, 2016

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!

techhelper1 commented Sep 5, 2016

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment