ComputingInternet Of ThingsProgramming

ESP32 Development Environment – Bleeding Edge ESP-IDF v4.1 with cmake

There’s a few options to program the esp32:

  • Arduino IDE : good. Heaps of support and tutorials. Some key limitations for ESP32, such as sleep modes.
  • ESP-IDF with Eclipse: messy to setup. Works okay. However, my PC is a bit slow for Eclipse.
  • PlatformIO : no experience but is well respected. Apparently it doesn’t use menuconfig / CMake. I want to be close to the hardware.
  • ESP-IDF with CMake and VSCode.

In ESP-IDF, CMake will soon (2019) become the “default build system” and in order to get the latest updates (e.g. power saving and camera), I needed to use the latest (6/9/2019) version.

Here are the steps:

Install Code (VSC)

Install ESP-IDF (master branch)

Follow nice instructions from Expressif.

At that point, before setting up VSCode, I check ESP-IDF runs okay with hello world.

Okay, back to VSCode. Only Windows notes, but adapt a boilerplate solution. I managed to adapt this to linux. See github for examples.

Great! This works really nicely. Some further work could improve the tasks and integrate the monitor, but it’s fast and easy. Intellisense is great.

Adding Arduino Libraries to ESP-IDF

Using the latest git branches (Sept 2019) and arduino-esp32 resulted in compile errors. See fixes below:

General notes:

  • Adjust this setting to prevent compiler error
  • Set flash size to 4MB
  • Ensure files are “.cpp” not “.c”
  • Add extern “C” {} around app_main()
  • Enable “Header Compatibility” in menuconfig
  • When in doubt:
    • rm -rf build && idf veryclean all

Specific fixes

  • Put ArduinoJSON, ESPASyncWebServer, AsyncTCP in libraries folder of Ardino
  • edit CMakeLists.txt in arduino-esp32/ to remove Azure and anything else you don’t need
  • Heaps of code, including vital stuff like ESPASyncWebServer is written for Arduino. Hence I need to add Arduino Esp32 as a component.
  • edit CMakeLists.txt in arduino-esp32/ to add third-party libraries (eg ESPASyncWebServer). Seems the new CMake system doesn’t pickup new libraries like the old make system
  • Manually #define ESP32 or put in CMake files:
    • add_definitions(-DESP32)
  • ArduinoJSON:
    • put in libraries file of arduino-esp32/
    • use the single .hpp header file install method
    • if your pass JsonDocuments around in functions, you need to put those functions in the header (.h), otherwise functions are undefined when templated.
  • Add requirements to CMakeFiles.txt of some components. Eg:
    • set(COMPONENT_REQUIRES arduino-esp32 fatfs)

Component Locations

According to the docs, we can put components at ESP-IDF or Project Level. For third-party, unchanging Arduino libaries, probably ESP-IDF Level makes sense. Project level makes everything in one place. You can there use either.

$IDF_PATH/components/          # eg. ~/esp/esp-idf/components, OR
$(PROJECT_PATH)/components     # eg. ~/esp/myproject/components

Libraries and Sub Systems

I found it better to use ESP-IDF subsystems were possible:

  • unix time functions and sntp component for time instead of eztime
  • unix file functions instead of Ardino File::
  • wifi_provisioning component instead of WiFiManager

Leave a Reply

Your email address will not be published. Required fields are marked *