0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MaixCubeでSPIFFSを使ってみる

Posted at

はじめに

MaixCubeは初期ファームウェアにMaixPyが入っていて、SPIFFSにデモアプリが書き込まれています。このSPIFFS領域にArduino開発環境(Maixduino)でアクセスしてみます。

SPIFFS

MaixCubeを含むMaixシリーズのフラッシュメモリは16Mバイトです。MaixPyのデフォルトでは0xD00000〜0xFFFFFFの3MバイトがSPIFFS領域になっています。

今回はESP8266のSPIFFS実装を参考に、MaixCube用のSPIFFSを実装してみました。SPIFFSライブラリーのソースはこちら

サンプル

デモアプリ

  • SPIFFS情報
  • ファイル一覧
  • ファイル読み込み
main.cpp
# include <Arduino.h>
# include <FS.h>

void setup() {
  Serial.begin(115200);

  bool res = SPIFFS.begin();
  if (!res) {
    Serial.printf("SPIFFS error \n");
    while (true) {};
  }

  // 1. SPIFFS info
  FSInfo fs_info;
  SPIFFS.info(fs_info);
  Serial.println("SPIFFS info");
  Serial.println("totalBytes:" + String(fs_info.totalBytes));
  Serial.println("usedBytes:" + String(fs_info.usedBytes));
  Serial.println("blockSize:" + String(fs_info.blockSize));
  Serial.println("pageSize:" + String(fs_info.pageSize));
  Serial.println("maxOpenFiles:" + String(fs_info.maxOpenFiles));
  Serial.println("maxPathLength:" + String(fs_info.maxPathLength));

  // 2. SPIFFS File list
  Serial.println("");
  Serial.println("File list");
  Dir dir = SPIFFS.openDir("/");
  while( dir.next()) {
    String fn, fs;
    fn = dir.fileName();
    fn.remove(0, 1);
    fs = String(dir.fileSize());
    Serial.printf("<%s> size=%s\n", fn.c_str(), fs.c_str());
  }

  // 3. SPIFFS File read
  Serial.println("");
  Serial.println("File read");
  File fd = SPIFFS.open("/main.py", "r");
  int len = fd.available();
  Serial.printf("file size=%d\n", len);
  String str = fd.readString();
  Serial.println(str);
  fd.close();
}

void loop() {
}

最後に

Maixシリーズは16Mバイトのフラッシュが搭載されているので、十分にSPIFFS領域を確保することができます。また、MaixCube以外のMaixシリーズ、M5StickVでも使えそうです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?