Я использую плату разработки MicroZed с Xilinx Zynq 7010 и пытаюсь записать на 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-карта находится в неправильном режиме/формате. Я отформатировал SD-карту как FAT32 с помощью Windows 10, и если бы 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;
}