cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
crclayton
Visitor
Visitor
5,601 Views
Registered: ‎02-18-2017

Failing to write to SD card with xilffs

I'm using a MicroZed with a Zynq 7010 and I'm trying to write to an SD card without any OS, just using the xilffs (LibXil fat file system) library: http://www.wiki.xilinx.com/xilffs

  

In order to test it, I am using this xilffs_polled_example.c test file provided by Xilinx here: https://github.com/Xilinx/embeddedsw/blob/master/lib/sw_services/xilffs/examples/xilffs_polled_example.c

 

But test fails at this point:

 

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

However, if I comment out that test the data verification test, then everything else is successful:

 

  1. Successful mount
  2. Successfully created FAT volume
  3. Successfully opened file with permissions
  4. Successfully put pointer at beginning of file
  5. Skip write test
  6. Successfully put pointer back to beginning of file
  7. Successfully read data from file
  8. Skip data verification
  9. Successfully closed file

I thought it might be a problem to do with the SD card being in the wrong mode/format. So I have formatted the SD card as FAT32 using Windows 10, and if the SD card was in read-only mode I think this test would also fail:

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

I have attached my code, although it's basically the same as the linked GitHub file except for print statements to debug. Does anyone have any theories for what the issue may be?

 

Thank you very much in advance. 

 

0 Kudos
3 Replies
crclayton
Visitor
Visitor
5,565 Views
Registered: ‎02-18-2017

I've also changed the filename and plugged the SD card into my computer, and I'm confident the code is creating the file -- I just can't write anything in it.
0 Kudos
crclayton
Visitor
Visitor
5,555 Views
Registered: ‎02-18-2017

Fixed the issue. The 16GB Micro SD card that came with the MicroZed apparently doesn't work with this code. I swapped that SD card out for a cheap 1GB one that came with an old phone, formatted it the same way, and now the code works. Anyone have a guess as to why?

0 Kudos
yag005
Newbie
Newbie
3,659 Views
Registered: ‎02-22-2018

Old thread, but hopefully this solution might be helpful to others having this problem.

I haven't tried your exact code, but I did experience not being able to use a memory card (16gb class 4 SDHC) by doing a quick format in ubuntu 16.04. After doing a full format by "overwriting existing data with zeroes (slow)", it worked perfectly. Might have been the same thing with your card. 

0 Kudos