Changing USB device VID PID

Tried it with an Arduino Nano Every with no luck.

Here a screenshot of my config, nothing happens.

Well given the automatic upload logic

This should work. Can you fully describe your setup with the attached devices and corresponding PIDs, VIDs and product IDs? Also a log of pio run -t upload -v?

It is an “Arduino Nano Every”, VID 2341, PID 0058
I want to change the PID to 0043 an the name “#lighthack
PIO version Home 3.0.1 and Core 4.1.0 and macOS Catalina 10.15.2
Where can I find the code in system?

Here the log:
sstaub1:#lighthack USB test sstaub$ pio run -t upload -v

Processing nano_every (platform: atmelmegaavr; board: nano_every; framework: arduino; extra_scripts: pre:custon_hwids.py)
---------------------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/atmelmegaavr/nano_every.html
PLATFORM: Atmel megaAVR 1.0.0 > Arduino Nano Every
HARDWARE: ATMEGA4809 16MHz, 6KB RAM, 47.50KB Flash
PACKAGES: toolchain-atmelavr 1.70300.191015 (7.3.0), tool-avrdude-megaavr 1.60300.191015 (6.3.0), framework-arduino-megaavr 1.8.5
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 6 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <OSC> (/Users/sstaub/Dateien/Development/Arduino/#lighthack USB test/lib/OSC)
Building in release mode
MethodWrapper(["checkprogsize"], [".pio/build/nano_every/firmware.elf"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
DATA:    [=         ]   8.0% (used 489 bytes from 6144 bytes)
PROGRAM: [==        ]  15.3% (used 7450 bytes from 48640 bytes)
.pio/build/nano_every/firmware.elf  :
section                     size      addr
.data                         10   8398848
.text                       7440         0
.rodata                      167     23824
.bss                         479   8398858
.comment                      17         0
.note.gnu.avr.deviceinfo      64         0
.debug_aranges               480         0
.debug_info                12058         0
.debug_abbrev               9172         0
.debug_line                 2899         0
.debug_str                  3979         0
Total                      36765
<lambda>(["upload"], [".pio/build/nano_every/firmware.hex"])
AVAILABLE: jtag2updi
CURRENT: upload_protocol = jtag2updi
BeforeUpload(["upload"], [".pio/build/nano_every/firmware.hex"])
Auto-detected: /dev/cu.usbmodem14301
Forcing reset using 1200bps open/close on port /dev/cu.usbmodem14301
Waiting for the new upload port...
avrdude -v -p atmega4809 -C /Users/sstaub/.platformio/packages/tool-avrdude-megaavr/avrdude.conf -c jtag2updi -D -V -b 115200 -e -P "/dev/cu.usbmodem14301" -U flash:w:.pio/build/nano_every/firmware.hex:i -Ufuse2:w:0x01:m -Ufuse5:w:0xC9:m -Ufuse8:w:0x00:m

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/Users/sstaub/.platformio/packages/tool-avrdude-megaavr/avrdude.conf"
         User configuration file is "/Users/sstaub/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/cu.usbmodem14301
         Using Programmer              : jtag2updi
         Overriding Baud Rate          : 115200
JTAG ICE mkII sign-on message:
Communications protocol version: 1
M_MCU:
  boot-loader FW version:        1
  firmware version:              6.00
  hardware version:              1
S_MCU:
  boot-loader FW version:        1
  firmware version:              6.00
  hardware version:              1
Serial number:                   00:00:00:00:00:00
Device ID:                       JTAGICE mkII
         AVR Part                      : ATmega4809
         Chip Erase delay              : 0 us
         PAGEL                         : P00
         BS2                           : P00
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 0
         StabDelay                     : 0
         CmdexeDelay                   : 0
         SyncLoops                     : 0
         ByteDelay                     : 0
         PollIndex                     : 0
         PollValue                     : 0x00
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           prodsig        0     0     0    0 no         61   61      0     0     0 0x00 0x00
           fuses          0     0     0    0 no          9    0      0     0     0 0x00 0x00
           fuse0          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse1          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse2          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse4          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse5          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse6          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse7          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse8          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           lock           0     0     0    0 no          1    0      0     0     0 0x00 0x00
           data           0     0     0    0 no          0    0      0     0     0 0x00 0x00
           usersig        0     0     0    0 no         64   64      0     0     0 0x00 0x00
           flash          0     0     0    0 no      49152  128      0     0     0 0x00 0x00
           eeprom         0     0     0    0 no        256   64      0     0     0 0x00 0x00

         Programmer Type : JTAGMKII_PDI
         Description     : JTAGv2 to UPDI bridge
         M_MCU hardware version: 1
         M_MCU firmware version: 6.00
         S_MCU hardware version: 1
         S_MCU firmware version: 6.00
         Serial number:          00:00:00:00:00:00
         Vtarget         : 5.0 V

avrdude: jtagmkII_initialize(): Cannot locate "flash" and "boot" memories in description
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.27s

avrdude: Device signature = 0x1e9651 (probably m4809)
avrdude: erasing chip
avrdude: reading input file ".pio/build/nano_every/firmware.hex"
avrdude: writing flash (7618 bytes):

Writing | ################################################## | 100% 5.55s

avrdude: 7618 bytes of flash written
avrdude: reading input file "0x01"
avrdude: writing fuse2 (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of fuse2 written
avrdude: reading input file "0xC9"
avrdude: writing fuse5 (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of fuse5 written
avrdude: reading input file "0x00"
avrdude: writing fuse8 (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of fuse8 written

avrdude: safemode: Fuses OK (E:FF, H:FF, L:FF)

avrdude done.  Thank you.

==================================================== [SUCCESS] Took 12.95 seconds ====================================================
sstaub1:#lighthack USB test sstaub$

The script changes the USB PIDs and VIDs to search for, not the PID and VID of the USB device. This is sent by the USB device in the USB descriptors and you’d have to change the firmware or bootloader in order to change these values. I’m not sure where the bootloader for the Arduino Every is. I think the usecase for these scripts is that, given some devices with a customized VID/PID, you can all connect them at once and flash them in a targeted manner.

build.hwids is incorrect in your case. See docs Redirecting...

It should be an array of [VID, PID] pairs.

There is a general misunderstood, I want to change the VID/PID of a board itself, not the search for. When I understood right, this must be done by boot loader or other tools.

1 Like

I was thinking that you’d need to alter the bootloader like is done with some other boards, but it might be simpler than that. From the looks of the BSP for the megaAVR, the VID/PID are set compile time

I don’t have any of the boards, so can’t try it… but perhaps set those two flags (or all four if you want) as platformio.ini build_flags and see if that changes them… and if it does, you’ll probably need to do the PID/VID override for platformio so that it recognises the new IDs.

This does not work, I tried first.

Same problems here as well.
Just to recap, here’s my platformio.ini config:

[env:teensy2pp]
platform = teensy
board = teensy2pp
framework = arduino
build_flags = -D USB_HID
extra_scripts = pre:custon_hwids.py

and my custon_hwids.py python script file:

Import("env")
board_config = env.BoardConfig()
# should be array of VID:PID pairs
board_config.update("build.hwids", [
    ["0x2341", "0x0243"] # VID, PID ?
])

I have reduced edits to the minimum and followed https://docs.platformio.org/en/latest/projectconf/advanced_scripting.html#override-board-configuration as suggested before but problem still persists.
When I type: lsusb to see all my peripherals I cannot see anything like 2341:0243.
What am I doing wrong ?

PS: python 3.8.2, Arch Linux AMD64, latest PlatformIO inside latest VSCode to date (2020-05)

Thanks
Ben

Sure you’re not having the same misunderstanding? As it says above

Since you’re using Teensy 2 with the USB-HID code, the PID and VID is hardcoded for you.

Try to first change that in the soruce code (<home folder>\.platformio\package\framework-arduinoteensy\...) and see if that works, then you can still do a custom platform_package or script to change it on the fly.

2 Likes

Thanks @maxgerhardt, after careful reading your advice I’ve solved it.
I’m fine with current Teensy platform and I’m not that expert (yet) so instead of creating a custom platform_package I have just altered usb_private.h file. After my first successful attempt I’ve scripted it in platformio.ini with something like:

extra_scripts = buildHooks.py

and a 10 lines script to change VID/PID before and after compilation

1 Like

Hi @beninside
I have made a simple joystick and controller and have been trying to change the VID, PID, and name on the Teensy LC boards that are being used in them. I am a hardware guy and trying to figure this out is scrambling my brain. I changed the VID, PID, and name in the C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\usb_hid\usb_private.h file but have had no success in getting the boards to be identified properly. They both are just listed in the device manager as keyboard+mouse+joystick.
Do I have to add anything to the sketch? I’ve read about writing an .ini file but that is so far beyond me.
I’ve been searching for an answer for several weeks now but have yet to find an answer.
Sorry if this is such a noob request but can you help me out?
Thanks
John

Hi @doon1 ,

I have just changed VID,PID defines in usb_private.h to see what happens and it worked, in the same files I’ve also seen descriptions and common information published when I need to collect some usb info (lsusb -v with my OS, but you’ll surely have something like that on Win as well). After that I’ve had some troubles with the Teensy Loader (GUI) and I manually need to reset the Teensy with its button to upload new code.

Now I’ve switched to the cli utility (adding a line in my platformio.ini project file) so when Visual Studio uploads everything I can see output on console without switching to other graphical programs. but I’ve reset VID/PID information to defaults, I’ll do some tests again when I’ll finish real code and real project.

In my final release I’d like to change device descriptions and VID:PID, I’d like to upload new code to device when needed and I don’t want to press reset button to do this. I’ll have more than one teensy device in a closed box without external reset buttons, each Teensy must have different VID:PIDs because they’re doing different things and when I upload my code I’d like to upload to proper device. I still don’t know how to achieve that but hopefully I’ll find a way.

This is something I’ve already had with older AVR devices (ATMega 168,328,…) with V-USB (gcc without Arduino) and avrdude without troubles, I’d like to do the same even if TeensyLoader doesn’t want it.

Still looking information for that, PlatformIO environment is complex but seems to be a really good tool I only need to get “suggested way” and keep it maintainable with more than one device.

I’ll share info when I’ll find something.

1 Like

can you share your working buildHooks.py ?
Thanks !

@beninside Could you share your 10 line scrip to change VID/PID on a Teensy?

This thread is among top results on google, but it is missing just this 1 detail.

I got it working with a teensy 2.0. Here are the steps I took (likely there are ways to optimize this)

Caution: Once you change PID and VID, platform.io will no longer recognize the device as a teensy and you won’t be able to reupload code with platform.io. (Work around is to use teensyduino application)

  1. Find all usb_private.h files in ~/.platform.io directory
find ~/.platformio  -type f -name usb_private.h
/Users/foobar/.platformio/packages/framework-arduinoteensy/cores/usb_disk/usb_private.h
/Users/foobar/.platformio/packages/framework-arduinoteensy/cores/usb_hid/usb_private.h
/Users/foobar/.platformio/packages/framework-arduinoteensy/cores/usb_flightsim/usb_private.h
/Users/foobar/.platformio/packages/framework-arduinoteensy/cores/usb_serial/usb_private.h
/Users/foobar/.platformio/packages/framework-arduinoteensy/cores/usb_serial_hid/usb_private.h
/Users/foobar/.platformio/packages/framework-arduinoteensy/cores/teensy/usb_private.h
/Users/foobar/.platformio/packages/framework-arduinoteensy/cores/usb_rawhid/usb_private.h
/Users/foobar/.platformio/packages/framework-arduinoteensy/cores/usb_midi/usb_private.h

Since I’m using a teensy, I want .platformio/packages/framework-arduinoteensy/cores/teensy/usb_private.h

Looking in that file I see conditional includes depending on what type of device it is (HID, Keyboard, joystick ect…)

#if defined(USB_SERIAL)
#include "usb_serial/usb_private.h"
#elif defined(USB_HID)
#include "usb_hid/usb_private.h"
#elif defined(USB_SERIAL_HID)
#include "usb_serial_hid/usb_private.h"
#elif defined(USB_DISK) || defined(USB_DISK_SDFLASH)
#include "usb_disk/usb_private.h"
#elif defined(USB_MIDI)
#include "usb_midi/usb_private.h"
#elif defined(USB_RAWHID)
#include "usb_rawhid/usb_private.h"
#elif defined(USB_FLIGHTSIM)
#include "usb_flightsim/usb_private.h"
#endif

I chose to set my device to a USB_SERIAL_HID. To do that I modified platform.ini to include a build flag build_flags = -D USB_SERIAL_HID

[env:teensy2]
platform = teensy
board = teensy2
framework = arduino
build_flags = -D USB_SERIAL_HID

I then manually modified usb_serial_hid/usb_private.h with the PID and VID I want

 59 //TODO: Revert these lines
 60 //#define VENDOR_ID               0x16C0
 61 //#define PRODUCT_ID              0x0487
 62 
 63 #define VENDOR_ID               0xAAAA
 64 #define PRODUCT_ID              0xBBBB

Build and upload and observe the PID and VID are now the programmed value.

I would much rather do this in a more repeatable way, but this is good enough for a proof of concept.

system_profiler SPUSBDataType (OSX)
lsusb (linux)

I finally got this working.

Here is how to use a custom VID:PID

The official documentation is here:

Create a script named foobar.py and put it in the same directory as platform.ini

Import("env")

print(env.Dump())

board_config = env.BoardConfig()
# should be array of VID:PID pairs
board_config.update("build.hwids", [
  ["0xAAA", "0xBBB"]
])

In platformio.ini add an extra_scripts stanza and prefix it with either pre: or post:

[env:pro-micro]
platform = atmelavr
board = sparkfun_promicro16
build_flags = -D USB_SERIAL_HID
framework = arduino
extra_scripts = pre:foobar.py

Once you upload code, the VID:PID will be modifed

Hey guys,

I use some ci pipeline on github.

*** missing SConscript file 'custom_hwids.py'

Since some weeks I get following error where I have no clue… this special target came into with a PR a while ago.
I trx to fix it now.



build
failed Jan 18, 2024 in 45s
1s
3s
0s
10s
29s
Run platformio ci --lib="." --project-conf=examples/knx-usb/platformio-ci.ini examples/knx-usb/src/main.cpp
********************************************************************************
If you like PlatformIO, please:
- star it on GitHub > https://github.com/platformio/platformio-core
- follow us on LinkedIn to stay up-to-date on the latest project news > https://www.linkedin.com/company/platformio/
- try PlatformIO IDE for embedded development > https://platformio.org/platformio-ide
********************************************************************************

Project has been successfully updated!
Processing adafruit_feather_m0 (platform: atmelsam@6.0.1; board: adafruit_feather_m0; framework: arduino)
--------------------------------------------------------------------------------
Platform Manager: Installing atmelsam @ 6.0.1
Downloading 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
Unpacking 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
Platform Manager: atmelsam@6.0.1 has been installed!
Tool Manager: Installing platformio/toolchain-gccarmnoneeabi @ ~1.90301.0
Downloading 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
Unpacking 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
Tool Manager: toolchain-gccarmnoneeabi@1.90301.200702 has been installed!
Tool Manager: Installing platformio/framework-arduino-samd-adafruit @ ~1.6.5
Downloading 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
Unpacking 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
Tool Manager: framework-arduino-samd-adafruit@1.6.8 has been installed!
Tool Manager: Installing platformio/framework-cmsis @ ~2.50400.0
Downloading 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
Unpacking 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
Tool Manager: framework-cmsis@2.50400.181126 has been installed!
Tool Manager: Installing platformio/framework-cmsis-atmel @ ~1.2.0
Downloading 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
Unpacking 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
Tool Manager: framework-cmsis-atmel@1.2.2 has been installed!
Tool Manager: Installing platformio/tool-scons @ ~4.40600.0
Downloading 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
Unpacking 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
Tool Manager: tool-scons@4.40600.0 has been installed!
Verbose mode can be enabled via `-v, --verbose` option

*** missing SConscript file 'custom_hwids.py'
File "/opt/hostedtoolcache/Python/3.12.1/x64/lib/python3.12/site-packages/platformio/builder/main.py", line 167, in <module>
========================= [FAILED] Took 28.79 seconds =========================
Error: Process completed with exit code 1.

thats my action https://github.com/OpenKNX/knx/blob/devel/.github/workflows/platform-io.yml
and thats the ini https://github.com/OpenKNX/knx/blob/devel/examples/knx-demo/platformio-ci.ini