Category:ESP8266 Code Guide

From ElectroDragon
Revision as of 01:36, 14 November 2018 by Chao (talk | contribs) (Flash Firmware)
Jump to navigation Jump to search

Pre-build firmware

Custom Interpreter


Flash Firmware

Setup up environment

Esp8266 setup 01.png
  • use our adapter board for example, it is 3.3V/5V compatible, please notice the board does not have "auto programming" function, you need manually enter into flash mode
  • If use over 5V voltage please supply from VIN, otherwise 3.3V to 3.3V
  • Wiring module, via a USB-TTL serial bridge board, for example our CP2102 as below image.
  • hold down flash button, and press reset to enter into flash mode
  • to check the status of module, open SSCOM or other similar tools to check and confirm, see image below
  • please first try ESP download tool to program first
  • for arduino please enter into flash mode, when starting upload, IDE indicates "uploading ..." info

Use ESP Download Tool

Use arduino IDE

  • Please see the guideline image on the right, this will be used in esp flash download tool, arduino IDE, etc
Option value Description
flash mode QIO -
flash frequency 40mhz -
upload using "serial" in arduino IDE
CPU frequency 80mhz -
flash size 4MBytes / 32Mbit (3M SPIFSS) old ESP8266 board should use 4Mbit (512Mbytes)
reset mode nodemcu -
upload speed 115200 up to 576000 is fine, speed up the flashing progress
upload port choose your own serial port -
crystal frequency 26mhz in esp flash download tool

Firmware Details

Boot Process

  • Reset vector is 0x40000080.
  • Boots into Espressif code in IROM0.
  • Loads SPI ROM data.
  • Starts executing ESP SDK-code shadowed SPI ROM (unconfirmed).

SPI Flash ROM Layout

Address Size Name Description
00000h 248k app.v6.flash.bin User application
3E000h 8k master_device_key.bin OTA device key
40000h 240K app.v6.irom0text.bin SDK libraries
7C000h 8k esp_init_data_default.bin Default configuration
7E000h 8k blank.bin Filled with FFh. May be WiFi configuration.


  • ESPTool
  • Install dependence if necessary, for lubuntu, first install python-pip, than pip install pyserial
apt-get install python-pip
pip install pyserial
  • More functions by using -h, for specific command try ie write_flash -h.:
   Run esptool {command} -h for additional help
   load_ram            Download an image to RAM and execute
   dump_mem            Dump arbitrary memory to disk
   read_mem            Read arbitrary memory location
   write_mem           Read-modify-write to arbitrary memory location
   write_flash         Write a binary blob to flash
   run                 Run application code in flash
   image_info          Dump headers from an application image
   make_image          Create an application image from binary files
   elf2image           Create an application image from ELF file
   read_mac            Read MAC address from OTP ROM
   flash_id            Read SPI flash manufacturer and device ID
   read_flash          Read SPI flash content
   erase_flash         Perform Chip Erase on SPI flash
  • read flash ID:
./ --baud 115200 --port /dev/ttyUSB0 flash_id
Manufacturer: e0
Device: 4016

Batch Flashing Nodemcu, Deploy firmware

  • After finish coding, upload your code lua into target board, better be complied
  • dump out the flash content out and save as firmware.bin file for batch deploy
  • use this firmware.bin for new products
  1. So first setup the working environment
  2. read out the flash content by command
./ --baud 115200 --port /dev/ttyUSB0 read_flash 0 4194304 output.bin
  1. 4194304 mbits = 4MB, read flash time take at least more than 5 minutes
  2. 2097152 mb = 2MB, 1048576 mbits = 1MB, 524288 = 512 KB, 262144 = 256 KB
  3. use flash download tool flash normally
  • Also can try dump mem out, like RAM, etc, dumping the ROM (64 KiB) from the chip:
./ dump_mem 0x40000000 65536 iram0.bin


  • Open arduino IDE, and set baud rate to 74880 on serial, can find esp8266 debug info.

This category currently contains no pages or media.