snd-usb-audio: probe of 1-1.5:1.3 failed with error -16 (Teensy 3.2, audio+midi+seria

Status
Not open for further replies.

jwatte

Well-known member
I'm building a sketch using Arduino 1.8.3, Teensuduino on Raspberry Pi downloaded two weeks ago. The board is 3.2, at standard 96 MHz overclock, with the USB model being Audio + Midi + Serial.

When I plug this Teensy into my Raspberry Pi (running Raspbian 8.0, updated a month ago,) it doesn't see the audio interface, and the following error is in dmesg:

Code:
[ 9780.098333] usb 1-1.5: new full-speed USB device number 87 using dwc_otg
[ 9780.231840] usb 1-1.5: New USB device found, idVendor=16c0, idProduct=048a
[ 9780.231859] usb 1-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 9780.231870] usb 1-1.5: Product: Teensy MIDI/Audio
[ 9780.231880] usb 1-1.5: Manufacturer: Teensyduino
[ 9780.231891] usb 1-1.5: SerialNumber: 605160
[ 9780.233734] cdc_acm 1-1.5:1.0: ttyACM0: USB ACM device
[ 9780.235725] snd-usb-audio 1-1.5:1.2: cannot find the slot for index 0 (range 0-0), error: -16
[ 9780.235744] usb 1-1.5: cannot create card instance 0
[ 9780.235799] snd-usb-audio: probe of 1-1.5:1.2 failed with error -16
[ 9780.236500] snd-usb-audio 1-1.5:1.3: cannot find the slot for index 0 (range 0-0), error: -16
[ 9780.236514] usb 1-1.5: cannot create card instance 0
[ 9780.236537] snd-usb-audio: probe of 1-1.5:1.3 failed with error -16


I have reduced it to the following sketch:


Code:
#include <Audio.h>


// GUItool: begin automatically generated code
AudioInputUSB            usb1;           //xy=70,242
AudioMixer4              mixer1;         //xy=218,255
AudioOutputAnalog        dac1;           //xy=367,255
AudioConnection          patchCord1(usb1, 0, mixer1, 0);
AudioConnection          patchCord2(usb1, 1, mixer1, 1);
AudioConnection          patchCord3(mixer1, dac1);
// GUItool: end automatically generated code


uint32_t last;
int n;

#define RESTART_ADDR       0xE000ED0C
#define READ_RESTART()     (*(volatile uint32_t *)RESTART_ADDR)
#define WRITE_RESTART(val) ((*(volatile uint32_t *)RESTART_ADDR) = (val))

void reboot() {
    WRITE_RESTART(0x5FA0004);
}


void setup() {
  // put your setup code here, to run once:
  AudioMemory(6);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (millis() - last > 5000) {
    ++n;
    SerialUSB.print("Message ");
    SerialUSB.println(n);
    last = millis();
    if (n == 6) {
      reboot();
    }
  }
}



What am I missing? Is there a "do audio work" function I need to call inside loop()? Does setup() need to do something other than AudioMemory()?
(Which, by the way, I accidentally discovered I'm supposed to call; the GUI editor doesn't tell me as much.)



Finally, this is what lsusb -v thinks of the device (which is more important for the linux side than the Teensy side):

Code:
pi@robot-raspberrypi:~/Arduino/audio_playout_sketch $ lsusb -v

