Usb: Vendor_id, manufacturer_name

Frank B

Senior Member
@Paul, can we talk about user-setable USB IDs?

At least for non-Arduino IDEs it is possible to set defines, so it would be possible to use something like that:

Code:
#if !defined(VENDOR_ID) && !defined(MANUFACTURER_NAME) && !defined(MANUFACTURER_NAME_LEN)
  #define VENDOR_ID          0x16C0
  #define MANUFACTURER_NAME    {'T','e','e','n','s','y','d','u','i','n','o'}
  #define MANUFACTURER_NAME_LEN 11
#endif

in usb_desc.h, at the beginning of the file and remove all later #defines.

It would (at least) make development much easier when using multiple Teensys on one computer. I use one as a USB sound card, and it is irritating when Teensyduino tries to program the board (best would be "invisible" to TD unless I press the button - Usually, I don't want to program it).
I don't think I'm the only user who experiences this issue.
The above change has the intended nice side effect of allowing users to easily set their own IDs without having to patch TD every time.

It could be extended with PRODUCT_NAME

Edit:
Example: With Platformio you could just add it to the project (platformio) ini:
Code:
[COLOR=#d4d4d4][FONT=Consolas][COLOR=#569cd6]build_flags[/COLOR][COLOR=#d4d4d4] = [/COLOR]
[COLOR=#d4d4d4]    -D USB_MIDI_AUDIO_SERIAL[/COLOR]
[COLOR=#d4d4d4]    -D [/COLOR][COLOR=#569cd6]VENDOR_ID[/COLOR][COLOR=#d4d4d4]=0xffff[/COLOR]
[COLOR=#d4d4d4]    -D [/COLOR][COLOR=#569cd6]MANUFACTURER_NAME[/COLOR][COLOR=#d4d4d4]=[/COLOR][COLOR=#ce9178]"{'F','r','a','n','k','y','d','u','i','n','o'}"[/COLOR]

[COLOR=#d4d4d4]    -D [/COLOR][COLOR=#569cd6]MANUFACTURER_NAME_LEN[/COLOR][COLOR=#d4d4d4]=11[/COLOR]

[/FONT][/COLOR]

The MANUFACTURER_NAME_LEN is not needed.
It can be caluclated during compile-time (optional addition to usb_desc.h) :
Code:
#if !defined(VENDOR_ID) && !defined(MANUFACTURER_NAME)
  #define VENDOR_ID        0x16C0
  #define MANUFACTURER_NAME    {'T','e','e','n','s','y','d','u','i','n','o'}  
#endif

[B]#define MANUFACTURER_NAME_LEN sizeof((char[])MANUFACTURER_NAME)[/B]

Same for PRODUCT_NAME_LEN.
 
Last edited:
This made me curious about a better way to handle this from the user sketch, as far as the Manufacturer Name, Product Name, and Serial Number goes these can already be changed from the user sketch with the use of the usb_names.h file. That is mostly used for usbMIDI devices, but it does work for any device even if the USB Type doesn't have usbMIDI.

For the VID and the PID these can surprisingly be changed from the user sketch since the device descriptor isn't constant, here's the code I've tested on a Teensy 4.0:
Code:
#define LSB(n) ((n) & 255)
#define MSB(n) (((n) >> 8) & 255)
#ifdef __cplusplus
extern "C" {
#endif
void startup_early_hook(){
  typedef struct {
  uint16_t  wValue;
  uint16_t  wIndex;
  const uint8_t *addr;
  uint16_t  length;
} usb_descriptor_list_t;
extern const usb_descriptor_list_t usb_descriptor_list[];
  uint8_t* device_descriptor = (uint8_t*)usb_descriptor_list[0].addr;

//  8-9 VID
//    device_descriptor[8] = LSB(VENDOR_ID);
//    device_descriptor[9] = MSB(VENDOR_ID);
//  10-11 PID
    device_descriptor[10] = LSB(0x3000);
    device_descriptor[11] = MSB(0x3000);
}
#ifdef __cplusplus
}
#endif

It compiles for Teensy 3.x so I suspect it should work on those models as well.
 
Played around with usb_desc.h and boards.txt to create MIDIx2 and MIDIx8 using PJRC's VID and PID.

Later, added a MIDI, x2, x4, x8 and x16 using some other VID and PID. Ended up seriously breaking Win7.

Assigning a unique BCD_DEVICE to each new entry got things working without breaking any more Windows.

Just mentioning as a potential headscratch alert.
 
Back
Top