Adafruit ESP 32 Development Board Setup

Instructions are unclear on Adafruit's website regarding how to set this board up, so I decided I would document the steps I took to get HelloWorld working on this development board.

Technical details:
Board: Adafruit Espressif ESP32 Development Board - Developer Edition
OS: OSX Yosemite 10.10.5

Step 1:

Download the Espressif pre built Xtensa Toolchain for OSX by visiting the page and looking for the download link. This page should have the latest tool chain.

Run

mkdir -p ~/esp  
cd ~/esp  
tar -xzf ~/Downloads/xtensa-esp32-elf-osx-1.22.0-61-gab8375a-5.2.0.tar.gz  

Note: If you substituted ~/esp with another directory of your choosing, make sure that there is no space in the path and for the rest of the guide you reference what you used in place of ~/esp. Additionally, your toolchain version may differ from mine so make sure you modify the command appropriately.

Then, to make sure that Terminal can find the binaries, we have to update the PATH variable:

echo '#Adding path variable for ESP32 development' >> ~/.bash_profile  
echo 'export PATH=$PATH:$HOME/esp/xtensa-esp32-elf/bin' >> ~/.bash_profile  
source ~/.bash_profile  

Note: If you used a different directory for ~/esp, replace $HOME/esp with your own.

Now, type in xt and press tab a few times you should see something along the lines of xtensa-esp32-elf-xxx. If nothing happens or you don't see anything like that, then your PATH has not been set up correctly.

Step 2:

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

Note: --recursive is critical, otherwise you have to update the submodules yourself.

Step 2.5:

Pause here. It is important to note that the ESP-IDF build system does not support spaces in esp-idf or project paths. You will end up getting weird errors otherwise.

Step 3:

The Adafruit ESP32 development board comes with a USB<--->UART module; namely, the SILABS CP2102. In order to get this to interface with our Mac, we must install the appropriate driver.

Scroll down and download the one for OSX and click through the installation.

After that, plug in your board via USB, open up Terminal, and type in:

ls /dev/tty.*  

You should see something along the lines of

/dev/tty.SLAB_USBtoUART

Step 4:

We will now get our ESP32 to print hello world to us via serial. First, we grab some example code from esp-idf:

cp -r ~/esp/esp-idf/examples/get-started/hello_world/ ~/esp/ESP32/HelloWorld  
cd ~/esp/ESP32/HelloWorld  

Make sure we set the correct path for ESP-IDF:

export IDF_PATH=~/esp/esp-idf  

Run the terminal interface with the command:

make menuconfig  

Then use your arrow key to go to Serial flasher config -> (xxx) Default serial port then type in the serial port that the ESP32 is connected to from step 3. For me, this is /dev/tty.SLAB_USBtoUART

Exit and save the config.

Run make and you should see the build process.

As an Aside: I got a warning of:

WARNING: Toolchain version is not supported: crosstool-NG crosstool-ng-1.22.0-53-g46f160f-dirty  
Expected to see version: crosstool-NG crosstool-ng-1.22.0-61-gab8375a  
Please check ESP-IDF setup instructions and update the toolchain, or proceed at your own risk.  

which meant that I got the wrong toolchain version because I was following ESP's out of date version of documentation. This has since been fixed and I have updated the guide accordingly. I will just leave this here for reference in case others run into the same issue.

If all went well, you should get a hint at the end of the compile telling you how to flash to the board:

> make flash
Flashing binaries to serial port /dev/tty.SLAB_USBtoUART (app at offset 0x10000)...  
esptool.py v2.0-beta3  
Connecting........__  
Uploading stub...  
Running stub...  
Stub running...  
Configuring flash size...  
Auto-detected Flash size: 4MB  
Flash params set to 0x0220  
Compressed 15872 bytes to 9318...  
Wrote 15872 bytes (9318 compressed) at 0x00001000 in 0.8 seconds (effective 154.3 kbit/s)...  
Hash of data verified.  
Compressed 355216 bytes to 167627...  
Wrote 355216 bytes (167627 compressed) at 0x00010000 in 14.8 seconds (effective 192.7 kbit/s)...  
Hash of data verified.  
Compressed 3072 bytes to 82...  
Wrote 3072 bytes (82 compressed) at 0x00008000 in 0.0 seconds (effective 2150.1 kbit/s)...  
Hash of data verified.

Leaving...  
Hard resetting...  

This means that we have successfully flashed HelloWorld to our board. To check if we really succeeded, run screen /dev/tty.SLAB_USBtoUART 115200 and look at the output. This is what I got:

Restarting in 3 seconds...  
Restarting in 2 seconds...  
Restarting in 1 seconds...  
Restarting in 0 seconds...  
Restarting now.  
E (11211) wifi: esp_wifi_stop 802 wifi is not init  
ets Jun  8 2016 00:22:57  
...
...
...
I (1121) cpu_start: Starting scheduler on PRO CPU.  
Hello world!  
I (201) cpu_start: Starting scheduler on APP CPU.  
This is ESP32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 0, 4MB external flash  
Restarting in 10 seconds...  

Congratulations, you have successfully set up the build environment for the ESP32 and flashed it. You are now well on your way to building the next awesome IOT project!