2

I'm writing a device-side USB driver that uses the USB module on a Freescale Kinetis K20 ARM Cortex-M4 processor. On the host side I am running Arch on an x64 processor.

The issue I am having is that I cannot seem to get linux to read the descriptor of my device. My device has one configuration with one interface and no endpoints (just the control). My device descriptor looks like so:

typedef struct {
    uint8_t bLength;
    uint8_t bDescriptorType;
    uint16_t bcdUSB;
    uint8_t bDeviceClass;
    uint8_t bDeviceSubClass;
    uint8_t bDeviceProtocol;
    uint8_t bMaxPacketSize0;
    uint16_t idVendor;
    uint16_t idProduct;
    uint16_t bcdDevice;
    uint8_t iManufacturer;
    uint8_t iProduct;
    uint8_t iSerialNumber;
    uint8_t bNumConfigurations;
} dev_descriptor_t;

static const dev_descriptor_t dev_descriptor = {
    .bLength = 18,
    .bDescriptorType = 1,
    .bcdUSB = 0x0100,
    .bDeviceClass = 0xff,
    .bDeviceSubClass = 0x0,
    .bDeviceProtocol = 0x0,
    .bMaxPacketSize0 = ENDP0_SIZE,
    .idVendor = 0x16c0,
    .idProduct = 0x05dc,
    .bcdDevice = 0x0001,
    .iManufacturer = 0,
    .iProduct = 0,
    .iSerialNumber = 0,
    .bNumConfigurations = 1
};

Assuming the processor reads the bytes starting at bLength I would think this descriptor would work (I have corresponding configuration and interface descriptors, but it isn't even getting that far).

The errors I get is as follows:

usb 4-1.4: device descriptor read/64, error 18
...repeated 4 times
usb 4-1.4: device descriptor read/8, error -75
..repeated 4 times
usb 4-1-port4: unable to enumerate USB device

I've managed to find a list of error codes and -75 is EOVERFLOW which makes sense since my descriptor wouldn't fit inside an 8 byte read. The one that really confuses me is error 18.

My Question:

What is error 18 and what causes it?

Just to be clear: My question isn't about getting the USB module to work on a Kinetis microcontroller (although any hints and experience would be appreciated)...its about finding out what this error code means and diagnosing the problem that causes it.

Error -18 (note the negative) is EXDEV (Cross-link device) which makes no sense to me because I don't know what it means.


Note 1

I know that there isn't a hardware issue with the USB module since the microcontroller is part of a Teensy 3.1 board and I have used its USB module in past projects, but using the provided driver that comes with the accompanying Teensyduino library. I'm writing my own to understand the module better.

Note 2

If its helpful to know, the microcontroller is receiving the command to be assigned an address and seems to respond correctly (i.e. no "not accepting address" errors in my log...I already worked through those). Other than that and the get descriptor command, it doesn't seem to be receiving any additional commands.

1 Answer 1

2

18 is not an error here. Note it is a positive number, while all the error codes are converted to negative numbers in Linux kernel.

Here, 18 is the return value of usb_control_msg(), which returns the length of the device descriptor if success. So it's the bLength field in your device descriptor, which is 18.

The problem lies in the bMaxPacketSize0 field. I don't know what ENDP0_SIZE is, but usb core only accepts following values: 8, 16, 32, 64, 255. If it does not match, the usb_control_msg() is considered failure and report error.

Check hub_port_init() in drivers/usb/core/hub.c. The code flow should be clear.

1
  • Turns out, it was the bMaxPacketSize0, but not in that it wasn't set correctly (mine is set to 64). Reading through the code, it seemed that it wasn't receiving any data at all from my device when it was expecting 18 bytes. I had marked my descriptor struct as const which for some reason was placing it in an inaccessible area of memory (likely the flash). Removing the const then allowed the device to actually send its descriptor which fixed the problem. Thanks for the tip about drivers/usb/core! Dec 4, 2014 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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