Teensy 3.2, 3.6: how to change GUID/UUID?

bsumlin

Member
My project is a UWP app communicating to a Teensy 3.2 and a 3.6, each doing different things. I have their tasks separated because of mission creep, and I've run out of ports on the 3.6 so I included the 3.2 to run some lasers. My UWP app won't accurately differentiate between the two of them. When programmed as serial devices, both uC's VID and PID are always 0x16C0 and 0x0483, respectively.

From the IDE, I can change their type, to any of the following:

types.PNG

When they're both programmed as serial devices, they show up in the UWP serial sample app like so:

devices.PNG

You'd think this would allow me to differentiate between the two based on everything after the PID, however, they seem to switch places every other time I start the app or unplug/replug. It's frustrating. Furthermore, when I connect to either of them, the part in braces is always the same:

addr.PNG

I've tried changing the type to various things, and I'm mostly able to talk to both devices but they show up in device manager as whatever I make them, and I'm concerned that this might cause conflicts with the rest of my system. For example, setting it as an "All of the Above" device allows my computer to see it as audio, which caused Hulu to crash when it tried to send digital audio to a microcontroller. I'd like to have them both as serial devices, if possible?

Is there anyway to change the built in identifiers so I can programmatically differentiate between two serial devices? Any guidance would be appreciated.
 

I'm aware of being able to change PID, that's what selecting different usb types does. Would changing the VID be a better option?

By editing usb_desc.h, it looks like I can change the VID and PID for each type. This is inconvenient because I'll have to swap them back and forth each time I reprogram the 3.2 or 3.6. I'm wondering if there's a more permanent identifier I can change.
 
That is GUID_DEVINTERFACE_COMPORT, which means Windows detected it as the "Ports" class of device. All serial ports, whether Teensy serial or FTDI USB serial or cable modems or even the built in (not USB) COM ports on older motherboards and anything else which shows up in "Ports" in the Windows Device Manager are all identified by this GUID.

Microsoft's documentation:

https://docs.microsoft.com/en-us/windows-hardware/drivers/install/guid-devinterface-comport

Every (genuine) Teensy 3.x, LC and 4.x has a unique serial number. Windows uses those to associate a COM port number with each physical device. You're also seeing those in the ID strings (though from the info you showed, I suspect one of your boards may be a counterfeit).
 
That is GUID_DEVINTERFACE_COMPORT, which means Windows detected it as the "Ports" class of device. All serial ports, whether Teensy serial or FTDI USB serial or cable modems or even the built in (not USB) COM ports on older motherboards and anything else which shows up in "Ports" in the Windows Device Manager are all identified by this GUID.

Microsoft's documentation:

https://docs.microsoft.com/en-us/windows-hardware/drivers/install/guid-devinterface-comport

Every (genuine) Teensy 3.x, LC and 4.x has a unique serial number. Windows uses those to associate a COM port number with each physical device. You're also seeing those in the ID strings (though from the info you shows, I suspect one of your boards may be a counterfeit).

They're "counterfeit" in the sense that I built them myself, but I used bootloader chips I purchased from PJRC. I needed the 10th pin on PORT D on the 3.6, which isn't broken out in the Teensy. Would this be the problem?
 
If your boards don't have serial numbers (or even if they do), you can edit usb_init_serialnumber() in usb_desc.c to initialize the serial number to anything you like. Then look for that info in the ID strings Windows creates.

Or you can change the VID or PID in usb_desc.h, as already mentioned. But if you do that, Teensyduino won't know how to send an auto-reboot request when you click Upload in Arduino. That's an easy problem to work around, just click Verify and then press the Program pushbutton on the board. If you want the convenience of having it all happen automatically, you need to keep the VID & PID as numbers Teensyduino recognizes.
 
SOLVED: HACKY WORKAROUND

I edited a few things to be able to differentiate my boards. First, I edited boards.txt to include two new boards, each with an appropriate name for my project, and with the "board.menu.usb.serial" value pointing to a new type of serial, called "Serial (Duplicate 1)" and "Serial (Duplicate 2)". I duplicated the usb_serial.h and usb_serial.c files with new names, and edited usb_desc.h to include them. Everything works and I can differentiate based on PID.

