Fix for boards.txt not updating is no longer valid

mborgerson

Well-known member
At the top of boards.txt for TD 1.59 there is this:

# Solution for Arduino IDE 2.0 recognizing changes to this file:
# https://github.com/arduino/arduino-ide/issues/1030#issuecomment-1152005617

The solution at GitHub from @per1234 is:

I'll share the workaround:
  1. Select File > Quit from the Arduino IDE menus if it is running.
  2. Delete the "User data" folder:
    • Windows:
      • C:\Users\<user name>\AppData\Roaming\arduino-ide\
    • Linux:
      • ~/.config/arduino-ide/
    • macOS:
      • ~/Library/Application Support/arduino-ide/
  3. Start the Arduino IDE.
The custom board options menus should now reflect any changes that were made to boards.txt.
👍1
That solution is no longer valid in Windows, as there is no "User data" folder at that location in IDE 2.3.1. Somewhere in researching the topic, I ran across the suggestion to delete the whole arduino-ide folder. That works, but does cause some library reload activity when the ide is restarted.

I also encountered problems when I tried to add a new device to the USB type menu. I added my "Serial + USBTMC [experimental] " item just after
"Serial + USBTMC [experimental]" in boards.txt and made the required changes to usb_desc.h, usb_desc., etc. in cores/Teensy4. When I compile the code, I get the descriptors for "Serial + USBTMC [experimental] ".

I have fallen back to my previous method of 'borrowing' the menu for USB "Triple Serial" and making my cores/Teensy4 changes under that device. I then get the proper descriptors for my project.
 
OK,
but there must be a place where Arduino copies the one provided by TD.
Someone knows where this is?
 
Update: It seems you can make cosmetic changes to the USB type menu, and long as you don't change the number of items or their order.

Code:
In boards.txt:

teensy41.menu.usb.serial=Serial
teensy41.menu.usb.serial.build.usbtype=USB_SERIAL
teensy41.menu.usb.serial.upload_port.usbtype=USB_SERIAL
teensy41.menu.usb.serial2=Dual Serial
teensy41.menu.usb.serial2.build.usbtype=USB_DUAL_SERIAL
teensy41.menu.usb.serial2.upload_port.usbtype=USB_DUAL_SERIAL
teensy41.menu.usb.serial3=Serial + USBTMC [experimental]<---Cosmetich change only. Not change to order or #items
teensy41.menu.usb.serial3.build.usbtype=USB_TRIPLE_SERIAL <---- mess with this and I don't see a serial port in device
teensy41.menu.usb.serial3.upload_port.usbtype=USB_TRIPLE_SERIAL
teensy41.menu.usb.keyboard=Keyboard
teensy41.menu.usb.keyboard.build.usbtype=USB_KEYBOARDONLY
teensy41.menu.usb.keyboard.upload_port.usbtype=USB_KEYBOARDONLY
teensy41.menu.usb.keyboard.fake_serial=teensy_gateway
The next step is to adjust usb_desc.h to add my device and interfaces:
Code:
In cores/Teensy4/usb_desc.h:

#elif defined(USB_TRIPLE_SERIAL) // Borowing the Triple Serialpositon to avoid sorting issues
  // added to cores/teensy4   2/16/2024
  // Cosmetic change only menu text
  // defines inserted between DUAL_SERIAL and USB_KEYBOARD_ONLY
  // although it may not matter where the defines go in file.
  #define VENDOR_ID        0x16C0
  #define PRODUCT_ID    0x04D8  // My chosen ID for Serial + USBTMC [experimental]
  #define MANUFACTURER_NAME    {'T','e','e','n','s','y','d','u','i','n','o'}
  #define MANUFACTURER_NAME_LEN    11
  #define PRODUCT_NAME        {'T','e','e','n','s','y',' ','U','S','B','T','M','C'}
  #define PRODUCT_NAME_LEN        13
  #define EP0_SIZE                64
  #define NUM_ENDPOINTS         4
  #define NUM_INTERFACE            3   
  #define CDC_IAD_DESCRIPTOR    1
  #define CDC_STATUS_INTERFACE    0
  #define CDC_DATA_INTERFACE    1    // Serial port to receive commands
  #define CDC_ACM_ENDPOINT        2   // and send debugging text to host
  #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 USBTMC_INTERFACE        2  // USBMTC
  #define USBTMC_TX_ENDPOINT    4
  #define USBTMC_RX_ENDPOINT    4
  #define USBTMC_TX_SIZE_12        64
  #define USBTMC_TX_SIZE_480    512
  #define USBTMC_RX_SIZE_12        64
  #define USBTMC_RX_SIZE_480    512

  #define ENDPOINT2_CONFIG    ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT  // CDC ACM
  #define ENDPOINT3_CONFIG    ENDPOINT_RECEIVE_BULK + ENDPOINT_TRANSMIT_BULK     // CDC DATA
  #define ENDPOINT4_CONFIG    ENDPOINT_RECEIVE_BULK + ENDPOINT_TRANSMIT_BULK     // USBTMC

