Question about probing details of Teensy 4 USB stack

tew468

Member
I am trying to figure out if there is a "simple" way at run-time for a Teensy 4 application to determine what specific values were held by a few private TeensyDuino constants at time of compilation.

I have a custom circuit powered by a Teensy 4 that can, under certain conditions, draws brief surges of 300mA from the USB port.

The default value of bMaxPower is set at "50"in the cores/teensy4/usb_desc.c file, which informs the host that the device will draw no more than 100mA of current.
If leave the default unchanged, my application will start to run, but then the host disconnects the device when it pulls over 100mA of current.

For my application, I increased the bMaxPower value from 50 to 200 (e.g. 400mA) for both the 480 megabit/sec and 12 megabit/sec instances, and then everything works just peachy.

The issue I'm trying to address is that my colleague (on the other side of the state) has a slightly different configuration than I do. I've tried to provide a set of instructions for how to modify the bMaxPower value on his installation, but he is still getting the occasional USB host disconnects due to excessive power consumption. I'm wondering if I can add a simple "sanity check" at the beginning of my Teensy app to test or print out those values. (Yes, I can theoretically also query the host for the specific USB device to ask the host how much power the USB device said it would take, but I'm hoping there's a simple way to check on the Teensy side...)

However, when I try a simple test app:
C++:
#include <usb_desc.h>

const uint8_t bMaxPower_480 = usb_config_descriptor_480[8];
const uint8_t bMaxPower_12 = usb_config_descriptor_12[8];


void setup() {
  Serial.begin(230400);
  delay(40);
  Serial.printf("usb_config_descriptor_12[bMaxPower] =%u (should be >=200)\n", bMaxPower_12);
  Serial.printf("usb_config_descriptor_480[bMaxPower]=%u (should be >=200)\n", bMaxPower_480);
}

void loop() {
  yield();
}


I get the error message
Code:
/Users/xxxxxx/Development/arduino/check_USB_params/check_USB_params.ino:4:31: error: 'usb_config_descriptor_480' was not declared in this scope
    4 | const uint8_t bMaxPower_480 = usb_config_descriptor_480[8];
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/xxxxxx/Development/arduino/check_USB_params/check_USB_params.ino:5:30: error: 'usb_config_descriptor_12' was not declared in this scope
    5 | const uint8_t bMaxPower_12 = usb_config_descriptor_12[8];
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~

exit status 1

Compilation error: 'usb_config_descriptor_480' was not declared in this scope


and looking at the top of cores/teensy4/usb_desc.h, there is a clearly printed warning:
Code:
// This header is NOT meant to be included when compiling
// user sketches in Arduino.  The low-level functions
// provided by usb_dev.c are meant to be called only by
// code which provides higher-level interfaces to the user.

So, my question is (even though I know I'm not "supposed" to do it), is there a simple way I can read/test the value assigned to those constants at compile time from within my arduino app that does not require changing (formerly) "static" (private) values in the core teensy4 library to be externally visible and linkable?


All ideas / suggestions are welcome.

Thank you,
-Tom
 
Try this:
C++:
extern "C" const uint8_t usb_config_descriptor_480[];
extern "C" const uint8_t usb_config_descriptor_12[];

const uint8_t bMaxPower_480 = usb_config_descriptor_480[8];
const uint8_t bMaxPower_12 = usb_config_descriptor_12[8];


void setup() {
  Serial.begin(230400);
  delay(40);
  Serial.printf("usb_config_descriptor_12[bMaxPower] =%u (should be >=200)\n", bMaxPower_12);
  Serial.printf("usb_config_descriptor_480[bMaxPower]=%u (should be >=200)\n", bMaxPower_480);
}
 
Back
Top