Using more than 4 MIDI-USB controllers [partially SOLVED]

When I plug in the last (5th) device there is dmesg output last lines:

[  283.242311] usb 1-1.3: new full-speed USB device number 8 using xhci_hcd
[  283.381073] usb 1-1.3: New USB device found, idVendor=0944, idProduct=0116, bcdDevice= 1.00
[  283.381080] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[  283.381085] usb 1-1.3: Product: nanoPAD2
[  283.381090] usb 1-1.3: Manufacturer: KORG INC.
[  283.385713] snd-usb-audio 1-1.3:1.0: cannot find the slot for index -1 (range 0-7), error: -19
[  283.385722] usb 1-1.3: cannot create card instance 4

And there is no matter which device and on which socket is plugged the last.
Last two lines are always the same.

There is a limitation in Zynthian’s 4.19.x Raspi kernel that only allows for a certain amount of USB Audio/MIDI devices. I think the limit is 8, but that counts both Audio and MIDI. I think it was introduced into Raspbian mainly for the (weaker) Pi1 and 2. In my opinion it is overdue to remove this limit as it makes no sense on the modern Raspis anymore. I am actually not sure if the recent Raspberry OS kernels still have this limit. Maybe time for a Zynthian kernel upgrade ?
I am not sure but it looks as if the Zynthian kernel is in itself a customized kernel compiled from Raspbian kernel sources. If that’s the case, then maybe the Zynthian kernel maintainer can recompile the kernel with that limit removed.

I think this was previously discussed. Do you know the parameter that needs changing in the kernel config?

@riban sadly not.

Okay - got it!

source/include/sound/core.h defines default maximum quantity of cards as 8 if CONFIG_SND_MAX_CARDS is not defined in the kernel config.

/* number of supported soundcards */
#ifdef CONFIG_SND_DYNAMIC_MINORS
#define SNDRV_CARDS CONFIG_SND_MAX_CARDS
#else
#define SNDRV_CARDS 8           /* don't change - minor numbers */
#endif

This is the maximum quantity of sound cards that the Linux kernel will support. Soundcards include audio and MIDI. Devices that share audio and MIDI or have multiple ports may appear as a single card.

amidi -l lists the MIDI cards whilst aplay -l lists the audio cards. You will see that these cover all the cards from 0-7.

You have 4 USB MIDI devices using cards 3-7, f_midi using card 0 and 2 audio devices using cards 1-2. If you run aplay -l you will see your audio cards. One will be sndrpihifiberry and the other is likely to be Headphones. The reason this stops Zynthian from starting up with all MIDI devices plugged in is because the 8 cards are being used but the MIDI and other audio interfaces hence the hifiberry is not available for jackd to use.

As described by @catherder we could recompile the kernel with a larger quantity of soundcards by passing CONFIG_SND_MAX_CARDS value to the kernel build. @jofemodo may consider this given that the prime use of this device is for audio it seems reasonable that we should allow many audio devices to be enabled.

In the short term there may be some options. The headphones device is enabled in /boot/config.txt

# Enable RBPi Onboard Audio (Headphones)
dtparam=audio=on
audio_pwm_mode=2

By commenting out these lines and rebooting the Headphones device is removed which frees a card. It also removes the HDMI audio output which uses another card hence we end up with two extra cards which may suffice. This file will be overwritten if you subsequently change some configuration elements in webconf or some admin but may work for you as a temporary solution.

f_midi is the OTG MIDI interface, that is an interface that is available if the Raspberry Pi is plugged into a USB host via its USB-C power connector. This is challenging due to power requirements for Zynthian but some people are experimenting with it. This can be disabled in /boot/config.txt by commenting out the dwc2 overlay line.

[pi4]
# Enable OTG
dtoverlay=dwc2

This will give back another card but again remember the file can get overwritten.

We need a feature request to make both these options configurable from webconf to allow them to be disabled when not required.

Done: Allow disabling of unused resources (USB OTG, HDMI audio, Headphones) through web ui · Issue #421 · zynthian/zynthian-issue-tracking · GitHub

2 Likes

Fantastic. That is it. I commented Onboard Audio and all keyboards works again.
Thank you so much @riban @catherder . As always I am shocked by the highest quality of this community :smiley:

and what happens when you have keyboards all working again, then … ? :face_with_monocle:

I can now return to my musical exercises again. I will not forget to show off when it will be ready :blush:

1 Like

Picks a particularly malevolent monitoring raven and provides it with a suitably encouraging grudge . . .

Hi @zynthianers!

I just added 2 options for disabling RBPi audio & OTC from the webconf. The new options are located in the Hardware->Audio menu.

This should solve partially the problem of connecting more than 4 midi controllers to zynthian, increasing the limit to 7. It’s not perfect, but it’s a good improvement.

For having more than 7, we need to recompile the kernel, what it’s not difficult, but it’s not trivial either. Devil is on details, you know … :wink:

Regards,

5 Likes