前言
项目需求:在ESP32板子重启之后,自动从Flash中寻找已经存储好的WiFi账号和秘密,连接到网络。
要想能够很好的理解如何将WiFi的账号和密码如何写入到Flash的什么地方,首先需要了解下ESP32中Flash的特点。
1 ESP32 Flash介绍
SP32 支持多个外部 QSPI flash 和静态随机存储器 (SRAM)。我用的是ESP32-WROOM-32D,集成了 4 MB 的 SPI flash,连接 ESP32 的管脚 GPIO6,GPIO7, GPIO8,GPIO9,GPIO10 和 GPIO11。
Flahs上包含不同类型的数据,如烧录的bin数据,校准数据、文件系统数据、参数存储数据等。因此,需要一张分区表对Flash空间进行管理。
通过理解烧写程序过程中的提示,可以更加深入理解Flash。
Chip is ESP32-D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: c8:f0:9e:9e:1e:04
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00001000 to 0x00007fff...
Flash will be erased from 0x00010000 to 0x000a9fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Compressed 25392 bytes to 15887...
Writing at 0x00001000... (100 %)
Wrote 25392 bytes (15887 compressed) at 0x00001000 in 0.7 seconds (effective 309.1 kbit/s)...
Hash of data verified.
Compressed 629024 bytes to 403328...
Writing at 0x00010000... (4 %)
Writing at 0x0001bf4e... (8 %)
Writing at 0x00026622... (12 %)
Writing at 0x0002c22e... (16 %)
Writing at 0x00031d70... (20 %)
Writing at 0x000375ea... (24 %)
Writing at 0x0003cf1b... (28 %)
Writing at 0x00042655... (32 %)
Writing at 0x00047cc1... (36 %)
Writing at 0x0004d37e... (40 %)
Writing at 0x00052bdf... (44 %)
Writing at 0x0005870e... (48 %)
Writing at 0x0005d9fd... (52 %)
Writing at 0x00062d65... (56 %)
Writing at 0x00067fed... (60 %)
Writing at 0x0006d67e... (64 %)
Writing at 0x00072e09... (68 %)
Writing at 0x000789e5... (72 %)
Writing at 0x0007e28c... (76 %)
Writing at 0x0008446f... (80 %)
Writing at 0x0008a2b4... (84 %)
Writing at 0x00090afb... (88 %)
Writing at 0x0009ace9... (92 %)
Writing at 0x000a0b27... (96 %)
Writing at 0x000a61c3... (100 %)
Wrote 629024 bytes (403328 compressed) at 0x00010000 in 9.4 seconds (effective 535.8 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 104...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (104 compressed) at 0x00008000 in 0.0 seconds (effective 498.6 kbit/s)...
Hash of data verified.
烧录的芯片是ESP32-D0WDQ6。烧录前擦除Flash的三个区域。