Sitelet https://github.com/micropython/micropython/commit/fe22d575fe0261b6de550fc352bf0f7d9d59247e
Skip to content

Commit fe22d57

Browse files
Josverldpgeorge
authored andcommitted
docs/esp8266: Clarify flashing ESP8266 devices with >4 MB flash.
Updated to current firmware variants Removed python 2.7 references. Signed-off-by: Jos Verlinde <Jos_Verlinde@hotmail.com>
1 parent aee96a0 commit fe22d57

1 file changed

Lines changed: 116 additions & 35 deletions

File tree

‎docs/esp8266/tutorial/intro.rst‎

Lines changed: 116 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,25 @@ characteristic of a board is how much flash it has, how the GPIO pins are
2020
connected to the outside world, and whether it includes a built-in USB-serial
2121
converter to make the UART available to your PC.
2222

23-
The minimum requirement for flash size is 1Mbyte. There is also a special
24-
build for boards with 512KB, but it is highly limited comparing to the
25-
normal build: there is no support for filesystem, and thus features which
26-
depend on it won't work (WebREPL, mip, etc.). As such, 512KB build will
27-
be more interesting for users who build from source and fine-tune parameters
28-
for their particular application.
23+
MicroPython is distributed as several firmware variants to suit the amount of
24+
flash on your board:
25+
26+
* The standard build (``ESP8266_GENERIC``) targets boards with **2MiB or more**
27+
of flash. This is the recommended build and the best choice for most users.
28+
* The ``FLASH_1M`` variant is for boards with **1MiB** of flash. It removes
29+
asyncio and FAT-filesystem support, as well as some modules from
30+
micropython-lib.
31+
* The ``FLASH_2M_ROMFS`` variant targets **2MiB** boards and reserves part of
32+
the flash for a read-only ROMFS filesystem.
33+
* The ``FLASH_512K`` variant is for boards with only **512kiB** of flash. It is
34+
highly limited compared to the other builds: there is no filesystem support,
35+
and so features that depend on it won't work (WebREPL, mip, etc.). It also
36+
drops framebuffer support, some Python language features, and has less
37+
detailed error messages. This variant is mainly of interest to users who
38+
build from source and fine-tune parameters for their particular application.
39+
40+
The minimum recommended flash size is therefore 1MiB, with 2MiB or more giving
41+
the best experience.
2942

3043
Names of pins will be given in this tutorial using the chip names (eg GPIO0)
3144
and it should be straightforward to find which pin this corresponds to on your
@@ -43,23 +56,31 @@ Getting the firmware
4356

4457
The first thing you need to do is download the most recent MicroPython firmware
4558
.bin file to load onto your ESP8266 device. You can download it from the
46-
`MicroPython downloads page <http://micropython.org/download#esp8266>`_.
47-
From here, you have 3 main choices
59+
`ESP8266 download page <https://micropython.org/download/ESP8266_GENERIC/>`_.
4860

49-
* Stable firmware builds for 1024kb modules and above.
50-
* Daily firmware builds for 1024kb modules and above.
51-
* Daily firmware builds for 512kb modules.
61+
The download page offers the firmware variants described above. Pick the one
62+
that matches your board's flash size:
5263

53-
If you are just starting with MicroPython, the best bet is to go for the Stable
54-
firmware builds. If you are an advanced, experienced MicroPython ESP8266 user
55-
who would like to follow development closely and help with testing new
56-
features, there are daily builds (note: you actually may need some
57-
development experience, e.g. being ready to follow git history to know
58-
what new changes and features were introduced).
64+
========================================================= =========================================
65+
Firmware file Board flash size
66+
========================================================= =========================================
67+
``ESP8266_GENERIC-<date>-<version>.bin`` 2MiB-4MiB, 8MiB-16MiB** (the standard build)
68+
``ESP8266_GENERIC-FLASH_1M-<date>-<version>.bin`` 1MiB
69+
``ESP8266_GENERIC-FLASH_2M_ROMFS-<date>-<version>.bin`` 2MiB-4MiB, 8MiB-16MiB** (includes a ROMFS)
70+
``ESP8266_GENERIC-FLASH_512K-<date>-<version>.bin`` 512kiB
71+
========================================================= =========================================
5972

60-
Support for 512kb modules is provided on a feature preview basis. For end
61-
users, it's recommended to use modules with flash of 1024kb or more. As
62-
such, only daily builds for 512kb modules are provided.
73+
** Boards with 8MiB or 16MiB of flash can use the standard build,
74+
but require an manual step to set up the RF calibration data, see :ref:`esp8266_large_flash` below.
75+
76+
For each variant the page lists *release* builds and *preview* builds. If you
77+
are just starting with MicroPython, choose the latest release build. If you are
78+
an experienced user who would like to follow development closely and help with
79+
testing new features, the preview builds are automatic builds of the
80+
development branch.
81+
82+
Throughout the rest of this tutorial the example commands use the standard
83+
``ESP8266_GENERIC`` firmware; substitute the exact filename you downloaded.
6384

6485
Deploying the firmware
6586
----------------------
@@ -88,10 +109,6 @@ using pip::
88109

89110
pip install esptool
90111

91-
Versions starting with 1.3 support both Python 2.7 and Python 3.4 (or newer).
92-
An older version (at least 1.2.1 is needed) works fine but will require Python
93-
2.7.
94-
95112
Any other flashing program should work, so feel free to try them out or refer
96113
to the documentation for your board to see its recommendations.
97114

@@ -101,20 +118,33 @@ Using esptool.py you can erase the flash with the command::
101118

102119
And then deploy the new firmware using::
103120

104-
esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 esp8266-20170108-v1.8.7.bin
121+
esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 ESP8266_GENERIC-20260406-v1.28.0.bin
105122

