標籤: ESP

ESP series, esp8266, esp32, …

ESP8266 Filesystem

No Comments

快速指引

  • SPIFFs and LittleFs 之比較請谷歌
  • 二者的使用方式幾乎全同,細節參考
  • 筆者採用 LittleFs
  • 先安裝 tool plugin 工具外掛至 Arduino IDE,會於工具選單中出現
  • ESP8266 Sketch Data Upload -> SPIFFs
  • ESP8266 LittleFS Data Upload
  • 個別的下載網址請參考上面連結 細節參考
  • 其功能就是將檔案上傳至 esp8266 flash 中。flash 會事先依選單中 工具 -> Flash Size 中指定的配置方式,分別是總大小,FS 大小,及 OTA 大小配置出三個主要的獨立的區塊(FS/OTA/Sketch)。其將檔案上傳置於 FS 區。
  • 所要上傳的檔案置於 sketch file folder 中的 data folder 內
  • 以上稱為離線配置。
  • 要注意的是 ./data 內的所有資料代表著/映射至 flash FS root 的整個空間。也就是所上傳者將取代 flash FS 區內的所有原有資料。
  • 此外刷寫 flash;作 sketch 的上傳,依 “工具 -> Erase Flash:” 的選擇,唯有 “All Flash Contents”才會將 FS 區也抹除。因此以上兩點的搭配下便能決定原有資料的保留與否。
  • 線上使用,便是使用 LittleFs/SPIFFs 的 API,有 format/open/read/write 等。
  • 以下是 little fs 的初始化程式碼及輸出範例。
  • 參考資料
  • 參考資料二
/*

09:36:50.447 -> --------
09:36:50.447 -> LittleFS:
09:36:50.447 -> entire space 2072576 bytes
09:36:50.447 -> 106496 bytes used
09:36:50.447 -> free space 1966080 bytes
09:36:50.447 -> block size 8192 bytes
09:36:50.447 -> page size 256 blocks
09:36:50.447 -> --------
09:36:50.447 -> list root directory "/":
09:36:50.447 -> c.txt    16 bytes
09:36:50.447 -> sketch_feb01a.ino    71221 bytes
09:36:50.447 -> test1    <DIR>

*/


void setup_littlefs(){
    LittleFS.begin();
    {
        Dir dir = LittleFS.openDir("/");
        if (!dir.next()){
            LittleFS.format();
            printf("filesystem formatted.\r\n");
        }
    }
    FSInfo fs_info;
    if (LittleFS.info(fs_info)){
        printf(\
            "--------\r\nLittleFS:\r\nentire space %d bytes\r\n%d bytes used\r\n"\
            "free space %d bytes\r\nblock size %d bytes\r\npage size %d blocks\r\n--------\r\n",\
            fs_info.totalBytes, fs_info.usedBytes, fs_info.totalBytes-fs_info.usedBytes, fs_info.blockSize, fs_info.pageSize);
    }

    Dir dir = LittleFS.openDir("/");
    printf("list root directory \"/\":\r\n");
    while (dir.next())
        printf("%s    %s\r\n", dir.fileName().c_str(), dir.isDirectory()? "<DIR>": (String(dir.fileSize())+" bytes").c_str());
}

Categories: Arduino

Tags:

PHP Code Snippets Powered By : XYZScripts.com