naxxfish
Posts: 10
Joined: Thu Oct 25, 2012 9:43 pm

USB Gadget mode in Stretch

Sun Jan 14, 2018 4:42 pm

Hi

I'm following this blog post:
http://isticktoit.net/?p=1383

With a Pi Zero (non W) - using Stretch (downloaded today 2017-11-29-raspbian-stretch-lite) - and I'm getting nowhere. It's not detected by a Mac on the USB as anything (not even the wrong thing), nor a Windows 10 machine.

If I do lsmod once the Pi has booted, I can see that libcomposite has loaded. I'm not sure why this isn't working....

Any ideas?
Thanks

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

Re: USB Gadget mode in Stretch

Sun Jan 14, 2018 10:10 pm

The reference blog on this subject is considered to be

https://blog.gbaman.info/?p=791

(replacing Jessie with Stretch)

If you follow those instructions and get it right then that sorts out the Pi end

naxxfish
Posts: 10
Joined: Thu Oct 25, 2012 9:43 pm

Re: USB Gadget mode in Stretch

Sun Jan 14, 2018 10:25 pm

I'll give it a go - although I'd quite like to have multiple endpoints in the end, which I don't believe that method will allow. But I'll see if it gets me anywhere

naxxfish
Posts: 10
Joined: Thu Oct 25, 2012 9:43 pm

Re: USB Gadget mode in Stretch

Sun Jan 14, 2018 10:37 pm

Nope - followed that to the letter from a completely clean image, on a Zero V1.2 - serial connection connected and USB power and USB to a computer - nothing at all.

lsmod says:

Code: Select all

Module                  Size  Used by
cfg80211              527100  0
rfkill                 21373  2 cfg80211
snd_bcm2835            23131  0
snd_pcm                97825  1 snd_bcm2835
snd_timer              22706  1 snd_pcm
snd                    68784  3 snd_timer,snd_bcm2835,snd_pcm
bcm2835_gpiomem         3791  0
fixed                   3029  0
uio_pdrv_genirq         3718  0
uio                    10166  1 uio_pdrv_genirq
usb_f_ecm               7416  1
g_ether                 5037  0
usb_f_rndis            16991  2 g_ether
u_ether                13511  3 usb_f_ecm,g_ether,usb_f_rndis
libcomposite           49651  3 usb_f_ecm,g_ether,usb_f_rndis
dwc2                  122113  0
udc_core               40452  5 usb_f_ecm,dwc2,u_ether,usb_f_rndis,libcomposite
ip_tables              12512  0
x_tables               20921  1 ip_tables
ipv6                  384613  16
I'm at a loss...

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

Re: USB Gadget mode in Stretch

Sun Jan 14, 2018 10:53 pm

your lsmod looks the same as mine so it does seem that you've configured it right.

If that is true, then the only common thing left is your USB lead.

Is it possible its just one of those power only leads that don't have data connections?