#elif defined(USB_KEYBOARDONLY)




Once my USBTMC defines are in place, I modified cores/Teensy4/usb_desc.c:

Code:
at about line 633,  I added the defines that set the position of the USBTMD descriptor inside the full device descriptor.
You not only have to get your own interface position and size correct, you also have to modify the position defines 
before and after your own interface.


#define MTP_INTERFACE_DESC_POS        JOYSTICK_INTERFACE_DESC_POS+JOYSTICK_INTERFACE_DESC_SIZE
#ifdef  MTP_INTERFACE
#define MTP_INTERFACE_DESC_SIZE        9+7+7+7
#else
#define MTP_INTERFACE_DESC_SIZE    0
#endif
// add my USBTMC interface position and size
#define USBTMC_INTERFACE_DESC_POS        MTP_INTERFACE_DESC_POS+MTP_INTERFACE_DESC_SIZE
#ifdef  USBTMC_INTERFACE
#define USBTMC_INTERFACE_DESC_SIZE        9+7+7
#else
#define USBTMC_INTERFACE_DESC_SIZE    0
#endif
// adjust the following interface to account for USBTMC position and size.
#define KEYMEDIA_INTERFACE_DESC_POS    USBTMC_INTERFACE_DESC_POS+USBTMC_INTERFACE_DESC_SIZE
#ifdef  KEYMEDIA_INTERFACE
#define KEYMEDIA_INTERFACE_DESC_SIZE    9+9+7
#define KEYMEDIA_HID_DESC_OFFSET    KEYMEDIA_INTERFACE_DESC_POS+9
#else
#define KEYMEDIA_INTERFACE_DESC_SIZE    0
#endif

At about line 1704 in cores/Teensy4/usb_desc.c
#endif // EXPERIMENTAL_INTERFACE

// add in contents for USBTMC interface
#ifdef USBTMC_INTERFACE
    // configuration for 480 Mbit/sec speed
        // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
        9,                                      // bLength
        4,                                      // bDescriptorType
        USBTMC_INTERFACE,        // bInterfaceNumber
        0,                                      // bAlternateSetting
        2,                                      // bNumEndpoints  just two: Bulk IN and Bulk OUT
        0xFE,                                   // bInterfaceClass (0xFE = App. Specific)
        0x03,                                   // bInterfaceSubClass (0x03 = USBTMC)
        0x00,                                   // bInterfaceProtocol (0x00 = USBTMC)
        3,                                      // iInterface
        // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
        7,                                      // bLength
        5,                                      // bDescriptorType
        USBTMC_TX_ENDPOINT | 0x80,                 // bEndpointAddress
        0x02,                                   // bmAttributes (0x02=bulk)
        0x00,0x02,                            // unexpected problems with the LSB and USB macros---avoided by hard-coded values
 //       LSB(USBTMC_TX_SIZE_480),MSB(USBTMC_TX_SIZE_480), // wMaxPacketSize
        0,                                      // bInterval
        // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
        7,                                      // bLength
        5,                                      // bDescriptorType
        USBTMC_RX_ENDPOINT,                        // bEndpointAddress
        0x02,                                   // bmAttributes (0x02=bulk)
        0x00,0x02,                          // unexpected problems with the LSB and USB macros---avoided by hard-coded values
//        LSB(USBTMC_RX_SIZE_480),MSB(USBTMC_RX_SIZE_480), // wMaxPacketSize
        0,                                      // bInterval

#endif // USBTMC_INTERFACE

};

Once I surfaced from that sea of #ifdefs, I became reluctant to dive in again--so I haven't done much with it in the last few days. I've now moved on to implementing and testing the host and device code that actually sends bytes back and forth. I'm currently testing the transmission of 8KB transfers from device to host. I'm using an IntervalTimer to send packets from device to host at regular intervals. I expect this part of the code to be critical in applications that use a T4.x USBTMC device to collect data at high rates and forward it to the host for evaluation, modification, and storage.
 
Back
Top