106123
You might need to change the "port" setting to something else relevant for your
107124
PC. You may also need to reduce the baudrate if you get errors when flashing
108125
(eg down to 115200). The filename of the firmware should also match the file
109126
that you have.
110127

128+
The ``--flash_size=detect`` option tells esptool.py to read the flash size from
129+
the chip's JEDEC ID. MicroPython itself also autodetects the flash size at
130+
runtime for chips up to **4MB**, so a single firmware build adapts to the actual
131+
flash on your board without any extra configuration. The filesystem is
132+
automatically sized to use all of the available flash.
133+
134+
The ESP8266 needs a small block of RF calibration data, known as
135+
``esp_init_data``, near the end of the flash before WiFi will start. On first
136+
boot MicroPython checks this region and, if it is blank (for example because you
137+
just ran ``erase_flash``), it automatically writes the default calibration data
138+
for you. For boards with **4MB of flash or less**, no manual step is needed. See
139+
:ref:`esp8266_large_flash` below for boards larger than 4MB.
140+
111141
For some boards with a particular FlashROM configuration (e.g. some variants of
112142
a NodeMCU board) you may need to manually set a compatible
113143
`SPI Flash Mode <https://github.com/espressif/esptool/wiki/SPI-Flash-Modes>`_.
114144
You'd usually pick the fastest option that is compatible with your device, but
115145
the ``-fm dout`` option (the slowest option) should have the best compatibility::
116146

117-
esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect -fm dout 0 esp8266-20170108-v1.8.7.bin
147+
esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect -fm dout 0 ESP8266_GENERIC-20260406-v1.28.0.bin
118148

119149
If the above commands run without error then MicroPython should be installed on
120150
your board!
@@ -123,6 +153,64 @@ If you pulled GPIO0 manually to ground to enter programming mode, release it
123153
now and reset the device by again pulling the reset pin to ground for a short
124154
duration.
125155

156+
.. _esp8266_large_flash:
157+
158+
Boards with more than 4MB of flash
159+
----------------------------------
160+
161+
Boards with **8MB or 16MB** of flash need one extra step. The flash routines
162+
built into the ESP8266 boot ROM (which MicroPython uses to write the calibration
163+
data on first boot) cannot address flash beyond 4MB: the ROM reads the chip's
164+
device ID but clamps the reported size to 4MB, so any access above that offset
165+
fails. As a result MicroPython can only write the ``esp_init_data`` RF
166+
calibration block automatically within the first 4MB of flash.
167+
So after a full flash erase MicroPython cannot place the calibration data at the correct end-of-flash
168+
address by itself. Without it the WiFi subsystem will not start (typically
169+
showing up as a continuous reset loop or ``rf_cal`` errors). For more background
170+
on this ROM limitation see
171+
`ESP8266 16MB Flash Handling <https://piers.rocks/esp8266/16mb/flash/eeprom/2016/10/14/esp8266-16mbyte-flash_handling.html>`_.
172+
173+
To fix this, flash the ``esp_init_data_default.bin`` file (shipped with the
174+
Espressif NONOS SDK) to the calibration address, which is the flash size minus
175+
``0x4000``, see table below.
176+
177+
You can download ``esp_init_data_default.bin`` from the Espressif repository
178+
(open the link and click "View raw" to download the file):
179+
`<https://github.com/espressif/ESP8266_AT/blob/master/bin/esp_init_data_default.bin>`__
180+
181+
The calibration addresses are:
182+
183+
=========== =====================================
184+
Flash size ``esp_init_data`` address
185+
=========== =====================================
186+
8MB ``0x7FC000``
187+
16MB ``0xFFC000``
188+
=========== =====================================
189+
190+
The full procedure for a 16MB board is::
191+
192+
# 1. Make sure esptool is up to date
193+
pip install --upgrade esptool
194+
195+
# 2. Erase the flash
196+
esptool.py --port /dev/ttyUSB0 --baud 460800 erase_flash
197+
198+
# 3. Flash the RF calibration blob at the end of flash (16MB example)
199+
esptool.py --port /dev/ttyUSB0 write_flash 0xFFC000 esp_init_data_default.bin
200+
201+
# 4. Flash MicroPython, telling esptool the real flash size
202+
esptool.py --port /dev/ttyUSB0 --baud 460800 \
203+
write_flash -fm dio --flash_size 16MB 0 ESP8266_GENERIC-20260406-v1.28.0.bin
204+
205+
# 5. Check detected flash size in the REPL
206+
mpremote exec "import esp;print(f'Detected flash: {esp.flash_size():_}')"
207+
208+
For an 8MB board, use ``0x7FC000`` in step 3 and ``--flash_size 8MB`` in step 4.
209+
210+
The filesystem is sized automatically from the detected flash size, so it
211+
will use all of the available space once the board boots.
212+
213+
126214
Serial prompt
127215
-------------
128216

@@ -173,15 +261,8 @@ after it, here are troubleshooting recommendations:
173261
rate may be too high and lead to errors. Try a more common 115200 baud
174262
rate instead in such cases.
175263

176-
* If lower baud rate didn't help, you may want to try older version of
177-
esptool.py, which had a different programming algorithm::
178-
179-
pip install esptool==1.0.1
180-
181-
This version doesn't support ``--flash_size=detect`` option, so you will
182-
need to specify FlashROM size explicitly (in megabits). It also requires
183-
Python 2.7, so you may need to use ``pip2`` instead of ``pip`` in the
184-
command above.
264+
* If lower baud rate didn't help, you may want to try a different version of
265+
esptool.py, which may use a different programming algorithm.
185266

186267
* The ``--flash_size`` option in the commands above is mandatory. Omitting
187268
it will lead to a corrupted firmware.

0 commit comments

Comments
 (0)