Skip to content

ESP32: "user C modules" should be able to add components to the build #8041

Open

Description

@aguaviva

Right now the list of components is hard coded in

USer C modules should be able to add new components without having to modify the above file

My current use case is a user module that adds support for the esp32-camera

Fixing this will help others extend micropython with minimal modifications in the core files

Activity

  1. mocleiri commented on Jan 15, 2022

    @mocleiri
    Contributor

    @aguaviva if you have control over the board directory then its possible with the current structure to include additional idf components in the build.

    This is the reference for the custom board config:
    https://github.com/micropython/micropython-example-boards/blob/main/boards/CUSTOM_ESP32

    There are two steps:

    1. Define the EXTRA_COMPONENT_DIRS variable to point at the directory containing the component. This makes additional idf components available to include in the build.
    2. Reference the extra components on the COMPONENTS variable. According to the documentation there are certain default components that build and then any REQUIRES components from the idf_component_register are also included.

    Its sort of a hack but the esp32 build only defines the components to build through the REQUIRES. That is where the IDF_COMPONENTS come in, So the COMPONENTS variable is available and when you set it that triggers building the additional components.

    I tried to set both via my user moduleś micropython.cmake file but it didn´t work. I was able to set the EXTRA_COMPONENT_DIRS in the board makefile:
    https://github.com/mocleiri/tensorflow-micropython-examples/blob/80a43ee1cf9ec24a7ebc0e1b7bb30ad5f461c01a/boards/esp32/MICROLITE/CMakeLists.txt#L6

    Then I set the components to build in the user module:
    https://github.com/mocleiri/tensorflow-micropython-examples/blob/80a43ee1cf9ec24a7ebc0e1b7bb30ad5f461c01a/micropython-modules/microlite/micropython.cmake#L52

    This process works, I can see the custom component build and the firmware links properly. For my project the firmware when flashed is buggy but I think that´s most likely unrelated to this approach.

    The downside is that it doesn´t work if you don´t control the board.

  2. mortbauer commented on Sep 9, 2023

    @mortbauer

    Probably this should be solved with the switch to esp-idf v5, where list(APPEND IDF_COMPONENTS is used, however I still do not manage make this work, the result is different if I have user_c_module which appends a module or if I directly add it to the variable in esp32_common.cmake. The latter case works and the first produces errors when linking, I do not know what could be possibly be going on.

  3. LnnrtS commented on Dec 18, 2023

    @LnnrtS
    Contributor

    This is (at least one of) the reason why it doesn't work

    # CMAKE_BUILD_EARLY_EXPANSION is set during the component-discovery phase of
    # `idf.py build`, so none of the extmod/usermod (and in reality, most of the
    # micropython) rules need to happen. Specifically, you cannot invoke add_library.
    if(NOT CMAKE_BUILD_EARLY_EXPANSION)

    Just always including generic usermod.cmake is not working since it calls add_library. Instead it would need some port-specific machinery to directly include the user module cmake file in the CMAKE_BUILD_EARLY_EXPANSION-phase. But then that flag needs to be checked there (to not call add_library). Plus you will probably need PARENT_SCOPE to write to the top level IDF_COMPONENTS variable.

    All in all, adding a port-specific make flag for additional components required my the c modules could be a cleaner compromise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions