MattDwnr
Posts: 2
Joined: Mon Jan 11, 2016 5:17 pm

Re: HOWTO: Enable USB device mode on Pi Zero

Tue Jan 19, 2016 10:10 am

mikerr wrote:If you use the modular kernels, you can flip between device and host mode easily:

http://pi.gbaman.info/?p=699

just playing with that now.
I'm having trouble getting this set up, I can't get any further than step 4/5?

Code: Select all

pi@raspberrypi:~ $ sudo echo "dwc2" | tee /etc/modules
tee: /etc/modules: Permission denied
dwc2

mattmiller
Posts: 1445
Joined: Thu Feb 05, 2015 11:25 pm

Re: HOWTO: Enable USB device mode on Pi Zero

Tue Jan 19, 2016 5:09 pm

I got this and thought it was just me
Just sudo nano the files instead

Matthew

User avatar
rpdom
Posts: 11800
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: HOWTO: Enable USB device mode on Pi Zero

Tue Jan 19, 2016 6:04 pm

mattmiller wrote:Just sudo nano the files instead
Probably the best option.

Code: Select all

pi@raspberrypi:~ $ sudo echo "dwc2" | tee /etc/modules
tee: /etc/modules: Permission denied
dwc2
Not the best way to do it, even if it did work. The "tee" in this case would (if allowed) overwrite the contents of /etc/modules. It isn't allowed because the sudo is in the wrong place. What you should do (if you want to do it this way) is

Code: Select all

pi@raspberrypi:~ $ echo "dwc2" |sudo tee -a /etc/modules
That will add "dwc2" to the end of /etc/modules

DirkS
Posts: 7709
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: HOWTO: Enable USB device mode on Pi Zero

Tue Jan 19, 2016 6:39 pm

rpdom wrote:That will add "dwc2" to the end of /etc/modules
I had a play with it the other day and AFAICT you actually don't need that entry in /etc/modules.

findx
Posts: 29
Joined: Mon Jul 29, 2013 7:52 pm

Re: HOWTO: Enable USB device mode on Pi Zero

Tue Jan 19, 2016 7:45 pm

Has anyone done a speed benchmark for the virtual Ethernet adapter? I'm curious how much data it can push, but I unfortunately do not have an RPi Zero to test it.

mattmiller
Posts: 1445
Joined: Thu Feb 05, 2015 11:25 pm

Re: HOWTO: Enable USB device mode on Pi Zero

Tue Jan 19, 2016 9:21 pm

Its much faster than WiFi - basically you've got a 480Mbs dedicated network :)

notro
Posts: 686
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: HOWTO: Enable USB device mode on Pi Zero

Tue Jan 19, 2016 9:33 pm

DirkS wrote:
rpdom wrote:That will add "dwc2" to the end of /etc/modules
I had a play with it the other day and AFAICT you actually don't need that entry in /etc/modules.
You're right, dwc2 is automatically loaded by udev, but this happens after /etc/modules is processed so if a gadget module is loaded in /etc/modules, dwc2 must be loaded there to.
More: https://github.com/raspberrypi/linux/pu ... -170253586

BTW I've looked at how we can get a usb console in default Raspian by just editing config.txt: https://github.com/RPi-Distro/repo/issues/17

mattmiller
Posts: 1445
Joined: Thu Feb 05, 2015 11:25 pm

Re: HOWTO: Enable USB device mode on Pi Zero

Tue Jan 19, 2016 9:43 pm

Just done a test
Over Wifi - 7 mins 30 secs to transfer 400MB file
Over USB 2mins

:)
Matthew

DirkS
Posts: 7709
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: HOWTO: Enable USB device mode on Pi Zero

Wed Jan 20, 2016 7:44 am

notro wrote:
DirkS wrote:
rpdom wrote:That will add "dwc2" to the end of /etc/modules
I had a play with it the other day and AFAICT you actually don't need that entry in /etc/modules.
You're right, dwc2 is automatically loaded by udev, but this happens after /etc/modules is processed so if a gadget module is loaded in /etc/modules, dwc2 must be loaded there to.
More: https://github.com/raspberrypi/linux/pu ... -170253586
Ah, yes. It worked for me then because I used modprobe to load the gadget modules.

findx
Posts: 29
Joined: Mon Jul 29, 2013 7:52 pm

Re: HOWTO: Enable USB device mode on Pi Zero

Thu Jan 21, 2016 6:08 am

@mattmiller Thanks for running a test!

notro
Posts: 686
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: HOWTO: Enable USB device mode on Pi Zero

Tue Jan 26, 2016 6:02 pm

I've made a systemd service that loads g_ether with static mac addresses: https://github.com/RPi-Distro/repo/issu ... -175140984

AndyPi
Posts: 82
Joined: Wed Feb 22, 2012 10:24 pm
Location: Gloucestershire,UK

Re: HOWTO: Enable USB device mode on Pi Zero

Sat Feb 06, 2016 12:48 pm

I must be doing something wrong! Got my Pi zero and want to experiment with the usb device mode. I am having trouble with the simple use of rpiboot.

I have compiled and installed the rpiboot program on Ubuntu 14.10 PC. Got a pi zero with empty sd slot, usb micro to USB A cable connected to USB slot.

Plug in Pi0 to USB port on Ubuntu PC and get the

Code: Select all

lsusb
Bus 002 Device 005: ID 0a5c:2763 Broadcom Corp. 

So far so good.

Code: Select all