Bus 001 Device 088: ID 16c0:048a Van Ooijen Technische Informatica 
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.01
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x16c0 Van Ooijen Technische Informatica
  idProduct          0x048a 
  bcdDevice            2.00
  iManufacturer           1 Teensyduino
  iProduct                2 Teensy MIDI/Audio
  iSerial                 3 605160
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength          341
    bNumInterfaces          6
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xc0
      Self Powered
    MaxPower              100mA
    Interface Association:
      bLength                 8
      bDescriptorType        11
      bFirstInterface         0
      bInterfaceCount         2
      bFunctionClass          2 Communications
      bFunctionSubClass       2 Abstract (modem)
      bFunctionProtocol       1 AT-commands (v.25ter)
      iFunction               4 (error)
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         2 Communications
      bInterfaceSubClass      2 Abstract (modem)
      bInterfaceProtocol      1 AT-commands (v.25ter)
      iInterface              0 
      CDC Header:
        bcdCDC               1.10
      CDC Call Management:
        bmCapabilities       0x01
          call management
        bDataInterface          1
      CDC ACM:
        bmCapabilities       0x06
          sends break
          line coding and serial state
      CDC Union:
        bMasterInterface        0
        bSlaveInterface         1 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0010  1x 16 bytes
        bInterval              64
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0 Unused
      bInterfaceProtocol      0 
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        2
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         1 Audio
      bInterfaceSubClass      3 MIDI Streaming
      bInterfaceProtocol      0 
      iInterface              0 
      MIDIStreaming Interface Descriptor:
        bLength                 7
        bDescriptorType        36
        bDescriptorSubtype      1 (HEADER)
        bcdADC               1.00
        wTotalLength           65
      MIDIStreaming Interface Descriptor:
        bLength                 6
        bDescriptorType        36
        bDescriptorSubtype      2 (MIDI_IN_JACK)
        bJackType               1 Embedded
        bJackID                 1
        iJack                   0 
      MIDIStreaming Interface Descriptor:
        bLength                 6
        bDescriptorType        36
        bDescriptorSubtype      2 (MIDI_IN_JACK)
        bJackType               2 External
        bJackID                 2
        iJack                   0 
      MIDIStreaming Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      3 (MIDI_OUT_JACK)
        bJackType               1 Embedded
        bJackID                 3
        bNrInputPins            1
        baSourceID( 0)          2
        BaSourcePin( 0)         1
        iJack                   0 
      MIDIStreaming Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      3 (MIDI_OUT_JACK)
        bJackType               2 External
        bJackID                 4
        bNrInputPins            1
        baSourceID( 0)          1
        BaSourcePin( 0)         1
        iJack                   0 
      Endpoint Descriptor:
        bLength                 9
        bDescriptorType         5
        bEndpointAddress     0x05  EP 5 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
        bRefresh                0
        bSynchAddress           0
        MIDIStreaming Endpoint Descriptor:
          bLength                 5
          bDescriptorType        37
          bDescriptorSubtype      1 (GENERAL)
          bNumEmbMIDIJack         1
          baAssocJackID( 0)       1
      Endpoint Descriptor:
        bLength                 9
        bDescriptorType         5
        bEndpointAddress     0x84  EP 4 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
        bRefresh                0
        bSynchAddress           0
        MIDIStreaming Endpoint Descriptor:
          bLength                 5
          bDescriptorType        37
          bDescriptorSubtype      1 (GENERAL)
          bNumEmbMIDIJack         1
          baAssocJackID( 0)       3
    Interface Association:
      bLength                 8
      bDescriptorType        11
      bFirstInterface         3
      bInterfaceCount         3
      bFunctionClass          1 Audio
      bFunctionSubClass       1 Control Device
      bFunctionProtocol       0 
      iFunction               0 
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        3
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         1 Audio
      bInterfaceSubClass      1 Control Device
      bInterfaceProtocol      0 
      iInterface              0 
      AudioControl Interface Descriptor:
        bLength                10
        bDescriptorType        36
        bDescriptorSubtype      1 (HEADER)
        bcdADC               1.00
        wTotalLength           62
        bInCollection           2
        baInterfaceNr( 0)       4
        baInterfaceNr( 1)       5
      AudioControl Interface Descriptor:
        bLength                12
        bDescriptorType        36
        bDescriptorSubtype      2 (INPUT_TERMINAL)
        bTerminalID             1
        wTerminalType      0x0602 Digital Audio Interface
        bAssocTerminal          0
        bNrChannels             2
        wChannelConfig     0x0003
          Left Front (L)
          Right Front (R)
        iChannelNames           0 
        iTerminal               0 
      AudioControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      3 (OUTPUT_TERMINAL)
        bTerminalID             2
        wTerminalType      0x0101 USB Streaming
        bAssocTerminal          0
        bSourceID               1
        iTerminal               0 
      AudioControl Interface Descriptor:
        bLength                12
        bDescriptorType        36
        bDescriptorSubtype      2 (INPUT_TERMINAL)
        bTerminalID             3
        wTerminalType      0x0101 USB Streaming
        bAssocTerminal          0
        bNrChannels             2
        wChannelConfig     0x0003
          Left Front (L)
          Right Front (R)
        iChannelNames           0 
        iTerminal               0 
      AudioControl Interface Descriptor:
        bLength                10
        bDescriptorType        36
        bDescriptorSubtype      6 (FEATURE_UNIT)
        bUnitID                49
        bSourceID               3
        bControlSize            1
        bmaControls( 0)      0x01
          Mute Control
        bmaControls( 1)      0x02
          Volume Control
        bmaControls( 2)      0x02
          Volume Control
        iFeature                0 
      AudioControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      3 (OUTPUT_TERMINAL)
        bTerminalID             4
        wTerminalType      0x0602 Digital Audio Interface
        bAssocTerminal          0
        bSourceID              49
        iTerminal               0 
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        4
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol      0 
      iInterface              0 
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        4
      bAlternateSetting       1
      bNumEndpoints           1
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol      0 
      iInterface              0 
      AudioStreaming Interface Descriptor:
        bLength                 7
        bDescriptorType        36
        bDescriptorSubtype      1 (AS_GENERAL)
        bTerminalLink           2
        bDelay                  3 frames
        wFormatTag              1 PCM
      AudioStreaming Interface Descriptor:
        bLength                11
        bDescriptorType        36
        bDescriptorSubtype      2 (FORMAT_TYPE)
        bFormatType             1 (FORMAT_TYPE_I)
        bNrChannels             2
        bSubframeSize           2
        bBitResolution         16
        bSamFreqType            1 Discrete
        tSamFreq[ 0]        44100
      Endpoint Descriptor:
        bLength                 9
        bDescriptorType         5
        bEndpointAddress     0x86  EP 6 IN
        bmAttributes            9
          Transfer Type            Isochronous
          Synch Type               Adaptive
          Usage Type               Data
        wMaxPacketSize     0x00b4  1x 180 bytes
        bInterval               1
        bRefresh                0
        bSynchAddress           0
        AudioControl Endpoint Descriptor:
          bLength                 7
          bDescriptorType        37
          bDescriptorSubtype      1 (EP_GENERAL)
          bmAttributes         0x00
          bLockDelayUnits         0 Undefined
          wLockDelay              0 Undefined
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        5
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol      0 
      iInterface              0 
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        5
      bAlternateSetting       1
      bNumEndpoints           2
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol      0 
      iInterface              0 
      AudioStreaming Interface Descriptor:
        bLength                 7
        bDescriptorType        36
        bDescriptorSubtype      1 (AS_GENERAL)
        bTerminalLink           3
        bDelay                  3 frames
        wFormatTag              1 PCM
      AudioStreaming Interface Descriptor:
        bLength                11
        bDescriptorType        36
        bDescriptorSubtype      2 (FORMAT_TYPE)
        bFormatType             1 (FORMAT_TYPE_I)
        bNrChannels             2
        bSubframeSize           2
        bBitResolution         16
        bSamFreqType            1 Discrete
        tSamFreq[ 0]        44100
      Endpoint Descriptor:
        bLength                 9
        bDescriptorType         5
        bEndpointAddress     0x07  EP 7 OUT
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x00b4  1x 180 bytes
        bInterval               1
        bRefresh                0
        bSynchAddress         136
        AudioControl Endpoint Descriptor:
          bLength                 7
          bDescriptorType        37
          bDescriptorSubtype      1 (EP_GENERAL)
          bmAttributes         0x00
          bLockDelayUnits         0 Undefined
          wLockDelay              0 Undefined
      Endpoint Descriptor:
        bLength                 9
        bDescriptorType         5
        bEndpointAddress     0x88  EP 8 IN
        bmAttributes           17
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Feedback
        wMaxPacketSize     0x0003  1x 3 bytes
        bInterval               1
        bRefresh                5
        bSynchAddress           0
