官方提供的RTT例程中,有一个挂载文件W25Q128flash文件系统的例程,我试了一下,没有问题。
/* 挂载 spi flash 中名为 "filesystem" 的分区上的文件系统 */
if (dfs_mount(flash_dev->parent.name, "/", "elm", 0, 0) == 0)
{
LOG_I("Filesystem initialized!");
}
else
{
LOG_E("Failed to initialize filesystem!");
LOG_D("You should create a filesystem on the block device first!");
}
int len;
char wbuf[] = "hello world!";
char buff[1024];
/* 打开名为 "filesystem" 的分区 */
int fd = open("/hello.txt", O_RDWR);
if (fd < 0)
{
rt_kprintf("Open filesystem partition failed\n");
return -1;
}
/* 从文件中读取数据 */
len = write(fd, wbuf, sizeof(wbuf));
lseek(fd, 0, SEEK_SET);
// fseek(fd, 0, SEEK_SET);
/* 从文件中读取数据 */
len = read(fd, buff, sizeof(buff));
if (len < 0)
{
rt_kprintf("Read file failed\n");
close(fd);
return -1;
}
/* 打印读取的数据 */
rt_kprintf("Data read from file: %s\n", buff);
运行结果如下:

但是,我用ENV生成了一个工程,同样的代码,确无法挂载成功。

比较了一下这两个工程的ENV配置,发现官方例程中【Enable OsPI mode】选项没有选中,如下图:

而我用ENV创建的工程中,【Enable OsPI mode】这选项默认就是选中的,无法取消,如下图:

其他配置都是一样的,新工程无法挂载文件系统,请高手赐教!!!
你说的这是个问题,扇区配置改为4096后,这个错误提示就没有了,但是文件系统仍旧挂载不上。