espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.47k stars 7.25k forks source link

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

Open AdrianSoundy opened 6 months ago

AdrianSoundy commented 6 months ago

Answers checklist.

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.

kumekay commented 6 months ago

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.

AdrianSoundy commented 6 months ago

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})
kumekay commented 6 months ago

@hfudev Could you please take a look?

hfudev commented 6 months ago

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

serdartoren commented 5 months ago

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 commented 4 months ago

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

AdrianSoundy commented 4 months ago

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 ?

serdartoren commented 4 months ago

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

kumekay commented 4 months ago

@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?

serdartoren commented 4 months ago

No but I will create one for you now

serdartoren commented 4 months ago

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 commented 3 months ago

Hi, is there any progress

hfudev commented 2 months ago

@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)
serdartoren commented 1 week ago

The method you gave worked, thank you!!