What we need?
To be able to flash nodeMCU firmware into ESP 12-F we need following hardware:
- ESP 12-F :-)
- 3.3V power supply
- USB to serial converter with TTL output
- 3x 1kOhm resistor
- 10uF capacitor for at least 3.3V (5 or 6V cap recommended)
- button (jumper, piece of wire, sth like that)
- computer running Linux (Ubuntu 16.04 used in examples)
- soldering tools, wires
We need following software:
- nodeMCU firmware - build your own via nodemcu-build.com - please note that your firmware needs to be smaller than flash size of your ESP
- esptool - current version is 2.0
- esplorer or screen
You need to connect your ESP as on image above, so:
- connect 3.3V power to Vcc (+) and GND (-)
- bypass the power with the capacitor - put the cap as close to the ESP as possible
- connenct RES and CH_PD pins to 3.3V via 1k resistors - on image above there is RES connected directly, but I recommend you to use 1k resistor in the same way as CH_PD in connected
- connect GPIO15 to GDN via 1k resistor
- connect button (jumper, sth what can be used to temporary short) to GPIO15 and GND
- connect RxD, TxD, GND of USB to serial converter to TxD, RxD and GND of ESP as on image
- connect USB to serial converter to your PC.
To put nodeMCU into FLASH mode you need to do following (you will need this later):
- power off, press the button or somehow connect GPIO0 to GND
- power on
- release the button (connection on GPIO0 - GND), now you are in flash mode
Install all the required software, make sure you have access to you serial converter device (usually something like /dev/ttyUSB0) - use following to allow access:
sudo chmod 777 /dev/ttyUSB0
We will use esptool to flash the nodeMCU firmware into ESP and esplorer or screen to check if the nodeMCU works.
Flashing the nodeMCU firmware
You need to erase the ESPs SPI flash and flash the nodeMCU firmware into it. After that you need to reset the ESP and wait until internal filesystem is formated.
In case that your ESP does not boot up, try to find out which SPI flash chip is used in your ESP and force flash parametters manually.
Erase SPI flash
Do not ommit this step, otherwise your ESP may experience problems to boot
- put ESP into flash mode
- erase flash using
esptool.py --port /dev/ttyUSB0 erase_flash
esptool.py v2.0-beta2 Connecting.... Detecting chip type... ESP8266 Uploading stub... Running stub... Stub running... Erasing flash (this may take a while)... Chip erase completed successfully in 8.4s Hard resetting...
Flash nodeMCU firmware
The simplesy way
You can try to let esptool to autodetect all flash parametters and specify just port and filename which should be flashed. 0x0 in the command bellow means the starting address for flashing, 0x0 simply means from the beginning of the flash.
To do that, follow these steps:
- put ESP into flash mode
esptool.py --port /dev/ttyUSB0 write_flash 0x0 <name-of-your-nodeMCU-firmware-bin-file>.bin
- output will be something like:
esptool.py v2.0-beta2 Connecting.... Detecting chip type... ESP8266 Uploading stub... Running stub... Stub running... Attaching SPI flash... Configuring flash size... Auto-detected Flash size: 4MB Flash params set to 0x0040 Compressed 472168 bytes to 306290... Wrote 472168 bytes (306290 compressed) at 0x00000000 in 27.5 seconds (effective 137.5 kbit/s)... Hash of data verified. Leaving... Hard resetting...
- DO NOT power off / reset the ESP now
- open esptool and open the serial console, port speed 115200b or open serial console using screen like:
screen /dev/ttyUSB0 115200
- power off ESP
- power on ESP, after few seconds in your termilal (esplorer / screen) there will appear few lines of strange characters followed by message
Formatting file system. Please wait...
- wait about half a minute, and you should get nodeMCU prompt
NodeMCU custom build by frightanic.com branch: master commit: 81ec3665cb5fe68eb8596612485cc206b65659c9 SSL: true modules: adc,bit,enduser_setup,file,gpio,i2c,mqtt,net,node,tmr,uart,wifi,tls build built on: 2017-01-15 02:24 powered by Lua 5.1.4 on SDK 18.104.22.168(39cb9a32) lua: cannot open init.lua >
If it does not work / you want to optimize
In case you want to speed up the flashing process, try following
esptool.py -b 1500000 --port /dev/ttyUSB0 write_flash --verify -fm qio -ff 80m 0x0 <name-of-your-nodeMCU-firmware-bin-file>.bin
- -b 1500000 will switch the speed of the serial port from default 115200 to 1500000
- -fm qio force qio access to the flash, may not work on dio flash chips
- -ff 80m switch the flash SPI speed to 80MHz, make sure that your flash chip can handle the speed (google datasheet), speed can be 20m, 26m, 40m, 80m, default is 40
Using command above my ESP-12F with 512KB (4mbit) flash finish flashing in 3.7seconds instead of 27.5seconds with default settings
In case that is the firmware flashing process failing, try to
- try to find out which SPI flash chip is used in your ESP and try to force -ff -fm -fs parametters manually
- lower serial speed using for examble -b 9600
- set dio access instead of qio using -fm dio
- lower flash SPI frequency using -ff 20m
- check connections
- read esptool documentation and instructions how to flash the nodeMCU firmware in nodeMCU documentation for more tips
- make sure your power supply is powerfull enough, do not use 3.3V of the USB to serial converter
Find out which SPI chip is used in you ESP
The simplest way how to find out which SPI flash chip is used in your ESP is to look on the flash chip on your ESP (use magnifier glass if needed, it is very small), read the marking and google its datasheet. Sometimes it is not possible - for example on ESP 12-F the flash chip is under metal cover.
Use esptool to find SPI flash type in your ESP
- put the ESP into flash mode (see Hardware setup)
esptool.py --port /dev/ttyUSB0 flash_id
- output should be something like
esptool.py v2.0-beta2 Connecting.... Detecting chip type... ESP8266 Uploading stub... Running stub... Stub running... Manufacturer: e0 Device: 4016 Hard resetting...
- look into flashchips.h, google datasheet
In datasheet look for:
- SPI speed
- DIO / QIO
Like my blog? Want to buy me coffee or beer?
LTC (litecoin): LeWzkcV2ArRv7Bi7TmrTpwkp6j2CZSLwfY
BTC (bitcoin): 1LzmUcwHK5Ys4zGPRoxYodjzpJsWiG61JY
DOGE (dogecoin): DQmS6EdDXssriDgSBpQMxYicHTiji6kMhx
ETH (ethereum): 0x387ff39c66e71c454ce5844c188c1a87835d2263
USDT (tether@ETH): 0xa69cae5a1da5ff5fb226e4bc87fe5d0f8c45908a
MANA (decentraland): 0xa69cae5a1da5ff5fb226e4bc87fe5d0f8c45908a
XMR (monero): 4JUdGzvrMFDWrUUwY3toJATSeNwjn54LkCnKBPRzDuhzi5vSepHfUckJNxRL2gjkNrSqtCoRUrEDAgRwsQvVCjZbRxBb8sEWJB1SCCuUEa