Arch Linux Users

Image result for programming in linux

Alternative Step 1: Compile the toolchain from source using crosstool-NG

Instead of downloading binary toolchain from Espressif website (Step 1 above) you may build the toolchain yourself.

If you can’t think of a reason why you need to build it yourself, then probably it’s better to stick with the binary version. However, here are some of the reasons why you might want to compile it from source:

  • if you want to customize toolchain build configuration
  • if you want to use a different GCC version (such as 4.8.5)
  • if you want to hack gcc or newlib or libstdc++
  • if you are curious and/or have time to spare
  • if you don’t trust binaries downloaded from the Internet

In any case, here are the steps to compile the toolchain yourself.

(Note: You will also need the prerequisite packages mentioned in step 0, above.)

  • Install dependencies:

    • Ubuntu pre-16.04:

      sudo apt-get install gawk gperf grep gettext libncurses-dev python python-dev automake bison flex texinfo help2man libtool
      
    • Ubuntu 16.04:

      sudo apt-get install gawk gperf grep gettext python python-dev automake bison flex texinfo help2man libtool libtool-bin
      
    • Debian:

      TODO
      
    • Arch:

      TODO
      

Download crosstool-NG and build it:

cd ~/esp
git clone -b xtensa-1.22.x https://github.com/espressif/crosstool-NG.git
cd crosstool-NG
./bootstrap && ./configure --enable-local && make install

Build the toolchain:

./ct-ng xtensa-esp32-elf
./ct-ng build
chmod -R u+w builds/xtensa-esp32-elf

Toolchain will be built in ~/esp/crosstool-NG/builds/xtensa-esp32-elf. Follow instructions given in the previous section to add the toolchain to your PATH.

Step 2: Getting ESP-IDF from github

Open terminal, navigate to the directory you want to clone ESP-IDF and clone it using git clonecommand:

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

ESP-IDF will be downloaded into ~/esp/esp-idf.

Note the --recursive option! If you have already cloned ESP-IDF without this option, run another command to get all the submodules:

cd ~/esp/esp-idf
git submodule update --init

IMPORTANT: The esp-idf build system does not support spaces in paths to esp-idf or to projects.

Step 3: Starting a project

ESP-IDF by itself does not build a binary to run on the ESP32. The binary “app” comes from a project in a different directory. Multiple projects can share the same ESP-IDF directory.

The easiest way to start a project is to download the template project from GitHub:

cd ~/esp
git clone https://github.com/espressif/esp-idf-template.git myapp

This will download esp-idf-template project into ~/esp/myapp directory.

Step 4: Building and flashing the application

In terminal, go to the application directory which was obtained on the previous step:

cd ~/esp/myapp

Type a command like this to set the path to ESP-IDF directory:

export IDF_PATH=~/esp/esp-idf

At this point you may configure the serial port to be used for uploading. Run:

make menuconfig

Then navigate to “Serial flasher config” submenu and change value of “Default serial port” to match the serial port you will use. Also take a moment to explore other options which are configurable in menuconfig.

Special note for Arch Linux users: navigate to “SDK tool configuration” and change the name of “Python 2 interpreter” from python to python2.

Now you can build and flash the application. Run:

make flash

This will compile the application and all the ESP-IDF components, generate bootloader, partition table, and application binaries, and flash these binaries to your development board.

Further reading

If you’d like to use the Eclipse IDE instead of running make, check out the Eclipse setup guide in this directory.

Leave a Reply

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