Device Status:     0x0000
  (Bus Powered)
 
I'm building a sketch using Arduino 1.8.3, Teensuduino on Raspberry Pi downloaded two weeks ago. The board is 3.2, at standard 96 MHz overclock, with the USB model being Audio + Midi + Serial.


What am I missing? Is there a "do audio work" function I need to call inside loop()? Does setup() need to do something other than AudioMemory()?
(Which, by the way, I accidentally discovered I'm supposed to call; the GUI editor doesn't tell me as much.)

cannot comment on RPI, so far never used it with Teensy

dac1 handles all audio updates
I would try to change number of available audio buffer to 12

not sure if SerialUSB is same as Serial and where it is defined
not sure if USB has sufficient time to reset and recognize audio,seral after reboot

try to add blink to sketch to see if it working.
let loop run at least for 5 seconds while blinking to see if program crashes or simply USB in PC is too slow
 
Thanks for the answer.

dac1 handles all audio updates

By this, I assume you mean, "the dac1 object, by existing, will pull data through the pipeline, so no specific work function needs to be called" ?

not sure if SerialUSB is same as Serial and where it is defined

SerialUSB is the name given to the USB serial port in the Arduino environment, because it may differ between boards. For Teensy 3, it's defined to equal Serial.

not sure if USB has sufficient time to reset and recognize audio,seral after reboot

