|
ST官方LX例程读写Nor flash的操作步骤如下,这样没问题
fx_file_create(&nor_disk, "test.txt");
fx_file_open(&nor_disk, &fx_file, "test.txt", FX_OPEN_FOR_READ);
fx_file_read(&fx_file,&readbuf, sizeof(readbuf), &bytes_read);
fx_file_close(&fx_file);
我调换了顺序,先打开某个文件,如果打开失败视为无此文件,然后再创建此文件。实际测试发现此方法不行,每次都是fx_file_open失败,返回值04。
每次都进入(status != FX_SUCCESS)里创建一次文件,如此反复运行都是这样。
status = fx_file_open(&nor_disk, &fx_file, "test.txt", FX_OPEN_FOR_READ);
if(status != FX_SUCCESS)
{
status = fx_file_create(&nor_disk, "test.txt");//每次创建文件函数返回值都为0,说明文件被创建了。
status = fx_file_open(&nor_disk, &fx_file, "test.txt", FX_OPEN_FOR_READ);
status = fx_file_read(&fx_file,&readbuf, sizeof(readbuf), &bytes_read);
status = fx_file_close(&fx_file);
}
else
{
status = fx_file_read(&fx_file,&readbuf, sizeof(readbuf), &bytes_read);
status = fx_file_close(&fx_file);
}
难道FX文件系统在读写某个未知文件时,首先必须要create,然后再open ? 不能先open失败后再crete ?
|
|