esp-idf
Standard Toolchain Setup for Linux and macOS
Installation Step by Step
This is a detailed roadmap to walk you through the installation process.
Setting up Development Environment
These are the steps for setting up the ESP-IDF for your ESP32.
Step 1. Install Prerequisites
In order to use ESP-IDF with the ESP32, you need to install some software packages based on your Operating System. This setup guide helps you on getting everything installed on Linux and macOS based systems.
For Linux Users
To compile using ESP-IDF, you need to get the following packages. The command to run depends on which distribution of Linux you are using:
Ubuntu and Debian:
CentOS 7 & 8:
CentOS 7 is still supported but CentOS version 8 is recommended for a better user experience.
Arch:
Note
CMake version 3.16 or newer is required for use with ESP-IDF. Run “tools/idf_tools.py install cmake” to install a suitable version if your OS versions does not have one.
If you do not see your Linux distribution in the above list then please check its documentation to find out which command to use for package installation.
For macOS Users
ESP-IDF uses the version of Python installed by default on macOS.
Note
If an error like this is shown during any step:
Then you need to install the XCode command line tools to continue. You can install these by running xcode-select --install
.
Apple M1 Users
If you use Apple M1 platform and see an error like this:
or:
Then you need to install Apple Rosetta 2 by running
Installing Python 3
Based on macOS Catalina 10.15 release notes, use of Python 2.7 is not recommended and Python 2.7 is not included by default in future versions of macOS. Check what Python you currently have:
If the output is like Python 2.7.17
, your default interpreter is Python 2.7. If so, also check if Python 3 is not already installed on your computer:
If the above command returns an error, it means Python 3 is not installed.
Below is an overview of the steps to install Python 3.
Step 2. Get ESP-IDF
To build applications for the ESP32, you need the software libraries provided by Espressif in ESP-IDF repository.
To get ESP-IDF, navigate to your installation directory and clone the repository with git clone
, following instructions below specific to your operating system.
Open Terminal, and run the following commands:
ESP-IDF is downloaded into ~/esp/esp-idf
.
Consult ESP-IDF Versions for information about which ESP-IDF version to use in a given situation.
Step 3. Set up the Tools
Aside from the ESP-IDF, you also need to install the tools used by ESP-IDF, such as the compiler, debugger, Python packages, etc, for projects supporting ESP32.
or with Fish shell
The above commands install tools for ESP32 only. If you intend to develop projects for more chip targets then you should list all of them and run for example:
or with Fish shell
In order to install tools for all supported targets please run the following command:
or with Fish shell
Note
For macOS users, if an error like this is shown during any step:
You may run Install Certificates.command
in the Python folder of your computer to install certificates. For details, see Download Error While Installing ESP-IDF Tools.
Alternative File Downloads
The tools installer downloads a number of files attached to GitHub Releases. If accessing GitHub is slow then it is possible to set an environment variable to prefer Espressif’s download server for GitHub asset downloads.
Note
This setting only controls individual tools downloaded from GitHub releases, it does not change the URLs used to access any Git repositories.
To prefer the Espressif download server when installing tools, use the following sequence of commands when running install.sh
:
Note
For users in China, we recommend using our download server located in China for faster download speed.
Customizing the Tools Installation Path
The scripts introduced in this step install compilation tools required by ESP-IDF inside the user home directory: $HOME/.espressif
on Linux. If you wish to install the tools into a different directory, set the environment variable IDF_TOOLS_PATH
before running the installation scripts. Make sure that your user account has sufficient permissions to read and write this path.
If changing the IDF_TOOLS_PATH
, make sure it is set to the same value every time the Install script (install.bat
, install.ps1
or install.sh
) and an Export script (export.bat
, export.ps1
or export.sh
) are executed.
Step 4. Set up the Environment Variables
The installed tools are not yet added to the PATH environment variable. To make the tools usable from the command line, some environment variables must be set. ESP-IDF provides another script which does that.
In the terminal where you are going to use ESP-IDF, run:
or for fish (supported only since fish version 3.0.0):
Note the space between the leading dot and the path!
If you plan to use esp-idf frequently, you can create an alias for executing export.sh
:
Copy and paste the following command to your shell’s profile (
.profile
,.bashrc
,.zprofile
, etc.)Refresh the configuration by restarting the terminal session or by running
source [path to profile]
, for example,source ~/.bashrc
.
Now you can run get_idf
to set up or refresh the esp-idf environment in any terminal session.
Technically, you can add export.sh
to your shell’s profile directly; however, it is not recommended. Doing so activates IDF virtual environment in every terminal session (including those where IDF is not needed), defeating the purpose of the virtual environment and likely affecting other software.
Step 5. First Steps on ESP-IDF
Now since all requirements are met, the next topic will guide you on how to start your first project.
This guide helps you on the first steps using ESP-IDF. Follow this guide to start a new project on the ESP32 and build, flash, and monitor the device output.
Note
If you have not yet installed ESP-IDF, please go to Installation and follow the instruction in order to get all the software needed to use this guide.
Start a Project
Now you are ready to prepare your application for ESP32. You can start with get-started/hello_world project from examples directory in ESP-IDF.
Important
The ESP-IDF build system does not support spaces in the paths to either ESP-IDF or to projects.
Copy the project get-started/hello_world to ~/esp
directory:
Note
There is a range of example projects in the examples directory in ESP-IDF. You can copy any project in the same way as presented above and run it. It is also possible to build examples in-place without copying them first.
Connect Your Device
Now connect your ESP32 board to the computer and check under which serial port the board is visible.
Serial ports have the following naming patterns:
Linux: starting with
/dev/tty
macOS: starting with
/dev/cu.
If you are not sure how to check the serial port name, please refer to Establish Serial Connection with ESP32 for full details.
Note
Keep the port name handy as it is needed in the next steps.
Configure Your Project
Navigate to your hello_world
directory, set ESP32 as the target, and run the project configuration utility menuconfig
.
After opening a new project, you should first set the target with idf.py set-target esp32
. Note that existing builds and configurations in the project, if any, are cleared and initialized in this process. The target may be saved in the environment variable to skip this step at all. See Select the Target Chip: set-target for additional information.
If the previous steps have been done correctly, the following menu appears:
You are using this menu to set up project specific variables, e.g., Wi-Fi network name and password, the processor speed, etc. Setting up the project with menuconfig may be skipped for “hello_world”, since this example runs with default configuration.
Attention
If you use ESP32-DevKitC board with the ESP32-SOLO-1 module, or ESP32-DevKitM-1 board with the ESP32-MIN1-1(1U) module, please enable single core mode (CONFIG_FREERTOS_UNICORE) in menuconfig before flashing examples.
Note
The colors of the menu could be different in your terminal. You can change the appearance with the option --style
. Please run idf.py menuconfig --help
for further information.
If you are using one of the supported development boards, you can speed up your development by using Board Support Package. See Additional Tips for more information.
Build the Project
Build the project by running:
This command compiles the application and all ESP-IDF components, then it generates the bootloader, partition table, and application binaries.
If there are no errors, the build finishes by generating the firmware binary .bin files.
Flash onto the Device
To flash the binaries that you just built for the ESP32 in the previous step, you need to run the following command:
Replace PORT
with your ESP32 board’s USB port name. If the PORT
is not defined, the idf.py will try to connect automatically using the available USB ports.
For more information on idf.py
arguments, see idf.py.
Note
The option flash
automatically builds and flashes the project, so running idf.py build
is not necessary.
Encountered Issues While Flashing? See this Flashing Troubleshooting page or Establish Serial Connection with ESP32 for more detailed information.
Normal Operation
When flashing, you will see the output log similar to the following:
If there are no issues by the end of the flash process, the board will reboot and start up the “hello_world” application.
If you would like to use the Eclipse or VS Code IDE instead of running idf.py
, check out Eclipse Plugin, VSCode Extension.
Monitor the Output
To check if “hello_world” is indeed running, type idf.py -p PORT monitor
(Do not forget to replace PORT with your serial port name).
This command launches the IDF Monitor application:
After startup and diagnostic logs scroll up, you should see “Hello world!” printed out by the application.
To exit IDF monitor use the shortcut Ctrl+]
.
If IDF monitor fails shortly after the upload, or, if instead of the messages above, you see random garbage similar to what is given below, your board is likely using a 26 MHz crystal. Most development board designs use 40 MHz, so ESP-IDF uses this frequency as a default value.
If you have such a problem, do the following:
Exit the monitor.
Go back to
menuconfig
.Go to
Component config
–>Hardware Settings
–>Main XTAL Config
–>Main XTAL frequency
, then change CONFIG_XTAL_FREQ_SEL to 26 MHz.After that,
build and flash
the application again.
In the current version of ESP-IDF, main XTAL frequencies supported by ESP32 are as follows:
26 MHz
40 MHz
Note
You can combine building, flashing and monitoring into one step by running:
See also:
IDF Monitor for handy shortcuts and more details on using IDF monitor.
idf.py for a full reference of
idf.py
commands and options.
That is all that you need to get started with ESP32!
Now you are ready to try some other examples or go straight to developing your own applications.
Important
Some of the examples do not support ESP32 because required hardware is not included in ESP32 so it cannot be supported.
If building an example, please check the README file for the Supported Targets
table. If this is present including ESP32 target, or the table does not exist at all, the example will work on ESP32.
Additional Tips
Permission Issues /dev/ttyUSB0
/dev/ttyUSB0
With some Linux distributions, you may get the Failed to open port /dev/ttyUSB0
error message when flashing the ESP32. This can be solved by adding the current user to the dialout group.
Python Compatibility
ESP-IDF supports Python 3.8 or newer. It is recommended to upgrade your operating system to a recent version satisfying this requirement. Other options include the installation of Python from sources or the use of a Python version management system such as pyenv.
Start with the Board Support Package
To speed up prototyping on some development boards, you can use Board Support Packages (BSPs), which make initialization of a particular board as easy as few function calls.
A BSP typically supports all of the hardware components provided on the development board. Apart from the pinout definition and initialization functions, a BSP ships with drivers for the external components such as sensors, displays, audio codecs etc.
The BSPs are distributed via IDF Component Manager, so they can be found in IDF Component Registry.
Here is an example of how to add ESP-WROVER-KIT BSP to your project:
More examples of BSP usage can be found in BSP examples folder.
Flash Erase
Erasing the flash is also possible. To erase the entire flash memory you can run the following command:
For erasing the OTA data, if present, you can run this command:
The flash erase command can take a while to be done. Do not disconnect your device while the flash erasing is in progress.
Tip: Updating ESP-IDF
It is recommended to update ESP-IDF from time to time, as newer versions fix bugs and/or provide new features. Please note that each ESP-IDF major and minor release version has an associated support period, and when one release branch is approaching end of life (EOL), all users are encouraged to upgrade their projects to more recent ESP-IDF releases, to find out more about support periods, see ESP-IDF Versions.
The simplest way to do the update is to delete the existing esp-idf
folder and clone it again as if performing the initial installation described in Step 2. Get ESP-IDF.
Another solution is to update only what has changed. The update procedure depends on the version of ESP-IDF you are using.
After updating ESP-IDF, execute the Install script again, in case the new ESP-IDF version requires different versions of tools. See instructions at Step 3. Set up the Tools.
Once the new tools are installed, update the environment using the Export script. See instructions in Step 4. Set up the Environment Variables.
Related Documents
Last updated