sudo rpiboot -v
Waiting for BCM2835 ...
Found serial = 0: writing file /usr/share/rpiboot/usbbootcode.bin
libusb_bulk_transfer returned 0
Writing 16674 bytes
libusb_bulk_transfer returned 0
Successful
Waiting for BCM2835 ...
and it just waits...

Looking at the rpiboot code (main.c) it seems that it enumerates with serial=0, successfuly sends the usbbootcode.bin, and reads the response which is OK ie 0.

It then waits for the Pi0 to enumerate serial = 1 before it progresses to stage 2. Mine seems not to re-enumerate.

The lsusb listing disappears after the read response.

Looking at posts here and there it seems that most people are not having problems with this and the pi0 re-enumerates quickly.

I've tried same procedure but with PiB2 (ARCH 4.1.17) as host with same result. I've even used USB port on powered hub to exclude (as far as I can) power issues.

I must be doing something stupid since it appears to be working elsewhere and recently too.

can anyone help?

regards

Andy

gregeric
Posts: 1495
Joined: Mon Nov 28, 2011 10:08 am

Re: HOWTO: Enable USB device mode on Pi Zero

Sat Feb 06, 2016 1:04 pm

I've experienced similar issues. Seem to be solved by using shorter, higher quality cabling. I've a 150mm long micro USB cable which came with some old Nokia phone, that works well.

AndyPi
Posts: 82
Joined: Wed Feb 22, 2012 10:24 pm
Location: Gloucestershire,UK

Re: HOWTO: Enable USB device mode on Pi Zero

Sat Feb 06, 2016 1:13 pm

I have a couple of cables with male micro A / male USB-A. Not sure where they came from, do I need something extra special. As I said the Pi0 seems to enumerate when connected using this cable and am able to send usbbootcode.bin OK and read response, just doesn't want to re-enumerate after the bootcode runs.

Ill try another cable...

AndyPi
Posts: 82
Joined: Wed Feb 22, 2012 10:24 pm
Location: Gloucestershire,UK

Re: HOWTO: Enable USB device mode on Pi Zero

Sat Feb 06, 2016 1:29 pm

Tried three cables. A short one (250mm) from Chromecast kit (I think), one from TomTom kit, one from newish Motorola smart phone. All give same results.

gregeric
Posts: 1495
Joined: Mon Nov 28, 2011 10:08 am

Re: HOWTO: Enable USB device mode on Pi Zero

Sat Feb 06, 2016 1:44 pm

My current working set-up for this is RPi2B with WD PiDrive kit, short Nokia micro-USB cable to Pi0.

It won't do any harm to add a second micro-USB to the Zero's power in port (so long as it's fed from the same hub or port on host Pi), see if that improves it.

AndyPi
Posts: 82
Joined: Wed Feb 22, 2012 10:24 pm
Location: Gloucestershire,UK

Re: HOWTO: Enable USB device mode on Pi Zero

Sat Feb 06, 2016 1:59 pm

Connect to my PiB2, Logik 2A 4 port hub, with power and usb ports

dmesg
  • usb 1-1.4.1: new full-speed USB device number 12 using dwc_otg
    usb 1-1.4.1: New USB device found, idVendor=0a5c, idProduct=2763
    usb 1-1.4.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
    usb 1-1.4.1: Product: BCM2708 Boot
    usb 1-1.4.1: Manufacturer: Broadcom


rpiboot -v
  • Waiting for BCM2835 ...
    Found serial = 0: writing file /usr/share/rpiboot/usbbootcode.bin
    libusb_bulk_transfer returned 0
    Writing 16674 bytes
    libusb_bulk_transfer returned 0
    Successful
    Waiting for BCM2835 ...
dmesg
  • usb 1-1.4.1: USB disconnect, device number 12

Killertechno
Posts: 99
Joined: Wed Jan 02, 2013 8:28 am

Re: HOWTO: Enable USB device mode on Pi Zero

Wed Apr 13, 2016 12:23 pm

DaveB wrote:
2. Modify the bcm2708_common.dtsi file.
You can do this either my applying this patch or by editing arch/arm/boot/dts/bcm2708_common.dtsi and changing the section that reads:

Code: Select all

                usb: usb@7e980000 {
                        compatible = "brcm,bcm2708-usb";
                        reg = <0x7e980000 0x10000>,
                              <0x7e006000 0x1000>;
                        interrupts = <2 0>,
                                     <1 9>;
to read:

Code: Select all

                        compatible = "brcm,bcm2835-usb";
                        reg = <0x7e980000 0x10000>;
                        interrupts = <1 9>;
                        g-np-tx-fifo-size = <32>;
                        g-rx-fifo-size = <256>;
                        g-tx-fifo-size = <256 128 128 64 64 64 32>;


Sorry guys, I'm noob in Kernel.....
So you mean I must select (changing dtsi) if USB port can work as gadget or host (for keyboard or mouse)?
But about other Raspberry versions, how can I set some USB ports for gadget and remaining for keyboard and mouse?
I'm trying to cross-compile Raspberry kernel on Ubuntu: I set gadget mode through "make menuconfig", after boot I can see USB0 port through ifconfig, but nothing happening when I plug USB cable.......
So it's the device-tree to be changed?
Thanks.
Thanks.

hirenvador
Posts: 1
Joined: Wed May 24, 2017 11:34 am

Re: HOWTO: Enable USB device mode on Pi Zero

Wed May 24, 2017 12:14 pm

Hello,
I am trying to enable USB device as Mass storage mode.I am having trouble in that.
My device is detected as unknown USB device(Device description not found).

Any help will be appreciated.

Thanks in advance.
Hiren

Return to “Advanced users”

Who is online

Users browsing this forum: No registered users and 12 guests