1

I'm trying to use the MIDI Linux Gadget Module (g_midi) to turn a Raspberry Pi Zero into a USB MIDI device. I've enabled g_midi using the following commands:

echo "dtoverlay=dwc2" | sudo tee -a /boot/config.txt
echo "dwc2" | sudo tee -a /etc/modules
echo "g_midi" | sudo tee -a /etc/modules
reboot

And now a MIDI device appears in the list when I run sudo amidi -l.

When I connect the Pi Zero to a computer over USB, the computer detects a new MIDI device, and I can send MIDI messages between the Pi and the computer. I can plug and unplug the device as many times as I want, and the computer always re-recognises the Pi.

However, this is not the same using an iPad. When I plug the Pi data USB cable into the Camera Connection Kit (with the Pi Zero also being plugged in with the PWR usb), I can plug the Camera Connection Kit into the iPad, and it will recognise the Pi as a MIDI device. However, if I unplug and replug the Camera Connection Kit, the iPad fails to recognise the Pi again.

Plugging the Pi USB back into a computer causes the Pi to be recognised again on that computer, but not on the iPad. If I unplug the Pi and power it up again, I can get it to recognise fine again, but only the first time I plug it in.

I had a look using dmesg -wH and the output is as follows:

Pi Zero being plugged initially into computer:

[May27 11:58] dwc2 20980000.usb: new device is high-speed
[  +0.012000] dwc2 20980000.usb: new address 25
[  +0.008198] MIDI Gadget gadget: high-speed config #1: MIDI Gadget

Pi Zero being plugged back into computer:

[May27 11:59] dwc2 20980000.usb: new device is high-speed
[  +0.010505] dwc2 20980000.usb: new address 26
[  +0.006452] MIDI Gadget gadget: high-speed config #1: MIDI Gadget

Pi Zero being plugged initially into iPad:

[ +23.850688] dwc2 20980000.usb: new device is low-speed
[  +0.158771] dwc2 20980000.usb: new device is high-speed
[  +0.015806] dwc2 20980000.usb: new address 1
[  +0.007635] MIDI Gadget gadget: high-speed config #1: MIDI Gadget

Pi Zero being plugged back into iPad:

[  +5.517874] dwc2 20980000.usb: new device is low-speed

I have (very occasionally) managed to get the Pi Zero to be recognised a second time on the iPad by unplugging and replugging many many times, whilst waiting between replugs. I've timed when I unplugged and replugged, but these times are not reproducible. What I noticed on the rare occasion that the Pi Zero was recognised for a second time was that the message from dmesg -wH was:

[May27 11:52] dwc2 20980000.usb: new device is low-speed
[  +0.158547] dwc2 20980000.usb: new device is high-speed
[  +0.015820] dwc2 20980000.usb: new address 1
[  +0.008327] MIDI Gadget gadget: high-speed config #1: MIDI Gadget

and the strange part was that the new address was still 1, whereas on the computer the address incremented by one every time I plugged the Pi Zero in.

Not knowing anything about MIDI, USB or the Linux Gadget Modules, I'm not sure if this is significant, but as far as I can tell it's the only differing thing between when I get the Pi Zero to recognise on a computer compared to an iPad.


Has anyone had any experience with working with the MIDI Linux Gadget Module and an iPad, that knows what's wrong here? I would appreciate any help I can get with this.

  • Apparently, the dwc2 driver does not completely reinitialize the port when un-/replugging. This looks like a bug that should be reported. Try reloading the dwc2 module. – CL. Aug 13 '16 at 14:09
  • @CL. I tried running modprobe -r dwc2, modprobe dwc2, modprobe -r g_midi, modprobe g_midi, after I had unplugged the Pi Zero for the first time, but the next time you plug it in it still does not recognise and shows the dwc2 20980000.usb: new device is low-speed in dmesg -wH – user2370460 Aug 13 '16 at 16:16
1

This could be because by default the g_midi gadget (which is deprecated BTW) uses 250mV VBus Draw, which means that it expects the host device to send 250mV to the device. I don't know if the iPad does that.

This is not a bug on g_midi because it is a generic configuration. You can change this when compiling the kernel by changing the CONFIG_USB_GADGET_VBUS_DRAW flag to a mV * 2, as specified by the USB spec.

Example, to require 13mV only:

CONFIG_USB_GADGET_VBUS_DRAW=26

Also, try to use the latest Linux kernel version available to you, it might this bug fixed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.