Setting up Bare Metal Development Toolchain for ESP32
(Tutorial in the making!...)
The Espressif Internet Development Framework (ESP-IDF) is core development tool-chain for the ESP32 chip. It includes the compiler, programming tools and various software components that enable software development on the chip. In this tutorial we will look at setting it up and describing in brief, the structure of the framework.
- 1 Windows ESP-IDF Setup
- 1.1 Step 1: Download the pre-compiled MYSYS2 environment for ESP32
- 1.2 Step 2: Extract the tool-chain to the C: drive
- 1.3 Step 3: Download the ESP-IDF
- 1.4 Step 4: Updating The Environment
- 1.5 Step 5: Download a project template
- 1.6 Step 6: Configure the project
- 1.7 Step 7: (Optional) Configure msys2 with ESP-IDF path for future use
- 2 Setup for MAC and Linux
Windows ESP-IDF Setup
The setup on other operating systems should be easier than Windows. I did set it up on Ubuntu and it was easier, so lets get started.
Step 1: Download the pre-compiled MYSYS2 environment for ESP32
There are other ways to accomplish this like compiling the environment itself but I would rather recommend doing this. So download it from the link below.
Step 2: Extract the tool-chain to the C: drive
Step 3: Download the ESP-IDF
You may either download it by cloning it with git like so
git clone --recursive https://github.com/espressif/esp-idf.git
or you download the repository directory.
Note: When downloading the git ensure that recursive is there, so that it can download all the required dependencies.
I did it under a directory called esp_bm (bm-baremetal) so that I can keep everything organized like so Notice that I have downloaded and extracted it to a different drive(F:) than the tool-chain(C:). So the next obvious thing is to tell the toolchain where the ESP-IDF is. We will do this in Step 5.
Step 4: Updating The Environment
The installed msys may be out of date. So its always better to update the environment before procedding. We will be using mingw32(remember, it is different than one available in msys installation) for update process. You may follow this link to install mingw32 but it is recommanded to use mingw32 provided by git-sdk to avoid installing packges manually. Clone git-sdk-64 or git-sdk-32 as per your system requirements
git clone --recursive https://github.com/git-for-windows/git-sdk-64.git or git clone --recursive https://github.com/git-for-windows/git-sdk-32.git
- Run mingw32.exe available in git-sdk folder
- Navigatte to msys installation folder and run the /esp-idf/tools/windows/windows_install_prerequisites.sh script
Step 5: Download a project template
The project template has all the essentials setup. Download and extract it from the like so:
git clone https://github.com/espressif/esp-idf-template.git blink
This will download the example template in the blink directory. You may also manually download it manually from the repo.
Step 6: Configure the project
As said in Step 3, we need to first set the esp-idf path in the tool chain and resolve if there are any dependencies. To do this open an MSYS2 terminal window by running C:\msys32\msys2_shell.cmd like so..
- Type the following command to set up the ESP-IDF path. You may change the path according to where you've downloaded the ESP-IDF in step 3.
- Now let's try and open the project directory, which we have named blink from the msys2 terminal like so
- ESP-IDF has a cool menu system to configure the project. This can be accessed by the command below:
- Then hit the make command to compile the project.
Step 7: (Optional) Configure msys2 with ESP-IDF path for future use
In the previous step, we configured the ESP-IDF path first. Now if we close and open the msys2 terminal it will forget the path. If you don't intend to move around the ESP-IDF directory we can configure msys2 to remember it. To do this, edit the profile.d file under C:/msys32/etc/profile.d and add the following line to it.
Setup for MAC and Linux
The setup for MAC and Linux is pretty straight forward, as these Operating systems come built in with the Msys environment. I was able to set it up easily on Ubuntu. Follow the steps on the links below to do so.