esp-idf icon indicating copy to clipboard operation
esp-idf copied to clipboard

Component manager not supported in IDF as a Lib project ? (IDFGH-12375)

Open AdrianSoundy opened this issue 1 year ago • 14 comments

Answers checklist.

  • [X] I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • [X] I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • [X] I have searched the issue tracker for a similar issue and not found a similar issue.

General issue report

When trying to port the nanoFramework project from IDF 4.x to 5.1.3 have found that the tinyusb component is no longer a core component and has to used from the Component registry instead. There doesn't seem to be any documentation for doing this.

Testing with the Cmake/idf_as_lib example I was unable to get the component to be loaded by adding a idf_component.yml file to the example project. It doesn't seem to be recognized.

Looking at the IDF_COMPONENT_MANAGER build property found it defaults to 0. Forcing it to 1 causes a whole heap of other errors.

The documentation says the component manager is available for all project types. But this doesn't seem to be the case.

  • How do you use a component from the component registry in a IDF as a Lib project ?
  • Have an example to show how to use a component from component registry not just core components.

AdrianSoundy avatar Mar 18 '24 03:03 AdrianSoundy

Hello @AdrianSoundy

Unfortunately, as for now it's true, the component manager is only supported in the projects using IDF's tools/cmake/project.cmake.

One possible workaround is to manually download all required components from the registry (download link can be found on the page) and put them, for example, to the IDF's components directory.

kumekay avatar Mar 18 '24 18:03 kumekay

Thanks for confirming this is the case. The documentation for the IDF as Library should be updated to reflect this as its currently unclear.

I have now managed to get it working by downloading the tinyusb and esp_tinyusb components to the IDF components directory.

To make it easier for next person I have written out below what I needed to do to get it to build.

I had to delete the 'idf_component.yml' file from components downloaded as I got a warning that the component manager is not enabled.

Also to sort out the dependencies between the esp_tinyusb and tinyusb and build without error.

Add components to idf_build_process in order tinyusb esp_tinyusb Add libraries for linking in order esp_tinyusb tinyusb otherwise link errors

Also added following to cmake to add tinyusb includes for esp_tinyusb and compile definition for tinyusb target type.

    # get the esp_tinyusb target library name
    idf_component_get_property(etusb_lib esp_tinyusb COMPONENT_LIB)
    # add the tinyusb src directory as include path to esp_tinyusb library project
    target_include_directories(${etusb_lib} PRIVATE ${esp32_idf_SOURCE_DIR}/components/tinyusb/src)

    # also add the freertos directory as include path
    idf_component_get_property(freertos_include freertos ORIG_INCLUDE_PATH)
    target_include_directories(${etusb_lib} PRIVATE ${freertos_include})

    # Set the CFG_TUSB_MCU compile option for the target MCU
    # for esp_tinyusb lib and main project
    if(${TARGET_SERIES_SHORT} STREQUAL "esp32s3")
        set(tusb_mcu "OPT_MCU_ESP32S3")
    elseif(${TARGET_SERIES_SHORT} STREQUAL "esp32s2")
        set(tusb_mcu "OPT_MCU_ESP32S2")
    elseif(${TARGET_SERIES_SHORT} STREQUAL "esp32p4")
        set(tusb_mcu "OPT_MCU_ESP32P4")
    endif()

    set(compile_options
        "-DCFG_TUSB_MCU=${tusb_mcu}"
    )

    target_compile_options(${etusb_lib} PUBLIC ${compile_options})
    target_compile_options(${NANOCLR_PROJECT_NAME}.elf PUBLIC ${compile_options})

AdrianSoundy avatar Mar 21 '24 10:03 AdrianSoundy

@hfudev Could you please take a look?

kumekay avatar Mar 25 '24 17:03 kumekay

Sure. I'll assign it to myself and we'll discuss about the idf-as-lib use case.

hfudev avatar Apr 09 '24 09:04 hfudev

Hello, I am having the same problem. Is there any progress regarding this situation?

IDF 5.2.1 version automatically downloads these 2 files(espressif__esp_tinyusb / espressif__tinyusb) for tinyusb. But I couldn't figure out how to add this to my own cmake-based project.

Can you help me on how to solve this problem? I'm not having good luck adding it manually. I've been stuck here for the last 2 days.

serdartoren avatar May 05 '24 22:05 serdartoren

Hi, I managed to pull my project to v5.1 and add it manually. But it is impossible for me to do this in v5.2.

I think this is becoming an important issue. It will make our job easier if ESP finds a solution to this soon.

Have a nice & healthy days

serdartoren avatar May 10 '24 22:05 serdartoren

Thats not good if I can't work around problem on IDF 5.2. We were planning to move to 5.2.x

Is there any other work around ?

AdrianSoundy avatar May 11 '24 00:05 AdrianSoundy

Hi, has anyone succeeded in running tinyusb on V5.2? This restricts us a lot

serdartoren avatar May 26 '24 08:05 serdartoren

@serdartoren Could please help us find a workaround for your case.

Do you have an example repo which works with 5.1 but fails with 5.2?

kumekay avatar May 27 '24 09:05 kumekay

No but I will create one for you now

serdartoren avatar May 27 '24 09:05 serdartoren

https://github.com/serdartoren/tinyusb_cmake_problem/tree/master I created a test repo for you.

v5.1.4 is the highest version that works smoothly. For example, in a last version such as 5.1.4-dirty, a problem occurring very similar to the error in v5.2 occurs.

I have explained the highest point where it works smoothly for you in the readme file. It may be useful to you.

But of course, our ultimate goal is to run this repo on v5.2.

My system: Ubuntu 22.04 esp32s3

serdartoren avatar May 27 '24 10:05 serdartoren

Hi, is there any progress

serdartoren avatar Jun 19 '24 14:06 serdartoren

@serdartoren Hi, sorry for the late reply.

I tried your repo, and IMHO it's unrelated to the original post. Instead, your build failure should be caused by this refactor commit: https://github.com/espressif/esp-idf/commit/5c2a003f915a0a8dcc4973fd7e64663ab6e5f565

After patching the file tinyusb/tinyusb/src/portable/espressif/esp32sx/dcd_esp32sx.c, I could run ./build-esp32s3.sh successfully with v5.2.1.

Here's the patch, could you give it another try?

diff --git a/tinyusb/tinyusb/src/portable/espressif/esp32sx/dcd_esp32sx.c b/tinyusb/tinyusb/src/portable/espressif/esp32sx/dcd_esp32sx.c
index a9c3113..9817a78 100644
--- a/tinyusb/tinyusb/src/portable/espressif/esp32sx/dcd_esp32sx.c
+++ b/tinyusb/tinyusb/src/portable/espressif/esp32sx/dcd_esp32sx.c
@@ -42,6 +42,14 @@
 
 #include "device/dcd.h"
 
+// --- modify after 5c2a003f915a0a8dcc4973fd7e64663ab6e5f565 ---
+#include "soc/usb_reg.h"
+#include "soc/usb_struct.h"
+
+#define USB_IN_EP_NUM     7
+#define USB_OUT_EP_NUM    7
+// --- modify ends here ---
+
 // Max number of bi-directional endpoints including EP0
 // Note: ESP32S2 specs say there are only up to 5 IN active endpoints include EP0
 // We should probably prohibit enabling Endpoint IN > 4 (not done yet)

hfudev avatar Jul 18 '24 02:07 hfudev

The method you gave worked, thank you!!

serdartoren avatar Sep 23 '24 17:09 serdartoren