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)
- 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:
- Extra Python packages — PlatformIO latest documentation
- Pre & Post Actions — PlatformIO latest documentation
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