10 years, 10 months ago.

Where is the USB Device Vendor ID and Product ID set?

I recently been trying some of the handbook tutorials with a view to constructing a USB device. I managed to get the serial hello world example and the USB mouse example to work once....One problem, I can't remember what I had to change in order to get them to work!

I know I have my wiring correct as it has not changed since my previous efforts and a USB device is present in my windows device manager. My issue comes from the fact that the USB device is reported as having a Vendor ID of 0x0000 and a Product ID of 0x0000.

I know the constructor for the USB device sets the type of device - lets say for example I am using the USBMouse example:

#include "mbed.h"
#include "USBMouse.h"
 
USBMouse mouse;
 
int main() {
    int16_t x = 0;
    int16_t y = 0;
    int32_t radius = 10;
    int32_t angle = 0;
 
    while (1) {
        x = cos((double)angle*3.14/180.0)*radius;
        y = sin((double)angle*3.14/180.0)*radius;
        
        mouse.move(x, y);
        angle += 3;
        wait(0.001);
    }
}

Inside the constructor in USBMouse.h the following line sets the Vendor ID and product ID to the default values for a mouse:

USBMouse(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0001, uint16_t product_release = 0x0001): 
            USBHID(0, 0, vendor_id, product_id, product_release, false)
            { 
                button = 0;
                this->mouse_type = mouse_type;
                connect();
            };

The program compiles ok and runs ok and a USB device does appear but the OS doesn't know what it is and so will not use it.

Somewhere the Vendor ID and Product ID are being overwritten and I can't find where....Can anyone help me?

Cheers

Alex

1 Answer

10 years, 10 months ago.

Please use <<code>> and <</code>> tags around your posted code to keep it readable.

The vendor and product IDs should not be 0, but they should take the default values when the code has not been changed in the declaration in Mouse.h. You can override them in your own declaration and see if they change:

#include "mbed.h" 
#include "USBMouse.h" 

USBMouse mouse(REL_MOUSE, 0x5678, 0x0002, 0x0003); //override default IDs
 
int main() { 

etc..
 
}

Note REL_MOUSE probably needs including the class or enum

Wim,

I have done as you asked and tried to create an instance of USBMouse with your code. It compiles but the device instance is still as I have seen before...I'm no expert but this obviously suggests that USBMouse is not setting the VID and PID number and some other code somewhere else is. I have tried several of the USB examples provided in the handbook and none of them seem to work. Do you have any idea as to why?

Cheers

Alex

posted by Alexander Lang 16 Jan 2014

Since none of the examples are working anymore it seems to me that there is a wiring and/or powersupply problem. In that case the PC hardware may detect that a USB device is plugged in, but it cant complete the enumeration and may get stuck and default to an unrecognized device with vendor and product IDs of 0. Recommend you check all wires, note that breadboards sometimes have bad connections when larger pins are inserted next to thinner wires. Try to actually measure connectivity and not just visually inspect (although that often helps). Power down mbed before doing that. Also check powersupply, can you measure the voltage, should be about 5V on Vcc from the USB socket? Try removing the Vcc line altogether (but keep GND connected to pin 1 on mbed) and power mbed through the USB that is used for downloading the code and then plug in the mouse device USB cable . When none of that resolves it , there is the possibility that the USB port on mbed or on the PC side has been damaged.

posted by Wim Huiskamp 16 Jan 2014