Page 1 of 1

Using tinyusb from a component

Posted: Mon Apr 24, 2023 7:24 am
by ghoti57
ESP-IDF 5.0.1
Windows 11

I originally posted this under hardware but in hindsight this is a tool problem so I'm re-posting here (and closing original post)

I can create a fairly trivial project using tinyusb that creates two cdc-acm serial ports and echoes input from each in the other (test.zip).

However if I try to move usb.c and usb.h into a component I can't get the system to build.

In the first instance i just moved usb.c and usb.h to components\usb
created components\usb\CmakeLists.txt
CODE: SELECT ALL

idf_component_register(
SRCS "usb.c"
INCLUDE_DIRS "."
)
and updated main\CMakeLists.txt
CODE: SELECT ALL

# See the build system documentation in IDF programming guide
# for more information about component CMakeLists.txt files.

idf_component_register(
test.zip
simple working project
(2.65 KiB) Downloaded 306 times
SRCS main.c
REQUIRES usb
)
Attempting to build now produces the following errors
CODE: SELECT ALL

<path>/eclipse-workspace/test1/components/usb/usb.c:6:10: fatal error: tinyusb.h: No such file or directory
6 | #include "tinyusb.h"
| ^~~~~~~~~~~
compilation terminated.

<path>/eclipse-workspace/test1/managed_components/espressif__esp_tinyusb/tinyusb.c:12:10: fatal error: esp_private/usb_phy.h: No such file or directory
12 | #include "esp_private/usb_phy.h"
| ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
The first can be fixed by adding a REQUIRES line to components\usb\CMakeLists.txt
CODE: SELECT ALL

idf_component_register(
SRCS "usb.c"
INCLUDE_DIRS "."
REQUIRES tinyusb
)
However, I can find no way to eliminate the second error.
I've tried moving idf_components.yml to various other parts of the project to no avail.
test1.zip is my latest component version

Anybody know how to get rid of this error please

Re: Using tinyusb from a component

Posted: Tue Jan 16, 2024 6:27 am
by broderio
I believe this problem is caused by having a custom component of the same name as the ESP IDF usb component. I was able to get this to compile by renaming your "usb" component to "my_usb" while using ESP-IDFv5.1.2: https://github.com/espressif/esp-idf/tree/v5.1.2. I had to change the main directory CMakeLists.txt to REQUIRE "my_usb" rather than "usb":

Code: Select all

# See the build system documentation in IDF programming guide
# for more information about component CMakeLists.txt files.

idf_component_register(
    SRCS main.c
    REQUIRES my_usb
)
Here is the rewritten test1 that you provided as it was when I was able to compile it.
test1_fixed.zip
(23.68 KiB) Downloaded 254 times