環境:
Arduino IDE 2.3.8、ESP32 NodeMCU-32S 開發板程式碼:
//#include "LittleFS.h"
void setup() {
Serial.begin(115200);
delay(2000);
Serial.println("--- RAM 資訊 ---");
// 內置 SRAM
Serial.printf("SRAM 總大小: %d bytes\n", ESP.getHeapSize());
Serial.printf("可用 SRAM: %d bytes\n", ESP.getFreeHeap());
// 外部 PSRAM (如果硬體支持且已開啟)
if (psramInit()) {
Serial.printf("PSRAM 總大小: %d bytes\n", ESP.getPsramSize());
Serial.printf("可用 PSRAM: %d bytes\n", ESP.getFreePsram());
} else {
Serial.println("未偵測到 PSRAM");
}
Serial.println("\n--- Flash 資訊 ---");
// 硬體上的總容量
uint32_t flashSize = ESP.getFlashChipSize();
Serial.printf("Flash 實際硬體大小: %u bytes (%d MB)\n", flashSize, flashSize / (1024 * 1024));
// 當前程式 (Sketch) 佔用與可用空間
uint32_t sketchSize = ESP.getSketchSize();
uint32_t freeSketchSpace = ESP.getFreeSketchSpace();
Serial.printf("程式已佔用: %u bytes\n", sketchSize);
Serial.printf("程式區剩餘可用: %u bytes\n", freeSketchSpace);
// 如果有用 LittleFS 或 SPIFFS (檔案系統)
// 需要先 #include "LittleFS.h"
/*
if (LittleFS.begin()) {
Serial.printf("檔案系統總量: %llu bytes\n", LittleFS.totalBytes());
Serial.printf("檔案系統已用: %llu bytes\n", LittleFS.usedBytes());
}
*/
Serial.println("\n--- 目前 Flash 分割表清單 ---");
Serial.println("Type | SubType | Offset | Size | Label");
Serial.println("----------------------------------------------");
esp_partition_iterator_t it = esp_partition_find(ESP_PARTITION_TYPE_ANY, ESP_PARTITION_SUBTYPE_ANY, NULL);
while (it != NULL) {
const esp_partition_t *p = esp_partition_get(it);
Serial.printf("%02x | %02x | 0x%06x | %10d | %s\n",
p->type, p->subtype, p->address, p->size, p->label);
it = esp_partition_next(it);
}
esp_partition_iterator_release(it);
Serial.println("----------------------------------------------");
}
void loop() {
}
輸出結果:
--- RAM 資訊 --- SRAM 總大小: 377912 bytes 可用 SRAM: 334240 bytes 未偵測到 PSRAM --- Flash 資訊 --- Flash 實際硬體大小: 4194304 bytes (4 MB) 程式已佔用: 282400 bytes 程式區剩餘可用: 1310720 bytes --- 目前 Flash 分割表清單 --- Type | SubType | Offset | Size | Label ---------------------------------------------- 01 | 02 | 0x009000 | 20480 | nvs 01 | 00 | 0x00e000 | 8192 | otadata 00 | 10 | 0x010000 | 1310720 | app0 00 | 11 | 0x150000 | 1310720 | app1 01 | 82 | 0x290000 | 1441792 | spiffs 01 | 03 | 0x3f0000 | 65536 | coredump ----------------------------------------------我這塊板子沒有 PSRAM,有 4MB Flash。
Flash 分割區資訊裡的
- Type 字段
- 參考
https://docs.espressif.com/projects/esp-idf/zh_CN/v6.0/esp32/api-guides/partition-tables.html#type - app(0x00)
- data(0x01)
- bootloader(0x02)
為可選項且不會影響系統功能。
預設情況下,不會出現在 ESP-IDF 的任何 CSV 分割區表檔案中,
僅在引導程式 OTA 更新和 flash 分割區時有用。
CSV 檔案中沒有該分割區,仍然可以執行 OTA。 - partition_table(0x03)
預設情況下,不會出現在 ESP-IDF 的任何 CSV 分割區表檔案中。 - 0x40-0xFE
預留給自訂分割區類型。
若需要 ESP-IDF 尚未支援的格式儲存數據,在0x40-0xFE 內新增自訂分區類型。 - app 和 data 分區的定義
https://docs.espressif.com/projects/esp-idf/zh_CN/v6.0/esp32/api-reference/storage/partition.html#_CPPv420esp_partition_type_t
- SubType 字段
- 參考
https://docs.espressif.com/projects/esp-idf/zh_CN/v6.0/esp32/api-guides/partition-tables.html#subtype - 定義
https://docs.espressif.com/projects/esp-idf/zh_CN/v6.0/esp32/api-reference/storage/partition.html#_CPPv423esp_partition_subtype_t - nvs (Non-volatile storage):非揮發性儲存,用來儲存 key-value 的資料,例如:裝置的 PHY 校準資料、Wi-Fi 資料...。
- otadata:保存OTA 升級時所需資訊。引導程式會查詢該分割區的數據,以判斷該從哪個OTA 應用程式分割區載入程式。如果"otadata" 分區為空,則會執行出廠程序。
- app:一個分割區大小是 1310720 bytes (1.25M),這個數值便是每次編譯上傳時,第一行顯示的 Maximum 最大容量限制。
例如「Sketch uses 282224 bytes (21%) of program storage space. Maximum is 1310720 bytes.」
參考:
- https://docs.espressif.com/projects/esp-idf/zh_CN/v6.0/esp32/api-guides/partition-tables.html
分区表 - ESP32 - — ESP-IDF 编程指南 latest 文档
沒有留言:
張貼留言