ESP32 (2) – The development environment

by luca
12 comments

After having introduced, in the previous post, the ESP32 chip and the official development board by Espressif, today I’m going to show you how to install and use the official development environment.

I’ll explain how to install the IDE under Windows because of it is the most complex procedure. The development environment its how-to-install guides are available also for Linux and MacOS.

The official development framework for the ESP32 chip is published by Expressif on Github, with an opensource license (Apache 2.0) and named Espressif IoT Development Framework (shortly idf).

To be able to use it under Windows, you need some GNU commands and toolchains (make, bash…). Espressif chose to offer a pre-configured version of MSYS2 that includes everything is required.

Download the ZIP archive from the Espressif website and unzip it in the root of your C drive; MSYS2 will be installed in the C:\msys32 subfolder:

Make sure you’re using the latest version of the toolchain; the link to download it is available in the official documentation

esp32-07

Double-click on minigw32.exe to run a bash shell:

esp-idf000

We can now clone the idf Github repository to have a local copy of it. First we must choose a folder where it will be copied; to keep it simple let’s use the user’s home folder.

Move into that folder and run the clone command:

$ cd
$ git clone --recursive https://github.com/espressif/esp-idf.git

esp32-09

During the git clone command execution, you may get some error messages like: not a valid identifier; those errors are caused by a known bug and can be therefore ignored.

After the process is completed, the development framework is available in the esp32-idf subfolder:

esp32-10

To use if when compiling your projects, you have to export the path as an environment variable (IDF-PATH):

$ export IDF_PATH=~/esp-idf

Let’s connect the board!

You’re now ready to connect the development board to your computer.

If you already have the correct drivers, once connected it will appear as a new serial port:

esp32-12

On the contrary, the needed drivers are available on the Silicon Labs official website.

Hello World

As usual when learning a new language or framework, let’s start with a simple program that displays (using the serial-usb connection) the sentence Hello world.

The framework is distributed with some examples, among them you can find the 01_hello_world program. To compile it, move to its folder and run the make command:

$ cd
$ cd esp-idf/examples/01_hello_world/
$ make

A configuration menu will be displayed: we’ll talk more about it in a next post. Now you only need to tell the flasher which is the serial port your board is connected to.

Choose Serial flasher config, then /dev/ttyUSB0 (the default port):

esp32-14

Type the name of your serial port (as identified above), then confirm with OkSave and Exit:

esp32-16

When the compile process is complete, you can upload the program on the board with the following command:

make flash

esp32-17

If you now use a terminal emulator to connect to the serial port with the correct speed (115200 baud) you should see the program output:

esp32-18

(the program prints the sentence “Hello world!”, counts 10 seconds and then restart the chip…)

Related Posts

12 comments

Other Paul Wednesday May 10th, 2017 - 11:13 AM

Presumably the Espressif ZIP archive you mentioned will occasionally get updated. As I can find no quick and obvious path to this zip from either github or espressif (I’ve spent the past half-hour looking), could you provide a URL on espressif’s site that points you to their latest zip – on the grounds that such a URL might change less frequently than that to which it refers 🙂

Reply
luca Wednesday May 10th, 2017 - 02:48 PM

Hi Paul, you’re right… the best way to find the link is the official documentation. I’ll update the article accordingly

Reply
Other Paul Wednesday May 10th, 2017 - 04:46 PM

Thanks. But unhappily there is more. Not that it matters to me, but I cannot find any trace of 01_hello_world in the esp-idf gittery (gittage?).

More seriously, I’m looking to make one of their wifi examples but the make – after several rumblings – just ends up saying that

… yada yada yada …
CC flash_qio_mode.o
CC bootloader_start.o
AR libmain.a
LD bootloader.elf
/bin/sh: python: command not found

And indeed the distribution shows an absence of python in /usr/bin. Thing is I already have python (both 2.7 and 3) installed under a separate cygwin environment but MSYS2 isn’t in the same universe (its / is not the same as my cygwin’s) and cannot see it. I have so many different IDEs (MPLAB, Atmel, Xilinx, not to mention GNU) living on this machine it’s hard to keep track of which one’s being used for what piece of hardware. :). I suppose I’ll have to install yet another python just for MSYS2. Gaah!

Just thought I’d mention a first-world problem!

Reply
luca Wednesday May 10th, 2017 - 09:18 PM

Hi Paul! Try running the “minigw32.exe” executable instead of “msys2.exe”… it should solve your issue

Reply
Other Paul Wednesday May 10th, 2017 - 11:32 PM

mingw32.exe works – python appears to be known on that route, so thanks! But – although I get a bootloader.bin out of it, it just won’t go via (in my case) /dev/ttyS20 onto the board, Boot buttion has no effect. All I get is

serial.serialutil.SerialException: could not open port ‘/??/COM21’: WindowsError(123, ‘The filename, directory name, or volume label syntax is incorrect.’)

As it happens I have a prior prog flashed onto it (via the arduino ide) and I can see its output coming in with a ‘cat < /dev/ttyS20' so I'm pretty confident the mingw config is correct.

Reply
luca Thursday May 11th, 2017 - 09:32 AM

Paul if you are under Windows, in menuconfig enter “COM21” (without quotes) as serial port for the flasher

Reply
Abhay Monday May 29th, 2017 - 06:06 AM

$ git clone –recursive https://github.com/expressif/esp-idf.git
Cloning into ‘esp-idf’…
Username for ‘https://github.com’:
Password for ‘https://abhayrjoshi@github.com’:
remote: Repository not found.
fatal: repository ‘https://github.com/expressif/esp-idf.git/’ not found

Why is it asking for a username and password?

Reply
luca Monday May 29th, 2017 - 08:12 AM

did you configure git with your account? Are you using Github also for your projects?

Reply
Tobo Tuesday June 6th, 2017 - 11:11 PM

thanks, works perfect
Next ESP32 (3)

Reply
ashu Wednesday December 5th, 2018 - 05:23 PM

MINGW32 ~/esp-idf/examples/get-started/hello_world
$ make flash
Toolchain path: /opt/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc
WARNING: Toolchain version is not supported: crosstool-ng-1.22.0-61-gab8375a
Expected to see version: crosstool-ng-1.22.0-80-g6c4433a
Please check ESP-IDF setup instructions and update the toolchain, or proceed at your own risk.
Compiler version: 5.2.0
WARNING: Toolchain version is not supported: crosstool-ng-1.22.0-61-gab8375a
Expected to see version: crosstool-ng-1.22.0-80-g6c4433a
Please check ESP-IDF setup instructions and update the toolchain, or proceed at your own risk.
Please run the following command to install MSYS2’s MINGW Python cryptography package:
pacman -Sy mingw-w64-i686-python2-cryptography
make: *** [/home/ashenafi/esp-idf/make/project.mk:476: check_python_dependencies] Error 1

Reply
ashu Wednesday December 5th, 2018 - 05:24 PM

how can i solve this problem?

Reply
luca Friday December 7th, 2018 - 03:52 PM

follow the instruction to update your environment –> https://docs.espressif.com/projects/esp-idf/en/latest/get-started/windows-setup.html

Reply

Leave a Reply to Other Paul Cancel Reply

one × 4 =