ESP8266

From Wikistix

Some notes on mucking with an old AI-Thinker/Espressif ESP8266 with 1MiB (8mbit) flash. These are "Serial WiFi" modules, not the more fancy "NodeMCU" modules.

ESP-AT RTOS based firmware

The documentation provided by Espressif is somewhat lacking. Looking at that page, the Windows and Linux instructions have different load addresses, I can't find phy_init_data.bin in the zip file, and we are left to guess. I'm yet to successfully flash a bootable image using this version; I believe support for 1MB flash size (8mbit) is somewhat limited, there's just not enough space.

Non OS firmware

This appears to be the old line of firmware, but also appears to be the one most supported by other SDKs (eg. Arduino). It's available at espressif.

Flashing via serial

First flash of much newer, but apparently deprecated, non-OS firmware, using esptool. Flip switch from "UART" to "PROGRAM" and hit reset.

$ cd ESP8266_NonOS_AT_Bin_V1.7.4/bin
$ esptool.py --chip esp8266 --port /dev/dtyU1 --baud 230400 write_flash 0x0 boot_v1.7.bin 0x01000 at/512+512/user1.1024.new.2.bin 0xfc000 esp_init_data_default_v08.bin 0x7e000 blank.bin 0xfe000 blank.bin
esptool.py v2.8
Serial port /dev/dtyU1
Connecting........____
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 18:fe:34:d5:ef:67
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 230400
Changed.
Configuring flash size...
Auto-detected Flash size: 1MB
Flash params set to 0x0020
Compressed 4080 bytes to 2936...
Wrote 4080 bytes (2936 compressed) at 0x00000000 in 0.1 seconds (effective 244.6 kbit/s)...
Hash of data verified.
Compressed 413444 bytes to 296966...
Wrote 413444 bytes (296966 compressed) at 0x00001000 in 13.2 seconds (effective 250.0 kbit/s)...
Hash of data verified.
Compressed 128 bytes to 75...
Wrote 128 bytes (75 compressed) at 0x000fc000 in 0.0 seconds (effective 146.5 kbit/s)...
Hash of data verified.
Compressed 4096 bytes to 26...
Wrote 4096 bytes (26 compressed) at 0x0007e000 in 0.0 seconds (effective 6309.5 kbit/s)...
Hash of data verified.
Compressed 4096 bytes to 26...
Wrote 4096 bytes (26 compressed) at 0x000fe000 in 0.0 seconds (effective 6595.3 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

Flashing via WiFi (OTA)

Should be in station mode, and connected to an access point, with internet access and working DNS. AT+PING tests this below.

AT+CWMODE_CUR=1

OK
AT+CWJAP_CUR="wifissid","password"
WIFI CONNECTED
WIFI GOT IP

OK
AT+PING="iot.espressif.cn"
+445

OK
AT+CIUPDATE
+CIPUPDATE:1
+CIPUPDATE:2
+CIPUPDATE:3
+CIPUPDATE:4
OK
WIFI DISCONNECT
… reboot

Testing

Boot msgs

Initial boot messages appear to be generated at 74880 baud. Prior to flashing:

$ cu -s 74880 -l /dev/dtyU1 
Connected

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x40100000, len 1396, room 16 
tail 4
chksum 0x89
load 0x3ffe8000, len 776, room 4 
tail 4
chksum 0xe8
load 0x3ffe8308, len 540, room 4 
tail 8
chksum 0xc0
csum 0xc0

2nd boot version : 1.4(b1)
  SPI Speed      : 40MHz
  SPI Mode       : DIO
  SPI Flash Size & Map: 8Mbit(512KB+512KB)
jump to run user1 @ 1000

After flashing:

$ cu -s 74880 -l /dev/dtyU1       
Connected

 ets Jan  8 2013,rst cause:2, boot mode:(3,7)

load 0x40100000, len 2592, room 16 
tail 0
chksum 0xf3
load 0x3ffe8000, len 764, room 8 
tail 4
chksum 0x92
load 0x3ffe82fc, len 676, room 4 
tail 0
chksum 0x22
csum 0x22

2nd boot version : 1.7(5d6f877)
SPI Speed : 40MHz
SPI Mode : QIO
SPI Flash Size & Map: 8Mbit(512KB+512KB)
jump to run user1 @ 1000

correct flash map
V2
Mo
Backup

ÿrf cal sector: 251
freq trace enable 0
rf[112] : 00
rf[113] : 00
rf[114] : 01
w_flash

SDK ver: 3.0.4(9532ceb) compiled @ May 22 2020 16:26:04
phy ver: 1156_0, pp ver: 10.2

It then switches by default to 115200 baud:

Ai-Thinker Technology Co.,Ltd.

ready

Checking version

Non-OS version appears to require \n\r to complete each command.

Before flashing:

$ esptool.py --chip esp8266 --port /dev/dtyU1 --baud 230400 flash_id
esptool.py v2.8
Serial port /dev/dtyU1
Connecting........___
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 18:fe:34:d5:ed:04
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 230400
Changed.
Manufacturer: e0
Device: 4014
Detected flash size: 1MB
Hard resetting via RTS pin...
AT+GMR
AT version:0.40.0.0(Aug  8 2015 14:45:58)
SDK version:1.3.0
Ai-Thinker Technology Co.,Ltd.
Build:1.3.0.2 Sep 11 2015 11:48:04
OK

After flashing:

$ esptool.py --chip esp8266 --port /dev/dtyU1 --baud 230400 flash_id                                                                                                                                       
esptool.py v2.8
Serial port /dev/dtyU1
Connecting........___
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 18:fe:34:d5:ed:04
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 230400
Changed.
Manufacturer: e0
Device: 4014
Detected flash size: 1MB
Hard resetting via RTS pin...
AT+GMR
AT version:1.7.4.0(May 11 2020 19:13:04)
SDK version:3.0.4(9532ceb)
compile time:May 27 2020 10:12:17
Bin version(Wroom 02):1.7.4
OK

Connectivity

AT+CWMODE_CUR=1

OK
AT+CWJAP_CUR="wifissid","password"
WIFI CONNECTED
WIFI GOT IP

OK
AT+PING="iot.espressif.cn"
+445

OK

Notes

  • Requiring \n\r is awkward, when using cu or tip, minicom, etc, <Enter> followed by ^J does the job.
  • After a initial flash, I found that my DNS list was empty (viewable using AT+CIPDNS_CUR) after connecting to an access point. This was fixed by running erase_flash thru esptool and re-flashing. It may be that AT+RESTORE may have fixed this.
  • Flashing over WiFi requires internet access and working DNS, and can be tested via AT+PING="iot.espressif.cn".

Links