(I got caught out once - the short ones that came with a USB battery didn't have any data connections!)

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

Re: USB Gadget mode in Stretch

Sun Jan 14, 2018 10:54 pm

And of course your Pi is also a common factor but you;d have to be unlucky for the USB to be broken

naxxfish
Posts: 10
Joined: Thu Oct 25, 2012 9:43 pm

Re: USB Gadget mode in Stretch

Sun Jan 14, 2018 11:03 pm

Tried a different cable that I know works - nothing. Also the port on the Pi Zero itself works - as I've hooked up keyboard to it previously via an OTG adaptor.

Code: Select all

pi@raspberrypi:~$ uname -a
Linux raspberrypi 4.9.59+ #1047 Sun Oct 29 11:47:10 GMT 2017 armv6l GNU/Linux

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

Re: USB Gadget mode in Stretch

Mon Jan 15, 2018 7:04 am

Well, this has defeated me as well :(

naxxfish
Posts: 10
Joined: Thu Oct 25, 2012 9:43 pm

Re: USB Gadget mode in Stretch

Mon Jan 15, 2018 5:57 pm

Has anyone else got a working image for a Zero 1.2 that I could try flashing to a SD card? Just to check to see if it's hardware based..

It's either hardware or something in my particular version of stretch that has gone awry..

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

Re: USB Gadget mode in Stretch

Mon Jan 15, 2018 9:07 pm

I've found a v1.2 - I'll do a fresh install on it - make sure it works with my Win10 then seed it as a torrent - prob be tomorrow but I'll start on it now

User avatar
HawaiianPi
Posts: 3669
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: USB Gadget mode in Stretch

Mon Jan 15, 2018 9:10 pm

naxxfish wrote:
Mon Jan 15, 2018 5:57 pm
Has anyone else got a working image for a Zero 1.2 that I could try flashing to a SD card? Just to check to see if it's hardware based..

It's either hardware or something in my particular version of stretch that has gone awry..
Did you verify the SHA-256 hash sum of your Raspbian download?
Did you use Etcher to extract, write and validate the image?

I have used USB Gadget mode on my Pi Zero v1.3 with the full Raspbian Stretch Desktop OS. SSH, VNC and ICS are all working for me.

I just set it up again with a fresh SD card on my Pi Zero v1.3 and my Windows 10 Ultrabook. I think my GF has a Pi Zero v1.2 that I could test it on. Problem is, we just moved, so she probably doesn't know where it is at the moment. I used the full Raspbian Stretch with Desktop image, so I could setup VNC for you as well. If you'd like I could hunt for the 1.2 Zero and test it, then squish the image down as much as possible for you.

However, from what you have posted so far, it seems like the problem might be external, with the computer you connected to not installing the proper driver. ¯\_(ツ)_/¯

In the meantime, here are the 3 files I used for USB Gadget mode (empty ssh, edited cmdline.txt and config.txt).
USB Gadget Mode.zip
(1.39 KiB) Downloaded 286 times
Last edited by HawaiianPi on Tue Jan 16, 2018 1:38 am, edited 1 time in total.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

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

Re: USB Gadget mode in Stretch

Mon Jan 15, 2018 9:51 pm

Classic!
Made new image - tested - shrunk it down to fit on any 8GB card

Put it into PC to create img - can't get w32diskimager to run! :(

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

Re: USB Gadget mode in Stretch

Mon Jan 15, 2018 9:54 pm

took card out and in again - I can now run the imageing program - so moving forwards again :)

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

Re: USB Gadget mode in Stretch

Mon Jan 15, 2018 10:13 pm

2 steps back again
I'd forgotton that win32diskimager images whole disk (16GB in this case) and not just the valid partitions :(

User avatar
HawaiianPi
Posts: 3669
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: USB Gadget mode in Stretch

Tue Jan 16, 2018 3:03 am

Would you like the image fully dist-upgraded and pre-configured for VNC access as well?

I have one now setup in its default boot state. The .zip file size is about 1.6GB and you'll need an 8GB card to write the image.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

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

Re: USB Gadget mode in Stretch

Tue Jan 16, 2018 10:03 am

I leave it to @hawaiianPi as they've beaten me to getting an 8G image :)

User avatar
HawaiianPi
Posts: 3669
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: USB Gadget mode in Stretch

Tue Jan 16, 2018 12:27 pm

For some reason my local file and torrent server is not showing up on the network. :cry:

So instead of serving the images up as a torrents, I uploaded them to my web host.

EDIT: Updated image to 2018-11-13 Raspbian Lite
Raspbian Stretch Lite 2018-11-13 Pi0(W) USB Gadget mode
SHA-256: 32ca25d28122cea2fd40d3f8d8c0e0ac2efd88fb5f569d0976828f42a604c2ed

Hope this helps someone.
Last edited by HawaiianPi on Sun Jan 06, 2019 8:54 am, edited 3 times in total.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

jsfour
Posts: 1
Joined: Tue Jan 30, 2018 5:57 am

Re: USB Gadget mode in Stretch

Tue Jan 30, 2018 6:01 am

For anyone having issues with the device not showing up in Stretch, make sure that you try the other USB port on your pi zero.

For some reason, one of my ports worked but the other one did not.

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

Re: USB Gadget mode in Stretch

Tue Jan 30, 2018 11:28 am

The port nearest the end is just for power

The one in the middle is the only working usb port

Made same mistake myself when PiZero came out :)

Al.Z.Heimer
Posts: 3
Joined: Sat Feb 03, 2018 7:00 am

Re: USB Gadget mode in Stretch

Sat Feb 03, 2018 7:45 am

Hi folks,

I've been struggling for days to let RPiZ play HID (USB keyboard). Without success.
My image is stretch now:
Linux raspberrypi 4.9.79+ #1086 Wed Jan 31 17:31:04 GMT 2018 armv6l GNU/Linux
And the device is "Raspberry Pi Zero W Rev 1.1" according to /proc/device-tree/model

From elinux.org I learned it is a Q1 2017 Revision (9000c1) based on the output of cat /proc/cpuinfo

While most info found in the net is based on older kernel versions and hardware the most promising approaches seem to be

https://www.rmedgar.com/blog/using-rpi- ... efinition
http://isticktoit.net/?p=1383


Both failed for me. Both rely on configFS. And at a certain point of the procedure echo (done as root) results in "write error: Device or resource busy"

One fails writing to
/sys/kernel/config/usb_gadget/mykeyboard/functions/hid.usb0/report_desc
The other fails writing to
/sys/kernel/config/usb_gadget/isticktoit/functions/hid.usb0/report_length

What takes me wonder in this discussion you had here is the addition of
modules-load=dwc2,g_ether
In cmdline.txt. That particular file would not be touched by the other approaches.

Would you advice to add modules-load=dwc2,g_hid for my purpose?
Output of lsmod follows

Thanks for any support.
Desperately
Me