This is going to be a pain when moving computers and when upgrading the Arduino IDE and Teensyduino stuff, so if anyone has a better idea I'd love to hear it.
 
If your boards don't have serial numbers (or even if they do), you can edit usb_init_serialnumber() in usb_desc.c to initialize the serial number to anything you like.

I was interested and had a look at this. @Paul: you probably forgot that in wise foresight you made the corresponding struct weak :) So changing the serial number can be done in user code without changing the core:

Code:
extern "C"
{
    struct usb_string_descriptor_struct
    {
        uint8_t bLength;
        uint8_t bDescriptorType;
        uint16_t wString[10];
    };

    usb_string_descriptor_struct usb_string_serial_number =
    {
         22,  // 2 + 2*length of the sn string
         3,
         {'M','Y', 'S','N', '0', '0', '0','0', '1', 0},
    };
}

//-----------------
void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
  digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN));
  delay(200);
}

Note: looks like the bootloader still reports the built in serial number which confuses tyCommander. Teensy.exe does not choke on it. Not very likely but is it possible to change the serial number reported by the bootloader as well?

I placed some info about changing the serial number in the Teensy User WIKI https://github.com/TeensyUser/doc/wiki/Custom-Serial-Number
 
I was interested and had a look at this. @Paul: you probably forgot that in wise foresight you made the corresponding struct weak :) So changing the serial number can be done in user code without changing the core:

Code:
extern "C"
{
    struct usb_string_descriptor_struct
    {
        uint8_t bLength;
        uint8_t bDescriptorType;
        uint16_t wString[10];
    };

    usb_string_descriptor_struct usb_string_serial_number =
    {
         22,  // 2 + 2*length of the sn string
         3,
         {'M','Y', 'S','N', '0', '0', '0','0', '1', 0},
    };
}

//-----------------
void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
  digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN));
  delay(200);
}

Note: looks like the bootloader still reports the built in serial number which confuses tyCommander. Teensy.exe does not choke on it. Not very likely but is it possible to change the serial number reported by the bootloader as well?

I placed some info about changing the serial number in the Teensy User WIKI https://github.com/TeensyUser/doc/wiki/Custom-Serial-Number

This works indeed but there is one issue. Starting the device, already connected to the computer via USB, it doesn't connect. Need to unplug and plug it back in when the device is running.
So, is there any way to reset the usb or refresh it via code? So that I can do that once the device is running, in setup or something.
 
To turn off USB on Teensy 4.x, from the PC side as if the cable where unplugged, try this:

Code:
        USB1_USBCMD = USB_USBCMD_RST;
        USBPHY1_CTRL_SET = USBPHY_CTRL_SFTRST;

PCs and hubs can take between 3 to 10ms to detect disconnect.

To actually reset, try this:

Code:
        SCB_AIRCR = 0x05FA0004;
 
To turn off USB, from the PC side as if the cable where unplugged, try this:

Code:
        USB1_USBCMD = USB_USBCMD_RST;
        USBPHY1_CTRL_SET = USBPHY_CTRL_SFTRST;

PCs and hubs can take between 3 to 10ms to detect disconnect.

To actually reset, try this:

Code:
        SCB_AIRCR = 0x05FA0004;

Paul you're a legend, thanks!
I found this tho by Luni in another thread and it works like a charm!
So it's a build flag "-D TEENSY_INIT_USB_DELAY_AFTER=1"
 
To turn off USB on Teensy 4.x, from the PC side as if the cable where unplugged, try this:

Code:
        USB1_USBCMD = USB_USBCMD_RST;
        USBPHY1_CTRL_SET = USBPHY_CTRL_SFTRST;

PCs and hubs can take between 3 to 10ms to detect disconnect.

To actually reset, try this:

Code:
        SCB_AIRCR = 0x05FA0004;

So I tried to use SCB_AIRCR = 0x05FA0004; but the Teensy wont start with that in my code.
The way I had it before worked fine, except the flashtool I use that Luni made, needs the USB to unplug and plug back in to work when flashing, otherwise I get rebootError.

So I almost have it all perfect, TEENSY_INIT_USB_DELAY_AFTER=1 is what I use, is there a way to tweak this so that the update tool doesn't get stupid over Halfkay?
 
Back
Top