ESP8266 Toolchain

From Bhack
Revision as of 20:36, 21 January 2015 by Zwollenar (Talk | contribs) (Restore AT firmware)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Debian oriented ESP8266 guide

Installation and usage of esp8266 toolchain on debian wheezy.

Guide is based on ws2812esp8266, ESP8266 Toolchain and Max Filippov's work

Your ESP8266 should come preloaded with the AT firmware.


ESP8266

Versions

There are several versions of the ESP8266.

The esp-01 is common with 2 gpio pin's accessible while the ESP-12 has more (all ?) pins and a terminal spacing of 2.0mm.


Serial connection

sudo apt-get install picocom

picocom --omap crcrlf -b 9600 /dev/ttyACM0

AT commands

Information


Prerequisites

apt-get install git autoconf build-essential gperf bison flex texinfo libtool libncurses5-dev wget gawk libc6-dev-amd64 python-serial libexpat-dev libgmp-dev libmpfr-dev libmpc-dev

Installing

Xtensa toolchain

Clone and build xtensa-toolchain

mkdir ~/esp8266
cd ~/esp8266
git clone https://github.com/jcmvbkbc/xtensa-toolchain-build.git
cd xtensa-toolchain-build
wget http://ftp.gnu.org/pub/gnu/binutils/binutils-2.24.tar.bz2
git clone --depth=1 https://github.com/jcmvbkbc/gcc-xtensa.git
mv gcc-xtensa gcc-4.9.1
wget http://ftp.gnu.org/gnu/gdb/gdb-7.6.tar.bz2
./prepare.sh lx106
./build-elf.sh lx106
Drink coffee, rewire, code and watch the sun come up.

ESPtool

cd ~/esp8266
mkdir other
cd other
wget http://filez.zoobab.com/esp8266/esptool-0.0.2.zip
unzip esptool-0.0.2.zip
cd esptool

! Edit Makefile to read on the first line: TARGET_ARCH = LINUX

make

You’ll need to get a copy of esptool.py. You may want to change:

ESP_ROM_BAUD    = 230400

So you don’t have to wait all day. You can get it from: https://github.com/themadinventor/esptool/. Simply git clone.

cd ~/esp8266
git clone https://github.com/themadinventor/esptool.git

SDK

cd ~/esp8266
wget http://bbs.espressif.com/download/file.php?id=72 -O esp_iot_sdk_v0.9.3_14_11_21.zip
wget http://bbs.espressif.com/download/file.php?id=73 -O esp_iot_sdk_v0.9.3_14_11_21_patch1.zip
unzip esp_iot_sdk_v0.9.3_14_11_21.zip 
unzip -f esp_iot_sdk_v0.9.3_14_11_21_patch1.zip 
cd ~/esp8266/esp_iot_sdk_v0.9.3
wget -O lib/libc.a https://github.com/esp8266/esp8266-wiki/raw/master/libs/libc.a
wget -O lib/libhal.a https://github.com/esp8266/esp8266-wiki/raw/master/libs/libhal.a

Building

Defaults

User environment

Set the following variables in your shell and optionally add them to your .bashrc file.

export SDK_BASE=~/esp8266/esp_iot_sdk_v0.9.3
export XTENSA_TOOLS_ROOT=~/esp8266/xtensa-toolchain-build/build-lx106/root/bin/
export FW_TOOL=~/esp8266/other/esptool/esptool
export ESPTOOL=~/esp8266/esptool/esptool.py


Using source-examples

Lets test drive the toolchain with the example blinky

cd ~/esp8266
git clone https://github.com/esp8266/source-code-examples

Edit the Makefile and change the line:

EXTRA_INCDIR    = include /opt/Espressif/include

to

EXTRA_INCDIR    = include $(SDK_BASE)/../include/

Execute make:

make clean && make

Output:

CC user/user_main.c
AR build/app_app.a
LD build/app.out
FW firmware/0x00000.bin
FW firmware/0x40000.bin

Flashing

pull GPIO0 down and restart.

ESPPORT=/dev/ttyACM0 make flash

Output:

/home/victor/esp8266/esptool/esptool.py --port /dev/ttyACM0 write_flash 0x00000 firmware/0x00000.bin 0x40000 firmware/0x40000.bin
Connecting...
Erasing flash...
Writing at 0x00007300... (100 %)
Erasing flash...
Writing at 0x00061200... (100 %)

Leaving...

disconnect GPIO0 and restart.

When using the blinky example connnect a LED and resistor to GPIO02.

Restore AT firmware

A bit of a mixed bag :(

Download the latest firmware I used v0.9.2.2 AT Firmware.bin

pull GPIO0 down and restart.

~/esp8266/esptool/esptool.py --port /dev/ttyACM0 write_flash  0x00000  v0.9.2.2\ AT\ Firmware.bin

disconnect GPIO0 and restart.


Connect and try some AT commands.


If this fails.. try again.