Build for esp32 with `framework = arduino, espidf` fails

My application for esp32 uses the Arduino framework, but I’m trying to also include espidf (to help with debugging an issue). I got the impression from discussions here that that should be possible. However, my builds fail with a cmake error while trying to configure esp-idf (I think).

The problem is shown even with an ino-file with empty setup() and loop(), and with the following
platformio.ini:

[platformio]
src_dir = .

[env:testframework]
framework = arduino, espidf
platform = espressif32
board = lolin32

The relevant bit of the error appears to be:

CMake Error at /Users/jack/.platformio/packages/framework-espidf/tools/cmake/component.cmake:222 (message):
  CMake Error at
  /Users/jack/.platformio/packages/tool-cmake/share/cmake-3.16/Modules/ExternalProject.cmake:1029
  (define_property):

    define_property command is not scriptable

Did I mis-interpret what I read here, and is it impossible to build with two frameworks? Am I doing something wrong? or did I hit a bug with the new cmake-based esp-idf build procedure?

This is platformio 4.3.3. And, in case it makes a difference, running on MacOS 10.13.6 inside vscode 1.45.1.

Looking at the provided official example

You’d need to point at the ESP-IDF v4 branch of Arduino-ESP32.

Also

looks unhealthy… surely directing the source directory at the project’s root with folders such as lib/ etc breaks things o_o. I’d keep that to its default value as shown in the example.

Makes no difference: I still get the cmake error. Was to be expected as the problem seems to be with configuring espidf… (But, indeed, the mod you gave to use the correct version of the esp32 arduino framework is also needed, thanks!).

… but the example you pointed to builds just fine. But: it isn’t a pure arduino project, it has a .cpp source file in stead of the .ino, and it has CMakeLists.txt and all that.

My expectation was that by changing framework = arduino to framework = arduino, espidf I could keep everything else in my project and build settings and all that the same, but it would simply replace the pre-compiled espidf with one that it would build within the project (so I could play with sdkconfig settings and all that). But apparently that isn’t the case: the example project is very aware of the fact that is being built for the combination of Arduino and esp-idf.

Indeed a better doc needs to be written for that espidf-arduino case. Because all that it’s doing is that it takes a standard ESP-IDF base project and activates the Arduino component in it, so the basic configuration (e.g. via CMakeLists.txt) must be from ESP-IDF foremost.

So maybe I should try taking a different angle. If I build with just the arduino framework the build will pick up the pre-built esp-idf from somewhere (I presume from somewhere in my ~/.platformio structure?).

Is there a way I can tell it to pick up espidf from another location, so I can prepare a build that is suited to what I want to try?

Arduino-ESP32 will pick up its ESP-IDF SDK libraries internally from its tools/sdk/lib folder. See github. So that’s already in your ~/.platformio/packages/framework-arduinoespressif32/tools/sdk folder.

You would have to replace the binary libraries there from your SDK compilation result. That is surely a somehow tedious process.

Are you sure it’s not better to build upon the arduino-idf-blink example so that it’s all dynamic and requires no local mods? Are there remaining problems with your setup?

Hi Jackjansen,
Not sure if I understand the goal: If you have an application written for Arduino API, you can call “esp_” functions ESP functions, just keep “framework = arduino” and your existing code. All what you need to do is to include esp’s header, just the same way you would do for ESP32. For example, one what I was working on today:

#include “esp_ota_ops.h”
err = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, update_handle);

The downside is that esp functions are by default for esp-idf 3.X, so all new code examples will not work. If this is a problem, staging version with ESP 4.X functions that can be used. It worked fine for me, the only minor issue I had was that I needed to install SimpleBLE library and list in lib_deps, even I am not using BlueTooth. But I think the need for BLE was my own doing, I list it here anyhow because I am not sure. The staging version is taken to use by setting platform_packages. Platformio documentation has better info Espressif 32 — PlatformIO latest documentation

[env:esp32cam]
platform_packages = framework-arduinoespressif32 @ GitHub - espressif/arduino-esp32: Arduino core for the ESP32

lib_deps = SimpleBLE