Module Size Used by
fuse 94600 3
rfcomm 37905 6
cmac 3134 1
bnep 11949 2
hci_uart 21222 1
btbcm 7917 1 hci_uart
bluetooth 376017 29 hci_uart,bnep,btbcm,rfcomm
usb_f_hid 11655 2
spidev 7034 0
enc28j60 20402 0
brcmfmac 269955 0
brcmutil 9911 1 brcmfmac
snd_bcm2835 23131 1
cfg80211 527260 1 brcmfmac
snd_pcm 97889 1 snd_bcm2835
snd_timer 22706 1 snd_pcm
rfkill 21373 6 bluetooth,cfg80211
snd 68784 5 snd_timer,snd_bcm2835,snd_pcm
spi_bcm2835 7424 0
bcm2835_gpiomem 3791 0
fixed 3029 0
uio_pdrv_genirq 3718 0
uio 10166 1 uio_pdrv_genirq
libcomposite 49907 10 usb_f_hid
dwc2 122113 0
udc_core 40452 3 dwc2,libcomposite,usb_f_hid
i2c_dev 6642 0
ip_tables 12512 0
x_tables 20921 1 ip_tables
ipv6 385136 18

User avatar
thagrol
Posts: 1331
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: USB Gadget mode in Stretch

Sat Feb 03, 2018 3:02 pm

Al.Z.Heimer wrote:
Sat Feb 03, 2018 7:45 am
Hi folks,

I've been struggling for days to let RPiZ play HID (USB keyboard). Without success.
I've had USB HID working using this method: http://isticktoit.net/?p=1383 (see https://github.com/thagrol/pwdgen for my code)
What takes me wonder in this discussion you had here is the addition of
modules-load=dwc2,g_ether
In cmdline.txt. That particular file would not be touched by the other approaches.
Just my 2 cents worth, but I've alway had better results with the default cmdline.tx, dtoverlay=dwc2 in config.txt, and loading the desired g_* module from /etc/rc.local
Note to self: don't feed the trolls

If I've asked you a question, please answer it. I'm unlikely to be able to help without that information.

Al.Z.Heimer
Posts: 3
Joined: Sat Feb 03, 2018 7:00 am

Re: USB Gadget mode in Stretch

Tue Feb 13, 2018 10:32 am

Hi folks,
I had (some) success. Using a freshly set up stretch image and using ISTICKTOIT finally it works -- somehow. The idea was to have Rpi0 powered by PC, then after autostart of application PC would receive the Keyboard Scan Codes.
However it seems the raspberry needs to be powered up first and then only needs to be connected to PC-USB. Otherwise the PC would report something like "unknown USB device".
Could someone imagine a better approach to accomplish the "just plug in RPi0 to PC" scenario?
-Al

User avatar
thagrol
Posts: 1331
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: USB Gadget mode in Stretch

Tue Feb 13, 2018 12:07 pm

Al.Z.Heimer wrote:
Tue Feb 13, 2018 10:32 am
Hi folks,
I had (some) success. Using a freshly set up stretch image and using ISTICKTOIT finally it works -- somehow. The idea was to have Rpi0 powered by PC, then after autostart of application PC would receive the Keyboard Scan Codes.
However it seems the raspberry needs to be powered up first and then only needs to be connected to PC-USB. Otherwise the PC would report something like "unknown USB device".
Could someone imagine a better approach to accomplish the "just plug in RPi0 to PC" scenario?
-Al
That error is why I load the gadget modules as detailed in my last post.
Note to self: don't feed the trolls

If I've asked you a question, please answer it. I'm unlikely to be able to help without that information.

Al.Z.Heimer
Posts: 3
Joined: Sat Feb 03, 2018 7:00 am

Re: USB Gadget mode in Stretch

Wed Feb 14, 2018 7:45 am

thargot, this is precisely what I did when following the ISTICKTOIT instructions, right? Nevertheless I get that "unfair" behaviour. Thanks for considering.

User avatar
thagrol
Posts: 1331
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: USB Gadget mode in Stretch

Wed Feb 14, 2018 12:47 pm

Al.Z.Heimer wrote:
Wed Feb 14, 2018 7:45 am
thargot, this is precisely what I did when following the ISTICKTOIT instructions, right? Nevertheless I get that "unfair" behaviour. Thanks for considering.
Just re-checked the zero I have running as a USB HID device. It seems I didn't quite follow those instructions. I'm doing the gadget setup from a shell script called by /etc/rc.local. That script includes "modprobe libcomposite" and I've not added libcomposite to /etc/modules or /boot/cmdline.txt

So, here's what I suggest:
  • Remove any reference to libcomposite from /etc/modules and /boot/cmdline.txt
  • Add

    Code: Select all

    modprobe libcomposite
    to /etc/rc.local making sure it's above "exit 0" and above any code you have in place to setup your USB gadget.
  • With your pi connected only by the USB host port reboot

Sorry for the mis-information and any confusion it may have caused.
Note to self: don't feed the trolls

If I've asked you a question, please answer it. I'm unlikely to be able to help without that information.

Return to “Advanced users”