ESP32——Array or structure and other types of data are saved after power-off (partition table method)

The content mainly comes from Espressif’s official website

When using the partition table, you need to open the project configuration menu (VSCODE SDK Configuration editor)

 There are 3 options below

  • “Single factory app, no OTA”

  • “Factory app, two OTA definitions”

  • “Custom partition table CSV”

Here is a summary of the partition table information for the "Single factory app, no OTA" option:

# ESP-IDF Partition Table
# Name,   Type, SubType, Offset,  Size,   Flags
nvs,      data, nvs,     0x9000,  0x6000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000, 1M,
  • At offset 0x10000 (64 KB) of the flash is stored a binary application marked "factory", and the boot loader will load this application by default.

  • Two data areas are also defined in the partition table, which are used to store NVS library-specific partitions and PHY initialization data respectively.

Here is a summary of the partition table information for the "Factory app, two OTA definitions" option:

# ESP-IDF Partition Table
# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x4000,
otadata,  data, ota,     0xd000,  0x2000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000,  1M,
ota_0,    app,  ota_0,   0x110000, 1M,
ota_1,    app,  ota_1,   0x210000, 1M,
  • Three application partitions are defined in the partition table, and the types of these three partitions are all set to "app", but the specific app types are different. Among them, the one located at the offset address of 0x10000 is the factory application program (factory), and the other two are OTA application programs (ota_0, ota_1).

  • A new data partition named "otadata" is added to save the data needed for OTA upgrade. The boot loader queries the partition's data to determine which OTA application partition to load from. If the "otadata" partition is empty, the factory program will be executed.

"Custom partition table CSV" is a custom partition table, and the corresponding CSV file needs to be modified. This method is not as common as the above two methods.

Code example:

    const esp_partition_t *partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, NULL);
    assert(partition != NULL);
    id[]={0xE2,0x01,0xD2,0x11,0x73,0x41,0x00,0x78,0x85,0x51,0x00,0x00};
    ESP_ERROR_CHECK(esp_partition_erase_range(partition, 0, partition->size));//SPI_FLASH_SEC_SIZE));
    ESP_ERROR_CHECK(esp_partition_write(partition, 0, id, 12));
    ESP_ERROR_CHECK(esp_partition_read(partition, 0, read_data, 12));

おすすめ

転載: blog.csdn.net/tsliuch/article/details/125498379