Adding New USB Type into the Arduino 2.x Tools Menu - K7MDL2/KEITHSDR GitHub Wiki

I use this procedure to add a Custom USB type for the Teensy to enable 2 Serial ports plus Audio to the Arduino 2.0 IDE. This enables debug on Serial and the optional CAT interface on USBSerial1.

Be sure to see 48KHz AUSB Audio Wiki Page for the 48Khz audio related changes. This procedure is focused on adding the device properly to the PC. with one small exception, the audio sample rate changes are located in other files.

Note: I supply several patched library files in my SDR_RA8875\libraries folder. As of Jan 3rd, these files are patched for the TeensyDuino 1.57.2. There is no guarantee that future or past lib files are the same so instruction are provided here to attempt to patch the version you have in case they have changed.

Note: This is for Arduino 2.0. It did, and should still, work on 1.8.19. For troubleshooting reasons, I have deleted all Arduino pre-IDE 2.0 installs and tools so this is focused on 2.0. I used 2.0.3 when this was first written Jan 3, 2023.

Add this section into usb_desc.h after the USB_AUDIO section.

#elif defined(USB_SERIAL_SERIAL_AUDIO)
  #define VENDOR_ID		0x16C0
  #define PRODUCT_ID		0x048A    // Ideally this should be a unique #, but the tools PID list is hard coded
  #define MANUFACTURER_NAME	{'T','e','e','n','s','y','d','u','i','n','o'}
  #define MANUFACTURER_NAME_LEN	11
  #define PRODUCT_NAME		{'K','7','M','D','L',' ','S','D','R'}    // custom, because we can!
  #define PRODUCT_NAME_LEN      9  // make sure this matches your product name length above.
  #define EP0_SIZE	       64
  #define NUM_ENDPOINTS         7   // 5 for 2 serial, + 2 for audio
  #define NUM_INTERFACE	        7   // 4 for 2 serial, + 3 for audio
  #define CDC_IAD_DESCRIPTOR	1
  #define CDC_STATUS_INTERFACE	0
  #define CDC_DATA_INTERFACE	1	// Serial
  #define CDC_ACM_ENDPOINT	2
  #define CDC_RX_ENDPOINT       3
  #define CDC_TX_ENDPOINT       3
  #define CDC_ACM_SIZE         16
  #define CDC_RX_SIZE_480     512
  #define CDC_TX_SIZE_480      512
  #define CDC_RX_SIZE_12        64
  #define CDC_TX_SIZE_12        64
  #define CDC2_STATUS_INTERFACE 2       // SerialUSB1
  #define CDC2_DATA_INTERFACE   3
  #define CDC2_ACM_ENDPOINT     4
  #define CDC2_RX_ENDPOINT      5
  #define CDC2_TX_ENDPOINT      5
  #define AUDIO_INTERFACE	4	// Audio (uses 3 consecutive interfaces)
  #define AUDIO_TX_ENDPOINT     6
  #define AUDIO_RX_ENDPOINT     6
  #ifdef USB_AUDIO_48KHZ
	#define AUDIO_TX_SIZE         196   // longer buffer
	#define AUDIO_RX_SIZE         196
  #else
	#define AUDIO_TX_SIZE         180
	#define AUDIO_RX_SIZE         180
  #endif
  #define AUDIO_SYNC_ENDPOINT	7
  #define ENDPOINT2_CONFIG	ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT
  #define ENDPOINT3_CONFIG	ENDPOINT_RECEIVE_BULK + ENDPOINT_TRANSMIT_BULK
  #define ENDPOINT4_CONFIG	ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT
  #define ENDPOINT5_CONFIG	ENDPOINT_RECEIVE_BULK + ENDPOINT_TRANSMIT_BULK
  #define ENDPOINT6_CONFIG	ENDPOINT_RECEIVE_ISOCHRONOUS + ENDPOINT_TRANSMIT_ISOCHRONOUS
  #define ENDPOINT7_CONFIG	ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_ISOCHRONOUS

To add custom Serial + Serial + Audio USB Type into the IDE

Modify C:\Users[username]\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.57.2\cores\teensy4\boards.txt by adding these 3 lines into the teensy41.menu section. Can add to the teensy40.menu section if you like.

Substitute your TeensyDuino version number. For example, here I have 1.57.2, I am currently on 0.58.3

NOTE: the correct way to add custom lines is to put these lines into boards.local.txt. The IDE merges them. However, VS Code does not fully support IDE 2.0 yet, and VS Code board manager ignores boards.local.txt. A bug has been filed. So for now will stay with modifying boards.txt.

Modify boards.txt located in %AppData%\Local\Arduino15\packages\teensy\hardware\avr\1.57.2.

teensy41.menu.usb.serialserialaudio=Serial + Serial + Audio
teensy41.menu.usb.serialserialaudio.build.usbtype=USB_SERIAL_SERIAL_AUDIO
teensy41.menu.usb.serialserialaudio.upload_port.usbtype=USB_SERIAL_SERIAL_AUDIO

This file, via the UI, sets the #define (USB_SERIAL_SERIAL_AUDIO in this case) that is consumed in usb_desc.h to set the right interfaces and endpoints.

Shutdown the Arduino IDE. The IDE caches this file content so we must delete a folder. See https://github.com/arduino/arduino-ide/issues/1030. For Windows users, this is typically %AppData%\Roaming\arduino-ide. I find that deleting the folder %AppData%\Roaming\arduino-ide\Local Storage\leveldb is all that is needed. This lets you see our new Serial+Serial+Audio USB Type display in the menu and get a correct compile.

NOTE: The USB Type label is a hard coded list inside the port monitoring tools. They match device VID and PID numbers to a fixed list of USB Type names. If you use an existing PID (PRODUCT_NAME) number in usb_desc.h, the menu will show that device combo name. PID=0x048A for example will display Serial+MIDI+Audio. PID=0x0484, being unique and unused, will display as "unknown" type. While this is incorrect and confusing, it is harmless and to be expected until this is resolved in future tools updates. See Discussion for more on this. For now, our custom Type will not display on the Ports menus but you will get your desired compile results.

Start the Arduino IDE 2.0, you should see some errors. This is expected while it rebuilds the cache. Restart the IDE and it will come up clean.

Under Tools:Board choose Teensy 4.1

Tools:Port choose the port displayed under the teensy ports section. The correct name may not show up until you do your first compile, maybe not even then but you will see 2 serial ports.

Tools:CPU Speed choose 816MHz (recommended, but anything you like that works)

Tools:USB Type choose Serial + Serial + Audio. This is our custom device type.

Due to the port tools hard coded PID list issue mentioned above, you will see 'Teensy: COMx Unkown (Teensy 4.1)' or if you used PID=0x048A you will see 'COMx Serial+Audio+MIDI (Teensy 4.1)'. You should still have 2 serial ports and audio working despite this incorrect display name. It is recommended that when choosing a serial port, pick the one listed under 'teensy ports'. This port type is recognized as the USB HID device and works best.

If DEBUG is enabled in top of SDR_RA8875.h, debug output will be on the first serial port.

If you have the RS_HFIQ, the second serial port will be CAT control at 38400 which emulates an Elecraft K3.