Replies: 3 comments 9 replies
-
Hi there, I have a similar problem. From reading as much of the TinyUSB docs as are available, I can see that it would help to enable the driver log output. This is mentioned here: https://docs.tinyusb.org/en/latest/reference/getting_started.html However, I am using the board "Adafruit Feather RP2040 with USB Type A Host" and the Arduino IDE and cannot for the life of me work out how to pass that make flag "LOG 2" to the compiler from Arduino. Any advice here? |
Beta Was this translation helpful? Give feedback.
-
This post is for anyone else trying to use the TinyUSB library with Arduino IDE and any one of the Adafruit RP2040 boards (in my case I am using a "Adafruit Feather RP2040 with USB Type A Host" board). The library has a lot of logging and debugging built in, but the library was originally written in a generic way which is not immediately compatible with Arduino. The contributors to this project have done a good job getting it going on Arduino, so please don't take anything I write here as a criticism, I am simply commenting on the state of the project at the time of writing and trying to help out anyone else who finds themselves in a similar situation to myself and the OP to this thread. Firstly, our motivation is to get the TinyUSB log/debug output enabled so we can debug our USB devices (some unknown/unmounted) when using the library in host mode. The next part is to enable the logging feature. This is done by setting this flag at the top of your sketch: #define CFG_TUSB_DEBUG 2 That is supposed to be equivalent to compiling the library with a flag of "LOG 2" in the command line. However, that does not enable any output. Note that comments from others suggest the output is on Serial1 rather than Serial, but I am checking both outputs and there is just nothing there. Both outputs work correctly when I write to them, so we can exclude simple and obvious issues like wiring problems or use of the wrong pins. Pulling apart the library I can follow the debugging output: The debugging fills up a buffer which is then written out. The function that does so uses a function called "tu_print_buf". Elsewhere, that function is remapped onto "printf" with the following declaration. #define tu_printf printf So this means the library debugging output is directed to the standard function "printf" which directs to standard out (stdout). However, there is no such thing on Arduino: https://forum.arduino.cc/t/printf-on-arduino/888528 "printf prints to stdout. Arduino has no stdout." That forum post then has a lot of back and forth about whether Arduino does have "stdout" and how it can be enabled. There are, however, no clear instructions on how to do this. I will make a comment here. The TinyUSB library does offer alternative debugging output. Those are mentioned in the library docs and exist because serial debugging output is slow. For our application, working out why on earth some devices are identified/mounted by the library, and others not, we do not care at all about the speed. The docs go on to mention two alternative debuggers "rtt" and "swo". From what I can follow, neither of these will work with the board I have ("Adafruit Feather RP2040 with USB Type A Host") out of the box, where as my Serial1 pins are right there, all set up, and should be easy to use, as is the USB serial. So now I'm trying to remap printf to something else, such as a custom function that will simply output to serial. I am trying to do this using the standard library. If I can't do this, I'll rework the library and go down that route. I thought I could write my own function to replace "printf" and then declare a macro as so: #define printf myprintf But I don't understand whether this will apply to the library, and whether it should be declared before or after the library inclusion. So far it has not worked. The point of my post is to ask for help and guidance on how best to proceed. As others claim that this "works" there is probably something obvious I have missed. Thank you in advance. |
Beta Was this translation helpful? Give feedback.
-
TinyUSB Arduino Library - How to Enable Debugging Platform: Arduino (in my case, IDE v2.3.3, but that should not matter) Library: "Adafruit TinyUSB Library" by Adafruit (v3.4.1) Board: "Adafruit Feather RP2040 with USB Type A Host" from the board collection "Raspberry Pi Pico/RP2040/RP2350" by Earle F. Philhower, III (v4.3.0) Objective: To use the library to drive a USB host that interfaces with various USB devices. In my case, USB mice, but the general approach could apply to any device. We want to enable the debugging output so we can work out why any given device is not being mounted by the library. Do not attempt to set any flags in your sketch or .h files, this will not work and you are only wasting your time. Libraries are downloaded by the Arduino IDE into a specific folder on your computer. On Linux this folder is ~/Arduino/libraries but on Windows it will be somewhere else. You may have to look this up before you continue. Navigate to the Arduino libraries folder and locate the following .h file. Open it in a text editor for editing: LIBRARIES FOLDER/Adafruit_TinyUSB_Library/src/arduino/ports/rp2040/tusb_config_rp2040.h Go to line 68 and change the log level as per the following example, which sets it to level 2. The available levels are 0, 1, 2, and 3, in order of increasing amounts of output. #ifndef CFG_TUSB_DEBUG Compile your sketch and flash it to your board. PLEASE NOTE: With the library edited in this way it will affect any and all sketches that use the library. Furthermore, when the library is updated your changes will be lost. PLEASE NOTE: Testing on this board confirms that debug information is sent to "Serial1" output which is set up by the library. You do not need to call Serial1.begin(...) in your own sketch. Furthermore, the baud rate seems to be something high (I had success with 115200) and using a low default value like 9600 will result in garbled characters appearing in the serial monitor. Serial1 on this board is exposed at the pins labelled "TX" and "RX". PLEASE NOTE: As warned elsewhere, enabling the debugging output over serial will slow down operation of the library and this could interfere with USB operation. However, the debug output is essential for identification of unknown devices and troubleshooting why the library won't mount them. PLEASE NOTE: A quirk of these boards is that USB serial is not enabled unless you call Serial.begin(...) in your sketch. This can be confusing as a blank sketch flashed to the RP2040 will result in no USB serial port appearing on the computer, meaning the only way to flash a new sketch to the device is to manually put it into bootloader mode (power cycle while holding down the BOOT button) and then choosing the "UF2 device" port in the Arduino IDE. Since Serial1 is being used here for the TinyUSB debugging, you might want to put your own debugging messages onto Serial, which is the USB serial, and can be started in the usual way in the setup() method using: Serial.begin(115200); Because of the aforementioned issues with the appearance of the USB serial and flashing the board, I find I always keep "Serial.begin(115200);" in the setup on all of my sketches, regardless of whether I use it for anything. |
Beta Was this translation helpful? Give feedback.
-
I encountered some issues when using the Adafruit-TinyUSB-Arruino library. I have two mice, one of which cannot read the scroll wheel value and the other cannot read the side key value. I think it's a compatibility issue. Can you teach me how to solve it? Thank you
Beta Was this translation helpful? Give feedback.
All reactions