I don't know what you mean by "if USB has sufficient time to reset and recognize audio."
As you can tell, the Raspberry Pi (host) USB subsystem sees the endpoints, and as you can tell from the dmesg output, the Linux usb audio code is trying to generate a sound card device for the Teensy, but fails because "snd-usb-audio 1-1.5:1.2: cannot find the slot for index 0 (range 0-0), error: -16"
Thus, something is mis-matched between how the Linux USB audio driver wants to see an audio device, and how Teensy actually exposes the device, so we never get to the point of exposing it to the host software, and thus never get the chance to feed it audio data.

try to add blink to sketch to see if it working.

The sketch already writes serial data, which I can see. Additionally, it re-boots every 30 seconds, just like it's supposed to, so clearly the loop() function works already.
I have the same "can't recognize the audio device" in another sketch that does a lot more work, and that, too, works well for all the other functions; the sketch you see above is the small reproduction path.
(Taking out the serial code and the reboot code still reproduces the problem, btw.)

let loop run at least for 5 seconds while blinking to see if program crashes or simply USB in PC is too slow

I don't understand this suggestion -- which program would that be that would crash?

As you can tell from the dmesg output, the USB stack on the Linux host has already reacted to the Teensy when it's plugged in, and the usb sound driver determines that something's wrong with the audio endpoints exposed by the Teensy.

This is either a bug in the Linux USB sound driver, or a bug in the endpoint exposed by the Teensy. I'm trying to figure out which it is, and what to do with it.
Surely I can't be the only person trying to use the Teensy audio USB support from a Linux host?
 
Okay, the plot thickens! I plugged the same Teensy into a x86 computer running Ubuntu 16.04, and here is dmesg:

Code:
[423140.406952] usb 2-1.1: new full-speed USB device number 10 using ehci-pci
[423140.516945] usb 2-1.1: New USB device found, idVendor=16c0, idProduct=048a
[423140.516948] usb 2-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[423140.516950] usb 2-1.1: Product: Teensy MIDI/Audio
[423140.516952] usb 2-1.1: Manufacturer: Teensyduino
[423140.516953] usb 2-1.1: SerialNumber: 605160
[423140.517886] usb 2-1.2: USB disconnect, device number 4
[423140.539995] cdc_acm 2-1.1:1.0: ttyACM0: USB ACM device
[423140.545258] usbcore: registered new interface driver cdc_acm
[423140.545259] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[423140.550154] usb 2-1.1: Warning! Unlikely big volume range (=4095), cval->res is probably wrong.
[423140.550157] usb 2-1.1: [49] FU [PCM Playback Volume] ch = 2, val = 0/4095/1
[423140.550552] usbcore: registered new interface driver snd-usb-audio

So, the problem seems to be between the snd-usb-audio module in the Raspbian distribution and the Teensy, where something got fixed in the later kernel on Ubuntu:

Raspbian:
Code:
Linux robot-raspberrypi 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux

Ubuntu:
Code:
Linux ub16 4.10.0-28-generic #32~16.04.2-Ubuntu SMP Thu Jul 20 10:19:48 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

This tells me I could look for diffs between the two kernel versions to see what might have changed, to help hone in on what the difference is.
 
So it seems the value "snd_ecards_limit" is just 1 on the Raspberry Pi / Raspbian kernel, and the first sound card slot is taken by the on-board audio.
Thus, there's no space for a second card (from USB.) And, for some reason, the USB driver tries to assign index 0 to the USB audio, which then ends up being taken by on-board.

The fix turns out to be creating a file /etc/modprobe.d/usb_sound.conf with the following contents:

Code:
options usb_snd_audio index=1


rmmod the old usb_snd_audio module, if installed, and then re-plug the Teensy. Now, a USB audio card index is allocated for it!

There's no good resource for this error I could find on the internets; I figured this out by reading the kernel source. Live and learn!
 
Status
Not open for further replies.
Back
Top