Esp32 Clion

Posted onby admin

The ULP is a low-power coprocessor (Ultra Low Power) integrated into the ESP32 MCU. It’s a very small processor that can run independently from the main cores and that has access to the GPIOs, some peripheral and an I²C controller.

The ULP is also able to run when the ESP32 is is deep-sleep mode. In this mode, nearly the whole MCU is powered-off, except the RTC domain, in which the ULP is built. It is also able to wake the ESP32 up.

  • I think it is possible to use CLion with IDF v4.0 and later. Starting from IDF 4.0 we have fixed some bugs in our builds of xtensa-esp32-elf-gcc toolchain, which prevented it from being correctly detected by CMake.
  • Since I’m a PyCharm fan and just discovering the ESP32 world, this plugin couldn’t arrive at at better moment. A couple of questions: 1/ I’m experimenting with an ESP32 based board, and ESP32 is not listed in the targets type (only ESP8266 is proposed for the ESP family). Is it supposed to arrive soon, or is the ESP8266 option suppose to.

A possible application of the ULP is to acquire temperature while the ESP32 is in deep-sleep and to wake it up once it reaches a specified threshold.

Esp32 config

Programming the ULP seems very interesting, but even if the documentation from Espressif is very complete, I couldn’t find a simple and easy example to learn how to use it.

This video is a step by step guide to show how you start the project, configure it, compile, correct the errors, flash into the program memory and also flash. In Espressif IDF Eclipse Plugins, though screenshots are captured from macOS, installation instructions are applicable for Windows, Linux and macOS.

Here is then in details an ultra simple exemple : the traditional blink, which blinks 2 LEDs on the WROVER-KIT V3.

The example I’ll explain here consists in blinking 2 LEDs (the blue and the green ones from the ESP32-WROVER-KIT V3). The 1st one is driven by the main core, the second one by the ULP.

Installing the ULP toolchain

The installation is documented in the official documentation.

The project & CMake

Oh, by the way : you program the ULP in its assembly language. There’s obviously no C compiler available!

We’ll start by creating a file with the extension .S in a subdirectory of the project. I called it ulp/main-ulp-blink.S.

Next, we’ll edit the file CMakeLists.txt of the main component to add the code for the ULP:

The “application” program

This program is voluntarily very simple. It starts by initializing the GPIOs : GPIO4 for the blue LED, GPIO2/RTC_GPIO12 for the green LED. Not that we use rtc method for the green LED, as it’ll be driven by the ULP.

Next, it programs the ULP and start it, and then, enters in an infinite loop. This loop powers-ON/OFF the blue LED every 1 second. In the meantime, the ULP takes care of the green LED.

The ULP program

For informations, here is the documentation of the assembly language. This document is very useful if you want to understand and write your own programs.

Wow, that’s a lot of WAITs… I’ll come to it later on 🙂

The program, written in ULP assembly, start by declaring an empty BSS segment (it contains declaration of variable, but this program is so simple it doesn’t even need one). Next comes the TEXT segment which contains the code.

This code writes a 1 on GPIO2/RTC_GPIO12, waits, wait, waits some more, than writes a 0 on this GPIO, waits again, and start again.

Why so much WAITs? The mnemonic WAIT accepts as operand a 16bits (0..65535) value. It’s the number of cycles (@8MHZ) we want to wait until the next instruction. If you specify a greater value, the assembler drops them, and only uses the 16 lower bits, and waits for less than you would have expected.

In order to keep the example as simple as possible, I’ve decided to not write a true loop to wait, and simply add multiple WAITs so that we can see the blinking with our eyes.

The source code of this example is available on my GitHub.

Clion Executable Not Specified

ESP-IDF V4.0 has a new CMake-based build system as the default build system.

Esp32 Clion

There is a new ESP-IDF Eclipse Plugin that works with the CMake-based build system. Please refer to Espressif IDF Eclipse Plugins IDF for further instructions.

Note

Esp32 Platformio Clion

In Espressif IDF Eclipse Plugins, though screenshots are captured from macOS, installation instructions are applicable for Windows, Linux and macOS.

Clion Cmake Not Found

If you require Eclipse IDE support for legacy ESP_IDF Make build system, you can follow the legacy GNU Make build system Getting Started guide which has steps for Building and Flashing with Eclipse IDE.