Max Duijsens
About computer security and other hobbies

ESP8266: Upgrading Firmware

As part of one of my Arduino Pro Mini projects I bought an ESP8266. The ESP8266 is a $3 System-on-a-Chip which provides WiFi connectivity to a serial port, made in China. The first version features a 6pin header which is not very common and not breadboard friendly. Since that, they updated the chip a lot and also included more flash memory, and they changed the chip layout. Since the default firmware version (v0.6) is actually half-chinese and not very API friendly, I will make an attempt to explain how to upgrade the firmware in this post because I found it to be not very straightforward and had to read many blog posts to get it to work in the end.

You will need the following:

  • ESP8266 Model 1 (a.k.a. ESP-1)
  • FTDI/SPI (or any other USB-to-Serial adapter should work)
  • A bunch of breadboard cables
  • The latest Espressif SDK (unless you want to run a custom firmware like NodeMCU)
  • esptool to flash it

ESP8266 Pin-out

To start to flash, it’s handy to know that the CH_PD pin should be pulled high at all times. If the CH_PD pin is low, the chip will go into sleep mode (and wake up once the CH_PD changes back to high). Further more, the GPIO pins configure the boot mode (more on that later). The rest of the pins you can leave connected.

Start by testing your chip. To do this, connect the following pins from the ESP8266 to your FTDI:

  • VCC –> VCC
  • GND –> GND
  • RX/TX –> TX/RX
  • RESET –> GND (via a button, it should be connected to GND in order to reset it, so removed in order to operate the ESP8266)
  • CH_PD –> VCC

As you can see you don’t connect anything to the GPIO pins as this will alter the boot mode. Give the chip a few seconds to boot and open up a terminal to your FTDI. The default baudrate is 115200. You can type AT+RST to give the chip a reset and you should see some unreadable characters being spammed (presumably Chinese) followed by “ready”. You should see the same output when you connect the RST pin to GND and remove it. Have a look at the official manual in the SDK you downloaded for all commands (it’s under /Document/English/….pdf). Note that not all commands work as this is firmware version 0.6 while the manual is for 1.0.1b15.

Once you confirmed your chip is working, remove the FTDI’s power and in addition to the pins you connected before now connect the following:

  • GPIO0 –> GND
  • GPIO2 –> VCC

By pulling GPIO0 low and GPIO2 high, it tells the chip to boot into flash mode. Enable the FTDI’s power again, and give the ESP8266 another reset by connecting the RST pin to GND (and removing it).

Now enter your shell, move the \bin\at\user1.1024.new.bin file two directories up (so into \bin). Run esptool from the \bin directory as follows (replace the /dev/cu.usbserial-000 with the portname of your FTDI, on linux it would be something like /dev/ttyUSB0):

esptool.py --port /dev/cu.usbserial-000 --baud 115200 write_flash 0x00000 boot_v1.2.bin 0x01000 user1.1024.new.bin 0x7E000 blank.bin

What this does, is flash the boot image (version 1.2, as we have the ESP-1) into the first bytes of the ROM. Followed by the user1.1024.new.bin image which contains the “application” as it’s called. This part actually provides you with the AT+* commands. Finally we need to write some blank data to the ROM to set the default values for some variables (for example it will start up in access point mode upon boot). You should see a message saying Erasing flash... Writing 0x00001 (0.0%) etc.

After the writing of the image is done, remove the GPIO pins again and give the ESP8266 another reset. Connecting your terminal with baudrate 115200 should now show something like:

ets Jan  8 2014,rst cause 1, boot mode:(3,7)

load 0x40100000, len 24236, room 16 
tail 12
chksum 0xb7
ho 0 tail 12 room 4
load 0x3ffe8000, len 3008, room 12 
tail 4
chksum 0x2c
load 0x3ffe8bc0, len 4816, room 4
tail 12
chksum 0x46
csum 0x46
ready

Try typing AT and hitting enter, it should say OK (mind the caps in the AT commands).

Now, to use it on the Arduino you’re either going to have to find a library which is able to handle the latest firmware (doesn’t exist at the time of writing), or you will have to write the serial code yourself. I’ve attached some sample code below that connects to your wifi and makes a http request. You should be able to program anything you like using this example and the manual referenced earlier.

If you need any more help with the ESP8266 have a look at the community forum 8266.com, 8266 Wiki or the ESP8266 page on NurdSpace