1

I'm working on a custom Arduino core based on the teensy code and want to be able to get the board USB VID/PID from boards.txt, as in .board.vid and .board.pid

From what I can tell, Arduino already does this for the Leonardo and similar since if I change the VID/PID in boards.txt then the sketch will run with those values.

But how do I actually get at them? Right now the code I have has hard coded values, but it would be great to make them dynamic.

1

The preprocessor will sub in the values for the names "USB_PID" and "USB_VID"

this line in "platform.txt" grabs them and makes build flags for them:

build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}'

the -D* option in the build is equivalent to the following lines being in the code

#define USB_VID /*value of build.vid*/
#define USB_PID /*value of build.pid*/
#define USB_MANUFACTURER /*value of build.usb_manufacturer*/
#define USB_PRODUCT /*value of build.usb_product*/

If you are curious, they are used by the libraries in "USBCore.cpp". Also, they will never be defined for devices they don't apply to.

  • Weird though... could not get manufacturer and product to work. VID/PID worked fine though. – Adam Haile Oct 26 '14 at 5:34
  • That is odd. What version of arduino are you using? That came from 1.5.8 – BrettAM Oct 26 '14 at 5:40
  • No wonder I couldn't find platform.txt... I'm using 1.0.5 I swear there was a reason I hadn't upgraded to the beta yet, but can't remember what that was at the moment... think it was incompatible with something I needed. – Adam Haile Oct 26 '14 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.