PlatformIO Community

Changing USB device VID PID

It is possible to change the USB VID and PID within the platformio.ini
instead of changing the IDs in the board .json file?

1 Like

Any ideas? I think I have seen another post.

There is http://docs.platformio.org/en/latest/projectconf/section_env_board.html#more-options
However, it does not work for arrays.

So, extra scripting will help here http://docs.platformio.org/en/latest/projectconf/advanced_scripting.html#override-board-configuration

1 Like

Thank you, good to know. :grinning:

Found this thread through google and helped me out in getting my multiple arduinos set up for a flight sim. Here’s a summary of what I did from the link provided above:

  • in platformIO locate ‘platform.ini’ in base project folder
  • add “extra_scripts = pre:custon_hwids.py” into ‘platform.ini’.
  • add a file into the main project folder and label it ‘custom_hwids.py’ or anything as long as it matches what was added to ‘platform.ini’
  • the link provided input on changing VIDS and PIDS through a HWID array (first block is VIDS, second block is PIDS)
  • you can also use board_config.update(“build.usb_product”, “Right Leo”) to relabel the board that windows sees.

Import(“env”)

board_config = env.BoardConfig()

board_config.update(“build.hwids”, [
[“0x2341”, “0x2341”, “0x2A03”, “0x2A03”], #VIDS
[“0x0036”, “0x8036”, “0x0036”, “0x8036”] #PIDS
])

board_config.update(“build.usb_product”, “Right Leo”)

1 Like

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 https://docs.platformio.org/en/latest/projectconf/advanced_scripting.html#override-board-configuration

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.