C++
ESP8266 flash memory sizes vary from 512Kbytes on the ESP-01 up to 4Mbytes on the ESP12F. Up to 16MBytes are supported for custom designs.
You can find general details for the memory layout in the ESP8266 Wiki.
This is the layout for Sming with a 4MByte flash device:
Address (hex) |
Config variable (if any) |
Size (KB) |
Source filename (if applicable) |
Description |
======= 000000 001000 002000 100000 202000 300000 3FB000 3FC000 3FD000 |
ROM_0_ADDR RBOOT_SPIFFS_0 ROM_1_ADDR RBOOT_SPIFFS_1 |
==== 1 4 4 4 12 |
========================= rboot.bin rom0.bin rom1.bin blank.bin esp_init_data_default.bin blank.bin |
=================================================== Boot loader rBoot configuration First ROM image Second ROM image RF Calibration data (Initialised to FFh) PHY configuration data System parameter area |
{ todo }
Whilst SDK version 3 requires a partition table, previous versions do not but this can be added so that we can use it as a common reference for all the above locations.
Flash memory on the ESP8266 is accessed via an external SPI bus, so reading it takes about 12x longer than reading from internal RAM. To mitigate this, some of the internal RAM is used to cache data. Part of this is managed in hardware, which means if the data required is already in the cache then there is no difference in speed. In general, then, frequently accessed data is read as if it were already in RAM.
Bear in mind that every time new data is read via the cache, something else will get thrown away and have to be re-read. Therefore, if you have large blocks of infrequently accessed data then it's a good idea to read it directly using :cppflashmem_read
. You can get the address for a memory location using :cppflashmem_get_address
.
See /framework/core/pgmspace
for details of how to store data in flash, and access it.