esp-matter with Micropython

JayAhr
Posts: 1
Joined: Mon Mar 25, 2024 9:31 pm

esp-matter with Micropython

Postby JayAhr » Mon Mar 25, 2024 9:41 pm

Dear ESP community,

I have an existing Micropython (version 1.22.1.0, ESP-IDF 5.1.2) project running fine on an ESP32 WROVER. Now I'd like to add Matter to the project via esp-matter. Build setup is working. I can build the "light"-example just fine. To test the build chain from within Micropython, I added a file with the following content:

Code: Select all

// Includes from the "light device" example.
#include <esp_matter.h>
#include <esp_matter_cluster.h>
#include <esp_matter_console.h>
#include <esp_matter_ota.h>

// Matter is C++ based, so functions need to be wrapped into extern "C"
extern "C" void matter_build_test()
{
    // Use something from Matter SDK to check build chain.
    node::config_t node_config;
}
and incorporated the contents of the "light"-example CMakeLists.txt into the Micropython CMakeLists, see below.

When I try to compile this, the following CMake error occurs:

Code: Select all

CMake Error:
  Error evaluating generator expression:

    $<TARGET_FILE:__idf_mbedtls>

  Target "__idf_mbedtls" is not an executable or library.
What can I do to solve this? Thanks in advance for any help.

Code: Select all

# Top-level cmake file for building MicroPython on ESP32.

cmake_minimum_required(VERSION 3.12)

### For matter (begin)

    if(NOT DEFINED ENV{ESP_MATTER_PATH})
        message(FATAL_ERROR "Please set ESP_MATTER_PATH to the path of esp-matter repo")
    endif(NOT DEFINED ENV{ESP_MATTER_PATH})

    # set(PROJECT_VER "1.0")
    # set(PROJECT_VER_NUMBER 1)

    set(ESP_MATTER_PATH $ENV{ESP_MATTER_PATH})
    set(MATTER_SDK_PATH ${ESP_MATTER_PATH}/connectedhomeip/connectedhomeip)

### For matter (end)

# Set the board if it's not already set.
if(NOT MICROPY_BOARD)
    set(MICROPY_BOARD ESP32_GENERIC)
endif()

# Set the board directory and check that it exists.
if(NOT MICROPY_BOARD_DIR)
    set(MICROPY_BOARD_DIR ${CMAKE_CURRENT_LIST_DIR}/boards/${MICROPY_BOARD})
endif()
if(NOT EXISTS ${MICROPY_BOARD_DIR}/mpconfigboard.cmake)
    message(FATAL_ERROR "Invalid MICROPY_BOARD specified: ${MICROPY_BOARD}")
endif()

# Define the output sdkconfig so it goes in the build directory.
set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig)

# Save the manifest file set from the cmake command line.
set(MICROPY_USER_FROZEN_MANIFEST ${MICROPY_FROZEN_MANIFEST})

# Include board config; this is expected to set (among other options):
# - SDKCONFIG_DEFAULTS
# - IDF_TARGET
include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake)

# Set the frozen manifest file. Note if MICROPY_FROZEN_MANIFEST is set from the cmake
# command line, then it will override the default and any manifest set by the board.
if (MICROPY_USER_FROZEN_MANIFEST)
    set(MICROPY_FROZEN_MANIFEST ${MICROPY_USER_FROZEN_MANIFEST})
elseif (NOT MICROPY_FROZEN_MANIFEST)
    set(MICROPY_FROZEN_MANIFEST ${CMAKE_CURRENT_LIST_DIR}/boards/manifest.py)
endif()

# Concatenate all sdkconfig files into a combined one for the IDF to use.
file(WRITE ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "")
foreach(SDKCONFIG_DEFAULT ${SDKCONFIG_DEFAULTS})
    file(READ ${SDKCONFIG_DEFAULT} CONTENTS)
    file(APPEND ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "${CONTENTS}")
endforeach()
configure_file(${CMAKE_BINARY_DIR}/sdkconfig.combined.in ${CMAKE_BINARY_DIR}/sdkconfig.combined COPYONLY)
set(SDKCONFIG_DEFAULTS ${CMAKE_BINARY_DIR}/sdkconfig.combined)

# Include main IDF cmake file.
include($ENV{IDF_PATH}/tools/cmake/project.cmake)

# Set the location of the main component for the project (one per target).
list(APPEND EXTRA_COMPONENT_DIRS
    "${ESP_MATTER_PATH}/components"
    "${MATTER_SDK_PATH}/config/esp32/components"
    # main_${IDF_TARGET})
    main)

# Define the project.
project(micropython)

### For matter (begin)
    # list(APPEND EXTRA_COMPONENT_DIRS
    #     "${ESP_MATTER_PATH}/components"
    #     "${MATTER_SDK_PATH}/config/esp32/components")

    idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++17;-Os;-DCHIP_HAVE_CONFIG_H" APPEND)
    idf_build_set_property(C_COMPILE_OPTIONS "-Os" APPEND)
    # For RISCV chips, project_include.cmake sets -Wno-format, but does not clear various
    # flags that depend on -Wformat
    idf_build_set_property(COMPILE_OPTIONS "-Wno-format-nonliteral;-Wno-format-security" APPEND)

### For matter (end)

Who is online

Users browsing this forum: Majestic-12 [Bot] and 219 guests