Seeed-Arduino-fs
介绍
Arduino的轻量级FATF端口。该库包含通过SPI驱动SD卡的例程。文件系统部分是通用的,这意味着您可以轻松地将其移植到其他类型的内存中,例如QSPI Flash,Emmc,等。
一个示例包含在Seeed_arduino_sfud中
用法
该代码已在WIO终端进行了测试。
Seeed_Arduino_FS.h>
#define LOG Serial
#define DEV SD
#ifdef _SAMD21_
#define SDCARD_SS_PIN 1
#define SDCARD_SPI SPI
#endif
void setup() {
LOG.begin(115200);
pinMode(5, OUTPUT);
digitalWrite(5, HIGH);
while (!LOG) {};
while (!DEV.begin(SDCARD_SS_PIN,SDCARD_SPI,4000000UL)) {
LOG.println("Card Mount Failed");
return;
}
LOG.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File RootWrite = DEV.open("/hello.txt", "w");
// File RootWrite = DEV.open("/hello.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (RootWrite) {
LOG.print("Writing to hello.txt…");
RootWrite.println("hello 1, 2, 3.");
// close the file:
RootWrite.close();
LOG.println("done.");
} else {
// if the file didn\’t open, print an error:
LOG.println("error opening hello.txt");
}
// re-open the file for reading:
File RootRead= DEV.open("/hello.txt");
if (RootRead) {
LOG.println("hello.txt:");
// read from the file until there\’s nothing else in it:
while (RootRead.available()) {
LOG.write(RootRead.read());
}
// close the file:
RootRead.close();
} else {
// if the file didn\’t open, print an error:
LOG.println("error opening hello.txt");
}
}
void loop() {
// nothing happens after setup
}
\”>
# include < Seeed_Arduino_FS .h > # define LOG Serial # define DEV SD # ifdef _SAMD21_ # define SDCARD_SS_PIN 1 # define SDCARD_SPI SPI # endif void setup () { LOG. begin ( 115200 ); pinMode ( 5 , OUTPUT); digitalWrite ( 5 , HIGH); while (!LOG) {}; while (!DEV. begin (SDCARD_SS_PIN,SDCARD_SPI, 4000000UL )) { LOG. println ( \" Card Mount Failed \" ); return ; } LOG. println ( \" initialization done. \" ); // open the file. note that only one file can be open at a time, // so you have to close this one before opening another. File RootWrite = DEV. open ( \" /hello.txt \" , \" w \" ); // File RootWrite = DEV.open(\"/hello.txt\", FILE_WRITE); // if the file opened okay, write to it: if (RootWrite) { LOG. print ( \" Writing to hello.txt... \" ); RootWrite. println ( \" hello 1, 2, 3. \" ); // close the file: RootWrite. close (); LOG. println ( \" done. \" ); } else { // if the file didn\'t open, print an error: LOG. println ( \" error opening hello.txt \" ); } // re-open the file for reading: File RootRead= DEV. open ( \" /hello.txt \" ); if (RootRead) { LOG. println ( \" hello.txt: \" ); // read from the file until there\'s nothing else in it: while (RootRead. available ()) { LOG. write (RootRead. read ()); } // close the file: RootRead. close (); } else { // if the file didn\'t open, print an error: LOG. println ( \" error opening hello.txt \" ); } } void loop () { // nothing happens after setup }
API参考
- 布尔开始(UINT8_T SSPIN,SPICLASS&SP,INT HZ):配置SPI控制存储设备
DEV.begin(SDCARD_SS_PIN,SDCARD_SPI, 4000000UL ) // DEV.begin(104000000UL) //use qspi flash
- sdcard_type_t cardtype():获取SD卡类型
注意:仅使用SD卡
uint8_t cardType = DEV.cardType(); if (cardType == CARD_NONE) { SERIAL. println ( \" No SD card attached \" ); return ; }
- sfud_type_t flashtype():获取flash类型
注意:仅与Flash一起工作
uint8_t flashType = DEV.flashType(); if (flashType == FLASH_NONE) { SERIAL. println ( \" No flash attached \" ); return ; }
- uint64_t cardsize():获取SD卡大小
注意:仅使用SD卡
uint64_t cardSize = DEV.cardSize() / ( 1024 * 1024 ); SERIAL.print( \" SD Card Size: \" ); SERIAL.print(( uint32_t )cardSize); SERIAL.println( \" MB \" );
- uint64_t flashsize():获取闪光灯大小
注意:仅与Flash一起工作
uint32_t flashSize = DEV.flashSize() / ( 1024 * 1024 ); SERIAL.print( \" flash Size: \" ); SERIAL.print(( uint32_t )flashSize); SERIAL.println( \" MB \" );
- uint64_t totalbytes():返回存储设备的总字节
uint32_t totalBytes = DEV.totalBytes(); SERIAL.print( \" Total space: \" ); SERIAL.print(totalBytes / ( 1024 * 1024 )); SERIAL.println( \" MB \" );
- uint64_t underbytes():返回存储设备的二手字节
uint32_t usedBytes = DEV.usedBytes(); SERIAL.print( \" Used space: \" ); SERIAL.print(usedBytes / ( 1024 * 1024 )); SERIAL.println( \" MB \" );
该软件由Seeed Studio撰写
并获得MIT许可证的许可。检查许可证.txt以获取更多信息。
热烈欢迎为此软件做出贡献。您基本上可以做到这一点
分叉,进行修改然后提取请求(请按照上述链接
用于操作指南)。鼓励添加更改日志,并鼓励您的联系人到文件标头中。
感谢您的贡献。
Seeed Studio是一家位于中国深圳的开放硬件便利化公司。
受益于本地制造能力和方便的全球逻辑系统,
我们整合资源以服务新时代的创新时代。 Seeed也可以使用
全球分销商和合作伙伴推动开放硬件运动。
