Skip to content

Commit baf65f5

Browse files
authored
Add notes on TinyUSB documentation and quirks (#659)
Fixes #648
1 parent 13f68fb commit baf65f5

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

docs/usb.rst

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,61 @@ Also, this stack requires sketches to manually call
4646
sketch upload from the IDE. If a sketch is run without this command
4747
in ``setup()``, the user will need to use the standard "hold BOOTSEL
4848
and plug in USB" method to enter program upload mode.
49+
50+
Adafruit TinyUSB Configuration and Quirks
51+
-----------------------------------------
52+
53+
The Adafruit TinyUSB's configuration header for RP2040 devices is stored
54+
in ``libraries/Adafruit_TinyUSB_Arduino/src/arduino/ports/rp2040/tusb_config_rp2040.h`` (`here <https://github.com/adafruit/Adafruit_TinyUSB_Arduino/blob/master/src/arduino/ports/rp2040/tusb_config_rp2040.h>`__).
55+
56+
In some cases it is important to know what TinyUSB is configured with. For example, by having set
57+
58+
.. code:: cpp
59+
60+
#define CFG_TUD_CDC 1
61+
#define CFG_TUD_MSC 1
62+
#define CFG_TUD_HID 1
63+
#define CFG_TUD_MIDI 1
64+
#define CFG_TUD_VENDOR 1
65+
66+
this configuration file defines the maximum number of USB CDC (serial)
67+
devices as 1. Hence, the example sketch `cdc_multi.ino <https://github.com/adafruit/Adafruit_TinyUSB_Arduino/blob/master/examples/CDC/cdc_multi/cdc_multi.ino>`__
68+
that is delivered with the library will not work, it will only create one
69+
USB CDC device instead of two. It will however work when the above
70+
``CFG_TUD_CDC`` macro is defined to 2 instead of 1.
71+
72+
To do such a modification when using the Arduino IDE, the file can be
73+
locally modified in the Arduino core's package files. The base path can
74+
be found per `this article <https://support.arduino.cc/hc/en-us/articles/360018448279-Open-the-Arduino15-folder>`__,
75+
then navigate further to the ``packages/rp2040/hardware/rp2040/<core version>/libraries/Adafruit_TinyUSB_Arduino``
76+
folder to find the Adafruit TinyUSB library.
77+
78+
When using PlatformIO, one can also make use of the feature that TinyUSB
79+
allows redirecting the configuration file to another one if a certain
80+
macro is set.
81+
82+
.. code:: cpp
83+
84+
#ifdef CFG_TUSB_CONFIG_FILE
85+
#include CFG_TUSB_CONFIG_FILE
86+
#else
87+
#include "tusb_config.h"
88+
#endif
89+
90+
And as such, in the ``platformio.ini`` of the project, one can add
91+
92+
.. code:: ini
93+
94+
build_flags =
95+
-DUSE_TINYUSB
96+
-DCFG_TUSB_CONFIG_FILE=\"custom_tusb_config.h\"
97+
-Iinclude/
98+
99+
and further add create the file ``include/custom_tusb_config.h`` as a copy
100+
of the original ``tusb_config_rp2040.h`` but with the needed modifications.
101+
102+
*Note:* Some configuration file changes have no effect because upper levels
103+
of the library don't properly support them. In particular, even though the
104+
maximum number of HID devices can be set to 2, and two ``Adafruit_USBD_HID``
105+
can be created, it will not cause two HID devices to actually show up, because
106+
of `code limitations <https://github.com/adafruit/Adafruit_TinyUSB_Arduino/blob/7264c1492a73d9a285512752b03f2550841c06bc/src/arduino/hid/Adafruit_USBD_HID.cpp#L36-L37>`__.

0 commit comments

Comments
 (0)