Skip to content

Adding New USB Type into the Arduino 2.x Tools Menu

K7MDL edited this page Dec 27, 2022 · 3 revisions

I used 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.

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		0x048C
  #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'}
  #define PRODUCT_NAME_LEN      9
  #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

Note: as a workaround the file usb_desc.h I supply in libraries folder has the same contents for USB_SERIAL_MIDI_AUDIO. More below.

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.

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

Make sure the file matches the version in C:\Users\Mike\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.57.2. Not sure how this gets updated.

There is a problem getting the IDE to properly process a new entry so this can also work. Repurpose/rename the menu item for the existing SERIAL_MIDI_AUDI

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

This causes the menu which had Serial + MIDI + AUDIO to now show as SERIAL + SERIAL + AUDIO, same as above, but the compiler recognizes it better.

The boards.txt I supply in the libraries/cores_IDE_2.0_1.57.2 has this modification already made. This file sets the #define that is consumed in usb_dec.h to set the right interfaces and endpoints. For now, USB_SERIAL_MIDI_AUDIO is identical to USB_SERIAL_SERIAL_AUDIO.

Shutdown the Arduino IDE

There is a bug in IDE/CLI that does not update the IDE when the board.txt is changed. Delete the cached IDE file so that the modified boards.txt changes will show on the IDE tool USB type menu and become a valid compile option. See https://github.com/arduino/arduino-ide/issues/1030. For Windows users, this is typically C:\Users<user name>\AppData\Roaming\arduino-ide. I found this to fix the menu part of the problem, but the ports refuse the show properly the serial+Serial+Audio, instead I get Triple Serial.

Start the Arduino IDE 2.0

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 IDE issue mentioned above, you may see Triple Serial or the previous Serial+Audio+MIDI. You should still have 2 serial ports and audio working.

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.