Skip to content
Andrew Collins edited this page May 1, 2016 · 9 revisions

Requirements:

To build the standalone SDK and toolchain, you need a GNU/POSIX system (Linux, BSD, MacOSX, Windows with Cygwin) with the standard GNU development tools installed: gcc, binutils, flex, bison, etc.

Please make sure that the machine you use to build the toolchain has at least 1G free RAM+swap (or more, which will speed up the build). ##Debian/Ubuntu

###Ubuntu 14.04:

$ sudo apt-get install make unrar autoconf automake libtool gcc g++ gperf \
    flex bison texinfo gawk ncurses-dev libexpat-dev python python-serial sed \
    git

###Later Debian/Ubuntu versions may require:

sudo apt-get install libtool-bin

##MacOS:

brew tap homebrew/dupes
brew install binutils coreutils automake wget gawk libtool gperf gnu-sed --with-default-names grep
export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"

In addition to the development tools MacOS needs a case-sensitive filesystem. You might need to create a virtual disk and build esp-open-sdk on it:

sudo hdiutil create ~/Documents/case-sensitive.dmg -volname "case-sensitive" -size 10g -fs "Case-sensitive HFS+"
sudo hdiutil mount ~/Documents/case-sensitive.dmg
cd /Volumes/case-sensitive

Building

First clone the esp-open-sdk repo (https://github.com/Andrew-Collins/esp-open-sdk). Then navigate to the open sdk directory and run make:

cd /your_path/esp-open-sdk
make

This will take up ~4.2GB, so make sure you have room. (After this is unpacked you can delete everything bar the xtensa-lx106-elf folder)

Once this is all done and dusted, clone this repo, as well as the esptool repo (https://github.com/themadinventor/esptool). For the esptool you will need Python2.7 and Pyserial installed. Once this is done you will need to edit to start exporting paths.

For linux this is simple, simply open ~/.bashrc and enter the following at the end of the file:

export PATH=$PATH:/your_path/esp-open-sdk/xtensa-lx106-elf/bin
export SDK_PATH=/your_path/esp_iot_rtos_sdk/
export BIN_PATH=/your_path/esp_bin

where 'esp_bin' is a folder you create (can be called whatever you want), that the binary files to be stored in.

Now

cp /your_path/esptool/esptool.py /your_path/esp_bin

Congrats you should be all setup and ready to go. Please see the next two sections on compiling code, and then flashing the board.

#Compiling If you haven't followed the above two sections yet, please go back and do them now!

Otherwise lets get to some code!!!

First off, clone my espsdk examples repo (https://github.com/Andrew-Collins/esp8266-sdk) which is based heavily on mattcallow's work.

You will want to be looking in the rtos_apps directory for RTOS examples.

Now to explain how this sdk actually compiles its code. The short answer is you run ./gen_misc.sh in each 'Project folder' (more on this in a bit), the long answer is it runs a series of nested makefiles within each 'Project folder', which is based on a standard topology, and which sources header files from /your_path/esp_iot_rtos_sdk/include/freertos.

An empty version of this standard topology can be found in /your_path/esp_iot_rtos_sdk/examples/project_template/. Basically copy this folder to wherever, and when using it, user_main.c is your main file, local includes go in /include/ and I am not too sure about the library stuff yet.

Lets start with a blinking LED example. Navigate into rtos_apps/01blinky, and run ./gen_misc.sh. OR if you can accept how the build system works, and just want to go with a preset that works, run ./build.sh.

Check that you have exported your paths correctly, then enter y. The inputs I use for each step are as follows: Step2 : 1 Step3: default (just press enter) Step4: default Step5: 2 (it throws an error in my experience if you let it be 0)

Once this has finished you should see something like this:

Files have now been generated in your /your_path/esp_bin folder, and this message tells you what files to write to what addresses in flash. Now boot.bin will not be in your esp_bin folder,copy it in by using:

cp /your_path/esp_iot_rtos_sdk/bin/boot_v1.4(b1).bin /your_path/esp_bin
mv /your_path/esp_bin/boot_v1.4(b1).bin /your_path/esp_bin/boot.bin

Navigate to the esp_bin folder and you should see an upgrade folder has been created in it. This folder houses your user generated files, you can leave the bin in that folder, but I prefer to move it up a folder and rename it for ease of use.

mv user1.1024.new.2.bin ../user.bin

Change 'user1.1024.new.2' to whatever name the bin file actually is, but that is a typical name.

Once this has occurred you should have the esptool.py, boot.bin, and user.bin files in your esp_bin folder. Now it is time to flash the board.

#Flashing Make sure you are in your esp_bin folder, and that you have recorded what addresses you are supposed to write your files too; typically though it will be boot.bin to 0x00000 and user.bin to 0x01000.

Now it is time to connect your board, and put it in programming mode. This basically involves pulling the GPIO0 pin low, and resetting the board. The NodeMCU devkit v0.9 and up will do this automatically, but with the bareboards, instructions on how to do this can be found here: http://hackaday.com/2015/03/18/how-to-directly-program-an-inexpensive-esp8266-wifi-module/ (It's a pretty good read as well).

Once you have it in programming mode, plug in your USB and run the following command, while in your esp_bin folder.

sudo python2.7 esptool.py -p /dev/ttyUSB0 write_flash 0x00000 boot.bin 0x01000 user.bin  

ttyUSB0 is typically the port it will be connected to, but if not, replace it with the actual port.

Put it back into operating mode, and the onboard LED should be flashing, and if you connect and LED to GPIO2 it will too!

Clone this wiki locally