Gravando no ESP32, ESP8266/ESP-12E

How Can We Help?
< Back
You are here:
Imprimir

Neste tutorial, vamos aprender a gravar firmware e programas compilados para estes microcontroladores – ESP32, ESP8266/ESP-12E.

1) Encontre o firmware mais atual

Através do site da Espressif, pode ser achado o firmware do ESP8266 em arquivo zip.

Existe um guia que explica como encontrar o firmware mais atualizado para o chip no Github. Sendo este o mais atualizado até o momento para o ESP8266.

2) (no MS-Windows) – Efetue o download do Flash Download Tools

No site da Espressif Download, baixar o arquivo zip do Flash Download Tools v. 3.9.2.

3) (no MS-Windows) – Gravando o firmware

Após descompactar o Flash Download Tools, executar flash_download_tool_3.9.2.exe.

Escolha ESP8266, develop e uart, clicando em OK
Clicar em “START” para detectar as informações – “DETECTED INFO”.
Após descompactar o arquivo zip do firmware, selecionar o “SPI SPEED”, neste caso, em 26.7MHz (crystal: 26 MHz) e preencher com o bin de fábrica (factory), bem como o endereço 0x0, clicando em “START”.

Após aparecer “FINISH”, em verde, a gravação ocorreu com sucesso.

4) (no Linux) – Instalar o esptool.py

Instalar o pacote e dependências no Python 3.x:

# pip3 install esptool
Collecting esptool
  Downloading esptool-4.2.1.tar.gz (202 kB)
     |████████████████████████████████| 202 kB 3.8 MB/s
Collecting bitstring>=3.1.6
  Downloading bitstring-3.1.9-py3-none-any.whl (38 kB)
Requirement already satisfied: cryptography>=2.1.4 in /usr/lib/python3/dist-packages (from esptool) (2.8)
Collecting ecdsa>=0.16.0
  Downloading ecdsa-0.18.0-py2.py3-none-any.whl (142 kB)
     |████████████████████████████████| 142 kB 4.8 MB/s
Requirement already satisfied: pyserial>=3.0 in /usr/lib/python3/dist-packages (from esptool) (3.4)
Collecting reedsolo<=1.5.4,>=1.5.3
  Downloading reedsolo-1.5.4.tar.gz (271 kB)
     |████████████████████████████████| 271 kB 6.3 MB/s
Requirement already satisfied: six>=1.9.0 in /usr/local/lib/python3.8/dist-packages (from ecdsa>=0.16.0->esptool) (1.15.0)
Building wheels for collected packages: esptool, reedsolo
  Building wheel for esptool (setup.py) ... done
  Created wheel for esptool: filename=esptool-4.2.1-py3-none-any.whl size=259061 sha256=c6882db6ef10b18d17cd5c499d0eb7d464a0c302816a89fe00f8956e801854fa
  Stored in directory: /root/.cache/pip/wheels/f0/e8/bf/3ffce5fd74eead2a1f1460250889e9042c283d689ef8e96620
  Building wheel for reedsolo (setup.py) ... done
  Created wheel for reedsolo: filename=reedsolo-1.5.4-py3-none-any.whl size=28950 sha256=a0ca4b03876b337a9c82bfb9eedebc15ad39886009e03277db47db62653eb3c8
  Stored in directory: /root/.cache/pip/wheels/09/d5/d4/7485a909ef156de1ad5d336eecbd784dd9d54af373850ff4bc
Successfully built esptool reedsolo
Installing collected packages: bitstring, ecdsa, reedsolo, esptool
Successfully installed bitstring-3.1.9 ecdsa-0.18.0 esptool-4.2.1 reedsolo-1.5.4

Pesquisar em qual tty está a placa ESP, corresponde a um COM x do Windows (p.ex. COM4):

# for tty in $(ls /dev/ttyS*); do stty -F $tty -a; done
stty: /dev/ttyS0: Input/output error
stty: /dev/ttyS1: Input/output error
...
stty: /dev/ttyS39: Input/output error
speed 115200 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = <undef>; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl -ixon -ixoff -iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc
stty: /dev/ttyS40: Input/output error
stty: /dev/ttyS41: Input/output error

Neste caso, se está depois de ttyS39 antes de ttyS40, é ttyS4.

Dessa forma, temos:

# esptool.py --chip auto --port /dev/ttyS4 --baud 115200 --before default_reset --after har
d_reset write_flash -z 0x0 download.config
esptool.py v4.2.1
Serial port /dev/ttyS4
Connecting....
Detecting chip type... Unsupported detection protocol, switching and trying again...
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 4c:75:25:37:8b:3f
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00000fff...
Compressed 512 bytes to 199...
Wrote 512 bytes (199 compressed) at 0x00000000 in 0.1 seconds (effective 74.3 kbit/s)...
Hash of data verified.

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

5) Considerações Finais

Podemos observar que, no download.config, usado no esptool.py (Linux), temos as configurações detalhadas de quais são os binários e os endereços de gravação no chip ESP:

# cat download.config
--flash_mode dio --flash_freq 80m --flash_size 2MB 0x8000 partition_table/partition-table.bin 0x9000 ota_data_initial.bin 0x0 bootloader/bootloader.bin 0x10000 esp-at.bin 0xF0000 at_customize.bin 0xFC000 customized_partitions/client_ca.bin 0x106000 customized_partitions/mqtt_key.bin 0x104000 customized_partitions/mqtt_cert.bin 0x108000 customized_partitions/mqtt_ca.bin 0xF1000 customized_partitions/factory_param.bin 0xF8000 customized_partitions/client_cert.bin 0xFA000 customized_partitions/client_key.bin

Dessa forma, é possível realizar o passo 3, utilizando os arquivos bin e endereçamentos acima (formato hexadecimal 0xNNNN).

Table of Contents