gpt4 book ai didi

c - MicroZed 无法使用 xilffs 库写入 SD 卡

转载 作者:太空宇宙 更新时间:2023-11-04 08:06:10 30 4
gpt4 key购买 nike

我正在使用带有 Xilinx Zynq 7010 的 MicroZed 开发板,我试图在没有任何操作系统的情况下写入 SD 卡,仅使用 xilffs (LibXil 胖文件系统)库。

为了测试它,我正在使用这个 xilffs_polled_example.c Xilinx提供的测试文件,此时测试失败:

// Write data to file.
Res = f_write(&fil, (const void*)SourceAddress, FileSize, &NumBytesWritten);
if (Res) {
xil_printf("6: Failed to write data to file\n");
return XST_FAILURE;
}

但是,如果我注释掉那个测试数据验证测试,那么其他一切都成功了:

2: Successful mount
3: Successfully created FAT volume
4: Successfully opened file with permissions
5: Successfully put pointer at beginning of file
skip write test
7:Successfully put pointer back to beginning of file
8: Successfully read data from file
skip data verification
10: Successfully closed file

我认为这可能是 SD 卡处于错误模式/格式的问题。我已经使用 Windows 10 将 SD 卡格式化为 FAT32,如果 SD 卡处于只读模式,我认为此测试也会失败:

SD_File = (char *)FileName;
Res = f_open(&fil, (char *)FileName, FA_CREATE_ALWAYS | FA_WRITE | FA_READ);
if (Res) {
xil_printf("4: Failed to open file with permissions\n");
return XST_FAILURE;
}

下面是我的代码,除了要调试的打印语句外,它与链接文件基本相同。有没有人对问题可能有任何理论?

int FfsSdPolledExample(void)
{
FRESULT Res;
UINT NumBytesRead;
UINT NumBytesWritten;
u32 BuffCnt;
u32 FileSize = (8*1024*1024);
//TCHAR *Path = "0:/";
const char *Path = "0:/";

Platform = XGetPlatform_Info();
if (Platform == XPLAT_ZYNQ_ULTRA_MP) {
// Since 8MB in Emulation Platform taking long time, reduced
// file size to 8KB.
FileSize = 8*1024;
}

for(BuffCnt = 0; BuffCnt < FileSize; BuffCnt++){
SourceAddress[BuffCnt] = TEST + BuffCnt;
}

// Register volume work area, initialize device
Res = f_mount(&fatfs, Path, 0);
if (Res != FR_OK) {
xil_printf("2: Failed to mount\n");
return XST_FAILURE;
}
xil_printf("2: Successful mount\n");

// Path - Path to logical driver, 0 - FDISK format.
// 0 - Cluster size is automatically determined based on Vol size.
Res = f_mkfs(Path, 0, 0);
if (Res != FR_OK) {
xil_printf("3: Failed to create FAT volume\n");
return XST_FAILURE;
}
xil_printf("3: Successfully created FAT volume\n");

// Open file with required permissions.
// Here - Creating new file with read/write permissions. .
// To open file with write permissions, file system should not
// be in Read Only mode.
SD_File = (char *)FileName;

Res = f_open(&fil, (char *)FileName, FA_CREATE_ALWAYS | FA_WRITE | FA_READ);
if (Res) {
xil_printf("4: Failed to open file with permissions\n");
return XST_FAILURE;
}
xil_printf("4: Successfully opened file with permissions\n");

// Pointer to beginning of file
Res = f_lseek(&fil, 0);
if (Res) {
xil_printf("5: Failed to put pointer at beginning of file\n");
return XST_FAILURE;
}
xil_printf("5: Successfully put pointer at beginning of file\n");

// Write data to file.
/*
Res = f_write(&fil, (const void*)SourceAddress, FileSize,
&NumBytesWritten);
if (Res) {
xil_printf("6: Failed to write data to file\n");
return XST_FAILURE;
}
xil_printf("6: Successfully written data to file\n");
*/

//Pointer to beginning of file .
Res = f_lseek(&fil, 0);
if (Res) {
xil_printf("7: Failed to put pointer back to beginning of file\n");
return XST_FAILURE;
}
xil_printf("7: Successfully put pointer back to beginning of file\n");

//Read data from file.
Res = f_read(&fil, (void*)DestinationAddress, FileSize,
&NumBytesRead);
if (Res) {
xil_printf("8: Failed to read data from file\n");
return XST_FAILURE;
}
xil_printf("8: Successfully read data from file\n");

// Data verification
/*
for(BuffCnt = 0; BuffCnt < FileSize; BuffCnt++){
if(SourceAddress[BuffCnt] != DestinationAddress[BuffCnt]){
xil_printf("9: Data verification failed\n");
return XST_FAILURE;
}
}
xil_printf("9: Data verification passed\n");
*/

//Close file.
Res = f_close(&fil);
if (Res) {
xil_printf("10: Failed to close file\n");
return XST_FAILURE;
}
xil_printf("10: Successfully closed file\n");

return XST_SUCCESS;
}

最佳答案

我在设计中偶然发现了同样的问题。 xilffs 中的写入功能似乎已损坏。

长话短说,问题出在 diskio.c 中,它在连续写入期间行为异常。卡或 DMA 可能仍然很忙,并且硬件包装器功能从不检查它们是否空闲。

到目前为止还没有好的和稳定的解决方案,但是在 disk_write() 中的 XSdPs_WritePolled() 之前添加 usleep(200) 会有所帮助。

这是一个 BSP 源代码,要对其进行编辑,您需要使用您的 xilffs 副本创建一个本地存储库,并将其添加到本地存储库列表(xilinx 工具 -> 存储库),然后在本地存储库中编辑 diskio.c 并重新生成 bsp (s).

关于c - MicroZed 无法使用 xilffs 库写入 SD 卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42772362/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com