Tuesday 3 April 2018

Building the ESP8266 SDK in Ubuntu

The ESP8266 is built upon Linux entirely, the compiler and linker are both based on GCC, and even the downloading tool is also a Linux application. But for some unknown reasons, Espressif chooses to provide its SDK in a Windows favor. In their official guides, you need to install a virtual machine in Windows and then download an entire Lubuntu image which contains the SDK.

For someone who uses Ubuntu more than Windows like me, this simply doesn't make sense. And Espressif won't tell you how to build the environment in linux at all. If you let me pick a company with bad documentation, Espressif must be in the top 3.

I finally figured it out after a lot of searching and trying, and I would share it here.

At first, it should be made clear, which Espressif has failed to do so, the SDK is consist of 2 parts, the esp-open-sdk and the ESP8266 SDK. The esp-open-sdk is complete open source, containing the compiler and other utilities. This part can be downloaded from Github as source file, and then compiled locally. Thanks for pfalcon for doing this great job. Just choose where you want to install it and run:

$git clone --recursive https://github.com/pfalcon/esp-open-sdk

 You should get a dir named esp-open-sdk, and then enter the dir and run:

$make

If there are any missing dependencies the make program will give an error message and you can just follow the hints it gives to fix that. There are detailed instructions about the install on Github. The compiling will take quite a while (tens of minutes) if your computer is not fast enough.

The next step, is to install the ESP8266 SDK itself. This part is related to the ESP8266 chip and not completely open source. It contains some proprietary libraries. This part should be downloaded from Espressif's official web site. It would be something like ESP8266_NONOS_SDK-2.2.0 or so. You can put the downloaded directory anywhere you like, but not in the esp-open-sdk.

An important step, don't forget to add the /esp-open-sdk/xtensa-lx106-elf/bin/ to your PATH:

$export PATH=$PATH:(your full /esp-open-sdk/xtensa-lx106-elf/bin/ path)

Now we are ready to compile the examples. There is another pitfall hiding there which Espressif didn't tell you and will make you crazy. The examples in the SDK can NOT be compiled unless you move them to the upper folder!

All the examples are in the /ESP8266_NONOS_SDK-2.2.0/examples/ , for example, the IoT_Demo example is in /ESP8266_NONOS_SDK-2.2.0/examples/IoT_Demo/ . If you would like to compile this example, you have to MOVE it one level up, parallel to the 'examples' folder, so the project compiled must be at a folder like /ESP8266_NONOS_SDK-2.2.0/IoT_Demo/ .

At the correct location, inside the IoT_Demo, just run:

$./gen_misc.sh

I hope this could help you.

No comments:

Post a Comment