Teensy 4.0 USB descriptor modifications

2022 FEB 11

In the previous article we modified the USB descriptor of a SparkFun Pro Micro to include a unique serial number and a product string of our choosing. In this article we will try to achieve a similar result using a Teensy 4.0 board.

Modifying the USB descriptor to include a custom product name (and manufacturer name) is beneficial for two reasons. Firstly, it allows us and our programs to unique identify the device without changing its VID/PID combination. Second, it allows our customers to identify the device in Windows Control Panel and Device Manager.

The Teensy SDK includes support for setting a custom product name and manufacturer. We only need to supply the correct information at compile time.

Create a new file called teensy4_usb_descriptor.c in your Arduino project. It is important to use a C-file since C++ does not allow this kind of struct initialization. Then copy and paste the following code. Modify the defines to suite your needs.

// file: teensy4_usb_descriptor.c
//
// This file overrides the default Teensy 4.0 USB descriptor's product name
// and manufacturer name.
//
// For more details see:
//   teensy/avr/cores/teensy4/usb_names.h
//   teensy/avr/cores/teensy4/usb_desc.c
//   teensy/avr/cores/teensy4/usb_desc.h
//
#include <avr/pgmspace.h>
#include <usb_names.h> // teensy/avr/cores/teensy4/usb_names.h

#define PRODUCT_NAME {'M','y',' ','B','o','a','r','d'}
#define PRODUCT_NAME_LEN 8
#define MANUFACTURER_NAME {'M','y',' ','C','o','m','p','a','n','y'}
#define MANUFACTURER_NAME_LEN 10

PROGMEM extern struct usb_string_descriptor_struct usb_string_manufacturer_name = {
    2 + MANUFACTURER_NAME_LEN * 2,
    3,
    MANUFACTURER_NAME
};

PROGMEM extern struct usb_string_descriptor_struct usb_string_product_name = {
    2 + PRODUCT_NAME_LEN * 2,
    3,
    PRODUCT_NAME
};

Don’t replace the initializer list with a string. It won’t work. A wchar_t string won’t work either.

Next part

In the next part we will look at enumerating USB serial devices and identifying our devices by product name instead of COM-port number.