Using custom ESP-IDF with Arduino

Hello possible future lifesavers.

I was wondering if there was a I can use a modified ESP-IDF with the Arduino framework in platformio. For context, I want to make changes to the Lightweight IP (LwIP) library, which is a part of the Espressif SDK, but I can’t make direct changes to it because I only have access to the header files in the ~/.platformio/packages/framework-arduinoespressif32 folder. Considering I use the Arduino framework for my project within platformio through VS Code, what’s the easiest way for me to make changes to the LwIP library?

Here’s what I tried so far.

  1. I cloned the esp-idf repository and checked out to the version I usually use (v4.4.3).
  2. I then made some changes to the LwIP sources files.
  3. In my platformio.ini file, under [env], I added the line “platform_packages = framework-espidf@file://insertPathToEspIdf”
  4. Selected my environment via VSCode and hit Build

Initially, nothing happened and everything compiled as normal. It was still using the default files as opposed to my custom esp-idf. I then found this post Platform_packages in platformio.ini not working as expected - #2 by maxgerhardt saying that as long as I use the arduino framework, I have to use “framework-arduinoespressif32@…” so I did and now all the Arduino files are not found, presumably because it overwrote the Arduino layer. Which brings us back to…

How does one modify files within esp-idf whilst making no chances at the Arduino and platformio layer?

  1. Download and compile https://github.com/platformio/platform-espressif32/tree/develop/examples/espidf-arduino-blink as-is
  2. Only if that works, add your platform_packags = framework-espidf@symlink://<path> to the platformio.ini.

The sketch works fine, but I was under the impression that if I were to use “framework = arduino”, I have to use framework-arduinoespressif32 according to this post here Platform_packages in platformio.ini not working as expected - #2 by maxgerhardt

Do you have object files in your build related to ESPIDF source? You will need to find wherever the ESPIDF source that the ArduinoEspressif32 framework uses are if you are going to change them. Good luck!

There’s no ESP-IDF source files in the Arduino library. Hence why I was cloning the ESP-IDF repository directly

Well if you use framework = arduino you by-default don’t have the possibility to change the ESP-IDF base. You would have to point the framework-arduinoespressif32 directly at a package that has a different ESP-IDF base or configuration precompiled in, e.g. as generated by espressif/esp32-arduino-lib-builder/. Hence, framework = arduino, espidf is a much easier way to exchange or modify the ESP-IDF base for Arduino projects, since ESP-IDF is compiled from source there.